Emil A
Emil A

Reputation: 55

JavaScript: XMLHttpRequest() from Firefox addon to get zip

I am trying to build a Firefox addon to request a zip file from a webpage and store it locally/decompress. I receive a 200 response code when I request the zip as a Blob type, but I am unsure how to store it since the Firefox file I/O documentation is quite confusing.

getFiles : function (version) {
  if(version != "?"){
    var xmlhttp=new XMLHttpRequest();
    url = "http://github.com/wet-boew/wet-boew/archive/master.zip"
    xmlhttp.open("GET", url, true);
    xmlhttp.responseType = 'blob';

    xmlhttp.onload = function(e) {
        if (this.status == 200) {
            // Note: .response instead of .responseText
            var blob = new Blob([this.response], {type: 'compress/zip'});
        }
    };
    xmlhttp.send();
 }
 return zip;
},

File I/O documentation

Any help or advice is appreciated!

Upvotes: 3

Views: 419

Answers (1)

Noitidart
Noitidart

Reputation: 37238

I'm almost dont, I'm just stuck on figuring out how to use the asynchronus zip.js module. You can use nsIZipWriter and nsIZipReader like the linked addon does from my comment. But I think async is just better so I'm working on that:

https://github.com/Noitidart/AysncZip/blob/master/bootstrap.js

Install the addon, click on the toolbar icon, download the zip. Clicking zipped will save it a a zipped file. Clicking "Decompressed" is currently a work in progress.

Using XPCOM for zips:

Upvotes: 1

Related Questions