getBinaryContent(path, callback)

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.
callback function the callback function.

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 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});
});