"use strict";function checkEntryCRC32(e){return new external.Promise(function(r,t){var i=e.decompressed.getContentWorker().pipe(new Crc32Probe);i.on("error",function(e){t(e)}).on("end",function(){i.streamInfo.crc32!==e.decompressed.crc32?t(new Error("Corrupted zip : CRC32 mismatch")):r()}).resume()})}var utils=require("./utils"),external=require("./external"),utf8=require("./utf8"),utils=require("./utils"),ZipEntries=require("./zipEntries"),Crc32Probe=require("./stream/Crc32Probe"),nodejsUtils=require("./nodejsUtils");module.exports=function(e,r){var t=this;return r=utils.extend(r||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:utf8.utf8decode}),nodejsUtils.isNode&&nodejsUtils.isStream(e)?external.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):utils.prepareContent("the loaded zip file",e,!0,r.optimizedBinaryString,r.base64).then(function(e){var t=new ZipEntries(r);return t.load(e),t}).then(function(e){var t=[external.Promise.resolve(e)],i=e.files;if(r.checkCRC32)for(var n=0;n<i.length;n++)t.push(checkEntryCRC32(i[n]));return external.Promise.all(t)}).then(function(e){for(var i=e.shift(),n=i.files,s=0;s<n.length;s++){var o=n[s];t.file(o.fileNameStr,o.decompressed,{binary:!0,optimizedBinaryString:!0,date:o.date,dir:o.dir,comment:o.fileCommentStr.length?o.fileCommentStr:null,unixPermissions:o.unixPermissions,dosPermissions:o.dosPermissions,createFolders:r.createFolders})}return i.zipComment.length&&(t.comment=i.zipComment),t})};