1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474 |
- var JSZip = function(data, options) {
-
-
-
-
-
- this.files = {};
-
- this.root = "";
- if (data) {
- this.load(data, options);
- }
- };
- JSZip.signature = {
- LOCAL_FILE_HEADER : "\x50\x4b\x03\x04",
- CENTRAL_FILE_HEADER : "\x50\x4b\x01\x02",
- CENTRAL_DIRECTORY_END : "\x50\x4b\x05\x06",
- ZIP64_CENTRAL_DIRECTORY_LOCATOR : "\x50\x4b\x06\x07",
- ZIP64_CENTRAL_DIRECTORY_END : "\x50\x4b\x06\x06",
- DATA_DESCRIPTOR : "\x50\x4b\x07\x08"
- };
- JSZip.defaults = {
- base64: false,
- binary: false,
- dir: false,
- date: null,
- compression: null
- };
- JSZip.support = {
-
- arraybuffer : (function(){
- return typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";
- })(),
-
- nodebuffer : (function(){
- return typeof Buffer !== "undefined";
- })(),
-
- uint8array : (function(){
- return typeof Uint8Array !== "undefined";
- })(),
-
- blob : (function(){
-
-
-
-
-
-
-
- if (typeof ArrayBuffer === "undefined") {
- return false;
- }
- var buffer = new ArrayBuffer(0);
- try {
- return new Blob([buffer], { type: "application/zip" }).size === 0;
- }
- catch(e) {}
- try {
- var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
- var builder = new BlobBuilder();
- builder.append(buffer);
- return builder.getBlob('application/zip').size === 0;
- }
- catch(e) {}
- return false;
- })()
- };
- JSZip.prototype = (function () {
- var textEncoder, textDecoder;
- if (
- JSZip.support.uint8array &&
- typeof TextEncoder === "function" &&
- typeof TextDecoder === "function"
- ) {
- textEncoder = new TextEncoder("utf-8");
- textDecoder = new TextDecoder("utf-8");
- }
-
- var getRawData = function (file) {
- if (file._data instanceof JSZip.CompressedObject) {
- file._data = file._data.getContent();
- file.options.binary = true;
- file.options.base64 = false;
- if (JSZip.utils.getTypeOf(file._data) === "uint8array") {
- var copy = file._data;
-
-
- file._data = new Uint8Array(copy.length);
-
- if (copy.length !== 0) {
- file._data.set(copy, 0);
- }
- }
- }
- return file._data;
- };
-
- var getBinaryData = function (file) {
- var result = getRawData(file), type = JSZip.utils.getTypeOf(result);
- if (type === "string") {
- if (!file.options.binary) {
-
-
- if (textEncoder) {
- return textEncoder.encode(result);
- }
- if (JSZip.support.nodebuffer) {
- return new Buffer(result, "utf-8");
- }
- }
- return file.asBinary();
- }
- return result;
- };
-
- var dataToString = function (asUTF8) {
- var result = getRawData(this);
- if (result === null || typeof result === "undefined") {
- return "";
- }
-
- if (this.options.base64) {
- result = JSZip.base64.decode(result);
- }
- if (asUTF8 && this.options.binary) {
-
-
- result = JSZip.prototype.utf8decode(result);
- } else {
-
- result = JSZip.utils.transformTo("string", result);
- }
- if (!asUTF8 && !this.options.binary) {
- result = JSZip.prototype.utf8encode(result);
- }
- return result;
- };
-
- var ZipObject = function (name, data, options) {
- this.name = name;
- this._data = data;
- this.options = options;
- };
- ZipObject.prototype = {
-
- asText : function () {
- return dataToString.call(this, true);
- },
-
- asBinary : function () {
- return dataToString.call(this, false);
- },
-
- asNodeBuffer : function () {
- var result = getBinaryData(this);
- return JSZip.utils.transformTo("nodebuffer", result);
- },
-
- asUint8Array : function () {
- var result = getBinaryData(this);
- return JSZip.utils.transformTo("uint8array", result);
- },
-
- asArrayBuffer : function () {
- return this.asUint8Array().buffer;
- }
- };
-
- var decToHex = function(dec, bytes) {
- var hex = "", i;
- for(i = 0; i < bytes; i++) {
- hex += String.fromCharCode(dec&0xff);
- dec=dec>>>8;
- }
- return hex;
- };
-
- var extend = function () {
- var result = {}, i, attr;
- for (i = 0; i < arguments.length; i++) {
- for (attr in arguments[i]) {
- if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") {
- result[attr] = arguments[i][attr];
- }
- }
- }
- return result;
- };
-
- var prepareFileAttrs = function (o) {
- o = o || {};
-
- if (o.base64 === true && o.binary == null) {
- o.binary = true;
- }
-
- o = extend(o, JSZip.defaults);
- o.date = o.date || new Date();
- if (o.compression !== null) o.compression = o.compression.toUpperCase();
- return o;
- };
-
- var fileAdd = function (name, data, o) {
-
- var parent = parentFolder(name), dataType = JSZip.utils.getTypeOf(data);
- if (parent) {
- folderAdd.call(this, parent);
- }
- o = prepareFileAttrs(o);
- if (o.dir || data === null || typeof data === "undefined") {
- o.base64 = false;
- o.binary = false;
- data = null;
- } else if (dataType === "string") {
- if (o.binary && !o.base64) {
-
- if (o.optimizedBinaryString !== true) {
-
-
- data = JSZip.utils.string2binary(data);
- }
- }
- } else {
- o.base64 = false;
- o.binary = true;
- if (!dataType && !(data instanceof JSZip.CompressedObject)) {
- throw new Error("The data of '" + name + "' is in an unsupported format !");
- }
-
- if (dataType === "arraybuffer") {
- data = JSZip.utils.transformTo("uint8array", data);
- }
- }
- var object = new ZipObject(name, data, o);
- this.files[name] = object;
- return object;
- };
-
- var parentFolder = function (path) {
- if (path.slice(-1) == '/') {
- path = path.substring(0, path.length - 1);
- }
- var lastSlash = path.lastIndexOf('/');
- return (lastSlash > 0) ? path.substring(0, lastSlash) : "";
- };
-
- var folderAdd = function (name) {
-
- if (name.slice(-1) != "/") {
- name += "/";
- }
-
- if (!this.files[name]) {
- fileAdd.call(this, name, null, {dir:true});
- }
- return this.files[name];
- };
-
- var generateCompressedObjectFrom = function (file, compression) {
- var result = new JSZip.CompressedObject(), content;
-
- if (file._data instanceof JSZip.CompressedObject) {
- result.uncompressedSize = file._data.uncompressedSize;
- result.crc32 = file._data.crc32;
- if (result.uncompressedSize === 0 || file.options.dir) {
- compression = JSZip.compressions['STORE'];
- result.compressedContent = "";
- result.crc32 = 0;
- } else if (file._data.compressionMethod === compression.magic) {
- result.compressedContent = file._data.getCompressedContent();
- } else {
- content = file._data.getContent();
-
- result.compressedContent = compression.compress(JSZip.utils.transformTo(compression.compressInputType, content));
- }
- } else {
-
- content = getBinaryData(file);
- if (!content || content.length === 0 || file.options.dir) {
- compression = JSZip.compressions['STORE'];
- content = "";
- }
- result.uncompressedSize = content.length;
- result.crc32 = this.crc32(content);
- result.compressedContent = compression.compress(JSZip.utils.transformTo(compression.compressInputType, content));
- }
- result.compressedSize = result.compressedContent.length;
- result.compressionMethod = compression.magic;
- return result;
- };
-
- var generateZipParts = function(name, file, compressedObject, offset) {
- var data = compressedObject.compressedContent,
- utfEncodedFileName = this.utf8encode(file.name),
- useUTF8 = utfEncodedFileName !== file.name,
- o = file.options,
- dosTime,
- dosDate;
-
-
-
-
- dosTime = o.date.getHours();
- dosTime = dosTime << 6;
- dosTime = dosTime | o.date.getMinutes();
- dosTime = dosTime << 5;
- dosTime = dosTime | o.date.getSeconds() / 2;
- dosDate = o.date.getFullYear() - 1980;
- dosDate = dosDate << 4;
- dosDate = dosDate | (o.date.getMonth() + 1);
- dosDate = dosDate << 5;
- dosDate = dosDate | o.date.getDate();
- var header = "";
-
- header += "\x0A\x00";
-
-
- header += useUTF8 ? "\x00\x08" : "\x00\x00";
-
- header += compressedObject.compressionMethod;
-
- header += decToHex(dosTime, 2);
-
- header += decToHex(dosDate, 2);
-
- header += decToHex(compressedObject.crc32, 4);
-
- header += decToHex(compressedObject.compressedSize, 4);
-
- header += decToHex(compressedObject.uncompressedSize, 4);
-
- header += decToHex(utfEncodedFileName.length, 2);
-
- header += "\x00\x00";
- var fileRecord = JSZip.signature.LOCAL_FILE_HEADER + header + utfEncodedFileName;
- var dirRecord = JSZip.signature.CENTRAL_FILE_HEADER +
-
- "\x14\x00" +
-
- header +
-
- "\x00\x00" +
-
- "\x00\x00" +
-
- "\x00\x00" +
-
- (file.options.dir===true?"\x10\x00\x00\x00":"\x00\x00\x00\x00")+
-
- decToHex(offset, 4) +
-
- utfEncodedFileName;
- return {
- fileRecord : fileRecord,
- dirRecord : dirRecord,
- compressedObject : compressedObject
- };
- };
-
- var StringWriter = function () {
- this.data = [];
- };
- StringWriter.prototype = {
-
- append : function (input) {
- input = JSZip.utils.transformTo("string", input);
- this.data.push(input);
- },
-
- finalize : function () {
- return this.data.join("");
- }
- };
-
- var Uint8ArrayWriter = function (length) {
- this.data = new Uint8Array(length);
- this.index = 0;
- };
- Uint8ArrayWriter.prototype = {
-
- append : function (input) {
- if (input.length !== 0) {
-
- input = JSZip.utils.transformTo("uint8array", input);
- this.data.set(input, this.index);
- this.index += input.length;
- }
- },
-
- finalize : function () {
- return this.data;
- }
- };
-
- return {
-
- load : function (stream, options) {
- throw new Error("Load method is not defined. Is the file jszip-load.js included ?");
- },
-
- filter : function (search) {
- var result = [], filename, relativePath, file, fileClone;
- for (filename in this.files) {
- if ( !this.files.hasOwnProperty(filename) ) { continue; }
- file = this.files[filename];
-
- fileClone = new ZipObject(file.name, file._data, extend(file.options));
- relativePath = filename.slice(this.root.length, filename.length);
- if (filename.slice(0, this.root.length) === this.root &&
- search(relativePath, fileClone)) {
- result.push(fileClone);
- }
- }
- return result;
- },
-
- file : function(name, data, o) {
- if (arguments.length === 1) {
- if (JSZip.utils.isRegExp(name)) {
- var regexp = name;
- return this.filter(function(relativePath, file) {
- return !file.options.dir && regexp.test(relativePath);
- });
- } else {
- return this.filter(function (relativePath, file) {
- return !file.options.dir && relativePath === name;
- })[0]||null;
- }
- } else {
- name = this.root+name;
- fileAdd.call(this, name, data, o);
- }
- return this;
- },
-
- folder : function(arg) {
- if (!arg) {
- return this;
- }
- if (JSZip.utils.isRegExp(arg)) {
- return this.filter(function(relativePath, file) {
- return file.options.dir && arg.test(relativePath);
- });
- }
-
- var name = this.root + arg;
- var newFolder = folderAdd.call(this, name);
-
- var ret = this.clone();
- ret.root = newFolder.name;
- return ret;
- },
-
- remove : function(name) {
- name = this.root + name;
- var file = this.files[name];
- if (!file) {
-
- if (name.slice(-1) != "/") {
- name += "/";
- }
- file = this.files[name];
- }
- if (file) {
- if (!file.options.dir) {
-
- delete this.files[name];
- } else {
-
- var kids = this.filter(function (relativePath, file) {
- return file.name.slice(0, name.length) === name;
- });
- for (var i = 0; i < kids.length; i++) {
- delete this.files[kids[i].name];
- }
- }
- }
- return this;
- },
-
- generate : function(options) {
- options = extend(options || {}, {
- base64 : true,
- compression : "STORE",
- type : "base64"
- });
- JSZip.utils.checkSupport(options.type);
- var zipData = [], localDirLength = 0, centralDirLength = 0, writer, i;
-
- for (var name in this.files) {
- if ( !this.files.hasOwnProperty(name) ) { continue; }
- var file = this.files[name];
- var compressionName = file.options.compression || options.compression.toUpperCase();
- var compression = JSZip.compressions[compressionName];
- if (!compression) {
- throw new Error(compressionName + " is not a valid compression method !");
- }
- var compressedObject = generateCompressedObjectFrom.call(this, file, compression);
- var zipPart = generateZipParts.call(this, name, file, compressedObject, localDirLength);
- localDirLength += zipPart.fileRecord.length + compressedObject.compressedSize;
- centralDirLength += zipPart.dirRecord.length;
- zipData.push(zipPart);
- }
- var dirEnd = "";
-
- dirEnd = JSZip.signature.CENTRAL_DIRECTORY_END +
-
- "\x00\x00" +
-
- "\x00\x00" +
-
- decToHex(zipData.length, 2) +
-
- decToHex(zipData.length, 2) +
-
- decToHex(centralDirLength, 4) +
-
- decToHex(localDirLength, 4) +
-
- "\x00\x00";
-
-
- switch(options.type.toLowerCase()) {
- case "uint8array" :
- case "arraybuffer" :
- case "blob" :
- case "nodebuffer" :
- writer = new Uint8ArrayWriter(localDirLength + centralDirLength + dirEnd.length);
- break;
-
-
- default :
- writer = new StringWriter(localDirLength + centralDirLength + dirEnd.length);
- break;
- }
- for (i = 0; i < zipData.length; i++) {
- writer.append(zipData[i].fileRecord);
- writer.append(zipData[i].compressedObject.compressedContent);
- }
- for (i = 0; i < zipData.length; i++) {
- writer.append(zipData[i].dirRecord);
- }
- writer.append(dirEnd);
- var zip = writer.finalize();
- switch(options.type.toLowerCase()) {
-
- case "uint8array" :
- case "arraybuffer" :
- case "nodebuffer" :
- return JSZip.utils.transformTo(options.type.toLowerCase(), zip);
- case "blob" :
- return JSZip.utils.arrayBuffer2Blob(JSZip.utils.transformTo("arraybuffer", zip));
-
- case "base64" :
- return (options.base64) ? JSZip.base64.encode(zip) : zip;
- default :
- return zip;
- }
- },
-
- crc32 : function crc32(input, crc) {
- if (typeof input === "undefined" || !input.length) {
- return 0;
- }
- var isArray = JSZip.utils.getTypeOf(input) !== "string";
- var table = [
- 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
- 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
- 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
- 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
- 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
- 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
- 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
- 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
- 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
- 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
- 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
- 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
- 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
- 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
- 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
- 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
- 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
- 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
- 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
- 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
- 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
- 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
- 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
- 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
- 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
- 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
- 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
- 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
- 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
- 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
- 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
- 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
- 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
- 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
- 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
- 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
- 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
- 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
- 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
- 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
- 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
- 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
- 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
- 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
- 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
- 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
- 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
- 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
- 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
- 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
- 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
- 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
- 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
- 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
- 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
- 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
- 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
- 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
- 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
- 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
- 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
- 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
- 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
- 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
- ];
- if (typeof(crc) == "undefined") { crc = 0; }
- var x = 0;
- var y = 0;
- var byte = 0;
- crc = crc ^ (-1);
- for( var i = 0, iTop = input.length; i < iTop; i++ ) {
- byte = isArray ? input[i] : input.charCodeAt(i);
- y = ( crc ^ byte ) & 0xFF;
- x = table[y];
- crc = ( crc >>> 8 ) ^ x;
- }
- return crc ^ (-1);
- },
-
- clone : function() {
- var newObj = new JSZip();
- for (var i in this) {
- if (typeof this[i] !== "function") {
- newObj[i] = this[i];
- }
- }
- return newObj;
- },
-
- utf8encode : function (string) {
-
-
-
- if (textEncoder) {
- var u8 = textEncoder.encode(string);
- return JSZip.utils.transformTo("string", u8);
- }
- if (JSZip.support.nodebuffer) {
- return JSZip.utils.transformTo("string", new Buffer(string, "utf-8"));
- }
-
-
- var result = [], resIndex = 0;
- for (var n = 0; n < string.length; n++) {
- var c = string.charCodeAt(n);
- if (c < 128) {
- result[resIndex++] = String.fromCharCode(c);
- } else if ((c > 127) && (c < 2048)) {
- result[resIndex++] = String.fromCharCode((c >> 6) | 192);
- result[resIndex++] = String.fromCharCode((c & 63) | 128);
- } else {
- result[resIndex++] = String.fromCharCode((c >> 12) | 224);
- result[resIndex++] = String.fromCharCode(((c >> 6) & 63) | 128);
- result[resIndex++] = String.fromCharCode((c & 63) | 128);
- }
- }
- return result.join("");
- },
-
- utf8decode : function (input) {
- var result = [], resIndex = 0;
- var type = JSZip.utils.getTypeOf(input);
- var isArray = type !== "string";
- var i = 0;
- var c = 0, c1 = 0, c2 = 0, c3 = 0;
-
-
- if (textDecoder) {
- return textDecoder.decode(
- JSZip.utils.transformTo("uint8array", input)
- );
- }
- if (JSZip.support.nodebuffer) {
- return JSZip.utils.transformTo("nodebuffer", input).toString("utf-8");
- }
- while ( i < input.length ) {
- c = isArray ? input[i] : input.charCodeAt(i);
- if (c < 128) {
- result[resIndex++] = String.fromCharCode(c);
- i++;
- } else if ((c > 191) && (c < 224)) {
- c2 = isArray ? input[i+1] : input.charCodeAt(i+1);
- result[resIndex++] = String.fromCharCode(((c & 31) << 6) | (c2 & 63));
- i += 2;
- } else {
- c2 = isArray ? input[i+1] : input.charCodeAt(i+1);
- c3 = isArray ? input[i+2] : input.charCodeAt(i+2);
- result[resIndex++] = String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- i += 3;
- }
- }
- return result.join("");
- }
- };
- }());
- JSZip.compressions = {
- "STORE" : {
- magic : "\x00\x00",
- compress : function (content) {
- return content;
- },
- uncompress : function (content) {
- return content;
- },
- compressInputType : null,
- uncompressInputType : null
- }
- };
- (function () {
- JSZip.utils = {
-
- string2binary : function (str) {
- var result = "";
- for (var i = 0; i < str.length; i++) {
- result += String.fromCharCode(str.charCodeAt(i) & 0xff);
- }
- return result;
- },
-
- string2Uint8Array : function (str) {
- return JSZip.utils.transformTo("uint8array", str);
- },
-
- uint8Array2String : function (array) {
- return JSZip.utils.transformTo("string", array);
- },
-
- arrayBuffer2Blob : function (buffer) {
- JSZip.utils.checkSupport("blob");
- try {
-
- return new Blob([buffer], { type: "application/zip" });
- }
- catch(e) {}
- try {
-
- var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
- var builder = new BlobBuilder();
- builder.append(buffer);
- return builder.getBlob('application/zip');
- }
- catch(e) {}
-
- throw new Error("Bug : can't construct the Blob.");
- },
-
- string2Blob : function (str) {
- var buffer = JSZip.utils.transformTo("arraybuffer", str);
- return JSZip.utils.arrayBuffer2Blob(buffer);
- }
- };
-
- function identity(input) {
- return input;
- }
-
- function stringToArrayLike(str, array) {
- for (var i = 0; i < str.length; ++i) {
- array[i] = str.charCodeAt(i) & 0xFF;
- }
- return array;
- }
-
- function arrayLikeToString(array) {
-
-
-
-
-
-
-
-
-
- var chunk = 65536;
- var result = [], len = array.length, type = JSZip.utils.getTypeOf(array), k = 0;
- var canUseApply = true;
- try {
- switch(type) {
- case "uint8array":
- String.fromCharCode.apply(null, new Uint8Array(0));
- break;
- case "nodebuffer":
- String.fromCharCode.apply(null, new Buffer(0));
- break;
- }
- } catch(e) {
- canUseApply = false;
- }
-
-
- if (!canUseApply) {
- var resultStr = "";
- for(var i = 0; i < array.length;i++) {
- resultStr += String.fromCharCode(array[i]);
- }
- return resultStr;
- }
- while (k < len && chunk > 1) {
- try {
- if (type === "array" || type === "nodebuffer") {
- result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));
- } else {
- result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));
- }
- k += chunk;
- } catch (e) {
- chunk = Math.floor(chunk / 2);
- }
- }
- return result.join("");
- }
-
- function arrayLikeToArrayLike(arrayFrom, arrayTo) {
- for(var i = 0; i < arrayFrom.length; i++) {
- arrayTo[i] = arrayFrom[i];
- }
- return arrayTo;
- }
-
- var transform = {};
-
- transform["string"] = {
- "string" : identity,
- "array" : function (input) {
- return stringToArrayLike(input, new Array(input.length));
- },
- "arraybuffer" : function (input) {
- return transform["string"]["uint8array"](input).buffer;
- },
- "uint8array" : function (input) {
- return stringToArrayLike(input, new Uint8Array(input.length));
- },
- "nodebuffer" : function (input) {
- return stringToArrayLike(input, new Buffer(input.length));
- }
- };
-
- transform["array"] = {
- "string" : arrayLikeToString,
- "array" : identity,
- "arraybuffer" : function (input) {
- return (new Uint8Array(input)).buffer;
- },
- "uint8array" : function (input) {
- return new Uint8Array(input);
- },
- "nodebuffer" : function (input) {
- return new Buffer(input);
- }
- };
-
- transform["arraybuffer"] = {
- "string" : function (input) {
- return arrayLikeToString(new Uint8Array(input));
- },
- "array" : function (input) {
- return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));
- },
- "arraybuffer" : identity,
- "uint8array" : function (input) {
- return new Uint8Array(input);
- },
- "nodebuffer" : function (input) {
- return new Buffer(new Uint8Array(input));
- }
- };
-
- transform["uint8array"] = {
- "string" : arrayLikeToString,
- "array" : function (input) {
- return arrayLikeToArrayLike(input, new Array(input.length));
- },
- "arraybuffer" : function (input) {
- return input.buffer;
- },
- "uint8array" : identity,
- "nodebuffer" : function(input) {
- return new Buffer(input);
- }
- };
-
- transform["nodebuffer"] = {
- "string" : arrayLikeToString,
- "array" : function (input) {
- return arrayLikeToArrayLike(input, new Array(input.length));
- },
- "arraybuffer" : function (input) {
- return transform["nodebuffer"]["uint8array"](input).buffer;
- },
- "uint8array" : function (input) {
- return arrayLikeToArrayLike(input, new Uint8Array(input.length));
- },
- "nodebuffer" : identity
- };
-
- JSZip.utils.transformTo = function (outputType, input) {
- if (!input) {
-
-
- input = "";
- }
- if (!outputType) {
- return input;
- }
- JSZip.utils.checkSupport(outputType);
- var inputType = JSZip.utils.getTypeOf(input);
- var result = transform[inputType][outputType](input);
- return result;
- };
-
- JSZip.utils.getTypeOf = function (input) {
- if (typeof input === "string") {
- return "string";
- }
- if (Object.prototype.toString.call(input) === "[object Array]") {
- return "array";
- }
- if (JSZip.support.nodebuffer && Buffer.isBuffer(input)) {
- return "nodebuffer";
- }
- if (JSZip.support.uint8array && input instanceof Uint8Array) {
- return "uint8array";
- }
- if (JSZip.support.arraybuffer && input instanceof ArrayBuffer) {
- return "arraybuffer";
- }
- };
-
- JSZip.utils.isRegExp = function (object) {
- return Object.prototype.toString.call(object) === "[object RegExp]";
- };
-
- JSZip.utils.checkSupport = function (type) {
- var supported = true;
- switch (type.toLowerCase()) {
- case "uint8array":
- supported = JSZip.support.uint8array;
- break;
- case "arraybuffer":
- supported = JSZip.support.arraybuffer;
- break;
- case "nodebuffer":
- supported = JSZip.support.nodebuffer;
- break;
- case "blob":
- supported = JSZip.support.blob;
- break;
- }
- if (!supported) {
- throw new Error(type + " is not supported by this browser");
- }
- };
- })();
- (function (){
-
- JSZip.CompressedObject = function () {
- this.compressedSize = 0;
- this.uncompressedSize = 0;
- this.crc32 = 0;
- this.compressionMethod = null;
- this.compressedContent = null;
- };
- JSZip.CompressedObject.prototype = {
-
- getContent : function () {
- return null;
- },
-
- getCompressedContent : function () {
- return null;
- }
- };
- })();
- JSZip.base64 = (function() {
-
- var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
- return {
-
- encode : function(input, utf8) {
- var output = "";
- var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
- var i = 0;
- while (i < input.length) {
- chr1 = input.charCodeAt(i++);
- chr2 = input.charCodeAt(i++);
- chr3 = input.charCodeAt(i++);
- enc1 = chr1 >> 2;
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
- enc4 = chr3 & 63;
- if (isNaN(chr2)) {
- enc3 = enc4 = 64;
- } else if (isNaN(chr3)) {
- enc4 = 64;
- }
- output = output +
- _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
- _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
- }
- return output;
- },
-
- decode : function(input, utf8) {
- var output = "";
- var chr1, chr2, chr3;
- var enc1, enc2, enc3, enc4;
- var i = 0;
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
- while (i < input.length) {
- enc1 = _keyStr.indexOf(input.charAt(i++));
- enc2 = _keyStr.indexOf(input.charAt(i++));
- enc3 = _keyStr.indexOf(input.charAt(i++));
- enc4 = _keyStr.indexOf(input.charAt(i++));
- chr1 = (enc1 << 2) | (enc2 >> 4);
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
- chr3 = ((enc3 & 3) << 6) | enc4;
- output = output + String.fromCharCode(chr1);
- if (enc3 != 64) {
- output = output + String.fromCharCode(chr2);
- }
- if (enc4 != 64) {
- output = output + String.fromCharCode(chr3);
- }
- }
- return output;
- }
- };
- }());
|