options.base64 in generate() (the base64 type is still valid)options.base64, options.binary, options.dir, options.date on ZipObject (see the 2.3 upgrade section)JSZip.utilsJSZip.prototype.crc32, JSZip.prototype.utf8encode, JSZip.prototype.utf8decodeJSZip.base64 (you can get the content of a file directly as a base64 string)JSZip.compressions has been removed.ZipObject, the synchronous getters has been replaced by async() and nodeStream().generate() method has been replaced by generateAsync() and generateNodeStream().type option in generate() is now mandatory.load() method and the constructor with data (new JSZip(data)) have been replaced by loadAsync().createFolders now defaults to true. If you don't want to create sub folders, set it to false.zip.generateAsync() and zip.generateNodeStream() now depend on the current folder level.// 2.x zip.file("test.txt").asText(); // 3.x zip.file("test.txt").async("string") .then(function (content) { // use content }); // 2.x zip.generate(); // 3.x zip.generateAsync({type:"uint8array"}) .then(function (content) { // use content }); // 2.x new JSZip(data); zip.load(data); // zip.file(...) // 3.x JSZip.loadAsync(data).then(zip) {...}; zip.loadAsync(data).then(zip) {...}; // here, zip won't have (yet) the updated content // 2.x var data = zip.file("img.jpg").asBinary(); var dataURI = "data:image/jpeg;base64," + JSZip.base64.encode(data); // 3.x zip.file("img.jpg").async("base64") .then(function (data64) { var dataURI = "data:image/jpeg;base64," + data64; });
async and loadAsync use (a polyfill of) promises, you can find the documentation here and a tutorial here.
It is worth noting that:
/* * JSZip accepts these promise as input */ // replace a content with JSZip v2 var content = zip.file("my_file").asText(); content = content.replace(/apples/, 'oranges'); zip.file("my_file", content); // replace a content with JSZip v3 var contentPromise = zip.file("my_file").async("text").then(function (content) { return content.replace(/apples/, 'oranges'); }); zip.file("my_file", contentPromise); /* * Promises are chainable */ // read, update, generate a zip file with JSZip v2 var zip = new JSZip(content); zip.file("new_file", "new_content"); var blob = zip.generate({type: "blob"}); saveAs(blob, "result.zip"); // read, update, generate a zip file with JSZip v3 JSZip.loadAsync(content) .then(function (zip) { zip.file("new_file", "new_content"); // if you return the zip object, it will be available in the next "then" return zip; .then(function (zip) { // if you return a promise of a blob, promises will "merge": the current // promise will wait for the other and the next "then" will get the // blob return zip.generateAsync({type: "blob"}); .then(function (blob) { saveAs(blob, "result.zip"); });
ZipObject#options, the attributes date and dir have been deprecated and are now on ZipObject.ZipObject#options, the attributes base64 and binary have been deprecated.JSZip.base64, JSZip.prototype.crc32, JSZip.prototype.utf8decode, JSZip.prototype.utf8encode and JSZip.utils have been deprecated.// deprecated zip.file("test.txt").options.date zip.file("test.txt").options.dir // new API zip.file("test.txt").date zip.file("test.txt").dir
JSZipBase64 has been renamed to JSZip.base64.data attribute doesn't exist anymore : use the getters asText(), asBinary(), etccompressInputType and uncompressInputType attributes.Example for the data attribute :
// before zip.file("test.txt").data; zip.files["test.txt"].data; zip.file("image.png").data; zip.files["image.png"].data; // after zip.file("test.txt").asText(); zip.files["test.txt"].asText(); zip.file("image.png").asBinary(); zip.files["image.png"].asBinary();