Description : Use an AJAX call to fetch a file (HTTP GET) on the server that served the file. Cross domain requests will work if the browser support them but only if the server send the right headers. This function doesn’t follow redirects: currently only 200 OK are accepted.

Arguments

name type description
path String the path to the resource to GET.
options function or object A callback function or options object.

The options object has a required callback function property and an optional progress function property.

The callback function has the following signature: function (err, data) {...} :

name type description
err Error the error, if any.
data ArrayBuffer/String the data in a format suitable for JSZip.

The progress function has the following signature: function (event) {...}, where event has the following properties:

name type description
path string The path of the file being loaded.
loaded number the amount of data currently transfered.
total number the total amount of data to be transferred.
percent number the percent of data currently transfered.

The data can be parsed by JSZip#load or used with JSZip#file to add a new file. With JSZip#file use {binary:true} as options.

Returns : Nothing.

Throws : Nothing.

Example

// loading a zip file
JSZipUtils.getBinaryContent("path/to/file.zip", function (err, data) {
   if(err) {
      throw err; // or handle the error
   }
   var zip = new JSZip(data);
});

// loading a file and add it in a zip file
JSZipUtils.getBinaryContent("path/to/picture.png", function (err, data) {
   if(err) {
      throw err; // or handle the error
   }
   var zip = new JSZip();
   zip.file("picture.png", data, {binary:true});
});

// loading a zip file with a progress callback
JSZipUtils.getBinaryContent("path/to/file.zip", {
    progress: function (event) {
        console.log(event.percent + "% of " + event.path+ " loaded")
    },
    callback: function (err, data) {
        if(err) {
           throw err; // or handle the error
        }
        var zip = new JSZip(data);
    }
});