From MozillaWiki
Jump to: navigation, search

Archive API Specification


To provide the ability to read the content of an archive file through DOM File objects.


See bug 772434 for the Archive API implementation.


Andrea Marchesini


The Archive API supports the following features:

  • Web application developer can get the list of filenames contained in an archive DOM file.
  • Web application developer can retrieve the content of files from an archive DOM File.
  • The API works asynchronously

Proposed API

 interface ArchiveRequest : DOMRequest
   readonly attribute ArchiveReader reader;
   // In case of a getFilenames() request, the result is an array of DOMString
   // If this is a getFile() request, the result is a DOM File
   // If this is a getFiles() request, the result is an array of DOM File
 [Constructor(Blob blob, optional ArchiveReaderOptions options)]
 interface ArchiveReader
   ArchiveRequest getFilenames();
   ArchiveRequest getFile(DOMString filename);
   ArchiveRequest getFiles();
 dictionary ArchiveReaderOptions
   DOMString encoding = "windows-1252"; // Default fallback encoding


  • How to get the list of files contained in an archive?
 var blob = ...;
 var reader = ArchiveReader(blob);
 var h = reader.getFilenames();
 h.onerror = function() { ... }
 h.onsuccess = function() {
   for (var i = 0; i < this.result.length; ++i) {
     something(this.result[i]); // this.result[i] is a DOMString
  • How to get a DOM File from the archive?
 // how to get a specific file:
 var hf = reader.getFile('image.png');
 hf.onerror = function() { ... }
 hf.onsuccess = function() {
   // this.result is a DOM File
   alert('Filename: ' + this.result.name + '\n' +
         'ContentType: ' + this.result.type + '\n' +
         'Size: ' + this.result.size);

See Also

Other Web APIs related to the Archive API: