W3C home > Mailing lists > Public > whatwg@whatwg.org > July 2012

[whatwg] Archive API - proposal

From: Andrea Marchesini <baku@mozilla.com>
Date: Tue, 17 Jul 2012 19:23:02 -0700 (PDT)
To: whatwg@whatwg.org
Message-ID: <1109088978.24458062.1342578182439.JavaMail.root@mozilla.com>
Hi All,

I would like to propose a new javascript/web API that provides the ability to read the content of an archive file through DOMFile objects.
I have started to work on this API because it has been requested during some Mozilla Game Meeting by game developers who often use ZIP files as storage system.

What I'm describing is a read-only and asynchronous API built on top of FileAPI ( http://dev.w3.org/2006/webapi/FileAPI/ ).

Here a draft written in webIDL:

interface ArchiveRequest : DOMRequest
  // this is the ArchiveReader:
  readonly attribute nsIDOMArchiveReader reader;

[Constructor(Blob blob)]
interface ArchiveReader
  // any method is supposed to be asynchronous

  // The ArchiveRequest.result is an array of strings (the filenames)
  ArchiveRequest getFilenames();

  // The ArchiveRequest.result is a DOMFile (http://dev.w3.org/2006/webapi/FileAPI/#dfn-file)
  ArchiveRequest getFile(DOMString filename);

Here an example about how to use it:

function startRead() {
  // Starting from a <input type="file" id="file" />:
  var file = document.getElementById('file').files[0];

  if (file.type != 'application/zip') {
    alert("This archive format is not supported");

  // The ArchiveReader object works with Blob objects:
  var archiveReader = new ArchiveReader(file);

  // Any request is asynchronous:
  var handler = archiveReader.getFilenames();
  handler.onsuccess = getFilenamesSuccess;
  handler.onerror = errorHandler;

  // Multiple requests can run at the same time:
  var handler2 = archiveReader.getFile("levels/1.txt");
  handler2.onsuccess = getFileSuccess;
  handler2.onerror = errorHandler;

// The getFilenames handler receives a list of DOMString:
function getFilenamesSuccess() {
  for (var i = 0; i < this.result.length; ++i) {
    /* this.reader is the ArchiveReader:
    var handle = this.reader.getFile(this.result[i]);
    handle.onsuccess = ...

// The GetFile handler receives a File/Blob object (and it can be used with FileReader):
function getFileSuccess() {
  var reader = FileReader();
  reader.onload = function(event) {
    // alert(event.target.result);

function errorHandler() {
  // ...

I would like to receive feedback about this.. In particular:
. Do you think it can be useful?
. Do you see any limitation, any feature missing?

Received on Wednesday, 18 July 2012 02:23:31 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:43 UTC