@syncfusion/ej2-compression
Advanced tools
Comparing version 15.4.17 to 15.4.20
/*! | ||
* filename: ej2-compression.umd.min.js | ||
* version : 15.4.17 | ||
* version : 15.4.20 | ||
* Copyright Syncfusion Inc. 2001 - 2017. All rights reserved. | ||
@@ -11,3 +11,3 @@ * Use of this code is subject to the terms of our license. | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@syncfusion/ej2-file-utils"));else if("function"==typeof define&&define.amd)define(["@syncfusion/ej2-file-utils"],e);else{var i=e("object"==typeof exports?require("@syncfusion/ej2-file-utils"):t["@syncfusion/ej2-file-utils"]);for(var r in i)("object"==typeof exports?exports:t)[r]=i[r]}}(this,function(t){return function(t){function e(r){if(i[r])return i[r].exports;var n=i[r]={exports:{},id:r,loaded:!1};return t[r].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){var r,n;r=[i,e,i(1),i(2)],void 0!==(n=function(t,e,i,r){"use strict";function n(t){for(var i in t)e.hasOwnProperty(i)||(e[i]=t[i])}Object.defineProperty(e,"__esModule",{value:!0}),n(i),n(r)}.apply(e,r))&&(t.exports=n)},function(t,e,i){var r,n;r=[i,e,i(2),i(3)],void 0!==(n=function(t,e,i,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=[],s=function(){function t(){this.files=[],this.level="Normal",r.Save.isMicrosoftBrowser=!!navigator.msSaveBlob}return Object.defineProperty(t.prototype,"compressionLevel",{get:function(){return this.level},set:function(t){this.level=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return void 0===this.files?0:this.files.length},enumerable:!0,configurable:!0}),t.prototype.addItem=function(t){if(null===t||void 0===t)throw new Error("ArgumentException: item cannot be null or undefined");for(var e=0;e<this.files.length;e++){var i=this.files[e];if(i instanceof h&&i.name===t.name)throw new Error("item with same name already exist")}this.files.push(t)},t.prototype.addDirectory=function(t){if(null===t||void 0===t)throw new Error("ArgumentException: string cannot be null or undefined");if(0===t.length)throw new Error("ArgumentException: string cannot be empty");if("/"!==t.slice(-1)&&(t+="/"),-1!==this.files.indexOf(t))throw new Error("item with same name already exist");this.files.push(t)},t.prototype.getItem=function(t){if(t>=0&&t<this.files.length)return this.files[t]},t.prototype.contains=function(t){return-1!==this.files.indexOf(t)},t.prototype.save=function(t){var e=this;if(null===t||void 0===t||0===t.length)throw new Error("ArgumentException: fileName cannot be null or undefined");if(0===this.files.length)throw new Error("InvalidOperation");var i=this;return new Promise(function(r,n){for(var s=[],h=0,o=0;o<e.files.length;o++){e.getCompressedData(e.files[o]).then(function(n){h=i.constructZippedObject(s,n,h,n.isDirectory),s.length===e.files.length&&(i.writeZippedContent(t,s,h),r(i))})}})},t.prototype.destroy=function(){if(void 0!==this.files&&this.files.length>0){for(var t=0;t<this.files.length;t++){var e=this.files[t];e instanceof h&&e.destroy(),e=void 0}this.files=[]}this.files=void 0,this.level=void 0},t.prototype.getCompressedData=function(t){var e=this;return new Promise(function(i,r){if(t instanceof h){var s=new FileReader;s.onload=function(){var r=new Uint8Array(s.result),h={fileName:t.name,crc32Value:0,compressedData:[],compressedSize:void 0,uncompressedDataSize:r.length,compressionType:void 0,isDirectory:!1};if("Normal"===e.level){e.compressData(r,h,n);for(var o=0,a=0;a<h.compressedData.length;a++)o+=h.compressedData[a].length;h.compressedSize=o,h.compressionType="\b\0"}else h.compressedSize=r.length,h.crc32Value=e.calculateCrc32Value(0,r,n),h.compressionType="\0\0",h.compressedData.push(r);i(h)},s.readAsArrayBuffer(t.data)}else{i({fileName:t,crc32Value:0,compressedData:"",compressedSize:0,uncompressedDataSize:0,compressionType:"\0\0",isDirectory:!0})}})},t.prototype.compressData=function(t,e,r){var n=new i.CompressedStreamWriter(!0),s=0,h=0;do{if(s>=t.length){n.close();break}h=Math.min(t.length,s+16384);var o=t.subarray(s,h);e.crc32Value=this.calculateCrc32Value(e.crc32Value,o,r),n.write(o,0,h-s),s=h}while(s<=t.length);e.compressedData=n.compressedData,n.destroy()},t.prototype.constructZippedObject=function(t,e,i,r){var n=0,s=new Date;r&&(n|=16),n|=0;var h=this.writeHeader(e,s),o="PK"+h+e.fileName,a=this.writeCentralDirectory(e,h,i,n);return t.push({localHeader:o,centralDir:a,compressedData:e}),i+o.length+e.compressedSize},t.prototype.writeHeader=function(t,e){var i="";return i+="\n\0\0\0",i+=t.compressionType,i+=this.getBytes(this.getModifiedTime(e),2),i+=this.getBytes(this.getModifiedDate(e),2),i+=this.getBytes(t.crc32Value,4),i+=this.getBytes(t.compressedSize,4),i+=this.getBytes(t.uncompressedDataSize,4),i+=this.getBytes(t.fileName.length,2),i+=this.getBytes(0,2)},t.prototype.writeZippedContent=function(t,e,i){for(var n=0,s=[],h=0;h<e.length;h++){var o=e[h];for(n+=o.centralDir.length,s.push(this.getArrayBuffer(o.localHeader));o.compressedData.compressedData.length;)s.push(o.compressedData.compressedData.shift().buffer)}for(var h=0;h<e.length;h++)s.push(this.getArrayBuffer(e[h].centralDir));s.push(this.getArrayBuffer(this.writeFooter(e,n,i))),r.Save.save(t,new Blob(s,{type:"application/zip"}))},t.prototype.writeCentralDirectory=function(t,e,i,r){return"PK"+this.getBytes(20,2)+e+this.getBytes(0,2)+"\0\0\0\0"+this.getBytes(r,4)+this.getBytes(i,4)+t.fileName},t.prototype.writeFooter=function(t,e,i){return"PK\0\0\0\0"+this.getBytes(t.length,2)+this.getBytes(t.length,2)+this.getBytes(e,4)+this.getBytes(i,4)+this.getBytes(0,2)},t.prototype.getArrayBuffer=function(t){for(var e=new Uint8Array(t.length),i=0;i<t.length;++i)e[i]=255&t.charCodeAt(i);return e.buffer},t.prototype.getBytes=function(t,e){for(var i="",r=0;r<e;r++)i+=String.fromCharCode(255&t),t>>>=8;return i},t.prototype.getModifiedTime=function(t){var e=t.getHours();return e<<=6,e|=t.getMinutes(),e<<=5,e|=t.getSeconds()/2},t.prototype.getModifiedDate=function(t){var e=t.getFullYear()-1980;return e<<=4,e|=t.getMonth()+1,e<<=5,e|=t.getDate()},t.prototype.calculateCrc32Value=function(t,e,i){t^=-1;for(var r=0;r<e.length;r++)t=t>>>8^i[255&(t^e[r])];return-1^t},t}();e.ZipArchive=s;var h=function(){function t(t,e){if(null===t||void 0===t)throw new Error("ArgumentException: data cannot be null or undefined");if(null===e||void 0===e)throw new Error("ArgumentException: string cannot be null or undefined");if(0===e.length)throw new Error("string cannot be empty");this.data=t,this.name=e}return Object.defineProperty(t.prototype,"name",{get:function(){return this.fileName},set:function(t){this.fileName=t},enumerable:!0,configurable:!0}),t.prototype.destroy=function(){this.fileName=void 0,this.data=void 0},t}();e.ZipArchiveItem=h,function(){for(var t,e=0;e<256;e++){t=e;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;n[e]=t}}()}.apply(e,r))&&(t.exports=n)},function(t,e,i){var r,n;r=[i,e,i(3)],void 0!==(n=function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=new Int16Array(286),n=new Uint8Array(286),s=new Int16Array(30),h=new Uint8Array(30),o=function(){function t(t){this.pendingBuffer=new Uint8Array(65536),this.pendingBufLength=0,this.pendingBufCache=0,this.pendingBufBitsInCache=0,this.bufferPosition=0,this.extraBits=0,this.currentHash=0,this.matchStart=0,this.matchLength=0,this.matchPrevAvail=!1,this.blockStart=0,this.stringStart=0,this.lookAhead=0,this.totalBytesIn=0,this.inputOffset=0,this.inputEnd=0,this.windowSize=32768,this.windowMask=this.windowSize-1,this.hashSize=32768,this.hashMask=this.hashSize-1,this.hashShift=Math.floor(17/3),this.maxDist=this.windowSize-262,this.checkSum=1,this.noWrap=!1,this.treeLiteral=new a(this,286,257,15),this.treeDistances=new a(this,30,1,15),this.treeCodeLengths=new a(this,19,4,7),this.arrDistances=new Uint16Array(16384),this.arrLiterals=new Uint8Array(16384),this.stream=[],this.dataWindow=new Uint8Array(2*this.windowSize),this.hashHead=new Int16Array(this.hashSize),this.hashPrevious=new Int16Array(this.windowSize),this.blockStart=this.stringStart=1,this.noWrap=t,t||this.writeZLibHeader()}return Object.defineProperty(t.prototype,"compressedData",{get:function(){return this.stream},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"getCompressedString",{get:function(){var t="";if(void 0!==this.stream)for(var e=0;e<this.stream.length;e++)t+=String.fromCharCode.apply(null,this.stream[e]);return t},enumerable:!0,configurable:!0}),t.prototype.write=function(t,e,r){if(void 0===t||null===t)throw new Error("ArgumentException: data cannot null or undefined");var n=e+r;if(0>e||e>n||n>t.length)throw new Error("ArgumentOutOfRangeException: Offset or length is incorrect");if("string"==typeof t){var s=new i.Encoding(!1);s.type="Utf8",t=new Uint8Array(s.getBytes(t,0,t.length)),n=e+t.length}for(this.inputBuffer=t,this.inputOffset=e,this.inputEnd=n,this.noWrap||(this.checkSum=f.checksumUpdate(this.checkSum,this.inputBuffer,this.inputOffset,n));this.inputEnd!==this.inputOffset||0!==this.pendingBufLength;)this.pendingBufferFlush(),this.compressData(!1)},t.prototype.writeZLibHeader=function(){var t=30720;t|=64,t+=31-t%31,this.pendingBufferWriteShortBytes(t)},t.prototype.pendingBufferWriteShortBytes=function(t){this.pendingBuffer[this.pendingBufLength++]=t>>8,this.pendingBuffer[this.pendingBufLength++]=t},t.prototype.compressData=function(t){var e;do{this.fillWindow();var i=t&&this.inputEnd===this.inputOffset;e=this.compressSlow(i,t)}while(0===this.pendingBufLength&&e);return e},t.prototype.compressSlow=function(t,e){if(this.lookAhead<262&&!t)return!1;for(;this.lookAhead>=262||t;){if(0===this.lookAhead)return this.lookAheadCompleted(e);this.stringStart>=2*this.windowSize-262&&this.slideWindow();var i=this.matchStart,r=this.matchLength;if(this.lookAhead>=3&&this.discardMatch(),r>=3&&this.matchLength<=r?r=this.matchPreviousBest(i,r):this.matchPreviousAvailable(),this.bufferPosition>=16384)return this.huffmanIsFull(e)}return!0},t.prototype.discardMatch=function(){var t=this.insertString();0!==t&&this.stringStart-t<=this.maxDist&&this.findLongestMatch(t)&&this.matchLength<=5&&3===this.matchLength&&this.stringStart-this.matchStart>4096&&(this.matchLength=2)},t.prototype.matchPreviousAvailable=function(){this.matchPrevAvail&&this.huffmanTallyLit(255&this.dataWindow[this.stringStart-1]),this.matchPrevAvail=!0,this.stringStart++,this.lookAhead--},t.prototype.matchPreviousBest=function(t,e){this.huffmanTallyDist(this.stringStart-1-t,e),e-=2;do{this.stringStart++,--this.lookAhead>=3&&this.insertString()}while(--e>0);return this.stringStart++,this.lookAhead--,this.matchPrevAvail=!1,this.matchLength=2,e},t.prototype.lookAheadCompleted=function(t){return this.matchPrevAvail&&this.huffmanTallyLit(255&this.dataWindow[this.stringStart-1]),this.matchPrevAvail=!1,this.huffmanFlushBlock(this.dataWindow,this.blockStart,this.stringStart-this.blockStart,t),this.blockStart=this.stringStart,!1},t.prototype.huffmanIsFull=function(t){var e=this.stringStart-this.blockStart;this.matchPrevAvail&&e--;var i=t&&0===this.lookAhead&&!this.matchPrevAvail;return this.huffmanFlushBlock(this.dataWindow,this.blockStart,e,i),this.blockStart+=e,!i},t.prototype.fillWindow=function(){for(this.stringStart>=this.windowSize+this.maxDist&&this.slideWindow();this.lookAhead<262&&this.inputOffset<this.inputEnd;){var t=2*this.windowSize-this.lookAhead-this.stringStart;t>this.inputEnd-this.inputOffset&&(t=this.inputEnd-this.inputOffset),this.dataWindow.set(this.inputBuffer.subarray(this.inputOffset,this.inputOffset+t),this.stringStart+this.lookAhead),this.inputOffset+=t,this.totalBytesIn+=t,this.lookAhead+=t}this.lookAhead>=3&&this.updateHash()},t.prototype.slideWindow=function(){this.dataWindow.set(this.dataWindow.subarray(this.windowSize,this.windowSize+this.windowSize),0),this.matchStart-=this.windowSize,this.stringStart-=this.windowSize,this.blockStart-=this.windowSize;for(var t=0;t<this.hashSize;++t){var e=65535&this.hashHead[t];this.hashHead[t]=e>=this.windowSize?e-this.windowSize:0}for(var t=0;t<this.windowSize;t++){var e=65535&this.hashPrevious[t];this.hashPrevious[t]=e>=this.windowSize?e-this.windowSize:0}},t.prototype.insertString=function(){var t,e=(this.currentHash<<this.hashShift^this.dataWindow[this.stringStart+2])&this.hashMask;return this.hashPrevious[this.stringStart&this.windowMask]=t=this.hashHead[e],this.hashHead[e]=this.stringStart,this.currentHash=e,65535&t},t.prototype.findLongestMatch=function(t){var e,i=4096,r=258,n=this.stringStart,s=this.stringStart+this.matchLength,h=Math.max(this.matchLength,2),o=Math.max(this.stringStart-this.maxDist,0),a=this.stringStart+258-1,f=this.dataWindow[s-1],u=this.dataWindow[s],d=this.dataWindow;h>=32&&(i>>=2),r>this.lookAhead&&(r=this.lookAhead);do{if(d[t+h]===u&&d[t+h-1]===f&&d[t]===d[n]&&d[t+1]===d[n+1]){for(e=t+2,n+=2;d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&n<a;);if(n>s){if(this.matchStart=t,s=n,(h=n-this.stringStart)>=r)break;f=d[s-1],u=d[s]}n=this.stringStart}}while((t=65535&this.hashPrevious[t&this.windowMask])>o&&0!=--i);return this.matchLength=Math.min(h,this.lookAhead),this.matchLength>=3},t.prototype.updateHash=function(){this.currentHash=this.dataWindow[this.stringStart]<<this.hashShift^this.dataWindow[this.stringStart+1]},t.prototype.huffmanTallyLit=function(t){return this.arrDistances[this.bufferPosition]=0,this.arrLiterals[this.bufferPosition++]=t,this.treeLiteral.codeFrequencies[t]++,this.bufferPosition>=16384},t.prototype.huffmanTallyDist=function(t,e){this.arrDistances[this.bufferPosition]=t,this.arrLiterals[this.bufferPosition++]=e-3;var i=this.huffmanLengthCode(e-3);this.treeLiteral.codeFrequencies[i]++,i>=265&&i<285&&(this.extraBits+=Math.floor((i-261)/4));var r=this.huffmanDistanceCode(t-1);return this.treeDistances.codeFrequencies[r]++,r>=4&&(this.extraBits+=Math.floor(r/2-1)),this.bufferPosition>=16384},t.prototype.huffmanFlushBlock=function(t,e,i,o){this.treeLiteral.codeFrequencies[256]++,this.treeLiteral.buildTree(),this.treeDistances.buildTree(),this.treeLiteral.calculateBLFreq(this.treeCodeLengths),this.treeDistances.calculateBLFreq(this.treeCodeLengths),this.treeCodeLengths.buildTree();for(var f=4,u=18;u>f;u--)this.treeCodeLengths.codeLengths[a.huffCodeLengthOrders[u]]>0&&(f=u+1);for(var d=14+3*f+this.treeCodeLengths.getEncodedLength()+this.treeLiteral.getEncodedLength()+this.treeDistances.getEncodedLength()+this.extraBits,c=this.extraBits,u=0;u<286;u++)c+=this.treeLiteral.codeFrequencies[u]*n[u];for(var u=0;u<30;u++)c+=this.treeDistances.codeFrequencies[u]*h[u];d>=c&&(d=c),e>=0&&i+4<d>>3?this.huffmanFlushStoredBlock(t,e,i,o):d==c?(this.pendingBufferWriteBits(2+(o?1:0),3),this.treeLiteral.setStaticCodes(r,n),this.treeDistances.setStaticCodes(s,h),this.huffmanCompressBlock(),this.huffmanReset()):(this.pendingBufferWriteBits(4+(o?1:0),3),this.huffmanSendAllTrees(f),this.huffmanCompressBlock(),this.huffmanReset())},t.prototype.huffmanFlushStoredBlock=function(t,e,i,r){this.pendingBufferWriteBits(0+(r?1:0),3),this.pendingBufferAlignToByte(),this.pendingBufferWriteShort(i),this.pendingBufferWriteShort(~i),this.pendingBufferWriteByteBlock(t,e,i),this.huffmanReset()},t.prototype.huffmanLengthCode=function(t){if(255===t)return 285;for(var e=257;t>=8;)e+=4,t>>=1;return e+t},t.prototype.huffmanDistanceCode=function(t){for(var e=0;t>=4;)e+=2,t>>=1;return e+t},t.prototype.huffmanSendAllTrees=function(t){this.treeCodeLengths.buildCodes(),this.treeLiteral.buildCodes(),this.treeDistances.buildCodes(),this.pendingBufferWriteBits(this.treeLiteral.treeLength-257,5),this.pendingBufferWriteBits(this.treeDistances.treeLength-1,5),this.pendingBufferWriteBits(t-4,4);for(var e=0;e<t;e++)this.pendingBufferWriteBits(this.treeCodeLengths.codeLengths[a.huffCodeLengthOrders[e]],3);this.treeLiteral.writeTree(this.treeCodeLengths),this.treeDistances.writeTree(this.treeCodeLengths)},t.prototype.huffmanReset=function(){this.bufferPosition=0,this.extraBits=0,this.treeLiteral.reset(),this.treeDistances.reset(),this.treeCodeLengths.reset()},t.prototype.huffmanCompressBlock=function(){for(var t=0;t<this.bufferPosition;t++){var e=255&this.arrLiterals[t],i=this.arrDistances[t];if(0!=i--){var r=this.huffmanLengthCode(e);this.treeLiteral.writeCodeToStream(r);var n=Math.floor((r-261)/4);n>0&&n<=5&&this.pendingBufferWriteBits(e&(1<<n)-1,n);var s=this.huffmanDistanceCode(i);this.treeDistances.writeCodeToStream(s),n=Math.floor(s/2-1),n>0&&this.pendingBufferWriteBits(i&(1<<n)-1,n)}else this.treeLiteral.writeCodeToStream(e)}this.treeLiteral.writeCodeToStream(256)},t.prototype.pendingBufferWriteBits=function(t,e){var i=new Uint32Array(1);i[0]=this.pendingBufCache|t<<this.pendingBufBitsInCache,this.pendingBufCache=i[0],this.pendingBufBitsInCache+=e,this.pendingBufferFlushBits()},t.prototype.pendingBufferFlush=function(t){if(this.pendingBufferFlushBits(),this.pendingBufLength>0){var e=new Uint8Array(this.pendingBufLength);e.set(this.pendingBuffer.subarray(0,this.pendingBufLength),0),this.stream.push(e)}this.pendingBufLength=0},t.prototype.pendingBufferFlushBits=function(){for(var t=0;this.pendingBufBitsInCache>=8&&this.pendingBufLength<65536;)this.pendingBuffer[this.pendingBufLength++]=this.pendingBufCache,this.pendingBufCache>>=8,this.pendingBufBitsInCache-=8,t++;return t},t.prototype.pendingBufferWriteByteBlock=function(t,e,i){var r=t.subarray(e,e+i);this.pendingBuffer.set(r,this.pendingBufLength),this.pendingBufLength+=i},t.prototype.pendingBufferWriteShort=function(t){this.pendingBuffer[this.pendingBufLength++]=t,this.pendingBuffer[this.pendingBufLength++]=t>>8},t.prototype.pendingBufferAlignToByte=function(){this.pendingBufBitsInCache>0&&(this.pendingBuffer[this.pendingBufLength++]=this.pendingBufCache),this.pendingBufCache=0,this.pendingBufBitsInCache=0},t.prototype.close=function(){do{this.pendingBufferFlush(!0),this.compressData(!0)||(this.pendingBufferFlush(!0),this.pendingBufferAlignToByte(),this.noWrap||(this.pendingBufferWriteShortBytes(this.checkSum>>16),this.pendingBufferWriteShortBytes(65535&this.checkSum)),this.pendingBufferFlush(!0))}while(this.inputEnd!==this.inputOffset||0!==this.pendingBufLength)},t.prototype.destroy=function(){this.stream=[],this.stream=void 0,this.pendingBuffer=void 0,this.treeLiteral=void 0,this.treeDistances=void 0,this.treeCodeLengths=void 0,this.arrLiterals=void 0,this.arrDistances=void 0,this.hashHead=void 0,this.hashPrevious=void 0,this.dataWindow=void 0,this.inputBuffer=void 0,this.pendingBufLength=void 0,this.pendingBufCache=void 0,this.pendingBufBitsInCache=void 0,this.bufferPosition=void 0,this.extraBits=void 0,this.currentHash=void 0,this.matchStart=void 0,this.matchLength=void 0,this.matchPrevAvail=void 0,this.blockStart=void 0,this.stringStart=void 0,this.lookAhead=void 0,this.totalBytesIn=void 0,this.inputOffset=void 0,this.inputEnd=void 0,this.windowSize=void 0,this.windowMask=void 0,this.hashSize=void 0,this.hashMask=void 0,this.hashShift=void 0,this.maxDist=void 0,this.checkSum=void 0,this.noWrap=void 0},t}();e.CompressedStreamWriter=o;var a=function(){function t(t,e,i,r){this.writer=t,this.codeMinCount=i,this.maxLength=r,this.codeFrequency=new Int16Array(e),this.lengthCount=new Int32Array(r)}return Object.defineProperty(t.prototype,"treeLength",{get:function(){return this.codeCount},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"codeLengths",{get:function(){return this.codeLength},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"codeFrequencies",{get:function(){return this.codeFrequency},enumerable:!0,configurable:!0}),t.prototype.setStaticCodes=function(t,e){var i=new Int16Array(t.length);i.set(t,0),this.codes=i;var r=new Uint8Array(e.length);r.set(e,0),this.codeLength=r},t.prototype.reset=function(){for(var t=0;t<this.codeFrequency.length;t++)this.codeFrequency[t]=0;this.codes=void 0,this.codeLength=void 0},t.prototype.writeCodeToStream=function(t){this.writer.pendingBufferWriteBits(65535&this.codes[t],this.codeLength[t])},t.prototype.buildCodes=function(){var e=new Int32Array(this.maxLength);this.codes=new Int16Array(this.codeCount);for(var i=0,r=0;r<this.maxLength;r++)e[r]=i,i+=this.lengthCount[r]<<15-r;for(var n=0;n<this.codeCount;n++){var s=this.codeLength[n];s>0&&(this.codes[n]=t.bitReverse(e[s-1]),e[s-1]+=1<<16-s)}},t.bitReverse=function(e){return t.reverseBits[15&e]<<12|t.reverseBits[e>>4&15]<<8|t.reverseBits[e>>8&15]<<4|t.reverseBits[e>>12]},t.prototype.getEncodedLength=function(){for(var t=0,e=0;e<this.codeFrequency.length;e++)t+=this.codeFrequency[e]*this.codeLength[e];return t},t.prototype.calculateBLFreq=function(t){for(var e,i,r,n=-1,s=0;s<this.codeCount;){r=1;var h=this.codeLength[s];for(0===h?(e=138,i=3):(e=6,i=3,n!==h&&(t.codeFrequency[h]++,r=0)),n=h,s++;s<this.codeCount&&n===this.codeLength[s]&&(s++,!(++r>=e)););r<i?t.codeFrequency[n]+=r:0!==n?t.codeFrequency[16]++:r<=10?t.codeFrequency[17]++:t.codeFrequency[18]++}},t.prototype.writeTree=function(t){for(var e,i,r,n=-1,s=0;s<this.codeCount;){r=1;var h=this.codeLength[s];for(0===h?(e=138,i=3):(e=6,i=3,n!==h&&(t.writeCodeToStream(h),r=0)),n=h,s++;s<this.codeCount&&n===this.codeLength[s]&&(s++,!(++r>=e)););if(r<i)for(;r-- >0;)t.writeCodeToStream(n);else 0!==n?(t.writeCodeToStream(16),this.writer.pendingBufferWriteBits(r-3,2)):r<=10?(t.writeCodeToStream(17),this.writer.pendingBufferWriteBits(r-3,3)):(t.writeCodeToStream(18),this.writer.pendingBufferWriteBits(r-11,7))}},t.prototype.buildTree=function(){for(var t=this.codeFrequency.length,e=new Int32Array(t),i=0,r=0,n=0;n<t;n++){var s=this.codeFrequency[n];if(0!==s){for(var h=i++,o=0;h>0&&this.codeFrequency[e[o=Math.floor((h-1)/2)]]>s;)e[h]=e[o],h=o;e[h]=n,r=n}}for(;i<2;)e[i++]=r<2?++r:0;this.codeCount=Math.max(r+1,this.codeMinCount);for(var a=i,f=a,u=new Int32Array(4*i-2),d=new Int32Array(2*i-1),c=0;c<i;c++){var p=e[c],l=2*c;u[l]=p,u[l+1]=-1,d[c]=this.codeFrequency[p]<<8,e[c]=c}this.constructHuffmanTree(e,i,d,f,u),this.buildLength(u)},t.prototype.constructHuffmanTree=function(t,e,i,r,n){do{for(var s=t[0],h=t[--e],o=i[h],a=0,f=1;f<e;)f+1<e&&i[t[f]]>i[t[f+1]]&&f++,t[a]=t[f],a=f,f=2*a+1;for(;(f=a)>0&&i[t[a=Math.floor((f-1)/2)]]>o;)t[f]=t[a];t[f]=h;var u=t[0];h=r++,n[2*h]=s,n[2*h+1]=u;var d=Math.min(255&i[s],255&i[u]);for(i[h]=o=i[s]+i[u]-d+1,a=0,f=1;f<e;)f+1<e&&i[t[f]]>i[t[f+1]]&&f++,t[a]=t[f],a=f,f=2*a+1;for(;(f=a)>0&&i[t[a=Math.floor((f-1)/2)]]>o;)t[f]=t[a];t[f]=h}while(e>1)},t.prototype.buildLength=function(t){this.codeLength=new Uint8Array(this.codeFrequency.length);for(var e=Math.floor(t.length/2),i=Math.floor((e+1)/2),r=0,n=0;n<this.maxLength;n++)this.lengthCount[n]=0;if(0!==(r=this.calculateOptimalCodeLength(t,r,e))){var s=this.maxLength-1;do{for(;0===this.lengthCount[--s];);do{this.lengthCount[s]--,this.lengthCount[++s]++,r-=1<<this.maxLength-1-s}while(r>0&&s<this.maxLength-1)}while(r>0);this.recreateTree(t,r,i)}},t.prototype.recreateTree=function(t,e,i){this.lengthCount[this.maxLength-1]+=e,this.lengthCount[this.maxLength-2]-=e;for(var r=2*i,n=this.maxLength;0!==n;n--)for(var s=this.lengthCount[n-1];s>0;){var h=2*t[r++];-1===t[h+1]&&(this.codeLength[t[h]]=n,s--)}},t.prototype.calculateOptimalCodeLength=function(t,e,i){var r=new Int32Array(i);r[i-1]=0;for(var n=i-1;n>=0;n--){var s=2*n+1;if(-1!==t[s]){var h=r[n]+1;h>this.maxLength&&(h=this.maxLength,e++),r[t[s-1]]=r[t[s]]=h}else{var h=r[n];this.lengthCount[h-1]++,this.codeLength[t[s-1]]=r[n]}}return e},t}();a.reverseBits=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],a.huffCodeLengthOrders=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],e.CompressorHuffmanTree=a;var f=function(){function t(){}return t.checksumUpdate=function(e,i,r,n){var s=new Uint32Array(1);s[0]=e;for(var h=s[0],o=s[0]=65535&h,a=s[0]=h>>t.checkSumBitOffset;n>0;){var f=Math.min(n,t.checksumIterationCount);for(n-=f;--f>=0;)o+=s[0]=255&i[r++],a+=o;o%=t.checksumBase,a%=t.checksumBase}return h=a<<t.checkSumBitOffset|o},t}();f.checkSumBitOffset=16,f.checksumBase=65521,f.checksumIterationCount=3800,e.ChecksumCalculator=f,function(){for(var t=0;t<144;)r[t]=a.bitReverse(48+t<<8),n[t++]=8;for(;t<256;)r[t]=a.bitReverse(256+t<<7),n[t++]=9;for(;t<280;)r[t]=a.bitReverse(-256+t<<9),n[t++]=7;for(;t<286;)r[t]=a.bitReverse(-88+t<<8),n[t++]=8;for(t=0;t<30;t++)s[t]=a.bitReverse(t<<11),h[t]=5}()}.apply(e,r))&&(t.exports=n)},function(e,i){e.exports=t}])}); | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@syncfusion/ej2-file-utils"));else if("function"==typeof define&&define.amd)define(["@syncfusion/ej2-file-utils"],e);else{var i=e("object"==typeof exports?require("@syncfusion/ej2-file-utils"):t["@syncfusion/ej2-file-utils"]);for(var r in i)("object"==typeof exports?exports:t)[r]=i[r]}}(this,function(t){return function(t){function e(r){if(i[r])return i[r].exports;var n=i[r]={exports:{},id:r,loaded:!1};return t[r].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){var r,n;r=[i,e,i(1),i(2)],void 0!==(n=function(t,e,i,r){"use strict";function n(t){for(var i in t)e.hasOwnProperty(i)||(e[i]=t[i])}Object.defineProperty(e,"__esModule",{value:!0}),n(i),n(r)}.apply(e,r))&&(t.exports=n)},function(t,e,i){var r,n;r=[i,e,i(2),i(3)],void 0!==(n=function(t,e,i,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=[],s=function(){function t(){this.files=[],this.level="Normal",r.Save.isMicrosoftBrowser=!!navigator.msSaveBlob}return Object.defineProperty(t.prototype,"compressionLevel",{get:function(){return this.level},set:function(t){this.level=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return void 0===this.files?0:this.files.length},enumerable:!0,configurable:!0}),t.prototype.addItem=function(t){if(null===t||void 0===t)throw new Error("ArgumentException: item cannot be null or undefined");for(var e=0;e<this.files.length;e++){var i=this.files[e];if(i instanceof h&&i.name===t.name)throw new Error("item with same name already exist")}this.files.push(t)},t.prototype.addDirectory=function(t){if(null===t||void 0===t)throw new Error("ArgumentException: string cannot be null or undefined");if(0===t.length)throw new Error("ArgumentException: string cannot be empty");if("/"!==t.slice(-1)&&(t+="/"),-1!==this.files.indexOf(t))throw new Error("item with same name already exist");this.files.push(t)},t.prototype.getItem=function(t){if(t>=0&&t<this.files.length)return this.files[t]},t.prototype.contains=function(t){return-1!==this.files.indexOf(t)},t.prototype.save=function(t){var e=this;if(null===t||void 0===t||0===t.length)throw new Error("ArgumentException: fileName cannot be null or undefined");if(0===this.files.length)throw new Error("InvalidOperation");var i=this;return new Promise(function(r,n){for(var s=[],h=0,o=0;o<e.files.length;o++){e.getCompressedData(e.files[o]).then(function(n){h=i.constructZippedObject(s,n,h,n.isDirectory),s.length===e.files.length&&(i.writeZippedContent(t,s,h),r(i))})}})},t.prototype.destroy=function(){if(void 0!==this.files&&this.files.length>0){for(var t=0;t<this.files.length;t++){var e=this.files[t];e instanceof h&&e.destroy(),e=void 0}this.files=[]}this.files=void 0,this.level=void 0},t.prototype.getCompressedData=function(t){var e=this;return new Promise(function(i,r){if(t instanceof h){var s=new FileReader;s.onload=function(){var r=new Uint8Array(s.result),h={fileName:t.name,crc32Value:0,compressedData:[],compressedSize:void 0,uncompressedDataSize:r.length,compressionType:void 0,isDirectory:!1};if("Normal"===e.level){e.compressData(r,h,n);for(var o=0,a=0;a<h.compressedData.length;a++)o+=h.compressedData[a].length;h.compressedSize=o,h.compressionType="\b\0"}else h.compressedSize=r.length,h.crc32Value=e.calculateCrc32Value(0,r,n),h.compressionType="\0\0",h.compressedData.push(r);i(h)},s.readAsArrayBuffer(t.data)}else{i({fileName:t,crc32Value:0,compressedData:"",compressedSize:0,uncompressedDataSize:0,compressionType:"\0\0",isDirectory:!0})}})},t.prototype.compressData=function(t,e,r){var n=new i.CompressedStreamWriter(!0),s=0,h=0;do{if(s>=t.length){n.close();break}h=Math.min(t.length,s+16384);var o=t.subarray(s,h);e.crc32Value=this.calculateCrc32Value(e.crc32Value,o,r),n.write(o,0,h-s),s=h}while(s<=t.length);e.compressedData=n.compressedData,n.destroy()},t.prototype.constructZippedObject=function(t,e,i,r){var n=0,s=new Date;r&&(n|=16),n|=0;var h=this.writeHeader(e,s),o="PK"+h+e.fileName,a=this.writeCentralDirectory(e,h,i,n);return t.push({localHeader:o,centralDir:a,compressedData:e}),i+o.length+e.compressedSize},t.prototype.writeHeader=function(t,e){var i="";return i+="\n\0\0\0",i+=t.compressionType,i+=this.getBytes(this.getModifiedTime(e),2),i+=this.getBytes(this.getModifiedDate(e),2),i+=this.getBytes(t.crc32Value,4),i+=this.getBytes(t.compressedSize,4),i+=this.getBytes(t.uncompressedDataSize,4),i+=this.getBytes(t.fileName.length,2),i+=this.getBytes(0,2)},t.prototype.writeZippedContent=function(t,e,i){for(var n=0,s=[],h=0;h<e.length;h++){var o=e[h];for(n+=o.centralDir.length,s.push(this.getArrayBuffer(o.localHeader));o.compressedData.compressedData.length;)s.push(o.compressedData.compressedData.shift().buffer)}for(var h=0;h<e.length;h++)s.push(this.getArrayBuffer(e[h].centralDir));s.push(this.getArrayBuffer(this.writeFooter(e,n,i))),r.Save.save(t,new Blob(s,{type:"application/zip"}))},t.prototype.writeCentralDirectory=function(t,e,i,r){return"PK"+this.getBytes(20,2)+e+this.getBytes(0,2)+"\0\0\0\0"+this.getBytes(r,4)+this.getBytes(i,4)+t.fileName},t.prototype.writeFooter=function(t,e,i){return"PK\0\0\0\0"+this.getBytes(t.length,2)+this.getBytes(t.length,2)+this.getBytes(e,4)+this.getBytes(i,4)+this.getBytes(0,2)},t.prototype.getArrayBuffer=function(t){for(var e=new Uint8Array(t.length),i=0;i<t.length;++i)e[i]=255&t.charCodeAt(i);return e.buffer},t.prototype.getBytes=function(t,e){for(var i="",r=0;r<e;r++)i+=String.fromCharCode(255&t),t>>>=8;return i},t.prototype.getModifiedTime=function(t){var e=t.getHours();return e<<=6,e|=t.getMinutes(),e<<=5,e|=t.getSeconds()/2},t.prototype.getModifiedDate=function(t){var e=t.getFullYear()-1980;return e<<=4,e|=t.getMonth()+1,e<<=5,e|=t.getDate()},t.prototype.calculateCrc32Value=function(t,e,i){t^=-1;for(var r=0;r<e.length;r++)t=t>>>8^i[255&(t^e[r])];return-1^t},t}();e.ZipArchive=s;var h=function(){function t(t,e){if(null===t||void 0===t)throw new Error("ArgumentException: data cannot be null or undefined");if(null===e||void 0===e)throw new Error("ArgumentException: string cannot be null or undefined");if(0===e.length)throw new Error("string cannot be empty");this.data=t,this.name=e}return Object.defineProperty(t.prototype,"name",{get:function(){return this.fileName},set:function(t){this.fileName=t},enumerable:!0,configurable:!0}),t.prototype.destroy=function(){this.fileName=void 0,this.data=void 0},t}();e.ZipArchiveItem=h,function(){for(var t,e=0;e<256;e++){t=e;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;n[e]=t}}()}.apply(e,r))&&(t.exports=n)},function(t,e,i){var r,n;r=[i,e,i(3)],void 0!==(n=function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=new Int16Array(286),n=new Uint8Array(286),s=new Int16Array(30),h=new Uint8Array(30),o=function(){function t(t){this.pendingBuffer=new Uint8Array(65536),this.pendingBufLength=0,this.pendingBufCache=0,this.pendingBufBitsInCache=0,this.bufferPosition=0,this.extraBits=0,this.currentHash=0,this.matchStart=0,this.matchLength=0,this.matchPrevAvail=!1,this.blockStart=0,this.stringStart=0,this.lookAhead=0,this.totalBytesIn=0,this.inputOffset=0,this.inputEnd=0,this.windowSize=32768,this.windowMask=this.windowSize-1,this.hashSize=32768,this.hashMask=this.hashSize-1,this.hashShift=Math.floor(17/3),this.maxDist=this.windowSize-262,this.checkSum=1,this.noWrap=!1,this.treeLiteral=new a(this,286,257,15),this.treeDistances=new a(this,30,1,15),this.treeCodeLengths=new a(this,19,4,7),this.arrDistances=new Uint16Array(16384),this.arrLiterals=new Uint8Array(16384),this.stream=[],this.dataWindow=new Uint8Array(2*this.windowSize),this.hashHead=new Int16Array(this.hashSize),this.hashPrevious=new Int16Array(this.windowSize),this.blockStart=this.stringStart=1,this.noWrap=t,t||this.writeZLibHeader()}return Object.defineProperty(t.prototype,"compressedData",{get:function(){return this.stream},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"getCompressedString",{get:function(){var t="";if(void 0!==this.stream)for(var e=0;e<this.stream.length;e++)t+=String.fromCharCode.apply(null,this.stream[e]);return t},enumerable:!0,configurable:!0}),t.prototype.write=function(t,e,r){if(void 0===t||null===t)throw new Error("ArgumentException: data cannot null or undefined");var n=e+r;if(0>e||e>n||n>t.length)throw new Error("ArgumentOutOfRangeException: Offset or length is incorrect");if("string"==typeof t){var s=new i.Encoding(!1);s.type="Utf8",t=new Uint8Array(s.getBytes(t,0,t.length)),n=e+t.length}for(this.inputBuffer=t,this.inputOffset=e,this.inputEnd=n,this.noWrap||(this.checkSum=f.checksumUpdate(this.checkSum,this.inputBuffer,this.inputOffset,n));this.inputEnd!==this.inputOffset||0!==this.pendingBufLength;)this.pendingBufferFlush(),this.compressData(!1)},t.prototype.writeZLibHeader=function(){var t=30720;t|=64,t+=31-t%31,this.pendingBufferWriteShortBytes(t)},t.prototype.pendingBufferWriteShortBytes=function(t){this.pendingBuffer[this.pendingBufLength++]=t>>8,this.pendingBuffer[this.pendingBufLength++]=t},t.prototype.compressData=function(t){var e;do{this.fillWindow();var i=t&&this.inputEnd===this.inputOffset;e=this.compressSlow(i,t)}while(0===this.pendingBufLength&&e);return e},t.prototype.compressSlow=function(t,e){if(this.lookAhead<262&&!t)return!1;for(;this.lookAhead>=262||t;){if(0===this.lookAhead)return this.lookAheadCompleted(e);this.stringStart>=2*this.windowSize-262&&this.slideWindow();var i=this.matchStart,r=this.matchLength;if(this.lookAhead>=3&&this.discardMatch(),r>=3&&this.matchLength<=r?r=this.matchPreviousBest(i,r):this.matchPreviousAvailable(),this.bufferPosition>=16384)return this.huffmanIsFull(e)}return!0},t.prototype.discardMatch=function(){var t=this.insertString();0!==t&&this.stringStart-t<=this.maxDist&&this.findLongestMatch(t)&&this.matchLength<=5&&3===this.matchLength&&this.stringStart-this.matchStart>4096&&(this.matchLength=2)},t.prototype.matchPreviousAvailable=function(){this.matchPrevAvail&&this.huffmanTallyLit(255&this.dataWindow[this.stringStart-1]),this.matchPrevAvail=!0,this.stringStart++,this.lookAhead--},t.prototype.matchPreviousBest=function(t,e){this.huffmanTallyDist(this.stringStart-1-t,e),e-=2;do{this.stringStart++,--this.lookAhead>=3&&this.insertString()}while(--e>0);return this.stringStart++,this.lookAhead--,this.matchPrevAvail=!1,this.matchLength=2,e},t.prototype.lookAheadCompleted=function(t){return this.matchPrevAvail&&this.huffmanTallyLit(255&this.dataWindow[this.stringStart-1]),this.matchPrevAvail=!1,this.huffmanFlushBlock(this.dataWindow,this.blockStart,this.stringStart-this.blockStart,t),this.blockStart=this.stringStart,!1},t.prototype.huffmanIsFull=function(t){var e=this.stringStart-this.blockStart;this.matchPrevAvail&&e--;var i=t&&0===this.lookAhead&&!this.matchPrevAvail;return this.huffmanFlushBlock(this.dataWindow,this.blockStart,e,i),this.blockStart+=e,!i},t.prototype.fillWindow=function(){for(this.stringStart>=this.windowSize+this.maxDist&&this.slideWindow();this.lookAhead<262&&this.inputOffset<this.inputEnd;){var t=2*this.windowSize-this.lookAhead-this.stringStart;t>this.inputEnd-this.inputOffset&&(t=this.inputEnd-this.inputOffset),this.dataWindow.set(this.inputBuffer.subarray(this.inputOffset,this.inputOffset+t),this.stringStart+this.lookAhead),this.inputOffset+=t,this.totalBytesIn+=t,this.lookAhead+=t}this.lookAhead>=3&&this.updateHash()},t.prototype.slideWindow=function(){this.dataWindow.set(this.dataWindow.subarray(this.windowSize,this.windowSize+this.windowSize),0),this.matchStart-=this.windowSize,this.stringStart-=this.windowSize,this.blockStart-=this.windowSize;for(var t=0;t<this.hashSize;++t){var e=65535&this.hashHead[t];this.hashHead[t]=e>=this.windowSize?e-this.windowSize:0}for(var t=0;t<this.windowSize;t++){var e=65535&this.hashPrevious[t];this.hashPrevious[t]=e>=this.windowSize?e-this.windowSize:0}},t.prototype.insertString=function(){var t,e=(this.currentHash<<this.hashShift^this.dataWindow[this.stringStart+2])&this.hashMask;return this.hashPrevious[this.stringStart&this.windowMask]=t=this.hashHead[e],this.hashHead[e]=this.stringStart,this.currentHash=e,65535&t},t.prototype.findLongestMatch=function(t){var e,i=4096,r=258,n=this.stringStart,s=this.stringStart+this.matchLength,h=Math.max(this.matchLength,2),o=Math.max(this.stringStart-this.maxDist,0),a=this.stringStart+258-1,f=this.dataWindow[s-1],u=this.dataWindow[s],d=this.dataWindow;h>=32&&(i>>=2),r>this.lookAhead&&(r=this.lookAhead);do{if(d[t+h]===u&&d[t+h-1]===f&&d[t]===d[n]&&d[t+1]===d[n+1]){for(e=t+2,n+=2;d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&d[++n]===d[++e]&&n<a;);if(n>s){if(this.matchStart=t,s=n,(h=n-this.stringStart)>=r)break;f=d[s-1],u=d[s]}n=this.stringStart}}while((t=65535&this.hashPrevious[t&this.windowMask])>o&&0!=--i);return this.matchLength=Math.min(h,this.lookAhead),this.matchLength>=3},t.prototype.updateHash=function(){this.currentHash=this.dataWindow[this.stringStart]<<this.hashShift^this.dataWindow[this.stringStart+1]},t.prototype.huffmanTallyLit=function(t){return this.arrDistances[this.bufferPosition]=0,this.arrLiterals[this.bufferPosition++]=t,this.treeLiteral.codeFrequencies[t]++,this.bufferPosition>=16384},t.prototype.huffmanTallyDist=function(t,e){this.arrDistances[this.bufferPosition]=t,this.arrLiterals[this.bufferPosition++]=e-3;var i=this.huffmanLengthCode(e-3);this.treeLiteral.codeFrequencies[i]++,i>=265&&i<285&&(this.extraBits+=Math.floor((i-261)/4));var r=this.huffmanDistanceCode(t-1);return this.treeDistances.codeFrequencies[r]++,r>=4&&(this.extraBits+=Math.floor(r/2-1)),this.bufferPosition>=16384},t.prototype.huffmanFlushBlock=function(t,e,i,o){this.treeLiteral.codeFrequencies[256]++,this.treeLiteral.buildTree(),this.treeDistances.buildTree(),this.treeLiteral.calculateBLFreq(this.treeCodeLengths),this.treeDistances.calculateBLFreq(this.treeCodeLengths),this.treeCodeLengths.buildTree();for(var f=4,u=18;u>f;u--)this.treeCodeLengths.codeLengths[a.huffCodeLengthOrders[u]]>0&&(f=u+1);for(var d=14+3*f+this.treeCodeLengths.getEncodedLength()+this.treeLiteral.getEncodedLength()+this.treeDistances.getEncodedLength()+this.extraBits,c=this.extraBits,u=0;u<286;u++)c+=this.treeLiteral.codeFrequencies[u]*n[u];for(var u=0;u<30;u++)c+=this.treeDistances.codeFrequencies[u]*h[u];d>=c&&(d=c),e>=0&&i+4<d>>3?this.huffmanFlushStoredBlock(t,e,i,o):d==c?(this.pendingBufferWriteBits(2+(o?1:0),3),this.treeLiteral.setStaticCodes(r,n),this.treeDistances.setStaticCodes(s,h),this.huffmanCompressBlock(),this.huffmanReset()):(this.pendingBufferWriteBits(4+(o?1:0),3),this.huffmanSendAllTrees(f),this.huffmanCompressBlock(),this.huffmanReset())},t.prototype.huffmanFlushStoredBlock=function(t,e,i,r){this.pendingBufferWriteBits(0+(r?1:0),3),this.pendingBufferAlignToByte(),this.pendingBufferWriteShort(i),this.pendingBufferWriteShort(~i),this.pendingBufferWriteByteBlock(t,e,i),this.huffmanReset()},t.prototype.huffmanLengthCode=function(t){if(255===t)return 285;for(var e=257;t>=8;)e+=4,t>>=1;return e+t},t.prototype.huffmanDistanceCode=function(t){for(var e=0;t>=4;)e+=2,t>>=1;return e+t},t.prototype.huffmanSendAllTrees=function(t){this.treeCodeLengths.buildCodes(),this.treeLiteral.buildCodes(),this.treeDistances.buildCodes(),this.pendingBufferWriteBits(this.treeLiteral.treeLength-257,5),this.pendingBufferWriteBits(this.treeDistances.treeLength-1,5),this.pendingBufferWriteBits(t-4,4);for(var e=0;e<t;e++)this.pendingBufferWriteBits(this.treeCodeLengths.codeLengths[a.huffCodeLengthOrders[e]],3);this.treeLiteral.writeTree(this.treeCodeLengths),this.treeDistances.writeTree(this.treeCodeLengths)},t.prototype.huffmanReset=function(){this.bufferPosition=0,this.extraBits=0,this.treeLiteral.reset(),this.treeDistances.reset(),this.treeCodeLengths.reset()},t.prototype.huffmanCompressBlock=function(){for(var t=0;t<this.bufferPosition;t++){var e=255&this.arrLiterals[t],i=this.arrDistances[t];if(0!=i--){var r=this.huffmanLengthCode(e);this.treeLiteral.writeCodeToStream(r);var n=Math.floor((r-261)/4);n>0&&n<=5&&this.pendingBufferWriteBits(e&(1<<n)-1,n);var s=this.huffmanDistanceCode(i);this.treeDistances.writeCodeToStream(s),n=Math.floor(s/2-1),n>0&&this.pendingBufferWriteBits(i&(1<<n)-1,n)}else this.treeLiteral.writeCodeToStream(e)}this.treeLiteral.writeCodeToStream(256)},t.prototype.pendingBufferWriteBits=function(t,e){var i=new Uint32Array(1);i[0]=this.pendingBufCache|t<<this.pendingBufBitsInCache,this.pendingBufCache=i[0],this.pendingBufBitsInCache+=e,this.pendingBufferFlushBits()},t.prototype.pendingBufferFlush=function(t){if(this.pendingBufferFlushBits(),this.pendingBufLength>0){var e=new Uint8Array(this.pendingBufLength);e.set(this.pendingBuffer.subarray(0,this.pendingBufLength),0),this.stream.push(e)}this.pendingBufLength=0},t.prototype.pendingBufferFlushBits=function(){for(var t=0;this.pendingBufBitsInCache>=8&&this.pendingBufLength<65536;)this.pendingBuffer[this.pendingBufLength++]=this.pendingBufCache,this.pendingBufCache>>=8,this.pendingBufBitsInCache-=8,t++;return t},t.prototype.pendingBufferWriteByteBlock=function(t,e,i){var r=t.subarray(e,e+i);this.pendingBuffer.set(r,this.pendingBufLength),this.pendingBufLength+=i},t.prototype.pendingBufferWriteShort=function(t){this.pendingBuffer[this.pendingBufLength++]=t,this.pendingBuffer[this.pendingBufLength++]=t>>8},t.prototype.pendingBufferAlignToByte=function(){this.pendingBufBitsInCache>0&&(this.pendingBuffer[this.pendingBufLength++]=this.pendingBufCache),this.pendingBufCache=0,this.pendingBufBitsInCache=0},t.prototype.close=function(){do{this.pendingBufferFlush(!0),this.compressData(!0)||(this.pendingBufferFlush(!0),this.pendingBufferAlignToByte(),this.noWrap||(this.pendingBufferWriteShortBytes(this.checkSum>>16),this.pendingBufferWriteShortBytes(65535&this.checkSum)),this.pendingBufferFlush(!0))}while(this.inputEnd!==this.inputOffset||0!==this.pendingBufLength)},t.prototype.destroy=function(){this.stream=[],this.stream=void 0,this.pendingBuffer=void 0,this.treeLiteral=void 0,this.treeDistances=void 0,this.treeCodeLengths=void 0,this.arrLiterals=void 0,this.arrDistances=void 0,this.hashHead=void 0,this.hashPrevious=void 0,this.dataWindow=void 0,this.inputBuffer=void 0,this.pendingBufLength=void 0,this.pendingBufCache=void 0,this.pendingBufBitsInCache=void 0,this.bufferPosition=void 0,this.extraBits=void 0,this.currentHash=void 0,this.matchStart=void 0,this.matchLength=void 0,this.matchPrevAvail=void 0,this.blockStart=void 0,this.stringStart=void 0,this.lookAhead=void 0,this.totalBytesIn=void 0,this.inputOffset=void 0,this.inputEnd=void 0,this.windowSize=void 0,this.windowMask=void 0,this.hashSize=void 0,this.hashMask=void 0,this.hashShift=void 0,this.maxDist=void 0,this.checkSum=void 0,this.noWrap=void 0},t}();e.CompressedStreamWriter=o;var a=function(){function t(t,e,i,r){this.writer=t,this.codeMinCount=i,this.maxLength=r,this.codeFrequency=new Int16Array(e),this.lengthCount=new Int32Array(r)}return Object.defineProperty(t.prototype,"treeLength",{get:function(){return this.codeCount},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"codeLengths",{get:function(){return this.codeLength},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"codeFrequencies",{get:function(){return this.codeFrequency},enumerable:!0,configurable:!0}),t.prototype.setStaticCodes=function(t,e){var i=new Int16Array(t.length);i.set(t,0),this.codes=i;var r=new Uint8Array(e.length);r.set(e,0),this.codeLength=r},t.prototype.reset=function(){for(var t=0;t<this.codeFrequency.length;t++)this.codeFrequency[t]=0;this.codes=void 0,this.codeLength=void 0},t.prototype.writeCodeToStream=function(t){this.writer.pendingBufferWriteBits(65535&this.codes[t],this.codeLength[t])},t.prototype.buildCodes=function(){var e=new Int32Array(this.maxLength);this.codes=new Int16Array(this.codeCount);for(var i=0,r=0;r<this.maxLength;r++)e[r]=i,i+=this.lengthCount[r]<<15-r;for(var n=0;n<this.codeCount;n++){var s=this.codeLength[n];s>0&&(this.codes[n]=t.bitReverse(e[s-1]),e[s-1]+=1<<16-s)}},t.bitReverse=function(e){return t.reverseBits[15&e]<<12|t.reverseBits[e>>4&15]<<8|t.reverseBits[e>>8&15]<<4|t.reverseBits[e>>12]},t.prototype.getEncodedLength=function(){for(var t=0,e=0;e<this.codeFrequency.length;e++)t+=this.codeFrequency[e]*this.codeLength[e];return t},t.prototype.calculateBLFreq=function(t){for(var e,i,r,n=-1,s=0;s<this.codeCount;){r=1;var h=this.codeLength[s];for(0===h?(e=138,i=3):(e=6,i=3,n!==h&&(t.codeFrequency[h]++,r=0)),n=h,s++;s<this.codeCount&&n===this.codeLength[s]&&(s++,!(++r>=e)););r<i?t.codeFrequency[n]+=r:0!==n?t.codeFrequency[16]++:r<=10?t.codeFrequency[17]++:t.codeFrequency[18]++}},t.prototype.writeTree=function(t){for(var e,i,r,n=-1,s=0;s<this.codeCount;){r=1;var h=this.codeLength[s];for(0===h?(e=138,i=3):(e=6,i=3,n!==h&&(t.writeCodeToStream(h),r=0)),n=h,s++;s<this.codeCount&&n===this.codeLength[s]&&(s++,!(++r>=e)););if(r<i)for(;r-- >0;)t.writeCodeToStream(n);else 0!==n?(t.writeCodeToStream(16),this.writer.pendingBufferWriteBits(r-3,2)):r<=10?(t.writeCodeToStream(17),this.writer.pendingBufferWriteBits(r-3,3)):(t.writeCodeToStream(18),this.writer.pendingBufferWriteBits(r-11,7))}},t.prototype.buildTree=function(){for(var t=this.codeFrequency.length,e=new Int32Array(t),i=0,r=0,n=0;n<t;n++){var s=this.codeFrequency[n];if(0!==s){for(var h=i++,o=0;h>0&&this.codeFrequency[e[o=Math.floor((h-1)/2)]]>s;)e[h]=e[o],h=o;e[h]=n,r=n}}for(;i<2;)e[i++]=r<2?++r:0;this.codeCount=Math.max(r+1,this.codeMinCount);for(var a=i,f=a,u=new Int32Array(4*i-2),d=new Int32Array(2*i-1),c=0;c<i;c++){var p=e[c],l=2*c;u[l]=p,u[l+1]=-1,d[c]=this.codeFrequency[p]<<8,e[c]=c}this.constructHuffmanTree(e,i,d,f,u),this.buildLength(u)},t.prototype.constructHuffmanTree=function(t,e,i,r,n){do{for(var s=t[0],h=t[--e],o=i[h],a=0,f=1;f<e;)f+1<e&&i[t[f]]>i[t[f+1]]&&f++,t[a]=t[f],a=f,f=2*a+1;for(;(f=a)>0&&i[t[a=Math.floor((f-1)/2)]]>o;)t[f]=t[a];t[f]=h;var u=t[0];h=r++,n[2*h]=s,n[2*h+1]=u;var d=Math.min(255&i[s],255&i[u]);for(i[h]=o=i[s]+i[u]-d+1,a=0,f=1;f<e;)f+1<e&&i[t[f]]>i[t[f+1]]&&f++,t[a]=t[f],a=f,f=2*a+1;for(;(f=a)>0&&i[t[a=Math.floor((f-1)/2)]]>o;)t[f]=t[a];t[f]=h}while(e>1)},t.prototype.buildLength=function(t){this.codeLength=new Uint8Array(this.codeFrequency.length);for(var e=Math.floor(t.length/2),i=Math.floor((e+1)/2),r=0,n=0;n<this.maxLength;n++)this.lengthCount[n]=0;if(0!==(r=this.calculateOptimalCodeLength(t,r,e))){var s=this.maxLength-1;do{for(;0===this.lengthCount[--s];);do{this.lengthCount[s]--,this.lengthCount[++s]++,r-=1<<this.maxLength-1-s}while(r>0&&s<this.maxLength-1)}while(r>0);this.recreateTree(t,r,i)}},t.prototype.recreateTree=function(t,e,i){this.lengthCount[this.maxLength-1]+=e,this.lengthCount[this.maxLength-2]-=e;for(var r=2*i,n=this.maxLength;0!==n;n--)for(var s=this.lengthCount[n-1];s>0;){var h=2*t[r++];-1===t[h+1]&&(this.codeLength[t[h]]=n,s--)}},t.prototype.calculateOptimalCodeLength=function(t,e,i){var r=new Int32Array(i);r[i-1]=0;for(var n=i-1;n>=0;n--){var s=2*n+1;if(-1!==t[s]){var h=r[n]+1;h>this.maxLength&&(h=this.maxLength,e++),r[t[s-1]]=r[t[s]]=h}else{var h=r[n];this.lengthCount[h-1]++,this.codeLength[t[s-1]]=r[n]}}return e},t.reverseBits=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],t.huffCodeLengthOrders=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],t}();e.CompressorHuffmanTree=a;var f=function(){function t(){}return t.checksumUpdate=function(e,i,r,n){var s=new Uint32Array(1);s[0]=e;for(var h=s[0],o=s[0]=65535&h,a=s[0]=h>>t.checkSumBitOffset;n>0;){var f=Math.min(n,t.checksumIterationCount);for(n-=f;--f>=0;)o+=s[0]=255&i[r++],a+=o;o%=t.checksumBase,a%=t.checksumBase}return h=a<<t.checkSumBitOffset|o},t.checkSumBitOffset=16,t.checksumBase=65521,t.checksumIterationCount=3800,t}();e.ChecksumCalculator=f,function(){for(var t=0;t<144;)r[t]=a.bitReverse(48+t<<8),n[t++]=8;for(;t<256;)r[t]=a.bitReverse(256+t<<7),n[t++]=9;for(;t<280;)r[t]=a.bitReverse(-256+t<<9),n[t++]=7;for(;t<286;)r[t]=a.bitReverse(-88+t<<8),n[t++]=8;for(t=0;t<30;t++)s[t]=a.bitReverse(t<<11),h[t]=5}()}.apply(e,r))&&(t.exports=n)},function(e,i){e.exports=t}])}); | ||
//# sourceMappingURL=ej2-compression.umd.min.js.map |
import { Encoding } from '@syncfusion/ej2-file-utils'; | ||
/** | ||
* array literal codes | ||
*/ | ||
var arrLiteralCodes = new Int16Array(286); | ||
@@ -6,3 +9,16 @@ var arrLiteralLengths = new Uint8Array(286); | ||
var arrDistanceLengths = new Uint8Array(30); | ||
var CompressedStreamWriter = (function () { | ||
/** | ||
* represent compression stream writer | ||
* ```typescript | ||
* let compressedWriter = new CompressedStreamWriter(); | ||
* let text: string = 'Hello world!!!'; | ||
* compressedWriter.write(text, 0, text.length); | ||
* compressedWriter.close(); | ||
* ``` | ||
*/ | ||
var CompressedStreamWriter = /** @class */ (function () { | ||
/** | ||
* Initializes compressor and writes ZLib header if needed. | ||
* @param {boolean} noWrap - optional if true, ZLib header and checksum will not be written. | ||
*/ | ||
function CompressedStreamWriter(noWrap) { | ||
@@ -49,2 +65,5 @@ this.pendingBuffer = new Uint8Array(1 << 16); | ||
Object.defineProperty(CompressedStreamWriter.prototype, "compressedData", { | ||
/** | ||
* get compressed data | ||
*/ | ||
get: function () { | ||
@@ -69,2 +88,9 @@ return this.stream; | ||
}); | ||
/** | ||
* Compresses data and writes it to the stream. | ||
* @param {Uint8Array} data - data to compress | ||
* @param {number} offset - offset in data | ||
* @param {number} length - length of the data | ||
* @returns {void} | ||
*/ | ||
CompressedStreamWriter.prototype.write = function (data, offset, length) { | ||
@@ -95,8 +121,20 @@ if (data === undefined || data === null) { | ||
}; | ||
/** | ||
* write ZLib header to the compressed data | ||
* @return {void} | ||
*/ | ||
CompressedStreamWriter.prototype.writeZLibHeader = function () { | ||
/* Initialize header.*/ | ||
var headerDate = (8 + (7 << 4)) << 8; | ||
/* Save compression level.*/ | ||
headerDate |= ((5 >> 2) & 3) << 6; | ||
/* Align header.*/ | ||
headerDate += 31 - (headerDate % 31); | ||
/* Write header to stream.*/ | ||
this.pendingBufferWriteShortBytes(headerDate); | ||
}; | ||
/** | ||
* Write Most Significant Bytes in to stream | ||
* @param {number} s - check sum value | ||
*/ | ||
CompressedStreamWriter.prototype.pendingBufferWriteShortBytes = function (s) { | ||
@@ -261,2 +299,3 @@ this.pendingBuffer[this.pendingBufLength++] = s >> 8; | ||
scan += 2; | ||
/* tslint:disable */ | ||
while (data[++scan] === data[++match] && data[++scan] === data[++match] && | ||
@@ -266,2 +305,3 @@ data[++scan] === data[++match] && data[++scan] === data[++match] && | ||
data[++scan] === data[++match] && data[++scan] === data[++match] && scan < stringEnd) { | ||
/* tslint:disable */ | ||
} | ||
@@ -330,2 +370,3 @@ if (scan > bestEnd) { | ||
if (opt_len >= static_len) { | ||
// Force static trees. | ||
opt_len = static_len; | ||
@@ -337,2 +378,3 @@ } | ||
else if (opt_len == static_len) { | ||
// Encode with static tree. | ||
this.pendingBufferWriteBits((1 << 1) + (lastBlock ? 1 : 0), 3); | ||
@@ -422,2 +464,7 @@ this.treeLiteral.setStaticCodes(arrLiteralCodes, arrLiteralLengths); | ||
}; | ||
/** | ||
* write bits in to internal buffer | ||
* @param {number} b - source of bits | ||
* @param {number} count - count of bits to write | ||
*/ | ||
CompressedStreamWriter.prototype.pendingBufferWriteBits = function (b, count) { | ||
@@ -465,2 +512,6 @@ var uint = new Uint32Array(1); | ||
}; | ||
/** | ||
* close the stream and write all pending buffer in to stream | ||
* @returns {void} | ||
*/ | ||
CompressedStreamWriter.prototype.close = function () { | ||
@@ -481,2 +532,6 @@ do { | ||
}; | ||
/** | ||
* release allocated un-managed resource | ||
* @returns {void} | ||
*/ | ||
CompressedStreamWriter.prototype.destroy = function () { | ||
@@ -522,3 +577,13 @@ this.stream = []; | ||
export { CompressedStreamWriter }; | ||
var CompressorHuffmanTree = (function () { | ||
/** | ||
* represent the Huffman Tree | ||
*/ | ||
var CompressorHuffmanTree = /** @class */ (function () { | ||
/** | ||
* Create new Huffman Tree | ||
* @param {CompressedStreamWriter} writer instance | ||
* @param {number} elementCount - element count | ||
* @param {number} minCodes - minimum count | ||
* @param {number} maxLength - maximum count | ||
*/ | ||
function CompressorHuffmanTree(writer, elementCount, minCodes, maxLength) { | ||
@@ -560,2 +625,6 @@ this.writer = writer; | ||
}; | ||
/** | ||
* reset all code data in tree | ||
* @returns {void} | ||
*/ | ||
CompressorHuffmanTree.prototype.reset = function () { | ||
@@ -568,5 +637,14 @@ for (var i = 0; i < this.codeFrequency.length; i++) { | ||
}; | ||
/** | ||
* write code to the compressor output stream | ||
* @param {number} code - code to be written | ||
* @returns {void} | ||
*/ | ||
CompressorHuffmanTree.prototype.writeCodeToStream = function (code) { | ||
this.writer.pendingBufferWriteBits(this.codes[code] & 0xffff, this.codeLength[code]); | ||
}; | ||
/** | ||
* calculate code from their frequencies | ||
* @returns {void} | ||
*/ | ||
CompressorHuffmanTree.prototype.buildCodes = function () { | ||
@@ -594,2 +672,6 @@ var nextCode = new Int32Array(this.maxLength); | ||
}; | ||
/** | ||
* calculate length of compressed data | ||
* @returns {number} | ||
*/ | ||
CompressorHuffmanTree.prototype.getEncodedLength = function () { | ||
@@ -602,2 +684,7 @@ var len = 0; | ||
}; | ||
/** | ||
* calculate code frequencies | ||
* @param {CompressorHuffmanTree} blTree | ||
* @returns {void} | ||
*/ | ||
CompressorHuffmanTree.prototype.calculateBLFreq = function (blTree) { | ||
@@ -646,2 +733,6 @@ var maxCount; | ||
}; | ||
/** | ||
* @param {CompressorHuffmanTree} blTree - write tree to output stream | ||
* @returns {void} | ||
*/ | ||
CompressorHuffmanTree.prototype.writeTree = function (blTree) { | ||
@@ -695,2 +786,6 @@ var maxRepeatCount; | ||
}; | ||
/** | ||
* Build huffman tree | ||
* @returns {void} | ||
*/ | ||
CompressorHuffmanTree.prototype.buildTree = function () { | ||
@@ -761,2 +856,3 @@ var codesCount = this.codeFrequency.length; | ||
path = 1; | ||
/* tslint:disable */ | ||
while (path < treeLength) { | ||
@@ -769,3 +865,3 @@ if (path + 1 < treeLength && values[arrTree[path]] > values[arrTree[path + 1]]) { | ||
path = pPos * 2 + 1; | ||
} | ||
} /* tslint:disable */ | ||
while ((path = pPos) > 0 && values[arrTree[pPos = Math.floor((path - 1) / 2)]] > lastVal) { | ||
@@ -792,2 +888,3 @@ arrTree[path] = arrTree[pPos]; | ||
while (this.lengthCount[--iIncreasableLength] === 0) { | ||
/* tslint:disable */ | ||
} | ||
@@ -838,10 +935,22 @@ do { | ||
}; | ||
CompressorHuffmanTree.reverseBits = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]; | ||
CompressorHuffmanTree.huffCodeLengthOrders = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; | ||
return CompressorHuffmanTree; | ||
}()); | ||
export { CompressorHuffmanTree }; | ||
CompressorHuffmanTree.reverseBits = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]; | ||
CompressorHuffmanTree.huffCodeLengthOrders = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; | ||
var ChecksumCalculator = (function () { | ||
/** | ||
* Checksum calculator, based on Adler32 algorithm. | ||
*/ | ||
var ChecksumCalculator = /** @class */ (function () { | ||
function ChecksumCalculator() { | ||
} | ||
/** | ||
* Updates checksum by calculating checksum of the | ||
* given buffer and adding it to current value. | ||
* @param {number} checksum - current checksum. | ||
* @param {Uint8Array} buffer - data byte array. | ||
* @param {number} offset - offset in the buffer. | ||
* @param {number} length - length of data to be used from the stream. | ||
* @returns {number} | ||
*/ | ||
ChecksumCalculator.checksumUpdate = function (checksum, buffer, offset, length) { | ||
@@ -866,8 +975,11 @@ var uint = new Uint32Array(1); | ||
}; | ||
ChecksumCalculator.checkSumBitOffset = 16; | ||
ChecksumCalculator.checksumBase = 65521; | ||
ChecksumCalculator.checksumIterationCount = 3800; | ||
return ChecksumCalculator; | ||
}()); | ||
export { ChecksumCalculator }; | ||
ChecksumCalculator.checkSumBitOffset = 16; | ||
ChecksumCalculator.checksumBase = 65521; | ||
ChecksumCalculator.checksumIterationCount = 3800; | ||
/** | ||
* Huffman Tree literal calculation | ||
*/ | ||
(function () { | ||
@@ -874,0 +986,0 @@ var i = 0; |
@@ -0,2 +1,5 @@ | ||
/** | ||
* export ZipArchive class | ||
*/ | ||
export * from './zip-archive'; | ||
export * from './compression-writer'; |
import { CompressedStreamWriter } from './compression-writer'; | ||
import { Save } from '@syncfusion/ej2-file-utils'; | ||
var crc32Table = []; | ||
var ZipArchive = (function () { | ||
/** | ||
* class provide compression library | ||
* ```typescript | ||
* let archive = new ZipArchive(); | ||
* archive.compressionLevel = 'Normal'; | ||
* let archiveItem = new ZipArchiveItem(archive, 'directoryName\fileName.txt'); | ||
* archive.addItem(archiveItem); | ||
* archive.save(fileName.zip); | ||
* ``` | ||
*/ | ||
var ZipArchive = /** @class */ (function () { | ||
/** | ||
* constructor for creating ZipArchive instance | ||
*/ | ||
function ZipArchive() { | ||
@@ -11,5 +24,11 @@ this.files = []; | ||
Object.defineProperty(ZipArchive.prototype, "compressionLevel", { | ||
/** | ||
* gets compression level | ||
*/ | ||
get: function () { | ||
return this.level; | ||
}, | ||
/** | ||
* sets compression level | ||
*/ | ||
set: function (level) { | ||
@@ -22,2 +41,5 @@ this.level = level; | ||
Object.defineProperty(ZipArchive.prototype, "length", { | ||
/** | ||
* gets items count | ||
*/ | ||
get: function () { | ||
@@ -32,2 +54,7 @@ if (this.files === undefined) { | ||
}); | ||
/** | ||
* add new item to archive | ||
* @param {ZipArchiveItem} item - item to be added | ||
* @returns {void} | ||
*/ | ||
ZipArchive.prototype.addItem = function (item) { | ||
@@ -47,2 +74,7 @@ if (item === null || item === undefined) { | ||
}; | ||
/** | ||
* add new directory to archive | ||
* @param directoryName directoryName to be created | ||
* @returns {void} | ||
*/ | ||
ZipArchive.prototype.addDirectory = function (directoryName) { | ||
@@ -63,2 +95,7 @@ if (directoryName === null || directoryName === undefined) { | ||
}; | ||
/** | ||
* gets item at specified index | ||
* @param {number} index - item index | ||
* @returns {ZipArchiveItem} | ||
*/ | ||
ZipArchive.prototype.getItem = function (index) { | ||
@@ -70,5 +107,15 @@ if (index >= 0 && index < this.files.length) { | ||
}; | ||
/** | ||
* determines whether an element is in the collection | ||
* @param {string | ZipArchiveItem} item - item to search | ||
* @returns {boolean} | ||
*/ | ||
ZipArchive.prototype.contains = function (item) { | ||
return this.files.indexOf(item) !== -1 ? true : false; | ||
}; | ||
/** | ||
* save archive with specified file name | ||
* @param {string} fileName save archive with specified file name | ||
* @returns {Promise<ZipArchive>} | ||
*/ | ||
ZipArchive.prototype.save = function (fileName) { | ||
@@ -99,2 +146,6 @@ var _this = this; | ||
}; | ||
/** | ||
* release allocated un-managed resource | ||
* @returns {void} | ||
*/ | ||
ZipArchive.prototype.destroy = function () { | ||
@@ -133,3 +184,3 @@ if (this.files !== undefined && this.files.length > 0) { | ||
data.compressedSize = length_1; | ||
data.compressionType = '\x08\x00'; | ||
data.compressionType = '\x08\x00'; //Deflated = 8 | ||
} | ||
@@ -139,3 +190,3 @@ else { | ||
data.crc32Value = zipArchive.calculateCrc32Value(0, input, crc32Table); | ||
data.compressionType = '\x00\x00'; | ||
data.compressionType = '\x00\x00'; // Stored = 0 | ||
data.compressedData.push(input); | ||
@@ -179,3 +230,3 @@ } | ||
if (isDirectory) { | ||
extFileAttr = extFileAttr | 0x00010; | ||
extFileAttr = extFileAttr | 0x00010; // directory flag | ||
} | ||
@@ -191,11 +242,11 @@ extFileAttr = extFileAttr | (0 & 0x3F); | ||
var zipHeader = ''; | ||
zipHeader += '\x0A\x00' + '\x00\x00'; | ||
zipHeader += data.compressionType; | ||
zipHeader += this.getBytes(this.getModifiedTime(date), 2); | ||
zipHeader += this.getBytes(this.getModifiedDate(date), 2); | ||
zipHeader += this.getBytes(data.crc32Value, 4); | ||
zipHeader += this.getBytes(data.compressedSize, 4); | ||
zipHeader += this.getBytes(data.uncompressedDataSize, 4); | ||
zipHeader += this.getBytes(data.fileName.length, 2); | ||
zipHeader += this.getBytes(0, 2); | ||
zipHeader += '\x0A\x00' + '\x00\x00'; // version needed to extract & general purpose bit flag | ||
zipHeader += data.compressionType; // compression method Deflate=8,Stored=0 | ||
zipHeader += this.getBytes(this.getModifiedTime(date), 2); // last modified Time | ||
zipHeader += this.getBytes(this.getModifiedDate(date), 2); // last modified date | ||
zipHeader += this.getBytes(data.crc32Value, 4); // crc-32 value | ||
zipHeader += this.getBytes(data.compressedSize, 4); // compressed file size | ||
zipHeader += this.getBytes(data.uncompressedDataSize, 4); // uncompressed file size | ||
zipHeader += this.getBytes(data.fileName.length, 2); // file name length | ||
zipHeader += this.getBytes(0, 2); // extra field length | ||
return zipHeader; | ||
@@ -222,7 +273,7 @@ }; | ||
var directoryHeader = 'PK\x01\x02' + | ||
this.getBytes(0x0014, 2) + localHeader + | ||
this.getBytes(0, 2) + | ||
'\x00\x00' + '\x00\x00' + | ||
this.getBytes(externalFileAttribute, 4) + | ||
this.getBytes(offset, 4) + | ||
this.getBytes(0x0014, 2) + localHeader + // inherit from file header | ||
this.getBytes(0, 2) + // comment length | ||
'\x00\x00' + '\x00\x00' + // internal file attributes | ||
this.getBytes(externalFileAttribute, 4) + // external file attributes | ||
this.getBytes(offset, 4) + // local fileHeader relative offset | ||
data.fileName; | ||
@@ -277,3 +328,14 @@ return directoryHeader; | ||
export { ZipArchive }; | ||
var ZipArchiveItem = (function () { | ||
/** | ||
* Class represent unique ZipArchive item | ||
* ```typescript | ||
* let archiveItem = new ZipArchiveItem(archive, 'directoryName\fileName.txt'); | ||
* ``` | ||
*/ | ||
var ZipArchiveItem = /** @class */ (function () { | ||
/** | ||
* constructor for creating {ZipArchiveItem} instance | ||
* @param {Blob|ArrayBuffer} data file data | ||
* @param {itemName} itemName absolute file path | ||
*/ | ||
function ZipArchiveItem(data, itemName) { | ||
@@ -293,5 +355,13 @@ if (data === null || data === undefined) { | ||
Object.defineProperty(ZipArchiveItem.prototype, "name", { | ||
/** | ||
* Get the name of archive item | ||
* @returns string | ||
*/ | ||
get: function () { | ||
return this.fileName; | ||
}, | ||
/** | ||
* Set the name of archive item | ||
* @param {string} value | ||
*/ | ||
set: function (value) { | ||
@@ -303,2 +373,6 @@ this.fileName = value; | ||
}); | ||
/** | ||
* release allocated un-managed resource | ||
* @returns {void} | ||
*/ | ||
ZipArchiveItem.prototype.destroy = function () { | ||
@@ -311,2 +385,5 @@ this.fileName = undefined; | ||
export { ZipArchiveItem }; | ||
/** | ||
* construct cyclic redundancy code table | ||
*/ | ||
(function () { | ||
@@ -313,0 +390,0 @@ var i; |
{ | ||
"name": "@syncfusion/ej2-compression", | ||
"version": "15.4.17", | ||
"version": "15.4.20", | ||
"description": "Essential JS 2 Compression library", | ||
@@ -9,3 +9,3 @@ "author": "Syncfusion Inc.", | ||
"dependencies": { | ||
"@syncfusion/ej2-file-utils": "^15.4.17" | ||
"@syncfusion/ej2-file-utils": "^15.4.20" | ||
}, | ||
@@ -12,0 +12,0 @@ "devDependencies": { |
@@ -819,6 +819,6 @@ define(["require", "exports", "@syncfusion/ej2-file-utils"], function (require, exports, ej2_file_utils_1) { | ||
}; | ||
CompressorHuffmanTree.reverseBits = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]; | ||
CompressorHuffmanTree.huffCodeLengthOrders = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; | ||
return CompressorHuffmanTree; | ||
}()); | ||
CompressorHuffmanTree.reverseBits = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]; | ||
CompressorHuffmanTree.huffCodeLengthOrders = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; | ||
exports.CompressorHuffmanTree = CompressorHuffmanTree; | ||
@@ -847,7 +847,7 @@ var ChecksumCalculator = (function () { | ||
}; | ||
ChecksumCalculator.checkSumBitOffset = 16; | ||
ChecksumCalculator.checksumBase = 65521; | ||
ChecksumCalculator.checksumIterationCount = 3800; | ||
return ChecksumCalculator; | ||
}()); | ||
ChecksumCalculator.checkSumBitOffset = 16; | ||
ChecksumCalculator.checksumBase = 65521; | ||
ChecksumCalculator.checksumIterationCount = 3800; | ||
exports.ChecksumCalculator = ChecksumCalculator; | ||
@@ -854,0 +854,0 @@ (function () { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
498010
4913