@zip.js/zip.js
Advanced tools
Comparing version 2.0.11 to 2.0.12
@@ -1,1 +0,1 @@ | ||
!function(){"use strict";const t="function";function e(e,n){return class{constructor(s){const i=t=>{if(this.pendingData){const e=this.pendingData;this.pendingData=new Uint8Array(e.length+t.length),this.pendingData.set(e,0),this.pendingData.set(t,e.length)}else this.pendingData=new Uint8Array(t)};if(this.codec=new e(Object.assign({},n,s)),typeof this.codec.onData==t)this.codec.onData=i;else{if(typeof this.codec.on!=t)throw new Error("Cannot register the callback function");this.codec.on("data",i)}}async append(t){return this.codec.push(t),s(this)}async flush(){return this.codec.push(new Uint8Array(0),!0),s(this)}};function s(t){if(t.pendingData){const e=t.pendingData;return t.pendingData=null,e}return new Uint8Array(0)}}class n{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let s=0,i=0|t.length;s<i;s++)n=n>>>8^e[255&(n^t[s])];this.crc=n}get(){return~this.crc}}const s="Invalid pasword",i=16,a="raw",r={name:"PBKDF2"},c={name:"HMAC"},h="SHA-1",p={name:"AES-CTR"},o=Object.assign({hash:c},r),u=Object.assign({iterations:1e3,hash:{name:h}},r),d=Object.assign({hash:h},c),l=Object.assign({length:i},p),y=["deriveBits"],g=["sign"],w=528,f=10,b=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],A=crypto.subtle;class U{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(s=0)=>{if(s+i<=r.length-f){const t=r.subarray(s,s+i),a=await A.decrypt(Object.assign({counter:this.counter},l),this.keys.decrypt,t);return D(this.counter),n.set(new Uint8Array(a),s),e(s+i)}return this.pendingInput=r.subarray(s),this.signed&&(this.input=I(this.input,t)),n};if(this.password){const e=t.subarray(0,18);await async function(t,e,n){t.counter=new Uint8Array(b);const i=e.subarray(0,16),r=e.subarray(16),c=(new TextEncoder).encode(n),h=await A.importKey(a,c,o,!1,y),l=await A.deriveBits(Object.assign({salt:i},u),h,528),w=new Uint8Array(l),f=w.subarray(64);if(t.keys={decrypt:await A.importKey(a,w.subarray(0,32),p,!0,["decrypt"]),authentication:await A.importKey(a,w.subarray(32,64),d,!1,g),passwordVerification:f},f[0]!=r[0]||f[1]!=r[1])throw new Error(s)}(this,e,this.password),this.password=null,t=t.subarray(18)}let n=new Uint8Array(t.length-f-(t.length-f)%i),r=t;return this.pendingInput.length&&(r=I(this.pendingInput,t),n=k(n,r.length-f-(r.length-f)%i)),e()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-f),s=t.subarray(t.length-f);let i=new Uint8Array(0);if(n.length){const t=await A.decrypt(Object.assign({counter:this.counter},l),e.decrypt,n);i=new Uint8Array(t)}let a=!0;if(this.signed){const t=await A.sign(c,e.authentication,this.input.subarray(0,this.input.length-f)),n=new Uint8Array(t);this.input=null;for(let t=0;t<f;t++)n[t]!=s[t]&&(a=!1)}return{valid:a,data:i}}}class m{constructor(t){this.password=t,this.output=new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(a=0)=>{if(a+i<=t.length){const r=t.subarray(a,a+i),c=await A.encrypt(Object.assign({counter:this.counter},l),this.keys.encrypt,r);return D(this.counter),s.set(new Uint8Array(c),a+n.length),e(a+i)}return this.pendingInput=t.subarray(a),this.output=I(this.output,s),s};let n=new Uint8Array(0);this.password&&(n=await async function(t,e){t.counter=new Uint8Array(b);const n=crypto.getRandomValues(new Uint8Array(16)),s=(new TextEncoder).encode(e),i=await A.importKey(a,s,o,!1,y),r=await A.deriveBits(Object.assign({salt:n},u),i,w),c=new Uint8Array(r);return t.keys={encrypt:await A.importKey(a,c.subarray(0,32),p,!0,["encrypt"]),authentication:await A.importKey(a,c.subarray(32,64),d,!1,g),passwordVerification:c.subarray(64)},I(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let s=new Uint8Array(n.length+t.length-t.length%i);return s.set(n,0),this.pendingInput.length&&(t=I(this.pendingInput,t),s=k(s,t.length-t.length%i)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await A.encrypt(Object.assign({counter:this.counter},l),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=I(this.output,t)}const e=await A.sign(c,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,f);return{data:I(t,n),signature:n}}}function D(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function I(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function k(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const v="Invalid signature";class E{constructor(t){this.signature=t.inputSignature,this.encrypted=Boolean(t.inputPassword),this.signed=t.inputSigned,this.compressed=t.inputCompressed,this.inflate=this.compressed&&new ZipInflate,this.crc32=this.signed&&this.signed&&new n,this.decrypt=this.encrypted&&new U(t.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error(v);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error(v)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class j{constructor(t){this.encrypted=t.outputEncrypted,this.signed=t.outputSigned,this.compressed=t.outputCompressed,this.deflate=this.compressed&&new ZipDeflate({level:t.level||5}),this.crc32=this.signed&&new n,this.encrypt=this.encrypted&&new m(t.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const s=new Uint8Array(e.length+n.data.length);s.set(e,0),s.set(n.data,e.length),e=s}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const O={init(t){t.scripts&&t.scripts.length&&importScripts.apply(void 0,t.scripts);const e=t.options;self.initExternalCodec&&self.initExternalCodec(),C=function(t){return t.codecType.startsWith("deflate")?new j(t):t.codecType.startsWith("inflate")?new E(t):void 0}(e)},append:async t=>({data:await C.append(t.data)}),flush:()=>C.flush()};let C;addEventListener("message",(async t=>{const e=t.data,n=e.type,s=O[n];if(s)try{const t=await s(e)||{};if(t.type=n,t.data)try{postMessage(t,[t.data.buffer])}catch(e){postMessage(t)}else postMessage(t)}catch(t){postMessage({type:n,error:{message:t.message,stack:t.stack}})}})),self.initExternalCodec=()=>{const{ZipDeflate:t,ZipInflate:n}=((t,n={})=>({ZipDeflate:e(t.Deflate,n.deflate),ZipInflate:e(t.Inflate,n.inflate)}))(pako,{deflate:{raw:!0},inflate:{raw:!0}});self.ZipDeflate=t,self.ZipInflate=n}}(); | ||
!function(){"use strict";class t{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let s=0,i=0|t.length;s<i;s++)n=n>>>8^e[255&(n^t[s])];this.crc=n}get(){return~this.crc}}const e="Invalid pasword",n=16,s="raw",i={name:"PBKDF2"},a={name:"HMAC"},r="SHA-1",c={name:"AES-CTR"},h=Object.assign({hash:a},i),o=Object.assign({iterations:1e3,hash:{name:r}},i),p=Object.assign({hash:r},a),u=Object.assign({length:n},c),d=["deriveBits"],l=["sign"],y=528,g=10,w=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=crypto.subtle;class b{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const i=async(e=0)=>{if(e+n<=r.length-g){const t=r.subarray(e,e+n),s=await f.decrypt(Object.assign({counter:this.counter},u),this.keys.decrypt,t);return U(this.counter),a.set(new Uint8Array(s),e),i(e+n)}return this.pendingInput=r.subarray(e),this.signed&&(this.input=m(this.input,t)),a};if(this.password){const n=t.subarray(0,18);await async function(t,n,i){t.counter=new Uint8Array(w);const a=n.subarray(0,16),r=n.subarray(16),u=(new TextEncoder).encode(i),y=await f.importKey(s,u,h,!1,d),g=await f.deriveBits(Object.assign({salt:a},o),y,528),b=new Uint8Array(g),A=b.subarray(64);if(t.keys={decrypt:await f.importKey(s,b.subarray(0,32),c,!0,["decrypt"]),authentication:await f.importKey(s,b.subarray(32,64),p,!1,l),passwordVerification:A},A[0]!=r[0]||A[1]!=r[1])throw new Error(e)}(this,n,this.password),this.password=null,t=t.subarray(18)}let a=new Uint8Array(t.length-g-(t.length-g)%n),r=t;return this.pendingInput.length&&(r=m(this.pendingInput,t),a=D(a,r.length-g-(r.length-g)%n)),i()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-g),s=t.subarray(t.length-g);let i=new Uint8Array(0);if(n.length){const t=await f.decrypt(Object.assign({counter:this.counter},u),e.decrypt,n);i=new Uint8Array(t)}let r=!0;if(this.signed){const t=await f.sign(a,e.authentication,this.input.subarray(0,this.input.length-g)),n=new Uint8Array(t);this.input=null;for(let t=0;t<g;t++)n[t]!=s[t]&&(r=!1)}return{valid:r,data:i}}}class A{constructor(t){this.password=t,this.output=new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(s=0)=>{if(s+n<=t.length){const r=t.subarray(s,s+n),c=await f.encrypt(Object.assign({counter:this.counter},u),this.keys.encrypt,r);return U(this.counter),a.set(new Uint8Array(c),s+i.length),e(s+n)}return this.pendingInput=t.subarray(s),this.output=m(this.output,a),a};let i=new Uint8Array(0);this.password&&(i=await async function(t,e){t.counter=new Uint8Array(w);const n=crypto.getRandomValues(new Uint8Array(16)),i=(new TextEncoder).encode(e),a=await f.importKey(s,i,h,!1,d),r=await f.deriveBits(Object.assign({salt:n},o),a,y),u=new Uint8Array(r);return t.keys={encrypt:await f.importKey(s,u.subarray(0,32),c,!0,["encrypt"]),authentication:await f.importKey(s,u.subarray(32,64),p,!1,l),passwordVerification:u.subarray(64)},m(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let a=new Uint8Array(i.length+t.length-t.length%n);return a.set(i,0),this.pendingInput.length&&(t=m(this.pendingInput,t),a=D(a,t.length-t.length%n)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await f.encrypt(Object.assign({counter:this.counter},u),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=m(this.output,t)}const e=await f.sign(a,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,g);return{data:m(t,n),signature:n}}}function U(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function m(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function D(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const I="deflate",k="inflate",v="Invalid signature";class C{constructor(e){this.signature=e.inputSignature,this.encrypted=Boolean(e.inputPassword),this.signed=e.inputSigned,this.compressed=e.inputCompressed,this.inflate=this.compressed&&new e.codecConstructor,this.crc32=this.signed&&this.signed&&new t,this.decrypt=this.encrypted&&new b(e.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error(v);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error(v)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class j{constructor(e){this.encrypted=e.outputEncrypted,this.signed=e.outputSigned,this.compressed=e.outputCompressed,this.deflate=this.compressed&&new e.codecConstructor({level:e.level||5}),this.crc32=this.signed&&new t,this.encrypt=this.encrypted&&new A(e.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const s=new Uint8Array(e.length+n.data.length);s.set(e,0),s.set(n.data,e.length),e=s}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const O={init(t){t.scripts&&t.scripts.length&&importScripts.apply(void 0,t.scripts);const e=t.options;self.initCodec&&self.initCodec(),e.codecType.startsWith(I)?e.codecConstructor=self.Deflate:e.codecType.startsWith(k)&&(e.codecConstructor=self.Inflate),E=function(t){return t.codecType.startsWith(I)?new j(t):t.codecType.startsWith(k)?new C(t):void 0}(e)},append:async t=>({data:await E.append(t.data)}),flush:()=>E.flush()};let E;addEventListener("message",(async t=>{const e=t.data,n=e.type,s=O[n];if(s)try{const t=await s(e)||{};if(t.type=n,t.data)try{postMessage(t,[t.data.buffer])}catch(e){postMessage(t)}else postMessage(t)}catch(t){postMessage({type:n,error:{message:t.message,stack:t.stack}})}}));const K="function";function T(t,e){return class{constructor(n){const s=t=>{if(this.pendingData){const e=this.pendingData;this.pendingData=new Uint8Array(e.length+t.length),this.pendingData.set(e,0),this.pendingData.set(t,e.length)}else this.pendingData=new Uint8Array(t)};if(this.codec=new t(Object.assign({},e,n)),typeof this.codec.onData==K)this.codec.onData=s;else{if(typeof this.codec.on!=K)throw new Error("Cannot register the callback function");this.codec.on("data",s)}}async append(t){return this.codec.push(t),n(this)}async flush(){return this.codec.push(new Uint8Array(0),!0),n(this)}};function n(t){if(t.pendingData){const e=t.pendingData;return t.pendingData=null,e}return new Uint8Array(0)}}self.initCodec=()=>{const{Deflate:t,Inflate:e}=((t,e={})=>({Deflate:T(t.Deflate,e.deflate),Inflate:T(t.Inflate,e.inflate)}))(pako,{deflate:{raw:!0},inflate:{raw:!0}});self.Deflate=t,self.Inflate=e}}(); |
@@ -1,1 +0,1 @@ | ||
!function(){"use strict";class t{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let s=0,i=0|t.length;s<i;s++)n=n>>>8^e[255&(n^t[s])];this.crc=n}get(){return~this.crc}}const e="Invalid pasword",n=16,s="raw",i={name:"PBKDF2"},r={name:"HMAC"},a="SHA-1",c={name:"AES-CTR"},h=Object.assign({hash:r},i),p=Object.assign({iterations:1e3,hash:{name:a}},i),o=Object.assign({hash:a},r),u=Object.assign({length:n},c),d=["deriveBits"],y=["sign"],l=528,g=10,w=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=crypto.subtle;class b{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const i=async(e=0)=>{if(e+n<=a.length-g){const t=a.subarray(e,e+n),s=await f.decrypt(Object.assign({counter:this.counter},u),this.keys.decrypt,t);return U(this.counter),r.set(new Uint8Array(s),e),i(e+n)}return this.pendingInput=a.subarray(e),this.signed&&(this.input=m(this.input,t)),r};if(this.password){const n=t.subarray(0,18);await async function(t,n,i){t.counter=new Uint8Array(w);const r=n.subarray(0,16),a=n.subarray(16),u=(new TextEncoder).encode(i),l=await f.importKey(s,u,h,!1,d),g=await f.deriveBits(Object.assign({salt:r},p),l,528),b=new Uint8Array(g),A=b.subarray(64);if(t.keys={decrypt:await f.importKey(s,b.subarray(0,32),c,!0,["decrypt"]),authentication:await f.importKey(s,b.subarray(32,64),o,!1,y),passwordVerification:A},A[0]!=a[0]||A[1]!=a[1])throw new Error(e)}(this,n,this.password),this.password=null,t=t.subarray(18)}let r=new Uint8Array(t.length-g-(t.length-g)%n),a=t;return this.pendingInput.length&&(a=m(this.pendingInput,t),r=I(r,a.length-g-(a.length-g)%n)),i()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-g),s=t.subarray(t.length-g);let i=new Uint8Array(0);if(n.length){const t=await f.decrypt(Object.assign({counter:this.counter},u),e.decrypt,n);i=new Uint8Array(t)}let a=!0;if(this.signed){const t=await f.sign(r,e.authentication,this.input.subarray(0,this.input.length-g)),n=new Uint8Array(t);this.input=null;for(let t=0;t<g;t++)n[t]!=s[t]&&(a=!1)}return{valid:a,data:i}}}class A{constructor(t){this.password=t,this.output=new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(s=0)=>{if(s+n<=t.length){const a=t.subarray(s,s+n),c=await f.encrypt(Object.assign({counter:this.counter},u),this.keys.encrypt,a);return U(this.counter),r.set(new Uint8Array(c),s+i.length),e(s+n)}return this.pendingInput=t.subarray(s),this.output=m(this.output,r),r};let i=new Uint8Array(0);this.password&&(i=await async function(t,e){t.counter=new Uint8Array(w);const n=crypto.getRandomValues(new Uint8Array(16)),i=(new TextEncoder).encode(e),r=await f.importKey(s,i,h,!1,d),a=await f.deriveBits(Object.assign({salt:n},p),r,l),u=new Uint8Array(a);return t.keys={encrypt:await f.importKey(s,u.subarray(0,32),c,!0,["encrypt"]),authentication:await f.importKey(s,u.subarray(32,64),o,!1,y),passwordVerification:u.subarray(64)},m(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let r=new Uint8Array(i.length+t.length-t.length%n);return r.set(i,0),this.pendingInput.length&&(t=m(this.pendingInput,t),r=I(r,t.length-t.length%n)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await f.encrypt(Object.assign({counter:this.counter},u),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=m(this.output,t)}const e=await f.sign(r,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,g);return{data:m(t,n),signature:n}}}function U(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function m(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function I(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const v="Invalid signature";class k{constructor(e){this.signature=e.inputSignature,this.encrypted=Boolean(e.inputPassword),this.signed=e.inputSigned,this.compressed=e.inputCompressed,this.inflate=this.compressed&&new ZipInflate,this.crc32=this.signed&&this.signed&&new t,this.decrypt=this.encrypted&&new b(e.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error(v);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error(v)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class j{constructor(e){this.encrypted=e.outputEncrypted,this.signed=e.outputSigned,this.compressed=e.outputCompressed,this.deflate=this.compressed&&new ZipDeflate({level:e.level||5}),this.crc32=this.signed&&new t,this.encrypt=this.encrypted&&new A(e.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const s=new Uint8Array(e.length+n.data.length);s.set(e,0),s.set(n.data,e.length),e=s}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const E={init(t){t.scripts&&t.scripts.length&&importScripts.apply(void 0,t.scripts);const e=t.options;self.initExternalCodec&&self.initExternalCodec(),O=function(t){return t.codecType.startsWith("deflate")?new j(t):t.codecType.startsWith("inflate")?new k(t):void 0}(e)},append:async t=>({data:await O.append(t.data)}),flush:()=>O.flush()};let O;addEventListener("message",(async t=>{const e=t.data,n=e.type,s=E[n];if(s)try{const t=await s(e)||{};if(t.type=n,t.data)try{postMessage(t,[t.data.buffer])}catch(e){postMessage(t)}else postMessage(t)}catch(t){postMessage({type:n,error:{message:t.message,stack:t.stack}})}}))}(); | ||
!function(){"use strict";class t{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let i=0,a=0|t.length;i<a;i++)n=n>>>8^e[255&(n^t[i])];this.crc=n}get(){return~this.crc}}const e="Invalid pasword",n=16,i="raw",a={name:"PBKDF2"},r={name:"HMAC"},s="SHA-1",l={name:"AES-CTR"},o=Object.assign({hash:r},a),_=Object.assign({iterations:1e3,hash:{name:s}},a),d=Object.assign({hash:s},r),u=Object.assign({length:n},l),f=["deriveBits"],c=["sign"],h=528,b=10,w=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],x=crypto.subtle;class p{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const a=async(e=0)=>{if(e+n<=s.length-b){const t=s.subarray(e,e+n),i=await x.decrypt(Object.assign({counter:this.counter},u),this.keys.decrypt,t);return g(this.counter),r.set(new Uint8Array(i),e),a(e+n)}return this.pendingInput=s.subarray(e),this.signed&&(this.input=m(this.input,t)),r};if(this.password){const n=t.subarray(0,18);await async function(t,n,a){t.counter=new Uint8Array(w);const r=n.subarray(0,16),s=n.subarray(16),u=(new TextEncoder).encode(a),h=await x.importKey(i,u,o,!1,f),b=await x.deriveBits(Object.assign({salt:r},_),h,528),p=new Uint8Array(b),y=p.subarray(64);if(t.keys={decrypt:await x.importKey(i,p.subarray(0,32),l,!0,["decrypt"]),authentication:await x.importKey(i,p.subarray(32,64),d,!1,c),passwordVerification:y},y[0]!=s[0]||y[1]!=s[1])throw new Error(e)}(this,n,this.password),this.password=null,t=t.subarray(18)}let r=new Uint8Array(t.length-b-(t.length-b)%n),s=t;return this.pendingInput.length&&(s=m(this.pendingInput,t),r=v(r,s.length-b-(s.length-b)%n)),a()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-b),i=t.subarray(t.length-b);let a=new Uint8Array(0);if(n.length){const t=await x.decrypt(Object.assign({counter:this.counter},u),e.decrypt,n);a=new Uint8Array(t)}let s=!0;if(this.signed){const t=await x.sign(r,e.authentication,this.input.subarray(0,this.input.length-b)),n=new Uint8Array(t);this.input=null;for(let t=0;t<b;t++)n[t]!=i[t]&&(s=!1)}return{valid:s,data:a}}}class y{constructor(t){this.password=t,this.output=new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(i=0)=>{if(i+n<=t.length){const s=t.subarray(i,i+n),l=await x.encrypt(Object.assign({counter:this.counter},u),this.keys.encrypt,s);return g(this.counter),r.set(new Uint8Array(l),i+a.length),e(i+n)}return this.pendingInput=t.subarray(i),this.output=m(this.output,r),r};let a=new Uint8Array(0);this.password&&(a=await async function(t,e){t.counter=new Uint8Array(w);const n=crypto.getRandomValues(new Uint8Array(16)),a=(new TextEncoder).encode(e),r=await x.importKey(i,a,o,!1,f),s=await x.deriveBits(Object.assign({salt:n},_),r,h),u=new Uint8Array(s);return t.keys={encrypt:await x.importKey(i,u.subarray(0,32),l,!0,["encrypt"]),authentication:await x.importKey(i,u.subarray(32,64),d,!1,c),passwordVerification:u.subarray(64)},m(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let r=new Uint8Array(a.length+t.length-t.length%n);return r.set(a,0),this.pendingInput.length&&(t=m(this.pendingInput,t),r=v(r,t.length-t.length%n)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await x.encrypt(Object.assign({counter:this.counter},u),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=m(this.output,t)}const e=await x.sign(r,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,b);return{data:m(t,n),signature:n}}}function g(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function m(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function v(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const k="deflate",A="inflate",U="Invalid signature";class I{constructor(e){this.signature=e.inputSignature,this.encrypted=Boolean(e.inputPassword),this.signed=e.inputSigned,this.compressed=e.inputCompressed,this.inflate=this.compressed&&new e.codecConstructor,this.crc32=this.signed&&this.signed&&new t,this.decrypt=this.encrypted&&new p(e.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error(U);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error(U)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class E{constructor(e){this.encrypted=e.outputEncrypted,this.signed=e.outputSigned,this.compressed=e.outputCompressed,this.deflate=this.compressed&&new e.codecConstructor({level:e.level||5}),this.crc32=this.signed&&new t,this.encrypt=this.encrypted&&new y(e.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const i=new Uint8Array(e.length+n.data.length);i.set(e,0),i.set(n.data,e.length),e=i}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const S={init(t){t.scripts&&t.scripts.length&&importScripts.apply(void 0,t.scripts);const e=t.options;self.initCodec&&self.initCodec(),e.codecType.startsWith(k)?e.codecConstructor=self.Deflate:e.codecType.startsWith(A)&&(e.codecConstructor=self.Inflate),C=function(t){return t.codecType.startsWith(k)?new E(t):t.codecType.startsWith(A)?new I(t):void 0}(e)},append:async t=>({data:await C.append(t.data)}),flush:()=>C.flush()};let C;addEventListener("message",(async t=>{const e=t.data,n=e.type,i=S[n];if(i)try{const t=await i(e)||{};if(t.type=n,t.data)try{postMessage(t,[t.data.buffer])}catch(e){postMessage(t)}else postMessage(t)}catch(t){postMessage({type:n,error:{message:t.message,stack:t.stack}})}}));const M=256,j=256,D=-2,O=-5,P=[0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,0,0,16,17,18,18,19,19,20,20,20,20,21,21,21,21,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29];function K(){const t=this;function e(t,e){let n=0;do{n|=1&t,t>>>=1,n<<=1}while(--e>0);return n>>>1}t.build_tree=function(n){const i=t.dyn_tree,a=t.stat_desc.static_tree,r=t.stat_desc.elems;let s,l,o,_=-1;for(n.heap_len=0,n.heap_max=573,s=0;s<r;s++)0!==i[2*s]?(n.heap[++n.heap_len]=_=s,n.depth[s]=0):i[2*s+1]=0;for(;n.heap_len<2;)o=n.heap[++n.heap_len]=_<2?++_:0,i[2*o]=1,n.depth[o]=0,n.opt_len--,a&&(n.static_len-=a[2*o+1]);for(t.max_code=_,s=Math.floor(n.heap_len/2);s>=1;s--)n.pqdownheap(i,s);o=r;do{s=n.heap[1],n.heap[1]=n.heap[n.heap_len--],n.pqdownheap(i,1),l=n.heap[1],n.heap[--n.heap_max]=s,n.heap[--n.heap_max]=l,i[2*o]=i[2*s]+i[2*l],n.depth[o]=Math.max(n.depth[s],n.depth[l])+1,i[2*s+1]=i[2*l+1]=o,n.heap[1]=o++,n.pqdownheap(i,1)}while(n.heap_len>=2);n.heap[--n.heap_max]=n.heap[1],function(e){const n=t.dyn_tree,i=t.stat_desc.static_tree,a=t.stat_desc.extra_bits,r=t.stat_desc.extra_base,s=t.stat_desc.max_length;let l,o,_,d,u,f,c=0;for(d=0;d<=15;d++)e.bl_count[d]=0;for(n[2*e.heap[e.heap_max]+1]=0,l=e.heap_max+1;l<573;l++)o=e.heap[l],d=n[2*n[2*o+1]+1]+1,d>s&&(d=s,c++),n[2*o+1]=d,o>t.max_code||(e.bl_count[d]++,u=0,o>=r&&(u=a[o-r]),f=n[2*o],e.opt_len+=f*(d+u),i&&(e.static_len+=f*(i[2*o+1]+u)));if(0!==c){do{for(d=s-1;0===e.bl_count[d];)d--;e.bl_count[d]--,e.bl_count[d+1]+=2,e.bl_count[s]--,c-=2}while(c>0);for(d=s;0!==d;d--)for(o=e.bl_count[d];0!==o;)_=e.heap[--l],_>t.max_code||(n[2*_+1]!=d&&(e.opt_len+=(d-n[2*_+1])*n[2*_],n[2*_+1]=d),o--)}}(n),function(t,n,i){const a=[];let r,s,l,o=0;for(r=1;r<=15;r++)a[r]=o=o+i[r-1]<<1;for(s=0;s<=n;s++)l=t[2*s+1],0!==l&&(t[2*s]=e(a[l]++,l))}(i,t.max_code,n.bl_count)}}function T(t,e,n,i,a){const r=this;r.static_tree=t,r.extra_bits=e,r.extra_base=n,r.elems=i,r.max_length=a}K._length_code=[0,1,2,3,4,5,6,7,8,8,9,9,10,10,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28],K.base_length=[0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224,0],K.base_dist=[0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576],K.d_code=function(t){return t<256?P[t]:P[256+(t>>>7)]},K.extra_lbits=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],K.extra_dbits=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],K.extra_blbits=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],K.bl_order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],T.static_ltree=[12,8,140,8,76,8,204,8,44,8,172,8,108,8,236,8,28,8,156,8,92,8,220,8,60,8,188,8,124,8,252,8,2,8,130,8,66,8,194,8,34,8,162,8,98,8,226,8,18,8,146,8,82,8,210,8,50,8,178,8,114,8,242,8,10,8,138,8,74,8,202,8,42,8,170,8,106,8,234,8,26,8,154,8,90,8,218,8,58,8,186,8,122,8,250,8,6,8,134,8,70,8,198,8,38,8,166,8,102,8,230,8,22,8,150,8,86,8,214,8,54,8,182,8,118,8,246,8,14,8,142,8,78,8,206,8,46,8,174,8,110,8,238,8,30,8,158,8,94,8,222,8,62,8,190,8,126,8,254,8,1,8,129,8,65,8,193,8,33,8,161,8,97,8,225,8,17,8,145,8,81,8,209,8,49,8,177,8,113,8,241,8,9,8,137,8,73,8,201,8,41,8,169,8,105,8,233,8,25,8,153,8,89,8,217,8,57,8,185,8,121,8,249,8,5,8,133,8,69,8,197,8,37,8,165,8,101,8,229,8,21,8,149,8,85,8,213,8,53,8,181,8,117,8,245,8,13,8,141,8,77,8,205,8,45,8,173,8,109,8,237,8,29,8,157,8,93,8,221,8,61,8,189,8,125,8,253,8,19,9,275,9,147,9,403,9,83,9,339,9,211,9,467,9,51,9,307,9,179,9,435,9,115,9,371,9,243,9,499,9,11,9,267,9,139,9,395,9,75,9,331,9,203,9,459,9,43,9,299,9,171,9,427,9,107,9,363,9,235,9,491,9,27,9,283,9,155,9,411,9,91,9,347,9,219,9,475,9,59,9,315,9,187,9,443,9,123,9,379,9,251,9,507,9,7,9,263,9,135,9,391,9,71,9,327,9,199,9,455,9,39,9,295,9,167,9,423,9,103,9,359,9,231,9,487,9,23,9,279,9,151,9,407,9,87,9,343,9,215,9,471,9,55,9,311,9,183,9,439,9,119,9,375,9,247,9,503,9,15,9,271,9,143,9,399,9,79,9,335,9,207,9,463,9,47,9,303,9,175,9,431,9,111,9,367,9,239,9,495,9,31,9,287,9,159,9,415,9,95,9,351,9,223,9,479,9,63,9,319,9,191,9,447,9,127,9,383,9,255,9,511,9,0,7,64,7,32,7,96,7,16,7,80,7,48,7,112,7,8,7,72,7,40,7,104,7,24,7,88,7,56,7,120,7,4,7,68,7,36,7,100,7,20,7,84,7,52,7,116,7,3,8,131,8,67,8,195,8,35,8,163,8,99,8,227,8],T.static_dtree=[0,5,16,5,8,5,24,5,4,5,20,5,12,5,28,5,2,5,18,5,10,5,26,5,6,5,22,5,14,5,30,5,1,5,17,5,9,5,25,5,5,5,21,5,13,5,29,5,3,5,19,5,11,5,27,5,7,5,23,5],T.static_l_desc=new T(T.static_ltree,K.extra_lbits,257,286,15),T.static_d_desc=new T(T.static_dtree,K.extra_dbits,0,30,15),T.static_bl_desc=new T(null,K.extra_blbits,0,19,7);function B(t,e,n,i,a){const r=this;r.good_length=t,r.max_lazy=e,r.nice_length=n,r.max_chain=i,r.func=a}const V=[new B(0,0,0,0,0),new B(4,4,8,4,1),new B(4,5,16,8,1),new B(4,6,32,32,1),new B(4,4,16,16,2),new B(8,16,32,32,2),new B(8,16,128,128,2),new B(8,32,128,256,2),new B(32,128,258,1024,2),new B(32,258,258,4096,2)],q=["need dictionary","stream end","","","stream error","data error","","buffer error","",""],z=113,W=666,H=258,R=262;function F(t,e,n,i){const a=t[2*e],r=t[2*n];return a<r||a==r&&i[e]<=i[n]}function L(){const t=this;let e,n,i,a,r,s,l,o,_,d,u,f,c,h,b,w,x,p,y,g,m,v,k,A,U,I,E,S,C,P,B,L,G;const J=new K,N=new K,Q=new K;let X,Y,Z,$,tt,et,nt,it;function at(){let e;for(e=0;e<286;e++)B[2*e]=0;for(e=0;e<30;e++)L[2*e]=0;for(e=0;e<19;e++)G[2*e]=0;B[512]=1,t.opt_len=t.static_len=0,Z=tt=0}function rt(t,e){let n,i=-1,a=t[1],r=0,s=7,l=4;0===a&&(s=138,l=3),t[2*(e+1)+1]=65535;for(let o=0;o<=e;o++)n=a,a=t[2*(o+1)+1],++r<s&&n==a||(r<l?G[2*n]+=r:0!==n?(n!=i&&G[2*n]++,G[32]++):r<=10?G[34]++:G[36]++,r=0,i=n,0===a?(s=138,l=3):n==a?(s=6,l=3):(s=7,l=4))}function st(e){t.pending_buf[t.pending++]=e}function lt(t){st(255&t),st(t>>>8&255)}function ot(t,e){let n;const i=e;it>16-i?(n=t,nt|=n<<it&65535,lt(nt),nt=n>>>16-it,it+=i-16):(nt|=t<<it&65535,it+=i)}function _t(t,e){const n=2*t;ot(65535&e[n],65535&e[n+1])}function dt(t,e){let n,i,a=-1,r=t[1],s=0,l=7,o=4;for(0===r&&(l=138,o=3),n=0;n<=e;n++)if(i=r,r=t[2*(n+1)+1],!(++s<l&&i==r)){if(s<o)do{_t(i,G)}while(0!=--s);else 0!==i?(i!=a&&(_t(i,G),s--),_t(16,G),ot(s-3,2)):s<=10?(_t(17,G),ot(s-3,3)):(_t(18,G),ot(s-11,7));s=0,a=i,0===r?(l=138,o=3):i==r?(l=6,o=3):(l=7,o=4)}}function ut(){16==it?(lt(nt),nt=0,it=0):it>=8&&(st(255&nt),nt>>>=8,it-=8)}function ft(e,n){let i,a,r;if(t.pending_buf[$+2*Z]=e>>>8&255,t.pending_buf[$+2*Z+1]=255&e,t.pending_buf[X+Z]=255&n,Z++,0===e?B[2*n]++:(tt++,e--,B[2*(K._length_code[n]+M+1)]++,L[2*K.d_code(e)]++),0==(8191&Z)&&E>2){for(i=8*Z,a=m-x,r=0;r<30;r++)i+=L[2*r]*(5+K.extra_dbits[r]);if(i>>>=3,tt<Math.floor(Z/2)&&i<Math.floor(a/2))return!0}return Z==Y-1}function ct(e,n){let i,a,r,s,l=0;if(0!==Z)do{i=t.pending_buf[$+2*l]<<8&65280|255&t.pending_buf[$+2*l+1],a=255&t.pending_buf[X+l],l++,0===i?_t(a,e):(r=K._length_code[a],_t(r+M+1,e),s=K.extra_lbits[r],0!==s&&(a-=K.base_length[r],ot(a,s)),i--,r=K.d_code(i),_t(r,n),s=K.extra_dbits[r],0!==s&&(i-=K.base_dist[r],ot(i,s)))}while(l<Z);_t(j,e),et=e[513]}function ht(){it>8?lt(nt):it>0&&st(255&nt),nt=0,it=0}function bt(e,n,i){ot(0+(i?1:0),3),function(e,n,i){ht(),et=8,i&&(lt(n),lt(~n)),t.pending_buf.set(o.subarray(e,e+n),t.pending),t.pending+=n}(e,n,!0)}function wt(e,n,i){let a,r,s=0;E>0?(J.build_tree(t),N.build_tree(t),s=function(){let e;for(rt(B,J.max_code),rt(L,N.max_code),Q.build_tree(t),e=18;e>=3&&0===G[2*K.bl_order[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(),a=t.opt_len+3+7>>>3,r=t.static_len+3+7>>>3,r<=a&&(a=r)):a=r=n+5,n+4<=a&&-1!=e?bt(e,n,i):r==a?(ot(2+(i?1:0),3),ct(T.static_ltree,T.static_dtree)):(ot(4+(i?1:0),3),function(t,e,n){let i;for(ot(t-257,5),ot(e-1,5),ot(n-4,4),i=0;i<n;i++)ot(G[2*K.bl_order[i]+1],3);dt(B,t-1),dt(L,e-1)}(J.max_code+1,N.max_code+1,s+1),ct(B,L)),at(),i&&ht()}function xt(t){wt(x>=0?x:-1,m-x,t),x=m,e.flush_pending()}function pt(){let t,n,i,a;do{if(a=_-k-m,0===a&&0===m&&0===k)a=r;else if(-1==a)a--;else if(m>=r+r-R){o.set(o.subarray(r,r+r),0),v-=r,m-=r,x-=r,t=c,i=t;do{n=65535&u[--i],u[i]=n>=r?n-r:0}while(0!=--t);t=r,i=t;do{n=65535&d[--i],d[i]=n>=r?n-r:0}while(0!=--t);a+=r}if(0===e.avail_in)return;t=e.read_buf(o,m+k,a),k+=t,k>=3&&(f=255&o[m],f=(f<<w^255&o[m+1])&b)}while(k<R&&0!==e.avail_in)}function yt(t){let e,n,i=U,a=m,s=A;const _=m>r-R?m-(r-R):0;let u=P;const f=l,c=m+H;let h=o[a+s-1],b=o[a+s];A>=C&&(i>>=2),u>k&&(u=k);do{if(e=t,o[e+s]==b&&o[e+s-1]==h&&o[e]==o[a]&&o[++e]==o[a+1]){a+=2,e++;do{}while(o[++a]==o[++e]&&o[++a]==o[++e]&&o[++a]==o[++e]&&o[++a]==o[++e]&&o[++a]==o[++e]&&o[++a]==o[++e]&&o[++a]==o[++e]&&o[++a]==o[++e]&&a<c);if(n=H-(c-a),a=c-H,n>s){if(v=t,s=n,n>=u)break;h=o[a+s-1],b=o[a+s]}}}while((t=65535&d[t&f])>_&&0!=--i);return s<=k?s:k}function gt(e){return e.total_in=e.total_out=0,e.msg=null,t.pending=0,t.pending_out=0,n=z,a=0,J.dyn_tree=B,J.stat_desc=T.static_l_desc,N.dyn_tree=L,N.stat_desc=T.static_d_desc,Q.dyn_tree=G,Q.stat_desc=T.static_bl_desc,nt=0,it=0,et=8,at(),function(){_=2*r,u[c-1]=0;for(let t=0;t<c-1;t++)u[t]=0;I=V[E].max_lazy,C=V[E].good_length,P=V[E].nice_length,U=V[E].max_chain,m=0,x=0,k=0,p=A=2,g=0,f=0}(),0}t.depth=[],t.bl_count=[],t.heap=[],B=[],L=[],G=[],t.pqdownheap=function(e,n){const i=t.heap,a=i[n];let r=n<<1;for(;r<=t.heap_len&&(r<t.heap_len&&F(e,i[r+1],i[r],t.depth)&&r++,!F(e,a,i[r],t.depth));)i[n]=i[r],n=r,r<<=1;i[n]=a},t.deflateInit=function(e,n,a,_,f,x){return _||(_=8),f||(f=8),x||(x=0),e.msg=null,-1==n&&(n=6),f<1||f>9||8!=_||a<9||a>15||n<0||n>9||x<0||x>2?D:(e.dstate=t,s=a,r=1<<s,l=r-1,h=f+7,c=1<<h,b=c-1,w=Math.floor((h+3-1)/3),o=new Uint8Array(2*r),d=[],u=[],Y=1<<f+6,t.pending_buf=new Uint8Array(4*Y),i=4*Y,$=Math.floor(Y/2),X=3*Y,E=n,S=x,gt(e))},t.deflateEnd=function(){return 42!=n&&n!=z&&n!=W?D:(t.pending_buf=null,u=null,d=null,o=null,t.dstate=null,n==z?-3:0)},t.deflateParams=function(t,e,n){let i=0;return-1==e&&(e=6),e<0||e>9||n<0||n>2?D:(V[E].func!=V[e].func&&0!==t.total_in&&(i=t.deflate(1)),E!=e&&(E=e,I=V[E].max_lazy,C=V[E].good_length,P=V[E].nice_length,U=V[E].max_chain),S=n,i)},t.deflateSetDictionary=function(t,e,i){let a,s=i,_=0;if(!e||42!=n)return D;if(s<3)return 0;for(s>r-R&&(s=r-R,_=i-s),o.set(e.subarray(_,_+s),0),m=s,x=s,f=255&o[0],f=(f<<w^255&o[1])&b,a=0;a<=s-3;a++)f=(f<<w^255&o[a+2])&b,d[a&l]=u[f],u[f]=a;return 0},t.deflate=function(_,h){let U,C,M,P,K;if(h>4||h<0)return D;if(!_.next_out||!_.next_in&&0!==_.avail_in||n==W&&4!=h)return _.msg=q[4],D;if(0===_.avail_out)return _.msg=q[7],O;var B;if(e=_,P=a,a=h,42==n&&(C=8+(s-8<<4)<<8,M=(E-1&255)>>1,M>3&&(M=3),C|=M<<6,0!==m&&(C|=32),C+=31-C%31,n=z,st((B=C)>>8&255),st(255&B)),0!==t.pending){if(e.flush_pending(),0===e.avail_out)return a=-1,0}else if(0===e.avail_in&&h<=P&&4!=h)return e.msg=q[7],O;if(n==W&&0!==e.avail_in)return _.msg=q[7],O;if(0!==e.avail_in||0!==k||0!=h&&n!=W){switch(K=-1,V[E].func){case 0:K=function(t){let n,a=65535;for(a>i-5&&(a=i-5);;){if(k<=1){if(pt(),0===k&&0==t)return 0;if(0===k)break}if(m+=k,k=0,n=x+a,(0===m||m>=n)&&(k=m-n,m=n,xt(!1),0===e.avail_out))return 0;if(m-x>=r-R&&(xt(!1),0===e.avail_out))return 0}return xt(4==t),0===e.avail_out?4==t?2:0:4==t?3:1}(h);break;case 1:K=function(t){let n,i=0;for(;;){if(k<R){if(pt(),k<R&&0==t)return 0;if(0===k)break}if(k>=3&&(f=(f<<w^255&o[m+2])&b,i=65535&u[f],d[m&l]=u[f],u[f]=m),0!==i&&(m-i&65535)<=r-R&&2!=S&&(p=yt(i)),p>=3)if(n=ft(m-v,p-3),k-=p,p<=I&&k>=3){p--;do{m++,f=(f<<w^255&o[m+2])&b,i=65535&u[f],d[m&l]=u[f],u[f]=m}while(0!=--p);m++}else m+=p,p=0,f=255&o[m],f=(f<<w^255&o[m+1])&b;else n=ft(0,255&o[m]),k--,m++;if(n&&(xt(!1),0===e.avail_out))return 0}return xt(4==t),0===e.avail_out?4==t?2:0:4==t?3:1}(h);break;case 2:K=function(t){let n,i,a=0;for(;;){if(k<R){if(pt(),k<R&&0==t)return 0;if(0===k)break}if(k>=3&&(f=(f<<w^255&o[m+2])&b,a=65535&u[f],d[m&l]=u[f],u[f]=m),A=p,y=v,p=2,0!==a&&A<I&&(m-a&65535)<=r-R&&(2!=S&&(p=yt(a)),p<=5&&(1==S||3==p&&m-v>4096)&&(p=2)),A>=3&&p<=A){i=m+k-3,n=ft(m-1-y,A-3),k-=A-1,A-=2;do{++m<=i&&(f=(f<<w^255&o[m+2])&b,a=65535&u[f],d[m&l]=u[f],u[f]=m)}while(0!=--A);if(g=0,p=2,m++,n&&(xt(!1),0===e.avail_out))return 0}else if(0!==g){if(n=ft(0,255&o[m-1]),n&&xt(!1),m++,k--,0===e.avail_out)return 0}else g=1,m++,k--}return 0!==g&&(n=ft(0,255&o[m-1]),g=0),xt(4==t),0===e.avail_out?4==t?2:0:4==t?3:1}(h)}if(2!=K&&3!=K||(n=W),0==K||2==K)return 0===e.avail_out&&(a=-1),0;if(1==K){if(1==h)ot(2,3),_t(j,T.static_ltree),ut(),1+et+10-it<9&&(ot(2,3),_t(j,T.static_ltree),ut()),et=7;else if(bt(0,0,!1),3==h)for(U=0;U<c;U++)u[U]=0;if(e.flush_pending(),0===e.avail_out)return a=-1,0}}return 4!=h?0:1}}function G(){const t=this;t.next_in_index=0,t.next_out_index=0,t.avail_in=0,t.total_in=0,t.avail_out=0,t.total_out=0}function J(t){const e=new G,n=512,i=new Uint8Array(n);let a=t?t.level:-1;void 0===a&&(a=-1),e.deflateInit(a),e.next_out=i,this.append=function(t,a){let r,s,l=0,o=0,_=0;const d=[];if(t.length){e.next_in_index=0,e.next_in=t,e.avail_in=t.length;do{if(e.next_out_index=0,e.avail_out=n,r=e.deflate(0),0!=r)throw new Error("deflating: "+e.msg);e.next_out_index&&(e.next_out_index==n?d.push(new Uint8Array(i)):d.push(new Uint8Array(i.subarray(0,e.next_out_index)))),_+=e.next_out_index,a&&e.next_in_index>0&&e.next_in_index!=l&&(a(e.next_in_index),l=e.next_in_index)}while(e.avail_in>0||0===e.avail_out);return s=new Uint8Array(_),d.forEach((function(t){s.set(t,o),o+=t.length})),s}},this.flush=function(){let t,a,r=0,s=0;const l=[];do{if(e.next_out_index=0,e.avail_out=n,t=e.deflate(4),1!=t&&0!=t)throw new Error("deflating: "+e.msg);n-e.avail_out>0&&l.push(new Uint8Array(i.subarray(0,e.next_out_index))),s+=e.next_out_index}while(e.avail_in>0||0===e.avail_out);return e.deflateEnd(),a=new Uint8Array(s),l.forEach((function(t){a.set(t,r),r+=t.length})),a}}G.prototype={deflateInit:function(t,e){const n=this;return n.dstate=new L,e||(e=15),n.dstate.deflateInit(n,t,e)},deflate:function(t){const e=this;return e.dstate?e.dstate.deflate(e,t):D},deflateEnd:function(){const t=this;if(!t.dstate)return D;const e=t.dstate.deflateEnd();return t.dstate=null,e},deflateParams:function(t,e){const n=this;return n.dstate?n.dstate.deflateParams(n,t,e):D},deflateSetDictionary:function(t,e){const n=this;return n.dstate?n.dstate.deflateSetDictionary(n,t,e):D},read_buf:function(t,e,n){const i=this;let a=i.avail_in;return a>n&&(a=n),0===a?0:(i.avail_in-=a,t.set(i.next_in.subarray(i.next_in_index,i.next_in_index+a),e),i.next_in_index+=a,i.total_in+=a,a)},flush_pending:function(){const t=this;let e=t.dstate.pending;e>t.avail_out&&(e=t.avail_out),0!==e&&(t.next_out.set(t.dstate.pending_buf.subarray(t.dstate.pending_out,t.dstate.pending_out+e),t.next_out_index),t.next_out_index+=e,t.dstate.pending_out+=e,t.total_out+=e,t.avail_out-=e,t.dstate.pending-=e,0===t.dstate.pending&&(t.dstate.pending_out=0))}};const N=-2,Q=-3,X=-5,Y=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Z=[96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,192,80,7,10,0,8,96,0,8,32,0,9,160,0,8,0,0,8,128,0,8,64,0,9,224,80,7,6,0,8,88,0,8,24,0,9,144,83,7,59,0,8,120,0,8,56,0,9,208,81,7,17,0,8,104,0,8,40,0,9,176,0,8,8,0,8,136,0,8,72,0,9,240,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,200,81,7,13,0,8,100,0,8,36,0,9,168,0,8,4,0,8,132,0,8,68,0,9,232,80,7,8,0,8,92,0,8,28,0,9,152,84,7,83,0,8,124,0,8,60,0,9,216,82,7,23,0,8,108,0,8,44,0,9,184,0,8,12,0,8,140,0,8,76,0,9,248,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,196,81,7,11,0,8,98,0,8,34,0,9,164,0,8,2,0,8,130,0,8,66,0,9,228,80,7,7,0,8,90,0,8,26,0,9,148,84,7,67,0,8,122,0,8,58,0,9,212,82,7,19,0,8,106,0,8,42,0,9,180,0,8,10,0,8,138,0,8,74,0,9,244,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,204,81,7,15,0,8,102,0,8,38,0,9,172,0,8,6,0,8,134,0,8,70,0,9,236,80,7,9,0,8,94,0,8,30,0,9,156,84,7,99,0,8,126,0,8,62,0,9,220,82,7,27,0,8,110,0,8,46,0,9,188,0,8,14,0,8,142,0,8,78,0,9,252,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,194,80,7,10,0,8,97,0,8,33,0,9,162,0,8,1,0,8,129,0,8,65,0,9,226,80,7,6,0,8,89,0,8,25,0,9,146,83,7,59,0,8,121,0,8,57,0,9,210,81,7,17,0,8,105,0,8,41,0,9,178,0,8,9,0,8,137,0,8,73,0,9,242,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,202,81,7,13,0,8,101,0,8,37,0,9,170,0,8,5,0,8,133,0,8,69,0,9,234,80,7,8,0,8,93,0,8,29,0,9,154,84,7,83,0,8,125,0,8,61,0,9,218,82,7,23,0,8,109,0,8,45,0,9,186,0,8,13,0,8,141,0,8,77,0,9,250,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,198,81,7,11,0,8,99,0,8,35,0,9,166,0,8,3,0,8,131,0,8,67,0,9,230,80,7,7,0,8,91,0,8,27,0,9,150,84,7,67,0,8,123,0,8,59,0,9,214,82,7,19,0,8,107,0,8,43,0,9,182,0,8,11,0,8,139,0,8,75,0,9,246,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,206,81,7,15,0,8,103,0,8,39,0,9,174,0,8,7,0,8,135,0,8,71,0,9,238,80,7,9,0,8,95,0,8,31,0,9,158,84,7,99,0,8,127,0,8,63,0,9,222,82,7,27,0,8,111,0,8,47,0,9,190,0,8,15,0,8,143,0,8,79,0,9,254,96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,193,80,7,10,0,8,96,0,8,32,0,9,161,0,8,0,0,8,128,0,8,64,0,9,225,80,7,6,0,8,88,0,8,24,0,9,145,83,7,59,0,8,120,0,8,56,0,9,209,81,7,17,0,8,104,0,8,40,0,9,177,0,8,8,0,8,136,0,8,72,0,9,241,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,201,81,7,13,0,8,100,0,8,36,0,9,169,0,8,4,0,8,132,0,8,68,0,9,233,80,7,8,0,8,92,0,8,28,0,9,153,84,7,83,0,8,124,0,8,60,0,9,217,82,7,23,0,8,108,0,8,44,0,9,185,0,8,12,0,8,140,0,8,76,0,9,249,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,197,81,7,11,0,8,98,0,8,34,0,9,165,0,8,2,0,8,130,0,8,66,0,9,229,80,7,7,0,8,90,0,8,26,0,9,149,84,7,67,0,8,122,0,8,58,0,9,213,82,7,19,0,8,106,0,8,42,0,9,181,0,8,10,0,8,138,0,8,74,0,9,245,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,205,81,7,15,0,8,102,0,8,38,0,9,173,0,8,6,0,8,134,0,8,70,0,9,237,80,7,9,0,8,94,0,8,30,0,9,157,84,7,99,0,8,126,0,8,62,0,9,221,82,7,27,0,8,110,0,8,46,0,9,189,0,8,14,0,8,142,0,8,78,0,9,253,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,195,80,7,10,0,8,97,0,8,33,0,9,163,0,8,1,0,8,129,0,8,65,0,9,227,80,7,6,0,8,89,0,8,25,0,9,147,83,7,59,0,8,121,0,8,57,0,9,211,81,7,17,0,8,105,0,8,41,0,9,179,0,8,9,0,8,137,0,8,73,0,9,243,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,203,81,7,13,0,8,101,0,8,37,0,9,171,0,8,5,0,8,133,0,8,69,0,9,235,80,7,8,0,8,93,0,8,29,0,9,155,84,7,83,0,8,125,0,8,61,0,9,219,82,7,23,0,8,109,0,8,45,0,9,187,0,8,13,0,8,141,0,8,77,0,9,251,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,199,81,7,11,0,8,99,0,8,35,0,9,167,0,8,3,0,8,131,0,8,67,0,9,231,80,7,7,0,8,91,0,8,27,0,9,151,84,7,67,0,8,123,0,8,59,0,9,215,82,7,19,0,8,107,0,8,43,0,9,183,0,8,11,0,8,139,0,8,75,0,9,247,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,207,81,7,15,0,8,103,0,8,39,0,9,175,0,8,7,0,8,135,0,8,71,0,9,239,80,7,9,0,8,95,0,8,31,0,9,159,84,7,99,0,8,127,0,8,63,0,9,223,82,7,27,0,8,111,0,8,47,0,9,191,0,8,15,0,8,143,0,8,79,0,9,255],$=[80,5,1,87,5,257,83,5,17,91,5,4097,81,5,5,89,5,1025,85,5,65,93,5,16385,80,5,3,88,5,513,84,5,33,92,5,8193,82,5,9,90,5,2049,86,5,129,192,5,24577,80,5,2,87,5,385,83,5,25,91,5,6145,81,5,7,89,5,1537,85,5,97,93,5,24577,80,5,4,88,5,769,84,5,49,92,5,12289,82,5,13,90,5,3073,86,5,193,192,5,24577],tt=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],et=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,112,112],nt=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],it=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],at=15;function rt(){let t,e,n,i,a,r;function s(t,e,s,l,o,_,d,u,f,c,h){let b,w,x,p,y,g,m,v,k,A,U,I,E,S,C;A=0,y=s;do{n[t[e+A]]++,A++,y--}while(0!==y);if(n[0]==s)return d[0]=-1,u[0]=0,0;for(v=u[0],g=1;g<=at&&0===n[g];g++);for(m=g,v<g&&(v=g),y=at;0!==y&&0===n[y];y--);for(x=y,v>y&&(v=y),u[0]=v,S=1<<g;g<y;g++,S<<=1)if((S-=n[g])<0)return Q;if((S-=n[y])<0)return Q;for(n[y]+=S,r[1]=g=0,A=1,E=2;0!=--y;)r[E]=g+=n[A],E++,A++;y=0,A=0;do{0!==(g=t[e+A])&&(h[r[g]++]=y),A++}while(++y<s);for(s=r[x],r[0]=y=0,A=0,p=-1,I=-v,a[0]=0,U=0,C=0;m<=x;m++)for(b=n[m];0!=b--;){for(;m>I+v;){if(p++,I+=v,C=x-I,C=C>v?v:C,(w=1<<(g=m-I))>b+1&&(w-=b+1,E=m,g<C))for(;++g<C&&!((w<<=1)<=n[++E]);)w-=n[E];if(C=1<<g,c[0]+C>1440)return Q;a[p]=U=c[0],c[0]+=C,0!==p?(r[p]=y,i[0]=g,i[1]=v,g=y>>>I-v,i[2]=U-a[p-1]-g,f.set(i,3*(a[p-1]+g))):d[0]=U}for(i[1]=m-I,A>=s?i[0]=192:h[A]<l?(i[0]=h[A]<256?0:96,i[2]=h[A++]):(i[0]=_[h[A]-l]+16+64,i[2]=o[h[A++]-l]),w=1<<m-I,g=y>>>I;g<C;g+=w)f.set(i,3*(U+g));for(g=1<<m-1;0!=(y&g);g>>>=1)y^=g;for(y^=g,k=(1<<I)-1;(y&k)!=r[p];)p--,I-=v,k=(1<<I)-1}return 0!==S&&1!=x?X:0}function l(s){let l;for(t||(t=[],e=[],n=new Int32Array(16),i=[],a=new Int32Array(at),r=new Int32Array(16)),e.length<s&&(e=[]),l=0;l<s;l++)e[l]=0;for(l=0;l<16;l++)n[l]=0;for(l=0;l<3;l++)i[l]=0;a.set(n.subarray(0,at),0),r.set(n.subarray(0,16),0)}this.inflate_trees_bits=function(n,i,a,r,o){let _;return l(19),t[0]=0,_=s(n,0,19,19,null,null,a,i,r,t,e),_==Q?o.msg="oversubscribed dynamic bit lengths tree":_!=X&&0!==i[0]||(o.msg="incomplete dynamic bit lengths tree",_=Q),_},this.inflate_trees_dynamic=function(n,i,a,r,o,_,d,u,f){let c;return l(288),t[0]=0,c=s(a,0,n,257,tt,et,_,r,u,t,e),0!=c||0===r[0]?(c==Q?f.msg="oversubscribed literal/length tree":-4!=c&&(f.msg="incomplete literal/length tree",c=Q),c):(l(288),c=s(a,n,i,0,nt,it,d,o,u,t,e),0!=c||0===o[0]&&n>257?(c==Q?f.msg="oversubscribed distance tree":c==X?(f.msg="incomplete distance tree",c=Q):-4!=c&&(f.msg="empty distance tree with lengths",c=Q),c):0)}}rt.inflate_trees_fixed=function(t,e,n,i){return t[0]=9,e[0]=5,n[0]=Z,i[0]=$,0};function st(){const t=this;let e,n,i,a,r=0,s=0,l=0,o=0,_=0,d=0,u=0,f=0,c=0,h=0;function b(t,e,n,i,a,r,s,l){let o,_,d,u,f,c,h,b,w,x,p,y,g,m,v,k;h=l.next_in_index,b=l.avail_in,f=s.bitb,c=s.bitk,w=s.write,x=w<s.read?s.read-w-1:s.end-w,p=Y[t],y=Y[e];do{for(;c<20;)b--,f|=(255&l.read_byte(h++))<<c,c+=8;if(o=f&p,_=n,d=i,k=3*(d+o),0!==(u=_[k]))for(;;){if(f>>=_[k+1],c-=_[k+1],0!=(16&u)){for(u&=15,g=_[k+2]+(f&Y[u]),f>>=u,c-=u;c<15;)b--,f|=(255&l.read_byte(h++))<<c,c+=8;for(o=f&y,_=a,d=r,k=3*(d+o),u=_[k];;){if(f>>=_[k+1],c-=_[k+1],0!=(16&u)){for(u&=15;c<u;)b--,f|=(255&l.read_byte(h++))<<c,c+=8;if(m=_[k+2]+(f&Y[u]),f>>=u,c-=u,x-=g,w>=m)v=w-m,w-v>0&&2>w-v?(s.window[w++]=s.window[v++],s.window[w++]=s.window[v++],g-=2):(s.window.set(s.window.subarray(v,v+2),w),w+=2,v+=2,g-=2);else{v=w-m;do{v+=s.end}while(v<0);if(u=s.end-v,g>u){if(g-=u,w-v>0&&u>w-v)do{s.window[w++]=s.window[v++]}while(0!=--u);else s.window.set(s.window.subarray(v,v+u),w),w+=u,v+=u,u=0;v=0}}if(w-v>0&&g>w-v)do{s.window[w++]=s.window[v++]}while(0!=--g);else s.window.set(s.window.subarray(v,v+g),w),w+=g,v+=g,g=0;break}if(0!=(64&u))return l.msg="invalid distance code",g=l.avail_in-b,g=c>>3<g?c>>3:g,b+=g,h-=g,c-=g<<3,s.bitb=f,s.bitk=c,l.avail_in=b,l.total_in+=h-l.next_in_index,l.next_in_index=h,s.write=w,Q;o+=_[k+2],o+=f&Y[u],k=3*(d+o),u=_[k]}break}if(0!=(64&u))return 0!=(32&u)?(g=l.avail_in-b,g=c>>3<g?c>>3:g,b+=g,h-=g,c-=g<<3,s.bitb=f,s.bitk=c,l.avail_in=b,l.total_in+=h-l.next_in_index,l.next_in_index=h,s.write=w,1):(l.msg="invalid literal/length code",g=l.avail_in-b,g=c>>3<g?c>>3:g,b+=g,h-=g,c-=g<<3,s.bitb=f,s.bitk=c,l.avail_in=b,l.total_in+=h-l.next_in_index,l.next_in_index=h,s.write=w,Q);if(o+=_[k+2],o+=f&Y[u],k=3*(d+o),0===(u=_[k])){f>>=_[k+1],c-=_[k+1],s.window[w++]=_[k+2],x--;break}}else f>>=_[k+1],c-=_[k+1],s.window[w++]=_[k+2],x--}while(x>=258&&b>=10);return g=l.avail_in-b,g=c>>3<g?c>>3:g,b+=g,h-=g,c-=g<<3,s.bitb=f,s.bitk=c,l.avail_in=b,l.total_in+=h-l.next_in_index,l.next_in_index=h,s.write=w,0}t.init=function(t,r,s,l,o,_){e=0,u=t,f=r,i=s,c=l,a=o,h=_,n=null},t.proc=function(t,w,x){let p,y,g,m,v,k,A,U=0,I=0,E=0;for(E=w.next_in_index,m=w.avail_in,U=t.bitb,I=t.bitk,v=t.write,k=v<t.read?t.read-v-1:t.end-v;;)switch(e){case 0:if(k>=258&&m>=10&&(t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,x=b(u,f,i,c,a,h,t,w),E=w.next_in_index,m=w.avail_in,U=t.bitb,I=t.bitk,v=t.write,k=v<t.read?t.read-v-1:t.end-v,0!=x)){e=1==x?7:9;break}l=u,n=i,s=c,e=1;case 1:for(p=l;I<p;){if(0===m)return t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);x=0,m--,U|=(255&w.read_byte(E++))<<I,I+=8}if(y=3*(s+(U&Y[p])),U>>>=n[y+1],I-=n[y+1],g=n[y],0===g){o=n[y+2],e=6;break}if(0!=(16&g)){_=15&g,r=n[y+2],e=2;break}if(0==(64&g)){l=g,s=y/3+n[y+2];break}if(0!=(32&g)){e=7;break}return e=9,w.msg="invalid literal/length code",x=Q,t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);case 2:for(p=_;I<p;){if(0===m)return t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);x=0,m--,U|=(255&w.read_byte(E++))<<I,I+=8}r+=U&Y[p],U>>=p,I-=p,l=f,n=a,s=h,e=3;case 3:for(p=l;I<p;){if(0===m)return t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);x=0,m--,U|=(255&w.read_byte(E++))<<I,I+=8}if(y=3*(s+(U&Y[p])),U>>=n[y+1],I-=n[y+1],g=n[y],0!=(16&g)){_=15&g,d=n[y+2],e=4;break}if(0==(64&g)){l=g,s=y/3+n[y+2];break}return e=9,w.msg="invalid distance code",x=Q,t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);case 4:for(p=_;I<p;){if(0===m)return t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);x=0,m--,U|=(255&w.read_byte(E++))<<I,I+=8}d+=U&Y[p],U>>=p,I-=p,e=5;case 5:for(A=v-d;A<0;)A+=t.end;for(;0!==r;){if(0===k&&(v==t.end&&0!==t.read&&(v=0,k=v<t.read?t.read-v-1:t.end-v),0===k&&(t.write=v,x=t.inflate_flush(w,x),v=t.write,k=v<t.read?t.read-v-1:t.end-v,v==t.end&&0!==t.read&&(v=0,k=v<t.read?t.read-v-1:t.end-v),0===k)))return t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);t.window[v++]=t.window[A++],k--,A==t.end&&(A=0),r--}e=0;break;case 6:if(0===k&&(v==t.end&&0!==t.read&&(v=0,k=v<t.read?t.read-v-1:t.end-v),0===k&&(t.write=v,x=t.inflate_flush(w,x),v=t.write,k=v<t.read?t.read-v-1:t.end-v,v==t.end&&0!==t.read&&(v=0,k=v<t.read?t.read-v-1:t.end-v),0===k)))return t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);x=0,t.window[v++]=o,k--,e=0;break;case 7:if(I>7&&(I-=8,m++,E--),t.write=v,x=t.inflate_flush(w,x),v=t.write,k=v<t.read?t.read-v-1:t.end-v,t.read!=t.write)return t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);e=8;case 8:return x=1,t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);case 9:return x=Q,t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x);default:return x=N,t.bitb=U,t.bitk=I,w.avail_in=m,w.total_in+=E-w.next_in_index,w.next_in_index=E,t.write=v,t.inflate_flush(w,x)}},t.free=function(){}}const lt=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function ot(t,e){const n=this;let i,a=0,r=0,s=0,l=0;const o=[0],_=[0],d=new st;let u=0,f=new Int32Array(4320);const c=new rt;n.bitk=0,n.bitb=0,n.window=new Uint8Array(e),n.end=e,n.read=0,n.write=0,n.reset=function(t,e){e&&(e[0]=0),6==a&&d.free(t),a=0,n.bitk=0,n.bitb=0,n.read=n.write=0},n.reset(t,null),n.inflate_flush=function(t,e){let i,a,r;return a=t.next_out_index,r=n.read,i=(r<=n.write?n.write:n.end)-r,i>t.avail_out&&(i=t.avail_out),0!==i&&e==X&&(e=0),t.avail_out-=i,t.total_out+=i,t.next_out.set(n.window.subarray(r,r+i),a),a+=i,r+=i,r==n.end&&(r=0,n.write==n.end&&(n.write=0),i=n.write-r,i>t.avail_out&&(i=t.avail_out),0!==i&&e==X&&(e=0),t.avail_out-=i,t.total_out+=i,t.next_out.set(n.window.subarray(r,r+i),a),a+=i,r+=i),t.next_out_index=a,n.read=r,e},n.proc=function(t,e){let h,b,w,x,p,y,g,m;for(x=t.next_in_index,p=t.avail_in,b=n.bitb,w=n.bitk,y=n.write,g=y<n.read?n.read-y-1:n.end-y;;){let v,k,A,U,I,E,S,C;switch(a){case 0:for(;w<3;){if(0===p)return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);e=0,p--,b|=(255&t.read_byte(x++))<<w,w+=8}switch(h=7&b,u=1&h,h>>>1){case 0:b>>>=3,w-=3,h=7&w,b>>>=h,w-=h,a=1;break;case 1:v=[],k=[],A=[[]],U=[[]],rt.inflate_trees_fixed(v,k,A,U),d.init(v[0],k[0],A[0],0,U[0],0),b>>>=3,w-=3,a=6;break;case 2:b>>>=3,w-=3,a=3;break;case 3:return b>>>=3,w-=3,a=9,t.msg="invalid block type",e=Q,n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e)}break;case 1:for(;w<32;){if(0===p)return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);e=0,p--,b|=(255&t.read_byte(x++))<<w,w+=8}if((~b>>>16&65535)!=(65535&b))return a=9,t.msg="invalid stored block lengths",e=Q,n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);r=65535&b,b=w=0,a=0!==r?2:0!==u?7:0;break;case 2:if(0===p)return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);if(0===g&&(y==n.end&&0!==n.read&&(y=0,g=y<n.read?n.read-y-1:n.end-y),0===g&&(n.write=y,e=n.inflate_flush(t,e),y=n.write,g=y<n.read?n.read-y-1:n.end-y,y==n.end&&0!==n.read&&(y=0,g=y<n.read?n.read-y-1:n.end-y),0===g)))return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);if(e=0,h=r,h>p&&(h=p),h>g&&(h=g),n.window.set(t.read_buf(x,h),y),x+=h,p-=h,y+=h,g-=h,0!=(r-=h))break;a=0!==u?7:0;break;case 3:for(;w<14;){if(0===p)return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);e=0,p--,b|=(255&t.read_byte(x++))<<w,w+=8}if(s=h=16383&b,(31&h)>29||(h>>5&31)>29)return a=9,t.msg="too many length or distance symbols",e=Q,n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);if(h=258+(31&h)+(h>>5&31),!i||i.length<h)i=[];else for(m=0;m<h;m++)i[m]=0;b>>>=14,w-=14,l=0,a=4;case 4:for(;l<4+(s>>>10);){for(;w<3;){if(0===p)return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);e=0,p--,b|=(255&t.read_byte(x++))<<w,w+=8}i[lt[l++]]=7&b,b>>>=3,w-=3}for(;l<19;)i[lt[l++]]=0;if(o[0]=7,h=c.inflate_trees_bits(i,o,_,f,t),0!=h)return(e=h)==Q&&(i=null,a=9),n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);l=0,a=5;case 5:for(;h=s,!(l>=258+(31&h)+(h>>5&31));){let r,d;for(h=o[0];w<h;){if(0===p)return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);e=0,p--,b|=(255&t.read_byte(x++))<<w,w+=8}if(h=f[3*(_[0]+(b&Y[h]))+1],d=f[3*(_[0]+(b&Y[h]))+2],d<16)b>>>=h,w-=h,i[l++]=d;else{for(m=18==d?7:d-14,r=18==d?11:3;w<h+m;){if(0===p)return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);e=0,p--,b|=(255&t.read_byte(x++))<<w,w+=8}if(b>>>=h,w-=h,r+=b&Y[m],b>>>=m,w-=m,m=l,h=s,m+r>258+(31&h)+(h>>5&31)||16==d&&m<1)return i=null,a=9,t.msg="invalid bit length repeat",e=Q,n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);d=16==d?i[m-1]:0;do{i[m++]=d}while(0!=--r);l=m}}if(_[0]=-1,I=[],E=[],S=[],C=[],I[0]=9,E[0]=6,h=s,h=c.inflate_trees_dynamic(257+(31&h),1+(h>>5&31),i,I,E,S,C,f,t),0!=h)return h==Q&&(i=null,a=9),e=h,n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);d.init(I[0],E[0],f,S[0],f,C[0]),a=6;case 6:if(n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,1!=(e=d.proc(n,t,e)))return n.inflate_flush(t,e);if(e=0,d.free(t),x=t.next_in_index,p=t.avail_in,b=n.bitb,w=n.bitk,y=n.write,g=y<n.read?n.read-y-1:n.end-y,0===u){a=0;break}a=7;case 7:if(n.write=y,e=n.inflate_flush(t,e),y=n.write,g=y<n.read?n.read-y-1:n.end-y,n.read!=n.write)return n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);a=8;case 8:return e=1,n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);case 9:return e=Q,n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e);default:return e=N,n.bitb=b,n.bitk=w,t.avail_in=p,t.total_in+=x-t.next_in_index,t.next_in_index=x,n.write=y,n.inflate_flush(t,e)}}},n.free=function(t){n.reset(t,null),n.window=null,f=null},n.set_dictionary=function(t,e,i){n.window.set(t.subarray(e,e+i),0),n.read=n.write=i},n.sync_point=function(){return 1==a?1:0}}const _t=13,dt=[0,0,255,255];function ut(){const t=this;function e(t){return t&&t.istate?(t.total_in=t.total_out=0,t.msg=null,t.istate.mode=7,t.istate.blocks.reset(t,null),0):N}t.mode=0,t.method=0,t.was=[0],t.need=0,t.marker=0,t.wbits=0,t.inflateEnd=function(e){return t.blocks&&t.blocks.free(e),t.blocks=null,0},t.inflateInit=function(n,i){return n.msg=null,t.blocks=null,i<8||i>15?(t.inflateEnd(n),N):(t.wbits=i,n.istate.blocks=new ot(n,1<<i),e(n),0)},t.inflate=function(t,e){let n,i;if(!t||!t.istate||!t.next_in)return N;const a=t.istate;for(e=4==e?X:0,n=X;;)switch(a.mode){case 0:if(0===t.avail_in)return n;if(n=e,t.avail_in--,t.total_in++,8!=(15&(a.method=t.read_byte(t.next_in_index++)))){a.mode=_t,t.msg="unknown compression method",a.marker=5;break}if(8+(a.method>>4)>a.wbits){a.mode=_t,t.msg="invalid window size",a.marker=5;break}a.mode=1;case 1:if(0===t.avail_in)return n;if(n=e,t.avail_in--,t.total_in++,i=255&t.read_byte(t.next_in_index++),((a.method<<8)+i)%31!=0){a.mode=_t,t.msg="incorrect header check",a.marker=5;break}if(0==(32&i)){a.mode=7;break}a.mode=2;case 2:if(0===t.avail_in)return n;n=e,t.avail_in--,t.total_in++,a.need=(255&t.read_byte(t.next_in_index++))<<24&4278190080,a.mode=3;case 3:if(0===t.avail_in)return n;n=e,t.avail_in--,t.total_in++,a.need+=(255&t.read_byte(t.next_in_index++))<<16&16711680,a.mode=4;case 4:if(0===t.avail_in)return n;n=e,t.avail_in--,t.total_in++,a.need+=(255&t.read_byte(t.next_in_index++))<<8&65280,a.mode=5;case 5:return 0===t.avail_in?n:(n=e,t.avail_in--,t.total_in++,a.need+=255&t.read_byte(t.next_in_index++),a.mode=6,2);case 6:return a.mode=_t,t.msg="need dictionary",a.marker=0,N;case 7:if(n=a.blocks.proc(t,n),n==Q){a.mode=_t,a.marker=0;break}if(0==n&&(n=e),1!=n)return n;n=e,a.blocks.reset(t,a.was),a.mode=12;case 12:return 1;case _t:return Q;default:return N}},t.inflateSetDictionary=function(t,e,n){let i=0,a=n;if(!t||!t.istate||6!=t.istate.mode)return N;const r=t.istate;return a>=1<<r.wbits&&(a=(1<<r.wbits)-1,i=n-a),r.blocks.set_dictionary(e,i,a),r.mode=7,0},t.inflateSync=function(t){let n,i,a,r,s;if(!t||!t.istate)return N;const l=t.istate;if(l.mode!=_t&&(l.mode=_t,l.marker=0),0===(n=t.avail_in))return X;for(i=t.next_in_index,a=l.marker;0!==n&&a<4;)t.read_byte(i)==dt[a]?a++:a=0!==t.read_byte(i)?0:4-a,i++,n--;return t.total_in+=i-t.next_in_index,t.next_in_index=i,t.avail_in=n,l.marker=a,4!=a?Q:(r=t.total_in,s=t.total_out,e(t),t.total_in=r,t.total_out=s,l.mode=7,0)},t.inflateSyncPoint=function(t){return t&&t.istate&&t.istate.blocks?t.istate.blocks.sync_point():N}}function ft(){}function ct(){const t=new ft,e=new Uint8Array(512);let n=!1;t.inflateInit(),t.next_out=e,this.append=function(i,a){const r=[];let s,l,o=0,_=0,d=0;if(0!==i.length){t.next_in_index=0,t.next_in=i,t.avail_in=i.length;do{if(t.next_out_index=0,t.avail_out=512,0!==t.avail_in||n||(t.next_in_index=0,n=!0),s=t.inflate(0),n&&s===X){if(0!==t.avail_in)throw new Error("inflating: bad input")}else if(0!==s&&1!==s)throw new Error("inflating: "+t.msg);if((n||1===s)&&t.avail_in===i.length)throw new Error("inflating: bad input");t.next_out_index&&(512===t.next_out_index?r.push(new Uint8Array(e)):r.push(new Uint8Array(e.subarray(0,t.next_out_index)))),d+=t.next_out_index,a&&t.next_in_index>0&&t.next_in_index!=o&&(a(t.next_in_index),o=t.next_in_index)}while(t.avail_in>0||0===t.avail_out);return l=new Uint8Array(d),r.forEach((function(t){l.set(t,_),_+=t.length})),l}},this.flush=function(){t.inflateEnd()}}ft.prototype={inflateInit:function(t){const e=this;return e.istate=new ut,t||(t=15),e.istate.inflateInit(e,t)},inflate:function(t){const e=this;return e.istate?e.istate.inflate(e,t):N},inflateEnd:function(){const t=this;if(!t.istate)return N;const e=t.istate.inflateEnd(t);return t.istate=null,e},inflateSync:function(){const t=this;return t.istate?t.istate.inflateSync(t):N},inflateSetDictionary:function(t,e){const n=this;return n.istate?n.istate.inflateSetDictionary(n,t,e):N},read_byte:function(t){return this.next_in.subarray(t,t+1)[0]},read_buf:function(t,e){return this.next_in.subarray(t,t+e)}},self.initCodec=()=>{self.Deflate=J,self.Inflate=ct}}(); |
@@ -29,4 +29,2 @@ /* | ||
/* global ZipInflate, ZipDeflate */ | ||
"use strict"; | ||
@@ -48,3 +46,3 @@ | ||
this.compressed = options.inputCompressed; | ||
this.inflate = this.compressed && new ZipInflate(); | ||
this.inflate = this.compressed && new options.codecConstructor(); | ||
this.crc32 = this.signed && this.signed && new Crc32(); | ||
@@ -97,3 +95,3 @@ this.decrypt = this.encrypted && new ZipDecrypt(options.inputPassword); | ||
this.compressed = options.outputCompressed; | ||
this.deflate = this.compressed && new ZipDeflate({ level: options.level || 5 }); | ||
this.deflate = this.compressed && new options.codecConstructor({ level: options.level || 5 }); | ||
this.crc32 = this.signed && new Crc32(); | ||
@@ -100,0 +98,0 @@ this.encrypt = this.encrypted && new ZipEncrypt(options.outputPassword); |
@@ -36,674 +36,741 @@ /* | ||
(function (globalThis) { | ||
"use strict"; | ||
"use strict"; | ||
// Global | ||
const MAX_BITS = 15; | ||
// Global | ||
const MAX_BITS = 15; | ||
const Z_OK = 0; | ||
const Z_STREAM_END = 1; | ||
const Z_NEED_DICT = 2; | ||
const Z_STREAM_ERROR = -2; | ||
const Z_DATA_ERROR = -3; | ||
const Z_MEM_ERROR = -4; | ||
const Z_BUF_ERROR = -5; | ||
const Z_OK = 0; | ||
const Z_STREAM_END = 1; | ||
const Z_NEED_DICT = 2; | ||
const Z_STREAM_ERROR = -2; | ||
const Z_DATA_ERROR = -3; | ||
const Z_MEM_ERROR = -4; | ||
const Z_BUF_ERROR = -5; | ||
const inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff, | ||
0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff]; | ||
const inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff, | ||
0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff]; | ||
const MANY = 1440; | ||
const MANY = 1440; | ||
// JZlib version : "1.0.2" | ||
const Z_NO_FLUSH = 0; | ||
const Z_FINISH = 4; | ||
// JZlib version : "1.0.2" | ||
const Z_NO_FLUSH = 0; | ||
const Z_FINISH = 4; | ||
// InfTree | ||
const fixed_bl = 9; | ||
const fixed_bd = 5; | ||
// InfTree | ||
const fixed_bl = 9; | ||
const fixed_bd = 5; | ||
const fixed_tl = [96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0, | ||
0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40, | ||
0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13, | ||
0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60, | ||
0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, | ||
35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8, | ||
26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80, | ||
7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0, | ||
8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0, | ||
8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97, | ||
0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210, | ||
81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, | ||
0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154, | ||
84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83, | ||
0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230, | ||
80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139, | ||
0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174, | ||
0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111, | ||
0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, | ||
193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8, | ||
120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, | ||
227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8, | ||
92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, | ||
249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8, | ||
130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, | ||
181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8, | ||
102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, | ||
221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, | ||
8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, | ||
147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8, | ||
85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, | ||
235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8, | ||
141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, | ||
167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8, | ||
107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, | ||
207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8, | ||
127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255]; | ||
const fixed_td = [80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5, | ||
8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5, | ||
24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577]; | ||
const fixed_tl = [96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0, | ||
0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40, | ||
0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13, | ||
0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60, | ||
0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, | ||
35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8, | ||
26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80, | ||
7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0, | ||
8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0, | ||
8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97, | ||
0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210, | ||
81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, | ||
0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154, | ||
84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83, | ||
0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230, | ||
80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139, | ||
0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174, | ||
0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111, | ||
0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, | ||
193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8, | ||
120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, | ||
227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8, | ||
92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, | ||
249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8, | ||
130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, | ||
181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8, | ||
102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, | ||
221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, | ||
8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, | ||
147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8, | ||
85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, | ||
235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8, | ||
141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, | ||
167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8, | ||
107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, | ||
207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8, | ||
127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255]; | ||
const fixed_td = [80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5, | ||
8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5, | ||
24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577]; | ||
// Tables for deflate from PKZIP's appnote.txt. | ||
const cplens = [ // Copy lengths for literal codes 257..285 | ||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]; | ||
// Tables for deflate from PKZIP's appnote.txt. | ||
const cplens = [ // Copy lengths for literal codes 257..285 | ||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]; | ||
// see note #13 above about 258 | ||
const cplext = [ // Extra bits for literal codes 257..285 | ||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid | ||
]; | ||
// see note #13 above about 258 | ||
const cplext = [ // Extra bits for literal codes 257..285 | ||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid | ||
]; | ||
const cpdist = [ // Copy offsets for distance codes 0..29 | ||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577]; | ||
const cpdist = [ // Copy offsets for distance codes 0..29 | ||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577]; | ||
const cpdext = [ // Extra bits for distance codes | ||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]; | ||
const cpdext = [ // Extra bits for distance codes | ||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]; | ||
// If BMAX needs to be larger than 16, then h and x[] should be uLong. | ||
const BMAX = 15; // maximum bit length of any code | ||
// If BMAX needs to be larger than 16, then h and x[] should be uLong. | ||
const BMAX = 15; // maximum bit length of any code | ||
function InfTree() { | ||
const that = this; | ||
function InfTree() { | ||
const that = this; | ||
let hn; // hufts used in space | ||
let v; // work area for huft_build | ||
let c; // bit length count table | ||
let r; // table entry for structure assignment | ||
let u; // table stack | ||
let x; // bit offsets, then code stack | ||
let hn; // hufts used in space | ||
let v; // work area for huft_build | ||
let c; // bit length count table | ||
let r; // table entry for structure assignment | ||
let u; // table stack | ||
let x; // bit offsets, then code stack | ||
function huft_build(b, // code lengths in bits (all assumed <= | ||
// BMAX) | ||
bindex, n, // number of codes (assumed <= 288) | ||
s, // number of simple-valued codes (0..s-1) | ||
d, // list of base values for non-simple codes | ||
e, // list of extra bits for non-simple codes | ||
t, // result: starting table | ||
m, // maximum lookup bits, returns actual | ||
hp,// space for trees | ||
hn,// hufts used in space | ||
v // working area: values in order of bit length | ||
) { | ||
// Given a list of code lengths and a maximum table size, make a set of | ||
// tables to decode that set of codes. Return Z_OK on success, | ||
// Z_BUF_ERROR | ||
// if the given code set is incomplete (the tables are still built in | ||
// this | ||
// case), Z_DATA_ERROR if the input is invalid (an over-subscribed set | ||
// of | ||
// lengths), or Z_MEM_ERROR if not enough memory. | ||
function huft_build(b, // code lengths in bits (all assumed <= | ||
// BMAX) | ||
bindex, n, // number of codes (assumed <= 288) | ||
s, // number of simple-valued codes (0..s-1) | ||
d, // list of base values for non-simple codes | ||
e, // list of extra bits for non-simple codes | ||
t, // result: starting table | ||
m, // maximum lookup bits, returns actual | ||
hp,// space for trees | ||
hn,// hufts used in space | ||
v // working area: values in order of bit length | ||
) { | ||
// Given a list of code lengths and a maximum table size, make a set of | ||
// tables to decode that set of codes. Return Z_OK on success, | ||
// Z_BUF_ERROR | ||
// if the given code set is incomplete (the tables are still built in | ||
// this | ||
// case), Z_DATA_ERROR if the input is invalid (an over-subscribed set | ||
// of | ||
// lengths), or Z_MEM_ERROR if not enough memory. | ||
let a; // counter for codes of length k | ||
let f; // i repeats in table every f entries | ||
let g; // maximum code length | ||
let h; // table level | ||
let i; // counter, current code | ||
let j; // counter | ||
let k; // number of bits in current code | ||
let l; // bits per table (returned in m) | ||
let mask; // (1 << w) - 1, to avoid cc -O bug on HP | ||
let p; // pointer into c[], b[], or v[] | ||
let q; // points to current table | ||
let w; // bits before this table == (l * h) | ||
let xp; // pointer into x | ||
let y; // number of dummy codes added | ||
let z; // number of entries in current table | ||
let a; // counter for codes of length k | ||
let f; // i repeats in table every f entries | ||
let g; // maximum code length | ||
let h; // table level | ||
let i; // counter, current code | ||
let j; // counter | ||
let k; // number of bits in current code | ||
let l; // bits per table (returned in m) | ||
let mask; // (1 << w) - 1, to avoid cc -O bug on HP | ||
let p; // pointer into c[], b[], or v[] | ||
let q; // points to current table | ||
let w; // bits before this table == (l * h) | ||
let xp; // pointer into x | ||
let y; // number of dummy codes added | ||
let z; // number of entries in current table | ||
// Generate counts for each bit length | ||
// Generate counts for each bit length | ||
p = 0; | ||
i = n; | ||
do { | ||
c[b[bindex + p]]++; | ||
p++; | ||
i--; // assume all entries <= BMAX | ||
} while (i !== 0); | ||
p = 0; | ||
i = n; | ||
do { | ||
c[b[bindex + p]]++; | ||
p++; | ||
i--; // assume all entries <= BMAX | ||
} while (i !== 0); | ||
if (c[0] == n) { // null input--all zero length codes | ||
t[0] = -1; | ||
m[0] = 0; | ||
return Z_OK; | ||
} | ||
if (c[0] == n) { // null input--all zero length codes | ||
t[0] = -1; | ||
m[0] = 0; | ||
return Z_OK; | ||
} | ||
// Find minimum and maximum length, bound *m by those | ||
l = m[0]; | ||
for (j = 1; j <= BMAX; j++) | ||
if (c[j] !== 0) | ||
break; | ||
k = j; // minimum code length | ||
if (l < j) { | ||
l = j; | ||
} | ||
for (i = BMAX; i !== 0; i--) { | ||
if (c[i] !== 0) | ||
break; | ||
} | ||
g = i; // maximum code length | ||
if (l > i) { | ||
l = i; | ||
} | ||
m[0] = l; | ||
// Find minimum and maximum length, bound *m by those | ||
l = m[0]; | ||
for (j = 1; j <= BMAX; j++) | ||
if (c[j] !== 0) | ||
break; | ||
k = j; // minimum code length | ||
if (l < j) { | ||
l = j; | ||
} | ||
for (i = BMAX; i !== 0; i--) { | ||
if (c[i] !== 0) | ||
break; | ||
} | ||
g = i; // maximum code length | ||
if (l > i) { | ||
l = i; | ||
} | ||
m[0] = l; | ||
// Adjust last length count to fill out codes, if needed | ||
for (y = 1 << j; j < i; j++, y <<= 1) { | ||
if ((y -= c[j]) < 0) { | ||
return Z_DATA_ERROR; | ||
} | ||
} | ||
if ((y -= c[i]) < 0) { | ||
// Adjust last length count to fill out codes, if needed | ||
for (y = 1 << j; j < i; j++, y <<= 1) { | ||
if ((y -= c[j]) < 0) { | ||
return Z_DATA_ERROR; | ||
} | ||
c[i] += y; | ||
} | ||
if ((y -= c[i]) < 0) { | ||
return Z_DATA_ERROR; | ||
} | ||
c[i] += y; | ||
// Generate starting offsets into the value table for each length | ||
x[1] = j = 0; | ||
p = 1; | ||
xp = 2; | ||
while (--i !== 0) { // note that i == g from above | ||
x[xp] = (j += c[p]); | ||
xp++; | ||
p++; | ||
// Generate starting offsets into the value table for each length | ||
x[1] = j = 0; | ||
p = 1; | ||
xp = 2; | ||
while (--i !== 0) { // note that i == g from above | ||
x[xp] = (j += c[p]); | ||
xp++; | ||
p++; | ||
} | ||
// Make a table of values in order of bit lengths | ||
i = 0; | ||
p = 0; | ||
do { | ||
if ((j = b[bindex + p]) !== 0) { | ||
v[x[j]++] = i; | ||
} | ||
p++; | ||
} while (++i < n); | ||
n = x[g]; // set n to length of v | ||
// Make a table of values in order of bit lengths | ||
i = 0; | ||
p = 0; | ||
do { | ||
if ((j = b[bindex + p]) !== 0) { | ||
v[x[j]++] = i; | ||
} | ||
p++; | ||
} while (++i < n); | ||
n = x[g]; // set n to length of v | ||
// Generate the Huffman codes and for each, make the table entries | ||
x[0] = i = 0; // first Huffman code is zero | ||
p = 0; // grab values in bit order | ||
h = -1; // no tables yet--level -1 | ||
w = -l; // bits decoded == (l * h) | ||
u[0] = 0; // just to keep compilers happy | ||
q = 0; // ditto | ||
z = 0; // ditto | ||
// Generate the Huffman codes and for each, make the table entries | ||
x[0] = i = 0; // first Huffman code is zero | ||
p = 0; // grab values in bit order | ||
h = -1; // no tables yet--level -1 | ||
w = -l; // bits decoded == (l * h) | ||
u[0] = 0; // just to keep compilers happy | ||
q = 0; // ditto | ||
z = 0; // ditto | ||
// go through the bit lengths (k already is bits in shortest code) | ||
for (; k <= g; k++) { | ||
a = c[k]; | ||
while (a-- !== 0) { | ||
// here i is the Huffman code of length k bits for value *p | ||
// make tables up to required level | ||
while (k > w + l) { | ||
h++; | ||
w += l; // previous table always l bits | ||
// compute minimum size table less than or equal to l bits | ||
z = g - w; | ||
z = (z > l) ? l : z; // table size upper limit | ||
if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table | ||
// too few codes for | ||
// k-w bit table | ||
f -= a + 1; // deduct codes from patterns left | ||
xp = k; | ||
if (j < z) { | ||
while (++j < z) { // try smaller tables up to z bits | ||
if ((f <<= 1) <= c[++xp]) | ||
break; // enough codes to use up j bits | ||
f -= c[xp]; // else deduct codes from patterns | ||
} | ||
// go through the bit lengths (k already is bits in shortest code) | ||
for (; k <= g; k++) { | ||
a = c[k]; | ||
while (a-- !== 0) { | ||
// here i is the Huffman code of length k bits for value *p | ||
// make tables up to required level | ||
while (k > w + l) { | ||
h++; | ||
w += l; // previous table always l bits | ||
// compute minimum size table less than or equal to l bits | ||
z = g - w; | ||
z = (z > l) ? l : z; // table size upper limit | ||
if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table | ||
// too few codes for | ||
// k-w bit table | ||
f -= a + 1; // deduct codes from patterns left | ||
xp = k; | ||
if (j < z) { | ||
while (++j < z) { // try smaller tables up to z bits | ||
if ((f <<= 1) <= c[++xp]) | ||
break; // enough codes to use up j bits | ||
f -= c[xp]; // else deduct codes from patterns | ||
} | ||
} | ||
z = 1 << j; // table entries for j-bit table | ||
} | ||
z = 1 << j; // table entries for j-bit table | ||
// allocate new table | ||
if (hn[0] + z > MANY) { // (note: doesn't matter for fixed) | ||
return Z_DATA_ERROR; // overflow of MANY | ||
} | ||
u[h] = q = /* hp+ */hn[0]; // DEBUG | ||
hn[0] += z; | ||
// connect to last table, if there is one | ||
if (h !== 0) { | ||
x[h] = i; // save pattern for backing up | ||
r[0] = /* (byte) */j; // bits in this table | ||
r[1] = /* (byte) */l; // bits to dump before this table | ||
j = i >>> (w - l); | ||
r[2] = /* (int) */(q - u[h - 1] - j); // offset to this table | ||
hp.set(r, (u[h - 1] + j) * 3); | ||
// to | ||
// last | ||
// table | ||
} else { | ||
t[0] = q; // first table is returned result | ||
} | ||
// allocate new table | ||
if (hn[0] + z > MANY) { // (note: doesn't matter for fixed) | ||
return Z_DATA_ERROR; // overflow of MANY | ||
} | ||
u[h] = q = /* hp+ */hn[0]; // DEBUG | ||
hn[0] += z; | ||
// set up table entry in r | ||
r[1] = /* (byte) */(k - w); | ||
if (p >= n) { | ||
r[0] = 128 + 64; // out of values--invalid code | ||
} else if (v[p] < s) { | ||
r[0] = /* (byte) */(v[p] < 256 ? 0 : 32 + 64); // 256 is | ||
// end-of-block | ||
r[2] = v[p++]; // simple code is just the value | ||
// connect to last table, if there is one | ||
if (h !== 0) { | ||
x[h] = i; // save pattern for backing up | ||
r[0] = /* (byte) */j; // bits in this table | ||
r[1] = /* (byte) */l; // bits to dump before this table | ||
j = i >>> (w - l); | ||
r[2] = /* (int) */(q - u[h - 1] - j); // offset to this table | ||
hp.set(r, (u[h - 1] + j) * 3); | ||
// to | ||
// last | ||
// table | ||
} else { | ||
r[0] = /* (byte) */(e[v[p] - s] + 16 + 64); // non-simple--look | ||
// up in lists | ||
r[2] = d[v[p++] - s]; | ||
t[0] = q; // first table is returned result | ||
} | ||
} | ||
// fill code-like entries with r | ||
f = 1 << (k - w); | ||
for (j = i >>> w; j < z; j += f) { | ||
hp.set(r, (q + j) * 3); | ||
} | ||
// set up table entry in r | ||
r[1] = /* (byte) */(k - w); | ||
if (p >= n) { | ||
r[0] = 128 + 64; // out of values--invalid code | ||
} else if (v[p] < s) { | ||
r[0] = /* (byte) */(v[p] < 256 ? 0 : 32 + 64); // 256 is | ||
// end-of-block | ||
r[2] = v[p++]; // simple code is just the value | ||
} else { | ||
r[0] = /* (byte) */(e[v[p] - s] + 16 + 64); // non-simple--look | ||
// up in lists | ||
r[2] = d[v[p++] - s]; | ||
} | ||
// backwards increment the k-bit code i | ||
for (j = 1 << (k - 1); (i & j) !== 0; j >>>= 1) { | ||
i ^= j; | ||
} | ||
// fill code-like entries with r | ||
f = 1 << (k - w); | ||
for (j = i >>> w; j < z; j += f) { | ||
hp.set(r, (q + j) * 3); | ||
} | ||
// backwards increment the k-bit code i | ||
for (j = 1 << (k - 1); (i & j) !== 0; j >>>= 1) { | ||
i ^= j; | ||
} | ||
i ^= j; | ||
// backup over finished tables | ||
mask = (1 << w) - 1; // needed on HP, cc -O bug | ||
while ((i & mask) != x[h]) { | ||
h--; // don't need to update q | ||
w -= l; | ||
mask = (1 << w) - 1; | ||
} | ||
// backup over finished tables | ||
mask = (1 << w) - 1; // needed on HP, cc -O bug | ||
while ((i & mask) != x[h]) { | ||
h--; // don't need to update q | ||
w -= l; | ||
mask = (1 << w) - 1; | ||
} | ||
} | ||
// Return Z_BUF_ERROR if we were given an incomplete table | ||
return y !== 0 && g != 1 ? Z_BUF_ERROR : Z_OK; | ||
} | ||
// Return Z_BUF_ERROR if we were given an incomplete table | ||
return y !== 0 && g != 1 ? Z_BUF_ERROR : Z_OK; | ||
} | ||
function initWorkArea(vsize) { | ||
let i; | ||
if (!hn) { | ||
hn = []; // []; //new Array(1); | ||
v = []; // new Array(vsize); | ||
c = new Int32Array(BMAX + 1); // new Array(BMAX + 1); | ||
r = []; // new Array(3); | ||
u = new Int32Array(BMAX); // new Array(BMAX); | ||
x = new Int32Array(BMAX + 1); // new Array(BMAX + 1); | ||
} | ||
if (v.length < vsize) { | ||
v = []; // new Array(vsize); | ||
} | ||
for (i = 0; i < vsize; i++) { | ||
v[i] = 0; | ||
} | ||
for (i = 0; i < BMAX + 1; i++) { | ||
c[i] = 0; | ||
} | ||
for (i = 0; i < 3; i++) { | ||
r[i] = 0; | ||
} | ||
// for(int i=0; i<BMAX; i++){u[i]=0;} | ||
u.set(c.subarray(0, BMAX), 0); | ||
// for(int i=0; i<BMAX+1; i++){x[i]=0;} | ||
x.set(c.subarray(0, BMAX + 1), 0); | ||
function initWorkArea(vsize) { | ||
let i; | ||
if (!hn) { | ||
hn = []; // []; //new Array(1); | ||
v = []; // new Array(vsize); | ||
c = new Int32Array(BMAX + 1); // new Array(BMAX + 1); | ||
r = []; // new Array(3); | ||
u = new Int32Array(BMAX); // new Array(BMAX); | ||
x = new Int32Array(BMAX + 1); // new Array(BMAX + 1); | ||
} | ||
if (v.length < vsize) { | ||
v = []; // new Array(vsize); | ||
} | ||
for (i = 0; i < vsize; i++) { | ||
v[i] = 0; | ||
} | ||
for (i = 0; i < BMAX + 1; i++) { | ||
c[i] = 0; | ||
} | ||
for (i = 0; i < 3; i++) { | ||
r[i] = 0; | ||
} | ||
// for(int i=0; i<BMAX; i++){u[i]=0;} | ||
u.set(c.subarray(0, BMAX), 0); | ||
// for(int i=0; i<BMAX+1; i++){x[i]=0;} | ||
x.set(c.subarray(0, BMAX + 1), 0); | ||
} | ||
that.inflate_trees_bits = function (c, // 19 code lengths | ||
bb, // bits tree desired/actual depth | ||
tb, // bits tree result | ||
hp, // space for trees | ||
z // for messages | ||
) { | ||
let result; | ||
initWorkArea(19); | ||
hn[0] = 0; | ||
result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v); | ||
that.inflate_trees_bits = function (c, // 19 code lengths | ||
bb, // bits tree desired/actual depth | ||
tb, // bits tree result | ||
hp, // space for trees | ||
z // for messages | ||
) { | ||
let result; | ||
initWorkArea(19); | ||
hn[0] = 0; | ||
result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v); | ||
if (result == Z_DATA_ERROR) { | ||
z.msg = "oversubscribed dynamic bit lengths tree"; | ||
} else if (result == Z_BUF_ERROR || bb[0] === 0) { | ||
z.msg = "incomplete dynamic bit lengths tree"; | ||
result = Z_DATA_ERROR; | ||
} | ||
return result; | ||
}; | ||
that.inflate_trees_dynamic = function (nl, // number of literal/length codes | ||
nd, // number of distance codes | ||
c, // that many (total) code lengths | ||
bl, // literal desired/actual bit depth | ||
bd, // distance desired/actual bit depth | ||
tl, // literal/length tree result | ||
td, // distance tree result | ||
hp, // space for trees | ||
z // for messages | ||
) { | ||
let result; | ||
// build literal/length tree | ||
initWorkArea(288); | ||
hn[0] = 0; | ||
result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v); | ||
if (result != Z_OK || bl[0] === 0) { | ||
if (result == Z_DATA_ERROR) { | ||
z.msg = "oversubscribed dynamic bit lengths tree"; | ||
} else if (result == Z_BUF_ERROR || bb[0] === 0) { | ||
z.msg = "incomplete dynamic bit lengths tree"; | ||
z.msg = "oversubscribed literal/length tree"; | ||
} else if (result != Z_MEM_ERROR) { | ||
z.msg = "incomplete literal/length tree"; | ||
result = Z_DATA_ERROR; | ||
} | ||
return result; | ||
}; | ||
} | ||
that.inflate_trees_dynamic = function (nl, // number of literal/length codes | ||
nd, // number of distance codes | ||
c, // that many (total) code lengths | ||
bl, // literal desired/actual bit depth | ||
bd, // distance desired/actual bit depth | ||
tl, // literal/length tree result | ||
td, // distance tree result | ||
hp, // space for trees | ||
z // for messages | ||
) { | ||
let result; | ||
// build distance tree | ||
initWorkArea(288); | ||
result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v); | ||
// build literal/length tree | ||
initWorkArea(288); | ||
hn[0] = 0; | ||
result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v); | ||
if (result != Z_OK || bl[0] === 0) { | ||
if (result == Z_DATA_ERROR) { | ||
z.msg = "oversubscribed literal/length tree"; | ||
} else if (result != Z_MEM_ERROR) { | ||
z.msg = "incomplete literal/length tree"; | ||
result = Z_DATA_ERROR; | ||
} | ||
return result; | ||
if (result != Z_OK || (bd[0] === 0 && nl > 257)) { | ||
if (result == Z_DATA_ERROR) { | ||
z.msg = "oversubscribed distance tree"; | ||
} else if (result == Z_BUF_ERROR) { | ||
z.msg = "incomplete distance tree"; | ||
result = Z_DATA_ERROR; | ||
} else if (result != Z_MEM_ERROR) { | ||
z.msg = "empty distance tree with lengths"; | ||
result = Z_DATA_ERROR; | ||
} | ||
return result; | ||
} | ||
// build distance tree | ||
initWorkArea(288); | ||
result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v); | ||
return Z_OK; | ||
}; | ||
if (result != Z_OK || (bd[0] === 0 && nl > 257)) { | ||
if (result == Z_DATA_ERROR) { | ||
z.msg = "oversubscribed distance tree"; | ||
} else if (result == Z_BUF_ERROR) { | ||
z.msg = "incomplete distance tree"; | ||
result = Z_DATA_ERROR; | ||
} else if (result != Z_MEM_ERROR) { | ||
z.msg = "empty distance tree with lengths"; | ||
result = Z_DATA_ERROR; | ||
} | ||
return result; | ||
} | ||
} | ||
return Z_OK; | ||
}; | ||
InfTree.inflate_trees_fixed = function (bl, // literal desired/actual bit depth | ||
bd, // distance desired/actual bit depth | ||
tl,// literal/length tree result | ||
td// distance tree result | ||
) { | ||
bl[0] = fixed_bl; | ||
bd[0] = fixed_bd; | ||
tl[0] = fixed_tl; | ||
td[0] = fixed_td; | ||
return Z_OK; | ||
}; | ||
} | ||
// InfCodes | ||
InfTree.inflate_trees_fixed = function (bl, // literal desired/actual bit depth | ||
bd, // distance desired/actual bit depth | ||
tl,// literal/length tree result | ||
td// distance tree result | ||
) { | ||
bl[0] = fixed_bl; | ||
bd[0] = fixed_bd; | ||
tl[0] = fixed_tl; | ||
td[0] = fixed_td; | ||
return Z_OK; | ||
}; | ||
// waiting for "i:"=input, | ||
// "o:"=output, | ||
// "x:"=nothing | ||
const START = 0; // x: set up for LEN | ||
const LEN = 1; // i: get length/literal/eob next | ||
const LENEXT = 2; // i: getting length extra (have base) | ||
const DIST = 3; // i: get distance next | ||
const DISTEXT = 4;// i: getting distance extra | ||
const COPY = 5; // o: copying bytes in window, waiting | ||
// for space | ||
const LIT = 6; // o: got literal, waiting for output | ||
// space | ||
const WASH = 7; // o: got eob, possibly still output | ||
// waiting | ||
const END = 8; // x: got eob and all data flushed | ||
const BADCODE = 9;// x: got error | ||
// InfCodes | ||
function InfCodes() { | ||
const that = this; | ||
// waiting for "i:"=input, | ||
// "o:"=output, | ||
// "x:"=nothing | ||
const START = 0; // x: set up for LEN | ||
const LEN = 1; // i: get length/literal/eob next | ||
const LENEXT = 2; // i: getting length extra (have base) | ||
const DIST = 3; // i: get distance next | ||
const DISTEXT = 4;// i: getting distance extra | ||
const COPY = 5; // o: copying bytes in window, waiting | ||
// for space | ||
const LIT = 6; // o: got literal, waiting for output | ||
// space | ||
const WASH = 7; // o: got eob, possibly still output | ||
// waiting | ||
const END = 8; // x: got eob and all data flushed | ||
const BADCODE = 9;// x: got error | ||
let mode; // current inflate_codes mode | ||
function InfCodes() { | ||
const that = this; | ||
// mode dependent information | ||
let len = 0; | ||
let mode; // current inflate_codes mode | ||
let tree; // pointer into tree | ||
let tree_index = 0; | ||
let need = 0; // bits needed | ||
// mode dependent information | ||
let len = 0; | ||
let lit = 0; | ||
let tree; // pointer into tree | ||
let tree_index = 0; | ||
let need = 0; // bits needed | ||
// if EXT or COPY, where and how much | ||
let get = 0; // bits to get for extra | ||
let dist = 0; // distance back to copy from | ||
let lit = 0; | ||
let lbits = 0; // ltree bits decoded per branch | ||
let dbits = 0; // dtree bits decoder per branch | ||
let ltree; // literal/length/eob tree | ||
let ltree_index = 0; // literal/length/eob tree | ||
let dtree; // distance tree | ||
let dtree_index = 0; // distance tree | ||
// if EXT or COPY, where and how much | ||
let get = 0; // bits to get for extra | ||
let dist = 0; // distance back to copy from | ||
// Called with number of bytes left to write in window at least 258 | ||
// (the maximum string length) and number of input bytes available | ||
// at least ten. The ten bytes are six bytes for the longest length/ | ||
// distance pair plus four bytes for overloading the bit buffer. | ||
let lbits = 0; // ltree bits decoded per branch | ||
let dbits = 0; // dtree bits decoder per branch | ||
let ltree; // literal/length/eob tree | ||
let ltree_index = 0; // literal/length/eob tree | ||
let dtree; // distance tree | ||
let dtree_index = 0; // distance tree | ||
function inflate_fast(bl, bd, tl, tl_index, td, td_index, s, z) { | ||
let t; // temporary pointer | ||
let tp; // temporary pointer | ||
let tp_index; // temporary pointer | ||
let e; // extra bits or operation | ||
let b; // bit buffer | ||
let k; // bits in bit buffer | ||
let p; // input data pointer | ||
let n; // bytes available there | ||
let q; // output window write pointer | ||
let m; // bytes to end of window or read pointer | ||
let ml; // mask for literal/length tree | ||
let md; // mask for distance tree | ||
let c; // bytes to copy | ||
let d; // distance back to copy from | ||
let r; // copy source pointer | ||
// Called with number of bytes left to write in window at least 258 | ||
// (the maximum string length) and number of input bytes available | ||
// at least ten. The ten bytes are six bytes for the longest length/ | ||
// distance pair plus four bytes for overloading the bit buffer. | ||
let tp_index_t_3; // (tp_index+t)*3 | ||
function inflate_fast(bl, bd, tl, tl_index, td, td_index, s, z) { | ||
let t; // temporary pointer | ||
let tp; // temporary pointer | ||
let tp_index; // temporary pointer | ||
let e; // extra bits or operation | ||
let b; // bit buffer | ||
let k; // bits in bit buffer | ||
let p; // input data pointer | ||
let n; // bytes available there | ||
let q; // output window write pointer | ||
let m; // bytes to end of window or read pointer | ||
let ml; // mask for literal/length tree | ||
let md; // mask for distance tree | ||
let c; // bytes to copy | ||
let d; // distance back to copy from | ||
let r; // copy source pointer | ||
// load input, output, bit values | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = s.bitb; | ||
k = s.bitk; | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
let tp_index_t_3; // (tp_index+t)*3 | ||
// initialize masks | ||
ml = inflate_mask[bl]; | ||
md = inflate_mask[bd]; | ||
// load input, output, bit values | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = s.bitb; | ||
k = s.bitk; | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
// do until not enough input or output space for fast loop | ||
do { // assume called with m >= 258 && n >= 10 | ||
// get literal/length code | ||
while (k < (20)) { // max bits for literal/length code | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
// initialize masks | ||
ml = inflate_mask[bl]; | ||
md = inflate_mask[bd]; | ||
t = b & ml; | ||
tp = tl; | ||
tp_index = tl_index; | ||
tp_index_t_3 = (tp_index + t) * 3; | ||
if ((e = tp[tp_index_t_3]) === 0) { | ||
b >>= (tp[tp_index_t_3 + 1]); | ||
k -= (tp[tp_index_t_3 + 1]); | ||
// do until not enough input or output space for fast loop | ||
do { // assume called with m >= 258 && n >= 10 | ||
// get literal/length code | ||
while (k < (20)) { // max bits for literal/length code | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
s.window[q++] = /* (byte) */tp[tp_index_t_3 + 2]; | ||
m--; | ||
continue; | ||
} | ||
do { | ||
t = b & ml; | ||
tp = tl; | ||
tp_index = tl_index; | ||
tp_index_t_3 = (tp_index + t) * 3; | ||
if ((e = tp[tp_index_t_3]) === 0) { | ||
b >>= (tp[tp_index_t_3 + 1]); | ||
k -= (tp[tp_index_t_3 + 1]); | ||
b >>= (tp[tp_index_t_3 + 1]); | ||
k -= (tp[tp_index_t_3 + 1]); | ||
s.window[q++] = /* (byte) */tp[tp_index_t_3 + 2]; | ||
m--; | ||
continue; | ||
} | ||
do { | ||
if ((e & 16) !== 0) { | ||
e &= 15; | ||
c = tp[tp_index_t_3 + 2] + (/* (int) */b & inflate_mask[e]); | ||
b >>= (tp[tp_index_t_3 + 1]); | ||
k -= (tp[tp_index_t_3 + 1]); | ||
b >>= e; | ||
k -= e; | ||
if ((e & 16) !== 0) { | ||
e &= 15; | ||
c = tp[tp_index_t_3 + 2] + (/* (int) */b & inflate_mask[e]); | ||
// decode distance base of block to copy | ||
while (k < (15)) { // max bits for distance code | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
b >>= e; | ||
k -= e; | ||
t = b & md; | ||
tp = td; | ||
tp_index = td_index; | ||
tp_index_t_3 = (tp_index + t) * 3; | ||
e = tp[tp_index_t_3]; | ||
// decode distance base of block to copy | ||
while (k < (15)) { // max bits for distance code | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
do { | ||
t = b & md; | ||
tp = td; | ||
tp_index = td_index; | ||
tp_index_t_3 = (tp_index + t) * 3; | ||
e = tp[tp_index_t_3]; | ||
b >>= (tp[tp_index_t_3 + 1]); | ||
k -= (tp[tp_index_t_3 + 1]); | ||
do { | ||
if ((e & 16) !== 0) { | ||
// get extra bits to add to distance base | ||
e &= 15; | ||
while (k < (e)) { // get extra bits (up to 13) | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
b >>= (tp[tp_index_t_3 + 1]); | ||
k -= (tp[tp_index_t_3 + 1]); | ||
d = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]); | ||
if ((e & 16) !== 0) { | ||
// get extra bits to add to distance base | ||
e &= 15; | ||
while (k < (e)) { // get extra bits (up to 13) | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
b >>= (e); | ||
k -= (e); | ||
// do the copy | ||
m -= c; | ||
if (q >= d) { // offset before dest | ||
// just copy | ||
r = q - d; | ||
if (q - r > 0 && 2 > (q - r)) { | ||
s.window[q++] = s.window[r++]; // minimum | ||
// count is | ||
// three, | ||
s.window[q++] = s.window[r++]; // so unroll | ||
// loop a | ||
// little | ||
c -= 2; | ||
} else { | ||
s.window.set(s.window.subarray(r, r + 2), q); | ||
q += 2; | ||
r += 2; | ||
c -= 2; | ||
} | ||
d = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]); | ||
b >>= (e); | ||
k -= (e); | ||
// do the copy | ||
m -= c; | ||
if (q >= d) { // offset before dest | ||
// just copy | ||
r = q - d; | ||
if (q - r > 0 && 2 > (q - r)) { | ||
s.window[q++] = s.window[r++]; // minimum | ||
// count is | ||
// three, | ||
s.window[q++] = s.window[r++]; // so unroll | ||
// loop a | ||
// little | ||
c -= 2; | ||
} else { // else offset after destination | ||
r = q - d; | ||
do { | ||
r += s.end; // force pointer in window | ||
} while (r < 0); // covers invalid distances | ||
e = s.end - r; | ||
if (c > e) { // if source crosses, | ||
c -= e; // wrapped copy | ||
if (q - r > 0 && e > (q - r)) { | ||
do { | ||
s.window[q++] = s.window[r++]; | ||
} while (--e !== 0); | ||
} else { | ||
s.window.set(s.window.subarray(r, r + 2), q); | ||
q += 2; | ||
r += 2; | ||
c -= 2; | ||
s.window.set(s.window.subarray(r, r + e), q); | ||
q += e; | ||
r += e; | ||
e = 0; | ||
} | ||
} else { // else offset after destination | ||
r = q - d; | ||
do { | ||
r += s.end; // force pointer in window | ||
} while (r < 0); // covers invalid distances | ||
e = s.end - r; | ||
if (c > e) { // if source crosses, | ||
c -= e; // wrapped copy | ||
if (q - r > 0 && e > (q - r)) { | ||
do { | ||
s.window[q++] = s.window[r++]; | ||
} while (--e !== 0); | ||
} else { | ||
s.window.set(s.window.subarray(r, r + e), q); | ||
q += e; | ||
r += e; | ||
e = 0; | ||
} | ||
r = 0; // copy rest from start of window | ||
} | ||
r = 0; // copy rest from start of window | ||
} | ||
// copy all or what's left | ||
if (q - r > 0 && c > (q - r)) { | ||
do { | ||
s.window[q++] = s.window[r++]; | ||
} while (--c !== 0); | ||
} else { | ||
s.window.set(s.window.subarray(r, r + c), q); | ||
q += c; | ||
r += c; | ||
c = 0; | ||
} | ||
break; | ||
} else if ((e & 64) === 0) { | ||
t += tp[tp_index_t_3 + 2]; | ||
t += (b & inflate_mask[e]); | ||
tp_index_t_3 = (tp_index + t) * 3; | ||
e = tp[tp_index_t_3]; | ||
} | ||
// copy all or what's left | ||
if (q - r > 0 && c > (q - r)) { | ||
do { | ||
s.window[q++] = s.window[r++]; | ||
} while (--c !== 0); | ||
} else { | ||
z.msg = "invalid distance code"; | ||
s.window.set(s.window.subarray(r, r + c), q); | ||
q += c; | ||
r += c; | ||
c = 0; | ||
} | ||
break; | ||
} else if ((e & 64) === 0) { | ||
t += tp[tp_index_t_3 + 2]; | ||
t += (b & inflate_mask[e]); | ||
tp_index_t_3 = (tp_index + t) * 3; | ||
e = tp[tp_index_t_3]; | ||
} else { | ||
z.msg = "invalid distance code"; | ||
c = z.avail_in - n; | ||
c = (k >> 3) < c ? k >> 3 : c; | ||
n += c; | ||
p -= c; | ||
k -= c << 3; | ||
c = z.avail_in - n; | ||
c = (k >> 3) < c ? k >> 3 : c; | ||
n += c; | ||
p -= c; | ||
k -= c << 3; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return Z_DATA_ERROR; | ||
} | ||
// eslint-disable-next-line no-constant-condition | ||
} while (true); | ||
return Z_DATA_ERROR; | ||
} | ||
// eslint-disable-next-line no-constant-condition | ||
} while (true); | ||
break; | ||
} | ||
if ((e & 64) === 0) { | ||
t += tp[tp_index_t_3 + 2]; | ||
t += (b & inflate_mask[e]); | ||
tp_index_t_3 = (tp_index + t) * 3; | ||
if ((e = tp[tp_index_t_3]) === 0) { | ||
b >>= (tp[tp_index_t_3 + 1]); | ||
k -= (tp[tp_index_t_3 + 1]); | ||
s.window[q++] = /* (byte) */tp[tp_index_t_3 + 2]; | ||
m--; | ||
break; | ||
} | ||
} else if ((e & 32) !== 0) { | ||
if ((e & 64) === 0) { | ||
t += tp[tp_index_t_3 + 2]; | ||
t += (b & inflate_mask[e]); | ||
tp_index_t_3 = (tp_index + t) * 3; | ||
if ((e = tp[tp_index_t_3]) === 0) { | ||
c = z.avail_in - n; | ||
c = (k >> 3) < c ? k >> 3 : c; | ||
n += c; | ||
p -= c; | ||
k -= c << 3; | ||
b >>= (tp[tp_index_t_3 + 1]); | ||
k -= (tp[tp_index_t_3 + 1]); | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
s.window[q++] = /* (byte) */tp[tp_index_t_3 + 2]; | ||
m--; | ||
break; | ||
} | ||
} else if ((e & 32) !== 0) { | ||
return Z_STREAM_END; | ||
} else { | ||
z.msg = "invalid literal/length code"; | ||
c = z.avail_in - n; | ||
c = (k >> 3) < c ? k >> 3 : c; | ||
n += c; | ||
p -= c; | ||
k -= c << 3; | ||
c = z.avail_in - n; | ||
c = (k >> 3) < c ? k >> 3 : c; | ||
n += c; | ||
p -= c; | ||
k -= c << 3; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return Z_STREAM_END; | ||
} else { | ||
z.msg = "invalid literal/length code"; | ||
return Z_DATA_ERROR; | ||
} | ||
// eslint-disable-next-line no-constant-condition | ||
} while (true); | ||
} while (m >= 258 && n >= 10); | ||
c = z.avail_in - n; | ||
c = (k >> 3) < c ? k >> 3 : c; | ||
n += c; | ||
p -= c; | ||
k -= c << 3; | ||
// not enough input or output--restore pointers and return | ||
c = z.avail_in - n; | ||
c = (k >> 3) < c ? k >> 3 : c; | ||
n += c; | ||
p -= c; | ||
k -= c << 3; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return Z_OK; | ||
} | ||
that.init = function (bl, bd, tl, tl_index, td, td_index) { | ||
mode = START; | ||
lbits = /* (byte) */bl; | ||
dbits = /* (byte) */bd; | ||
ltree = tl; | ||
ltree_index = tl_index; | ||
dtree = td; | ||
dtree_index = td_index; | ||
tree = null; | ||
}; | ||
that.proc = function (s, z, r) { | ||
let j; // temporary storage | ||
let tindex; // temporary pointer | ||
let e; // extra bits or operation | ||
let b = 0; // bit buffer | ||
let k = 0; // bits in bit buffer | ||
let p = 0; // input data pointer | ||
let n; // bytes available there | ||
let q; // output window write pointer | ||
let m; // bytes to end of window or read pointer | ||
let f; // pointer to copy strings from | ||
// copy input/output information to locals (UPDATE macro restores) | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = s.bitb; | ||
k = s.bitk; | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
// process input and output based on current state | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
switch (mode) { | ||
// waiting for "i:"=input, "o:"=output, "x:"=nothing | ||
case START: // x: set up for LEN | ||
if (m >= 258 && n >= 10) { | ||
s.bitb = b; | ||
@@ -715,65 +782,30 @@ s.bitk = k; | ||
s.write = q; | ||
r = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z); | ||
return Z_DATA_ERROR; | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = s.bitb; | ||
k = s.bitk; | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
if (r != Z_OK) { | ||
mode = r == Z_STREAM_END ? WASH : BADCODE; | ||
break; | ||
} | ||
} | ||
// eslint-disable-next-line no-constant-condition | ||
} while (true); | ||
} while (m >= 258 && n >= 10); | ||
need = lbits; | ||
tree = ltree; | ||
tree_index = ltree_index; | ||
// not enough input or output--restore pointers and return | ||
c = z.avail_in - n; | ||
c = (k >> 3) < c ? k >> 3 : c; | ||
n += c; | ||
p -= c; | ||
k -= c << 3; | ||
mode = LEN; | ||
/* falls through */ | ||
case LEN: // i: get length/literal/eob next | ||
j = need; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
while (k < (j)) { | ||
if (n !== 0) | ||
r = Z_OK; | ||
else { | ||
return Z_OK; | ||
} | ||
that.init = function (bl, bd, tl, tl_index, td, td_index) { | ||
mode = START; | ||
lbits = /* (byte) */bl; | ||
dbits = /* (byte) */bd; | ||
ltree = tl; | ||
ltree_index = tl_index; | ||
dtree = td; | ||
dtree_index = td_index; | ||
tree = null; | ||
}; | ||
that.proc = function (s, z, r) { | ||
let j; // temporary storage | ||
let tindex; // temporary pointer | ||
let e; // extra bits or operation | ||
let b = 0; // bit buffer | ||
let k = 0; // bits in bit buffer | ||
let p = 0; // input data pointer | ||
let n; // bytes available there | ||
let q; // output window write pointer | ||
let m; // bytes to end of window or read pointer | ||
let f; // pointer to copy strings from | ||
// copy input/output information to locals (UPDATE macro restores) | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = s.bitb; | ||
k = s.bitk; | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
// process input and output based on current state | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
switch (mode) { | ||
// waiting for "i:"=input, "o:"=output, "x:"=nothing | ||
case START: // x: set up for LEN | ||
if (m >= 258 && n >= 10) { | ||
s.bitb = b; | ||
@@ -785,236 +817,164 @@ s.bitk = k; | ||
s.write = q; | ||
r = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z); | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = s.bitb; | ||
k = s.bitk; | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
if (r != Z_OK) { | ||
mode = r == Z_STREAM_END ? WASH : BADCODE; | ||
break; | ||
} | ||
return s.inflate_flush(z, r); | ||
} | ||
need = lbits; | ||
tree = ltree; | ||
tree_index = ltree_index; | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
mode = LEN; | ||
/* falls through */ | ||
case LEN: // i: get length/literal/eob next | ||
j = need; | ||
tindex = (tree_index + (b & inflate_mask[j])) * 3; | ||
while (k < (j)) { | ||
if (n !== 0) | ||
r = Z_OK; | ||
else { | ||
b >>>= (tree[tindex + 1]); | ||
k -= (tree[tindex + 1]); | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
e = tree[tindex]; | ||
tindex = (tree_index + (b & inflate_mask[j])) * 3; | ||
if (e === 0) { // literal | ||
lit = tree[tindex + 2]; | ||
mode = LIT; | ||
break; | ||
} | ||
if ((e & 16) !== 0) { // length | ||
get = e & 15; | ||
len = tree[tindex + 2]; | ||
mode = LENEXT; | ||
break; | ||
} | ||
if ((e & 64) === 0) { // next table | ||
need = e; | ||
tree_index = tindex / 3 + tree[tindex + 2]; | ||
break; | ||
} | ||
if ((e & 32) !== 0) { // end of block | ||
mode = WASH; | ||
break; | ||
} | ||
mode = BADCODE; // invalid code | ||
z.msg = "invalid literal/length code"; | ||
r = Z_DATA_ERROR; | ||
b >>>= (tree[tindex + 1]); | ||
k -= (tree[tindex + 1]); | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
e = tree[tindex]; | ||
case LENEXT: // i: getting length extra (have base) | ||
j = get; | ||
if (e === 0) { // literal | ||
lit = tree[tindex + 2]; | ||
mode = LIT; | ||
break; | ||
} | ||
if ((e & 16) !== 0) { // length | ||
get = e & 15; | ||
len = tree[tindex + 2]; | ||
mode = LENEXT; | ||
break; | ||
} | ||
if ((e & 64) === 0) { // next table | ||
need = e; | ||
tree_index = tindex / 3 + tree[tindex + 2]; | ||
break; | ||
} | ||
if ((e & 32) !== 0) { // end of block | ||
mode = WASH; | ||
break; | ||
} | ||
mode = BADCODE; // invalid code | ||
z.msg = "invalid literal/length code"; | ||
r = Z_DATA_ERROR; | ||
while (k < (j)) { | ||
if (n !== 0) | ||
r = Z_OK; | ||
else { | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
case LENEXT: // i: getting length extra (have base) | ||
j = get; | ||
while (k < (j)) { | ||
if (n !== 0) | ||
r = Z_OK; | ||
else { | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
len += (b & inflate_mask[j]); | ||
len += (b & inflate_mask[j]); | ||
b >>= j; | ||
k -= j; | ||
b >>= j; | ||
k -= j; | ||
need = dbits; | ||
tree = dtree; | ||
tree_index = dtree_index; | ||
mode = DIST; | ||
/* falls through */ | ||
case DIST: // i: get distance next | ||
j = need; | ||
need = dbits; | ||
tree = dtree; | ||
tree_index = dtree_index; | ||
mode = DIST; | ||
/* falls through */ | ||
case DIST: // i: get distance next | ||
j = need; | ||
while (k < (j)) { | ||
if (n !== 0) | ||
r = Z_OK; | ||
else { | ||
while (k < (j)) { | ||
if (n !== 0) | ||
r = Z_OK; | ||
else { | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
tindex = (tree_index + (b & inflate_mask[j])) * 3; | ||
tindex = (tree_index + (b & inflate_mask[j])) * 3; | ||
b >>= tree[tindex + 1]; | ||
k -= tree[tindex + 1]; | ||
b >>= tree[tindex + 1]; | ||
k -= tree[tindex + 1]; | ||
e = (tree[tindex]); | ||
if ((e & 16) !== 0) { // distance | ||
get = e & 15; | ||
dist = tree[tindex + 2]; | ||
mode = DISTEXT; | ||
break; | ||
} | ||
if ((e & 64) === 0) { // next table | ||
need = e; | ||
tree_index = tindex / 3 + tree[tindex + 2]; | ||
break; | ||
} | ||
mode = BADCODE; // invalid code | ||
z.msg = "invalid distance code"; | ||
r = Z_DATA_ERROR; | ||
e = (tree[tindex]); | ||
if ((e & 16) !== 0) { // distance | ||
get = e & 15; | ||
dist = tree[tindex + 2]; | ||
mode = DISTEXT; | ||
break; | ||
} | ||
if ((e & 64) === 0) { // next table | ||
need = e; | ||
tree_index = tindex / 3 + tree[tindex + 2]; | ||
break; | ||
} | ||
mode = BADCODE; // invalid code | ||
z.msg = "invalid distance code"; | ||
r = Z_DATA_ERROR; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
case DISTEXT: // i: getting distance extra | ||
j = get; | ||
case DISTEXT: // i: getting distance extra | ||
j = get; | ||
while (k < (j)) { | ||
if (n !== 0) | ||
r = Z_OK; | ||
else { | ||
while (k < (j)) { | ||
if (n !== 0) | ||
r = Z_OK; | ||
else { | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
dist += (b & inflate_mask[j]); | ||
dist += (b & inflate_mask[j]); | ||
b >>= j; | ||
k -= j; | ||
b >>= j; | ||
k -= j; | ||
mode = COPY; | ||
/* falls through */ | ||
case COPY: // o: copying bytes in window, waiting for space | ||
f = q - dist; | ||
while (f < 0) { // modulo window size-"while" instead | ||
f += s.end; // of "if" handles invalid distances | ||
} | ||
while (len !== 0) { | ||
mode = COPY; | ||
/* falls through */ | ||
case COPY: // o: copying bytes in window, waiting for space | ||
f = q - dist; | ||
while (f < 0) { // modulo window size-"while" instead | ||
f += s.end; // of "if" handles invalid distances | ||
} | ||
while (len !== 0) { | ||
if (m === 0) { | ||
if (q == s.end && s.read !== 0) { | ||
q = 0; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
} | ||
if (m === 0) { | ||
s.write = q; | ||
r = s.inflate_flush(z, r); | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
if (q == s.end && s.read !== 0) { | ||
q = 0; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
} | ||
if (m === 0) { | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
} | ||
} | ||
s.window[q++] = s.window[f++]; | ||
m--; | ||
if (f == s.end) | ||
f = 0; | ||
len--; | ||
} | ||
mode = START; | ||
break; | ||
case LIT: // o: got literal, waiting for output space | ||
if (m === 0) { | ||
@@ -1035,2 +995,3 @@ if (q == s.end && s.read !== 0) { | ||
} | ||
if (m === 0) { | ||
@@ -1047,46 +1008,59 @@ s.bitb = b; | ||
} | ||
r = Z_OK; | ||
s.window[q++] = /* (byte) */lit; | ||
s.window[q++] = s.window[f++]; | ||
m--; | ||
mode = START; | ||
break; | ||
case WASH: // o: got eob, possibly more output | ||
if (k > 7) { // return unused byte, if any | ||
k -= 8; | ||
n++; | ||
p--; // can always return one | ||
if (f == s.end) | ||
f = 0; | ||
len--; | ||
} | ||
mode = START; | ||
break; | ||
case LIT: // o: got literal, waiting for output space | ||
if (m === 0) { | ||
if (q == s.end && s.read !== 0) { | ||
q = 0; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
} | ||
if (m === 0) { | ||
s.write = q; | ||
r = s.inflate_flush(z, r); | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
s.write = q; | ||
r = s.inflate_flush(z, r); | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
if (s.read != s.write) { | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
if (q == s.end && s.read !== 0) { | ||
q = 0; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
} | ||
if (m === 0) { | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
} | ||
mode = END; | ||
/* falls through */ | ||
case END: | ||
r = Z_STREAM_END; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
r = Z_OK; | ||
case BADCODE: // x: got error | ||
s.window[q++] = /* (byte) */lit; | ||
m--; | ||
r = Z_DATA_ERROR; | ||
mode = START; | ||
break; | ||
case WASH: // o: got eob, possibly more output | ||
if (k > 7) { // return unused byte, if any | ||
k -= 8; | ||
n++; | ||
p--; // can always return one | ||
} | ||
s.write = q; | ||
r = s.inflate_flush(z, r); | ||
q = s.write; | ||
m = q < s.read ? s.read - q - 1 : s.end - q; | ||
if (s.read != s.write) { | ||
s.bitb = b; | ||
@@ -1099,98 +1073,145 @@ s.bitk = k; | ||
return s.inflate_flush(z, r); | ||
} | ||
mode = END; | ||
/* falls through */ | ||
case END: | ||
r = Z_STREAM_END; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
default: | ||
r = Z_STREAM_ERROR; | ||
case BADCODE: // x: got error | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
r = Z_DATA_ERROR; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
default: | ||
r = Z_STREAM_ERROR; | ||
s.bitb = b; | ||
s.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
s.write = q; | ||
return s.inflate_flush(z, r); | ||
} | ||
}; | ||
} | ||
}; | ||
that.free = function () { | ||
// ZFREE(z, c); | ||
}; | ||
that.free = function () { | ||
// ZFREE(z, c); | ||
}; | ||
} | ||
} | ||
// InfBlocks | ||
// InfBlocks | ||
// Table for deflate from PKZIP's appnote.txt. | ||
const border = [ // Order of the bit length code lengths | ||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; | ||
// Table for deflate from PKZIP's appnote.txt. | ||
const border = [ // Order of the bit length code lengths | ||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; | ||
const TYPE = 0; // get type bits (3, including end bit) | ||
const LENS = 1; // get lengths for stored | ||
const STORED = 2;// processing stored block | ||
const TABLE = 3; // get table lengths | ||
const BTREE = 4; // get bit lengths tree for a dynamic | ||
// block | ||
const DTREE = 5; // get length, distance trees for a | ||
// dynamic block | ||
const CODES = 6; // processing fixed or dynamic block | ||
const DRY = 7; // output remaining window bytes | ||
const DONELOCKS = 8; // finished last block, done | ||
const BADBLOCKS = 9; // ot a data error--stuck here | ||
const TYPE = 0; // get type bits (3, including end bit) | ||
const LENS = 1; // get lengths for stored | ||
const STORED = 2;// processing stored block | ||
const TABLE = 3; // get table lengths | ||
const BTREE = 4; // get bit lengths tree for a dynamic | ||
// block | ||
const DTREE = 5; // get length, distance trees for a | ||
// dynamic block | ||
const CODES = 6; // processing fixed or dynamic block | ||
const DRY = 7; // output remaining window bytes | ||
const DONELOCKS = 8; // finished last block, done | ||
const BADBLOCKS = 9; // ot a data error--stuck here | ||
function InfBlocks(z, w) { | ||
const that = this; | ||
function InfBlocks(z, w) { | ||
const that = this; | ||
let mode = TYPE; // current inflate_block mode | ||
let mode = TYPE; // current inflate_block mode | ||
let left = 0; // if STORED, bytes left to copy | ||
let left = 0; // if STORED, bytes left to copy | ||
let table = 0; // table lengths (14 bits) | ||
let index = 0; // index into blens (or border) | ||
let blens; // bit lengths of codes | ||
const bb = [0]; // bit length tree depth | ||
const tb = [0]; // bit length decoding tree | ||
let table = 0; // table lengths (14 bits) | ||
let index = 0; // index into blens (or border) | ||
let blens; // bit lengths of codes | ||
const bb = [0]; // bit length tree depth | ||
const tb = [0]; // bit length decoding tree | ||
const codes = new InfCodes(); // if CODES, current state | ||
const codes = new InfCodes(); // if CODES, current state | ||
let last = 0; // true if this block is the last block | ||
let last = 0; // true if this block is the last block | ||
let hufts = new Int32Array(MANY * 3); // single malloc for tree space | ||
const check = 0; // check on output | ||
const inftree = new InfTree(); | ||
let hufts = new Int32Array(MANY * 3); // single malloc for tree space | ||
const check = 0; // check on output | ||
const inftree = new InfTree(); | ||
that.bitk = 0; // bits in bit buffer | ||
that.bitb = 0; // bit buffer | ||
that.window = new Uint8Array(w); // sliding window | ||
that.end = w; // one byte after sliding window | ||
that.read = 0; // window read pointer | ||
that.write = 0; // window write pointer | ||
that.bitk = 0; // bits in bit buffer | ||
that.bitb = 0; // bit buffer | ||
that.window = new Uint8Array(w); // sliding window | ||
that.end = w; // one byte after sliding window | ||
that.read = 0; // window read pointer | ||
that.write = 0; // window write pointer | ||
that.reset = function (z, c) { | ||
if (c) | ||
c[0] = check; | ||
// if (mode == BTREE || mode == DTREE) { | ||
// } | ||
if (mode == CODES) { | ||
codes.free(z); | ||
} | ||
mode = TYPE; | ||
that.bitk = 0; | ||
that.bitb = 0; | ||
that.read = that.write = 0; | ||
}; | ||
that.reset = function (z, c) { | ||
if (c) | ||
c[0] = check; | ||
// if (mode == BTREE || mode == DTREE) { | ||
// } | ||
if (mode == CODES) { | ||
codes.free(z); | ||
} | ||
mode = TYPE; | ||
that.bitk = 0; | ||
that.bitb = 0; | ||
that.read = that.write = 0; | ||
}; | ||
that.reset(z, null); | ||
that.reset(z, null); | ||
// copy as much as possible from the sliding window to the output area | ||
that.inflate_flush = function (z, r) { | ||
let n; | ||
let p; | ||
let q; | ||
// copy as much as possible from the sliding window to the output area | ||
that.inflate_flush = function (z, r) { | ||
let n; | ||
let p; | ||
let q; | ||
// local copies of source and destination pointers | ||
p = z.next_out_index; | ||
q = that.read; | ||
// local copies of source and destination pointers | ||
p = z.next_out_index; | ||
q = that.read; | ||
// compute number of bytes to copy as far as end of window | ||
n = /* (int) */((q <= that.write ? that.write : that.end) - q); | ||
// compute number of bytes to copy as far as end of window | ||
n = /* (int) */((q <= that.write ? that.write : that.end) - q); | ||
if (n > z.avail_out) | ||
n = z.avail_out; | ||
if (n !== 0 && r == Z_BUF_ERROR) | ||
r = Z_OK; | ||
// update counters | ||
z.avail_out -= n; | ||
z.total_out += n; | ||
// copy as far as end of window | ||
z.next_out.set(that.window.subarray(q, q + n), p); | ||
p += n; | ||
q += n; | ||
// see if more to copy at beginning of window | ||
if (q == that.end) { | ||
// wrap pointers | ||
q = 0; | ||
if (that.write == that.end) | ||
that.write = 0; | ||
// compute bytes to copy | ||
n = that.write - q; | ||
if (n > z.avail_out) | ||
@@ -1205,171 +1226,115 @@ n = z.avail_out; | ||
// copy as far as end of window | ||
// copy | ||
z.next_out.set(that.window.subarray(q, q + n), p); | ||
p += n; | ||
q += n; | ||
} | ||
// see if more to copy at beginning of window | ||
if (q == that.end) { | ||
// wrap pointers | ||
q = 0; | ||
if (that.write == that.end) | ||
that.write = 0; | ||
// update pointers | ||
z.next_out_index = p; | ||
that.read = q; | ||
// compute bytes to copy | ||
n = that.write - q; | ||
if (n > z.avail_out) | ||
n = z.avail_out; | ||
if (n !== 0 && r == Z_BUF_ERROR) | ||
r = Z_OK; | ||
// done | ||
return r; | ||
}; | ||
// update counters | ||
z.avail_out -= n; | ||
z.total_out += n; | ||
that.proc = function (z, r) { | ||
let t; // temporary storage | ||
let b; // bit buffer | ||
let k; // bits in bit buffer | ||
let p; // input data pointer | ||
let n; // bytes available there | ||
let q; // output window write pointer | ||
let m; // bytes to end of window or read pointer | ||
// copy | ||
z.next_out.set(that.window.subarray(q, q + n), p); | ||
p += n; | ||
q += n; | ||
} | ||
let i; | ||
// update pointers | ||
z.next_out_index = p; | ||
that.read = q; | ||
// copy input/output information to locals (UPDATE macro restores) | ||
// { | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = that.bitb; | ||
k = that.bitk; | ||
// } | ||
// { | ||
q = that.write; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
// } | ||
// done | ||
return r; | ||
}; | ||
// process input based on current state | ||
// DEBUG dtree | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
let bl, bd, tl, td, bl_, bd_, tl_, td_; | ||
switch (mode) { | ||
case TYPE: | ||
that.proc = function (z, r) { | ||
let t; // temporary storage | ||
let b; // bit buffer | ||
let k; // bits in bit buffer | ||
let p; // input data pointer | ||
let n; // bytes available there | ||
let q; // output window write pointer | ||
let m; // bytes to end of window or read pointer | ||
let i; | ||
// copy input/output information to locals (UPDATE macro restores) | ||
// { | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = that.bitb; | ||
k = that.bitk; | ||
// } | ||
// { | ||
q = that.write; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
// } | ||
// process input based on current state | ||
// DEBUG dtree | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
let bl, bd, tl, td, bl_, bd_, tl_, td_; | ||
switch (mode) { | ||
case TYPE: | ||
while (k < (3)) { | ||
if (n !== 0) { | ||
r = Z_OK; | ||
} else { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
while (k < (3)) { | ||
if (n !== 0) { | ||
r = Z_OK; | ||
} else { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
t = /* (int) */(b & 7); | ||
last = t & 1; | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
t = /* (int) */(b & 7); | ||
last = t & 1; | ||
switch (t >>> 1) { | ||
case 0: // stored | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
t = k & 7; // go to byte boundary | ||
switch (t >>> 1) { | ||
case 0: // stored | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
t = k & 7; // go to byte boundary | ||
// { | ||
b >>>= (t); | ||
k -= (t); | ||
// } | ||
mode = LENS; // get length of stored block | ||
break; | ||
case 1: // fixed | ||
// { | ||
bl = []; // new Array(1); | ||
bd = []; // new Array(1); | ||
tl = [[]]; // new Array(1); | ||
td = [[]]; // new Array(1); | ||
// { | ||
b >>>= (t); | ||
k -= (t); | ||
// } | ||
mode = LENS; // get length of stored block | ||
break; | ||
case 1: // fixed | ||
// { | ||
bl = []; // new Array(1); | ||
bd = []; // new Array(1); | ||
tl = [[]]; // new Array(1); | ||
td = [[]]; // new Array(1); | ||
InfTree.inflate_trees_fixed(bl, bd, tl, td); | ||
codes.init(bl[0], bd[0], tl[0], 0, td[0], 0); | ||
// } | ||
InfTree.inflate_trees_fixed(bl, bd, tl, td); | ||
codes.init(bl[0], bd[0], tl[0], 0, td[0], 0); | ||
// } | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
mode = CODES; | ||
break; | ||
case 2: // dynamic | ||
mode = CODES; | ||
break; | ||
case 2: // dynamic | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
mode = TABLE; | ||
break; | ||
case 3: // illegal | ||
mode = TABLE; | ||
break; | ||
case 3: // illegal | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
mode = BADBLOCKS; | ||
z.msg = "invalid block type"; | ||
r = Z_DATA_ERROR; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
break; | ||
case LENS: | ||
while (k < (32)) { | ||
if (n !== 0) { | ||
r = Z_OK; | ||
} else { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) { | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
mode = BADBLOCKS; | ||
z.msg = "invalid stored block lengths"; | ||
z.msg = "invalid block type"; | ||
r = Z_DATA_ERROR; | ||
@@ -1384,9 +1349,10 @@ | ||
return that.inflate_flush(z, r); | ||
} | ||
left = (b & 0xffff); | ||
b = k = 0; // dump bits | ||
mode = left !== 0 ? STORED : (last !== 0 ? DRY : TYPE); | ||
break; | ||
case STORED: | ||
if (n === 0) { | ||
} | ||
break; | ||
case LENS: | ||
while (k < (32)) { | ||
if (n !== 0) { | ||
r = Z_OK; | ||
} else { | ||
that.bitb = b; | ||
@@ -1400,4 +1366,45 @@ that.bitk = k; | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) { | ||
mode = BADBLOCKS; | ||
z.msg = "invalid stored block lengths"; | ||
r = Z_DATA_ERROR; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
left = (b & 0xffff); | ||
b = k = 0; // dump bits | ||
mode = left !== 0 ? STORED : (last !== 0 ? DRY : TYPE); | ||
break; | ||
case STORED: | ||
if (n === 0) { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
if (m === 0) { | ||
if (q == that.end && that.read !== 0) { | ||
q = 0; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
} | ||
if (m === 0) { | ||
that.write = q; | ||
r = that.inflate_flush(z, r); | ||
q = that.write; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
if (q == that.end && that.read !== 0) { | ||
@@ -1408,40 +1415,82 @@ q = 0; | ||
if (m === 0) { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
r = that.inflate_flush(z, r); | ||
q = that.write; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
if (q == that.end && that.read !== 0) { | ||
q = 0; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
} | ||
if (m === 0) { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
return that.inflate_flush(z, r); | ||
} | ||
} | ||
r = Z_OK; | ||
} | ||
r = Z_OK; | ||
t = left; | ||
if (t > n) | ||
t = n; | ||
if (t > m) | ||
t = m; | ||
that.window.set(z.read_buf(p, t), q); | ||
p += t; | ||
n -= t; | ||
q += t; | ||
m -= t; | ||
if ((left -= t) !== 0) | ||
break; | ||
mode = last !== 0 ? DRY : TYPE; | ||
t = left; | ||
if (t > n) | ||
t = n; | ||
if (t > m) | ||
t = m; | ||
that.window.set(z.read_buf(p, t), q); | ||
p += t; | ||
n -= t; | ||
q += t; | ||
m -= t; | ||
if ((left -= t) !== 0) | ||
break; | ||
case TABLE: | ||
mode = last !== 0 ? DRY : TYPE; | ||
break; | ||
case TABLE: | ||
while (k < (14)) { | ||
while (k < (14)) { | ||
if (n !== 0) { | ||
r = Z_OK; | ||
} else { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
table = t = (b & 0x3fff); | ||
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) { | ||
mode = BADBLOCKS; | ||
z.msg = "too many length or distance symbols"; | ||
r = Z_DATA_ERROR; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); | ||
if (!blens || blens.length < t) { | ||
blens = []; // new Array(t); | ||
} else { | ||
for (i = 0; i < t; i++) { | ||
blens[i] = 0; | ||
} | ||
} | ||
// { | ||
b >>>= (14); | ||
k -= (14); | ||
// } | ||
index = 0; | ||
mode = BTREE; | ||
/* falls through */ | ||
case BTREE: | ||
while (index < 4 + (table >>> 10)) { | ||
while (k < (3)) { | ||
if (n !== 0) { | ||
@@ -1458,3 +1507,2 @@ r = Z_OK; | ||
} | ||
n--; | ||
@@ -1465,98 +1513,80 @@ b |= (z.read_byte(p++) & 0xff) << k; | ||
table = t = (b & 0x3fff); | ||
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) { | ||
mode = BADBLOCKS; | ||
z.msg = "too many length or distance symbols"; | ||
r = Z_DATA_ERROR; | ||
blens[border[index++]] = b & 7; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); | ||
if (!blens || blens.length < t) { | ||
blens = []; // new Array(t); | ||
} else { | ||
for (i = 0; i < t; i++) { | ||
blens[i] = 0; | ||
} | ||
} | ||
// { | ||
b >>>= (14); | ||
k -= (14); | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
} | ||
index = 0; | ||
mode = BTREE; | ||
/* falls through */ | ||
case BTREE: | ||
while (index < 4 + (table >>> 10)) { | ||
while (k < (3)) { | ||
if (n !== 0) { | ||
r = Z_OK; | ||
} else { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
while (index < 19) { | ||
blens[border[index++]] = 0; | ||
} | ||
blens[border[index++]] = b & 7; | ||
// { | ||
b >>>= (3); | ||
k -= (3); | ||
// } | ||
bb[0] = 7; | ||
t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z); | ||
if (t != Z_OK) { | ||
r = t; | ||
if (r == Z_DATA_ERROR) { | ||
blens = null; | ||
mode = BADBLOCKS; | ||
} | ||
while (index < 19) { | ||
blens[border[index++]] = 0; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
index = 0; | ||
mode = DTREE; | ||
/* falls through */ | ||
case DTREE: | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
t = table; | ||
if (index >= 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) { | ||
break; | ||
} | ||
bb[0] = 7; | ||
t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z); | ||
if (t != Z_OK) { | ||
r = t; | ||
if (r == Z_DATA_ERROR) { | ||
blens = null; | ||
mode = BADBLOCKS; | ||
} | ||
let j, c; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
t = bb[0]; | ||
index = 0; | ||
mode = DTREE; | ||
/* falls through */ | ||
case DTREE: | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
t = table; | ||
if (index >= 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) { | ||
break; | ||
while (k < (t)) { | ||
if (n !== 0) { | ||
r = Z_OK; | ||
} else { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
let j, c; | ||
// if (tb[0] == -1) { | ||
// System.err.println("null..."); | ||
// } | ||
t = bb[0]; | ||
t = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1]; | ||
c = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2]; | ||
while (k < (t)) { | ||
if (c < 16) { | ||
b >>>= (t); | ||
k -= (t); | ||
blens[index++] = c; | ||
} else { // c == 16..18 | ||
i = c == 18 ? 7 : c - 14; | ||
j = c == 18 ? 11 : 3; | ||
while (k < (t + i)) { | ||
if (n !== 0) { | ||
@@ -1578,143 +1608,53 @@ r = Z_OK; | ||
// if (tb[0] == -1) { | ||
// System.err.println("null..."); | ||
// } | ||
b >>>= (t); | ||
k -= (t); | ||
t = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1]; | ||
c = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2]; | ||
j += (b & inflate_mask[i]); | ||
if (c < 16) { | ||
b >>>= (t); | ||
k -= (t); | ||
blens[index++] = c; | ||
} else { // c == 16..18 | ||
i = c == 18 ? 7 : c - 14; | ||
j = c == 18 ? 11 : 3; | ||
b >>>= (i); | ||
k -= (i); | ||
while (k < (t + i)) { | ||
if (n !== 0) { | ||
r = Z_OK; | ||
} else { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
n--; | ||
b |= (z.read_byte(p++) & 0xff) << k; | ||
k += 8; | ||
} | ||
b >>>= (t); | ||
k -= (t); | ||
j += (b & inflate_mask[i]); | ||
b >>>= (i); | ||
k -= (i); | ||
i = index; | ||
t = table; | ||
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) { | ||
blens = null; | ||
mode = BADBLOCKS; | ||
z.msg = "invalid bit length repeat"; | ||
r = Z_DATA_ERROR; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
c = c == 16 ? blens[i - 1] : 0; | ||
do { | ||
blens[i++] = c; | ||
} while (--j !== 0); | ||
index = i; | ||
} | ||
} | ||
tb[0] = -1; | ||
// { | ||
bl_ = []; // new Array(1); | ||
bd_ = []; // new Array(1); | ||
tl_ = []; // new Array(1); | ||
td_ = []; // new Array(1); | ||
bl_[0] = 9; // must be <= 9 for lookahead assumptions | ||
bd_[0] = 6; // must be <= 9 for lookahead assumptions | ||
t = table; | ||
t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl_, bd_, tl_, td_, hufts, z); | ||
if (t != Z_OK) { | ||
if (t == Z_DATA_ERROR) { | ||
i = index; | ||
t = table; | ||
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) { | ||
blens = null; | ||
mode = BADBLOCKS; | ||
z.msg = "invalid bit length repeat"; | ||
r = Z_DATA_ERROR; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
r = t; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
c = c == 16 ? blens[i - 1] : 0; | ||
do { | ||
blens[i++] = c; | ||
} while (--j !== 0); | ||
index = i; | ||
} | ||
codes.init(bl_[0], bd_[0], hufts, tl_[0], hufts, td_[0]); | ||
// } | ||
mode = CODES; | ||
/* falls through */ | ||
case CODES: | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
} | ||
if ((r = codes.proc(that, z, r)) != Z_STREAM_END) { | ||
return that.inflate_flush(z, r); | ||
} | ||
r = Z_OK; | ||
codes.free(z); | ||
tb[0] = -1; | ||
// { | ||
bl_ = []; // new Array(1); | ||
bd_ = []; // new Array(1); | ||
tl_ = []; // new Array(1); | ||
td_ = []; // new Array(1); | ||
bl_[0] = 9; // must be <= 9 for lookahead assumptions | ||
bd_[0] = 6; // must be <= 9 for lookahead assumptions | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = that.bitb; | ||
k = that.bitk; | ||
q = that.write; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
t = table; | ||
t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl_, bd_, tl_, td_, hufts, z); | ||
if (last === 0) { | ||
mode = TYPE; | ||
break; | ||
if (t != Z_OK) { | ||
if (t == Z_DATA_ERROR) { | ||
blens = null; | ||
mode = BADBLOCKS; | ||
} | ||
mode = DRY; | ||
/* falls through */ | ||
case DRY: | ||
that.write = q; | ||
r = that.inflate_flush(z, r); | ||
q = that.write; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
if (that.read != that.write) { | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
mode = DONELOCKS; | ||
/* falls through */ | ||
case DONELOCKS: | ||
r = Z_STREAM_END; | ||
r = t; | ||
@@ -1728,16 +1668,40 @@ that.bitb = b; | ||
return that.inflate_flush(z, r); | ||
case BADBLOCKS: | ||
r = Z_DATA_ERROR; | ||
} | ||
codes.init(bl_[0], bd_[0], hufts, tl_[0], hufts, td_[0]); | ||
// } | ||
mode = CODES; | ||
/* falls through */ | ||
case CODES: | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
if ((r = codes.proc(that, z, r)) != Z_STREAM_END) { | ||
return that.inflate_flush(z, r); | ||
} | ||
r = Z_OK; | ||
codes.free(z); | ||
default: | ||
r = Z_STREAM_ERROR; | ||
p = z.next_in_index; | ||
n = z.avail_in; | ||
b = that.bitb; | ||
k = that.bitk; | ||
q = that.write; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
if (last === 0) { | ||
mode = TYPE; | ||
break; | ||
} | ||
mode = DRY; | ||
/* falls through */ | ||
case DRY: | ||
that.write = q; | ||
r = that.inflate_flush(z, r); | ||
q = that.write; | ||
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q); | ||
if (that.read != that.write) { | ||
that.bitb = b; | ||
@@ -1750,429 +1714,461 @@ that.bitk = k; | ||
return that.inflate_flush(z, r); | ||
} | ||
} | ||
mode = DONELOCKS; | ||
/* falls through */ | ||
case DONELOCKS: | ||
r = Z_STREAM_END; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
case BADBLOCKS: | ||
r = Z_DATA_ERROR; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
default: | ||
r = Z_STREAM_ERROR; | ||
that.bitb = b; | ||
that.bitk = k; | ||
z.avail_in = n; | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
that.write = q; | ||
return that.inflate_flush(z, r); | ||
} | ||
}; | ||
} | ||
}; | ||
that.free = function (z) { | ||
that.reset(z, null); | ||
that.window = null; | ||
hufts = null; | ||
// ZFREE(z, s); | ||
}; | ||
that.free = function (z) { | ||
that.reset(z, null); | ||
that.window = null; | ||
hufts = null; | ||
// ZFREE(z, s); | ||
}; | ||
that.set_dictionary = function (d, start, n) { | ||
that.window.set(d.subarray(start, start + n), 0); | ||
that.read = that.write = n; | ||
}; | ||
that.set_dictionary = function (d, start, n) { | ||
that.window.set(d.subarray(start, start + n), 0); | ||
that.read = that.write = n; | ||
}; | ||
// Returns true if inflate is currently at the end of a block generated | ||
// by Z_SYNC_FLUSH or Z_FULL_FLUSH. | ||
that.sync_point = function () { | ||
return mode == LENS ? 1 : 0; | ||
}; | ||
// Returns true if inflate is currently at the end of a block generated | ||
// by Z_SYNC_FLUSH or Z_FULL_FLUSH. | ||
that.sync_point = function () { | ||
return mode == LENS ? 1 : 0; | ||
}; | ||
} | ||
} | ||
// Inflate | ||
// Inflate | ||
// preset dictionary flag in zlib header | ||
const PRESET_DICT = 0x20; | ||
// preset dictionary flag in zlib header | ||
const PRESET_DICT = 0x20; | ||
const Z_DEFLATED = 8; | ||
const Z_DEFLATED = 8; | ||
const METHOD = 0; // waiting for method byte | ||
const FLAG = 1; // waiting for flag byte | ||
const DICT4 = 2; // four dictionary check bytes to go | ||
const DICT3 = 3; // three dictionary check bytes to go | ||
const DICT2 = 4; // two dictionary check bytes to go | ||
const DICT1 = 5; // one dictionary check byte to go | ||
const DICT0 = 6; // waiting for inflateSetDictionary | ||
const BLOCKS = 7; // decompressing blocks | ||
const DONE = 12; // finished check, done | ||
const BAD = 13; // got an error--stay here | ||
const METHOD = 0; // waiting for method byte | ||
const FLAG = 1; // waiting for flag byte | ||
const DICT4 = 2; // four dictionary check bytes to go | ||
const DICT3 = 3; // three dictionary check bytes to go | ||
const DICT2 = 4; // two dictionary check bytes to go | ||
const DICT1 = 5; // one dictionary check byte to go | ||
const DICT0 = 6; // waiting for inflateSetDictionary | ||
const BLOCKS = 7; // decompressing blocks | ||
const DONE = 12; // finished check, done | ||
const BAD = 13; // got an error--stay here | ||
const mark = [0, 0, 0xff, 0xff]; | ||
const mark = [0, 0, 0xff, 0xff]; | ||
function Inflate() { | ||
const that = this; | ||
function Inflate() { | ||
const that = this; | ||
that.mode = 0; // current inflate mode | ||
that.mode = 0; // current inflate mode | ||
// mode dependent information | ||
that.method = 0; // if FLAGS, method byte | ||
// mode dependent information | ||
that.method = 0; // if FLAGS, method byte | ||
// if CHECK, check values to compare | ||
that.was = [0]; // new Array(1); // computed check value | ||
that.need = 0; // stream check value | ||
// if CHECK, check values to compare | ||
that.was = [0]; // new Array(1); // computed check value | ||
that.need = 0; // stream check value | ||
// if BAD, inflateSync's marker bytes count | ||
that.marker = 0; | ||
// if BAD, inflateSync's marker bytes count | ||
that.marker = 0; | ||
// mode independent information | ||
that.wbits = 0; // log2(window size) (8..15, defaults to 15) | ||
// mode independent information | ||
that.wbits = 0; // log2(window size) (8..15, defaults to 15) | ||
// this.blocks; // current inflate_blocks state | ||
// this.blocks; // current inflate_blocks state | ||
function inflateReset(z) { | ||
if (!z || !z.istate) | ||
return Z_STREAM_ERROR; | ||
function inflateReset(z) { | ||
if (!z || !z.istate) | ||
return Z_STREAM_ERROR; | ||
z.total_in = z.total_out = 0; | ||
z.msg = null; | ||
z.istate.mode = BLOCKS; | ||
z.istate.blocks.reset(z, null); | ||
return Z_OK; | ||
} | ||
z.total_in = z.total_out = 0; | ||
z.msg = null; | ||
z.istate.mode = BLOCKS; | ||
z.istate.blocks.reset(z, null); | ||
return Z_OK; | ||
} | ||
that.inflateEnd = function (z) { | ||
if (that.blocks) | ||
that.blocks.free(z); | ||
that.blocks = null; | ||
// ZFREE(z, z->state); | ||
return Z_OK; | ||
}; | ||
that.inflateEnd = function (z) { | ||
if (that.blocks) | ||
that.blocks.free(z); | ||
that.blocks = null; | ||
// ZFREE(z, z->state); | ||
return Z_OK; | ||
}; | ||
that.inflateInit = function (z, w) { | ||
z.msg = null; | ||
that.blocks = null; | ||
that.inflateInit = function (z, w) { | ||
z.msg = null; | ||
that.blocks = null; | ||
// set window size | ||
if (w < 8 || w > 15) { | ||
that.inflateEnd(z); | ||
return Z_STREAM_ERROR; | ||
} | ||
that.wbits = w; | ||
// set window size | ||
if (w < 8 || w > 15) { | ||
that.inflateEnd(z); | ||
return Z_STREAM_ERROR; | ||
} | ||
that.wbits = w; | ||
z.istate.blocks = new InfBlocks(z, 1 << w); | ||
z.istate.blocks = new InfBlocks(z, 1 << w); | ||
// reset state | ||
inflateReset(z); | ||
return Z_OK; | ||
}; | ||
// reset state | ||
inflateReset(z); | ||
return Z_OK; | ||
}; | ||
that.inflate = function (z, f) { | ||
let r; | ||
let b; | ||
that.inflate = function (z, f) { | ||
let r; | ||
let b; | ||
if (!z || !z.istate || !z.next_in) | ||
return Z_STREAM_ERROR; | ||
const istate = z.istate; | ||
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK; | ||
r = Z_BUF_ERROR; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
switch (istate.mode) { | ||
case METHOD: | ||
if (!z || !z.istate || !z.next_in) | ||
return Z_STREAM_ERROR; | ||
const istate = z.istate; | ||
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK; | ||
r = Z_BUF_ERROR; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
switch (istate.mode) { | ||
case METHOD: | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
z.avail_in--; | ||
z.total_in++; | ||
if (((istate.method = z.read_byte(z.next_in_index++)) & 0xf) != Z_DEFLATED) { | ||
istate.mode = BAD; | ||
z.msg = "unknown compression method"; | ||
istate.marker = 5; // can't try inflateSync | ||
break; | ||
} | ||
if ((istate.method >> 4) + 8 > istate.wbits) { | ||
istate.mode = BAD; | ||
z.msg = "invalid window size"; | ||
istate.marker = 5; // can't try inflateSync | ||
break; | ||
} | ||
istate.mode = FLAG; | ||
/* falls through */ | ||
case FLAG: | ||
z.avail_in--; | ||
z.total_in++; | ||
if (((istate.method = z.read_byte(z.next_in_index++)) & 0xf) != Z_DEFLATED) { | ||
istate.mode = BAD; | ||
z.msg = "unknown compression method"; | ||
istate.marker = 5; // can't try inflateSync | ||
break; | ||
} | ||
if ((istate.method >> 4) + 8 > istate.wbits) { | ||
istate.mode = BAD; | ||
z.msg = "invalid window size"; | ||
istate.marker = 5; // can't try inflateSync | ||
break; | ||
} | ||
istate.mode = FLAG; | ||
/* falls through */ | ||
case FLAG: | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
z.avail_in--; | ||
z.total_in++; | ||
b = (z.read_byte(z.next_in_index++)) & 0xff; | ||
z.avail_in--; | ||
z.total_in++; | ||
b = (z.read_byte(z.next_in_index++)) & 0xff; | ||
if ((((istate.method << 8) + b) % 31) !== 0) { | ||
istate.mode = BAD; | ||
z.msg = "incorrect header check"; | ||
istate.marker = 5; // can't try inflateSync | ||
break; | ||
} | ||
if ((((istate.method << 8) + b) % 31) !== 0) { | ||
istate.mode = BAD; | ||
z.msg = "incorrect header check"; | ||
istate.marker = 5; // can't try inflateSync | ||
break; | ||
} | ||
if ((b & PRESET_DICT) === 0) { | ||
istate.mode = BLOCKS; | ||
break; | ||
} | ||
istate.mode = DICT4; | ||
/* falls through */ | ||
case DICT4: | ||
if ((b & PRESET_DICT) === 0) { | ||
istate.mode = BLOCKS; | ||
break; | ||
} | ||
istate.mode = DICT4; | ||
/* falls through */ | ||
case DICT4: | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
z.avail_in--; | ||
z.total_in++; | ||
istate.need = ((z.read_byte(z.next_in_index++) & 0xff) << 24) & 0xff000000; | ||
istate.mode = DICT3; | ||
/* falls through */ | ||
case DICT3: | ||
z.avail_in--; | ||
z.total_in++; | ||
istate.need = ((z.read_byte(z.next_in_index++) & 0xff) << 24) & 0xff000000; | ||
istate.mode = DICT3; | ||
/* falls through */ | ||
case DICT3: | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
z.avail_in--; | ||
z.total_in++; | ||
istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 16) & 0xff0000; | ||
istate.mode = DICT2; | ||
/* falls through */ | ||
case DICT2: | ||
z.avail_in--; | ||
z.total_in++; | ||
istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 16) & 0xff0000; | ||
istate.mode = DICT2; | ||
/* falls through */ | ||
case DICT2: | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
z.avail_in--; | ||
z.total_in++; | ||
istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 8) & 0xff00; | ||
istate.mode = DICT1; | ||
/* falls through */ | ||
case DICT1: | ||
z.avail_in--; | ||
z.total_in++; | ||
istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 8) & 0xff00; | ||
istate.mode = DICT1; | ||
/* falls through */ | ||
case DICT1: | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
if (z.avail_in === 0) | ||
return r; | ||
r = f; | ||
z.avail_in--; | ||
z.total_in++; | ||
istate.need += (z.read_byte(z.next_in_index++) & 0xff); | ||
istate.mode = DICT0; | ||
return Z_NEED_DICT; | ||
case DICT0: | ||
z.avail_in--; | ||
z.total_in++; | ||
istate.need += (z.read_byte(z.next_in_index++) & 0xff); | ||
istate.mode = DICT0; | ||
return Z_NEED_DICT; | ||
case DICT0: | ||
istate.mode = BAD; | ||
z.msg = "need dictionary"; | ||
istate.marker = 0; // can try inflateSync | ||
return Z_STREAM_ERROR; | ||
case BLOCKS: | ||
r = istate.blocks.proc(z, r); | ||
if (r == Z_DATA_ERROR) { | ||
istate.mode = BAD; | ||
z.msg = "need dictionary"; | ||
istate.marker = 0; // can try inflateSync | ||
return Z_STREAM_ERROR; | ||
case BLOCKS: | ||
r = istate.blocks.proc(z, r); | ||
if (r == Z_DATA_ERROR) { | ||
istate.mode = BAD; | ||
istate.marker = 0; // can try inflateSync | ||
break; | ||
} | ||
if (r == Z_OK) { | ||
r = f; | ||
} | ||
if (r != Z_STREAM_END) { | ||
return r; | ||
} | ||
break; | ||
} | ||
if (r == Z_OK) { | ||
r = f; | ||
istate.blocks.reset(z, istate.was); | ||
istate.mode = DONE; | ||
/* falls through */ | ||
case DONE: | ||
return Z_STREAM_END; | ||
case BAD: | ||
return Z_DATA_ERROR; | ||
default: | ||
return Z_STREAM_ERROR; | ||
} | ||
} | ||
if (r != Z_STREAM_END) { | ||
return r; | ||
} | ||
r = f; | ||
istate.blocks.reset(z, istate.was); | ||
istate.mode = DONE; | ||
/* falls through */ | ||
case DONE: | ||
return Z_STREAM_END; | ||
case BAD: | ||
return Z_DATA_ERROR; | ||
default: | ||
return Z_STREAM_ERROR; | ||
} | ||
}; | ||
} | ||
}; | ||
that.inflateSetDictionary = function (z, dictionary, dictLength) { | ||
let index = 0, length = dictLength; | ||
if (!z || !z.istate || z.istate.mode != DICT0) | ||
return Z_STREAM_ERROR; | ||
const istate = z.istate; | ||
if (length >= (1 << istate.wbits)) { | ||
length = (1 << istate.wbits) - 1; | ||
index = dictLength - length; | ||
} | ||
istate.blocks.set_dictionary(dictionary, index, length); | ||
istate.mode = BLOCKS; | ||
return Z_OK; | ||
}; | ||
that.inflateSetDictionary = function (z, dictionary, dictLength) { | ||
let index = 0, length = dictLength; | ||
if (!z || !z.istate || z.istate.mode != DICT0) | ||
return Z_STREAM_ERROR; | ||
const istate = z.istate; | ||
if (length >= (1 << istate.wbits)) { | ||
length = (1 << istate.wbits) - 1; | ||
index = dictLength - length; | ||
} | ||
istate.blocks.set_dictionary(dictionary, index, length); | ||
istate.mode = BLOCKS; | ||
return Z_OK; | ||
}; | ||
that.inflateSync = function (z) { | ||
let n; // number of bytes to look at | ||
let p; // pointer to bytes | ||
let m; // number of marker bytes found in a row | ||
let r, w; // temporaries to save total_in and total_out | ||
that.inflateSync = function (z) { | ||
let n; // number of bytes to look at | ||
let p; // pointer to bytes | ||
let m; // number of marker bytes found in a row | ||
let r, w; // temporaries to save total_in and total_out | ||
// set up | ||
if (!z || !z.istate) | ||
return Z_STREAM_ERROR; | ||
const istate = z.istate; | ||
if (istate.mode != BAD) { | ||
istate.mode = BAD; | ||
istate.marker = 0; | ||
} | ||
if ((n = z.avail_in) === 0) | ||
return Z_BUF_ERROR; | ||
p = z.next_in_index; | ||
m = istate.marker; | ||
// set up | ||
if (!z || !z.istate) | ||
return Z_STREAM_ERROR; | ||
const istate = z.istate; | ||
if (istate.mode != BAD) { | ||
istate.mode = BAD; | ||
istate.marker = 0; | ||
} | ||
if ((n = z.avail_in) === 0) | ||
return Z_BUF_ERROR; | ||
p = z.next_in_index; | ||
m = istate.marker; | ||
// search | ||
while (n !== 0 && m < 4) { | ||
if (z.read_byte(p) == mark[m]) { | ||
m++; | ||
} else if (z.read_byte(p) !== 0) { | ||
m = 0; | ||
} else { | ||
m = 4 - m; | ||
} | ||
p++; | ||
n--; | ||
// search | ||
while (n !== 0 && m < 4) { | ||
if (z.read_byte(p) == mark[m]) { | ||
m++; | ||
} else if (z.read_byte(p) !== 0) { | ||
m = 0; | ||
} else { | ||
m = 4 - m; | ||
} | ||
p++; | ||
n--; | ||
} | ||
// restore | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
z.avail_in = n; | ||
istate.marker = m; | ||
// restore | ||
z.total_in += p - z.next_in_index; | ||
z.next_in_index = p; | ||
z.avail_in = n; | ||
istate.marker = m; | ||
// return no joy or set up to restart on a new block | ||
if (m != 4) { | ||
return Z_DATA_ERROR; | ||
} | ||
r = z.total_in; | ||
w = z.total_out; | ||
inflateReset(z); | ||
z.total_in = r; | ||
z.total_out = w; | ||
istate.mode = BLOCKS; | ||
return Z_OK; | ||
}; | ||
// return no joy or set up to restart on a new block | ||
if (m != 4) { | ||
return Z_DATA_ERROR; | ||
} | ||
r = z.total_in; | ||
w = z.total_out; | ||
inflateReset(z); | ||
z.total_in = r; | ||
z.total_out = w; | ||
istate.mode = BLOCKS; | ||
return Z_OK; | ||
}; | ||
// Returns true if inflate is currently at the end of a block generated | ||
// by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP | ||
// implementation to provide an additional safety check. PPP uses | ||
// Z_SYNC_FLUSH | ||
// but removes the length bytes of the resulting empty stored block. When | ||
// decompressing, PPP checks that at the end of input packet, inflate is | ||
// waiting for these length bytes. | ||
that.inflateSyncPoint = function (z) { | ||
if (!z || !z.istate || !z.istate.blocks) | ||
return Z_STREAM_ERROR; | ||
return z.istate.blocks.sync_point(); | ||
}; | ||
} | ||
// Returns true if inflate is currently at the end of a block generated | ||
// by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP | ||
// implementation to provide an additional safety check. PPP uses | ||
// Z_SYNC_FLUSH | ||
// but removes the length bytes of the resulting empty stored block. When | ||
// decompressing, PPP checks that at the end of input packet, inflate is | ||
// waiting for these length bytes. | ||
that.inflateSyncPoint = function (z) { | ||
if (!z || !z.istate || !z.istate.blocks) | ||
return Z_STREAM_ERROR; | ||
return z.istate.blocks.sync_point(); | ||
}; | ||
} | ||
// ZStream | ||
// ZStream | ||
function ZStream() { | ||
} | ||
function ZStream() { | ||
} | ||
ZStream.prototype = { | ||
inflateInit: function (bits) { | ||
const that = this; | ||
that.istate = new Inflate(); | ||
if (!bits) | ||
bits = MAX_BITS; | ||
return that.istate.inflateInit(that, bits); | ||
}, | ||
ZStream.prototype = { | ||
inflateInit: function (bits) { | ||
const that = this; | ||
that.istate = new Inflate(); | ||
if (!bits) | ||
bits = MAX_BITS; | ||
return that.istate.inflateInit(that, bits); | ||
}, | ||
inflate: function (f) { | ||
const that = this; | ||
if (!that.istate) | ||
return Z_STREAM_ERROR; | ||
return that.istate.inflate(that, f); | ||
}, | ||
inflate: function (f) { | ||
const that = this; | ||
if (!that.istate) | ||
return Z_STREAM_ERROR; | ||
return that.istate.inflate(that, f); | ||
}, | ||
inflateEnd: function () { | ||
const that = this; | ||
if (!that.istate) | ||
return Z_STREAM_ERROR; | ||
const ret = that.istate.inflateEnd(that); | ||
that.istate = null; | ||
return ret; | ||
}, | ||
inflateEnd: function () { | ||
const that = this; | ||
if (!that.istate) | ||
return Z_STREAM_ERROR; | ||
const ret = that.istate.inflateEnd(that); | ||
that.istate = null; | ||
return ret; | ||
}, | ||
inflateSync: function () { | ||
const that = this; | ||
if (!that.istate) | ||
return Z_STREAM_ERROR; | ||
return that.istate.inflateSync(that); | ||
}, | ||
inflateSetDictionary: function (dictionary, dictLength) { | ||
const that = this; | ||
if (!that.istate) | ||
return Z_STREAM_ERROR; | ||
return that.istate.inflateSetDictionary(that, dictionary, dictLength); | ||
}, | ||
read_byte: function (start) { | ||
const that = this; | ||
return that.next_in.subarray(start, start + 1)[0]; | ||
}, | ||
read_buf: function (start, size) { | ||
const that = this; | ||
return that.next_in.subarray(start, start + size); | ||
} | ||
}; | ||
inflateSync: function () { | ||
const that = this; | ||
if (!that.istate) | ||
return Z_STREAM_ERROR; | ||
return that.istate.inflateSync(that); | ||
}, | ||
inflateSetDictionary: function (dictionary, dictLength) { | ||
const that = this; | ||
if (!that.istate) | ||
return Z_STREAM_ERROR; | ||
return that.istate.inflateSetDictionary(that, dictionary, dictLength); | ||
}, | ||
read_byte: function (start) { | ||
const that = this; | ||
return that.next_in.subarray(start, start + 1)[0]; | ||
}, | ||
read_buf: function (start, size) { | ||
const that = this; | ||
return that.next_in.subarray(start, start + size); | ||
} | ||
}; | ||
// Inflater | ||
// Inflater | ||
function ZipInflate() { | ||
const that = this; | ||
const z = new ZStream(); | ||
const bufsize = 512; | ||
const flush = Z_NO_FLUSH; | ||
const buf = new Uint8Array(bufsize); | ||
let nomoreinput = false; | ||
function ZipInflate() { | ||
const that = this; | ||
const z = new ZStream(); | ||
const bufsize = 512; | ||
const flush = Z_NO_FLUSH; | ||
const buf = new Uint8Array(bufsize); | ||
let nomoreinput = false; | ||
z.inflateInit(); | ||
z.next_out = buf; | ||
z.inflateInit(); | ||
z.next_out = buf; | ||
that.append = function (data, onprogress) { | ||
const buffers = []; | ||
let err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0; | ||
if (data.length === 0) | ||
return; | ||
z.next_in_index = 0; | ||
z.next_in = data; | ||
z.avail_in = data.length; | ||
do { | ||
z.next_out_index = 0; | ||
z.avail_out = bufsize; | ||
if ((z.avail_in === 0) && (!nomoreinput)) { // if buffer is empty and more input is available, refill it | ||
z.next_in_index = 0; | ||
nomoreinput = true; | ||
} | ||
err = z.inflate(flush); | ||
if (nomoreinput && (err === Z_BUF_ERROR)) { | ||
if (z.avail_in !== 0) | ||
throw new Error("inflating: bad input"); | ||
} else if (err !== Z_OK && err !== Z_STREAM_END) | ||
throw new Error("inflating: " + z.msg); | ||
if ((nomoreinput || err === Z_STREAM_END) && (z.avail_in === data.length)) | ||
that.append = function (data, onprogress) { | ||
const buffers = []; | ||
let err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0; | ||
if (data.length === 0) | ||
return; | ||
z.next_in_index = 0; | ||
z.next_in = data; | ||
z.avail_in = data.length; | ||
do { | ||
z.next_out_index = 0; | ||
z.avail_out = bufsize; | ||
if ((z.avail_in === 0) && (!nomoreinput)) { // if buffer is empty and more input is available, refill it | ||
z.next_in_index = 0; | ||
nomoreinput = true; | ||
} | ||
err = z.inflate(flush); | ||
if (nomoreinput && (err === Z_BUF_ERROR)) { | ||
if (z.avail_in !== 0) | ||
throw new Error("inflating: bad input"); | ||
if (z.next_out_index) | ||
if (z.next_out_index === bufsize) | ||
buffers.push(new Uint8Array(buf)); | ||
else | ||
buffers.push(new Uint8Array(buf.subarray(0, z.next_out_index))); | ||
bufferSize += z.next_out_index; | ||
if (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) { | ||
onprogress(z.next_in_index); | ||
lastIndex = z.next_in_index; | ||
} | ||
} while (z.avail_in > 0 || z.avail_out === 0); | ||
array = new Uint8Array(bufferSize); | ||
buffers.forEach(function (chunk) { | ||
array.set(chunk, bufferIndex); | ||
bufferIndex += chunk.length; | ||
}); | ||
return array; | ||
}; | ||
that.flush = function () { | ||
z.inflateEnd(); | ||
}; | ||
} | ||
} else if (err !== Z_OK && err !== Z_STREAM_END) | ||
throw new Error("inflating: " + z.msg); | ||
if ((nomoreinput || err === Z_STREAM_END) && (z.avail_in === data.length)) | ||
throw new Error("inflating: bad input"); | ||
if (z.next_out_index) | ||
if (z.next_out_index === bufsize) | ||
buffers.push(new Uint8Array(buf)); | ||
else | ||
buffers.push(new Uint8Array(buf.subarray(0, z.next_out_index))); | ||
bufferSize += z.next_out_index; | ||
if (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) { | ||
onprogress(z.next_in_index); | ||
lastIndex = z.next_in_index; | ||
} | ||
} while (z.avail_in > 0 || z.avail_out === 0); | ||
array = new Uint8Array(bufferSize); | ||
buffers.forEach(function (chunk) { | ||
array.set(chunk, bufferIndex); | ||
bufferIndex += chunk.length; | ||
}); | ||
return array; | ||
}; | ||
that.flush = function () { | ||
z.inflateEnd(); | ||
}; | ||
} | ||
globalThis.ZipInflate = ZipInflate; | ||
})(this); | ||
export default ZipInflate; |
@@ -37,8 +37,8 @@ /* | ||
const LOCAL_FILE_HEADER_SIGNATURE = 0x504b0304; | ||
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x504b0708; | ||
const CENTRAL_FILE_HEADER_SIGNATURE = 0x504b0102; | ||
const END_OF_CENTRAL_DIR_SIGNATURE = 0x504b0506; | ||
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x504b0606; | ||
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x504b0607; | ||
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50; | ||
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50; | ||
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50; | ||
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50; | ||
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50; | ||
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50; | ||
const END_OF_CENTRAL_DIR_LENGTH = 22; | ||
@@ -45,0 +45,0 @@ const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20; |
@@ -36,4 +36,4 @@ | ||
return { | ||
ZipDeflate: createCodecClass(library.Deflate, options.deflate), | ||
ZipInflate: createCodecClass(library.Inflate, options.inflate) | ||
Deflate: createCodecClass(library.Deflate, options.deflate), | ||
Inflate: createCodecClass(library.Inflate, options.inflate) | ||
}; | ||
@@ -40,0 +40,0 @@ }; |
@@ -42,4 +42,4 @@ /* | ||
const DEFAULT_WORKER_SCRIPTS = { | ||
deflate: [Z_WORKER_SCRIPT_PATH, "deflate.js"], | ||
inflate: [Z_WORKER_SCRIPT_PATH, "inflate.js"] | ||
deflate: [Z_WORKER_SCRIPT_PATH], | ||
inflate: [Z_WORKER_SCRIPT_PATH] | ||
}; | ||
@@ -134,4 +134,20 @@ const workers = { | ||
if (!task) { | ||
const options = workerData.options; | ||
const scripts = workerData.scripts.slice(1); | ||
await sendMessage(Object.assign({ type: MESSAGE_INIT, options: workerData.options, scripts })); | ||
await sendMessage(Object.assign({ | ||
scripts, | ||
type: MESSAGE_INIT, options: { | ||
codecType: options.codecType, | ||
inputPassword: options.inputPassword, | ||
inputSigned: options.inputSigned, | ||
inputSignature: options.signature, | ||
inputCompressed: options.inputCompressed, | ||
inputEncrypted: options.inputEncrypted, | ||
level: options.level, | ||
outputPassword: options.outputPassword, | ||
outputSigned: options.outputSigned, | ||
outputCompressed: options.outputCompressed, | ||
outputEncrypted: options.outputEncrypted | ||
} | ||
})); | ||
} | ||
@@ -138,0 +154,0 @@ return sendMessage(message); |
@@ -32,9 +32,9 @@ | ||
import "./z-worker-core.js"; | ||
import { default as initShimAsyncCodec } from "./util/stream-codec-shim.js"; | ||
import "./z-worker.js"; | ||
self.initExternalCodec = () => { | ||
const { ZipDeflate, ZipInflate } = initShimAsyncCodec(pako, { deflate: { raw: true }, inflate: { raw: true } }); | ||
self.ZipDeflate = ZipDeflate; | ||
self.ZipInflate = ZipInflate; | ||
self.initCodec = () => { | ||
const { Deflate, Inflate } = initShimAsyncCodec(pako, { deflate: { raw: true }, inflate: { raw: true } }); | ||
self.Deflate = Deflate; | ||
self.Inflate = Inflate; | ||
}; |
@@ -29,49 +29,11 @@ /* | ||
/* global self, importScripts, addEventListener, postMessage */ | ||
/* global self */ | ||
import { createCodec } from "./codec.js"; | ||
import "./z-worker-core.js"; | ||
import Deflate from "./codecs/deflate.js"; | ||
import Inflate from "./codecs/inflate.js"; | ||
"use strict"; | ||
const handlers = { | ||
init(message) { | ||
if (message.scripts && message.scripts.length) { | ||
importScripts.apply(undefined, message.scripts); | ||
} | ||
const options = message.options; | ||
if (self.initExternalCodec) { | ||
self.initExternalCodec(); | ||
} | ||
codec = createCodec(options); | ||
}, | ||
async append(message) { | ||
return { data: await codec.append(message.data) }; | ||
}, | ||
flush() { | ||
return codec.flush(); | ||
} | ||
}; | ||
let codec; | ||
addEventListener("message", async event => { | ||
const message = event.data; | ||
const type = message.type; | ||
const handler = handlers[type]; | ||
if (handler) { | ||
try { | ||
const response = (await handler(message)) || {}; | ||
response.type = type; | ||
if (response.data) { | ||
try { | ||
postMessage(response, [response.data.buffer]); | ||
} catch (error) { | ||
postMessage(response); | ||
} | ||
} else { | ||
postMessage(response); | ||
} | ||
} catch (error) { | ||
postMessage({ type, error: { message: error.message, stack: error.stack } }); | ||
} | ||
} | ||
}); | ||
self.initCodec = () => { | ||
self.Deflate = Deflate; | ||
self.Inflate = Inflate; | ||
}; |
@@ -100,4 +100,4 @@ /* | ||
let zip64; | ||
let directoryDataOffset = endOfDirectoryView.getUint32(16, true); | ||
let filesLength = endOfDirectoryView.getUint16(8, true); | ||
let directoryDataOffset = getUint32(endOfDirectoryView, 16); | ||
let filesLength = getUint16(endOfDirectoryView, 8); | ||
if (directoryDataOffset == MAX_32_BITS || filesLength == MAX_16_BITS) { | ||
@@ -107,13 +107,13 @@ zip64 = true; | ||
const endOfDirectoryLocatorView = new DataView(endOfDirectoryLocatorArray.buffer); | ||
if (Number(endOfDirectoryLocatorView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) { | ||
if (Number(getUint32(endOfDirectoryLocatorView, 0)) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) { | ||
throw new Error(ERR_EOCDR_ZIP64_NOT_FOUND); | ||
} | ||
directoryDataOffset = Number(endOfDirectoryLocatorView.getBigUint64(8, true)); | ||
directoryDataOffset = Number(getBigUint64(endOfDirectoryLocatorView, 8)); | ||
const endOfDirectoryArray = await reader.readUint8Array(directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH); | ||
const endOfDirectoryView = new DataView(endOfDirectoryArray.buffer); | ||
if (Number(endOfDirectoryView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) { | ||
if (Number(getUint32(endOfDirectoryView, 0)) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) { | ||
throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND); | ||
} | ||
filesLength = Number(endOfDirectoryView.getBigUint64(24, true)); | ||
directoryDataOffset -= Number(endOfDirectoryView.getBigUint64(40, true)); | ||
filesLength = Number(getBigUint64(endOfDirectoryView, 24)); | ||
directoryDataOffset -= Number(getBigUint64(endOfDirectoryView, 40)); | ||
} | ||
@@ -129,3 +129,3 @@ if (directoryDataOffset < 0 || (!zip64 && (directoryDataOffset >= reader.size || filesLength >= MAX_16_BITS))) { | ||
const fileEntry = new Entry(this.reader, this.config, this.options); | ||
if (directoryView.getUint32(offset, false) != CENTRAL_FILE_HEADER_SIGNATURE) { | ||
if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) { | ||
throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND); | ||
@@ -136,5 +136,5 @@ } | ||
readCommonHeader(fileEntry, directoryView, offset + 6); | ||
fileEntry.commentLength = directoryView.getUint16(offset + 32, true); | ||
fileEntry.directory = ((directoryView.getUint8(offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK); | ||
fileEntry.offset = directoryView.getUint32(offset + 42, true); | ||
fileEntry.commentLength = getUint16(directoryView, offset + 32); | ||
fileEntry.directory = (getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK; | ||
fileEntry.offset = getUint32(directoryView, offset + 42); | ||
fileEntry.rawFilename = directoryArray.subarray(offset + 46, offset + 46 + fileEntry.filenameLength); | ||
@@ -206,3 +206,3 @@ const filenameEncoding = options.filenameEncoding === undefined ? this.options.filenameEncoding : options.filenameEncoding; | ||
} | ||
if (dataView.getUint32(0, false) != LOCAL_FILE_HEADER_SIGNATURE) { | ||
if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) { | ||
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND); | ||
@@ -221,2 +221,3 @@ } | ||
codecType: CODEC_INFLATE, | ||
codecConstructor: this.config.Inflate, | ||
inputPassword, | ||
@@ -238,4 +239,4 @@ inputSigned: options.checkSignature === undefined ? this.options.checkSignature : options.checkSignature, | ||
function readCommonHeader(directory, dataView, offset) { | ||
directory.version = dataView.getUint16(offset, true); | ||
const rawBitFlag = directory.rawBitFlag = dataView.getUint16(offset + 2, true); | ||
directory.version = getUint16(dataView, offset); | ||
const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2); | ||
directory.bitFlag = { | ||
@@ -248,6 +249,6 @@ encrypted: (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED, | ||
directory.encrypted = directory.bitFlag.encrypted; | ||
directory.rawLastModDate = dataView.getUint32(offset + 6, true); | ||
directory.rawLastModDate = getUint32(dataView, offset + 6); | ||
directory.lastModDate = getDate(directory.rawLastModDate); | ||
directory.filenameLength = dataView.getUint16(offset + 22, true); | ||
directory.extraFieldLength = dataView.getUint16(offset + 24, true); | ||
directory.filenameLength = getUint16(dataView, offset + 22); | ||
directory.extraFieldLength = getUint16(dataView, offset + 24); | ||
} | ||
@@ -262,4 +263,4 @@ | ||
while (offsetExtraField < rawExtraField.length) { | ||
const type = rawExtraFieldView.getUint16(offsetExtraField, true); | ||
const size = rawExtraFieldView.getUint16(offsetExtraField + 2, true); | ||
const type = getUint16(rawExtraFieldView, offsetExtraField); | ||
const size = getUint16(rawExtraFieldView, offsetExtraField + 2); | ||
extraField.set(type, { | ||
@@ -274,6 +275,6 @@ type, | ||
} | ||
const compressionMethod = dataView.getUint16(offset + 4, true); | ||
directory.signature = dataView.getUint32(offset + 10, true); | ||
directory.uncompressedSize = dataView.getUint32(offset + 18, true); | ||
directory.compressedSize = dataView.getUint32(offset + 14, true); | ||
const compressionMethod = getUint16(dataView, offset + 4); | ||
directory.signature = getUint32(dataView, offset + 10); | ||
directory.uncompressedSize = getUint32(dataView, offset + 18); | ||
directory.compressedSize = getUint32(dataView, offset + 14); | ||
const extraFieldZip64 = directory.extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64); | ||
@@ -307,3 +308,3 @@ if (extraFieldZip64) { | ||
for (let indexValue = 0; indexValue < Math.floor(extraFieldZip64.data.length / 8); indexValue++) { | ||
extraFieldZip64.values.push(Number(extraFieldView.getBigUint64(0 + indexValue * 8, true))); | ||
extraFieldZip64.values.push(Number(getBigUint64(extraFieldView, 0 + indexValue * 8))); | ||
} | ||
@@ -327,4 +328,4 @@ const missingProperties = ZIP64_PROPERTIES.filter(propertyName => directory[propertyName] == MAX_32_BITS); | ||
const extraFieldView = new DataView(extraFieldUnicode.data.buffer); | ||
extraFieldUnicode.version = extraFieldView.getUint8(0); | ||
extraFieldUnicode.signature = extraFieldView.getUint32(1, true); | ||
extraFieldUnicode.version = getUint8(extraFieldView, 0); | ||
extraFieldUnicode.signature = getUint32(extraFieldView, 1); | ||
const crc32 = new Crc32(); | ||
@@ -335,3 +336,3 @@ crc32.append(fileEntry[rawPropertyName]); | ||
extraFieldUnicode[propertyName] = (new TextDecoder()).decode(extraFieldUnicode.data.subarray(5)); | ||
if (!fileEntry.bitFlag.languageEncodingFlag && extraFieldUnicode.signature == dataViewSignature.getUint32(0, false)) { | ||
if (!fileEntry.bitFlag.languageEncodingFlag && extraFieldUnicode.signature == getUint32(dataViewSignature, 0)) { | ||
directory[propertyName] = extraFieldUnicode[propertyName]; | ||
@@ -344,8 +345,8 @@ } | ||
const extraFieldView = new DataView(extraFieldAES.data.buffer); | ||
extraFieldAES.vendorVersion = extraFieldView.getUint8(0); | ||
extraFieldAES.vendorId = extraFieldView.getUint8(2); | ||
const strength = extraFieldView.getUint8(4); | ||
extraFieldAES.vendorVersion = getUint8(extraFieldView, 0); | ||
extraFieldAES.vendorId = getUint8(extraFieldView, 2); | ||
const strength = getUint8(extraFieldView, 4); | ||
extraFieldAES.strength = strength; | ||
extraFieldAES.originalCompressionMethod = compressionMethod; | ||
directory.compressionMethod = extraFieldAES.compressionMethod = extraFieldView.getUint16(5, true); | ||
directory.compressionMethod = extraFieldAES.compressionMethod = getUint16(extraFieldView, 5); | ||
} else { | ||
@@ -359,3 +360,3 @@ directory.compressionMethod = compressionMethod; | ||
const signatureView = new DataView(signatureArray.buffer); | ||
signatureView.setUint32(0, signature); | ||
setUint32(signatureView, 0, signature); | ||
if (reader.size < minimumBytes) { | ||
@@ -406,2 +407,22 @@ throw new Error(ERR_BAD_FORMAT); | ||
} | ||
} | ||
function getUint8(view, offset) { | ||
return view.getUint8(offset); | ||
} | ||
function getUint16(view, offset) { | ||
return view.getUint16(offset, true); | ||
} | ||
function getUint32(view, offset) { | ||
return view.getUint32(offset, true); | ||
} | ||
function getBigUint64(view, offset) { | ||
return view.getBigUint64(offset, true); | ||
} | ||
function setUint32(view, offset, value) { | ||
view.setUint32(offset, value, true); | ||
} |
@@ -83,3 +83,2 @@ /* | ||
this.offset = writer.size; | ||
this.zip64 = options.zip64; | ||
} | ||
@@ -133,7 +132,7 @@ | ||
} | ||
let zip64 = options.zip64 || this.zip64; | ||
if (this.offset >= MAX_32_BITS || (reader && (reader.size >= MAX_32_BITS || this.offset + reader.size >= MAX_32_BITS))) { | ||
zip64 = true; | ||
} | ||
await addFile(this, name, reader, Object.assign({}, options, { rawFilename, rawComment, version, lastModDate, rawExtraField, zip64 })); | ||
const zip64 = options.zip64 || this.options.zip64 || this.offset >= MAX_32_BITS || (reader && (reader.size >= MAX_32_BITS || this.offset + reader.size >= MAX_32_BITS)); | ||
const password = options.password === undefined ? this.options.password : options.password; | ||
const level = options.level === undefined ? this.options.level : options.level; | ||
const useWebWorkers = options.useWebWorkers === undefined ? this.options.useWebWorkers : options.useWebWorkers; | ||
await addFile(this, name, reader, Object.assign({}, options, { rawFilename, rawComment, version, lastModDate, rawExtraField, zip64, password, level, useWebWorkers })); | ||
} | ||
@@ -147,3 +146,3 @@ | ||
if (comment.length <= MAX_16_BITS) { | ||
directoryView.setUint16(offset + 20, comment.length, true); | ||
setUint16(directoryView, offset + 20, comment.length); | ||
} else { | ||
@@ -156,6 +155,4 @@ throw new Error(ERR_INVALID_COMMENT); | ||
} | ||
if (directoryOffset + directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) { | ||
this.zip64 = true; | ||
} | ||
const directoryArray = new Uint8Array(directoryDataLength + (this.zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH)); | ||
const zip64 = this.options.zip64 || directoryOffset + directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS; | ||
const directoryArray = new Uint8Array(directoryDataLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH)); | ||
const directoryView = new DataView(directoryArray.buffer); | ||
@@ -167,14 +164,14 @@ for (const [, fileEntry] of files) { | ||
const extraFieldLength = extraFieldZip64.length + extraFieldAES.length + fileEntry.rawExtraField.length; | ||
directoryView.setUint32(offset, CENTRAL_FILE_HEADER_SIGNATURE); | ||
directoryView.setUint16(offset + 4, fileEntry.version, true); | ||
setUint32(directoryView, offset, CENTRAL_FILE_HEADER_SIGNATURE); | ||
setUint16(directoryView, offset + 4, fileEntry.version); | ||
directoryArray.set(fileEntry.headerArray, offset + 6); | ||
directoryView.setUint16(offset + 30, extraFieldLength, true); | ||
directoryView.setUint16(offset + 32, fileEntry.rawComment.length, true); | ||
setUint16(directoryView, offset + 30, extraFieldLength); | ||
setUint16(directoryView, offset + 32, fileEntry.rawComment.length); | ||
if (fileEntry.directory) { | ||
directoryView.setUint8(offset + 38, FILE_ATTR_MSDOS_DIR_MASK); | ||
setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK); | ||
} | ||
if (fileEntry.zip64) { | ||
directoryView.setUint32(offset + 42, MAX_32_BITS, true); | ||
setUint32(directoryView, offset + 42, MAX_32_BITS); | ||
} else { | ||
directoryView.setUint32(offset + 42, fileEntry.offset, true); | ||
setUint32(directoryView, offset + 42, fileEntry.offset); | ||
} | ||
@@ -188,14 +185,14 @@ directoryArray.set(rawFilename, offset + 46); | ||
} | ||
if (this.zip64) { | ||
directoryView.setUint32(offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE); | ||
directoryView.setBigUint64(offset + 4, BigInt(44), true); | ||
directoryView.setUint16(offset + 12, 45, true); | ||
directoryView.setUint16(offset + 14, 45, true); | ||
directoryView.setBigUint64(offset + 24, BigInt(filesLength), true); | ||
directoryView.setBigUint64(offset + 32, BigInt(filesLength), true); | ||
directoryView.setBigUint64(offset + 40, BigInt(directoryDataLength), true); | ||
directoryView.setBigUint64(offset + 48, BigInt(directoryOffset), true); | ||
directoryView.setUint32(offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE); | ||
directoryView.setBigUint64(offset + 64, BigInt(directoryOffset + directoryDataLength), true); | ||
directoryView.setUint32(offset + 72, ZIP64_TOTAL_NUMBER_OF_DISKS, true); | ||
if (zip64) { | ||
setUint32(directoryView, offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE); | ||
setBigUint64(directoryView, offset + 4, BigInt(44)); | ||
setUint16(directoryView, offset + 12, 45); | ||
setUint16(directoryView, offset + 14, 45); | ||
setBigUint64(directoryView, offset + 24, BigInt(filesLength)); | ||
setBigUint64(directoryView, offset + 32, BigInt(filesLength)); | ||
setBigUint64(directoryView, offset + 40, BigInt(directoryDataLength)); | ||
setBigUint64(directoryView, offset + 48, BigInt(directoryOffset)); | ||
setUint32(directoryView, offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE); | ||
setBigUint64(directoryView, offset + 64, BigInt(directoryOffset + directoryDataLength)); | ||
setUint32(directoryView, offset + 72, ZIP64_TOTAL_NUMBER_OF_DISKS); | ||
filesLength = MAX_16_BITS; | ||
@@ -205,7 +202,7 @@ directoryOffset = MAX_32_BITS; | ||
} | ||
directoryView.setUint32(offset, END_OF_CENTRAL_DIR_SIGNATURE); | ||
directoryView.setUint16(offset + 8, filesLength, true); | ||
directoryView.setUint16(offset + 10, filesLength, true); | ||
directoryView.setUint32(offset + 12, directoryDataLength, true); | ||
directoryView.setUint32(offset + 16, directoryOffset, true); | ||
setUint32(directoryView, offset, END_OF_CENTRAL_DIR_SIGNATURE); | ||
setUint16(directoryView, offset + 8, filesLength); | ||
setUint16(directoryView, offset + 10, filesLength); | ||
setUint32(directoryView, offset + 12, directoryDataLength); | ||
setUint32(directoryView, offset + 16, directoryOffset); | ||
await writer.writeUint8Array(directoryArray); | ||
@@ -246,4 +243,3 @@ await writer.writeUint8Array(comment); | ||
} | ||
fileEntry = await createFileEntry(name, reader, fileWriter, zipWriter.config, zipWriter.options, options); | ||
fileEntry = await createFileEntry(reader, fileWriter, zipWriter.config, options); | ||
} catch (error) { | ||
@@ -263,3 +259,3 @@ files.delete(name); | ||
const extraFieldZip64View = new DataView(fileEntry.extraFieldZip64.buffer); | ||
extraFieldZip64View.setBigUint64(20, BigInt(fileEntry.offset), true); | ||
setBigUint64(extraFieldZip64View, 20, BigInt(fileEntry.offset)); | ||
} | ||
@@ -275,18 +271,15 @@ zipWriter.offset += fileEntry.length; | ||
async function createFileEntry(filename, reader, writer, config, zipWriterOptions, options) { | ||
async function createFileEntry(reader, writer, config, options) { | ||
const rawFilename = options.rawFilename; | ||
const date = options.lastModDate; | ||
const headerArray = new Uint8Array(26); | ||
const headerView = new DataView(headerArray.buffer); | ||
const password = options.password === undefined ? zipWriterOptions.password : options.password; | ||
const outputPassword = password && password.length && password; | ||
const level = options.level === undefined ? zipWriterOptions.level : options.level; | ||
const compressed = level !== 0 && !options.directory; | ||
const outputSigned = password === undefined || !password.length; | ||
const lastModDate = options.lastModDate; | ||
const outputPassword = options.password; | ||
const outputEncrypted = outputPassword && outputPassword.length; | ||
const level = options.level; | ||
const outputCompressed = level !== 0 && !options.directory; | ||
const zip64 = options.zip64; | ||
let extraFieldAES; | ||
if (outputPassword) { | ||
if (outputEncrypted) { | ||
extraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2); | ||
const extraFieldAESView = new DataView(extraFieldAES.buffer); | ||
extraFieldAESView.setUint16(0, EXTRAFIELD_TYPE_AES, true); | ||
setUint16(extraFieldAESView, 0, EXTRAFIELD_TYPE_AES); | ||
extraFieldAES.set(EXTRAFIELD_DATA_AES, 2); | ||
@@ -299,7 +292,4 @@ } else { | ||
zip64, | ||
headerArray: headerArray, | ||
directory: options.directory, | ||
filename, | ||
rawFilename, | ||
comment: options.comment, | ||
rawComment: options.rawComment, | ||
@@ -312,3 +302,3 @@ extraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(0), | ||
let compressionMethod = COMPRESSION_METHOD_STORE; | ||
if (compressed) { | ||
if (outputCompressed) { | ||
compressionMethod = COMPRESSION_METHOD_DEFLATE; | ||
@@ -319,37 +309,40 @@ } | ||
} | ||
if (outputPassword) { | ||
fileEntry.encrypted = true; | ||
if (outputEncrypted) { | ||
fileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES; | ||
bitFlag = bitFlag | BITFLAG_ENCRYPTED; | ||
compressionMethod = COMPRESSION_METHOD_AES; | ||
if (compressed) { | ||
if (outputCompressed) { | ||
fileEntry.extraFieldAES[9] = COMPRESSION_METHOD_DEFLATE; | ||
} | ||
} | ||
headerView.setUint16(0, fileEntry.version, true); | ||
headerView.setUint16(2, bitFlag, true); | ||
headerView.setUint16(4, compressionMethod, true); | ||
headerView.setUint16(6, (((date.getHours() << 6) | date.getMinutes()) << 5) | date.getSeconds() / 2, true); | ||
headerView.setUint16(8, ((((date.getFullYear() - 1980) << 4) | (date.getMonth() + 1)) << 5) | date.getDate(), true); | ||
headerView.setUint16(22, rawFilename.length, true); | ||
headerView.setUint16(24, 0, true); | ||
const headerArray = fileEntry.headerArray = new Uint8Array(26); | ||
const headerView = new DataView(headerArray.buffer); | ||
setUint16(headerView, 0, fileEntry.version); | ||
setUint16(headerView, 2, bitFlag); | ||
setUint16(headerView, 4, compressionMethod); | ||
setUint16(headerView, 6, (((lastModDate.getHours() << 6) | lastModDate.getMinutes()) << 5) | lastModDate.getSeconds() / 2); | ||
setUint16(headerView, 8, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate()); | ||
setUint16(headerView, 22, rawFilename.length); | ||
setUint16(headerView, 24, 0); | ||
const fileDataArray = new Uint8Array(30 + rawFilename.length); | ||
const fileDataView = new DataView(fileDataArray.buffer); | ||
fileDataView.setUint32(0, LOCAL_FILE_HEADER_SIGNATURE); | ||
setUint32(fileDataView, 0, LOCAL_FILE_HEADER_SIGNATURE); | ||
fileDataArray.set(headerArray, 4); | ||
fileDataArray.set(rawFilename, 30); | ||
let result; | ||
let result, unCompressedSize, compressedSize; | ||
if (reader) { | ||
unCompressedSize = reader.size; | ||
const codec = await createCodec(config, { | ||
codecType: CODEC_DEFLATE, | ||
codecConstructor: config.Deflate, | ||
level, | ||
outputPassword: password, | ||
outputSigned, | ||
outputCompressed: compressed, | ||
outputEncrypted: Boolean(password), | ||
useWebWorkers: options.useWebWorkers === undefined ? zipWriterOptions.useWebWorkers : options.useWebWorkers | ||
outputPassword, | ||
outputSigned: true, | ||
outputCompressed, | ||
outputEncrypted, | ||
useWebWorkers: options.useWebWorkers | ||
}); | ||
await writer.writeUint8Array(fileDataArray); | ||
result = await processData(codec, reader, writer, 0, reader.size, config, { onprogress: options.onprogress }); | ||
fileEntry.compressedSize = result.length; | ||
result = await processData(codec, reader, writer, 0, unCompressedSize, config, { onprogress: options.onprogress }); | ||
compressedSize = result.length; | ||
} else { | ||
@@ -360,23 +353,23 @@ await writer.writeUint8Array(fileDataArray); | ||
const footerView = new DataView(footerArray.buffer); | ||
footerView.setUint32(0, DATA_DESCRIPTOR_RECORD_SIGNATURE); | ||
setUint32(footerView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE); | ||
if (reader) { | ||
if (!outputPassword && result.signature !== undefined) { | ||
headerView.setUint32(10, result.signature, true); | ||
footerView.setUint32(4, result.signature, true); | ||
if (!outputEncrypted && result.signature !== undefined) { | ||
setUint32(headerView, 10, result.signature); | ||
setUint32(footerView, 4, result.signature); | ||
} | ||
if (zip64) { | ||
headerView.setUint32(14, MAX_32_BITS, true); | ||
footerView.setBigUint64(8, BigInt(fileEntry.compressedSize), true); | ||
headerView.setUint32(18, MAX_32_BITS, true); | ||
footerView.setBigUint64(16, BigInt(reader.size), true); | ||
const extraFieldZip64View = new DataView(fileEntry.extraFieldZip64.buffer); | ||
extraFieldZip64View.setUint16(0, EXTRAFIELD_TYPE_ZIP64, true); | ||
extraFieldZip64View.setUint16(2, EXTRAFIELD_LENGTH_ZIP64, true); | ||
extraFieldZip64View.setBigUint64(4, BigInt(reader.size), true); | ||
extraFieldZip64View.setBigUint64(12, BigInt(fileEntry.compressedSize), true); | ||
setUint16(extraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64); | ||
setUint16(extraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64); | ||
setUint32(headerView, 14, MAX_32_BITS); | ||
setBigUint64(footerView, 8, BigInt(compressedSize)); | ||
setBigUint64(extraFieldZip64View, 12, BigInt(compressedSize)); | ||
setUint32(headerView, 18, MAX_32_BITS); | ||
setBigUint64(footerView, 16, BigInt(unCompressedSize)); | ||
setBigUint64(extraFieldZip64View, 4, BigInt(unCompressedSize)); | ||
} else { | ||
headerView.setUint32(14, fileEntry.compressedSize, true); | ||
footerView.setUint32(8, fileEntry.compressedSize, true); | ||
headerView.setUint32(18, reader.size, true); | ||
footerView.setUint32(12, reader.size, true); | ||
setUint32(headerView, 14, compressedSize); | ||
setUint32(footerView, 8, compressedSize); | ||
setUint32(headerView, 18, unCompressedSize); | ||
setUint32(footerView, 12, unCompressedSize); | ||
} | ||
@@ -387,2 +380,18 @@ } | ||
return fileEntry; | ||
} | ||
function setUint8(view, offset, value) { | ||
view.setUint8(offset, value); | ||
} | ||
function setUint16(view, offset, value) { | ||
view.setUint16(offset, value, true); | ||
} | ||
function setUint32(view, offset, value) { | ||
view.setUint32(offset, value, true); | ||
} | ||
function setBigUint64(view, offset, value) { | ||
view.setBigUint64(offset, value, true); | ||
} |
@@ -33,2 +33,5 @@ /* | ||
import Deflate from "./codecs/deflate.js"; | ||
import Inflate from "./codecs/inflate.js"; | ||
import { | ||
@@ -86,3 +89,5 @@ Reader, | ||
workerScriptsPath: undefined, | ||
useWebWorkers: true | ||
useWebWorkers: true, | ||
Deflate, | ||
Inflate | ||
}; | ||
@@ -89,0 +94,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"license": "BSD-3-Clause", | ||
"version": "2.0.11", | ||
"version": "2.0.12", | ||
"keywords": [ | ||
@@ -9,0 +9,0 @@ "zip", |
@@ -17,3 +17,3 @@ /* eslint-disable no-console */ | ||
deflate: ["../../dist/z-worker-pako.js", "../vendor/pako_deflate.min.js"], | ||
inflate: ["../../dist/z-worker.js", "../../dist/inflate.js"] | ||
inflate: ["../../dist/z-worker.js"] | ||
} | ||
@@ -20,0 +20,0 @@ }); |
@@ -7,3 +7,3 @@ /* eslint-disable no-console */ | ||
const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum."; | ||
const URL = "../data/lorem.zip"; | ||
const url = "../data/lorem.zip"; | ||
@@ -17,3 +17,3 @@ test().catch(error => console.error(error)); | ||
let directory = zipFs.root.addDirectory("import"); | ||
await directory.importHttpContent(URL); | ||
await directory.importHttpContent(url); | ||
const blob = await zipFs.exportBlob(); | ||
@@ -20,0 +20,0 @@ zipFs = new zip.fs.FS(); |
@@ -8,3 +8,3 @@ /* eslint-disable no-console */ | ||
const FILENAME = "lorem.txt"; | ||
const URL = "../data/lorem.txt"; | ||
const url = "../data/lorem.txt"; | ||
@@ -17,3 +17,3 @@ test().catch(error => console.error(error)); | ||
let zipFs = new zip.fs.FS(); | ||
zipFs.root.addHttpContent(FILENAME, URL); | ||
zipFs.root.addHttpContent(FILENAME, url); | ||
const blob = await zipFs.exportBlob(); | ||
@@ -20,0 +20,0 @@ zipFs = new zip.fs.FS(); |
@@ -7,3 +7,3 @@ /* eslint-disable no-console */ | ||
const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum."; | ||
const URL = "../data/lorem-store.zip"; | ||
const url = "../data/lorem-store.zip"; | ||
@@ -17,3 +17,3 @@ test().catch(error => console.error(error)); | ||
let directory = zipFs.root.addDirectory("import"); | ||
await directory.importHttpContent(URL); | ||
await directory.importHttpContent(url); | ||
const zippedBlob = await zipFs.exportBlob(); | ||
@@ -20,0 +20,0 @@ zipFs = new zip.fs.FS(); |
@@ -10,4 +10,3 @@ /* eslint-disable no-console */ | ||
// eslint-disable-next-line no-unused-vars | ||
const { ZipDeflate, ZipInflate } = zip.initShimAsyncCodec(pako, { deflate: { raw: true }, inflate: { raw: true } }); | ||
const { Deflate, Inflate } = zip.initShimAsyncCodec(pako, { deflate: { raw: true }, inflate: { raw: true } }); | ||
test().catch(error => console.error(error)); | ||
@@ -18,3 +17,5 @@ | ||
zip.configure({ | ||
useWebWorkers: false | ||
useWebWorkers: false, | ||
Deflate, | ||
Inflate | ||
}); | ||
@@ -21,0 +22,0 @@ const blobWriter = new zip.BlobWriter("application/zip"); |
@@ -19,9 +19,7 @@ /* eslint-disable no-console */ | ||
let zipWriter = new zip.ZipWriter(blobWriter); | ||
try { | ||
await zipWriter.add(FILENAME, new zip.BlobReader(BLOB), { level: 5 }); | ||
zipWriter = null; | ||
} catch (error) { | ||
await zipWriter.add(FILENAME, new zip.BlobReader(BLOB), { level: 0 }); | ||
await zipWriter.close(); | ||
const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData())); | ||
await zipWriter.add(FILENAME, new zip.BlobReader(BLOB), { level: 0 }); | ||
await zipWriter.close(); | ||
const compressedData = blobWriter.getData(); | ||
if ((await getBlobText(compressedData)).includes(TEXT_CONTENT)) { | ||
const zipReader = new zip.ZipReader(new zip.BlobReader(compressedData)); | ||
const entries = await zipReader.getEntries(); | ||
@@ -28,0 +26,0 @@ const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename))); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
1164991
21277
94