WebAPI/ArchiveAPI: Difference between revisions
< WebAPI
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...") |
No edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 32: | Line 32: | ||
// In case of a getFilenames() request, the result is an array of DOMString | // 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 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)] | [Constructor(Blob blob, optional ArchiveReaderOptions options)] | ||
interface ArchiveReader | interface ArchiveReader | ||
{ | { | ||
ArchiveRequest getFilenames(); | ArchiveRequest getFilenames(); | ||
ArchiveRequest getFile(DOMString filename); | ArchiveRequest getFile(DOMString filename); | ||
ArchiveRequest getFiles(); | |||
}; | |||
dictionary ArchiveReaderOptions | |||
{ | |||
DOMString encoding = "windows-1252"; // Default fallback encoding | |||
}; | }; | ||
== Examples == | == Examples == | ||
* How to get the list of files contained in an archive? | * How to get the list of files contained in an archive? | ||
Line 72: | Line 77: | ||
== See Also == | == See Also == | ||
Other Web APIs related to the | Other Web APIs related to the Archive API: | ||
* [[WebAPI]] | * [[WebAPI]] | ||
[[Category:Web APIs]] |
Latest revision as of 23:48, 1 October 2014
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 // 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 };
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 Archive API: