WebAPI/ArchiveAPI: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Created page with "= Archive API Specification = == Goals == To provide the ability to read the content of an archive file through DOM File objects. __TOC__ == Status == See {{bug|772434}} for...")
 
Line 42: Line 42:


== Examples ==
== Examples ==
Example use of the Archive API:


* How to get the list of files contained in an archive?
* How to get the list of files contained in an archive?

Revision as of 10:15, 7 August 2012

Archive API Specification

Goals

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

Status

See bug 772434 for the Archive API implementation.

Proposers

Andrea Marchesini

Features

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
 {
   [infallible]
   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
 }
  
 [Constructor(Blob blob)]
 interface ArchiveReader
 {
   ArchiveRequest getFilenames();
   ArchiveRequest getFile(DOMString filename);
 };

Examples

  • 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 Alarm API: