@zip.js/zip.js 2.6.30 → 2.6.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/z-worker-fflate.js +1 -1
- package/dist/z-worker-pako.js +1 -1
- package/dist/z-worker.js +1 -1
- package/dist/zip-fs-full.js +26 -19
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +26 -19
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +26 -19
- package/dist/zip-full.min.js +1 -1
- package/dist/zip-no-worker-deflate.min.js +1 -1
- package/dist/zip-no-worker-inflate.min.js +1 -1
- package/dist/zip-no-worker.min.js +1 -1
- package/dist/zip.js +4635 -1
- package/dist/zip.min.js +1 -1
- package/index.cjs +26 -19
- package/lib/core/codec-pool-worker.js +23 -11
- package/lib/core/z-worker-core.js +4 -2
- package/lib/core/zip-reader.js +3 -8
- package/lib/z-worker-inline.js +1 -1
- package/package.json +1 -1
- package/rollup.config.js +4 -4
package/dist/zip.js
CHANGED
|
@@ -1 +1,4635 @@
|
|
|
1
|
-
((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).zip={})})(this,(function(e){"use strict";const{Array:t,Object:n,String:r,Number:s,BigInt:i,Math:a,Date:o,Map:c,Set:l,Response:f,URL:u,Error:d,Uint8Array:h,Uint16Array:w,Uint32Array:p,DataView:g,Blob:y,Promise:m,TextEncoder:b,TextDecoder:k,document:S,crypto:z,btoa:v,TransformStream:x,ReadableStream:_,WritableStream:D,CompressionStream:C,DecompressionStream:R,navigator:I}="undefined"!=typeof globalThis?globalThis:this||self,A=[];for(let e=0;256>e;e++){let t=e;for(let e=0;8>e;e++)1&t?t=t>>>1^3988292384:t>>>=1;A[e]=t}class E{constructor(e){this.crc=e||-1}append(e){let t=0|this.crc;for(let n=0,r=0|e.length;r>n;n++)t=t>>>8^A[255&(t^e[n])];this.crc=t}get(){return~this.crc}}class F extends x{constructor(){const e=new E;super({transform(t){e.append(t)},flush(t){const n=new h(4);new g(n.buffer).setUint32(0,e.get()),t.enqueue(n)}})}}function T(e){if(void 0===b){const t=new h((e=unescape(encodeURIComponent(e))).length);for(let n=0;n<t.length;n++)t[n]=e.charCodeAt(n);return t}return(new b).encode(e)}const U={concat(e,t){if(0===e.length||0===t.length)return e.concat(t);const n=e[e.length-1],r=U.getPartial(n);return 32===r?e.concat(t):U._shiftRight(t,r,0|n,e.slice(0,e.length-1))},bitLength(e){const t=e.length;if(0===t)return 0;const n=e[t-1];return 32*(t-1)+U.getPartial(n)},clamp(e,t){if(32*e.length<t)return e;const n=(e=e.slice(0,a.ceil(t/32))).length;return t&=31,n>0&&t&&(e[n-1]=U.partial(t,e[n-1]&2147483648>>t-1,1)),e},partial:(e,t,n)=>32===e?t:(n?0|t:t<<32-e)+1099511627776*e,getPartial:e=>a.round(e/1099511627776)||32,_shiftRight(e,t,n,r){for(void 0===r&&(r=[]);t>=32;t-=32)r.push(n),n=0;if(0===t)return r.concat(e);for(let s=0;s<e.length;s++)r.push(n|e[s]>>>t),n=e[s]<<32-t;const s=e.length?e[e.length-1]:0,i=U.getPartial(s);return r.push(U.partial(t+i&31,t+i>32?n:r.pop(),1)),r}},G={bytes:{fromBits(e){const t=U.bitLength(e)/8,n=new h(t);let r;for(let s=0;t>s;s++)0==(3&s)&&(r=e[s/4]),n[s]=r>>>24,r<<=8;return n},toBits(e){const t=[];let n,r=0;for(n=0;n<e.length;n++)r=r<<8|e[n],3==(3&n)&&(t.push(r),r=0);return 3&n&&t.push(U.partial(8*(3&n),r)),t}}},N={sha1:function(e){e?(this._h=e._h.slice(0),this._buffer=e._buffer.slice(0),this._length=e._length):this.reset()}};N.sha1.prototype={blockSize:512,reset(){const e=this;return e._h=this._init.slice(0),e._buffer=[],e._length=0,e},update(e){const t=this;"string"==typeof e&&(e=G.utf8String.toBits(e));const n=t._buffer=U.concat(t._buffer,e),r=t._length,s=t._length=r+U.bitLength(e);if(s>9007199254740991)throw new d("Cannot hash more than 2^53 - 1 bits");const i=new p(n);let a=0;for(let e=t.blockSize+r-(t.blockSize+r&t.blockSize-1);s>=e;e+=t.blockSize)t._block(i.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),t},finalize(){const e=this;let t=e._buffer;const n=e._h;t=U.concat(t,[U.partial(1,1)]);for(let e=t.length+2;15&e;e++)t.push(0);for(t.push(a.floor(e._length/4294967296)),t.push(0|e._length);t.length;)e._block(t.splice(0,16));return e.reset(),n},_init:[1732584193,4023233417,2562383102,271733878,3285377520],_key:[1518500249,1859775393,2400959708,3395469782],_f:(e,t,n,r)=>e>19?e>39?e>59?e>79?void 0:t^n^r:t&n|t&r|n&r:t^n^r:t&n|~t&r,_S:(e,t)=>t<<e|t>>>32-e,_block(e){const n=this,r=n._h,s=t(80);for(let t=0;16>t;t++)s[t]=e[t];let i=r[0],o=r[1],c=r[2],l=r[3],f=r[4];for(let e=0;79>=e;e++){16>e||(s[e]=n._S(1,s[e-3]^s[e-8]^s[e-14]^s[e-16]));const t=n._S(5,i)+n._f(e,o,c,l)+f+s[e]+n._key[a.floor(e/20)]|0;f=l,l=c,c=n._S(30,o),o=i,i=t}r[0]=r[0]+i|0,r[1]=r[1]+o|0,r[2]=r[2]+c|0,r[3]=r[3]+l|0,r[4]=r[4]+f|0}};const M={getRandomValues(e){const t=new p(e.buffer),n=e=>{let t=987654321;const n=4294967295;return()=>(t=36969*(65535&t)+(t>>16)&n,(((t<<16)+(e=18e3*(65535&e)+(e>>16)&n)&n)/4294967296+.5)*(a.random()>.5?1:-1))};for(let r,s=0;s<e.length;s+=4){const e=n(4294967296*(r||a.random()));r=987654071*e(),t[s/4]=4294967296*e()|0}return e}},W={importKey:e=>new W.hmacSha1(G.bytes.toBits(e)),pbkdf2(e,t,n,r){if(n=n||1e4,0>r||0>n)throw new d("invalid params to pbkdf2");const s=1+(r>>5)<<2;let i,a,o,c,l;const f=new ArrayBuffer(s),u=new g(f);let h=0;const w=U;for(t=G.bytes.toBits(t),l=1;(s||1)>h;l++){for(i=a=e.encrypt(w.concat(t,[l])),o=1;n>o;o++)for(a=e.encrypt(a),c=0;c<a.length;c++)i[c]^=a[c];for(o=0;(s||1)>h&&o<i.length;o++)u.setInt32(h,i[o]),h+=4}return f.slice(0,r/8)},hmacSha1:class{constructor(e){const t=this,n=t._hash=N.sha1,r=[[],[]],s=n.prototype.blockSize/32;t._baseHash=[new n,new n],e.length>s&&(e=n.hash(e));for(let t=0;s>t;t++)r[0][t]=909522486^e[t],r[1][t]=1549556828^e[t];t._baseHash[0].update(r[0]),t._baseHash[1].update(r[1]),t._resultHash=new n(t._baseHash[0])}reset(){const e=this;e._resultHash=new e._hash(e._baseHash[0]),e._updated=!1}update(e){this._updated=!0,this._resultHash.update(e)}digest(){const e=this,t=e._resultHash.finalize(),n=new e._hash(e._baseHash[1]).update(t).finalize();return e.reset(),n}encrypt(e){if(this._updated)throw new d("encrypt on already updated hmac called!");return this.update(e),this.digest(e)}}},L=void 0!==z&&"function"==typeof z.getRandomValues,Z="Invalid password",B="Invalid signature";function O(e){return L?z.getRandomValues(e):M.getRandomValues(e)}const V=16,H={name:"PBKDF2"},X=n.assign({hash:{name:"HMAC"}},H),P=n.assign({iterations:1e3,hash:{name:"SHA-1"}},H),q=["deriveBits"],Y=[8,12,16],K=[16,24,32],j=10,J=[0,0,0,0],$="undefined",Q="function",ee=typeof z!=$,te=ee&&z.subtle,ne=ee&&typeof te!=$,re=ee&&ne&&typeof te.importKey==Q,se=ee&&ne&&typeof te.deriveBits==Q,ie=G.bytes,ae=class{constructor(e){const t=this;t._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],t._tables[0][0][0]||t._precompute();const n=t._tables[0][4],r=t._tables[1],s=e.length;let i,a,o,c=1;if(4!==s&&6!==s&&8!==s)throw new d("invalid aes key size");for(t._key=[a=e.slice(0),o=[]],i=s;4*s+28>i;i++){let e=a[i-1];(i%s==0||8===s&&i%s==4)&&(e=n[e>>>24]<<24^n[e>>16&255]<<16^n[e>>8&255]<<8^n[255&e],i%s==0&&(e=e<<8^e>>>24^c<<24,c=c<<1^283*(c>>7))),a[i]=a[i-s]^e}for(let e=0;i;e++,i--){const t=a[3&e?i:i-4];o[e]=4>=i||4>e?t:r[0][n[t>>>24]]^r[1][n[t>>16&255]]^r[2][n[t>>8&255]]^r[3][n[255&t]]}}encrypt(e){return this._crypt(e,0)}decrypt(e){return this._crypt(e,1)}_precompute(){const e=this._tables[0],t=this._tables[1],n=e[4],r=t[4],s=[],i=[];let a,o,c,l;for(let e=0;256>e;e++)i[(s[e]=e<<1^283*(e>>7))^e]=e;for(let f=a=0;!n[f];f^=o||1,a=i[a]||1){let i=a^a<<1^a<<2^a<<3^a<<4;i=i>>8^255&i^99,n[f]=i,r[i]=f,l=s[c=s[o=s[f]]];let u=16843009*l^65537*c^257*o^16843008*f,d=257*s[i]^16843008*i;for(let n=0;4>n;n++)e[n][f]=d=d<<24^d>>>8,t[n][i]=u=u<<24^u>>>8}for(let n=0;5>n;n++)e[n]=e[n].slice(0),t[n]=t[n].slice(0)}_crypt(e,t){if(4!==e.length)throw new d("invalid aes block size");const n=this._key[t],r=n.length/4-2,s=[0,0,0,0],i=this._tables[t],a=i[0],o=i[1],c=i[2],l=i[3],f=i[4];let u,h,w,p=e[0]^n[0],g=e[t?3:1]^n[1],y=e[2]^n[2],m=e[t?1:3]^n[3],b=4;for(let e=0;r>e;e++)u=a[p>>>24]^o[g>>16&255]^c[y>>8&255]^l[255&m]^n[b],h=a[g>>>24]^o[y>>16&255]^c[m>>8&255]^l[255&p]^n[b+1],w=a[y>>>24]^o[m>>16&255]^c[p>>8&255]^l[255&g]^n[b+2],m=a[m>>>24]^o[p>>16&255]^c[g>>8&255]^l[255&y]^n[b+3],b+=4,p=u,g=h,y=w;for(let e=0;4>e;e++)s[t?3&-e:e]=f[p>>>24]<<24^f[g>>16&255]<<16^f[y>>8&255]<<8^f[255&m]^n[b++],u=p,p=g,g=y,y=m,m=u;return s}},oe=class{constructor(e,t){this._prf=e,this._initIv=t,this._iv=t}reset(){this._iv=this._initIv}update(e){return this.calculate(this._prf,e,this._iv)}incWord(e){if(255==(e>>24&255)){let t=e>>16&255,n=e>>8&255,r=255&e;255===t?(t=0,255===n?(n=0,255===r?r=0:++r):++n):++t,e=0,e+=t<<16,e+=n<<8,e+=r}else e+=1<<24;return e}incCounter(e){0===(e[0]=this.incWord(e[0]))&&(e[1]=this.incWord(e[1]))}calculate(e,t,n){let r;if(!(r=t.length))return[];const s=U.bitLength(t);for(let s=0;r>s;s+=4){this.incCounter(n);const r=e.encrypt(n);t[s]^=r[0],t[s+1]^=r[1],t[s+2]^=r[2],t[s+3]^=r[3]}return U.clamp(t,s)}},ce=W.hmacSha1;class le extends x{constructor(e,t,r){super({start(){n.assign(this,{ready:new m((e=>this.resolveReady=e)),password:e,signed:t,strength:r-1,pending:new h})},async transform(e,t){const n=this,{password:r,strength:s,resolveReady:i,ready:a}=n;r?(await(async(e,t,n,r)=>{const s=await de(e,t,n,we(r,0,Y[t])),i=we(r,Y[t]);if(s[0]!=i[0]||s[1]!=i[1])throw new d(Z)})(n,s,r,we(e,0,Y[s]+2)),e=we(e,Y[s]+2),i()):await a;const o=new h(e.length-j-(e.length-j)%V);t.enqueue(ue(n,e,o,0,j,!0))},async flush(e){const{signed:t,ctr:n,hmac:r,pending:s,ready:i}=this;await i;const a=we(s,0,s.length-j),o=we(s,s.length-j);let c=new h;if(a.length){const e=ge(ie,a);r.update(e);const t=n.update(e);c=pe(ie,t)}if(t){const e=we(pe(ie,r.digest()),0,j);for(let t=0;j>t;t++)if(e[t]!=o[t])throw new d(B)}e.enqueue(c)}})}}class fe extends x{constructor(e,t){let r;super({start(){n.assign(this,{ready:new m((e=>this.resolveReady=e)),password:e,strength:t-1,pending:new h})},async transform(e,t){const n=this,{password:r,strength:s,resolveReady:i,ready:a}=n;let o=new h;r?(o=await(async(e,t,n)=>{const r=O(new h(Y[t]));return he(r,await de(e,t,n,r))})(n,s,r),i()):await a;const c=new h(o.length+e.length-e.length%V);c.set(o,0),t.enqueue(ue(n,e,c,o.length,0))},async flush(e){const{ctr:t,hmac:n,pending:s,ready:i}=this;await i;let a=new h;if(s.length){const e=t.update(ge(ie,s));n.update(e),a=pe(ie,e)}r.signature=pe(ie,n.digest()).slice(0,j),e.enqueue(he(a,r.signature))}}),r=this}}function ue(e,t,n,r,s,i){const{ctr:a,hmac:o,pending:c}=e,l=t.length-s;let f;for(c.length&&(t=he(c,t),n=((e,t)=>{if(t&&t>e.length){const n=e;(e=new h(t)).set(n,0)}return e})(n,l-l%V)),f=0;l-V>=f;f+=V){const e=ge(ie,we(t,f,f+V));i&&o.update(e);const s=a.update(e);i||o.update(s),n.set(pe(ie,s),f+r)}return e.pending=we(t,f),n}async function de(e,r,s,i){e.password=null;const a=T(s),o=await((e,t,n,r,s)=>re?te.importKey("raw",t,n,!1,s):W.importKey(t))(0,a,X,0,q),c=await(async(e,t,n)=>se?await te.deriveBits(e,t,n):W.pbkdf2(t,e.salt,P.iterations,n))(n.assign({salt:i},P),o,8*(2*K[r]+2)),l=new h(c),f=ge(ie,we(l,0,K[r])),u=ge(ie,we(l,K[r],2*K[r])),d=we(l,2*K[r]);return n.assign(e,{keys:{key:f,authentication:u,passwordVerification:d},ctr:new oe(new ae(f),t.from(J)),hmac:new ce(u)}),d}function he(e,t){let n=e;return e.length+t.length&&(n=new h(e.length+t.length),n.set(e,0),n.set(t,e.length)),n}function we(e,t,n){return e.subarray(t,n)}function pe(e,t){return e.fromBits(t)}function ge(e,t){return e.toBits(t)}class ye extends x{constructor(e,t){super({start(){n.assign(this,{password:e,passwordVerification:t}),Se(this,e)},transform(e,t){const n=this;if(n.password){const t=be(n,e.subarray(0,12));if(n.password=null,t[11]!=n.passwordVerification)throw new d(Z);e=e.subarray(12)}t.enqueue(be(n,e))}})}}class me extends x{constructor(e,t){super({start(){n.assign(this,{password:e,passwordVerification:t}),Se(this,e)},transform(e,t){const n=this;let r,s;if(n.password){n.password=null;const t=O(new h(12));t[11]=n.passwordVerification,r=new h(e.length+t.length),r.set(ke(n,t),0),s=12}else r=new h(e.length),s=0;r.set(ke(n,e),s),t.enqueue(r)}})}}function be(e,t){const n=new h(t.length);for(let r=0;r<t.length;r++)n[r]=ve(e)^t[r],ze(e,n[r]);return n}function ke(e,t){const n=new h(t.length);for(let r=0;r<t.length;r++)n[r]=ve(e)^t[r],ze(e,t[r]);return n}function Se(e,t){const r=[305419896,591751049,878082192];n.assign(e,{keys:r,crcKey0:new E(r[0]),crcKey2:new E(r[2])});for(let n=0;n<t.length;n++)ze(e,t.charCodeAt(n))}function ze(e,t){let[n,r,s]=e.keys;e.crcKey0.append([t]),n=~e.crcKey0.get(),r=_e(a.imul(_e(r+xe(n)),134775813)+1),e.crcKey2.append([r>>>24]),s=~e.crcKey2.get(),e.keys=[n,r,s]}function ve(e){const t=2|e.keys[2];return xe(a.imul(t,1^t)>>>8)}function xe(e){return 255&e}function _e(e){return 4294967295&e}const De="deflate-raw";class Ce extends x{constructor(e,{chunkSize:t,CompressionStream:n,CompressionStreamNative:r}){super({});const{compressed:s,encrypted:i,useCompressionStream:a,password:o,passwordVerification:c,encryptionStrength:l,zipCrypto:f,signed:u,level:d}=e,h=this;let w,p,y=Ie(super.readable);i&&!f||!u||([y,w]=y.tee(),w=Fe(w,new F)),s&&(y=Ee(y,a,{level:d,chunkSize:t},r,n)),i&&(f?y=Fe(y,new me(o,c)):(p=new fe(o,l),y=Fe(y,p))),Ae(h,y,(async()=>{let e;i&&!f&&(e=p.signature),i&&!f||!u||(e=await w.getReader().read(),e=new g(e.value.buffer).getUint32(0)),h.signature=e}))}}class Re extends x{constructor(e,{chunkSize:t,DecompressionStream:n,DecompressionStreamNative:r}){super({});const{zipCrypto:s,encrypted:i,password:a,passwordVerification:o,signed:c,signature:l,encryptionStrength:f,compressed:u,useCompressionStream:h}=e;let w,p,y=Ie(super.readable);i&&(s?y=Fe(y,new ye(a,o)):(p=new le(a,c,f),y=Fe(y,p))),u&&(y=Ee(y,h,{chunkSize:t},r,n)),i&&!s||!c||([y,w]=y.tee(),w=Fe(w,new F)),Ae(this,y,(async()=>{if((!i||s)&&c){const e=await w.getReader().read(),t=new g(e.value.buffer);if(l!=t.getUint32(0,!1))throw new d(B)}}))}}function Ie(e){return Fe(e,new x({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function Ae(e,t,r){t=Fe(t,new x({flush:r})),n.defineProperty(e,"readable",{get:()=>t})}function Ee(e,t,n,r,s){try{e=Fe(e,new(t&&r?r:s)(De,n))}catch(r){if(!t)throw r;e=Fe(e,new s(De,n))}return e}function Fe(e,t){return e.pipeThrough(t)}class Te extends x{constructor(e,t){const n=new e(t);super({transform(e,t){t.enqueue(n.append(e))},flush(e){const t=n.flush();t&&e.enqueue(t)}})}}const Ue="deflate",Ge="inflate",Ne="data";class Me{constructor(e,t,r,s){const{codecType:i}=r;let a;i.startsWith(Ue)?a=Ce:i.startsWith(Ge)&&(a=Re),n.assign(this,{CodecStream:a,readable:e,writable:t,options:r,config:s})}async run(){const{CodecStream:e,readable:t,writable:n,options:r,config:s}=this,i=new e(r,s);let a=0;await t.pipeThrough(i).pipeThrough(new x({transform(e,t){e&&e.length&&(a+=e.length,t.enqueue(e))}})).pipeTo(n,{preventClose:!0,preventAbort:!0});const{signature:o}=i;return{size:a,signature:o}}}function We(e){return class extends Te{constructor(t,n){super(e,n)}}}const Le=void 0;let Ze=2;try{void 0!==I&&I.hardwareConcurrency&&(Ze=I.hardwareConcurrency)}catch(e){}const Be={chunkSize:524288,maxWorkers:Ze,terminateWorkerTimeout:5e3,useWebWorkers:!0,useCompressionStream:!0,workerScripts:void 0,CompressionStreamNative:void 0!==C&&C,DecompressionStreamNative:void 0!==R&&R},Oe=n.assign({},Be);function Ve(){return Oe}function He(e){return a.max(e.chunkSize,64)}function Xe(e){const{baseURL:n,chunkSize:r,maxWorkers:s,terminateWorkerTimeout:i,useCompressionStream:a,useWebWorkers:o,Deflate:c,Inflate:l,CompressionStream:f,DecompressionStream:u,workerScripts:h}=e;if(Pe("baseURL",n),Pe("chunkSize",r),Pe("maxWorkers",s),Pe("terminateWorkerTimeout",i),Pe("useCompressionStream",a),Pe("useWebWorkers",o),c&&(Oe.CompressionStream=We(c)),l&&(Oe.DecompressionStream=We(l)),Pe("CompressionStream",f),Pe("DecompressionStream",u),h!==Le){const{deflate:e,inflate:n}=h;if((e||n)&&(Oe.workerScripts||(Oe.workerScripts={})),e){if(!t.isArray(e))throw new d("workerScripts.deflate must be an array");Oe.workerScripts.deflate=e}if(n){if(!t.isArray(n))throw new d("workerScripts.inflate must be an array");Oe.workerScripts.inflate=n}}}function Pe(e,t){t!==Le&&(Oe[e]=t)}function qe(e,t,r){return class{constructor(s){const i=this;n.hasOwn(s,"level")&&void 0===s.level&&delete s.level,i.codec=new e(n.assign({},t,s)),r(i.codec,(e=>{if(i.pendingData){const{pendingData:t}=i;i.pendingData=new h(t.length+e.length),t.set(t,0),t.set(e,t.length)}else i.pendingData=new h(e)}))}append(e){return this.codec.push(e),s(this)}flush(){return this.codec.push(new h,!0),s(this)}};function s(e){if(e.pendingData){const t=e.pendingData;return e.pendingData=null,t}return new h}}let Ye,Ke=!0,je=!0;class Je{constructor(e,t,r,s){const{readable:i,writable:a}=t,{options:o,config:c,streamOptions:l,useWebWorkers:f,transferStreams:w,scripts:p}=r;n.assign(e,{busy:!0,readable:i,writable:a,options:n.assign({},o),scripts:p,transferStreams:w,terminate(){e.worker&&!e.busy&&(e.worker.terminate(),e.interface=null)},onTaskFinished(){e.busy=!1,s(e)}});const{signal:g,onstart:y,onprogress:b,size:k,onend:S}=l;let z=0;const v={};return y&&(v.start=()=>$e(y,k)),v.transform=async(e,t)=>{z+=e.length,b&&await $e(b,z,k),t.enqueue(e)},v.flush=()=>{i.size=z,S&&$e(S,z)},e.readable=i.pipeThrough(new x(v,{highWaterMark:1,size:()=>c.chunkSize}),{signal:g}),void 0===Ye&&(Ye="undefined"!=typeof Worker),f&&Ye?((e,{baseURL:t,chunkSize:r})=>{const s={type:"module"};if(n.assign(e,{streams:{},result:new m(((t,n)=>{e.resolveResult=t,e.rejectResult=n}))}),!e.interface){if(Ke)try{e.worker=a({})}catch(t){Ke=!1,e.worker=a(s)}else e.worker=a(s);e.worker.addEventListener("message",(async t=>{const r=t.data,{resolveResult:s,rejectResult:i,onTaskFinished:a}=e,{reader:c,writer:l}=e.streams,{type:f,data:u,messageId:w,result:p}=r,g=r.error;try{if(g){const{message:e,stack:t,code:r,name:s}=g,i=new d(e);n.assign(i,{stack:t,code:r,name:s}),y(i)}else{if("pull"==f){const{value:e,done:t}=await c.read();o({type:Ne,data:e,done:t,messageId:w})}f==Ne&&(await l.ready,await l.write(new h(u)),o({type:"ack",messageId:w})),"close"==f&&y(null,p)}}catch(e){y(e)}function y(e,t){e?i(e):s(t),l&&l.releaseLock(),a()}}),!1),e.interface={async run(){const{readable:t,writable:n,options:s}=e,a={type:"start",scripts:e.scripts.slice(1),options:s,config:{chunkSize:r}};e.transferStreams&&je?o({...a,readable:t,writable:n})||(je=!1,i(t,n)):(o(a),i(t,n));const c=await e.result;return e.transferStreams&&je&&n.locked&&await async function e(){if(await new m((e=>setTimeout(e,10))),n.locked)return await e()}(),c}}}return e.interface;function i(t,r){n.assign(e.streams,{reader:t.getReader(),writer:r.getWriter()})}function a(n){let r,s;r=e.scripts[0],"function"==typeof r&&(r=r());try{s=new u(r,t)}catch(e){s=r}return new Worker(s,n)}function o(t){const{worker:n,writer:r,onTaskFinished:s}=e;try{let{data:e,readable:r,writable:s}=t;const i=[];if(e){const{buffer:n,length:r}=e;r!=n.byteLength&&(e=new h(e)),t.data=e.buffer,i.push(t.data)}if(r&&i.push(r),s&&i.push(s),i.length)try{return n.postMessage(t,i),!0}catch(e){t.readable=t.writable=null,n.postMessage(t)}else n.postMessage(t)}catch(e){throw r&&r.releaseLock(),s(),e}}})(e,c):((e,t)=>{const n=new Me(e.readable,e.writable,e.options,t),{onTaskFinished:r}=e;return{async run(){try{return await n.run()}finally{r()}}}})(e,c)}}async function $e(e,...t){try{await e(...t)}catch(e){}}let Qe=[];const et=[];let tt=0;async function nt(e,t){const{options:n,config:r}=t,{transferStreams:i,useWebWorkers:a,useCompressionStream:o,codecType:c,compressed:l,signed:f,encrypted:u}=n,{workerScripts:d}=r;t.transferStreams=i||void 0===i;const h=!(l||f||u||t.transferStreams);let w;if(t.useWebWorkers=!h&&(a||void 0===a&&r.useWebWorkers),t.scripts=t.useWebWorkers&&d?d[c]:[],n.useCompressionStream=o||void 0===o&&r.useCompressionStream,Qe.length<r.maxWorkers){const n={indexWorker:tt};tt++,Qe.push(n),w=new Je(n,e,t,p)}else{const n=Qe.find((e=>!e.busy));n?(rt(n),w=new Je(n,e,t,p)):w=await new m((n=>et.push({resolve:n,stream:e,workerOptions:t})))}return w.run();function p(e){if(et.length){const[{resolve:t,stream:n,workerOptions:r}]=et.splice(0,1);t(new Je(e,n,r,p))}else if(e.worker){const{terminateWorkerTimeout:t}=r;rt(e),s.isFinite(t)&&t>=0&&(e.terminateTimeout=setTimeout((()=>{Qe=Qe.filter((t=>t!=e)),e.terminate()}),t))}else Qe=Qe.filter((t=>t!=e))}}function rt(e){const{terminateTimeout:t}=e;t&&(clearTimeout(t),e.terminateTimeout=null)}const st="HTTP error ",it="HTTP Range not supported",at="GET",ot=65536;class ct{constructor(){this.size=0}init(){this.initialized=!0}}class lt extends ct{get readable(){const e=this,{chunkSize:t=ot}=e,n=new _({start(){this.chunkOffset=0},async pull(r){const{offset:s=0,size:i,diskNumberStart:o}=n,{chunkOffset:c}=this;r.enqueue(await Rt(e,s+c,a.min(t,i-c),o)),c+t>i?r.close():this.chunkOffset+=t}});return n}}class ft extends ct{constructor(){super();const e=this,t=new D({write:t=>e.writeUint8Array(t)});n.defineProperty(e,"writable",{get:()=>t})}writeUint8Array(){}}class ut extends lt{constructor(e){super(),this.blob=e,this.size=e.size}async readUint8Array(e,t){return new h(await this.blob.slice(e,e+t).arrayBuffer())}}class dt extends ct{constructor(e){super();const t=new x,r=[];e&&r.push(["content-type",e]),n.defineProperty(this,"writable",{get:()=>t.writable}),this.blob=new f(t.readable,{headers:r}).blob()}getData(){return this.blob}}class ht extends lt{constructor(e,t){super();const r=this;r.url=e,r.preventHeadRequest=t.preventHeadRequest,r.useRangeHeader=t.useRangeHeader,r.forceRangeRequests=t.forceRangeRequests,r.options=t=n.assign({},t),delete t.preventHeadRequest,delete t.useRangeHeader,delete t.forceRangeRequests,delete t.useXHR}async init(){super.init(),await pt(this,vt,bt)}readUint8Array(e,t){return gt(this,e,t,vt,bt)}}class wt extends lt{constructor(e,t){super();const n=this;n.url=e,n.preventHeadRequest=t.preventHeadRequest,n.useRangeHeader=t.useRangeHeader,n.forceRangeRequests=t.forceRangeRequests,n.options=t}async init(){super.init(),await pt(this,xt,kt)}readUint8Array(e,t){return gt(this,e,t,xt,kt)}}async function pt(e,t,n){if((e=>{const{baseURL:t}=Ve(),{protocol:n}=new u(e,t);return"http:"==n||"https:"==n})(e.url)&&(e.useRangeHeader||e.forceRangeRequests)){const r=await t(at,e,yt(e));if(!e.forceRangeRequests&&"bytes"!=r.headers.get("Accept-Ranges"))throw new d(it);{let i;const a=r.headers.get("Content-Range");if(a){const e=a.trim().split(/\s*\/\s*/);if(e.length){const t=e[1];t&&"*"!=t&&(i=s(t))}}void 0===i?await zt(e,t,n):e.size=i}}else await zt(e,t,n)}async function gt(e,t,n,r,s){if(e.useRangeHeader||e.forceRangeRequests){const s=await r(at,e,yt(e,t,n));if(206!=s.status)throw new d(it);return new h(await s.arrayBuffer())}return e.data||await s(e,e.options),new h(e.data.subarray(t,t+n))}function yt(e,t=0,r=1){return n.assign({},mt(e),{Range:"bytes="+t+"-"+(t+r-1)})}function mt(e){const t=e.options.headers;if(t)return Symbol.iterator in t?n.fromEntries(t):t}async function bt(e){await St(e,vt)}async function kt(e){await St(e,xt)}async function St(e,t){const n=await t(at,e,mt(e));e.data=new h(await n.arrayBuffer()),e.size||(e.size=e.data.length)}async function zt(e,t,n){if(e.preventHeadRequest)await n(e,e.options);else{const r=(await t("HEAD",e,mt(e))).headers.get("Content-Length");r?e.size=s(r):await n(e,e.options)}}async function vt(e,{options:t,url:r},s){const i=await fetch(r,n.assign({},t,{method:e,headers:s}));if(400>i.status)return i;throw 416==i.status?new d(it):new d(st+(i.statusText||i.status))}function xt(e,{url:t},r){return new m(((s,i)=>{const a=new XMLHttpRequest;if(a.addEventListener("load",(()=>{if(400>a.status){const e=[];a.getAllResponseHeaders().trim().split(/[\r\n]+/).forEach((t=>{const n=t.trim().split(/\s*:\s*/);n[0]=n[0].trim().replace(/^[a-z]|-[a-z]/g,(e=>e.toUpperCase())),e.push(n)})),s({status:a.status,arrayBuffer:()=>a.response,headers:new c(e)})}else i(416==a.status?new d(it):new d(st+(a.statusText||a.status)))}),!1),a.addEventListener("error",(e=>i(e.detail.error)),!1),a.open(e,t),r)for(const e of n.entries(r))a.setRequestHeader(e[0],e[1]);a.responseType="arraybuffer",a.send()}))}class _t extends lt{constructor(e,t={}){super(),this.url=e,this.reader=t.useXHR?new wt(e,t):new ht(e,t)}set size(e){}get size(){return this.reader.size}async init(){super.init(),await this.reader.init()}readUint8Array(e,t){return this.reader.readUint8Array(e,t)}}class Dt extends lt{constructor(e){super(),this.readers=e}async init(){super.init();const e=this,{readers:t}=e;e.lastDiskNumber=0,await m.all(t.map((async t=>{await t.init(),e.size+=t.size})))}async readUint8Array(e,t,n=0){const r=this,{readers:s}=this;let i,o=n;-1==o&&(o=s.length-1);let c=e;for(;c>=s[o].size;)c-=s[o].size,o++;const l=s[o],f=l.size;if(c+t>f){const s=f-c;i=new h(t),i.set(await Rt(l,c,s)),i.set(await r.readUint8Array(e+s,t-s,n),s)}else i=await Rt(l,c,t);return r.lastDiskNumber=a.max(o,r.lastDiskNumber),i}}async function Ct(e,t){e.init&&!e.initialized&&await e.init(t)}function Rt(e,t,n,r){return e.readUint8Array(t,n,r)}const It=4294967295,At=65535,Et=67324752,Ft=33639248,Tt=101075792,Ut=117853008,Gt=21589,Nt=2048,Mt="/",Wt=new o(2107,11,31),Lt=new o(1980,0,1),Zt="\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");function Bt(e,t){return t&&"cp437"==t.trim().toLowerCase()?(e=>{{let t="";for(let n=0;n<e.length;n++)t+=Zt[e[n]];return t}})(e):new k(t).decode(e)}const Ot=["filename","rawFilename","directory","encrypted","compressedSize","uncompressedSize","lastModDate","rawLastModDate","comment","rawComment","signature","extraField","rawExtraField","bitFlag","extraFieldZip64","extraFieldUnicodePath","extraFieldUnicodeComment","extraFieldAES","filenameUTF8","commentUTF8","offset","zip64","compressionMethod","extraFieldNTFS","lastAccessDate","creationDate","extraFieldExtendedTimestamp","version","versionMadeBy","msDosCompatible","internalFileAttribute","externalFileAttribute"];class Vt{constructor(e){Ot.forEach((t=>this[t]=e[t]))}}const Ht="File format is not recognized",Xt="End of central directory not found",Pt="End of Zip64 central directory not found",qt="End of Zip64 central directory locator not found",Yt="Central directory header not found",Kt="Local file header not found",jt="Zip64 extra field not found",Jt="File contains encrypted entry",$t="Encryption method not supported",Qt="Compression method not supported",en="Split zip file",tn="utf-8",nn="cp437",rn=[["uncompressedSize",It],["compressedSize",It],["offset",It],["diskNumberStart",At]],sn={[At]:{getValue:pn,bytes:4},[It]:{getValue:gn,bytes:8}};class an{constructor(e,t,r){n.assign(this,{reader:e,config:t,options:r})}async getData(e,t,r={}){const s=this,{reader:i,offset:a,diskNumberStart:o,extraFieldAES:c,compressionMethod:l,config:f,bitFlag:u,signature:h,rawLastModDate:w,uncompressedSize:p,compressedSize:g}=s,y=s.localDirectory={};let m=await Rt(i,a,30,o);const b=yn(m);let k=fn(s,r,"password");if(k=k&&k.length&&k,c&&99!=c.originalCompressionMethod)throw new d(Qt);if(0!=l&&8!=l)throw new d(Qt);if(pn(b,0)!=Et)throw new d(Kt);on(y,b,4),m=await Rt(i,a,30+y.filenameLength+y.extraFieldLength,o),y.rawExtraField=m.subarray(30+y.filenameLength),await cn(s,y,b,4),n.assign(t,{lastAccessDate:y.lastAccessDate,creationDate:y.creationDate});const S=s.encrypted&&y.encrypted,z=S&&!c;if(S){if(!z&&void 0===c.strength)throw new d($t);if(!k)throw new d(Jt)}const v=a+30+y.filenameLength+y.extraFieldLength,x=i.readable;x.diskNumberStart=o,x.offset=v;const _=x.size=g;e instanceof D&&(e={writable:e});const{writable:C}=e;void 0===C.size&&(C.size=0);const R=fn(s,r,"signal"),I=fn(s,r,"preventClose");await Ct(e,p);const{onstart:A,onprogress:E,onend:F}=r,T={options:{codecType:Ge,password:k,zipCrypto:z,encryptionStrength:c&&c.strength,signed:fn(s,r,"checkSignature"),passwordVerification:z&&(u.dataDescriptor?w>>>8&255:h>>>24&255),signature:h,compressed:0!=l,encrypted:S,useWebWorkers:fn(s,r,"useWebWorkers"),useCompressionStream:fn(s,r,"useCompressionStream"),transferStreams:fn(s,r,"transferStreams"),preventClose:I},config:f,streamOptions:{signal:R,size:_,onstart:A,onprogress:E,onend:F}};if(C.size+=(await nt({readable:x,writable:C},T)).size,!I)try{await C.close()}catch(e){}return e.getData?e.getData():C}}function on(e,t,r){const s=e.rawBitFlag=wn(t,r+2),i=1==(1&s),a=pn(t,r+6);n.assign(e,{encrypted:i,version:wn(t,r),bitFlag:{level:(6&s)>>1,dataDescriptor:8==(8&s),languageEncodingFlag:(s&Nt)==Nt},rawLastModDate:a,lastModDate:un(a),filenameLength:wn(t,r+22),extraFieldLength:wn(t,r+24)})}async function cn(e,t,r,s){const{rawExtraField:i}=t,a=t.extraField=new c,l=yn(new h(i));let f=0;try{for(;f<i.length;){const e=wn(l,f),t=wn(l,f+2);a.set(e,{type:e,data:i.slice(f+4,f+4+t)}),f+=4+t}}catch(e){}const u=wn(r,s+4);n.assign(t,{signature:pn(r,s+10),uncompressedSize:pn(r,s+18),compressedSize:pn(r,s+14)});const w=a.get(1);w&&(((e,t)=>{t.zip64=!0;const n=yn(e.data),r=rn.filter((([e,n])=>t[e]==n));for(let s=0,i=0;s<r.length;s++){const[a,o]=r[s];if(t[a]==o){const r=sn[o];t[a]=e[a]=r.getValue(n,i),i+=r.bytes}else if(e[a])throw new d(jt)}})(w,t),t.extraFieldZip64=w);const p=a.get(28789);p&&(await ln(p,"filename","rawFilename",t,e),t.extraFieldUnicodePath=p);const g=a.get(25461);g&&(await ln(g,"comment","rawComment",t,e),t.extraFieldUnicodeComment=g);const y=a.get(39169);y?(((e,t,r)=>{const s=yn(e.data),i=hn(s,4);n.assign(e,{vendorVersion:hn(s,0),vendorId:hn(s,2),strength:i,originalCompressionMethod:r,compressionMethod:wn(s,5)}),t.compressionMethod=e.compressionMethod})(y,t,u),t.extraFieldAES=y):t.compressionMethod=u;const m=a.get(10);m&&(((e,t)=>{const r=yn(e.data);let s,i=4;try{for(;i<e.data.length&&!s;){const t=wn(r,i),n=wn(r,i+2);1==t&&(s=e.data.slice(i+4,i+4+n)),i+=4+n}}catch(e){}try{if(s&&24==s.length){const r=yn(s),i=r.getBigUint64(0,!0),a=r.getBigUint64(8,!0),o=r.getBigUint64(16,!0);n.assign(e,{rawLastModDate:i,rawLastAccessDate:a,rawCreationDate:o});const c={lastModDate:dn(i),lastAccessDate:dn(a),creationDate:dn(o)};n.assign(e,c),n.assign(t,c)}}catch(e){}})(m,t),t.extraFieldNTFS=m);const b=a.get(Gt);b&&(((e,t)=>{const n=yn(e.data),r=hn(n,0),s=[],i=[];1==(1&r)&&(s.push("lastModDate"),i.push("rawLastModDate")),2==(2&r)&&(s.push("lastAccessDate"),i.push("rawLastAccessDate")),4==(4&r)&&(s.push("creationDate"),i.push("rawCreationDate"));let a=1;s.forEach(((r,s)=>{if(e.data.length>=a+4){const c=pn(n,a);t[r]=e[r]=new o(1e3*c);const l=i[s];e[l]=c}a+=4}))})(b,t),t.extraFieldExtendedTimestamp=b)}async function ln(e,t,r,s,i){const a=yn(e.data),o=new E;o.append(i[r]);const c=yn(new h(4));c.setUint32(0,o.get(),!0),n.assign(e,{version:hn(a,0),signature:pn(a,1),[t]:await Bt(e.data.subarray(5)),valid:!i.bitFlag.languageEncodingFlag&&e.signature==pn(c,0)}),e.valid&&(s[t]=e[t],s[t+"UTF8"]=!0)}function fn(e,t,n){return void 0===t[n]?e.options[n]:t[n]}function un(e){const t=(4294901760&e)>>16,n=65535&e;try{return new o(1980+((65024&t)>>9),((480&t)>>5)-1,31&t,(63488&n)>>11,(2016&n)>>5,2*(31&n),0)}catch(e){}}function dn(e){return new o(s(e/i(1e4)-i(116444736e5)))}function hn(e,t){return e.getUint8(t)}function wn(e,t){return e.getUint16(t,!0)}function pn(e,t){return e.getUint32(t,!0)}function gn(e,t){return s(e.getBigUint64(t,!0))}function yn(e){return new g(e.buffer)}const mn="File already exists",bn="Zip file comment exceeds 64KB",kn="File entry comment exceeds 64KB",Sn="File entry name exceeds 64KB",zn="Version exceeds 65535",vn="The strength must equal 1, 2, or 3",xn="Extra field type exceeds 65535",_n="Extra field data exceeds 64KB",Dn="Zip64 is not supported (make sure 'keepOrder' is set to 'true')",Cn=new h([7,0,2,0,65,69,3,0,0]);let Rn=0;const In=[];async function An(e,t){const n=e.getWriter();await n.ready,e.size+=Ln(t),await n.write(t),n.releaseLock()}function En(e){if(e)return(i(e.getTime())+i(116444736e5))*i(1e4)}function Fn(e,t,n){return void 0===t[n]?e.options[n]:t[n]}function Tn(e,t,n){e.setUint8(t,n)}function Un(e,t,n){e.setUint16(t,n,!0)}function Gn(e,t,n){e.setUint32(t,n,!0)}function Nn(e,t,n){e.setBigUint64(t,n,!0)}function Mn(e,t,n){e.set(t,n)}function Wn(e){return new g(e.buffer)}function Ln(...e){let t=0;return e.forEach((e=>e&&(t+=e.length))),t}let Zn;try{Zn=void 0===S&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:void 0===S?location.href:S.currentScript&&S.currentScript.src||new u("zip.js",S.baseURI).href}catch(e){}Xe({baseURL:Zn}),(e=>{const t=()=>u.createObjectURL(new y(['const{Array:e,Object:t,Math:n,Error:r,Uint8Array:s,Uint16Array:i,Uint32Array:o,Int32Array:c,Map:f,DataView:a,Promise:l,TextEncoder:u,crypto:w,postMessage:h,TransformStream:d,ReadableStream:p,WritableStream:y,CompressionStream:m,DecompressionStream:b}=self,g=[];for(let e=0;256>e;e++){let t=e;for(let e=0;8>e;e++)1&t?t=t>>>1^3988292384:t>>>=1;g[e]=t}class k{constructor(e){this.t=e||-1}append(e){let t=0|this.t;for(let n=0,r=0|e.length;r>n;n++)t=t>>>8^g[255&(t^e[n])];this.t=t}get(){return~this.t}}class v extends d{constructor(){const e=new k;super({transform(t){e.append(t)},flush(t){const n=new s(4);new a(n.buffer).setUint32(0,e.get()),t.enqueue(n)}})}}const S={concat(e,t){if(0===e.length||0===t.length)return e.concat(t);const n=e[e.length-1],r=S.i(n);return 32===r?e.concat(t):S.o(t,r,0|n,e.slice(0,e.length-1))},l(e){const t=e.length;if(0===t)return 0;const n=e[t-1];return 32*(t-1)+S.i(n)},u(e,t){if(32*e.length<t)return e;const r=(e=e.slice(0,n.ceil(t/32))).length;return t&=31,r>0&&t&&(e[r-1]=S.h(t,e[r-1]&2147483648>>t-1,1)),e},h:(e,t,n)=>32===e?t:(n?0|t:t<<32-e)+1099511627776*e,i:e=>n.round(e/1099511627776)||32,o(e,t,n,r){for(void 0===r&&(r=[]);t>=32;t-=32)r.push(n),n=0;if(0===t)return r.concat(e);for(let s=0;s<e.length;s++)r.push(n|e[s]>>>t),n=e[s]<<32-t;const s=e.length?e[e.length-1]:0,i=S.i(s);return r.push(S.h(t+i&31,t+i>32?n:r.pop(),1)),r}},C={p:{m(e){const t=S.l(e)/8,n=new s(t);let r;for(let s=0;t>s;s++)0==(3&s)&&(r=e[s/4]),n[s]=r>>>24,r<<=8;return n},g(e){const t=[];let n,r=0;for(n=0;n<e.length;n++)r=r<<8|e[n],3==(3&n)&&(t.push(r),r=0);return 3&n&&t.push(S.h(8*(3&n),r)),t}}},z={k:function(e){e?(this.v=e.v.slice(0),this.S=e.S.slice(0),this.C=e.C):this.reset()}};z.k.prototype={blockSize:512,reset(){const e=this;return e.v=this._.slice(0),e.S=[],e.C=0,e},update(e){const t=this;"string"==typeof e&&(e=C.I.g(e));const n=t.S=S.concat(t.S,e),s=t.C,i=t.C=s+S.l(e);if(i>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new o(n);let f=0;for(let e=t.blockSize+s-(t.blockSize+s&t.blockSize-1);i>=e;e+=t.blockSize)t.A(c.subarray(16*f,16*(f+1))),f+=1;return n.splice(0,16*f),t},D(){const e=this;let t=e.S;const r=e.v;t=S.concat(t,[S.h(1,1)]);for(let e=t.length+2;15&e;e++)t.push(0);for(t.push(n.floor(e.C/4294967296)),t.push(0|e.C);t.length;)e.A(t.splice(0,16));return e.reset(),r},_:[1732584193,4023233417,2562383102,271733878,3285377520],V:[1518500249,1859775393,2400959708,3395469782],R:(e,t,n,r)=>e>19?e>39?e>59?e>79?void 0:t^n^r:t&n|t&r|n&r:t^n^r:t&n|~t&r,B:(e,t)=>t<<e|t>>>32-e,A(t){const r=this,s=r.v,i=e(80);for(let e=0;16>e;e++)i[e]=t[e];let o=s[0],c=s[1],f=s[2],a=s[3],l=s[4];for(let e=0;79>=e;e++){16>e||(i[e]=r.B(1,i[e-3]^i[e-8]^i[e-14]^i[e-16]));const t=r.B(5,o)+r.R(e,c,f,a)+l+i[e]+r.V[n.floor(e/20)]|0;l=a,a=f,f=r.B(30,c),c=o,o=t}s[0]=s[0]+o|0,s[1]=s[1]+c|0,s[2]=s[2]+f|0,s[3]=s[3]+a|0,s[4]=s[4]+l|0}};const _={getRandomValues(e){const t=new o(e.buffer),r=e=>{let t=987654321;const r=4294967295;return()=>(t=36969*(65535&t)+(t>>16)&r,(((t<<16)+(e=18e3*(65535&e)+(e>>16)&r)&r)/4294967296+.5)*(n.random()>.5?1:-1))};for(let s,i=0;i<e.length;i+=4){const e=r(4294967296*(s||n.random()));s=987654071*e(),t[i/4]=4294967296*e()|0}return e}},I={importKey:e=>new I.M(C.p.g(e)),K(e,t,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const i=1+(s>>5)<<2;let o,c,f,l,u;const w=new ArrayBuffer(i),h=new a(w);let d=0;const p=S;for(t=C.p.g(t),u=1;(i||1)>d;u++){for(o=c=e.encrypt(p.concat(t,[u])),f=1;n>f;f++)for(c=e.encrypt(c),l=0;l<c.length;l++)o[l]^=c[l];for(f=0;(i||1)>d&&f<o.length;f++)h.setInt32(d,o[f]),d+=4}return w.slice(0,s/8)},M:class{constructor(e){const t=this,n=t.N=z.k,r=[[],[]],s=n.prototype.blockSize/32;t.P=[new n,new n],e.length>s&&(e=n.hash(e));for(let t=0;s>t;t++)r[0][t]=909522486^e[t],r[1][t]=1549556828^e[t];t.P[0].update(r[0]),t.P[1].update(r[1]),t.U=new n(t.P[0])}reset(){const e=this;e.U=new e.N(e.P[0]),e.T=!1}update(e){this.T=!0,this.U.update(e)}digest(){const e=this,t=e.U.D(),n=new e.N(e.P[1]).update(t).D();return e.reset(),n}encrypt(e){if(this.T)throw new r("encrypt on already updated hmac called!");return this.update(e),this.digest(e)}}},x=void 0!==w&&"function"==typeof w.getRandomValues;function A(e){return x?w.getRandomValues(e):_.getRandomValues(e)}const D={name:"PBKDF2"},V=t.assign({hash:{name:"HMAC"}},D),R=t.assign({iterations:1e3,hash:{name:"SHA-1"}},D),B=["deriveBits"],E=[8,12,16],M=[16,24,32],K=[0,0,0,0],N=void 0!==w,P=N&&w.subtle,U=N&&void 0!==P,T=N&&U&&"function"==typeof P.importKey,W=N&&U&&"function"==typeof P.deriveBits,H=C.p,L=class{constructor(e){const t=this;t.W=[[[],[],[],[],[]],[[],[],[],[],[]]],t.W[0][0][0]||t.H();const n=t.W[0][4],s=t.W[1],i=e.length;let o,c,f,a=1;if(4!==i&&6!==i&&8!==i)throw new r("invalid aes key size");for(t.V=[c=e.slice(0),f=[]],o=i;4*i+28>o;o++){let e=c[o-1];(o%i==0||8===i&&o%i==4)&&(e=n[e>>>24]<<24^n[e>>16&255]<<16^n[e>>8&255]<<8^n[255&e],o%i==0&&(e=e<<8^e>>>24^a<<24,a=a<<1^283*(a>>7))),c[o]=c[o-i]^e}for(let e=0;o;e++,o--){const t=c[3&e?o:o-4];f[e]=4>=o||4>e?t:s[0][n[t>>>24]]^s[1][n[t>>16&255]]^s[2][n[t>>8&255]]^s[3][n[255&t]]}}encrypt(e){return this.L(e,0)}decrypt(e){return this.L(e,1)}H(){const e=this.W[0],t=this.W[1],n=e[4],r=t[4],s=[],i=[];let o,c,f,a;for(let e=0;256>e;e++)i[(s[e]=e<<1^283*(e>>7))^e]=e;for(let l=o=0;!n[l];l^=c||1,o=i[o]||1){let i=o^o<<1^o<<2^o<<3^o<<4;i=i>>8^255&i^99,n[l]=i,r[i]=l,a=s[f=s[c=s[l]]];let u=16843009*a^65537*f^257*c^16843008*l,w=257*s[i]^16843008*i;for(let n=0;4>n;n++)e[n][l]=w=w<<24^w>>>8,t[n][i]=u=u<<24^u>>>8}for(let n=0;5>n;n++)e[n]=e[n].slice(0),t[n]=t[n].slice(0)}L(e,t){if(4!==e.length)throw new r("invalid aes block size");const n=this.V[t],s=n.length/4-2,i=[0,0,0,0],o=this.W[t],c=o[0],f=o[1],a=o[2],l=o[3],u=o[4];let w,h,d,p=e[0]^n[0],y=e[t?3:1]^n[1],m=e[2]^n[2],b=e[t?1:3]^n[3],g=4;for(let e=0;s>e;e++)w=c[p>>>24]^f[y>>16&255]^a[m>>8&255]^l[255&b]^n[g],h=c[y>>>24]^f[m>>16&255]^a[b>>8&255]^l[255&p]^n[g+1],d=c[m>>>24]^f[b>>16&255]^a[p>>8&255]^l[255&y]^n[g+2],b=c[b>>>24]^f[p>>16&255]^a[y>>8&255]^l[255&m]^n[g+3],g+=4,p=w,y=h,m=d;for(let e=0;4>e;e++)i[t?3&-e:e]=u[p>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&b]^n[g++],w=p,p=y,y=m,m=b,b=w;return i}},j=class{constructor(e,t){this.j=e,this.F=t,this.O=t}reset(){this.O=this.F}update(e){return this.q(this.j,e,this.O)}G(e){if(255==(e>>24&255)){let t=e>>16&255,n=e>>8&255,r=255&e;255===t?(t=0,255===n?(n=0,255===r?r=0:++r):++n):++t,e=0,e+=t<<16,e+=n<<8,e+=r}else e+=1<<24;return e}J(e){0===(e[0]=this.G(e[0]))&&(e[1]=this.G(e[1]))}q(e,t,n){let r;if(!(r=t.length))return[];const s=S.l(t);for(let s=0;r>s;s+=4){this.J(n);const r=e.encrypt(n);t[s]^=r[0],t[s+1]^=r[1],t[s+2]^=r[2],t[s+3]^=r[3]}return S.u(t,s)}},F=I.M;class O extends d{constructor(e,n,i){super({start(){t.assign(this,{ready:new l((e=>this.X=e)),password:e,signed:n,Y:i-1,pending:new s})},async transform(e,t){const n=this,{password:i,Y:o,X:c,ready:f}=n;i?(await(async(e,t,n,s)=>{const i=await J(e,t,n,X(s,0,E[t])),o=X(s,E[t]);if(i[0]!=o[0]||i[1]!=o[1])throw new r("Invalid password")})(n,o,i,X(e,0,E[o]+2)),e=X(e,E[o]+2),c()):await f;const a=new s(e.length-10-(e.length-10)%16);t.enqueue(G(n,e,a,0,10,!0))},async flush(e){const{signed:t,Z:n,$:i,pending:o,ready:c}=this;await c;const f=X(o,0,o.length-10),a=X(o,o.length-10);let l=new s;if(f.length){const e=Z(H,f);i.update(e);const t=n.update(e);l=Y(H,t)}if(t){const e=X(Y(H,i.digest()),0,10);for(let t=0;10>t;t++)if(e[t]!=a[t])throw new r("Invalid signature")}e.enqueue(l)}})}}class q extends d{constructor(e,n){let r;super({start(){t.assign(this,{ready:new l((e=>this.X=e)),password:e,Y:n-1,pending:new s})},async transform(e,t){const n=this,{password:r,Y:i,X:o,ready:c}=n;let f=new s;r?(f=await(async(e,t,n)=>{const r=A(new s(E[t]));return Q(r,await J(e,t,n,r))})(n,i,r),o()):await c;const a=new s(f.length+e.length-e.length%16);a.set(f,0),t.enqueue(G(n,e,a,f.length,0))},async flush(e){const{Z:t,$:n,pending:i,ready:o}=this;await o;let c=new s;if(i.length){const e=t.update(Z(H,i));n.update(e),c=Y(H,e)}r.signature=Y(H,n.digest()).slice(0,10),e.enqueue(Q(c,r.signature))}}),r=this}}function G(e,t,n,r,i,o){const{Z:c,$:f,pending:a}=e,l=t.length-i;let u;for(a.length&&(t=Q(a,t),n=((e,t)=>{if(t&&t>e.length){const n=e;(e=new s(t)).set(n,0)}return e})(n,l-l%16)),u=0;l-16>=u;u+=16){const e=Z(H,X(t,u,u+16));o&&f.update(e);const s=c.update(e);o||f.update(s),n.set(Y(H,s),u+r)}return e.pending=X(t,u),n}async function J(n,r,i,o){n.password=null;const c=(e=>{if(void 0===u){const t=new s((e=unescape(encodeURIComponent(e))).length);for(let n=0;n<t.length;n++)t[n]=e.charCodeAt(n);return t}return(new u).encode(e)})(i),f=await((e,t,n,r,s)=>T?P.importKey("raw",t,n,!1,s):I.importKey(t))(0,c,V,0,B),a=await(async(e,t,n)=>W?await P.deriveBits(e,t,n):I.K(t,e.salt,R.iterations,n))(t.assign({salt:o},R),f,8*(2*M[r]+2)),l=new s(a),w=Z(H,X(l,0,M[r])),h=Z(H,X(l,M[r],2*M[r])),d=X(l,2*M[r]);return t.assign(n,{keys:{key:w,ee:h,passwordVerification:d},Z:new j(new L(w),e.from(K)),$:new F(h)}),d}function Q(e,t){let n=e;return e.length+t.length&&(n=new s(e.length+t.length),n.set(e,0),n.set(t,e.length)),n}function X(e,t,n){return e.subarray(t,n)}function Y(e,t){return e.m(t)}function Z(e,t){return e.g(t)}class $ extends d{constructor(e,n){super({start(){t.assign(this,{password:e,passwordVerification:n}),re(this,e)},transform(e,t){const n=this;if(n.password){const t=te(n,e.subarray(0,12));if(n.password=null,t[11]!=n.passwordVerification)throw new r("Invalid password");e=e.subarray(12)}t.enqueue(te(n,e))}})}}class ee extends d{constructor(e,n){super({start(){t.assign(this,{password:e,passwordVerification:n}),re(this,e)},transform(e,t){const n=this;let r,i;if(n.password){n.password=null;const t=A(new s(12));t[11]=n.passwordVerification,r=new s(e.length+t.length),r.set(ne(n,t),0),i=12}else r=new s(e.length),i=0;r.set(ne(n,e),i),t.enqueue(r)}})}}function te(e,t){const n=new s(t.length);for(let r=0;r<t.length;r++)n[r]=ie(e)^t[r],se(e,n[r]);return n}function ne(e,t){const n=new s(t.length);for(let r=0;r<t.length;r++)n[r]=ie(e)^t[r],se(e,t[r]);return n}function re(e,n){const r=[305419896,591751049,878082192];t.assign(e,{keys:r,te:new k(r[0]),ne:new k(r[2])});for(let t=0;t<n.length;t++)se(e,n.charCodeAt(t))}function se(e,t){let[r,s,i]=e.keys;e.te.append([t]),r=~e.te.get(),s=ce(n.imul(ce(s+oe(r)),134775813)+1),e.ne.append([s>>>24]),i=~e.ne.get(),e.keys=[r,s,i]}function ie(e){const t=2|e.keys[2];return oe(n.imul(t,1^t)>>>8)}function oe(e){return 255&e}function ce(e){return 4294967295&e}class fe extends d{constructor(e,{chunkSize:t,CompressionStream:n,re:r}){super({});const{compressed:s,encrypted:i,useCompressionStream:o,password:c,passwordVerification:f,encryptionStrength:l,zipCrypto:u,signed:w,level:h}=e,d=this;let p,y,m=le(super.readable);i&&!u||!w||([m,p]=m.tee(),p=he(p,new v)),s&&(m=we(m,o,{level:h,chunkSize:t},r,n)),i&&(u?m=he(m,new ee(c,f)):(y=new q(c,l),m=he(m,y))),ue(d,m,(async()=>{let e;i&&!u&&(e=y.signature),i&&!u||!w||(e=await p.getReader().read(),e=new a(e.value.buffer).getUint32(0)),d.signature=e}))}}class ae extends d{constructor(e,{chunkSize:t,DecompressionStream:n,se:s}){super({});const{zipCrypto:i,encrypted:o,password:c,passwordVerification:f,signed:l,signature:u,encryptionStrength:w,compressed:h,useCompressionStream:d}=e;let p,y,m=le(super.readable);o&&(i?m=he(m,new $(c,f)):(y=new O(c,l,w),m=he(m,y))),h&&(m=we(m,d,{chunkSize:t},s,n)),o&&!i||!l||([m,p]=m.tee(),p=he(p,new v)),ue(this,m,(async()=>{if((!o||i)&&l){const e=await p.getReader().read(),t=new a(e.value.buffer);if(u!=t.getUint32(0,!1))throw new r("Invalid signature")}}))}}function le(e){return he(e,new d({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function ue(e,n,r){n=he(n,new d({flush:r})),t.defineProperty(e,"readable",{get:()=>n})}function we(e,t,n,r,s){try{e=he(e,new(t&&r?r:s)("deflate-raw",n))}catch(r){if(!t)throw r;e=he(e,new s("deflate-raw",n))}return e}function he(e,t){return e.pipeThrough(t)}class de extends d{constructor(e,t){const n=new e(t);super({transform(e,t){t.enqueue(n.append(e))},flush(e){const t=n.flush();t&&e.enqueue(t)}})}}class pe{constructor(e,n,r,s){const{codecType:i}=r;let o;i.startsWith("deflate")?o=fe:i.startsWith("inflate")&&(o=ae),t.assign(this,{ie:o,readable:e,writable:n,options:r,config:s})}async oe(){const{ie:e,readable:t,writable:n,options:r,config:s}=this,i=new e(r,s);let o=0;await t.pipeThrough(i).pipeThrough(new d({transform(e,t){e&&e.length&&(o+=e.length,t.enqueue(e))}})).pipeTo(n,{preventClose:!0,ce:!0});const{signature:c}=i;return{size:o,signature:c}}}function ye(e){return class extends de{constructor(t,n){super(e,n)}}}const me=new f,be=new f;let ge,ke=0;async function ve(e){try{const{options:t,scripts:n,config:r}=e;n&&n.length&&importScripts.apply(void 0,n),self.initCodec&&self.initCodec(),r.re=self.CompressionStream,r.se=self.DecompressionStream,self.Deflate&&(r.CompressionStream=ye(self.Deflate)),self.Inflate&&(r.DecompressionStream=ye(self.Inflate));const s={highWaterMark:1,size:()=>r.chunkSize},i=e.readable||new p({async pull(e){let t=new l((e=>me.set(ke,e)));Se({type:"pull",messageId:ke}),ke=(ke+1)%Number.MAX_SAFE_INTEGER;const{value:n,done:r}=await t;e.enqueue(n),r&&e.close()}},s),o=e.writable||new y({async write(e){let t;const n=new l((e=>t=e));be.set(ke,t),Se({type:"data",data:e,messageId:ke}),ke=(ke+1)%Number.MAX_SAFE_INTEGER,await n}},s);ge=new pe(i,o,t,r);const c=await ge.oe();e.writable&&!t.preventClose&&await e.writable.close(),Se({type:"close",result:c})}catch(e){Ce(e)}}function Se(e){if(e.data){let{data:t}=e;if(t&&t.length)try{t=new s(t),e.data=t.buffer,h(e,[e.data])}catch(t){h(e)}else h(e)}else h(e)}function Ce(e){const{message:t,stack:n,code:r,name:s}=e;h({error:{message:t,stack:n,code:r,name:s}})}function ze(t){return _e(t.map((([t,n])=>new e(t).fill(n,0,t))))}function _e(t){return t.reduce(((t,n)=>t.concat(e.isArray(n)?_e(n):n)),[])}addEventListener("message",(async e=>{const t=e.data,{type:n,messageId:r,data:i,done:o}=t;try{if("start"==n&&ve(t),"data"==n){const e=me.get(r);me.delete(r),e({value:new s(i),done:o})}if("ack"==n){const e=be.get(r);be.delete(r),e()}}catch(e){Ce(e)}}));const Ie=[0,1,2,3].concat(...ze([[2,4],[2,5],[4,6],[4,7],[8,8],[8,9],[16,10],[16,11],[32,12],[32,13],[64,14],[64,15],[2,0],[1,16],[1,17],[2,18],[2,19],[4,20],[4,21],[8,22],[8,23],[16,24],[16,25],[32,26],[32,27],[64,28],[64,29]]));function xe(){const e=this;function t(e,t){let n=0;do{n|=1&e,e>>>=1,n<<=1}while(--t>0);return n>>>1}e.fe=r=>{const s=e.ae,i=e.ue.le,o=e.ue.we;let c,f,a,l=-1;for(r.he=0,r.de=573,c=0;o>c;c++)0!==s[2*c]?(r.pe[++r.he]=l=c,r.ye[c]=0):s[2*c+1]=0;for(;2>r.he;)a=r.pe[++r.he]=2>l?++l:0,s[2*a]=1,r.ye[a]=0,r.me--,i&&(r.be-=i[2*a+1]);for(e.ge=l,c=n.floor(r.he/2);c>=1;c--)r.ke(s,c);a=o;do{c=r.pe[1],r.pe[1]=r.pe[r.he--],r.ke(s,1),f=r.pe[1],r.pe[--r.de]=c,r.pe[--r.de]=f,s[2*a]=s[2*c]+s[2*f],r.ye[a]=n.max(r.ye[c],r.ye[f])+1,s[2*c+1]=s[2*f+1]=a,r.pe[1]=a++,r.ke(s,1)}while(r.he>=2);r.pe[--r.de]=r.pe[1],(t=>{const n=e.ae,r=e.ue.le,s=e.ue.ve,i=e.ue.Se,o=e.ue.Ce;let c,f,a,l,u,w,h=0;for(l=0;15>=l;l++)t.ze[l]=0;for(n[2*t.pe[t.de]+1]=0,c=t.de+1;573>c;c++)f=t.pe[c],l=n[2*n[2*f+1]+1]+1,l>o&&(l=o,h++),n[2*f+1]=l,f>e.ge||(t.ze[l]++,u=0,i>f||(u=s[f-i]),w=n[2*f],t.me+=w*(l+u),r&&(t.be+=w*(r[2*f+1]+u)));if(0!==h){do{for(l=o-1;0===t.ze[l];)l--;t.ze[l]--,t.ze[l+1]+=2,t.ze[o]--,h-=2}while(h>0);for(l=o;0!==l;l--)for(f=t.ze[l];0!==f;)a=t.pe[--c],a>e.ge||(n[2*a+1]!=l&&(t.me+=(l-n[2*a+1])*n[2*a],n[2*a+1]=l),f--)}})(r),((e,n,r)=>{const s=[];let i,o,c,f=0;for(i=1;15>=i;i++)s[i]=f=f+r[i-1]<<1;for(o=0;n>=o;o++)c=e[2*o+1],0!==c&&(e[2*o]=t(s[c]++,c))})(s,e.ge,r.ze)}}function Ae(e,t,n,r,s){const i=this;i.le=e,i.ve=t,i.Se=n,i.we=r,i.Ce=s}xe._e=[0,1,2,3,4,5,6,7].concat(...ze([[2,8],[2,9],[2,10],[2,11],[4,12],[4,13],[4,14],[4,15],[8,16],[8,17],[8,18],[8,19],[16,20],[16,21],[16,22],[16,23],[32,24],[32,25],[32,26],[31,27],[1,28]])),xe.Ie=[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],xe.xe=[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],xe.Ae=e=>256>e?Ie[e]:Ie[256+(e>>>7)],xe.De=[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],xe.Ve=[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],xe.Re=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],xe.Be=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];const De=ze([[144,8],[112,9],[24,7],[8,8]]);Ae.Ee=_e([12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,19,275,147,403,83,339,211,467,51,307,179,435,115,371,243,499,11,267,139,395,75,331,203,459,43,299,171,427,107,363,235,491,27,283,155,411,91,347,219,475,59,315,187,443,123,379,251,507,7,263,135,391,71,327,199,455,39,295,167,423,103,359,231,487,23,279,151,407,87,343,215,471,55,311,183,439,119,375,247,503,15,271,143,399,79,335,207,463,47,303,175,431,111,367,239,495,31,287,159,415,95,351,223,479,63,319,191,447,127,383,255,511,0,64,32,96,16,80,48,112,8,72,40,104,24,88,56,120,4,68,36,100,20,84,52,116,3,131,67,195,35,163,99,227].map(((e,t)=>[e,De[t]])));const Ve=ze([[30,5]]);function Re(e,t,n,r,s){const i=this;i.Me=e,i.Ke=t,i.Ne=n,i.Pe=r,i.Ue=s}Ae.Te=_e([0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30,1,17,9,25,5,21,13,29,3,19,11,27,7,23].map(((e,t)=>[e,Ve[t]]))),Ae.We=new Ae(Ae.Ee,xe.De,257,286,15),Ae.He=new Ae(Ae.Te,xe.Ve,0,30,15),Ae.Le=new Ae(null,xe.Re,0,19,7);const Be=[new Re(0,0,0,0,0),new Re(4,4,8,4,1),new Re(4,5,16,8,1),new Re(4,6,32,32,1),new Re(4,4,16,16,2),new Re(8,16,32,32,2),new Re(8,16,128,128,2),new Re(8,32,128,256,2),new Re(32,128,258,1024,2),new Re(32,258,258,4096,2)],Ee=["need dictionary","stream end","","","stream error","data error","","buffer error","",""];function Me(e,t,n,r){const s=e[2*t],i=e[2*n];return i>s||s==i&&r[t]<=r[n]}function Ke(){const e=this;let t,r,o,c,f,a,l,u,w,h,d,p,y,m,b,g,k,v,S,C,z,_,I,x,A,D,V,R,B,E,M,K,N;const P=new xe,U=new xe,T=new xe;let W,H,L,j,F,O;function q(){let t;for(t=0;286>t;t++)M[2*t]=0;for(t=0;30>t;t++)K[2*t]=0;for(t=0;19>t;t++)N[2*t]=0;M[512]=1,e.me=e.be=0,H=L=0}function G(e,t){let n,r=-1,s=e[1],i=0,o=7,c=4;0===s&&(o=138,c=3),e[2*(t+1)+1]=65535;for(let f=0;t>=f;f++)n=s,s=e[2*(f+1)+1],++i<o&&n==s||(c>i?N[2*n]+=i:0!==n?(n!=r&&N[2*n]++,N[32]++):i>10?N[36]++:N[34]++,i=0,r=n,0===s?(o=138,c=3):n==s?(o=6,c=3):(o=7,c=4))}function J(t){e.je[e.pending++]=t}function Q(e){J(255&e),J(e>>>8&255)}function X(e,t){let n;const r=t;O>16-r?(n=e,F|=n<<O&65535,Q(F),F=n>>>16-O,O+=r-16):(F|=e<<O&65535,O+=r)}function Y(e,t){const n=2*e;X(65535&t[n],65535&t[n+1])}function Z(e,t){let n,r,s=-1,i=e[1],o=0,c=7,f=4;for(0===i&&(c=138,f=3),n=0;t>=n;n++)if(r=i,i=e[2*(n+1)+1],++o>=c||r!=i){if(f>o)do{Y(r,N)}while(0!=--o);else 0!==r?(r!=s&&(Y(r,N),o--),Y(16,N),X(o-3,2)):o>10?(Y(18,N),X(o-11,7)):(Y(17,N),X(o-3,3));o=0,s=r,0===i?(c=138,f=3):r==i?(c=6,f=3):(c=7,f=4)}}function $(){16==O?(Q(F),F=0,O=0):8>O||(J(255&F),F>>>=8,O-=8)}function ee(t,r){let s,i,o;if(e.Fe[H]=t,e.Oe[H]=255&r,H++,0===t?M[2*r]++:(L++,t--,M[2*(xe._e[r]+256+1)]++,K[2*xe.Ae(t)]++),0==(8191&H)&&V>2){for(s=8*H,i=z-k,o=0;30>o;o++)s+=K[2*o]*(5+xe.Ve[o]);if(s>>>=3,L<n.floor(H/2)&&s<n.floor(i/2))return!0}return H==W-1}function te(t,n){let r,s,i,o,c=0;if(0!==H)do{r=e.Fe[c],s=e.Oe[c],c++,0===r?Y(s,t):(i=xe._e[s],Y(i+256+1,t),o=xe.De[i],0!==o&&(s-=xe.Ie[i],X(s,o)),r--,i=xe.Ae(r),Y(i,n),o=xe.Ve[i],0!==o&&(r-=xe.xe[i],X(r,o)))}while(H>c);Y(256,t),j=t[513]}function ne(){O>8?Q(F):O>0&&J(255&F),F=0,O=0}function re(t,n,r){X(0+(r?1:0),3),((t,n)=>{ne(),j=8,Q(n),Q(~n),e.je.set(u.subarray(t,t+n),e.pending),e.pending+=n})(t,n)}function se(n){((t,n,r)=>{let s,i,o=0;V>0?(P.fe(e),U.fe(e),o=(()=>{let t;for(G(M,P.ge),G(K,U.ge),T.fe(e),t=18;t>=3&&0===N[2*xe.Be[t]+1];t--);return e.me+=14+3*(t+1),t})(),s=e.me+3+7>>>3,i=e.be+3+7>>>3,i>s||(s=i)):s=i=n+5,n+4>s||-1==t?i==s?(X(2+(r?1:0),3),te(Ae.Ee,Ae.Te)):(X(4+(r?1:0),3),((e,t,n)=>{let r;for(X(e-257,5),X(t-1,5),X(n-4,4),r=0;n>r;r++)X(N[2*xe.Be[r]+1],3);Z(M,e-1),Z(K,t-1)})(P.ge+1,U.ge+1,o+1),te(M,K)):re(t,n,r),q(),r&&ne()})(0>k?-1:k,z-k,n),k=z,t.qe()}function ie(){let e,n,r,s;do{if(s=w-I-z,0===s&&0===z&&0===I)s=f;else if(-1==s)s--;else if(z>=f+f-262){u.set(u.subarray(f,f+f),0),_-=f,z-=f,k-=f,e=y,r=e;do{n=65535&d[--r],d[r]=f>n?0:n-f}while(0!=--e);e=f,r=e;do{n=65535&h[--r],h[r]=f>n?0:n-f}while(0!=--e);s+=f}if(0===t.Ge)return;e=t.Je(u,z+I,s),I+=e,3>I||(p=255&u[z],p=(p<<g^255&u[z+1])&b)}while(262>I&&0!==t.Ge)}function oe(e){let t,n,r=A,s=z,i=x;const o=z>f-262?z-(f-262):0;let c=E;const a=l,w=z+258;let d=u[s+i-1],p=u[s+i];B>x||(r>>=2),c>I&&(c=I);do{if(t=e,u[t+i]==p&&u[t+i-1]==d&&u[t]==u[s]&&u[++t]==u[s+1]){s+=2,t++;do{}while(u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&w>s);if(n=258-(w-s),s=w-258,n>i){if(_=e,i=n,n>=c)break;d=u[s+i-1],p=u[s+i]}}}while((e=65535&h[e&a])>o&&0!=--r);return i>I?I:i}e.ye=[],e.ze=[],e.pe=[],M=[],K=[],N=[],e.ke=(t,n)=>{const r=e.pe,s=r[n];let i=n<<1;for(;i<=e.he&&(i<e.he&&Me(t,r[i+1],r[i],e.ye)&&i++,!Me(t,s,r[i],e.ye));)r[n]=r[i],n=i,i<<=1;r[n]=s},e.Qe=(t,S,_,H,L,G)=>(H||(H=8),L||(L=8),G||(G=0),t.Xe=null,-1==S&&(S=6),1>L||L>9||8!=H||9>_||_>15||0>S||S>9||0>G||G>2?-2:(t.Ye=e,a=_,f=1<<a,l=f-1,m=L+7,y=1<<m,b=y-1,g=n.floor((m+3-1)/3),u=new s(2*f),h=[],d=[],W=1<<L+6,e.je=new s(4*W),o=4*W,e.Fe=new i(W),e.Oe=new s(W),V=S,R=G,(t=>(t.Ze=t.$e=0,t.Xe=null,e.pending=0,e.et=0,r=113,c=0,P.ae=M,P.ue=Ae.We,U.ae=K,U.ue=Ae.He,T.ae=N,T.ue=Ae.Le,F=0,O=0,j=8,q(),(()=>{w=2*f,d[y-1]=0;for(let e=0;y-1>e;e++)d[e]=0;D=Be[V].Ke,B=Be[V].Me,E=Be[V].Ne,A=Be[V].Pe,z=0,k=0,I=0,v=x=2,C=0,p=0})(),0))(t))),e.tt=()=>42!=r&&113!=r&&666!=r?-2:(e.Oe=null,e.Fe=null,e.je=null,d=null,h=null,u=null,e.Ye=null,113==r?-3:0),e.nt=(e,t,n)=>{let r=0;return-1==t&&(t=6),0>t||t>9||0>n||n>2?-2:(Be[V].Ue!=Be[t].Ue&&0!==e.Ze&&(r=e.rt(1)),V!=t&&(V=t,D=Be[V].Ke,B=Be[V].Me,E=Be[V].Ne,A=Be[V].Pe),R=n,r)},e.st=(e,t,n)=>{let s,i=n,o=0;if(!t||42!=r)return-2;if(3>i)return 0;for(i>f-262&&(i=f-262,o=n-i),u.set(t.subarray(o,o+i),0),z=i,k=i,p=255&u[0],p=(p<<g^255&u[1])&b,s=0;i-3>=s;s++)p=(p<<g^255&u[s+2])&b,h[s&l]=d[p],d[p]=s;return 0},e.rt=(n,s)=>{let i,w,m,A,B;if(s>4||0>s)return-2;if(!n.it||!n.ot&&0!==n.Ge||666==r&&4!=s)return n.Xe=Ee[4],-2;if(0===n.ct)return n.Xe=Ee[7],-5;var E;if(t=n,A=c,c=s,42==r&&(w=8+(a-8<<4)<<8,m=(V-1&255)>>1,m>3&&(m=3),w|=m<<6,0!==z&&(w|=32),w+=31-w%31,r=113,J((E=w)>>8&255),J(255&E)),0!==e.pending){if(t.qe(),0===t.ct)return c=-1,0}else if(0===t.Ge&&A>=s&&4!=s)return t.Xe=Ee[7],-5;if(666==r&&0!==t.Ge)return n.Xe=Ee[7],-5;if(0!==t.Ge||0!==I||0!=s&&666!=r){switch(B=-1,Be[V].Ue){case 0:B=(e=>{let n,r=65535;for(r>o-5&&(r=o-5);;){if(1>=I){if(ie(),0===I&&0==e)return 0;if(0===I)break}if(z+=I,I=0,n=k+r,(0===z||z>=n)&&(I=z-n,z=n,se(!1),0===t.ct))return 0;if(z-k>=f-262&&(se(!1),0===t.ct))return 0}return se(4==e),0===t.ct?4==e?2:0:4==e?3:1})(s);break;case 1:B=(e=>{let n,r=0;for(;;){if(262>I){if(ie(),262>I&&0==e)return 0;if(0===I)break}if(3>I||(p=(p<<g^255&u[z+2])&b,r=65535&d[p],h[z&l]=d[p],d[p]=z),0===r||(z-r&65535)>f-262||2!=R&&(v=oe(r)),3>v)n=ee(0,255&u[z]),I--,z++;else if(n=ee(z-_,v-3),I-=v,v>D||3>I)z+=v,v=0,p=255&u[z],p=(p<<g^255&u[z+1])&b;else{v--;do{z++,p=(p<<g^255&u[z+2])&b,r=65535&d[p],h[z&l]=d[p],d[p]=z}while(0!=--v);z++}if(n&&(se(!1),0===t.ct))return 0}return se(4==e),0===t.ct?4==e?2:0:4==e?3:1})(s);break;case 2:B=(e=>{let n,r,s=0;for(;;){if(262>I){if(ie(),262>I&&0==e)return 0;if(0===I)break}if(3>I||(p=(p<<g^255&u[z+2])&b,s=65535&d[p],h[z&l]=d[p],d[p]=z),x=v,S=_,v=2,0!==s&&D>x&&f-262>=(z-s&65535)&&(2!=R&&(v=oe(s)),5>=v&&(1==R||3==v&&z-_>4096)&&(v=2)),3>x||v>x)if(0!==C){if(n=ee(0,255&u[z-1]),n&&se(!1),z++,I--,0===t.ct)return 0}else C=1,z++,I--;else{r=z+I-3,n=ee(z-1-S,x-3),I-=x-1,x-=2;do{++z>r||(p=(p<<g^255&u[z+2])&b,s=65535&d[p],h[z&l]=d[p],d[p]=z)}while(0!=--x);if(C=0,v=2,z++,n&&(se(!1),0===t.ct))return 0}}return 0!==C&&(n=ee(0,255&u[z-1]),C=0),se(4==e),0===t.ct?4==e?2:0:4==e?3:1})(s)}if(2!=B&&3!=B||(r=666),0==B||2==B)return 0===t.ct&&(c=-1),0;if(1==B){if(1==s)X(2,3),Y(256,Ae.Ee),$(),9>1+j+10-O&&(X(2,3),Y(256,Ae.Ee),$()),j=7;else if(re(0,0,!1),3==s)for(i=0;y>i;i++)d[i]=0;if(t.qe(),0===t.ct)return c=-1,0}}return 4!=s?0:1}}function Ne(){const e=this;e.ft=0,e.lt=0,e.Ge=0,e.Ze=0,e.ct=0,e.$e=0}function Pe(e){const t=new Ne,i=(o=e&&e.chunkSize?e.chunkSize:65536)+5*(n.floor(o/16383)+1);var o;const c=new s(i);let f=e?e.level:-1;void 0===f&&(f=-1),t.Qe(f),t.it=c,this.append=(e,n)=>{let o,f,a=0,l=0,u=0;const w=[];if(e.length){t.ft=0,t.ot=e,t.Ge=e.length;do{if(t.lt=0,t.ct=i,o=t.rt(0),0!=o)throw new r("deflating: "+t.Xe);t.lt&&(t.lt==i?w.push(new s(c)):w.push(c.slice(0,t.lt))),u+=t.lt,n&&t.ft>0&&t.ft!=a&&(n(t.ft),a=t.ft)}while(t.Ge>0||0===t.ct);return w.length>1?(f=new s(u),w.forEach((e=>{f.set(e,l),l+=e.length}))):f=w[0]||new s,f}},this.flush=()=>{let e,n,o=0,f=0;const a=[];do{if(t.lt=0,t.ct=i,e=t.rt(4),1!=e&&0!=e)throw new r("deflating: "+t.Xe);i-t.ct>0&&a.push(c.slice(0,t.lt)),f+=t.lt}while(t.Ge>0||0===t.ct);return t.tt(),n=new s(f),a.forEach((e=>{n.set(e,o),o+=e.length})),n}}Ne.prototype={Qe(e,t){const n=this;return n.Ye=new Ke,t||(t=15),n.Ye.Qe(n,e,t)},rt(e){const t=this;return t.Ye?t.Ye.rt(t,e):-2},tt(){const e=this;if(!e.Ye)return-2;const t=e.Ye.tt();return e.Ye=null,t},nt(e,t){const n=this;return n.Ye?n.Ye.nt(n,e,t):-2},st(e,t){const n=this;return n.Ye?n.Ye.st(n,e,t):-2},Je(e,t,n){const r=this;let s=r.Ge;return s>n&&(s=n),0===s?0:(r.Ge-=s,e.set(r.ot.subarray(r.ft,r.ft+s),t),r.ft+=s,r.Ze+=s,s)},qe(){const e=this;let t=e.Ye.pending;t>e.ct&&(t=e.ct),0!==t&&(e.it.set(e.Ye.je.subarray(e.Ye.et,e.Ye.et+t),e.lt),e.lt+=t,e.Ye.et+=t,e.$e+=t,e.ct-=t,e.Ye.pending-=t,0===e.Ye.pending&&(e.Ye.et=0))}};const Ue=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Te=[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],We=[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],He=[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],Le=[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],je=[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],Fe=[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];function Oe(){let e,t,n,r,s,i;function o(e,t,o,c,f,a,l,u,w,h,d){let p,y,m,b,g,k,v,S,C,z,_,I,x,A,D;z=0,g=o;do{n[e[t+z]]++,z++,g--}while(0!==g);if(n[0]==o)return l[0]=-1,u[0]=0,0;for(S=u[0],k=1;15>=k&&0===n[k];k++);for(v=k,k>S&&(S=k),g=15;0!==g&&0===n[g];g--);for(m=g,S>g&&(S=g),u[0]=S,A=1<<k;g>k;k++,A<<=1)if(0>(A-=n[k]))return-3;if(0>(A-=n[g]))return-3;for(n[g]+=A,i[1]=k=0,z=1,x=2;0!=--g;)i[x]=k+=n[z],x++,z++;g=0,z=0;do{0!==(k=e[t+z])&&(d[i[k]++]=g),z++}while(++g<o);for(o=i[m],i[0]=g=0,z=0,b=-1,I=-S,s[0]=0,_=0,D=0;m>=v;v++)for(p=n[v];0!=p--;){for(;v>I+S;){if(b++,I+=S,D=m-I,D=D>S?S:D,(y=1<<(k=v-I))>p+1&&(y-=p+1,x=v,D>k))for(;++k<D&&(y<<=1)>n[++x];)y-=n[x];if(D=1<<k,h[0]+D>1440)return-3;s[b]=_=h[0],h[0]+=D,0!==b?(i[b]=g,r[0]=k,r[1]=S,k=g>>>I-S,r[2]=_-s[b-1]-k,w.set(r,3*(s[b-1]+k))):l[0]=_}for(r[1]=v-I,o>z?d[z]<c?(r[0]=256>d[z]?0:96,r[2]=d[z++]):(r[0]=a[d[z]-c]+16+64,r[2]=f[d[z++]-c]):r[0]=192,y=1<<v-I,k=g>>>I;D>k;k+=y)w.set(r,3*(_+k));for(k=1<<v-1;0!=(g&k);k>>>=1)g^=k;for(g^=k,C=(1<<I)-1;(g&C)!=i[b];)b--,I-=S,C=(1<<I)-1}return 0!==A&&1!=m?-5:0}function f(o){let f;for(e||(e=[],t=[],n=new c(16),r=[],s=new c(15),i=new c(16)),t.length<o&&(t=[]),f=0;o>f;f++)t[f]=0;for(f=0;16>f;f++)n[f]=0;for(f=0;3>f;f++)r[f]=0;s.set(n.subarray(0,15),0),i.set(n.subarray(0,16),0)}this.ut=(n,r,s,i,c)=>{let a;return f(19),e[0]=0,a=o(n,0,19,19,null,null,s,r,i,e,t),-3==a?c.Xe="oversubscribed dynamic bit lengths tree":-5!=a&&0!==r[0]||(c.Xe="incomplete dynamic bit lengths tree",a=-3),a},this.wt=(n,r,s,i,c,a,l,u,w)=>{let h;return f(288),e[0]=0,h=o(s,0,n,257,He,Le,a,i,u,e,t),0!=h||0===i[0]?(-3==h?w.Xe="oversubscribed literal/length tree":-4!=h&&(w.Xe="incomplete literal/length tree",h=-3),h):(f(288),h=o(s,n,r,0,je,Fe,l,c,u,e,t),0!=h||0===c[0]&&n>257?(-3==h?w.Xe="oversubscribed distance tree":-5==h?(w.Xe="incomplete distance tree",h=-3):-4!=h&&(w.Xe="empty distance tree with lengths",h=-3),h):0)}}function qe(){const e=this;let t,n,r,s,i=0,o=0,c=0,f=0,a=0,l=0,u=0,w=0,h=0,d=0;function p(e,t,n,r,s,i,o,c){let f,a,l,u,w,h,d,p,y,m,b,g,k,v,S,C;d=c.ft,p=c.Ge,w=o.ht,h=o.dt,y=o.write,m=y<o.read?o.read-y-1:o.end-y,b=Ue[e],g=Ue[t];do{for(;20>h;)p--,w|=(255&c.yt(d++))<<h,h+=8;if(f=w&b,a=n,l=r,C=3*(l+f),0!==(u=a[C]))for(;;){if(w>>=a[C+1],h-=a[C+1],0!=(16&u)){for(u&=15,k=a[C+2]+(w&Ue[u]),w>>=u,h-=u;15>h;)p--,w|=(255&c.yt(d++))<<h,h+=8;for(f=w&g,a=s,l=i,C=3*(l+f),u=a[C];;){if(w>>=a[C+1],h-=a[C+1],0!=(16&u)){for(u&=15;u>h;)p--,w|=(255&c.yt(d++))<<h,h+=8;if(v=a[C+2]+(w&Ue[u]),w>>=u,h-=u,m-=k,v>y){S=y-v;do{S+=o.end}while(0>S);if(u=o.end-S,k>u){if(k-=u,y-S>0&&u>y-S)do{o.bt[y++]=o.bt[S++]}while(0!=--u);else o.bt.set(o.bt.subarray(S,S+u),y),y+=u,S+=u,u=0;S=0}}else S=y-v,y-S>0&&2>y-S?(o.bt[y++]=o.bt[S++],o.bt[y++]=o.bt[S++],k-=2):(o.bt.set(o.bt.subarray(S,S+2),y),y+=2,S+=2,k-=2);if(y-S>0&&k>y-S)do{o.bt[y++]=o.bt[S++]}while(0!=--k);else o.bt.set(o.bt.subarray(S,S+k),y),y+=k,S+=k,k=0;break}if(0!=(64&u))return c.Xe="invalid distance code",k=c.Ge-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.ht=w,o.dt=h,c.Ge=p,c.Ze+=d-c.ft,c.ft=d,o.write=y,-3;f+=a[C+2],f+=w&Ue[u],C=3*(l+f),u=a[C]}break}if(0!=(64&u))return 0!=(32&u)?(k=c.Ge-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.ht=w,o.dt=h,c.Ge=p,c.Ze+=d-c.ft,c.ft=d,o.write=y,1):(c.Xe="invalid literal/length code",k=c.Ge-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.ht=w,o.dt=h,c.Ge=p,c.Ze+=d-c.ft,c.ft=d,o.write=y,-3);if(f+=a[C+2],f+=w&Ue[u],C=3*(l+f),0===(u=a[C])){w>>=a[C+1],h-=a[C+1],o.bt[y++]=a[C+2],m--;break}}else w>>=a[C+1],h-=a[C+1],o.bt[y++]=a[C+2],m--}while(m>=258&&p>=10);return k=c.Ge-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.ht=w,o.dt=h,c.Ge=p,c.Ze+=d-c.ft,c.ft=d,o.write=y,0}e.init=(e,i,o,c,f,a)=>{t=0,u=e,w=i,r=o,h=c,s=f,d=a,n=null},e.gt=(e,y,m)=>{let b,g,k,v,S,C,z,_=0,I=0,x=0;for(x=y.ft,v=y.Ge,_=e.ht,I=e.dt,S=e.write,C=S<e.read?e.read-S-1:e.end-S;;)switch(t){case 0:if(C>=258&&v>=10&&(e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,m=p(u,w,r,h,s,d,e,y),x=y.ft,v=y.Ge,_=e.ht,I=e.dt,S=e.write,C=S<e.read?e.read-S-1:e.end-S,0!=m)){t=1==m?7:9;break}c=u,n=r,o=h,t=1;case 1:for(b=c;b>I;){if(0===v)return e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);m=0,v--,_|=(255&y.yt(x++))<<I,I+=8}if(g=3*(o+(_&Ue[b])),_>>>=n[g+1],I-=n[g+1],k=n[g],0===k){f=n[g+2],t=6;break}if(0!=(16&k)){a=15&k,i=n[g+2],t=2;break}if(0==(64&k)){c=k,o=g/3+n[g+2];break}if(0!=(32&k)){t=7;break}return t=9,y.Xe="invalid literal/length code",m=-3,e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);case 2:for(b=a;b>I;){if(0===v)return e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);m=0,v--,_|=(255&y.yt(x++))<<I,I+=8}i+=_&Ue[b],_>>=b,I-=b,c=w,n=s,o=d,t=3;case 3:for(b=c;b>I;){if(0===v)return e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);m=0,v--,_|=(255&y.yt(x++))<<I,I+=8}if(g=3*(o+(_&Ue[b])),_>>=n[g+1],I-=n[g+1],k=n[g],0!=(16&k)){a=15&k,l=n[g+2],t=4;break}if(0==(64&k)){c=k,o=g/3+n[g+2];break}return t=9,y.Xe="invalid distance code",m=-3,e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);case 4:for(b=a;b>I;){if(0===v)return e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);m=0,v--,_|=(255&y.yt(x++))<<I,I+=8}l+=_&Ue[b],_>>=b,I-=b,t=5;case 5:for(z=S-l;0>z;)z+=e.end;for(;0!==i;){if(0===C&&(S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C&&(e.write=S,m=e.kt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C)))return e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);e.bt[S++]=e.bt[z++],C--,z==e.end&&(z=0),i--}t=0;break;case 6:if(0===C&&(S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C&&(e.write=S,m=e.kt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C)))return e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);m=0,e.bt[S++]=f,C--,t=0;break;case 7:if(I>7&&(I-=8,v++,x--),e.write=S,m=e.kt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,e.read!=e.write)return e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);t=8;case 8:return m=1,e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);case 9:return m=-3,e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m);default:return m=-2,e.ht=_,e.dt=I,y.Ge=v,y.Ze+=x-y.ft,y.ft=x,e.write=S,e.kt(y,m)}},e.vt=()=>{}}Oe.St=(e,t,n,r)=>(e[0]=9,t[0]=5,n[0]=Te,r[0]=We,0);const Ge=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function Je(e,t){const n=this;let r,i=0,o=0,f=0,a=0;const l=[0],u=[0],w=new qe;let h=0,d=new c(4320);const p=new Oe;n.dt=0,n.ht=0,n.bt=new s(t),n.end=t,n.read=0,n.write=0,n.reset=(e,t)=>{t&&(t[0]=0),6==i&&w.vt(e),i=0,n.dt=0,n.ht=0,n.read=n.write=0},n.reset(e,null),n.kt=(e,t)=>{let r,s,i;return s=e.lt,i=n.read,r=(i>n.write?n.end:n.write)-i,r>e.ct&&(r=e.ct),0!==r&&-5==t&&(t=0),e.ct-=r,e.$e+=r,e.it.set(n.bt.subarray(i,i+r),s),s+=r,i+=r,i==n.end&&(i=0,n.write==n.end&&(n.write=0),r=n.write-i,r>e.ct&&(r=e.ct),0!==r&&-5==t&&(t=0),e.ct-=r,e.$e+=r,e.it.set(n.bt.subarray(i,i+r),s),s+=r,i+=r),e.lt=s,n.read=i,t},n.gt=(e,t)=>{let s,c,y,m,b,g,k,v;for(m=e.ft,b=e.Ge,c=n.ht,y=n.dt,g=n.write,k=g<n.read?n.read-g-1:n.end-g;;){let S,C,z,_,I,x,A,D;switch(i){case 0:for(;3>y;){if(0===b)return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);t=0,b--,c|=(255&e.yt(m++))<<y,y+=8}switch(s=7&c,h=1&s,s>>>1){case 0:c>>>=3,y-=3,s=7&y,c>>>=s,y-=s,i=1;break;case 1:S=[],C=[],z=[[]],_=[[]],Oe.St(S,C,z,_),w.init(S[0],C[0],z[0],0,_[0],0),c>>>=3,y-=3,i=6;break;case 2:c>>>=3,y-=3,i=3;break;case 3:return c>>>=3,y-=3,i=9,e.Xe="invalid block type",t=-3,n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t)}break;case 1:for(;32>y;){if(0===b)return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);t=0,b--,c|=(255&e.yt(m++))<<y,y+=8}if((~c>>>16&65535)!=(65535&c))return i=9,e.Xe="invalid stored block lengths",t=-3,n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);o=65535&c,c=y=0,i=0!==o?2:0!==h?7:0;break;case 2:if(0===b)return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);if(0===k&&(g==n.end&&0!==n.read&&(g=0,k=g<n.read?n.read-g-1:n.end-g),0===k&&(n.write=g,t=n.kt(e,t),g=n.write,k=g<n.read?n.read-g-1:n.end-g,g==n.end&&0!==n.read&&(g=0,k=g<n.read?n.read-g-1:n.end-g),0===k)))return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);if(t=0,s=o,s>b&&(s=b),s>k&&(s=k),n.bt.set(e.Je(m,s),g),m+=s,b-=s,g+=s,k-=s,0!=(o-=s))break;i=0!==h?7:0;break;case 3:for(;14>y;){if(0===b)return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);t=0,b--,c|=(255&e.yt(m++))<<y,y+=8}if(f=s=16383&c,(31&s)>29||(s>>5&31)>29)return i=9,e.Xe="too many length or distance symbols",t=-3,n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);if(s=258+(31&s)+(s>>5&31),!r||r.length<s)r=[];else for(v=0;s>v;v++)r[v]=0;c>>>=14,y-=14,a=0,i=4;case 4:for(;4+(f>>>10)>a;){for(;3>y;){if(0===b)return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);t=0,b--,c|=(255&e.yt(m++))<<y,y+=8}r[Ge[a++]]=7&c,c>>>=3,y-=3}for(;19>a;)r[Ge[a++]]=0;if(l[0]=7,s=p.ut(r,l,u,d,e),0!=s)return-3==(t=s)&&(r=null,i=9),n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);a=0,i=5;case 5:for(;s=f,258+(31&s)+(s>>5&31)>a;){let o,w;for(s=l[0];s>y;){if(0===b)return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);t=0,b--,c|=(255&e.yt(m++))<<y,y+=8}if(s=d[3*(u[0]+(c&Ue[s]))+1],w=d[3*(u[0]+(c&Ue[s]))+2],16>w)c>>>=s,y-=s,r[a++]=w;else{for(v=18==w?7:w-14,o=18==w?11:3;s+v>y;){if(0===b)return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);t=0,b--,c|=(255&e.yt(m++))<<y,y+=8}if(c>>>=s,y-=s,o+=c&Ue[v],c>>>=v,y-=v,v=a,s=f,v+o>258+(31&s)+(s>>5&31)||16==w&&1>v)return r=null,i=9,e.Xe="invalid bit length repeat",t=-3,n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);w=16==w?r[v-1]:0;do{r[v++]=w}while(0!=--o);a=v}}if(u[0]=-1,I=[],x=[],A=[],D=[],I[0]=9,x[0]=6,s=f,s=p.wt(257+(31&s),1+(s>>5&31),r,I,x,A,D,d,e),0!=s)return-3==s&&(r=null,i=9),t=s,n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);w.init(I[0],x[0],d,A[0],d,D[0]),i=6;case 6:if(n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,1!=(t=w.gt(n,e,t)))return n.kt(e,t);if(t=0,w.vt(e),m=e.ft,b=e.Ge,c=n.ht,y=n.dt,g=n.write,k=g<n.read?n.read-g-1:n.end-g,0===h){i=0;break}i=7;case 7:if(n.write=g,t=n.kt(e,t),g=n.write,k=g<n.read?n.read-g-1:n.end-g,n.read!=n.write)return n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);i=8;case 8:return t=1,n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);case 9:return t=-3,n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t);default:return t=-2,n.ht=c,n.dt=y,e.Ge=b,e.Ze+=m-e.ft,e.ft=m,n.write=g,n.kt(e,t)}}},n.vt=e=>{n.reset(e,null),n.bt=null,d=null},n.Ct=(e,t,r)=>{n.bt.set(e.subarray(t,t+r),0),n.read=n.write=r},n.zt=()=>1==i?1:0}const Qe=[0,0,255,255];function Xe(){const e=this;function t(e){return e&&e._t?(e.Ze=e.$e=0,e.Xe=null,e._t.mode=7,e._t.It.reset(e,null),0):-2}e.mode=0,e.method=0,e.xt=[0],e.At=0,e.marker=0,e.Dt=0,e.Vt=t=>(e.It&&e.It.vt(t),e.It=null,0),e.Rt=(n,r)=>(n.Xe=null,e.It=null,8>r||r>15?(e.Vt(n),-2):(e.Dt=r,n._t.It=new Je(n,1<<r),t(n),0)),e.Bt=(e,t)=>{let n,r;if(!e||!e._t||!e.ot)return-2;const s=e._t;for(t=4==t?-5:0,n=-5;;)switch(s.mode){case 0:if(0===e.Ge)return n;if(n=t,e.Ge--,e.Ze++,8!=(15&(s.method=e.yt(e.ft++)))){s.mode=13,e.Xe="unknown compression method",s.marker=5;break}if(8+(s.method>>4)>s.Dt){s.mode=13,e.Xe="invalid win size",s.marker=5;break}s.mode=1;case 1:if(0===e.Ge)return n;if(n=t,e.Ge--,e.Ze++,r=255&e.yt(e.ft++),((s.method<<8)+r)%31!=0){s.mode=13,e.Xe="incorrect header check",s.marker=5;break}if(0==(32&r)){s.mode=7;break}s.mode=2;case 2:if(0===e.Ge)return n;n=t,e.Ge--,e.Ze++,s.At=(255&e.yt(e.ft++))<<24&4278190080,s.mode=3;case 3:if(0===e.Ge)return n;n=t,e.Ge--,e.Ze++,s.At+=(255&e.yt(e.ft++))<<16&16711680,s.mode=4;case 4:if(0===e.Ge)return n;n=t,e.Ge--,e.Ze++,s.At+=(255&e.yt(e.ft++))<<8&65280,s.mode=5;case 5:return 0===e.Ge?n:(n=t,e.Ge--,e.Ze++,s.At+=255&e.yt(e.ft++),s.mode=6,2);case 6:return s.mode=13,e.Xe="need dictionary",s.marker=0,-2;case 7:if(n=s.It.gt(e,n),-3==n){s.mode=13,s.marker=0;break}if(0==n&&(n=t),1!=n)return n;n=t,s.It.reset(e,s.xt),s.mode=12;case 12:return e.Ge=0,1;case 13:return-3;default:return-2}},e.Et=(e,t,n)=>{let r=0,s=n;if(!e||!e._t||6!=e._t.mode)return-2;const i=e._t;return s<1<<i.Dt||(s=(1<<i.Dt)-1,r=n-s),i.It.Ct(t,r,s),i.mode=7,0},e.Mt=e=>{let n,r,s,i,o;if(!e||!e._t)return-2;const c=e._t;if(13!=c.mode&&(c.mode=13,c.marker=0),0===(n=e.Ge))return-5;for(r=e.ft,s=c.marker;0!==n&&4>s;)e.yt(r)==Qe[s]?s++:s=0!==e.yt(r)?0:4-s,r++,n--;return e.Ze+=r-e.ft,e.ft=r,e.Ge=n,c.marker=s,4!=s?-3:(i=e.Ze,o=e.$e,t(e),e.Ze=i,e.$e=o,c.mode=7,0)},e.Kt=e=>e&&e._t&&e._t.It?e._t.It.zt():-2}function Ye(){}function Ze(e){const t=new Ye,i=e&&e.chunkSize?n.floor(2*e.chunkSize):131072,o=new s(i);let c=!1;t.Rt(),t.it=o,this.append=(e,n)=>{const f=[];let a,l,u=0,w=0,h=0;if(0!==e.length){t.ft=0,t.ot=e,t.Ge=e.length;do{if(t.lt=0,t.ct=i,0!==t.Ge||c||(t.ft=0,c=!0),a=t.Bt(0),c&&-5===a){if(0!==t.Ge)throw new r("inflating: bad input")}else if(0!==a&&1!==a)throw new r("inflating: "+t.Xe);if((c||1===a)&&t.Ge===e.length)throw new r("inflating: bad input");t.lt&&(t.lt===i?f.push(new s(o)):f.push(o.slice(0,t.lt))),h+=t.lt,n&&t.ft>0&&t.ft!=u&&(n(t.ft),u=t.ft)}while(t.Ge>0||0===t.ct);return f.length>1?(l=new s(h),f.forEach((e=>{l.set(e,w),w+=e.length}))):l=f[0]||new s,l}},this.flush=()=>{t.Vt()}}Ye.prototype={Rt(e){const t=this;return t._t=new Xe,e||(e=15),t._t.Rt(t,e)},Bt(e){const t=this;return t._t?t._t.Bt(t,e):-2},Vt(){const e=this;if(!e._t)return-2;const t=e._t.Vt(e);return e._t=null,t},Mt(){const e=this;return e._t?e._t.Mt(e):-2},Et(e,t){const n=this;return n._t?n._t.Et(n,e,t):-2},yt(e){return this.ot[e]},Je(e,t){return this.ot.subarray(e,e+t)}},self.initCodec=()=>{self.Deflate=Pe,self.Inflate=Ze};\n'],{type:"text/javascript"}));e({workerScripts:{inflate:[t],deflate:[t]}})})(Xe),e.BlobReader=ut,e.BlobWriter=dt,e.Data64URIReader=class extends lt{constructor(e){super();const t=this;t.dataURI=e;let n=e.length;for(;"="==e.charAt(n-1);)n--;t.dataStart=e.indexOf(",")+1,t.size=a.floor(.75*(n-t.dataStart))}readUint8Array(e,t){const n=new h(t),r=4*a.floor(e/3),s=this.dataStart,i=atob(this.dataURI.substring(r+s,4*a.ceil((e+t)/3)+s)),o=e-3*a.floor(r/4);for(let e=o;o+t>e;e++)n[e-o]=i.charCodeAt(e);return n}},e.Data64URIWriter=class extends ft{constructor(e){super(),this.data="data:"+(e||"")+";base64,",this.pending=[]}writeUint8Array(e){const t=this;let n=0,s=t.pending;const i=t.pending.length;for(t.pending="",n=0;n<3*a.floor((i+e.length)/3)-i;n++)s+=r.fromCharCode(e[n]);for(;n<e.length;n++)t.pending+=r.fromCharCode(e[n]);s.length>2?t.data+=v(s):t.pending=s}getData(){return this.data+v(this.pending)}},e.ERR_BAD_FORMAT=Ht,e.ERR_CENTRAL_DIRECTORY_NOT_FOUND=Yt,e.ERR_DUPLICATED_NAME=mn,e.ERR_ENCRYPTED=Jt,e.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND=qt,e.ERR_EOCDR_NOT_FOUND=Xt,e.ERR_EOCDR_ZIP64_NOT_FOUND=Pt,e.ERR_EXTRAFIELD_ZIP64_NOT_FOUND=jt,e.ERR_HTTP_RANGE=it,e.ERR_INVALID_COMMENT=bn,e.ERR_INVALID_ENCRYPTION_STRENGTH=vn,e.ERR_INVALID_ENTRY_COMMENT=kn,e.ERR_INVALID_ENTRY_NAME=Sn,e.ERR_INVALID_EXTRAFIELD_DATA=_n,e.ERR_INVALID_EXTRAFIELD_TYPE=xn,e.ERR_INVALID_PASSWORD=Z,e.ERR_INVALID_SIGNATURE=B,e.ERR_INVALID_VERSION=zn,e.ERR_LOCAL_FILE_HEADER_NOT_FOUND=Kt,e.ERR_SPLIT_ZIP_FILE=en,e.ERR_UNSUPPORTED_COMPRESSION=Qt,e.ERR_UNSUPPORTED_ENCRYPTION=$t,e.ERR_UNSUPPORTED_FORMAT=Dn,e.HttpRangeReader=class extends _t{constructor(e,t={}){t.useRangeHeader=!0,super(e,t)}},e.HttpReader=_t,e.Reader=lt,e.SplitZipReader=Dt,e.TextReader=class extends ut{constructor(e){super(new y([e],{type:"text/plain"}))}},e.TextWriter=class extends dt{constructor(e){super(e),n.assign(this,{encoding:e,utf8:!e||"utf-8"==e.toLowerCase()})}async getData(){const{encoding:e,utf8:t}=this,n=await super.getData();if(n.text&&t)return n.text();{const t=new FileReader;return new m(((r,s)=>{t.onload=({target:e})=>r(e.result),t.onerror=()=>s(t.error),t.readAsText(n,e)}))}}},e.Uint8ArrayReader=class extends lt{constructor(e){super(),this.array=e,this.size=e.length}readUint8Array(e,t){return this.array.slice(e,e+t)}},e.Uint8ArrayWriter=class extends ft{init(e=0){super.init(),this.offset=0,this.array=new h(e)}writeUint8Array(e){const t=this;if(t.offset+e.length>t.array.length){const n=t.array;t.array=new h(n.length+e.length),t.array.set(n)}t.array.set(e,t.offset),t.offset+=e.length}getData(){return this.array}},e.Writer=ft,e.ZipReader=class{constructor(e,t={}){e instanceof _&&(e={readable:e}),n.assign(this,{reader:e,options:t,config:Ve()})}async*getEntriesGenerator(e={}){const r=this;let{reader:s}=r;const{config:i}=r;if(await Ct(s),void 0!==s.size&&s.readUint8Array||(s=t.isArray(s)?new Dt(s):new ut(await new f(s.readable).blob()),await Ct(s)),22>s.size)throw new d(Ht);s.chunkSize=He(i);const o=await(async(e,t,n)=>{const r=new h(4);return yn(r).setUint32(0,101010256,!0),await s(22)||await s(a.min(1048582,n));async function s(t){const s=n-t,i=await Rt(e,s,t);for(let e=i.length-22;e>=0;e--)if(i[e]==r[0]&&i[e+1]==r[1]&&i[e+2]==r[2]&&i[e+3]==r[3])return{offset:s+e,buffer:i.slice(e,e+22).buffer}}})(s,0,s.size);if(!o)throw 134695760==pn(yn(await Rt(s,0,4)))?new d(en):new d(Xt);const{lastDiskNumber:c}=s,l=yn(o);let u=pn(l,12),w=pn(l,16);const p=o.offset,g=wn(l,20),y=p+22+g;let b=wn(l,4);if(void 0!==c&&b!=c)throw new d(en);let k=wn(l,8),S=0,z=0;if(w==It||u==It||k==At||b==At){const e=yn(await Rt(s,o.offset-20,20));if(pn(e,0)!=Ut)throw new d(Pt);w=gn(e,8);let t=await Rt(s,w,56,-1),n=yn(t);const r=o.offset-20-56;if(pn(n,0)!=Tt&&w!=r){const e=w;w=r,S=w-e,t=await Rt(s,w,56,-1),n=yn(t)}if(pn(n,0)!=Tt)throw new d(qt);b==At&&(b=pn(n,16)),k==At&&(k=gn(n,32)),u==It&&(u=gn(n,40)),w-=u}if(0>w||w>=s.size)throw new d(Ht);let v=0,x=await Rt(s,w,u,b),_=yn(x);if(u){const e=o.offset-u;if(pn(_,v)!=Ft&&w!=e){const t=w;w=e,S=w-t,x=await Rt(s,w,u,b),_=yn(x)}}if(0>w||w>=s.size)throw new d(Ht);const D=fn(r,e,"filenameEncoding"),C=fn(r,e,"commentEncoding");for(let t=0;k>t;t++){const o=new an(s,i,r.options);if(pn(_,v)!=Ft)throw new d(Yt);on(o,_,v+6);const c=!!o.bitFlag.languageEncodingFlag,l=v+46,f=l+o.filenameLength,u=f+o.extraFieldLength,h=wn(_,v+4),w=0==(0&h),p=x.subarray(l,f),g=wn(_,v+32),y=u+g,b=x.subarray(u,y),R=c,I=c,A=w&&16==(16&hn(_,v+38)),E=pn(_,v+42)+S;n.assign(o,{versionMadeBy:h,msDosCompatible:w,compressedSize:0,uncompressedSize:0,commentLength:g,directory:A,offset:E,diskNumberStart:wn(_,v+34),internalFileAttribute:wn(_,v+36),externalFileAttribute:pn(_,v+38),rawFilename:p,filenameUTF8:R,commentUTF8:I,rawExtraField:x.subarray(f,u)});const[F,T]=await m.all([Bt(p,R?tn:D||nn),Bt(b,I?tn:C||nn)]);n.assign(o,{rawComment:b,filename:F,comment:T,directory:A||F.endsWith(Mt)}),z=a.max(E,z),await cn(o,o,_,v+6);const U=new Vt(o);U.getData=(e,t)=>o.getData(e,U,t),v=y;const{onprogress:G}=e;if(G)try{await G(t+1,k,new Vt(o))}catch(e){}yield U}const R=fn(r,e,"extractPrependedData"),I=fn(r,e,"extractAppendedData");return R&&(r.prependedData=z>0?await Rt(s,0,z):new h),r.comment=g?await Rt(s,p+22,g):new h,I&&(r.appendedData=y<s.size?await Rt(s,y,s.size-y):new h),!0}async getEntries(e={}){const t=[];for await(const n of this.getEntriesGenerator(e))t.push(n);return t}async close(){}},e.ZipWriter=class{constructor(e,t={}){e instanceof D&&(e={writable:e}),void 0===e.writable.size&&(e.writable.size=0),n.assign(this,{writer:e,options:t,config:Ve(),files:new c,filenames:new l,offset:e.writable.size,pendingEntriesSize:0,pendingAddFileCalls:new l})}async add(e="",r,s={}){const c=this,{pendingAddFileCalls:l,config:f}=c;let u;Rn<f.maxWorkers?Rn++:await new m((e=>In.push(e)));try{if(e=e.trim(),c.filenames.has(e))throw new d(mn);return c.filenames.add(e),u=(async(e,r,s,c)=>{r=r.trim(),c.directory&&!r.endsWith(Mt)?r+=Mt:c.directory=r.endsWith(Mt);const l=T(r);if(Ln(l)>At)throw new d(Sn);const f=c.comment||"",u=T(f);if(Ln(u)>At)throw new d(kn);const y=e.options.version||c.version||0;if(y>At)throw new d(zn);const b=e.options.versionMadeBy||c.versionMadeBy||20;if(b>At)throw new d(zn);const k=Fn(e,c,"lastModDate")||new o,S=Fn(e,c,"lastAccessDate"),z=Fn(e,c,"creationDate"),v=Fn(e,c,"password"),x=Fn(e,c,"encryptionStrength")||3,D=Fn(e,c,"zipCrypto");if(void 0!==v&&void 0!==x&&(1>x||x>3))throw new d(vn);let C=new h;const{extraField:R}=c;if(R){let e=0,t=0;R.forEach((t=>e+=4+Ln(t))),C=new h(e),R.forEach(((e,n)=>{if(n>At)throw new d(xn);if(Ln(e)>At)throw new d(_n);Mn(C,new w([n]),t),Mn(C,new w([Ln(e)]),t+2),Mn(C,e,t+4),t+=4+Ln(e)}))}let I=Fn(e,c,"extendedTimestamp");void 0===I&&(I=!0);let A=0,E=0,F=Fn(e,c,"keepOrder");void 0===F&&(F=!0);let U=0,G=Fn(e,c,"msDosCompatible");void 0===G&&(G=!0);const N=Fn(e,c,"internalFileAttribute")||0,M=Fn(e,c,"externalFileAttribute")||0;let W=Fn(e,c,"zip64");if(s&&(s instanceof _&&(s={readable:s}),await Ct(s),void 0===s.size?(c.dataDescriptor=!0,void 0===W&&(W=!0)):U=s.size,A=(e=>e+5*(a.floor(e/16383)+1))(U)),e.offset+e.pendingEntriesSize>=It||U>=It||A>=It){if(!1===W||!F)throw new d(Dn);W=!0}W=W||!1;const L=Fn(e,c,"level"),Z=Fn(e,c,"useWebWorkers"),B=Fn(e,c,"bufferedWrite");let O=Fn(e,c,"dataDescriptor"),V=Fn(e,c,"dataDescriptorSignature");const H=Fn(e,c,"signal"),X=Fn(e,c,"useCompressionStream");void 0===O&&(O=!0),O&&void 0===V&&(V=!1);const P=(e=>{const{rawFilename:t,lastModDate:n,lastAccessDate:r,creationDate:s,password:i,level:o,zip64:c,zipCrypto:l,dataDescriptor:f,directory:u,rawExtraField:d,encryptionStrength:w,extendedTimestamp:g}=e,y=0!==o&&!u,m=!(!i||!Ln(i));let b,k,S;if(m&&!l){b=new h(Ln(Cn)+2);const e=Wn(b);Un(e,0,39169),Mn(b,Cn,2),Tn(e,8,w)}else b=new h;if(g){S=new h(9+(r?4:0)+(s?4:0));const e=Wn(S);Un(e,0,Gt),Un(e,2,Ln(S)-4),Tn(e,4,1+(r?2:0)+(s?4:0)),Gn(e,5,a.floor(n.getTime()/1e3)),r&&Gn(e,9,a.floor(r.getTime()/1e3)),s&&Gn(e,13,a.floor(s.getTime()/1e3));try{k=new h(36);const e=Wn(k),t=En(n);Un(e,0,10),Un(e,2,32),Un(e,8,1),Un(e,10,24),Nn(e,12,t),Nn(e,20,En(r)||t),Nn(e,28,En(s)||t)}catch(e){k=new h}}else k=S=new h;let z=Nt;f&&(z|=8);let v=0;y&&(v=8);let x=e.version||20;c&&(x=x>45?x:45),m&&(z|=1,l||(x=x>51?x:51,v=99,y&&(b[9]=8)));const _=new h(26),D=Wn(_);Un(D,0,x),Un(D,2,z),Un(D,4,v);const C=new p(1),R=Wn(C);let I;I=Lt>n?Lt:n>Wt?Wt:n,Un(R,0,(I.getHours()<<6|I.getMinutes())<<5|I.getSeconds()/2),Un(R,2,(I.getFullYear()-1980<<4|I.getMonth()+1)<<5|I.getDate());const A=C[0];Gn(D,6,A),Un(D,22,Ln(t));const E=Ln(b,S,k,d);Un(D,24,E);const F=new h(30+Ln(t)+E);return Gn(Wn(F),0,Et),Mn(F,_,4),Mn(F,t,30),Mn(F,b,30+Ln(t)),Mn(F,S,30+Ln(t,b)),Mn(F,k,30+Ln(t,b,S)),Mn(F,d,30+Ln(t,b,S,k)),{localHeaderArray:F,headerArray:_,headerView:D,lastModDate:n,rawLastModDate:A,encrypted:m,compressed:y,version:x,compressionMethod:v,rawExtraFieldExtendedTimestamp:S,rawExtraFieldNTFS:k,rawExtraFieldAES:b}})(c=n.assign({},c,{rawFilename:l,rawComment:u,version:y,versionMadeBy:b,lastModDate:k,lastAccessDate:S,creationDate:z,rawExtraField:C,zip64:W,password:v,level:L,useWebWorkers:Z,encryptionStrength:x,extendedTimestamp:I,zipCrypto:D,bufferedWrite:B,keepOrder:F,dataDescriptor:O,dataDescriptorSignature:V,signal:H,msDosCompatible:G,internalFileAttribute:N,externalFileAttribute:M,useCompressionStream:X})),q=(e=>{const{zip64:t,dataDescriptor:n,dataDescriptorSignature:r}=e;let s,i=new h,a=0;return n&&(i=new h(t?r?24:20:r?16:12),s=Wn(i),r&&(a=4,Gn(s,0,134695760))),{dataDescriptorArray:i,dataDescriptorView:s,dataDescriptorOffset:a}})(c);let Y;E=Ln(P.localHeaderArray,q.dataDescriptorArray)+A,e.pendingEntriesSize+=E;try{Y=await(async(e,r,s,a,o)=>{const{files:c,writer:l}=e,{keepOrder:f,dataDescriptor:u,zipCrypto:w,signal:p}=o,y=t.from(c.values()).pop();let b,k,S,z,v,x,_={};c.set(r,_);try{let t;if(f&&(t=y&&y.lock,_.lock=new m((e=>S=e))),o.bufferedWrite||e.lockWriter||!u?(x=new dt,x.writable.size=0,b=!0,await Ct(l)):(x=l,e.lockWriter=m.resolve(),k=()=>delete e.lockWriter),await Ct(x),b||await t,v=!0,_=await(async(e,t,r,s,a,o)=>{const{headerInfo:c,dataDescriptorInfo:l}=s,{localHeaderArray:f,headerArray:u,lastModDate:d,rawLastModDate:w,encrypted:p,compressed:g,version:y,compressionMethod:m,rawExtraFieldExtendedTimestamp:b,rawExtraFieldNTFS:k,rawExtraFieldAES:S}=c,{dataDescriptorArray:z}=l,{rawFilename:v,lastAccessDate:x,creationDate:_,password:D,level:C,zip64:R,zipCrypto:I,dataDescriptor:A,directory:E,versionMadeBy:F,rawComment:T,rawExtraField:U,useWebWorkers:G,onstart:N,onprogress:M,onend:W,signal:L,encryptionStrength:Z,extendedTimestamp:B,msDosCompatible:O,internalFileAttribute:V,externalFileAttribute:H,useCompressionStream:X}=o,P={lock:r.lock,versionMadeBy:F,zip64:R,directory:!!E,filenameUTF8:!0,rawFilename:v,commentUTF8:!0,rawComment:T,rawExtraFieldExtendedTimestamp:b,rawExtraFieldNTFS:k,rawExtraFieldAES:S,rawExtraField:U,extendedTimestamp:B,msDosCompatible:O,internalFileAttribute:V,externalFileAttribute:H};let q,Y=0,K=0;const{writable:j}=t;if(e){e.chunkSize=He(a),await An(j,f);const t=e.readable,n=t.size=e.size,r={options:{codecType:Ue,level:C,password:D,encryptionStrength:Z,zipCrypto:p&&I,passwordVerification:p&&I&&w>>8&255,signed:!0,compressed:g,encrypted:p,useWebWorkers:G,useCompressionStream:X,transferStreams:!1},config:a,streamOptions:{signal:L,size:n,onstart:N,onprogress:M,onend:W}},s=await nt({readable:t,writable:j},r);j.size+=s.size,q=s.signature,Y=e.size=t.size,K=s.size}else await An(j,f);const J=R?new h(28):new h;return e&&((e,t)=>{const{signature:n,rawExtraFieldZip64:r,compressedSize:s,uncompressedSize:a,headerInfo:o,dataDescriptorInfo:c}=e,{headerView:l,encrypted:f}=o,{dataDescriptorView:u,dataDescriptorOffset:d}=c,{zip64:h,zipCrypto:w,dataDescriptor:p}=t;if(f&&!w||void 0===n||(Gn(l,10,n),p&&Gn(u,d,n)),h){const e=Wn(r);Un(e,0,1),Un(e,2,24),Gn(l,14,It),Nn(e,12,i(s)),Gn(l,18,It),Nn(e,4,i(a)),p&&(Nn(u,d+4,i(s)),Nn(u,d+12,i(a)))}else Gn(l,14,s),Gn(l,18,a),p&&(Gn(u,d+4,s),Gn(u,d+8,a))})({signature:q,rawExtraFieldZip64:J,compressedSize:K,uncompressedSize:Y,headerInfo:c,dataDescriptorInfo:l},o),A&&await An(j,z),n.assign(P,{compressedSize:K,lastModDate:d,rawLastModDate:w,creationDate:_,lastAccessDate:x,encrypted:p,length:Ln(f,z)+K,compressionMethod:m,version:y,headerArray:u,signature:q,rawExtraFieldZip64:J}),P})(s,x,_,a,e.config,o),v=!1,c.set(r,_),_.filename=r,b){await x.writable.close();let n=await x.getData();await t,await async function t(){const{lockWriter:n}=e;if(n)return await n.then((()=>delete e.lockWriter)),t();e.lockWriter=new m((e=>k=e))}(),z=!0;const{writable:r}=l;if(!u){const e=await(e=>e.slice(0,26).arrayBuffer())(n),t=new g(e);_.encrypted&&!w||Gn(t,14,_.signature),_.zip64?(Gn(t,18,It),Gn(t,22,It)):(Gn(t,18,_.compressedSize),Gn(t,22,_.uncompressedSize)),await An(r,new h(e)),n=n.slice(e.byteLength)}await n.stream().pipeTo(r,{preventClose:!0,signal:p}),z=!1}if(_.offset=e.offset,_.zip64)Nn(Wn(_.rawExtraFieldZip64),20,i(_.offset));else if(_.offset>=It)throw new d(Dn);return e.offset+=_.length,_}catch(t){throw(b&&z||!b&&v)&&(e.hasCorruptedEntries=!0,t&&(t.corruptedEntry=!0),b?e.offset+=x.writable.size:e.offset=x.writable.size),c.delete(r),t}finally{S&&S(),k&&k()}})(e,r,s,{headerInfo:P,dataDescriptorInfo:q},c)}catch(t){throw!t.corruptedEntry&&E&&(e.pendingEntriesSize-=E),t}return n.assign(Y,{name:r,comment:f,extraField:R}),new Vt(Y)})(c,e,r,s),l.add(u),await u}catch(t){throw c.filenames.delete(e),t}finally{l.delete(u);const e=In.shift();e?e():Rn--}}async close(e=new h,n={}){const{pendingAddFileCalls:r,writer:s}=this,{writable:o}=s;for(;r.size;)await m.all(t.from(r));return await(async(e,n,r)=>{const{files:s}=e;let o=0,c=0,l=e.offset,f=s.size;for(const[,{rawFilename:e,rawExtraFieldZip64:t,rawExtraFieldAES:n,rawExtraField:r,rawComment:i,rawExtraFieldExtendedTimestamp:a,rawExtraFieldNTFS:o}]of s)c+=46+Ln(e,i,t,n,a,o,r);let u=r.zip64||e.options.zip64||!1;if(l>=It||c>=It||f>=At){if(!1===r.zip64||!1===e.options.zip64)throw new d(Dn);u=!0}const w=new h(c+(u?98:22)),p=Wn(w);for(const[e,n]of t.from(s.values()).entries()){const{offset:t,rawFilename:i,rawExtraFieldZip64:c,rawExtraFieldAES:l,rawExtraFieldNTFS:f,rawExtraField:u,rawComment:d,versionMadeBy:g,headerArray:y,directory:m,zip64:b,msDosCompatible:k,internalFileAttribute:S,externalFileAttribute:z,extendedTimestamp:v,lastModDate:x}=n;let _;if(v){_=new h(9);const e=Wn(_);Un(e,0,Gt),Un(e,2,Ln(_)-4),Tn(e,4,1),Gn(e,5,a.floor(x.getTime()/1e3))}else _=new h;const D=Ln(c,l,_,f,u);if(Gn(p,o,Ft),Un(p,o+4,g),Mn(w,y,o+6),Un(p,o+30,D),Un(p,o+32,Ln(d)),Un(p,o+36,S),z?Gn(p,o+38,z):m&&k&&Tn(p,o+38,16),Gn(p,o+42,b?It:t),Mn(w,i,o+46),Mn(w,c,o+46+Ln(i)),Mn(w,l,o+46+Ln(i,c)),Mn(w,_,o+46+Ln(i,c,l)),Mn(w,f,o+46+Ln(i,c,l,_)),Mn(w,u,o+46+Ln(i,c,l,_,f)),Mn(w,d,o+46+Ln(i)+D),o+=46+Ln(i,d)+D,r.onprogress)try{await r.onprogress(e+1,s.size,new Vt(n))}catch(e){}}u&&(Gn(p,o,Tt),Nn(p,o+4,i(44)),Un(p,o+12,45),Un(p,o+14,45),Nn(p,o+24,i(f)),Nn(p,o+32,i(f)),Nn(p,o+40,i(c)),Nn(p,o+48,i(l)),Gn(p,o+56,Ut),Nn(p,o+64,i(l)+i(c)),Gn(p,o+72,1),f=At,l=It,c=It,o+=76),Gn(p,o,101010256),Un(p,o+8,f),Un(p,o+10,f),Gn(p,o+12,c),Gn(p,o+16,l);const g=Ln(n);if(g){if(g>At)throw new d(bn);Un(p,o+20,g)}const{writable:y}=e.writer;await Ct(e.writer),await An(y,w),g&&await An(y,n)})(this,e,n),s.preventClose||n.preventClose||await o.close(),s.getData?s.getData():o}},e.configure=Xe,e.getMimeType=()=>"application/octet-stream",e.initShimAsyncCodec=(e,t={},n)=>({Deflate:qe(e.Deflate,t.deflate,n),Inflate:qe(e.Inflate,t.inflate,n)}),e.initStream=Ct,e.readUint8Array=Rt,e.terminateWorkers=()=>{Qe.forEach((e=>{rt(e),e.terminate()}))},n.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.zip = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const { Array, Object, String, Number, BigInt, Math, Date, Map, Set, Response, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, document, crypto, btoa, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream, navigator } = typeof globalThis !== 'undefined' ? globalThis : this || self;
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
11
|
+
|
|
12
|
+
Redistribution and use in source and binary forms, with or without
|
|
13
|
+
modification, are permitted provided that the following conditions are met:
|
|
14
|
+
|
|
15
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
16
|
+
this list of conditions and the following disclaimer.
|
|
17
|
+
|
|
18
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
19
|
+
notice, this list of conditions and the following disclaimer in
|
|
20
|
+
the documentation and/or other materials provided with the distribution.
|
|
21
|
+
|
|
22
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
23
|
+
derived from this software without specific prior written permission.
|
|
24
|
+
|
|
25
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
26
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
28
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
29
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
30
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
31
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
32
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
33
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
34
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const table = [];
|
|
38
|
+
for (let i = 0; i < 256; i++) {
|
|
39
|
+
let t = i;
|
|
40
|
+
for (let j = 0; j < 8; j++) {
|
|
41
|
+
if (t & 1) {
|
|
42
|
+
t = (t >>> 1) ^ 0xEDB88320;
|
|
43
|
+
} else {
|
|
44
|
+
t = t >>> 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
table[i] = t;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class Crc32 {
|
|
51
|
+
|
|
52
|
+
constructor(crc) {
|
|
53
|
+
this.crc = crc || -1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
append(data) {
|
|
57
|
+
let crc = this.crc | 0;
|
|
58
|
+
for (let offset = 0, length = data.length | 0; offset < length; offset++) {
|
|
59
|
+
crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
|
|
60
|
+
}
|
|
61
|
+
this.crc = crc;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get() {
|
|
65
|
+
return ~this.crc;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
71
|
+
|
|
72
|
+
Redistribution and use in source and binary forms, with or without
|
|
73
|
+
modification, are permitted provided that the following conditions are met:
|
|
74
|
+
|
|
75
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
76
|
+
this list of conditions and the following disclaimer.
|
|
77
|
+
|
|
78
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
79
|
+
notice, this list of conditions and the following disclaimer in
|
|
80
|
+
the documentation and/or other materials provided with the distribution.
|
|
81
|
+
|
|
82
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
83
|
+
derived from this software without specific prior written permission.
|
|
84
|
+
|
|
85
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
86
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
87
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
88
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
89
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
90
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
91
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
92
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
93
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
94
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
class Crc32Stream extends TransformStream {
|
|
98
|
+
|
|
99
|
+
constructor() {
|
|
100
|
+
const crc32 = new Crc32();
|
|
101
|
+
super({
|
|
102
|
+
transform(chunk) {
|
|
103
|
+
crc32.append(chunk);
|
|
104
|
+
},
|
|
105
|
+
flush(controller) {
|
|
106
|
+
const value = new Uint8Array(4);
|
|
107
|
+
const dataView = new DataView(value.buffer);
|
|
108
|
+
dataView.setUint32(0, crc32.get());
|
|
109
|
+
controller.enqueue(value);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
117
|
+
|
|
118
|
+
Redistribution and use in source and binary forms, with or without
|
|
119
|
+
modification, are permitted provided that the following conditions are met:
|
|
120
|
+
|
|
121
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
122
|
+
this list of conditions and the following disclaimer.
|
|
123
|
+
|
|
124
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
125
|
+
notice, this list of conditions and the following disclaimer in
|
|
126
|
+
the documentation and/or other materials provided with the distribution.
|
|
127
|
+
|
|
128
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
129
|
+
derived from this software without specific prior written permission.
|
|
130
|
+
|
|
131
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
132
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
133
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
134
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
135
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
136
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
137
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
138
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
139
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
140
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
function encodeText(value) {
|
|
144
|
+
if (typeof TextEncoder == "undefined") {
|
|
145
|
+
value = unescape(encodeURIComponent(value));
|
|
146
|
+
const result = new Uint8Array(value.length);
|
|
147
|
+
for (let i = 0; i < result.length; i++) {
|
|
148
|
+
result[i] = value.charCodeAt(i);
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
} else {
|
|
152
|
+
return new TextEncoder().encode(value);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl
|
|
157
|
+
|
|
158
|
+
/*// deno-lint-ignore-file no-this-alias *
|
|
159
|
+
|
|
160
|
+
/*
|
|
161
|
+
* SJCL is open. You can use, modify and redistribute it under a BSD
|
|
162
|
+
* license or under the GNU GPL, version 2.0.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/** @fileOverview Javascript cryptography implementation.
|
|
166
|
+
*
|
|
167
|
+
* Crush to remove comments, shorten variable names and
|
|
168
|
+
* generally reduce transmission size.
|
|
169
|
+
*
|
|
170
|
+
* @author Emily Stark
|
|
171
|
+
* @author Mike Hamburg
|
|
172
|
+
* @author Dan Boneh
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
/*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
|
|
176
|
+
|
|
177
|
+
/** @fileOverview Arrays of bits, encoded as arrays of Numbers.
|
|
178
|
+
*
|
|
179
|
+
* @author Emily Stark
|
|
180
|
+
* @author Mike Hamburg
|
|
181
|
+
* @author Dan Boneh
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Arrays of bits, encoded as arrays of Numbers.
|
|
186
|
+
* @namespace
|
|
187
|
+
* @description
|
|
188
|
+
* <p>
|
|
189
|
+
* These objects are the currency accepted by SJCL's crypto functions.
|
|
190
|
+
* </p>
|
|
191
|
+
*
|
|
192
|
+
* <p>
|
|
193
|
+
* Most of our crypto primitives operate on arrays of 4-byte words internally,
|
|
194
|
+
* but many of them can take arguments that are not a multiple of 4 bytes.
|
|
195
|
+
* This library encodes arrays of bits (whose size need not be a multiple of 8
|
|
196
|
+
* bits) as arrays of 32-bit words. The bits are packed, big-endian, into an
|
|
197
|
+
* array of words, 32 bits at a time. Since the words are double-precision
|
|
198
|
+
* floating point numbers, they fit some extra data. We use this (in a private,
|
|
199
|
+
* possibly-changing manner) to encode the number of bits actually present
|
|
200
|
+
* in the last word of the array.
|
|
201
|
+
* </p>
|
|
202
|
+
*
|
|
203
|
+
* <p>
|
|
204
|
+
* Because bitwise ops clear this out-of-band data, these arrays can be passed
|
|
205
|
+
* to ciphers like AES which want arrays of words.
|
|
206
|
+
* </p>
|
|
207
|
+
*/
|
|
208
|
+
const bitArray = {
|
|
209
|
+
/**
|
|
210
|
+
* Concatenate two bit arrays.
|
|
211
|
+
* @param {bitArray} a1 The first array.
|
|
212
|
+
* @param {bitArray} a2 The second array.
|
|
213
|
+
* @return {bitArray} The concatenation of a1 and a2.
|
|
214
|
+
*/
|
|
215
|
+
concat(a1, a2) {
|
|
216
|
+
if (a1.length === 0 || a2.length === 0) {
|
|
217
|
+
return a1.concat(a2);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const last = a1[a1.length - 1], shift = bitArray.getPartial(last);
|
|
221
|
+
if (shift === 32) {
|
|
222
|
+
return a1.concat(a2);
|
|
223
|
+
} else {
|
|
224
|
+
return bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Find the length of an array of bits.
|
|
230
|
+
* @param {bitArray} a The array.
|
|
231
|
+
* @return {Number} The length of a, in bits.
|
|
232
|
+
*/
|
|
233
|
+
bitLength(a) {
|
|
234
|
+
const l = a.length;
|
|
235
|
+
if (l === 0) {
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
const x = a[l - 1];
|
|
239
|
+
return (l - 1) * 32 + bitArray.getPartial(x);
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Truncate an array.
|
|
244
|
+
* @param {bitArray} a The array.
|
|
245
|
+
* @param {Number} len The length to truncate to, in bits.
|
|
246
|
+
* @return {bitArray} A new array, truncated to len bits.
|
|
247
|
+
*/
|
|
248
|
+
clamp(a, len) {
|
|
249
|
+
if (a.length * 32 < len) {
|
|
250
|
+
return a;
|
|
251
|
+
}
|
|
252
|
+
a = a.slice(0, Math.ceil(len / 32));
|
|
253
|
+
const l = a.length;
|
|
254
|
+
len = len & 31;
|
|
255
|
+
if (l > 0 && len) {
|
|
256
|
+
a[l - 1] = bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);
|
|
257
|
+
}
|
|
258
|
+
return a;
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Make a partial word for a bit array.
|
|
263
|
+
* @param {Number} len The number of bits in the word.
|
|
264
|
+
* @param {Number} x The bits.
|
|
265
|
+
* @param {Number} [_end=0] Pass 1 if x has already been shifted to the high side.
|
|
266
|
+
* @return {Number} The partial word.
|
|
267
|
+
*/
|
|
268
|
+
partial(len, x, _end) {
|
|
269
|
+
if (len === 32) {
|
|
270
|
+
return x;
|
|
271
|
+
}
|
|
272
|
+
return (_end ? x | 0 : x << (32 - len)) + len * 0x10000000000;
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Get the number of bits used by a partial word.
|
|
277
|
+
* @param {Number} x The partial word.
|
|
278
|
+
* @return {Number} The number of bits used by the partial word.
|
|
279
|
+
*/
|
|
280
|
+
getPartial(x) {
|
|
281
|
+
return Math.round(x / 0x10000000000) || 32;
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
/** Shift an array right.
|
|
285
|
+
* @param {bitArray} a The array to shift.
|
|
286
|
+
* @param {Number} shift The number of bits to shift.
|
|
287
|
+
* @param {Number} [carry=0] A byte to carry in
|
|
288
|
+
* @param {bitArray} [out=[]] An array to prepend to the output.
|
|
289
|
+
* @private
|
|
290
|
+
*/
|
|
291
|
+
_shiftRight(a, shift, carry, out) {
|
|
292
|
+
if (out === undefined) {
|
|
293
|
+
out = [];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
for (; shift >= 32; shift -= 32) {
|
|
297
|
+
out.push(carry);
|
|
298
|
+
carry = 0;
|
|
299
|
+
}
|
|
300
|
+
if (shift === 0) {
|
|
301
|
+
return out.concat(a);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
for (let i = 0; i < a.length; i++) {
|
|
305
|
+
out.push(carry | a[i] >>> shift);
|
|
306
|
+
carry = a[i] << (32 - shift);
|
|
307
|
+
}
|
|
308
|
+
const last2 = a.length ? a[a.length - 1] : 0;
|
|
309
|
+
const shift2 = bitArray.getPartial(last2);
|
|
310
|
+
out.push(bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));
|
|
311
|
+
return out;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/** @fileOverview Bit array codec implementations.
|
|
316
|
+
*
|
|
317
|
+
* @author Emily Stark
|
|
318
|
+
* @author Mike Hamburg
|
|
319
|
+
* @author Dan Boneh
|
|
320
|
+
*/
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Arrays of bytes
|
|
324
|
+
* @namespace
|
|
325
|
+
*/
|
|
326
|
+
const codec = {
|
|
327
|
+
bytes: {
|
|
328
|
+
/** Convert from a bitArray to an array of bytes. */
|
|
329
|
+
fromBits(arr) {
|
|
330
|
+
const bl = bitArray.bitLength(arr);
|
|
331
|
+
const byteLength = bl / 8;
|
|
332
|
+
const out = new Uint8Array(byteLength);
|
|
333
|
+
let tmp;
|
|
334
|
+
for (let i = 0; i < byteLength; i++) {
|
|
335
|
+
if ((i & 3) === 0) {
|
|
336
|
+
tmp = arr[i / 4];
|
|
337
|
+
}
|
|
338
|
+
out[i] = tmp >>> 24;
|
|
339
|
+
tmp <<= 8;
|
|
340
|
+
}
|
|
341
|
+
return out;
|
|
342
|
+
},
|
|
343
|
+
/** Convert from an array of bytes to a bitArray. */
|
|
344
|
+
toBits(bytes) {
|
|
345
|
+
const out = [];
|
|
346
|
+
let i;
|
|
347
|
+
let tmp = 0;
|
|
348
|
+
for (i = 0; i < bytes.length; i++) {
|
|
349
|
+
tmp = tmp << 8 | bytes[i];
|
|
350
|
+
if ((i & 3) === 3) {
|
|
351
|
+
out.push(tmp);
|
|
352
|
+
tmp = 0;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (i & 3) {
|
|
356
|
+
out.push(bitArray.partial(8 * (i & 3), tmp));
|
|
357
|
+
}
|
|
358
|
+
return out;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const hash = {};
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Context for a SHA-1 operation in progress.
|
|
367
|
+
* @constructor
|
|
368
|
+
*/
|
|
369
|
+
hash.sha1 = function (hash) {
|
|
370
|
+
if (hash) {
|
|
371
|
+
this._h = hash._h.slice(0);
|
|
372
|
+
this._buffer = hash._buffer.slice(0);
|
|
373
|
+
this._length = hash._length;
|
|
374
|
+
} else {
|
|
375
|
+
this.reset();
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
hash.sha1.prototype = {
|
|
380
|
+
/**
|
|
381
|
+
* The hash's block size, in bits.
|
|
382
|
+
* @constant
|
|
383
|
+
*/
|
|
384
|
+
blockSize: 512,
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Reset the hash state.
|
|
388
|
+
* @return this
|
|
389
|
+
*/
|
|
390
|
+
reset() {
|
|
391
|
+
const sha1 = this;
|
|
392
|
+
sha1._h = this._init.slice(0);
|
|
393
|
+
sha1._buffer = [];
|
|
394
|
+
sha1._length = 0;
|
|
395
|
+
return sha1;
|
|
396
|
+
},
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Input several words to the hash.
|
|
400
|
+
* @param {bitArray|String} data the data to hash.
|
|
401
|
+
* @return this
|
|
402
|
+
*/
|
|
403
|
+
update(data) {
|
|
404
|
+
const sha1 = this;
|
|
405
|
+
if (typeof data === "string") {
|
|
406
|
+
data = codec.utf8String.toBits(data);
|
|
407
|
+
}
|
|
408
|
+
const b = sha1._buffer = bitArray.concat(sha1._buffer, data);
|
|
409
|
+
const ol = sha1._length;
|
|
410
|
+
const nl = sha1._length = ol + bitArray.bitLength(data);
|
|
411
|
+
if (nl > 9007199254740991) {
|
|
412
|
+
throw new Error("Cannot hash more than 2^53 - 1 bits");
|
|
413
|
+
}
|
|
414
|
+
const c = new Uint32Array(b);
|
|
415
|
+
let j = 0;
|
|
416
|
+
for (let i = sha1.blockSize + ol - ((sha1.blockSize + ol) & (sha1.blockSize - 1)); i <= nl;
|
|
417
|
+
i += sha1.blockSize) {
|
|
418
|
+
sha1._block(c.subarray(16 * j, 16 * (j + 1)));
|
|
419
|
+
j += 1;
|
|
420
|
+
}
|
|
421
|
+
b.splice(0, 16 * j);
|
|
422
|
+
return sha1;
|
|
423
|
+
},
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Complete hashing and output the hash value.
|
|
427
|
+
* @return {bitArray} The hash value, an array of 5 big-endian words. TODO
|
|
428
|
+
*/
|
|
429
|
+
finalize() {
|
|
430
|
+
const sha1 = this;
|
|
431
|
+
let b = sha1._buffer;
|
|
432
|
+
const h = sha1._h;
|
|
433
|
+
|
|
434
|
+
// Round out and push the buffer
|
|
435
|
+
b = bitArray.concat(b, [bitArray.partial(1, 1)]);
|
|
436
|
+
// Round out the buffer to a multiple of 16 words, less the 2 length words.
|
|
437
|
+
for (let i = b.length + 2; i & 15; i++) {
|
|
438
|
+
b.push(0);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// append the length
|
|
442
|
+
b.push(Math.floor(sha1._length / 0x100000000));
|
|
443
|
+
b.push(sha1._length | 0);
|
|
444
|
+
|
|
445
|
+
while (b.length) {
|
|
446
|
+
sha1._block(b.splice(0, 16));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
sha1.reset();
|
|
450
|
+
return h;
|
|
451
|
+
},
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* The SHA-1 initialization vector.
|
|
455
|
+
* @private
|
|
456
|
+
*/
|
|
457
|
+
_init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* The SHA-1 hash key.
|
|
461
|
+
* @private
|
|
462
|
+
*/
|
|
463
|
+
_key: [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6],
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* The SHA-1 logical functions f(0), f(1), ..., f(79).
|
|
467
|
+
* @private
|
|
468
|
+
*/
|
|
469
|
+
_f(t, b, c, d) {
|
|
470
|
+
if (t <= 19) {
|
|
471
|
+
return (b & c) | (~b & d);
|
|
472
|
+
} else if (t <= 39) {
|
|
473
|
+
return b ^ c ^ d;
|
|
474
|
+
} else if (t <= 59) {
|
|
475
|
+
return (b & c) | (b & d) | (c & d);
|
|
476
|
+
} else if (t <= 79) {
|
|
477
|
+
return b ^ c ^ d;
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Circular left-shift operator.
|
|
483
|
+
* @private
|
|
484
|
+
*/
|
|
485
|
+
_S(n, x) {
|
|
486
|
+
return (x << n) | (x >>> 32 - n);
|
|
487
|
+
},
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Perform one cycle of SHA-1.
|
|
491
|
+
* @param {Uint32Array|bitArray} words one block of words.
|
|
492
|
+
* @private
|
|
493
|
+
*/
|
|
494
|
+
_block(words) {
|
|
495
|
+
const sha1 = this;
|
|
496
|
+
const h = sha1._h;
|
|
497
|
+
// When words is passed to _block, it has 16 elements. SHA1 _block
|
|
498
|
+
// function extends words with new elements (at the end there are 80 elements).
|
|
499
|
+
// The problem is that if we use Uint32Array instead of Array,
|
|
500
|
+
// the length of Uint32Array cannot be changed. Thus, we replace words with a
|
|
501
|
+
// normal Array here.
|
|
502
|
+
const w = Array(80); // do not use Uint32Array here as the instantiation is slower
|
|
503
|
+
for (let j = 0; j < 16; j++) {
|
|
504
|
+
w[j] = words[j];
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
let a = h[0];
|
|
508
|
+
let b = h[1];
|
|
509
|
+
let c = h[2];
|
|
510
|
+
let d = h[3];
|
|
511
|
+
let e = h[4];
|
|
512
|
+
|
|
513
|
+
for (let t = 0; t <= 79; t++) {
|
|
514
|
+
if (t >= 16) {
|
|
515
|
+
w[t] = sha1._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
|
|
516
|
+
}
|
|
517
|
+
const tmp = (sha1._S(5, a) + sha1._f(t, b, c, d) + e + w[t] +
|
|
518
|
+
sha1._key[Math.floor(t / 20)]) | 0;
|
|
519
|
+
e = d;
|
|
520
|
+
d = c;
|
|
521
|
+
c = sha1._S(30, b);
|
|
522
|
+
b = a;
|
|
523
|
+
a = tmp;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
h[0] = (h[0] + a) | 0;
|
|
527
|
+
h[1] = (h[1] + b) | 0;
|
|
528
|
+
h[2] = (h[2] + c) | 0;
|
|
529
|
+
h[3] = (h[3] + d) | 0;
|
|
530
|
+
h[4] = (h[4] + e) | 0;
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
/** @fileOverview Low-level AES implementation.
|
|
535
|
+
*
|
|
536
|
+
* This file contains a low-level implementation of AES, optimized for
|
|
537
|
+
* size and for efficiency on several browsers. It is based on
|
|
538
|
+
* OpenSSL's aes_core.c, a public-domain implementation by Vincent
|
|
539
|
+
* Rijmen, Antoon Bosselaers and Paulo Barreto.
|
|
540
|
+
*
|
|
541
|
+
* An older version of this implementation is available in the public
|
|
542
|
+
* domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,
|
|
543
|
+
* Stanford University 2008-2010 and BSD-licensed for liability
|
|
544
|
+
* reasons.
|
|
545
|
+
*
|
|
546
|
+
* @author Emily Stark
|
|
547
|
+
* @author Mike Hamburg
|
|
548
|
+
* @author Dan Boneh
|
|
549
|
+
*/
|
|
550
|
+
|
|
551
|
+
const cipher = {};
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Schedule out an AES key for both encryption and decryption. This
|
|
555
|
+
* is a low-level class. Use a cipher mode to do bulk encryption.
|
|
556
|
+
*
|
|
557
|
+
* @constructor
|
|
558
|
+
* @param {Array} key The key as an array of 4, 6 or 8 words.
|
|
559
|
+
*/
|
|
560
|
+
cipher.aes = class {
|
|
561
|
+
constructor(key) {
|
|
562
|
+
/**
|
|
563
|
+
* The expanded S-box and inverse S-box tables. These will be computed
|
|
564
|
+
* on the client so that we don't have to send them down the wire.
|
|
565
|
+
*
|
|
566
|
+
* There are two tables, _tables[0] is for encryption and
|
|
567
|
+
* _tables[1] is for decryption.
|
|
568
|
+
*
|
|
569
|
+
* The first 4 sub-tables are the expanded S-box with MixColumns. The
|
|
570
|
+
* last (_tables[01][4]) is the S-box itself.
|
|
571
|
+
*
|
|
572
|
+
* @private
|
|
573
|
+
*/
|
|
574
|
+
const aes = this;
|
|
575
|
+
aes._tables = [[[], [], [], [], []], [[], [], [], [], []]];
|
|
576
|
+
|
|
577
|
+
if (!aes._tables[0][0][0]) {
|
|
578
|
+
aes._precompute();
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const sbox = aes._tables[0][4];
|
|
582
|
+
const decTable = aes._tables[1];
|
|
583
|
+
const keyLen = key.length;
|
|
584
|
+
|
|
585
|
+
let i, encKey, decKey, rcon = 1;
|
|
586
|
+
|
|
587
|
+
if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
|
|
588
|
+
throw new Error("invalid aes key size");
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
aes._key = [encKey = key.slice(0), decKey = []];
|
|
592
|
+
|
|
593
|
+
// schedule encryption keys
|
|
594
|
+
for (i = keyLen; i < 4 * keyLen + 28; i++) {
|
|
595
|
+
let tmp = encKey[i - 1];
|
|
596
|
+
|
|
597
|
+
// apply sbox
|
|
598
|
+
if (i % keyLen === 0 || (keyLen === 8 && i % keyLen === 4)) {
|
|
599
|
+
tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
|
|
600
|
+
|
|
601
|
+
// shift rows and add rcon
|
|
602
|
+
if (i % keyLen === 0) {
|
|
603
|
+
tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
|
|
604
|
+
rcon = rcon << 1 ^ (rcon >> 7) * 283;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
encKey[i] = encKey[i - keyLen] ^ tmp;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// schedule decryption keys
|
|
612
|
+
for (let j = 0; i; j++, i--) {
|
|
613
|
+
const tmp = encKey[j & 3 ? i : i - 4];
|
|
614
|
+
if (i <= 4 || j < 4) {
|
|
615
|
+
decKey[j] = tmp;
|
|
616
|
+
} else {
|
|
617
|
+
decKey[j] = decTable[0][sbox[tmp >>> 24]] ^
|
|
618
|
+
decTable[1][sbox[tmp >> 16 & 255]] ^
|
|
619
|
+
decTable[2][sbox[tmp >> 8 & 255]] ^
|
|
620
|
+
decTable[3][sbox[tmp & 255]];
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
// public
|
|
625
|
+
/* Something like this might appear here eventually
|
|
626
|
+
name: "AES",
|
|
627
|
+
blockSize: 4,
|
|
628
|
+
keySizes: [4,6,8],
|
|
629
|
+
*/
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Encrypt an array of 4 big-endian words.
|
|
633
|
+
* @param {Array} data The plaintext.
|
|
634
|
+
* @return {Array} The ciphertext.
|
|
635
|
+
*/
|
|
636
|
+
encrypt(data) {
|
|
637
|
+
return this._crypt(data, 0);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Decrypt an array of 4 big-endian words.
|
|
642
|
+
* @param {Array} data The ciphertext.
|
|
643
|
+
* @return {Array} The plaintext.
|
|
644
|
+
*/
|
|
645
|
+
decrypt(data) {
|
|
646
|
+
return this._crypt(data, 1);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Expand the S-box tables.
|
|
651
|
+
*
|
|
652
|
+
* @private
|
|
653
|
+
*/
|
|
654
|
+
_precompute() {
|
|
655
|
+
const encTable = this._tables[0];
|
|
656
|
+
const decTable = this._tables[1];
|
|
657
|
+
const sbox = encTable[4];
|
|
658
|
+
const sboxInv = decTable[4];
|
|
659
|
+
const d = [];
|
|
660
|
+
const th = [];
|
|
661
|
+
let xInv, x2, x4, x8;
|
|
662
|
+
|
|
663
|
+
// Compute double and third tables
|
|
664
|
+
for (let i = 0; i < 256; i++) {
|
|
665
|
+
th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
for (let x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
|
|
669
|
+
// Compute sbox
|
|
670
|
+
let s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
|
|
671
|
+
s = s >> 8 ^ s & 255 ^ 99;
|
|
672
|
+
sbox[x] = s;
|
|
673
|
+
sboxInv[s] = x;
|
|
674
|
+
|
|
675
|
+
// Compute MixColumns
|
|
676
|
+
x8 = d[x4 = d[x2 = d[x]]];
|
|
677
|
+
let tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
|
|
678
|
+
let tEnc = d[s] * 0x101 ^ s * 0x1010100;
|
|
679
|
+
|
|
680
|
+
for (let i = 0; i < 4; i++) {
|
|
681
|
+
encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
|
|
682
|
+
decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// Compactify. Considerable speedup on Firefox.
|
|
687
|
+
for (let i = 0; i < 5; i++) {
|
|
688
|
+
encTable[i] = encTable[i].slice(0);
|
|
689
|
+
decTable[i] = decTable[i].slice(0);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Encryption and decryption core.
|
|
695
|
+
* @param {Array} input Four words to be encrypted or decrypted.
|
|
696
|
+
* @param dir The direction, 0 for encrypt and 1 for decrypt.
|
|
697
|
+
* @return {Array} The four encrypted or decrypted words.
|
|
698
|
+
* @private
|
|
699
|
+
*/
|
|
700
|
+
_crypt(input, dir) {
|
|
701
|
+
if (input.length !== 4) {
|
|
702
|
+
throw new Error("invalid aes block size");
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
const key = this._key[dir];
|
|
706
|
+
|
|
707
|
+
const nInnerRounds = key.length / 4 - 2;
|
|
708
|
+
const out = [0, 0, 0, 0];
|
|
709
|
+
const table = this._tables[dir];
|
|
710
|
+
|
|
711
|
+
// load up the tables
|
|
712
|
+
const t0 = table[0];
|
|
713
|
+
const t1 = table[1];
|
|
714
|
+
const t2 = table[2];
|
|
715
|
+
const t3 = table[3];
|
|
716
|
+
const sbox = table[4];
|
|
717
|
+
|
|
718
|
+
// state variables a,b,c,d are loaded with pre-whitened data
|
|
719
|
+
let a = input[0] ^ key[0];
|
|
720
|
+
let b = input[dir ? 3 : 1] ^ key[1];
|
|
721
|
+
let c = input[2] ^ key[2];
|
|
722
|
+
let d = input[dir ? 1 : 3] ^ key[3];
|
|
723
|
+
let kIndex = 4;
|
|
724
|
+
let a2, b2, c2;
|
|
725
|
+
|
|
726
|
+
// Inner rounds. Cribbed from OpenSSL.
|
|
727
|
+
for (let i = 0; i < nInnerRounds; i++) {
|
|
728
|
+
a2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];
|
|
729
|
+
b2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];
|
|
730
|
+
c2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];
|
|
731
|
+
d = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];
|
|
732
|
+
kIndex += 4;
|
|
733
|
+
a = a2; b = b2; c = c2;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Last round.
|
|
737
|
+
for (let i = 0; i < 4; i++) {
|
|
738
|
+
out[dir ? 3 & -i : i] =
|
|
739
|
+
sbox[a >>> 24] << 24 ^
|
|
740
|
+
sbox[b >> 16 & 255] << 16 ^
|
|
741
|
+
sbox[c >> 8 & 255] << 8 ^
|
|
742
|
+
sbox[d & 255] ^
|
|
743
|
+
key[kIndex++];
|
|
744
|
+
a2 = a; a = b; b = c; c = d; d = a2;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
return out;
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Random values
|
|
753
|
+
* @namespace
|
|
754
|
+
*/
|
|
755
|
+
const random = {
|
|
756
|
+
/**
|
|
757
|
+
* Generate random words with pure js, cryptographically not as strong & safe as native implementation.
|
|
758
|
+
* @param {TypedArray} typedArray The array to fill.
|
|
759
|
+
* @return {TypedArray} The random values.
|
|
760
|
+
*/
|
|
761
|
+
getRandomValues(typedArray) {
|
|
762
|
+
const words = new Uint32Array(typedArray.buffer);
|
|
763
|
+
const r = (m_w) => {
|
|
764
|
+
let m_z = 0x3ade68b1;
|
|
765
|
+
const mask = 0xffffffff;
|
|
766
|
+
return function () {
|
|
767
|
+
m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
|
|
768
|
+
m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
|
|
769
|
+
const result = ((((m_z << 0x10) + m_w) & mask) / 0x100000000) + .5;
|
|
770
|
+
return result * (Math.random() > .5 ? 1 : -1);
|
|
771
|
+
};
|
|
772
|
+
};
|
|
773
|
+
for (let i = 0, rcache; i < typedArray.length; i += 4) {
|
|
774
|
+
const _r = r((rcache || Math.random()) * 0x100000000);
|
|
775
|
+
rcache = _r() * 0x3ade67b7;
|
|
776
|
+
words[i / 4] = (_r() * 0x100000000) | 0;
|
|
777
|
+
}
|
|
778
|
+
return typedArray;
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
/** @fileOverview CTR mode implementation.
|
|
783
|
+
*
|
|
784
|
+
* Special thanks to Roy Nicholson for pointing out a bug in our
|
|
785
|
+
* implementation.
|
|
786
|
+
*
|
|
787
|
+
* @author Emily Stark
|
|
788
|
+
* @author Mike Hamburg
|
|
789
|
+
* @author Dan Boneh
|
|
790
|
+
*/
|
|
791
|
+
|
|
792
|
+
/** Brian Gladman's CTR Mode.
|
|
793
|
+
* @constructor
|
|
794
|
+
* @param {Object} _prf The aes instance to generate key.
|
|
795
|
+
* @param {bitArray} _iv The iv for ctr mode, it must be 128 bits.
|
|
796
|
+
*/
|
|
797
|
+
|
|
798
|
+
const mode = {};
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Brian Gladman's CTR Mode.
|
|
802
|
+
* @namespace
|
|
803
|
+
*/
|
|
804
|
+
mode.ctrGladman = class {
|
|
805
|
+
constructor(prf, iv) {
|
|
806
|
+
this._prf = prf;
|
|
807
|
+
this._initIv = iv;
|
|
808
|
+
this._iv = iv;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
reset() {
|
|
812
|
+
this._iv = this._initIv;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/** Input some data to calculate.
|
|
816
|
+
* @param {bitArray} data the data to process, it must be intergral multiple of 128 bits unless it's the last.
|
|
817
|
+
*/
|
|
818
|
+
update(data) {
|
|
819
|
+
return this.calculate(this._prf, data, this._iv);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
incWord(word) {
|
|
823
|
+
if (((word >> 24) & 0xff) === 0xff) { //overflow
|
|
824
|
+
let b1 = (word >> 16) & 0xff;
|
|
825
|
+
let b2 = (word >> 8) & 0xff;
|
|
826
|
+
let b3 = word & 0xff;
|
|
827
|
+
|
|
828
|
+
if (b1 === 0xff) { // overflow b1
|
|
829
|
+
b1 = 0;
|
|
830
|
+
if (b2 === 0xff) {
|
|
831
|
+
b2 = 0;
|
|
832
|
+
if (b3 === 0xff) {
|
|
833
|
+
b3 = 0;
|
|
834
|
+
} else {
|
|
835
|
+
++b3;
|
|
836
|
+
}
|
|
837
|
+
} else {
|
|
838
|
+
++b2;
|
|
839
|
+
}
|
|
840
|
+
} else {
|
|
841
|
+
++b1;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
word = 0;
|
|
845
|
+
word += (b1 << 16);
|
|
846
|
+
word += (b2 << 8);
|
|
847
|
+
word += b3;
|
|
848
|
+
} else {
|
|
849
|
+
word += (0x01 << 24);
|
|
850
|
+
}
|
|
851
|
+
return word;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
incCounter(counter) {
|
|
855
|
+
if ((counter[0] = this.incWord(counter[0])) === 0) {
|
|
856
|
+
// encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
|
|
857
|
+
counter[1] = this.incWord(counter[1]);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
calculate(prf, data, iv) {
|
|
862
|
+
let l;
|
|
863
|
+
if (!(l = data.length)) {
|
|
864
|
+
return [];
|
|
865
|
+
}
|
|
866
|
+
const bl = bitArray.bitLength(data);
|
|
867
|
+
for (let i = 0; i < l; i += 4) {
|
|
868
|
+
this.incCounter(iv);
|
|
869
|
+
const e = prf.encrypt(iv);
|
|
870
|
+
data[i] ^= e[0];
|
|
871
|
+
data[i + 1] ^= e[1];
|
|
872
|
+
data[i + 2] ^= e[2];
|
|
873
|
+
data[i + 3] ^= e[3];
|
|
874
|
+
}
|
|
875
|
+
return bitArray.clamp(data, bl);
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
const misc = {
|
|
880
|
+
importKey(password) {
|
|
881
|
+
return new misc.hmacSha1(codec.bytes.toBits(password));
|
|
882
|
+
},
|
|
883
|
+
pbkdf2(prf, salt, count, length) {
|
|
884
|
+
count = count || 10000;
|
|
885
|
+
if (length < 0 || count < 0) {
|
|
886
|
+
throw new Error("invalid params to pbkdf2");
|
|
887
|
+
}
|
|
888
|
+
const byteLength = ((length >> 5) + 1) << 2;
|
|
889
|
+
let u, ui, i, j, k;
|
|
890
|
+
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
891
|
+
const out = new DataView(arrayBuffer);
|
|
892
|
+
let outLength = 0;
|
|
893
|
+
const b = bitArray;
|
|
894
|
+
salt = codec.bytes.toBits(salt);
|
|
895
|
+
for (k = 1; outLength < (byteLength || 1); k++) {
|
|
896
|
+
u = ui = prf.encrypt(b.concat(salt, [k]));
|
|
897
|
+
for (i = 1; i < count; i++) {
|
|
898
|
+
ui = prf.encrypt(ui);
|
|
899
|
+
for (j = 0; j < ui.length; j++) {
|
|
900
|
+
u[j] ^= ui[j];
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
for (i = 0; outLength < (byteLength || 1) && i < u.length; i++) {
|
|
904
|
+
out.setInt32(outLength, u[i]);
|
|
905
|
+
outLength += 4;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return arrayBuffer.slice(0, length / 8);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
/** @fileOverview HMAC implementation.
|
|
913
|
+
*
|
|
914
|
+
* @author Emily Stark
|
|
915
|
+
* @author Mike Hamburg
|
|
916
|
+
* @author Dan Boneh
|
|
917
|
+
*/
|
|
918
|
+
|
|
919
|
+
/** HMAC with the specified hash function.
|
|
920
|
+
* @constructor
|
|
921
|
+
* @param {bitArray} key the key for HMAC.
|
|
922
|
+
* @param {Object} [Hash=hash.sha1] The hash function to use.
|
|
923
|
+
*/
|
|
924
|
+
misc.hmacSha1 = class {
|
|
925
|
+
|
|
926
|
+
constructor(key) {
|
|
927
|
+
const hmac = this;
|
|
928
|
+
const Hash = hmac._hash = hash.sha1;
|
|
929
|
+
const exKey = [[], []];
|
|
930
|
+
const bs = Hash.prototype.blockSize / 32;
|
|
931
|
+
hmac._baseHash = [new Hash(), new Hash()];
|
|
932
|
+
|
|
933
|
+
if (key.length > bs) {
|
|
934
|
+
key = Hash.hash(key);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
for (let i = 0; i < bs; i++) {
|
|
938
|
+
exKey[0][i] = key[i] ^ 0x36363636;
|
|
939
|
+
exKey[1][i] = key[i] ^ 0x5C5C5C5C;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
hmac._baseHash[0].update(exKey[0]);
|
|
943
|
+
hmac._baseHash[1].update(exKey[1]);
|
|
944
|
+
hmac._resultHash = new Hash(hmac._baseHash[0]);
|
|
945
|
+
}
|
|
946
|
+
reset() {
|
|
947
|
+
const hmac = this;
|
|
948
|
+
hmac._resultHash = new hmac._hash(hmac._baseHash[0]);
|
|
949
|
+
hmac._updated = false;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
update(data) {
|
|
953
|
+
const hmac = this;
|
|
954
|
+
hmac._updated = true;
|
|
955
|
+
hmac._resultHash.update(data);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
digest() {
|
|
959
|
+
const hmac = this;
|
|
960
|
+
const w = hmac._resultHash.finalize();
|
|
961
|
+
const result = new (hmac._hash)(hmac._baseHash[1]).update(w).finalize();
|
|
962
|
+
|
|
963
|
+
hmac.reset();
|
|
964
|
+
|
|
965
|
+
return result;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
encrypt(data) {
|
|
969
|
+
if (!this._updated) {
|
|
970
|
+
this.update(data);
|
|
971
|
+
return this.digest(data);
|
|
972
|
+
} else {
|
|
973
|
+
throw new Error("encrypt on already updated hmac called!");
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
/*
|
|
979
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
980
|
+
|
|
981
|
+
Redistribution and use in source and binary forms, with or without
|
|
982
|
+
modification, are permitted provided that the following conditions are met:
|
|
983
|
+
|
|
984
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
985
|
+
this list of conditions and the following disclaimer.
|
|
986
|
+
|
|
987
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
988
|
+
notice, this list of conditions and the following disclaimer in
|
|
989
|
+
the documentation and/or other materials provided with the distribution.
|
|
990
|
+
|
|
991
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
992
|
+
derived from this software without specific prior written permission.
|
|
993
|
+
|
|
994
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
995
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
996
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
997
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
998
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
999
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1000
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1001
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1002
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1003
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1004
|
+
*/
|
|
1005
|
+
|
|
1006
|
+
/* global crypto */
|
|
1007
|
+
|
|
1008
|
+
const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != "undefined" && typeof crypto.getRandomValues == "function";
|
|
1009
|
+
|
|
1010
|
+
const ERR_INVALID_PASSWORD = "Invalid password";
|
|
1011
|
+
const ERR_INVALID_SIGNATURE = "Invalid signature";
|
|
1012
|
+
|
|
1013
|
+
function getRandomValues(array) {
|
|
1014
|
+
if (GET_RANDOM_VALUES_SUPPORTED) {
|
|
1015
|
+
return crypto.getRandomValues(array);
|
|
1016
|
+
} else {
|
|
1017
|
+
return random.getRandomValues(array);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/*
|
|
1022
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1023
|
+
|
|
1024
|
+
Redistribution and use in source and binary forms, with or without
|
|
1025
|
+
modification, are permitted provided that the following conditions are met:
|
|
1026
|
+
|
|
1027
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1028
|
+
this list of conditions and the following disclaimer.
|
|
1029
|
+
|
|
1030
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1031
|
+
notice, this list of conditions and the following disclaimer in
|
|
1032
|
+
the documentation and/or other materials provided with the distribution.
|
|
1033
|
+
|
|
1034
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1035
|
+
derived from this software without specific prior written permission.
|
|
1036
|
+
|
|
1037
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1038
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1039
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1040
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1041
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1042
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1043
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1044
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1045
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1046
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1047
|
+
*/
|
|
1048
|
+
|
|
1049
|
+
const BLOCK_LENGTH = 16;
|
|
1050
|
+
const RAW_FORMAT = "raw";
|
|
1051
|
+
const PBKDF2_ALGORITHM = { name: "PBKDF2" };
|
|
1052
|
+
const HASH_ALGORITHM = { name: "HMAC" };
|
|
1053
|
+
const HASH_FUNCTION = "SHA-1";
|
|
1054
|
+
const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
|
|
1055
|
+
const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
|
|
1056
|
+
const DERIVED_BITS_USAGE = ["deriveBits"];
|
|
1057
|
+
const SALT_LENGTH = [8, 12, 16];
|
|
1058
|
+
const KEY_LENGTH = [16, 24, 32];
|
|
1059
|
+
const SIGNATURE_LENGTH = 10;
|
|
1060
|
+
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
1061
|
+
const UNDEFINED_TYPE = "undefined";
|
|
1062
|
+
const FUNCTION_TYPE = "function";
|
|
1063
|
+
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
|
|
1064
|
+
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
1065
|
+
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE;
|
|
1066
|
+
const IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
|
|
1067
|
+
const DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
|
|
1068
|
+
const codecBytes = codec.bytes;
|
|
1069
|
+
const Aes = cipher.aes;
|
|
1070
|
+
const CtrGladman = mode.ctrGladman;
|
|
1071
|
+
const HmacSha1 = misc.hmacSha1;
|
|
1072
|
+
|
|
1073
|
+
class AESDecryptionStream extends TransformStream {
|
|
1074
|
+
|
|
1075
|
+
constructor(password, signed, strength) {
|
|
1076
|
+
super({
|
|
1077
|
+
start() {
|
|
1078
|
+
Object.assign(this, {
|
|
1079
|
+
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
1080
|
+
password,
|
|
1081
|
+
signed,
|
|
1082
|
+
strength: strength - 1,
|
|
1083
|
+
pending: new Uint8Array()
|
|
1084
|
+
});
|
|
1085
|
+
},
|
|
1086
|
+
async transform(chunk, controller) {
|
|
1087
|
+
const aesCrypto = this;
|
|
1088
|
+
const {
|
|
1089
|
+
password,
|
|
1090
|
+
strength,
|
|
1091
|
+
resolveReady,
|
|
1092
|
+
ready
|
|
1093
|
+
} = aesCrypto;
|
|
1094
|
+
if (password) {
|
|
1095
|
+
await createDecryptionKeys(aesCrypto, strength, password, subarray(chunk, 0, SALT_LENGTH[strength] + 2));
|
|
1096
|
+
chunk = subarray(chunk, SALT_LENGTH[strength] + 2);
|
|
1097
|
+
resolveReady();
|
|
1098
|
+
} else {
|
|
1099
|
+
await ready;
|
|
1100
|
+
}
|
|
1101
|
+
const output = new Uint8Array(chunk.length - SIGNATURE_LENGTH - ((chunk.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
|
|
1102
|
+
controller.enqueue(append(aesCrypto, chunk, output, 0, SIGNATURE_LENGTH, true));
|
|
1103
|
+
},
|
|
1104
|
+
async flush(controller) {
|
|
1105
|
+
const {
|
|
1106
|
+
signed,
|
|
1107
|
+
ctr,
|
|
1108
|
+
hmac,
|
|
1109
|
+
pending,
|
|
1110
|
+
ready
|
|
1111
|
+
} = this;
|
|
1112
|
+
await ready;
|
|
1113
|
+
const chunkToDecrypt = subarray(pending, 0, pending.length - SIGNATURE_LENGTH);
|
|
1114
|
+
const originalSignature = subarray(pending, pending.length - SIGNATURE_LENGTH);
|
|
1115
|
+
let decryptedChunkArray = new Uint8Array();
|
|
1116
|
+
if (chunkToDecrypt.length) {
|
|
1117
|
+
const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
|
|
1118
|
+
hmac.update(encryptedChunk);
|
|
1119
|
+
const decryptedChunk = ctr.update(encryptedChunk);
|
|
1120
|
+
decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
|
|
1121
|
+
}
|
|
1122
|
+
if (signed) {
|
|
1123
|
+
const signature = subarray(fromBits(codecBytes, hmac.digest()), 0, SIGNATURE_LENGTH);
|
|
1124
|
+
for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
|
|
1125
|
+
if (signature[indexSignature] != originalSignature[indexSignature]) {
|
|
1126
|
+
throw new Error(ERR_INVALID_SIGNATURE);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
controller.enqueue(decryptedChunkArray);
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
class AESEncryptionStream extends TransformStream {
|
|
1137
|
+
|
|
1138
|
+
constructor(password, strength) {
|
|
1139
|
+
let stream;
|
|
1140
|
+
super({
|
|
1141
|
+
start() {
|
|
1142
|
+
Object.assign(this, {
|
|
1143
|
+
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
1144
|
+
password,
|
|
1145
|
+
strength: strength - 1,
|
|
1146
|
+
pending: new Uint8Array()
|
|
1147
|
+
});
|
|
1148
|
+
},
|
|
1149
|
+
async transform(chunk, controller) {
|
|
1150
|
+
const aesCrypto = this;
|
|
1151
|
+
const {
|
|
1152
|
+
password,
|
|
1153
|
+
strength,
|
|
1154
|
+
resolveReady,
|
|
1155
|
+
ready
|
|
1156
|
+
} = aesCrypto;
|
|
1157
|
+
let preamble = new Uint8Array();
|
|
1158
|
+
if (password) {
|
|
1159
|
+
preamble = await createEncryptionKeys(aesCrypto, strength, password);
|
|
1160
|
+
resolveReady();
|
|
1161
|
+
} else {
|
|
1162
|
+
await ready;
|
|
1163
|
+
}
|
|
1164
|
+
const output = new Uint8Array(preamble.length + chunk.length - (chunk.length % BLOCK_LENGTH));
|
|
1165
|
+
output.set(preamble, 0);
|
|
1166
|
+
controller.enqueue(append(aesCrypto, chunk, output, preamble.length, 0));
|
|
1167
|
+
},
|
|
1168
|
+
async flush(controller) {
|
|
1169
|
+
const {
|
|
1170
|
+
ctr,
|
|
1171
|
+
hmac,
|
|
1172
|
+
pending,
|
|
1173
|
+
ready
|
|
1174
|
+
} = this;
|
|
1175
|
+
await ready;
|
|
1176
|
+
let encryptedChunkArray = new Uint8Array();
|
|
1177
|
+
if (pending.length) {
|
|
1178
|
+
const encryptedChunk = ctr.update(toBits(codecBytes, pending));
|
|
1179
|
+
hmac.update(encryptedChunk);
|
|
1180
|
+
encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
|
|
1181
|
+
}
|
|
1182
|
+
stream.signature = fromBits(codecBytes, hmac.digest()).slice(0, SIGNATURE_LENGTH);
|
|
1183
|
+
controller.enqueue(concat(encryptedChunkArray, stream.signature));
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
stream = this;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {
|
|
1191
|
+
const {
|
|
1192
|
+
ctr,
|
|
1193
|
+
hmac,
|
|
1194
|
+
pending
|
|
1195
|
+
} = aesCrypto;
|
|
1196
|
+
const inputLength = input.length - paddingEnd;
|
|
1197
|
+
if (pending.length) {
|
|
1198
|
+
input = concat(pending, input);
|
|
1199
|
+
output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
|
|
1200
|
+
}
|
|
1201
|
+
let offset;
|
|
1202
|
+
for (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {
|
|
1203
|
+
const inputChunk = toBits(codecBytes, subarray(input, offset, offset + BLOCK_LENGTH));
|
|
1204
|
+
if (verifySignature) {
|
|
1205
|
+
hmac.update(inputChunk);
|
|
1206
|
+
}
|
|
1207
|
+
const outputChunk = ctr.update(inputChunk);
|
|
1208
|
+
if (!verifySignature) {
|
|
1209
|
+
hmac.update(outputChunk);
|
|
1210
|
+
}
|
|
1211
|
+
output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
|
|
1212
|
+
}
|
|
1213
|
+
aesCrypto.pending = subarray(input, offset);
|
|
1214
|
+
return output;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
async function createDecryptionKeys(decrypt, strength, password, preamble) {
|
|
1218
|
+
const passwordVerificationKey = await createKeys$1(decrypt, strength, password, subarray(preamble, 0, SALT_LENGTH[strength]));
|
|
1219
|
+
const passwordVerification = subarray(preamble, SALT_LENGTH[strength]);
|
|
1220
|
+
if (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {
|
|
1221
|
+
throw new Error(ERR_INVALID_PASSWORD);
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
async function createEncryptionKeys(encrypt, strength, password) {
|
|
1226
|
+
const salt = getRandomValues(new Uint8Array(SALT_LENGTH[strength]));
|
|
1227
|
+
const passwordVerification = await createKeys$1(encrypt, strength, password, salt);
|
|
1228
|
+
return concat(salt, passwordVerification);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
async function createKeys$1(aesCrypto, strength, password, salt) {
|
|
1232
|
+
aesCrypto.password = null;
|
|
1233
|
+
const encodedPassword = encodeText(password);
|
|
1234
|
+
const baseKey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
|
|
1235
|
+
const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), baseKey, 8 * ((KEY_LENGTH[strength] * 2) + 2));
|
|
1236
|
+
const compositeKey = new Uint8Array(derivedBits);
|
|
1237
|
+
const key = toBits(codecBytes, subarray(compositeKey, 0, KEY_LENGTH[strength]));
|
|
1238
|
+
const authentication = toBits(codecBytes, subarray(compositeKey, KEY_LENGTH[strength], KEY_LENGTH[strength] * 2));
|
|
1239
|
+
const passwordVerification = subarray(compositeKey, KEY_LENGTH[strength] * 2);
|
|
1240
|
+
Object.assign(aesCrypto, {
|
|
1241
|
+
keys: {
|
|
1242
|
+
key,
|
|
1243
|
+
authentication,
|
|
1244
|
+
passwordVerification
|
|
1245
|
+
},
|
|
1246
|
+
ctr: new CtrGladman(new Aes(key), Array.from(COUNTER_DEFAULT_VALUE)),
|
|
1247
|
+
hmac: new HmacSha1(authentication)
|
|
1248
|
+
});
|
|
1249
|
+
return passwordVerification;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
function importKey(format, password, algorithm, extractable, keyUsages) {
|
|
1253
|
+
if (IMPORT_KEY_SUPPORTED) {
|
|
1254
|
+
return subtle.importKey(format, password, algorithm, extractable, keyUsages);
|
|
1255
|
+
} else {
|
|
1256
|
+
return misc.importKey(password);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
async function deriveBits(algorithm, baseKey, length) {
|
|
1261
|
+
if (DERIVE_BITS_SUPPORTED) {
|
|
1262
|
+
return await subtle.deriveBits(algorithm, baseKey, length);
|
|
1263
|
+
} else {
|
|
1264
|
+
return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
function concat(leftArray, rightArray) {
|
|
1269
|
+
let array = leftArray;
|
|
1270
|
+
if (leftArray.length + rightArray.length) {
|
|
1271
|
+
array = new Uint8Array(leftArray.length + rightArray.length);
|
|
1272
|
+
array.set(leftArray, 0);
|
|
1273
|
+
array.set(rightArray, leftArray.length);
|
|
1274
|
+
}
|
|
1275
|
+
return array;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
function expand(inputArray, length) {
|
|
1279
|
+
if (length && length > inputArray.length) {
|
|
1280
|
+
const array = inputArray;
|
|
1281
|
+
inputArray = new Uint8Array(length);
|
|
1282
|
+
inputArray.set(array, 0);
|
|
1283
|
+
}
|
|
1284
|
+
return inputArray;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
function subarray(array, begin, end) {
|
|
1288
|
+
return array.subarray(begin, end);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
function fromBits(codecBytes, chunk) {
|
|
1292
|
+
return codecBytes.fromBits(chunk);
|
|
1293
|
+
}
|
|
1294
|
+
function toBits(codecBytes, chunk) {
|
|
1295
|
+
return codecBytes.toBits(chunk);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
/*
|
|
1299
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1300
|
+
|
|
1301
|
+
Redistribution and use in source and binary forms, with or without
|
|
1302
|
+
modification, are permitted provided that the following conditions are met:
|
|
1303
|
+
|
|
1304
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1305
|
+
this list of conditions and the following disclaimer.
|
|
1306
|
+
|
|
1307
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1308
|
+
notice, this list of conditions and the following disclaimer in
|
|
1309
|
+
the documentation and/or other materials provided with the distribution.
|
|
1310
|
+
|
|
1311
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1312
|
+
derived from this software without specific prior written permission.
|
|
1313
|
+
|
|
1314
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1315
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1316
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1317
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1318
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1319
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1320
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1321
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1322
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1323
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1324
|
+
*/
|
|
1325
|
+
|
|
1326
|
+
const HEADER_LENGTH = 12;
|
|
1327
|
+
|
|
1328
|
+
class ZipCryptoDecryptionStream extends TransformStream {
|
|
1329
|
+
|
|
1330
|
+
constructor(password, passwordVerification) {
|
|
1331
|
+
super({
|
|
1332
|
+
start() {
|
|
1333
|
+
Object.assign(this, {
|
|
1334
|
+
password,
|
|
1335
|
+
passwordVerification
|
|
1336
|
+
});
|
|
1337
|
+
createKeys(this, password);
|
|
1338
|
+
},
|
|
1339
|
+
transform(chunk, controller) {
|
|
1340
|
+
const zipCrypto = this;
|
|
1341
|
+
if (zipCrypto.password) {
|
|
1342
|
+
const decryptedHeader = decrypt(zipCrypto, chunk.subarray(0, HEADER_LENGTH));
|
|
1343
|
+
zipCrypto.password = null;
|
|
1344
|
+
if (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {
|
|
1345
|
+
throw new Error(ERR_INVALID_PASSWORD);
|
|
1346
|
+
}
|
|
1347
|
+
chunk = chunk.subarray(HEADER_LENGTH);
|
|
1348
|
+
}
|
|
1349
|
+
controller.enqueue(decrypt(zipCrypto, chunk));
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
class ZipCryptoEncryptionStream extends TransformStream {
|
|
1356
|
+
|
|
1357
|
+
constructor(password, passwordVerification) {
|
|
1358
|
+
super({
|
|
1359
|
+
start() {
|
|
1360
|
+
Object.assign(this, {
|
|
1361
|
+
password,
|
|
1362
|
+
passwordVerification
|
|
1363
|
+
});
|
|
1364
|
+
createKeys(this, password);
|
|
1365
|
+
},
|
|
1366
|
+
transform(chunk, controller) {
|
|
1367
|
+
const zipCrypto = this;
|
|
1368
|
+
let output;
|
|
1369
|
+
let offset;
|
|
1370
|
+
if (zipCrypto.password) {
|
|
1371
|
+
zipCrypto.password = null;
|
|
1372
|
+
const header = getRandomValues(new Uint8Array(HEADER_LENGTH));
|
|
1373
|
+
header[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;
|
|
1374
|
+
output = new Uint8Array(chunk.length + header.length);
|
|
1375
|
+
output.set(encrypt(zipCrypto, header), 0);
|
|
1376
|
+
offset = HEADER_LENGTH;
|
|
1377
|
+
} else {
|
|
1378
|
+
output = new Uint8Array(chunk.length);
|
|
1379
|
+
offset = 0;
|
|
1380
|
+
}
|
|
1381
|
+
output.set(encrypt(zipCrypto, chunk), offset);
|
|
1382
|
+
controller.enqueue(output);
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
function decrypt(target, input) {
|
|
1389
|
+
const output = new Uint8Array(input.length);
|
|
1390
|
+
for (let index = 0; index < input.length; index++) {
|
|
1391
|
+
output[index] = getByte(target) ^ input[index];
|
|
1392
|
+
updateKeys(target, output[index]);
|
|
1393
|
+
}
|
|
1394
|
+
return output;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
function encrypt(target, input) {
|
|
1398
|
+
const output = new Uint8Array(input.length);
|
|
1399
|
+
for (let index = 0; index < input.length; index++) {
|
|
1400
|
+
output[index] = getByte(target) ^ input[index];
|
|
1401
|
+
updateKeys(target, input[index]);
|
|
1402
|
+
}
|
|
1403
|
+
return output;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
function createKeys(target, password) {
|
|
1407
|
+
const keys = [0x12345678, 0x23456789, 0x34567890];
|
|
1408
|
+
Object.assign(target, {
|
|
1409
|
+
keys,
|
|
1410
|
+
crcKey0: new Crc32(keys[0]),
|
|
1411
|
+
crcKey2: new Crc32(keys[2]),
|
|
1412
|
+
});
|
|
1413
|
+
for (let index = 0; index < password.length; index++) {
|
|
1414
|
+
updateKeys(target, password.charCodeAt(index));
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function updateKeys(target, byte) {
|
|
1419
|
+
let [key0, key1, key2] = target.keys;
|
|
1420
|
+
target.crcKey0.append([byte]);
|
|
1421
|
+
key0 = ~target.crcKey0.get();
|
|
1422
|
+
key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
|
|
1423
|
+
target.crcKey2.append([key1 >>> 24]);
|
|
1424
|
+
key2 = ~target.crcKey2.get();
|
|
1425
|
+
target.keys = [key0, key1, key2];
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
function getByte(target) {
|
|
1429
|
+
const temp = target.keys[2] | 2;
|
|
1430
|
+
return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
function getInt8(number) {
|
|
1434
|
+
return number & 0xFF;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
function getInt32(number) {
|
|
1438
|
+
return number & 0xFFFFFFFF;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
/*
|
|
1442
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1443
|
+
|
|
1444
|
+
Redistribution and use in source and binary forms, with or without
|
|
1445
|
+
modification, are permitted provided that the following conditions are met:
|
|
1446
|
+
|
|
1447
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1448
|
+
this list of conditions and the following disclaimer.
|
|
1449
|
+
|
|
1450
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1451
|
+
notice, this list of conditions and the following disclaimer in
|
|
1452
|
+
the documentation and/or other materials provided with the distribution.
|
|
1453
|
+
|
|
1454
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1455
|
+
derived from this software without specific prior written permission.
|
|
1456
|
+
|
|
1457
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1458
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1459
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1460
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1461
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1462
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1463
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1464
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1465
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1466
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1467
|
+
*/
|
|
1468
|
+
|
|
1469
|
+
const COMPRESSION_FORMAT = "deflate-raw";
|
|
1470
|
+
|
|
1471
|
+
class DeflateStream extends TransformStream {
|
|
1472
|
+
|
|
1473
|
+
constructor(options, { chunkSize, CompressionStream, CompressionStreamNative }) {
|
|
1474
|
+
super({});
|
|
1475
|
+
const { compressed, encrypted, useCompressionStream, password, passwordVerification, encryptionStrength, zipCrypto, signed, level } = options;
|
|
1476
|
+
const stream = this;
|
|
1477
|
+
let crc32Stream, encryptionStream;
|
|
1478
|
+
let readable = filterEmptyChunks(super.readable);
|
|
1479
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
1480
|
+
[readable, crc32Stream] = readable.tee();
|
|
1481
|
+
crc32Stream = pipeThrough(crc32Stream, new Crc32Stream());
|
|
1482
|
+
}
|
|
1483
|
+
if (compressed) {
|
|
1484
|
+
readable = pipeThroughCommpressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStreamNative, CompressionStream);
|
|
1485
|
+
}
|
|
1486
|
+
if (encrypted) {
|
|
1487
|
+
if (zipCrypto) {
|
|
1488
|
+
readable = pipeThrough(readable, new ZipCryptoEncryptionStream(password, passwordVerification));
|
|
1489
|
+
} else {
|
|
1490
|
+
encryptionStream = new AESEncryptionStream(password, encryptionStrength);
|
|
1491
|
+
readable = pipeThrough(readable, encryptionStream);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
setReadable(stream, readable, async () => {
|
|
1495
|
+
let signature;
|
|
1496
|
+
if (encrypted && !zipCrypto) {
|
|
1497
|
+
signature = encryptionStream.signature;
|
|
1498
|
+
}
|
|
1499
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
1500
|
+
signature = await crc32Stream.getReader().read();
|
|
1501
|
+
signature = new DataView(signature.value.buffer).getUint32(0);
|
|
1502
|
+
}
|
|
1503
|
+
stream.signature = signature;
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
class InflateStream extends TransformStream {
|
|
1509
|
+
|
|
1510
|
+
constructor(options, { chunkSize, DecompressionStream, DecompressionStreamNative }) {
|
|
1511
|
+
super({});
|
|
1512
|
+
const { zipCrypto, encrypted, password, passwordVerification, signed, signature, encryptionStrength, compressed, useCompressionStream } = options;
|
|
1513
|
+
let crc32Stream, decryptionStream;
|
|
1514
|
+
let readable = filterEmptyChunks(super.readable);
|
|
1515
|
+
if (encrypted) {
|
|
1516
|
+
if (zipCrypto) {
|
|
1517
|
+
readable = pipeThrough(readable, new ZipCryptoDecryptionStream(password, passwordVerification));
|
|
1518
|
+
} else {
|
|
1519
|
+
decryptionStream = new AESDecryptionStream(password, signed, encryptionStrength);
|
|
1520
|
+
readable = pipeThrough(readable, decryptionStream);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
if (compressed) {
|
|
1524
|
+
readable = pipeThroughCommpressionStream(readable, useCompressionStream, { chunkSize }, DecompressionStreamNative, DecompressionStream);
|
|
1525
|
+
}
|
|
1526
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
1527
|
+
[readable, crc32Stream] = readable.tee();
|
|
1528
|
+
crc32Stream = pipeThrough(crc32Stream, new Crc32Stream());
|
|
1529
|
+
}
|
|
1530
|
+
setReadable(this, readable, async () => {
|
|
1531
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
1532
|
+
const streamSignature = await crc32Stream.getReader().read();
|
|
1533
|
+
const dataViewSignature = new DataView(streamSignature.value.buffer);
|
|
1534
|
+
if (signature != dataViewSignature.getUint32(0, false)) {
|
|
1535
|
+
throw new Error(ERR_INVALID_SIGNATURE);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
function filterEmptyChunks(readable) {
|
|
1543
|
+
return pipeThrough(readable, new TransformStream({
|
|
1544
|
+
transform(chunk, controller) {
|
|
1545
|
+
if (chunk && chunk.length) {
|
|
1546
|
+
controller.enqueue(chunk);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
}));
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
function setReadable(stream, readable, flush) {
|
|
1553
|
+
readable = pipeThrough(readable, new TransformStream({ flush }));
|
|
1554
|
+
Object.defineProperty(stream, "readable", {
|
|
1555
|
+
get() {
|
|
1556
|
+
return readable;
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
function pipeThroughCommpressionStream(readable, useCompressionStream, options, CodecStreamNative, CodecStream) {
|
|
1562
|
+
try {
|
|
1563
|
+
const CompressionStream = useCompressionStream && CodecStreamNative ? CodecStreamNative : CodecStream;
|
|
1564
|
+
readable = pipeThrough(readable, new CompressionStream(COMPRESSION_FORMAT, options));
|
|
1565
|
+
} catch (error) {
|
|
1566
|
+
if (useCompressionStream) {
|
|
1567
|
+
readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
|
|
1568
|
+
} else {
|
|
1569
|
+
throw error;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
return readable;
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
function pipeThrough(readable, transformStream) {
|
|
1576
|
+
return readable.pipeThrough(transformStream);
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
/*
|
|
1580
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1581
|
+
|
|
1582
|
+
Redistribution and use in source and binary forms, with or without
|
|
1583
|
+
modification, are permitted provided that the following conditions are met:
|
|
1584
|
+
|
|
1585
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1586
|
+
this list of conditions and the following disclaimer.
|
|
1587
|
+
|
|
1588
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1589
|
+
notice, this list of conditions and the following disclaimer in
|
|
1590
|
+
the documentation and/or other materials provided with the distribution.
|
|
1591
|
+
|
|
1592
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1593
|
+
derived from this software without specific prior written permission.
|
|
1594
|
+
|
|
1595
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1596
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1597
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1598
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1599
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1600
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1601
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1602
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1603
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1604
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1605
|
+
*/
|
|
1606
|
+
|
|
1607
|
+
/*
|
|
1608
|
+
* This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.
|
|
1609
|
+
* JZlib is based on zlib-1.1.3, so all credit should go authors
|
|
1610
|
+
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
|
1611
|
+
* and contributors of zlib.
|
|
1612
|
+
*/
|
|
1613
|
+
|
|
1614
|
+
/* global TransformStream */
|
|
1615
|
+
|
|
1616
|
+
class CodecStream extends TransformStream {
|
|
1617
|
+
|
|
1618
|
+
constructor(Codec, options) {
|
|
1619
|
+
const codec = new Codec(options);
|
|
1620
|
+
super({
|
|
1621
|
+
transform(chunk, controller) {
|
|
1622
|
+
controller.enqueue(codec.append(chunk));
|
|
1623
|
+
},
|
|
1624
|
+
flush(controller) {
|
|
1625
|
+
const chunk = codec.flush();
|
|
1626
|
+
if (chunk) {
|
|
1627
|
+
controller.enqueue(chunk);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/*
|
|
1635
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1636
|
+
|
|
1637
|
+
Redistribution and use in source and binary forms, with or without
|
|
1638
|
+
modification, are permitted provided that the following conditions are met:
|
|
1639
|
+
|
|
1640
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1641
|
+
this list of conditions and the following disclaimer.
|
|
1642
|
+
|
|
1643
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1644
|
+
notice, this list of conditions and the following disclaimer in
|
|
1645
|
+
the documentation and/or other materials provided with the distribution.
|
|
1646
|
+
|
|
1647
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1648
|
+
derived from this software without specific prior written permission.
|
|
1649
|
+
|
|
1650
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1651
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1652
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1653
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1654
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1655
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1656
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1657
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1658
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1659
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1660
|
+
*/
|
|
1661
|
+
|
|
1662
|
+
const CODEC_DEFLATE = "deflate";
|
|
1663
|
+
const CODEC_INFLATE = "inflate";
|
|
1664
|
+
const MESSAGE_EVENT_TYPE = "message";
|
|
1665
|
+
const MESSAGE_START = "start";
|
|
1666
|
+
const MESSAGE_PULL = "pull";
|
|
1667
|
+
const MESSAGE_DATA = "data";
|
|
1668
|
+
const MESSAGE_ACK_DATA = "ack";
|
|
1669
|
+
const MESSAGE_CLOSE = "close";
|
|
1670
|
+
|
|
1671
|
+
class Codec {
|
|
1672
|
+
|
|
1673
|
+
constructor(readable, writable, options, config) {
|
|
1674
|
+
const { codecType } = options;
|
|
1675
|
+
let CodecStream;
|
|
1676
|
+
if (codecType.startsWith(CODEC_DEFLATE)) {
|
|
1677
|
+
CodecStream = DeflateStream;
|
|
1678
|
+
} else if (codecType.startsWith(CODEC_INFLATE)) {
|
|
1679
|
+
CodecStream = InflateStream;
|
|
1680
|
+
}
|
|
1681
|
+
Object.assign(this, {
|
|
1682
|
+
CodecStream,
|
|
1683
|
+
readable,
|
|
1684
|
+
writable,
|
|
1685
|
+
options,
|
|
1686
|
+
config
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
async run() {
|
|
1691
|
+
const {
|
|
1692
|
+
CodecStream,
|
|
1693
|
+
readable,
|
|
1694
|
+
writable,
|
|
1695
|
+
options,
|
|
1696
|
+
config
|
|
1697
|
+
} = this;
|
|
1698
|
+
const stream = new CodecStream(options, config);
|
|
1699
|
+
let size = 0;
|
|
1700
|
+
await readable
|
|
1701
|
+
.pipeThrough(stream)
|
|
1702
|
+
.pipeThrough(new TransformStream({
|
|
1703
|
+
transform(chunk, controller) {
|
|
1704
|
+
if (chunk && chunk.length) {
|
|
1705
|
+
size += chunk.length;
|
|
1706
|
+
controller.enqueue(chunk);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}))
|
|
1710
|
+
.pipeTo(writable, { preventClose: true, preventAbort: true });
|
|
1711
|
+
const { signature } = stream;
|
|
1712
|
+
return { size, signature };
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
function getCodecStreamClass(Codec) {
|
|
1717
|
+
return class extends CodecStream {
|
|
1718
|
+
constructor(algorithm, options) {
|
|
1719
|
+
super(Codec, options);
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
/*
|
|
1725
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1726
|
+
|
|
1727
|
+
Redistribution and use in source and binary forms, with or without
|
|
1728
|
+
modification, are permitted provided that the following conditions are met:
|
|
1729
|
+
|
|
1730
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1731
|
+
this list of conditions and the following disclaimer.
|
|
1732
|
+
|
|
1733
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1734
|
+
notice, this list of conditions and the following disclaimer in
|
|
1735
|
+
the documentation and/or other materials provided with the distribution.
|
|
1736
|
+
|
|
1737
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1738
|
+
derived from this software without specific prior written permission.
|
|
1739
|
+
|
|
1740
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1741
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1742
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1743
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1744
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1745
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1746
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1747
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1748
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1749
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1750
|
+
*/
|
|
1751
|
+
|
|
1752
|
+
const MINIMUM_CHUNK_SIZE = 64;
|
|
1753
|
+
const UNDEFINED_VALUE = undefined;
|
|
1754
|
+
let maxWorkers = 2;
|
|
1755
|
+
try {
|
|
1756
|
+
if (typeof navigator != "undefined" && navigator.hardwareConcurrency) {
|
|
1757
|
+
maxWorkers = navigator.hardwareConcurrency;
|
|
1758
|
+
}
|
|
1759
|
+
} catch (_error) {
|
|
1760
|
+
// ignored
|
|
1761
|
+
}
|
|
1762
|
+
const DEFAULT_CONFIGURATION = {
|
|
1763
|
+
chunkSize: 512 * 1024,
|
|
1764
|
+
maxWorkers,
|
|
1765
|
+
terminateWorkerTimeout: 5000,
|
|
1766
|
+
useWebWorkers: true,
|
|
1767
|
+
useCompressionStream: true,
|
|
1768
|
+
workerScripts: undefined,
|
|
1769
|
+
CompressionStreamNative: typeof CompressionStream != "undefined" && CompressionStream,
|
|
1770
|
+
DecompressionStreamNative: typeof DecompressionStream != "undefined" && DecompressionStream
|
|
1771
|
+
};
|
|
1772
|
+
|
|
1773
|
+
const config = Object.assign({}, DEFAULT_CONFIGURATION);
|
|
1774
|
+
|
|
1775
|
+
function getConfiguration() {
|
|
1776
|
+
return config;
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
function getChunkSize(config) {
|
|
1780
|
+
return Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
function configure(configuration) {
|
|
1784
|
+
const {
|
|
1785
|
+
baseURL,
|
|
1786
|
+
chunkSize,
|
|
1787
|
+
maxWorkers,
|
|
1788
|
+
terminateWorkerTimeout,
|
|
1789
|
+
useCompressionStream,
|
|
1790
|
+
useWebWorkers,
|
|
1791
|
+
Deflate,
|
|
1792
|
+
Inflate,
|
|
1793
|
+
CompressionStream,
|
|
1794
|
+
DecompressionStream,
|
|
1795
|
+
workerScripts
|
|
1796
|
+
} = configuration;
|
|
1797
|
+
setIfDefined("baseURL", baseURL);
|
|
1798
|
+
setIfDefined("chunkSize", chunkSize);
|
|
1799
|
+
setIfDefined("maxWorkers", maxWorkers);
|
|
1800
|
+
setIfDefined("terminateWorkerTimeout", terminateWorkerTimeout);
|
|
1801
|
+
setIfDefined("useCompressionStream", useCompressionStream);
|
|
1802
|
+
setIfDefined("useWebWorkers", useWebWorkers);
|
|
1803
|
+
if (Deflate) {
|
|
1804
|
+
config.CompressionStream = getCodecStreamClass(Deflate);
|
|
1805
|
+
}
|
|
1806
|
+
if (Inflate) {
|
|
1807
|
+
config.DecompressionStream = getCodecStreamClass(Inflate);
|
|
1808
|
+
}
|
|
1809
|
+
setIfDefined("CompressionStream", CompressionStream);
|
|
1810
|
+
setIfDefined("DecompressionStream", DecompressionStream);
|
|
1811
|
+
if (workerScripts !== UNDEFINED_VALUE) {
|
|
1812
|
+
const { deflate, inflate } = workerScripts;
|
|
1813
|
+
if (deflate || inflate) {
|
|
1814
|
+
if (!config.workerScripts) {
|
|
1815
|
+
config.workerScripts = {};
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
if (deflate) {
|
|
1819
|
+
if (!Array.isArray(deflate)) {
|
|
1820
|
+
throw new Error("workerScripts.deflate must be an array");
|
|
1821
|
+
}
|
|
1822
|
+
config.workerScripts.deflate = deflate;
|
|
1823
|
+
}
|
|
1824
|
+
if (inflate) {
|
|
1825
|
+
if (!Array.isArray(inflate)) {
|
|
1826
|
+
throw new Error("workerScripts.inflate must be an array");
|
|
1827
|
+
}
|
|
1828
|
+
config.workerScripts.inflate = inflate;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
function setIfDefined(propertyName, propertyValue) {
|
|
1834
|
+
if (propertyValue !== UNDEFINED_VALUE) {
|
|
1835
|
+
config[propertyName] = propertyValue;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
function e(e){const t=()=>URL.createObjectURL(new Blob(['const{Array:e,Object:t,Math:n,Error:r,Uint8Array:s,Uint16Array:i,Uint32Array:o,Int32Array:c,Map:f,DataView:a,Promise:l,TextEncoder:u,crypto:w,postMessage:h,TransformStream:d,ReadableStream:p,WritableStream:y,CompressionStream:m,DecompressionStream:b}=self,g=[];for(let e=0;256>e;e++){let t=e;for(let e=0;8>e;e++)1&t?t=t>>>1^3988292384:t>>>=1;g[e]=t}class k{constructor(e){this.t=e||-1}append(e){let t=0|this.t;for(let n=0,r=0|e.length;r>n;n++)t=t>>>8^g[255&(t^e[n])];this.t=t}get(){return~this.t}}class v extends d{constructor(){const e=new k;super({transform(t){e.append(t)},flush(t){const n=new s(4);new a(n.buffer).setUint32(0,e.get()),t.enqueue(n)}})}}const S={concat(e,t){if(0===e.length||0===t.length)return e.concat(t);const n=e[e.length-1],r=S.i(n);return 32===r?e.concat(t):S.o(t,r,0|n,e.slice(0,e.length-1))},l(e){const t=e.length;if(0===t)return 0;const n=e[t-1];return 32*(t-1)+S.i(n)},u(e,t){if(32*e.length<t)return e;const r=(e=e.slice(0,n.ceil(t/32))).length;return t&=31,r>0&&t&&(e[r-1]=S.h(t,e[r-1]&2147483648>>t-1,1)),e},h:(e,t,n)=>32===e?t:(n?0|t:t<<32-e)+1099511627776*e,i:e=>n.round(e/1099511627776)||32,o(e,t,n,r){for(void 0===r&&(r=[]);t>=32;t-=32)r.push(n),n=0;if(0===t)return r.concat(e);for(let s=0;s<e.length;s++)r.push(n|e[s]>>>t),n=e[s]<<32-t;const s=e.length?e[e.length-1]:0,i=S.i(s);return r.push(S.h(t+i&31,t+i>32?n:r.pop(),1)),r}},C={p:{m(e){const t=S.l(e)/8,n=new s(t);let r;for(let s=0;t>s;s++)0==(3&s)&&(r=e[s/4]),n[s]=r>>>24,r<<=8;return n},g(e){const t=[];let n,r=0;for(n=0;n<e.length;n++)r=r<<8|e[n],3==(3&n)&&(t.push(r),r=0);return 3&n&&t.push(S.h(8*(3&n),r)),t}}},z={k:function(e){e?(this.v=e.v.slice(0),this.S=e.S.slice(0),this.C=e.C):this.reset()}};z.k.prototype={blockSize:512,reset(){const e=this;return e.v=this._.slice(0),e.S=[],e.C=0,e},update(e){const t=this;"string"==typeof e&&(e=C.I.g(e));const n=t.S=S.concat(t.S,e),s=t.C,i=t.C=s+S.l(e);if(i>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new o(n);let f=0;for(let e=t.blockSize+s-(t.blockSize+s&t.blockSize-1);i>=e;e+=t.blockSize)t.A(c.subarray(16*f,16*(f+1))),f+=1;return n.splice(0,16*f),t},D(){const e=this;let t=e.S;const r=e.v;t=S.concat(t,[S.h(1,1)]);for(let e=t.length+2;15&e;e++)t.push(0);for(t.push(n.floor(e.C/4294967296)),t.push(0|e.C);t.length;)e.A(t.splice(0,16));return e.reset(),r},_:[1732584193,4023233417,2562383102,271733878,3285377520],V:[1518500249,1859775393,2400959708,3395469782],R:(e,t,n,r)=>e>19?e>39?e>59?e>79?void 0:t^n^r:t&n|t&r|n&r:t^n^r:t&n|~t&r,B:(e,t)=>t<<e|t>>>32-e,A(t){const r=this,s=r.v,i=e(80);for(let e=0;16>e;e++)i[e]=t[e];let o=s[0],c=s[1],f=s[2],a=s[3],l=s[4];for(let e=0;79>=e;e++){16>e||(i[e]=r.B(1,i[e-3]^i[e-8]^i[e-14]^i[e-16]));const t=r.B(5,o)+r.R(e,c,f,a)+l+i[e]+r.V[n.floor(e/20)]|0;l=a,a=f,f=r.B(30,c),c=o,o=t}s[0]=s[0]+o|0,s[1]=s[1]+c|0,s[2]=s[2]+f|0,s[3]=s[3]+a|0,s[4]=s[4]+l|0}};const _={getRandomValues(e){const t=new o(e.buffer),r=e=>{let t=987654321;const r=4294967295;return()=>(t=36969*(65535&t)+(t>>16)&r,(((t<<16)+(e=18e3*(65535&e)+(e>>16)&r)&r)/4294967296+.5)*(n.random()>.5?1:-1))};for(let s,i=0;i<e.length;i+=4){const e=r(4294967296*(s||n.random()));s=987654071*e(),t[i/4]=4294967296*e()|0}return e}},I={importKey:e=>new I.M(C.p.g(e)),K(e,t,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const i=1+(s>>5)<<2;let o,c,f,l,u;const w=new ArrayBuffer(i),h=new a(w);let d=0;const p=S;for(t=C.p.g(t),u=1;(i||1)>d;u++){for(o=c=e.encrypt(p.concat(t,[u])),f=1;n>f;f++)for(c=e.encrypt(c),l=0;l<c.length;l++)o[l]^=c[l];for(f=0;(i||1)>d&&f<o.length;f++)h.setInt32(d,o[f]),d+=4}return w.slice(0,s/8)},M:class{constructor(e){const t=this,n=t.N=z.k,r=[[],[]],s=n.prototype.blockSize/32;t.P=[new n,new n],e.length>s&&(e=n.hash(e));for(let t=0;s>t;t++)r[0][t]=909522486^e[t],r[1][t]=1549556828^e[t];t.P[0].update(r[0]),t.P[1].update(r[1]),t.U=new n(t.P[0])}reset(){const e=this;e.U=new e.N(e.P[0]),e.T=!1}update(e){this.T=!0,this.U.update(e)}digest(){const e=this,t=e.U.D(),n=new e.N(e.P[1]).update(t).D();return e.reset(),n}encrypt(e){if(this.T)throw new r("encrypt on already updated hmac called!");return this.update(e),this.digest(e)}}},x=void 0!==w&&"function"==typeof w.getRandomValues;function A(e){return x?w.getRandomValues(e):_.getRandomValues(e)}const D={name:"PBKDF2"},V=t.assign({hash:{name:"HMAC"}},D),R=t.assign({iterations:1e3,hash:{name:"SHA-1"}},D),B=["deriveBits"],E=[8,12,16],M=[16,24,32],K=[0,0,0,0],N=void 0!==w,P=N&&w.subtle,U=N&&void 0!==P,T=N&&U&&"function"==typeof P.importKey,W=N&&U&&"function"==typeof P.deriveBits,H=C.p,L=class{constructor(e){const t=this;t.W=[[[],[],[],[],[]],[[],[],[],[],[]]],t.W[0][0][0]||t.H();const n=t.W[0][4],s=t.W[1],i=e.length;let o,c,f,a=1;if(4!==i&&6!==i&&8!==i)throw new r("invalid aes key size");for(t.V=[c=e.slice(0),f=[]],o=i;4*i+28>o;o++){let e=c[o-1];(o%i==0||8===i&&o%i==4)&&(e=n[e>>>24]<<24^n[e>>16&255]<<16^n[e>>8&255]<<8^n[255&e],o%i==0&&(e=e<<8^e>>>24^a<<24,a=a<<1^283*(a>>7))),c[o]=c[o-i]^e}for(let e=0;o;e++,o--){const t=c[3&e?o:o-4];f[e]=4>=o||4>e?t:s[0][n[t>>>24]]^s[1][n[t>>16&255]]^s[2][n[t>>8&255]]^s[3][n[255&t]]}}encrypt(e){return this.L(e,0)}decrypt(e){return this.L(e,1)}H(){const e=this.W[0],t=this.W[1],n=e[4],r=t[4],s=[],i=[];let o,c,f,a;for(let e=0;256>e;e++)i[(s[e]=e<<1^283*(e>>7))^e]=e;for(let l=o=0;!n[l];l^=c||1,o=i[o]||1){let i=o^o<<1^o<<2^o<<3^o<<4;i=i>>8^255&i^99,n[l]=i,r[i]=l,a=s[f=s[c=s[l]]];let u=16843009*a^65537*f^257*c^16843008*l,w=257*s[i]^16843008*i;for(let n=0;4>n;n++)e[n][l]=w=w<<24^w>>>8,t[n][i]=u=u<<24^u>>>8}for(let n=0;5>n;n++)e[n]=e[n].slice(0),t[n]=t[n].slice(0)}L(e,t){if(4!==e.length)throw new r("invalid aes block size");const n=this.V[t],s=n.length/4-2,i=[0,0,0,0],o=this.W[t],c=o[0],f=o[1],a=o[2],l=o[3],u=o[4];let w,h,d,p=e[0]^n[0],y=e[t?3:1]^n[1],m=e[2]^n[2],b=e[t?1:3]^n[3],g=4;for(let e=0;s>e;e++)w=c[p>>>24]^f[y>>16&255]^a[m>>8&255]^l[255&b]^n[g],h=c[y>>>24]^f[m>>16&255]^a[b>>8&255]^l[255&p]^n[g+1],d=c[m>>>24]^f[b>>16&255]^a[p>>8&255]^l[255&y]^n[g+2],b=c[b>>>24]^f[p>>16&255]^a[y>>8&255]^l[255&m]^n[g+3],g+=4,p=w,y=h,m=d;for(let e=0;4>e;e++)i[t?3&-e:e]=u[p>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&b]^n[g++],w=p,p=y,y=m,m=b,b=w;return i}},j=class{constructor(e,t){this.j=e,this.F=t,this.O=t}reset(){this.O=this.F}update(e){return this.q(this.j,e,this.O)}G(e){if(255==(e>>24&255)){let t=e>>16&255,n=e>>8&255,r=255&e;255===t?(t=0,255===n?(n=0,255===r?r=0:++r):++n):++t,e=0,e+=t<<16,e+=n<<8,e+=r}else e+=1<<24;return e}J(e){0===(e[0]=this.G(e[0]))&&(e[1]=this.G(e[1]))}q(e,t,n){let r;if(!(r=t.length))return[];const s=S.l(t);for(let s=0;r>s;s+=4){this.J(n);const r=e.encrypt(n);t[s]^=r[0],t[s+1]^=r[1],t[s+2]^=r[2],t[s+3]^=r[3]}return S.u(t,s)}},F=I.M;class O extends d{constructor(e,n,i){super({start(){t.assign(this,{ready:new l((e=>this.X=e)),password:e,signed:n,Y:i-1,pending:new s})},async transform(e,t){const n=this,{password:i,Y:o,X:c,ready:f}=n;i?(await(async(e,t,n,s)=>{const i=await J(e,t,n,X(s,0,E[t])),o=X(s,E[t]);if(i[0]!=o[0]||i[1]!=o[1])throw new r("Invalid password")})(n,o,i,X(e,0,E[o]+2)),e=X(e,E[o]+2),c()):await f;const a=new s(e.length-10-(e.length-10)%16);t.enqueue(G(n,e,a,0,10,!0))},async flush(e){const{signed:t,Z:n,$:i,pending:o,ready:c}=this;await c;const f=X(o,0,o.length-10),a=X(o,o.length-10);let l=new s;if(f.length){const e=Z(H,f);i.update(e);const t=n.update(e);l=Y(H,t)}if(t){const e=X(Y(H,i.digest()),0,10);for(let t=0;10>t;t++)if(e[t]!=a[t])throw new r("Invalid signature")}e.enqueue(l)}})}}class q extends d{constructor(e,n){let r;super({start(){t.assign(this,{ready:new l((e=>this.X=e)),password:e,Y:n-1,pending:new s})},async transform(e,t){const n=this,{password:r,Y:i,X:o,ready:c}=n;let f=new s;r?(f=await(async(e,t,n)=>{const r=A(new s(E[t]));return Q(r,await J(e,t,n,r))})(n,i,r),o()):await c;const a=new s(f.length+e.length-e.length%16);a.set(f,0),t.enqueue(G(n,e,a,f.length,0))},async flush(e){const{Z:t,$:n,pending:i,ready:o}=this;await o;let c=new s;if(i.length){const e=t.update(Z(H,i));n.update(e),c=Y(H,e)}r.signature=Y(H,n.digest()).slice(0,10),e.enqueue(Q(c,r.signature))}}),r=this}}function G(e,t,n,r,i,o){const{Z:c,$:f,pending:a}=e,l=t.length-i;let u;for(a.length&&(t=Q(a,t),n=((e,t)=>{if(t&&t>e.length){const n=e;(e=new s(t)).set(n,0)}return e})(n,l-l%16)),u=0;l-16>=u;u+=16){const e=Z(H,X(t,u,u+16));o&&f.update(e);const s=c.update(e);o||f.update(s),n.set(Y(H,s),u+r)}return e.pending=X(t,u),n}async function J(n,r,i,o){n.password=null;const c=(e=>{if(void 0===u){const t=new s((e=unescape(encodeURIComponent(e))).length);for(let n=0;n<t.length;n++)t[n]=e.charCodeAt(n);return t}return(new u).encode(e)})(i),f=await((e,t,n,r,s)=>T?P.importKey("raw",t,n,!1,s):I.importKey(t))(0,c,V,0,B),a=await(async(e,t,n)=>W?await P.deriveBits(e,t,n):I.K(t,e.salt,R.iterations,n))(t.assign({salt:o},R),f,8*(2*M[r]+2)),l=new s(a),w=Z(H,X(l,0,M[r])),h=Z(H,X(l,M[r],2*M[r])),d=X(l,2*M[r]);return t.assign(n,{keys:{key:w,ee:h,passwordVerification:d},Z:new j(new L(w),e.from(K)),$:new F(h)}),d}function Q(e,t){let n=e;return e.length+t.length&&(n=new s(e.length+t.length),n.set(e,0),n.set(t,e.length)),n}function X(e,t,n){return e.subarray(t,n)}function Y(e,t){return e.m(t)}function Z(e,t){return e.g(t)}class $ extends d{constructor(e,n){super({start(){t.assign(this,{password:e,passwordVerification:n}),re(this,e)},transform(e,t){const n=this;if(n.password){const t=te(n,e.subarray(0,12));if(n.password=null,t[11]!=n.passwordVerification)throw new r("Invalid password");e=e.subarray(12)}t.enqueue(te(n,e))}})}}class ee extends d{constructor(e,n){super({start(){t.assign(this,{password:e,passwordVerification:n}),re(this,e)},transform(e,t){const n=this;let r,i;if(n.password){n.password=null;const t=A(new s(12));t[11]=n.passwordVerification,r=new s(e.length+t.length),r.set(ne(n,t),0),i=12}else r=new s(e.length),i=0;r.set(ne(n,e),i),t.enqueue(r)}})}}function te(e,t){const n=new s(t.length);for(let r=0;r<t.length;r++)n[r]=ie(e)^t[r],se(e,n[r]);return n}function ne(e,t){const n=new s(t.length);for(let r=0;r<t.length;r++)n[r]=ie(e)^t[r],se(e,t[r]);return n}function re(e,n){const r=[305419896,591751049,878082192];t.assign(e,{keys:r,te:new k(r[0]),ne:new k(r[2])});for(let t=0;t<n.length;t++)se(e,n.charCodeAt(t))}function se(e,t){let[r,s,i]=e.keys;e.te.append([t]),r=~e.te.get(),s=ce(n.imul(ce(s+oe(r)),134775813)+1),e.ne.append([s>>>24]),i=~e.ne.get(),e.keys=[r,s,i]}function ie(e){const t=2|e.keys[2];return oe(n.imul(t,1^t)>>>8)}function oe(e){return 255&e}function ce(e){return 4294967295&e}class fe extends d{constructor(e,{chunkSize:t,CompressionStream:n,re:r}){super({});const{compressed:s,encrypted:i,useCompressionStream:o,password:c,passwordVerification:f,encryptionStrength:l,zipCrypto:u,signed:w,level:h}=e,d=this;let p,y,m=le(super.readable);i&&!u||!w||([m,p]=m.tee(),p=he(p,new v)),s&&(m=we(m,o,{level:h,chunkSize:t},r,n)),i&&(u?m=he(m,new ee(c,f)):(y=new q(c,l),m=he(m,y))),ue(d,m,(async()=>{let e;i&&!u&&(e=y.signature),i&&!u||!w||(e=await p.getReader().read(),e=new a(e.value.buffer).getUint32(0)),d.signature=e}))}}class ae extends d{constructor(e,{chunkSize:t,DecompressionStream:n,se:s}){super({});const{zipCrypto:i,encrypted:o,password:c,passwordVerification:f,signed:l,signature:u,encryptionStrength:w,compressed:h,useCompressionStream:d}=e;let p,y,m=le(super.readable);o&&(i?m=he(m,new $(c,f)):(y=new O(c,l,w),m=he(m,y))),h&&(m=we(m,d,{chunkSize:t},s,n)),o&&!i||!l||([m,p]=m.tee(),p=he(p,new v)),ue(this,m,(async()=>{if((!o||i)&&l){const e=await p.getReader().read(),t=new a(e.value.buffer);if(u!=t.getUint32(0,!1))throw new r("Invalid signature")}}))}}function le(e){return he(e,new d({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function ue(e,n,r){n=he(n,new d({flush:r})),t.defineProperty(e,"readable",{get:()=>n})}function we(e,t,n,r,s){try{e=he(e,new(t&&r?r:s)("deflate-raw",n))}catch(r){if(!t)throw r;e=he(e,new s("deflate-raw",n))}return e}function he(e,t){return e.pipeThrough(t)}class de extends d{constructor(e,t){const n=new e(t);super({transform(e,t){t.enqueue(n.append(e))},flush(e){const t=n.flush();t&&e.enqueue(t)}})}}class pe{constructor(e,n,r,s){const{codecType:i}=r;let o;i.startsWith("deflate")?o=fe:i.startsWith("inflate")&&(o=ae),t.assign(this,{ie:o,readable:e,writable:n,options:r,config:s})}async oe(){const{ie:e,readable:t,writable:n,options:r,config:s}=this,i=new e(r,s);let o=0;await t.pipeThrough(i).pipeThrough(new d({transform(e,t){e&&e.length&&(o+=e.length,t.enqueue(e))}})).pipeTo(n,{ce:!0,fe:!0});const{signature:c}=i;return{size:o,signature:c}}}function ye(e){return class extends de{constructor(t,n){super(e,n)}}}const me=new f,be=new f;let ge,ke=0;async function ve(e){try{const{options:t,scripts:n,config:r}=e;n&&n.length&&importScripts.apply(void 0,n),self.initCodec&&self.initCodec(),r.re=self.CompressionStream,r.se=self.DecompressionStream,self.Deflate&&(r.CompressionStream=ye(self.Deflate)),self.Inflate&&(r.DecompressionStream=ye(self.Inflate));const s={highWaterMark:1,size:()=>r.chunkSize},i=e.readable||new p({async pull(e){let t=new l((e=>me.set(ke,e)));Se({type:"pull",messageId:ke}),ke=(ke+1)%Number.MAX_SAFE_INTEGER;const{value:n,done:r}=await t;e.enqueue(n),r&&e.close()}},s),o=e.writable||new y({async write(e){let t;const n=new l((e=>t=e));be.set(ke,t),Se({type:"data",data:e,messageId:ke}),ke=(ke+1)%Number.MAX_SAFE_INTEGER,await n}},s);ge=new pe(i,o,t,r);const c=await ge.oe();try{await o.close()}catch(e){}Se({type:"close",result:c})}catch(e){Ce(e)}}function Se(e){if(e.data){let{data:t}=e;if(t&&t.length)try{t=new s(t),e.data=t.buffer,h(e,[e.data])}catch(t){h(e)}else h(e)}else h(e)}function Ce(e){const{message:t,stack:n,code:r,name:s}=e;h({error:{message:t,stack:n,code:r,name:s}})}function ze(t){return _e(t.map((([t,n])=>new e(t).fill(n,0,t))))}function _e(t){return t.reduce(((t,n)=>t.concat(e.isArray(n)?_e(n):n)),[])}addEventListener("message",(async e=>{const t=e.data,{type:n,messageId:r,data:i,done:o}=t;try{if("start"==n&&ve(t),"data"==n){const e=me.get(r);me.delete(r),e({value:new s(i),done:o})}if("ack"==n){const e=be.get(r);be.delete(r),e()}}catch(e){Ce(e)}}));const Ie=[0,1,2,3].concat(...ze([[2,4],[2,5],[4,6],[4,7],[8,8],[8,9],[16,10],[16,11],[32,12],[32,13],[64,14],[64,15],[2,0],[1,16],[1,17],[2,18],[2,19],[4,20],[4,21],[8,22],[8,23],[16,24],[16,25],[32,26],[32,27],[64,28],[64,29]]));function xe(){const e=this;function t(e,t){let n=0;do{n|=1&e,e>>>=1,n<<=1}while(--t>0);return n>>>1}e.ae=r=>{const s=e.le,i=e.we.ue,o=e.we.he;let c,f,a,l=-1;for(r.de=0,r.pe=573,c=0;o>c;c++)0!==s[2*c]?(r.ye[++r.de]=l=c,r.me[c]=0):s[2*c+1]=0;for(;2>r.de;)a=r.ye[++r.de]=2>l?++l:0,s[2*a]=1,r.me[a]=0,r.be--,i&&(r.ge-=i[2*a+1]);for(e.ke=l,c=n.floor(r.de/2);c>=1;c--)r.ve(s,c);a=o;do{c=r.ye[1],r.ye[1]=r.ye[r.de--],r.ve(s,1),f=r.ye[1],r.ye[--r.pe]=c,r.ye[--r.pe]=f,s[2*a]=s[2*c]+s[2*f],r.me[a]=n.max(r.me[c],r.me[f])+1,s[2*c+1]=s[2*f+1]=a,r.ye[1]=a++,r.ve(s,1)}while(r.de>=2);r.ye[--r.pe]=r.ye[1],(t=>{const n=e.le,r=e.we.ue,s=e.we.Se,i=e.we.Ce,o=e.we.ze;let c,f,a,l,u,w,h=0;for(l=0;15>=l;l++)t._e[l]=0;for(n[2*t.ye[t.pe]+1]=0,c=t.pe+1;573>c;c++)f=t.ye[c],l=n[2*n[2*f+1]+1]+1,l>o&&(l=o,h++),n[2*f+1]=l,f>e.ke||(t._e[l]++,u=0,i>f||(u=s[f-i]),w=n[2*f],t.be+=w*(l+u),r&&(t.ge+=w*(r[2*f+1]+u)));if(0!==h){do{for(l=o-1;0===t._e[l];)l--;t._e[l]--,t._e[l+1]+=2,t._e[o]--,h-=2}while(h>0);for(l=o;0!==l;l--)for(f=t._e[l];0!==f;)a=t.ye[--c],a>e.ke||(n[2*a+1]!=l&&(t.be+=(l-n[2*a+1])*n[2*a],n[2*a+1]=l),f--)}})(r),((e,n,r)=>{const s=[];let i,o,c,f=0;for(i=1;15>=i;i++)s[i]=f=f+r[i-1]<<1;for(o=0;n>=o;o++)c=e[2*o+1],0!==c&&(e[2*o]=t(s[c]++,c))})(s,e.ke,r._e)}}function Ae(e,t,n,r,s){const i=this;i.ue=e,i.Se=t,i.Ce=n,i.he=r,i.ze=s}xe.Ie=[0,1,2,3,4,5,6,7].concat(...ze([[2,8],[2,9],[2,10],[2,11],[4,12],[4,13],[4,14],[4,15],[8,16],[8,17],[8,18],[8,19],[16,20],[16,21],[16,22],[16,23],[32,24],[32,25],[32,26],[31,27],[1,28]])),xe.xe=[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],xe.Ae=[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],xe.De=e=>256>e?Ie[e]:Ie[256+(e>>>7)],xe.Ve=[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],xe.Re=[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],xe.Be=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],xe.Ee=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];const De=ze([[144,8],[112,9],[24,7],[8,8]]);Ae.Me=_e([12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,19,275,147,403,83,339,211,467,51,307,179,435,115,371,243,499,11,267,139,395,75,331,203,459,43,299,171,427,107,363,235,491,27,283,155,411,91,347,219,475,59,315,187,443,123,379,251,507,7,263,135,391,71,327,199,455,39,295,167,423,103,359,231,487,23,279,151,407,87,343,215,471,55,311,183,439,119,375,247,503,15,271,143,399,79,335,207,463,47,303,175,431,111,367,239,495,31,287,159,415,95,351,223,479,63,319,191,447,127,383,255,511,0,64,32,96,16,80,48,112,8,72,40,104,24,88,56,120,4,68,36,100,20,84,52,116,3,131,67,195,35,163,99,227].map(((e,t)=>[e,De[t]])));const Ve=ze([[30,5]]);function Re(e,t,n,r,s){const i=this;i.Ke=e,i.Ne=t,i.Pe=n,i.Ue=r,i.Te=s}Ae.We=_e([0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30,1,17,9,25,5,21,13,29,3,19,11,27,7,23].map(((e,t)=>[e,Ve[t]]))),Ae.He=new Ae(Ae.Me,xe.Ve,257,286,15),Ae.Le=new Ae(Ae.We,xe.Re,0,30,15),Ae.je=new Ae(null,xe.Be,0,19,7);const Be=[new Re(0,0,0,0,0),new Re(4,4,8,4,1),new Re(4,5,16,8,1),new Re(4,6,32,32,1),new Re(4,4,16,16,2),new Re(8,16,32,32,2),new Re(8,16,128,128,2),new Re(8,32,128,256,2),new Re(32,128,258,1024,2),new Re(32,258,258,4096,2)],Ee=["need dictionary","stream end","","","stream error","data error","","buffer error","",""];function Me(e,t,n,r){const s=e[2*t],i=e[2*n];return i>s||s==i&&r[t]<=r[n]}function Ke(){const e=this;let t,r,o,c,f,a,l,u,w,h,d,p,y,m,b,g,k,v,S,C,z,_,I,x,A,D,V,R,B,E,M,K,N;const P=new xe,U=new xe,T=new xe;let W,H,L,j,F,O;function q(){let t;for(t=0;286>t;t++)M[2*t]=0;for(t=0;30>t;t++)K[2*t]=0;for(t=0;19>t;t++)N[2*t]=0;M[512]=1,e.be=e.ge=0,H=L=0}function G(e,t){let n,r=-1,s=e[1],i=0,o=7,c=4;0===s&&(o=138,c=3),e[2*(t+1)+1]=65535;for(let f=0;t>=f;f++)n=s,s=e[2*(f+1)+1],++i<o&&n==s||(c>i?N[2*n]+=i:0!==n?(n!=r&&N[2*n]++,N[32]++):i>10?N[36]++:N[34]++,i=0,r=n,0===s?(o=138,c=3):n==s?(o=6,c=3):(o=7,c=4))}function J(t){e.Fe[e.pending++]=t}function Q(e){J(255&e),J(e>>>8&255)}function X(e,t){let n;const r=t;O>16-r?(n=e,F|=n<<O&65535,Q(F),F=n>>>16-O,O+=r-16):(F|=e<<O&65535,O+=r)}function Y(e,t){const n=2*e;X(65535&t[n],65535&t[n+1])}function Z(e,t){let n,r,s=-1,i=e[1],o=0,c=7,f=4;for(0===i&&(c=138,f=3),n=0;t>=n;n++)if(r=i,i=e[2*(n+1)+1],++o>=c||r!=i){if(f>o)do{Y(r,N)}while(0!=--o);else 0!==r?(r!=s&&(Y(r,N),o--),Y(16,N),X(o-3,2)):o>10?(Y(18,N),X(o-11,7)):(Y(17,N),X(o-3,3));o=0,s=r,0===i?(c=138,f=3):r==i?(c=6,f=3):(c=7,f=4)}}function $(){16==O?(Q(F),F=0,O=0):8>O||(J(255&F),F>>>=8,O-=8)}function ee(t,r){let s,i,o;if(e.Oe[H]=t,e.qe[H]=255&r,H++,0===t?M[2*r]++:(L++,t--,M[2*(xe.Ie[r]+256+1)]++,K[2*xe.De(t)]++),0==(8191&H)&&V>2){for(s=8*H,i=z-k,o=0;30>o;o++)s+=K[2*o]*(5+xe.Re[o]);if(s>>>=3,L<n.floor(H/2)&&s<n.floor(i/2))return!0}return H==W-1}function te(t,n){let r,s,i,o,c=0;if(0!==H)do{r=e.Oe[c],s=e.qe[c],c++,0===r?Y(s,t):(i=xe.Ie[s],Y(i+256+1,t),o=xe.Ve[i],0!==o&&(s-=xe.xe[i],X(s,o)),r--,i=xe.De(r),Y(i,n),o=xe.Re[i],0!==o&&(r-=xe.Ae[i],X(r,o)))}while(H>c);Y(256,t),j=t[513]}function ne(){O>8?Q(F):O>0&&J(255&F),F=0,O=0}function re(t,n,r){X(0+(r?1:0),3),((t,n)=>{ne(),j=8,Q(n),Q(~n),e.Fe.set(u.subarray(t,t+n),e.pending),e.pending+=n})(t,n)}function se(n){((t,n,r)=>{let s,i,o=0;V>0?(P.ae(e),U.ae(e),o=(()=>{let t;for(G(M,P.ke),G(K,U.ke),T.ae(e),t=18;t>=3&&0===N[2*xe.Ee[t]+1];t--);return e.be+=14+3*(t+1),t})(),s=e.be+3+7>>>3,i=e.ge+3+7>>>3,i>s||(s=i)):s=i=n+5,n+4>s||-1==t?i==s?(X(2+(r?1:0),3),te(Ae.Me,Ae.We)):(X(4+(r?1:0),3),((e,t,n)=>{let r;for(X(e-257,5),X(t-1,5),X(n-4,4),r=0;n>r;r++)X(N[2*xe.Ee[r]+1],3);Z(M,e-1),Z(K,t-1)})(P.ke+1,U.ke+1,o+1),te(M,K)):re(t,n,r),q(),r&&ne()})(0>k?-1:k,z-k,n),k=z,t.Ge()}function ie(){let e,n,r,s;do{if(s=w-I-z,0===s&&0===z&&0===I)s=f;else if(-1==s)s--;else if(z>=f+f-262){u.set(u.subarray(f,f+f),0),_-=f,z-=f,k-=f,e=y,r=e;do{n=65535&d[--r],d[r]=f>n?0:n-f}while(0!=--e);e=f,r=e;do{n=65535&h[--r],h[r]=f>n?0:n-f}while(0!=--e);s+=f}if(0===t.Je)return;e=t.Qe(u,z+I,s),I+=e,3>I||(p=255&u[z],p=(p<<g^255&u[z+1])&b)}while(262>I&&0!==t.Je)}function oe(e){let t,n,r=A,s=z,i=x;const o=z>f-262?z-(f-262):0;let c=E;const a=l,w=z+258;let d=u[s+i-1],p=u[s+i];B>x||(r>>=2),c>I&&(c=I);do{if(t=e,u[t+i]==p&&u[t+i-1]==d&&u[t]==u[s]&&u[++t]==u[s+1]){s+=2,t++;do{}while(u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&w>s);if(n=258-(w-s),s=w-258,n>i){if(_=e,i=n,n>=c)break;d=u[s+i-1],p=u[s+i]}}}while((e=65535&h[e&a])>o&&0!=--r);return i>I?I:i}e.me=[],e._e=[],e.ye=[],M=[],K=[],N=[],e.ve=(t,n)=>{const r=e.ye,s=r[n];let i=n<<1;for(;i<=e.de&&(i<e.de&&Me(t,r[i+1],r[i],e.me)&&i++,!Me(t,s,r[i],e.me));)r[n]=r[i],n=i,i<<=1;r[n]=s},e.Xe=(t,S,_,H,L,G)=>(H||(H=8),L||(L=8),G||(G=0),t.Ye=null,-1==S&&(S=6),1>L||L>9||8!=H||9>_||_>15||0>S||S>9||0>G||G>2?-2:(t.Ze=e,a=_,f=1<<a,l=f-1,m=L+7,y=1<<m,b=y-1,g=n.floor((m+3-1)/3),u=new s(2*f),h=[],d=[],W=1<<L+6,e.Fe=new s(4*W),o=4*W,e.Oe=new i(W),e.qe=new s(W),V=S,R=G,(t=>(t.$e=t.et=0,t.Ye=null,e.pending=0,e.tt=0,r=113,c=0,P.le=M,P.we=Ae.He,U.le=K,U.we=Ae.Le,T.le=N,T.we=Ae.je,F=0,O=0,j=8,q(),(()=>{w=2*f,d[y-1]=0;for(let e=0;y-1>e;e++)d[e]=0;D=Be[V].Ne,B=Be[V].Ke,E=Be[V].Pe,A=Be[V].Ue,z=0,k=0,I=0,v=x=2,C=0,p=0})(),0))(t))),e.nt=()=>42!=r&&113!=r&&666!=r?-2:(e.qe=null,e.Oe=null,e.Fe=null,d=null,h=null,u=null,e.Ze=null,113==r?-3:0),e.rt=(e,t,n)=>{let r=0;return-1==t&&(t=6),0>t||t>9||0>n||n>2?-2:(Be[V].Te!=Be[t].Te&&0!==e.$e&&(r=e.st(1)),V!=t&&(V=t,D=Be[V].Ne,B=Be[V].Ke,E=Be[V].Pe,A=Be[V].Ue),R=n,r)},e.it=(e,t,n)=>{let s,i=n,o=0;if(!t||42!=r)return-2;if(3>i)return 0;for(i>f-262&&(i=f-262,o=n-i),u.set(t.subarray(o,o+i),0),z=i,k=i,p=255&u[0],p=(p<<g^255&u[1])&b,s=0;i-3>=s;s++)p=(p<<g^255&u[s+2])&b,h[s&l]=d[p],d[p]=s;return 0},e.st=(n,s)=>{let i,w,m,A,B;if(s>4||0>s)return-2;if(!n.ot||!n.ct&&0!==n.Je||666==r&&4!=s)return n.Ye=Ee[4],-2;if(0===n.ft)return n.Ye=Ee[7],-5;var E;if(t=n,A=c,c=s,42==r&&(w=8+(a-8<<4)<<8,m=(V-1&255)>>1,m>3&&(m=3),w|=m<<6,0!==z&&(w|=32),w+=31-w%31,r=113,J((E=w)>>8&255),J(255&E)),0!==e.pending){if(t.Ge(),0===t.ft)return c=-1,0}else if(0===t.Je&&A>=s&&4!=s)return t.Ye=Ee[7],-5;if(666==r&&0!==t.Je)return n.Ye=Ee[7],-5;if(0!==t.Je||0!==I||0!=s&&666!=r){switch(B=-1,Be[V].Te){case 0:B=(e=>{let n,r=65535;for(r>o-5&&(r=o-5);;){if(1>=I){if(ie(),0===I&&0==e)return 0;if(0===I)break}if(z+=I,I=0,n=k+r,(0===z||z>=n)&&(I=z-n,z=n,se(!1),0===t.ft))return 0;if(z-k>=f-262&&(se(!1),0===t.ft))return 0}return se(4==e),0===t.ft?4==e?2:0:4==e?3:1})(s);break;case 1:B=(e=>{let n,r=0;for(;;){if(262>I){if(ie(),262>I&&0==e)return 0;if(0===I)break}if(3>I||(p=(p<<g^255&u[z+2])&b,r=65535&d[p],h[z&l]=d[p],d[p]=z),0===r||(z-r&65535)>f-262||2!=R&&(v=oe(r)),3>v)n=ee(0,255&u[z]),I--,z++;else if(n=ee(z-_,v-3),I-=v,v>D||3>I)z+=v,v=0,p=255&u[z],p=(p<<g^255&u[z+1])&b;else{v--;do{z++,p=(p<<g^255&u[z+2])&b,r=65535&d[p],h[z&l]=d[p],d[p]=z}while(0!=--v);z++}if(n&&(se(!1),0===t.ft))return 0}return se(4==e),0===t.ft?4==e?2:0:4==e?3:1})(s);break;case 2:B=(e=>{let n,r,s=0;for(;;){if(262>I){if(ie(),262>I&&0==e)return 0;if(0===I)break}if(3>I||(p=(p<<g^255&u[z+2])&b,s=65535&d[p],h[z&l]=d[p],d[p]=z),x=v,S=_,v=2,0!==s&&D>x&&f-262>=(z-s&65535)&&(2!=R&&(v=oe(s)),5>=v&&(1==R||3==v&&z-_>4096)&&(v=2)),3>x||v>x)if(0!==C){if(n=ee(0,255&u[z-1]),n&&se(!1),z++,I--,0===t.ft)return 0}else C=1,z++,I--;else{r=z+I-3,n=ee(z-1-S,x-3),I-=x-1,x-=2;do{++z>r||(p=(p<<g^255&u[z+2])&b,s=65535&d[p],h[z&l]=d[p],d[p]=z)}while(0!=--x);if(C=0,v=2,z++,n&&(se(!1),0===t.ft))return 0}}return 0!==C&&(n=ee(0,255&u[z-1]),C=0),se(4==e),0===t.ft?4==e?2:0:4==e?3:1})(s)}if(2!=B&&3!=B||(r=666),0==B||2==B)return 0===t.ft&&(c=-1),0;if(1==B){if(1==s)X(2,3),Y(256,Ae.Me),$(),9>1+j+10-O&&(X(2,3),Y(256,Ae.Me),$()),j=7;else if(re(0,0,!1),3==s)for(i=0;y>i;i++)d[i]=0;if(t.Ge(),0===t.ft)return c=-1,0}}return 4!=s?0:1}}function Ne(){const e=this;e.lt=0,e.ut=0,e.Je=0,e.$e=0,e.ft=0,e.et=0}function Pe(e){const t=new Ne,i=(o=e&&e.chunkSize?e.chunkSize:65536)+5*(n.floor(o/16383)+1);var o;const c=new s(i);let f=e?e.level:-1;void 0===f&&(f=-1),t.Xe(f),t.ot=c,this.append=(e,n)=>{let o,f,a=0,l=0,u=0;const w=[];if(e.length){t.lt=0,t.ct=e,t.Je=e.length;do{if(t.ut=0,t.ft=i,o=t.st(0),0!=o)throw new r("deflating: "+t.Ye);t.ut&&(t.ut==i?w.push(new s(c)):w.push(c.slice(0,t.ut))),u+=t.ut,n&&t.lt>0&&t.lt!=a&&(n(t.lt),a=t.lt)}while(t.Je>0||0===t.ft);return w.length>1?(f=new s(u),w.forEach((e=>{f.set(e,l),l+=e.length}))):f=w[0]||new s,f}},this.flush=()=>{let e,n,o=0,f=0;const a=[];do{if(t.ut=0,t.ft=i,e=t.st(4),1!=e&&0!=e)throw new r("deflating: "+t.Ye);i-t.ft>0&&a.push(c.slice(0,t.ut)),f+=t.ut}while(t.Je>0||0===t.ft);return t.nt(),n=new s(f),a.forEach((e=>{n.set(e,o),o+=e.length})),n}}Ne.prototype={Xe(e,t){const n=this;return n.Ze=new Ke,t||(t=15),n.Ze.Xe(n,e,t)},st(e){const t=this;return t.Ze?t.Ze.st(t,e):-2},nt(){const e=this;if(!e.Ze)return-2;const t=e.Ze.nt();return e.Ze=null,t},rt(e,t){const n=this;return n.Ze?n.Ze.rt(n,e,t):-2},it(e,t){const n=this;return n.Ze?n.Ze.it(n,e,t):-2},Qe(e,t,n){const r=this;let s=r.Je;return s>n&&(s=n),0===s?0:(r.Je-=s,e.set(r.ct.subarray(r.lt,r.lt+s),t),r.lt+=s,r.$e+=s,s)},Ge(){const e=this;let t=e.Ze.pending;t>e.ft&&(t=e.ft),0!==t&&(e.ot.set(e.Ze.Fe.subarray(e.Ze.tt,e.Ze.tt+t),e.ut),e.ut+=t,e.Ze.tt+=t,e.et+=t,e.ft-=t,e.Ze.pending-=t,0===e.Ze.pending&&(e.Ze.tt=0))}};const Ue=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Te=[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],We=[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],He=[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],Le=[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],je=[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],Fe=[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];function Oe(){let e,t,n,r,s,i;function o(e,t,o,c,f,a,l,u,w,h,d){let p,y,m,b,g,k,v,S,C,z,_,I,x,A,D;z=0,g=o;do{n[e[t+z]]++,z++,g--}while(0!==g);if(n[0]==o)return l[0]=-1,u[0]=0,0;for(S=u[0],k=1;15>=k&&0===n[k];k++);for(v=k,k>S&&(S=k),g=15;0!==g&&0===n[g];g--);for(m=g,S>g&&(S=g),u[0]=S,A=1<<k;g>k;k++,A<<=1)if(0>(A-=n[k]))return-3;if(0>(A-=n[g]))return-3;for(n[g]+=A,i[1]=k=0,z=1,x=2;0!=--g;)i[x]=k+=n[z],x++,z++;g=0,z=0;do{0!==(k=e[t+z])&&(d[i[k]++]=g),z++}while(++g<o);for(o=i[m],i[0]=g=0,z=0,b=-1,I=-S,s[0]=0,_=0,D=0;m>=v;v++)for(p=n[v];0!=p--;){for(;v>I+S;){if(b++,I+=S,D=m-I,D=D>S?S:D,(y=1<<(k=v-I))>p+1&&(y-=p+1,x=v,D>k))for(;++k<D&&(y<<=1)>n[++x];)y-=n[x];if(D=1<<k,h[0]+D>1440)return-3;s[b]=_=h[0],h[0]+=D,0!==b?(i[b]=g,r[0]=k,r[1]=S,k=g>>>I-S,r[2]=_-s[b-1]-k,w.set(r,3*(s[b-1]+k))):l[0]=_}for(r[1]=v-I,o>z?d[z]<c?(r[0]=256>d[z]?0:96,r[2]=d[z++]):(r[0]=a[d[z]-c]+16+64,r[2]=f[d[z++]-c]):r[0]=192,y=1<<v-I,k=g>>>I;D>k;k+=y)w.set(r,3*(_+k));for(k=1<<v-1;0!=(g&k);k>>>=1)g^=k;for(g^=k,C=(1<<I)-1;(g&C)!=i[b];)b--,I-=S,C=(1<<I)-1}return 0!==A&&1!=m?-5:0}function f(o){let f;for(e||(e=[],t=[],n=new c(16),r=[],s=new c(15),i=new c(16)),t.length<o&&(t=[]),f=0;o>f;f++)t[f]=0;for(f=0;16>f;f++)n[f]=0;for(f=0;3>f;f++)r[f]=0;s.set(n.subarray(0,15),0),i.set(n.subarray(0,16),0)}this.wt=(n,r,s,i,c)=>{let a;return f(19),e[0]=0,a=o(n,0,19,19,null,null,s,r,i,e,t),-3==a?c.Ye="oversubscribed dynamic bit lengths tree":-5!=a&&0!==r[0]||(c.Ye="incomplete dynamic bit lengths tree",a=-3),a},this.ht=(n,r,s,i,c,a,l,u,w)=>{let h;return f(288),e[0]=0,h=o(s,0,n,257,He,Le,a,i,u,e,t),0!=h||0===i[0]?(-3==h?w.Ye="oversubscribed literal/length tree":-4!=h&&(w.Ye="incomplete literal/length tree",h=-3),h):(f(288),h=o(s,n,r,0,je,Fe,l,c,u,e,t),0!=h||0===c[0]&&n>257?(-3==h?w.Ye="oversubscribed distance tree":-5==h?(w.Ye="incomplete distance tree",h=-3):-4!=h&&(w.Ye="empty distance tree with lengths",h=-3),h):0)}}function qe(){const e=this;let t,n,r,s,i=0,o=0,c=0,f=0,a=0,l=0,u=0,w=0,h=0,d=0;function p(e,t,n,r,s,i,o,c){let f,a,l,u,w,h,d,p,y,m,b,g,k,v,S,C;d=c.lt,p=c.Je,w=o.dt,h=o.yt,y=o.write,m=y<o.read?o.read-y-1:o.end-y,b=Ue[e],g=Ue[t];do{for(;20>h;)p--,w|=(255&c.bt(d++))<<h,h+=8;if(f=w&b,a=n,l=r,C=3*(l+f),0!==(u=a[C]))for(;;){if(w>>=a[C+1],h-=a[C+1],0!=(16&u)){for(u&=15,k=a[C+2]+(w&Ue[u]),w>>=u,h-=u;15>h;)p--,w|=(255&c.bt(d++))<<h,h+=8;for(f=w&g,a=s,l=i,C=3*(l+f),u=a[C];;){if(w>>=a[C+1],h-=a[C+1],0!=(16&u)){for(u&=15;u>h;)p--,w|=(255&c.bt(d++))<<h,h+=8;if(v=a[C+2]+(w&Ue[u]),w>>=u,h-=u,m-=k,v>y){S=y-v;do{S+=o.end}while(0>S);if(u=o.end-S,k>u){if(k-=u,y-S>0&&u>y-S)do{o.gt[y++]=o.gt[S++]}while(0!=--u);else o.gt.set(o.gt.subarray(S,S+u),y),y+=u,S+=u,u=0;S=0}}else S=y-v,y-S>0&&2>y-S?(o.gt[y++]=o.gt[S++],o.gt[y++]=o.gt[S++],k-=2):(o.gt.set(o.gt.subarray(S,S+2),y),y+=2,S+=2,k-=2);if(y-S>0&&k>y-S)do{o.gt[y++]=o.gt[S++]}while(0!=--k);else o.gt.set(o.gt.subarray(S,S+k),y),y+=k,S+=k,k=0;break}if(0!=(64&u))return c.Ye="invalid distance code",k=c.Je-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.dt=w,o.yt=h,c.Je=p,c.$e+=d-c.lt,c.lt=d,o.write=y,-3;f+=a[C+2],f+=w&Ue[u],C=3*(l+f),u=a[C]}break}if(0!=(64&u))return 0!=(32&u)?(k=c.Je-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.dt=w,o.yt=h,c.Je=p,c.$e+=d-c.lt,c.lt=d,o.write=y,1):(c.Ye="invalid literal/length code",k=c.Je-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.dt=w,o.yt=h,c.Je=p,c.$e+=d-c.lt,c.lt=d,o.write=y,-3);if(f+=a[C+2],f+=w&Ue[u],C=3*(l+f),0===(u=a[C])){w>>=a[C+1],h-=a[C+1],o.gt[y++]=a[C+2],m--;break}}else w>>=a[C+1],h-=a[C+1],o.gt[y++]=a[C+2],m--}while(m>=258&&p>=10);return k=c.Je-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.dt=w,o.yt=h,c.Je=p,c.$e+=d-c.lt,c.lt=d,o.write=y,0}e.init=(e,i,o,c,f,a)=>{t=0,u=e,w=i,r=o,h=c,s=f,d=a,n=null},e.kt=(e,y,m)=>{let b,g,k,v,S,C,z,_=0,I=0,x=0;for(x=y.lt,v=y.Je,_=e.dt,I=e.yt,S=e.write,C=S<e.read?e.read-S-1:e.end-S;;)switch(t){case 0:if(C>=258&&v>=10&&(e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,m=p(u,w,r,h,s,d,e,y),x=y.lt,v=y.Je,_=e.dt,I=e.yt,S=e.write,C=S<e.read?e.read-S-1:e.end-S,0!=m)){t=1==m?7:9;break}c=u,n=r,o=h,t=1;case 1:for(b=c;b>I;){if(0===v)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,v--,_|=(255&y.bt(x++))<<I,I+=8}if(g=3*(o+(_&Ue[b])),_>>>=n[g+1],I-=n[g+1],k=n[g],0===k){f=n[g+2],t=6;break}if(0!=(16&k)){a=15&k,i=n[g+2],t=2;break}if(0==(64&k)){c=k,o=g/3+n[g+2];break}if(0!=(32&k)){t=7;break}return t=9,y.Ye="invalid literal/length code",m=-3,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);case 2:for(b=a;b>I;){if(0===v)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,v--,_|=(255&y.bt(x++))<<I,I+=8}i+=_&Ue[b],_>>=b,I-=b,c=w,n=s,o=d,t=3;case 3:for(b=c;b>I;){if(0===v)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,v--,_|=(255&y.bt(x++))<<I,I+=8}if(g=3*(o+(_&Ue[b])),_>>=n[g+1],I-=n[g+1],k=n[g],0!=(16&k)){a=15&k,l=n[g+2],t=4;break}if(0==(64&k)){c=k,o=g/3+n[g+2];break}return t=9,y.Ye="invalid distance code",m=-3,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);case 4:for(b=a;b>I;){if(0===v)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,v--,_|=(255&y.bt(x++))<<I,I+=8}l+=_&Ue[b],_>>=b,I-=b,t=5;case 5:for(z=S-l;0>z;)z+=e.end;for(;0!==i;){if(0===C&&(S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C&&(e.write=S,m=e.vt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C)))return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);e.gt[S++]=e.gt[z++],C--,z==e.end&&(z=0),i--}t=0;break;case 6:if(0===C&&(S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C&&(e.write=S,m=e.vt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C)))return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,e.gt[S++]=f,C--,t=0;break;case 7:if(I>7&&(I-=8,v++,x--),e.write=S,m=e.vt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,e.read!=e.write)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);t=8;case 8:return m=1,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);case 9:return m=-3,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);default:return m=-2,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m)}},e.St=()=>{}}Oe.Ct=(e,t,n,r)=>(e[0]=9,t[0]=5,n[0]=Te,r[0]=We,0);const Ge=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function Je(e,t){const n=this;let r,i=0,o=0,f=0,a=0;const l=[0],u=[0],w=new qe;let h=0,d=new c(4320);const p=new Oe;n.yt=0,n.dt=0,n.gt=new s(t),n.end=t,n.read=0,n.write=0,n.reset=(e,t)=>{t&&(t[0]=0),6==i&&w.St(e),i=0,n.yt=0,n.dt=0,n.read=n.write=0},n.reset(e,null),n.vt=(e,t)=>{let r,s,i;return s=e.ut,i=n.read,r=(i>n.write?n.end:n.write)-i,r>e.ft&&(r=e.ft),0!==r&&-5==t&&(t=0),e.ft-=r,e.et+=r,e.ot.set(n.gt.subarray(i,i+r),s),s+=r,i+=r,i==n.end&&(i=0,n.write==n.end&&(n.write=0),r=n.write-i,r>e.ft&&(r=e.ft),0!==r&&-5==t&&(t=0),e.ft-=r,e.et+=r,e.ot.set(n.gt.subarray(i,i+r),s),s+=r,i+=r),e.ut=s,n.read=i,t},n.kt=(e,t)=>{let s,c,y,m,b,g,k,v;for(m=e.lt,b=e.Je,c=n.dt,y=n.yt,g=n.write,k=g<n.read?n.read-g-1:n.end-g;;){let S,C,z,_,I,x,A,D;switch(i){case 0:for(;3>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}switch(s=7&c,h=1&s,s>>>1){case 0:c>>>=3,y-=3,s=7&y,c>>>=s,y-=s,i=1;break;case 1:S=[],C=[],z=[[]],_=[[]],Oe.Ct(S,C,z,_),w.init(S[0],C[0],z[0],0,_[0],0),c>>>=3,y-=3,i=6;break;case 2:c>>>=3,y-=3,i=3;break;case 3:return c>>>=3,y-=3,i=9,e.Ye="invalid block type",t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t)}break;case 1:for(;32>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}if((~c>>>16&65535)!=(65535&c))return i=9,e.Ye="invalid stored block lengths",t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);o=65535&c,c=y=0,i=0!==o?2:0!==h?7:0;break;case 2:if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);if(0===k&&(g==n.end&&0!==n.read&&(g=0,k=g<n.read?n.read-g-1:n.end-g),0===k&&(n.write=g,t=n.vt(e,t),g=n.write,k=g<n.read?n.read-g-1:n.end-g,g==n.end&&0!==n.read&&(g=0,k=g<n.read?n.read-g-1:n.end-g),0===k)))return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);if(t=0,s=o,s>b&&(s=b),s>k&&(s=k),n.gt.set(e.Qe(m,s),g),m+=s,b-=s,g+=s,k-=s,0!=(o-=s))break;i=0!==h?7:0;break;case 3:for(;14>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}if(f=s=16383&c,(31&s)>29||(s>>5&31)>29)return i=9,e.Ye="too many length or distance symbols",t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);if(s=258+(31&s)+(s>>5&31),!r||r.length<s)r=[];else for(v=0;s>v;v++)r[v]=0;c>>>=14,y-=14,a=0,i=4;case 4:for(;4+(f>>>10)>a;){for(;3>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}r[Ge[a++]]=7&c,c>>>=3,y-=3}for(;19>a;)r[Ge[a++]]=0;if(l[0]=7,s=p.wt(r,l,u,d,e),0!=s)return-3==(t=s)&&(r=null,i=9),n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);a=0,i=5;case 5:for(;s=f,258+(31&s)+(s>>5&31)>a;){let o,w;for(s=l[0];s>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}if(s=d[3*(u[0]+(c&Ue[s]))+1],w=d[3*(u[0]+(c&Ue[s]))+2],16>w)c>>>=s,y-=s,r[a++]=w;else{for(v=18==w?7:w-14,o=18==w?11:3;s+v>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}if(c>>>=s,y-=s,o+=c&Ue[v],c>>>=v,y-=v,v=a,s=f,v+o>258+(31&s)+(s>>5&31)||16==w&&1>v)return r=null,i=9,e.Ye="invalid bit length repeat",t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);w=16==w?r[v-1]:0;do{r[v++]=w}while(0!=--o);a=v}}if(u[0]=-1,I=[],x=[],A=[],D=[],I[0]=9,x[0]=6,s=f,s=p.ht(257+(31&s),1+(s>>5&31),r,I,x,A,D,d,e),0!=s)return-3==s&&(r=null,i=9),t=s,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);w.init(I[0],x[0],d,A[0],d,D[0]),i=6;case 6:if(n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,1!=(t=w.kt(n,e,t)))return n.vt(e,t);if(t=0,w.St(e),m=e.lt,b=e.Je,c=n.dt,y=n.yt,g=n.write,k=g<n.read?n.read-g-1:n.end-g,0===h){i=0;break}i=7;case 7:if(n.write=g,t=n.vt(e,t),g=n.write,k=g<n.read?n.read-g-1:n.end-g,n.read!=n.write)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);i=8;case 8:return t=1,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);case 9:return t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);default:return t=-2,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t)}}},n.St=e=>{n.reset(e,null),n.gt=null,d=null},n.zt=(e,t,r)=>{n.gt.set(e.subarray(t,t+r),0),n.read=n.write=r},n._t=()=>1==i?1:0}const Qe=[0,0,255,255];function Xe(){const e=this;function t(e){return e&&e.It?(e.$e=e.et=0,e.Ye=null,e.It.mode=7,e.It.xt.reset(e,null),0):-2}e.mode=0,e.method=0,e.At=[0],e.Dt=0,e.marker=0,e.Vt=0,e.Rt=t=>(e.xt&&e.xt.St(t),e.xt=null,0),e.Bt=(n,r)=>(n.Ye=null,e.xt=null,8>r||r>15?(e.Rt(n),-2):(e.Vt=r,n.It.xt=new Je(n,1<<r),t(n),0)),e.Et=(e,t)=>{let n,r;if(!e||!e.It||!e.ct)return-2;const s=e.It;for(t=4==t?-5:0,n=-5;;)switch(s.mode){case 0:if(0===e.Je)return n;if(n=t,e.Je--,e.$e++,8!=(15&(s.method=e.bt(e.lt++)))){s.mode=13,e.Ye="unknown compression method",s.marker=5;break}if(8+(s.method>>4)>s.Vt){s.mode=13,e.Ye="invalid win size",s.marker=5;break}s.mode=1;case 1:if(0===e.Je)return n;if(n=t,e.Je--,e.$e++,r=255&e.bt(e.lt++),((s.method<<8)+r)%31!=0){s.mode=13,e.Ye="incorrect header check",s.marker=5;break}if(0==(32&r)){s.mode=7;break}s.mode=2;case 2:if(0===e.Je)return n;n=t,e.Je--,e.$e++,s.Dt=(255&e.bt(e.lt++))<<24&4278190080,s.mode=3;case 3:if(0===e.Je)return n;n=t,e.Je--,e.$e++,s.Dt+=(255&e.bt(e.lt++))<<16&16711680,s.mode=4;case 4:if(0===e.Je)return n;n=t,e.Je--,e.$e++,s.Dt+=(255&e.bt(e.lt++))<<8&65280,s.mode=5;case 5:return 0===e.Je?n:(n=t,e.Je--,e.$e++,s.Dt+=255&e.bt(e.lt++),s.mode=6,2);case 6:return s.mode=13,e.Ye="need dictionary",s.marker=0,-2;case 7:if(n=s.xt.kt(e,n),-3==n){s.mode=13,s.marker=0;break}if(0==n&&(n=t),1!=n)return n;n=t,s.xt.reset(e,s.At),s.mode=12;case 12:return e.Je=0,1;case 13:return-3;default:return-2}},e.Mt=(e,t,n)=>{let r=0,s=n;if(!e||!e.It||6!=e.It.mode)return-2;const i=e.It;return s<1<<i.Vt||(s=(1<<i.Vt)-1,r=n-s),i.xt.zt(t,r,s),i.mode=7,0},e.Kt=e=>{let n,r,s,i,o;if(!e||!e.It)return-2;const c=e.It;if(13!=c.mode&&(c.mode=13,c.marker=0),0===(n=e.Je))return-5;for(r=e.lt,s=c.marker;0!==n&&4>s;)e.bt(r)==Qe[s]?s++:s=0!==e.bt(r)?0:4-s,r++,n--;return e.$e+=r-e.lt,e.lt=r,e.Je=n,c.marker=s,4!=s?-3:(i=e.$e,o=e.et,t(e),e.$e=i,e.et=o,c.mode=7,0)},e.Nt=e=>e&&e.It&&e.It.xt?e.It.xt._t():-2}function Ye(){}function Ze(e){const t=new Ye,i=e&&e.chunkSize?n.floor(2*e.chunkSize):131072,o=new s(i);let c=!1;t.Bt(),t.ot=o,this.append=(e,n)=>{const f=[];let a,l,u=0,w=0,h=0;if(0!==e.length){t.lt=0,t.ct=e,t.Je=e.length;do{if(t.ut=0,t.ft=i,0!==t.Je||c||(t.lt=0,c=!0),a=t.Et(0),c&&-5===a){if(0!==t.Je)throw new r("inflating: bad input")}else if(0!==a&&1!==a)throw new r("inflating: "+t.Ye);if((c||1===a)&&t.Je===e.length)throw new r("inflating: bad input");t.ut&&(t.ut===i?f.push(new s(o)):f.push(o.slice(0,t.ut))),h+=t.ut,n&&t.lt>0&&t.lt!=u&&(n(t.lt),u=t.lt)}while(t.Je>0||0===t.ft);return f.length>1?(l=new s(h),f.forEach((e=>{l.set(e,w),w+=e.length}))):l=f[0]||new s,l}},this.flush=()=>{t.Rt()}}Ye.prototype={Bt(e){const t=this;return t.It=new Xe,e||(e=15),t.It.Bt(t,e)},Et(e){const t=this;return t.It?t.It.Et(t,e):-2},Rt(){const e=this;if(!e.It)return-2;const t=e.It.Rt(e);return e.It=null,t},Kt(){const e=this;return e.It?e.It.Kt(e):-2},Mt(e,t){const n=this;return n.It?n.It.Mt(n,e,t):-2},bt(e){return this.ct[e]},Qe(e,t){return this.ct.subarray(e,e+t)}},self.initCodec=()=>{self.Deflate=Pe,self.Inflate=Ze};\n'],{type:"text/javascript"}));e({workerScripts:{inflate:[t],deflate:[t]}});}
|
|
1840
|
+
|
|
1841
|
+
/*
|
|
1842
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1843
|
+
|
|
1844
|
+
Redistribution and use in source and binary forms, with or without
|
|
1845
|
+
modification, are permitted provided that the following conditions are met:
|
|
1846
|
+
|
|
1847
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1848
|
+
this list of conditions and the following disclaimer.
|
|
1849
|
+
|
|
1850
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1851
|
+
notice, this list of conditions and the following disclaimer in
|
|
1852
|
+
the documentation and/or other materials provided with the distribution.
|
|
1853
|
+
|
|
1854
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1855
|
+
derived from this software without specific prior written permission.
|
|
1856
|
+
|
|
1857
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1858
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1859
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1860
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1861
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1862
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1863
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1864
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1865
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1866
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1867
|
+
*/
|
|
1868
|
+
|
|
1869
|
+
function getMimeType() {
|
|
1870
|
+
return "application/octet-stream";
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
function initShimAsyncCodec(library, options = {}, registerDataHandler) {
|
|
1874
|
+
return {
|
|
1875
|
+
Deflate: createCodecClass(library.Deflate, options.deflate, registerDataHandler),
|
|
1876
|
+
Inflate: createCodecClass(library.Inflate, options.inflate, registerDataHandler)
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
function createCodecClass(constructor, constructorOptions, registerDataHandler) {
|
|
1881
|
+
return class {
|
|
1882
|
+
|
|
1883
|
+
constructor(options) {
|
|
1884
|
+
const codecAdapter = this;
|
|
1885
|
+
const onData = data => {
|
|
1886
|
+
if (codecAdapter.pendingData) {
|
|
1887
|
+
const { pendingData } = codecAdapter;
|
|
1888
|
+
codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
|
|
1889
|
+
pendingData.set(pendingData, 0);
|
|
1890
|
+
pendingData.set(data, pendingData.length);
|
|
1891
|
+
} else {
|
|
1892
|
+
codecAdapter.pendingData = new Uint8Array(data);
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
if (Object.hasOwn(options, "level") && options.level === undefined) {
|
|
1896
|
+
delete options.level;
|
|
1897
|
+
}
|
|
1898
|
+
codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
|
|
1899
|
+
registerDataHandler(codecAdapter.codec, onData);
|
|
1900
|
+
}
|
|
1901
|
+
append(data) {
|
|
1902
|
+
this.codec.push(data);
|
|
1903
|
+
return getResponse(this);
|
|
1904
|
+
}
|
|
1905
|
+
flush() {
|
|
1906
|
+
this.codec.push(new Uint8Array(), true);
|
|
1907
|
+
return getResponse(this);
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
|
|
1911
|
+
function getResponse(codec) {
|
|
1912
|
+
if (codec.pendingData) {
|
|
1913
|
+
const output = codec.pendingData;
|
|
1914
|
+
codec.pendingData = null;
|
|
1915
|
+
return output;
|
|
1916
|
+
} else {
|
|
1917
|
+
return new Uint8Array();
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
/*
|
|
1923
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1924
|
+
|
|
1925
|
+
Redistribution and use in source and binary forms, with or without
|
|
1926
|
+
modification, are permitted provided that the following conditions are met:
|
|
1927
|
+
|
|
1928
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1929
|
+
this list of conditions and the following disclaimer.
|
|
1930
|
+
|
|
1931
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1932
|
+
notice, this list of conditions and the following disclaimer in
|
|
1933
|
+
the documentation and/or other materials provided with the distribution.
|
|
1934
|
+
|
|
1935
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1936
|
+
derived from this software without specific prior written permission.
|
|
1937
|
+
|
|
1938
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1939
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1940
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1941
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1942
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1943
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1944
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1945
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1946
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1947
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1948
|
+
*/
|
|
1949
|
+
|
|
1950
|
+
let workersSupported;
|
|
1951
|
+
let classicWorkersSupported = true;
|
|
1952
|
+
let transferStreamsSupported = true;
|
|
1953
|
+
|
|
1954
|
+
class CodecWorker {
|
|
1955
|
+
|
|
1956
|
+
constructor(workerData, stream, workerOptions, onTaskFinished) {
|
|
1957
|
+
const { readable, writable } = stream;
|
|
1958
|
+
const { options, config, streamOptions, useWebWorkers, transferStreams, scripts } = workerOptions;
|
|
1959
|
+
Object.assign(workerData, {
|
|
1960
|
+
busy: true,
|
|
1961
|
+
readable,
|
|
1962
|
+
writable,
|
|
1963
|
+
options: Object.assign({}, options),
|
|
1964
|
+
scripts,
|
|
1965
|
+
transferStreams,
|
|
1966
|
+
terminate() {
|
|
1967
|
+
if (workerData.worker && !workerData.busy) {
|
|
1968
|
+
workerData.worker.terminate();
|
|
1969
|
+
workerData.interface = null;
|
|
1970
|
+
}
|
|
1971
|
+
},
|
|
1972
|
+
onTaskFinished() {
|
|
1973
|
+
workerData.busy = false;
|
|
1974
|
+
onTaskFinished(workerData);
|
|
1975
|
+
}
|
|
1976
|
+
});
|
|
1977
|
+
const { signal, onstart, onprogress, size, onend } = streamOptions;
|
|
1978
|
+
let chunkOffset = 0;
|
|
1979
|
+
const transformer = {};
|
|
1980
|
+
if (onstart) {
|
|
1981
|
+
transformer.start = () => callHandler(onstart, size);
|
|
1982
|
+
}
|
|
1983
|
+
transformer.transform = async (chunk, controller) => {
|
|
1984
|
+
chunkOffset += chunk.length;
|
|
1985
|
+
if (onprogress) {
|
|
1986
|
+
await callHandler(onprogress, chunkOffset, size);
|
|
1987
|
+
}
|
|
1988
|
+
controller.enqueue(chunk);
|
|
1989
|
+
};
|
|
1990
|
+
transformer.flush = () => {
|
|
1991
|
+
readable.size = chunkOffset;
|
|
1992
|
+
if (onend) {
|
|
1993
|
+
callHandler(onend, chunkOffset);
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
|
|
1997
|
+
if (workersSupported === undefined) {
|
|
1998
|
+
workersSupported = typeof Worker != "undefined";
|
|
1999
|
+
}
|
|
2000
|
+
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
async function callHandler(handler, ...parameters) {
|
|
2005
|
+
try {
|
|
2006
|
+
await handler(...parameters);
|
|
2007
|
+
} catch (_error) {
|
|
2008
|
+
// ignored
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
function createWorkerInterface(workerData, config) {
|
|
2013
|
+
const interfaceCodec = new Codec(workerData.readable, workerData.writable, workerData.options, config);
|
|
2014
|
+
const { onTaskFinished } = workerData;
|
|
2015
|
+
const codec = {
|
|
2016
|
+
async run() {
|
|
2017
|
+
try {
|
|
2018
|
+
return await interfaceCodec.run();
|
|
2019
|
+
} finally {
|
|
2020
|
+
onTaskFinished();
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
};
|
|
2024
|
+
return codec;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
2028
|
+
const workerOptions = { type: "module" };
|
|
2029
|
+
Object.assign(workerData, {
|
|
2030
|
+
streams: {},
|
|
2031
|
+
result: new Promise((resolve, reject) => {
|
|
2032
|
+
workerData.resolveResult = resolve;
|
|
2033
|
+
workerData.rejectResult = reject;
|
|
2034
|
+
})
|
|
2035
|
+
});
|
|
2036
|
+
if (!workerData.interface) {
|
|
2037
|
+
if (!classicWorkersSupported) {
|
|
2038
|
+
workerData.worker = getWorker(workerOptions);
|
|
2039
|
+
} else {
|
|
2040
|
+
try {
|
|
2041
|
+
workerData.worker = getWorker({});
|
|
2042
|
+
} catch (_error) {
|
|
2043
|
+
classicWorkersSupported = false;
|
|
2044
|
+
workerData.worker = getWorker(workerOptions);
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
|
|
2048
|
+
workerData.interface = {
|
|
2049
|
+
async run() {
|
|
2050
|
+
const { readable, options } = workerData;
|
|
2051
|
+
const writer = workerData.writable.getWriter();
|
|
2052
|
+
let resolveStreamClosed, streamClosed;
|
|
2053
|
+
streamClosed = new Promise(resolve => resolveStreamClosed = resolve);
|
|
2054
|
+
const writable = new WritableStream({
|
|
2055
|
+
async write(chunk) {
|
|
2056
|
+
await writer.ready;
|
|
2057
|
+
await writer.write(new Uint8Array(chunk));
|
|
2058
|
+
},
|
|
2059
|
+
async close() {
|
|
2060
|
+
writer.releaseLock();
|
|
2061
|
+
resolveStreamClosed();
|
|
2062
|
+
},
|
|
2063
|
+
abort(reason) {
|
|
2064
|
+
writer.abort(reason);
|
|
2065
|
+
}
|
|
2066
|
+
});
|
|
2067
|
+
const scripts = workerData.scripts.slice(1);
|
|
2068
|
+
const message = { type: MESSAGE_START, scripts, options, config: { chunkSize } };
|
|
2069
|
+
if (workerData.transferStreams && transferStreamsSupported) {
|
|
2070
|
+
const streamsTransferred = sendMessage({ ...message, readable, writable });
|
|
2071
|
+
if (!streamsTransferred) {
|
|
2072
|
+
transferStreamsSupported = false;
|
|
2073
|
+
initStreams(readable, writable);
|
|
2074
|
+
}
|
|
2075
|
+
} else {
|
|
2076
|
+
sendMessage(message);
|
|
2077
|
+
initStreams(readable, writable);
|
|
2078
|
+
}
|
|
2079
|
+
const result = await workerData.result;
|
|
2080
|
+
try {
|
|
2081
|
+
await writable.close();
|
|
2082
|
+
} catch (_error) {
|
|
2083
|
+
// ignored
|
|
2084
|
+
}
|
|
2085
|
+
await streamClosed;
|
|
2086
|
+
return result;
|
|
2087
|
+
}
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
return workerData.interface;
|
|
2091
|
+
|
|
2092
|
+
function initStreams(readable, writable) {
|
|
2093
|
+
Object.assign(workerData.streams, {
|
|
2094
|
+
reader: readable.getReader(),
|
|
2095
|
+
writer: writable.getWriter()
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
function getWorker(options) {
|
|
2100
|
+
let url, scriptUrl;
|
|
2101
|
+
url = workerData.scripts[0];
|
|
2102
|
+
if (typeof url == "function") {
|
|
2103
|
+
url = url();
|
|
2104
|
+
}
|
|
2105
|
+
try {
|
|
2106
|
+
scriptUrl = new URL(url, baseURL);
|
|
2107
|
+
} catch (_error) {
|
|
2108
|
+
scriptUrl = url;
|
|
2109
|
+
}
|
|
2110
|
+
return new Worker(scriptUrl, options);
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
function sendMessage(message) {
|
|
2114
|
+
const { worker, writer, onTaskFinished } = workerData;
|
|
2115
|
+
try {
|
|
2116
|
+
let { data, readable, writable } = message;
|
|
2117
|
+
const transferrables = [];
|
|
2118
|
+
if (data) {
|
|
2119
|
+
const { buffer, length } = data;
|
|
2120
|
+
if (length != buffer.byteLength) {
|
|
2121
|
+
data = new Uint8Array(data);
|
|
2122
|
+
}
|
|
2123
|
+
message.data = data.buffer;
|
|
2124
|
+
transferrables.push(message.data);
|
|
2125
|
+
}
|
|
2126
|
+
if (readable) {
|
|
2127
|
+
transferrables.push(readable);
|
|
2128
|
+
}
|
|
2129
|
+
if (writable) {
|
|
2130
|
+
transferrables.push(writable);
|
|
2131
|
+
}
|
|
2132
|
+
if (transferrables.length) {
|
|
2133
|
+
try {
|
|
2134
|
+
worker.postMessage(message, transferrables);
|
|
2135
|
+
return true;
|
|
2136
|
+
} catch (error) {
|
|
2137
|
+
message.readable = message.writable = null;
|
|
2138
|
+
worker.postMessage(message);
|
|
2139
|
+
}
|
|
2140
|
+
} else {
|
|
2141
|
+
worker.postMessage(message);
|
|
2142
|
+
}
|
|
2143
|
+
} catch (error) {
|
|
2144
|
+
if (writer) {
|
|
2145
|
+
writer.releaseLock();
|
|
2146
|
+
}
|
|
2147
|
+
onTaskFinished();
|
|
2148
|
+
throw error;
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
async function onMessage(event) {
|
|
2153
|
+
const message = event.data;
|
|
2154
|
+
const { resolveResult, rejectResult, onTaskFinished } = workerData;
|
|
2155
|
+
const { reader, writer } = workerData.streams;
|
|
2156
|
+
const { type, data, messageId, result } = message;
|
|
2157
|
+
const reponseError = message.error;
|
|
2158
|
+
try {
|
|
2159
|
+
if (reponseError) {
|
|
2160
|
+
const { message, stack, code, name } = reponseError;
|
|
2161
|
+
const error = new Error(message);
|
|
2162
|
+
Object.assign(error, { stack, code, name });
|
|
2163
|
+
close(error);
|
|
2164
|
+
} else {
|
|
2165
|
+
if (type == MESSAGE_PULL) {
|
|
2166
|
+
const { value, done } = await reader.read();
|
|
2167
|
+
sendMessage({ type: MESSAGE_DATA, data: value, done, messageId });
|
|
2168
|
+
}
|
|
2169
|
+
if (type == MESSAGE_DATA) {
|
|
2170
|
+
await writer.ready;
|
|
2171
|
+
await writer.write(new Uint8Array(data));
|
|
2172
|
+
sendMessage({ type: MESSAGE_ACK_DATA, messageId });
|
|
2173
|
+
}
|
|
2174
|
+
if (type == MESSAGE_CLOSE) {
|
|
2175
|
+
close(null, result);
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
} catch (error) {
|
|
2179
|
+
close(error);
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
function close(error, result) {
|
|
2183
|
+
if (error) {
|
|
2184
|
+
rejectResult(error);
|
|
2185
|
+
} else {
|
|
2186
|
+
resolveResult(result);
|
|
2187
|
+
}
|
|
2188
|
+
if (writer) {
|
|
2189
|
+
writer.releaseLock();
|
|
2190
|
+
}
|
|
2191
|
+
onTaskFinished();
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
/*
|
|
2197
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2198
|
+
|
|
2199
|
+
Redistribution and use in source and binary forms, with or without
|
|
2200
|
+
modification, are permitted provided that the following conditions are met:
|
|
2201
|
+
|
|
2202
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
2203
|
+
this list of conditions and the following disclaimer.
|
|
2204
|
+
|
|
2205
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2206
|
+
notice, this list of conditions and the following disclaimer in
|
|
2207
|
+
the documentation and/or other materials provided with the distribution.
|
|
2208
|
+
|
|
2209
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
2210
|
+
derived from this software without specific prior written permission.
|
|
2211
|
+
|
|
2212
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
2213
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
2214
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
2215
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
2216
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
2217
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
2218
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
2219
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
2220
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
2221
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2222
|
+
*/
|
|
2223
|
+
|
|
2224
|
+
let pool = [];
|
|
2225
|
+
const pendingRequests = [];
|
|
2226
|
+
|
|
2227
|
+
let indexWorker = 0;
|
|
2228
|
+
|
|
2229
|
+
async function runWorker(stream, workerOptions) {
|
|
2230
|
+
const { options, config } = workerOptions;
|
|
2231
|
+
const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
|
|
2232
|
+
const { workerScripts } = config;
|
|
2233
|
+
workerOptions.transferStreams = transferStreams || transferStreams === undefined;
|
|
2234
|
+
const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
|
|
2235
|
+
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === undefined && config.useWebWorkers));
|
|
2236
|
+
workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
|
|
2237
|
+
options.useCompressionStream = useCompressionStream || (useCompressionStream === undefined && config.useCompressionStream);
|
|
2238
|
+
let worker;
|
|
2239
|
+
if (pool.length < config.maxWorkers) {
|
|
2240
|
+
const workerData = { indexWorker };
|
|
2241
|
+
indexWorker++;
|
|
2242
|
+
pool.push(workerData);
|
|
2243
|
+
worker = new CodecWorker(workerData, stream, workerOptions, onTaskFinished);
|
|
2244
|
+
} else {
|
|
2245
|
+
const workerData = pool.find(workerData => !workerData.busy);
|
|
2246
|
+
if (workerData) {
|
|
2247
|
+
clearTerminateTimeout(workerData);
|
|
2248
|
+
worker = new CodecWorker(workerData, stream, workerOptions, onTaskFinished);
|
|
2249
|
+
} else {
|
|
2250
|
+
worker = await new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
return worker.run();
|
|
2254
|
+
|
|
2255
|
+
function onTaskFinished(workerData) {
|
|
2256
|
+
if (pendingRequests.length) {
|
|
2257
|
+
const [{ resolve, stream, workerOptions }] = pendingRequests.splice(0, 1);
|
|
2258
|
+
resolve(new CodecWorker(workerData, stream, workerOptions, onTaskFinished));
|
|
2259
|
+
} else if (workerData.worker) {
|
|
2260
|
+
const { terminateWorkerTimeout } = config;
|
|
2261
|
+
clearTerminateTimeout(workerData);
|
|
2262
|
+
if (Number.isFinite(terminateWorkerTimeout) && terminateWorkerTimeout >= 0) {
|
|
2263
|
+
workerData.terminateTimeout = setTimeout(() => {
|
|
2264
|
+
pool = pool.filter(data => data != workerData);
|
|
2265
|
+
workerData.terminate();
|
|
2266
|
+
}, terminateWorkerTimeout);
|
|
2267
|
+
}
|
|
2268
|
+
} else {
|
|
2269
|
+
pool = pool.filter(data => data != workerData);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
function clearTerminateTimeout(workerData) {
|
|
2275
|
+
const { terminateTimeout } = workerData;
|
|
2276
|
+
if (terminateTimeout) {
|
|
2277
|
+
clearTimeout(terminateTimeout);
|
|
2278
|
+
workerData.terminateTimeout = null;
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
function terminateWorkers() {
|
|
2283
|
+
pool.forEach(workerData => {
|
|
2284
|
+
clearTerminateTimeout(workerData);
|
|
2285
|
+
workerData.terminate();
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
/*
|
|
2290
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2291
|
+
|
|
2292
|
+
Redistribution and use in source and binary forms, with or without
|
|
2293
|
+
modification, are permitted provided that the following conditions are met:
|
|
2294
|
+
|
|
2295
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
2296
|
+
this list of conditions and the following disclaimer.
|
|
2297
|
+
|
|
2298
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2299
|
+
notice, this list of conditions and the following disclaimer in
|
|
2300
|
+
the documentation and/or other materials provided with the distribution.
|
|
2301
|
+
|
|
2302
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
2303
|
+
derived from this software without specific prior written permission.
|
|
2304
|
+
|
|
2305
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
2306
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
2307
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
2308
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
2309
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
2310
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
2311
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
2312
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
2313
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
2314
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2315
|
+
*/
|
|
2316
|
+
|
|
2317
|
+
/* global Blob, atob, btoa, XMLHttpRequest, URL, fetch, ReadableStream, WritableStream, FileReader, TransformStream, Response */
|
|
2318
|
+
|
|
2319
|
+
const ERR_HTTP_STATUS = "HTTP error ";
|
|
2320
|
+
const ERR_HTTP_RANGE = "HTTP Range not supported";
|
|
2321
|
+
|
|
2322
|
+
const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
|
|
2323
|
+
const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
|
|
2324
|
+
const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
|
|
2325
|
+
const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
|
|
2326
|
+
const HTTP_HEADER_RANGE = "Range";
|
|
2327
|
+
const HTTP_METHOD_HEAD = "HEAD";
|
|
2328
|
+
const HTTP_METHOD_GET = "GET";
|
|
2329
|
+
const HTTP_RANGE_UNIT = "bytes";
|
|
2330
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2331
|
+
|
|
2332
|
+
class Stream {
|
|
2333
|
+
|
|
2334
|
+
constructor() {
|
|
2335
|
+
this.size = 0;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
init() {
|
|
2339
|
+
this.initialized = true;
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
class Reader extends Stream {
|
|
2344
|
+
|
|
2345
|
+
get readable() {
|
|
2346
|
+
const reader = this;
|
|
2347
|
+
const { chunkSize = DEFAULT_CHUNK_SIZE } = reader;
|
|
2348
|
+
const readable = new ReadableStream({
|
|
2349
|
+
start() {
|
|
2350
|
+
this.chunkOffset = 0;
|
|
2351
|
+
},
|
|
2352
|
+
async pull(controller) {
|
|
2353
|
+
const { offset = 0, size, diskNumberStart } = readable;
|
|
2354
|
+
const { chunkOffset } = this;
|
|
2355
|
+
controller.enqueue(await readUint8Array(reader, offset + chunkOffset, Math.min(chunkSize, size - chunkOffset), diskNumberStart));
|
|
2356
|
+
if (chunkOffset + chunkSize > size) {
|
|
2357
|
+
controller.close();
|
|
2358
|
+
} else {
|
|
2359
|
+
this.chunkOffset += chunkSize;
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
});
|
|
2363
|
+
return readable;
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
class Writer extends Stream {
|
|
2368
|
+
|
|
2369
|
+
constructor() {
|
|
2370
|
+
super();
|
|
2371
|
+
const writer = this;
|
|
2372
|
+
const writable = new WritableStream({
|
|
2373
|
+
write(chunk) {
|
|
2374
|
+
return writer.writeUint8Array(chunk);
|
|
2375
|
+
}
|
|
2376
|
+
});
|
|
2377
|
+
Object.defineProperty(writer, "writable", {
|
|
2378
|
+
get() {
|
|
2379
|
+
return writable;
|
|
2380
|
+
}
|
|
2381
|
+
});
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
writeUint8Array() {
|
|
2385
|
+
// abstract
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
class Data64URIReader extends Reader {
|
|
2390
|
+
|
|
2391
|
+
constructor(dataURI) {
|
|
2392
|
+
super();
|
|
2393
|
+
const reader = this;
|
|
2394
|
+
reader.dataURI = dataURI;
|
|
2395
|
+
let dataEnd = dataURI.length;
|
|
2396
|
+
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
2397
|
+
dataEnd--;
|
|
2398
|
+
}
|
|
2399
|
+
reader.dataStart = dataURI.indexOf(",") + 1;
|
|
2400
|
+
reader.size = Math.floor((dataEnd - reader.dataStart) * 0.75);
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
readUint8Array(offset, length) {
|
|
2404
|
+
const dataArray = new Uint8Array(length);
|
|
2405
|
+
const start = Math.floor(offset / 3) * 4;
|
|
2406
|
+
const dataStart = this.dataStart;
|
|
2407
|
+
const bytes = atob(this.dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
2408
|
+
const delta = offset - Math.floor(start / 4) * 3;
|
|
2409
|
+
for (let indexByte = delta; indexByte < delta + length; indexByte++) {
|
|
2410
|
+
dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
|
|
2411
|
+
}
|
|
2412
|
+
return dataArray;
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
class Data64URIWriter extends Writer {
|
|
2417
|
+
|
|
2418
|
+
constructor(contentType) {
|
|
2419
|
+
super();
|
|
2420
|
+
this.data = "data:" + (contentType || "") + ";base64,";
|
|
2421
|
+
this.pending = [];
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
writeUint8Array(array) {
|
|
2425
|
+
const writer = this;
|
|
2426
|
+
let indexArray = 0;
|
|
2427
|
+
let dataString = writer.pending;
|
|
2428
|
+
const delta = writer.pending.length;
|
|
2429
|
+
writer.pending = "";
|
|
2430
|
+
for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
|
|
2431
|
+
dataString += String.fromCharCode(array[indexArray]);
|
|
2432
|
+
}
|
|
2433
|
+
for (; indexArray < array.length; indexArray++) {
|
|
2434
|
+
writer.pending += String.fromCharCode(array[indexArray]);
|
|
2435
|
+
}
|
|
2436
|
+
if (dataString.length > 2) {
|
|
2437
|
+
writer.data += btoa(dataString);
|
|
2438
|
+
} else {
|
|
2439
|
+
writer.pending = dataString;
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2443
|
+
getData() {
|
|
2444
|
+
return this.data + btoa(this.pending);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
class BlobReader extends Reader {
|
|
2449
|
+
|
|
2450
|
+
constructor(blob) {
|
|
2451
|
+
super();
|
|
2452
|
+
this.blob = blob;
|
|
2453
|
+
this.size = blob.size;
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
async readUint8Array(offset, length) {
|
|
2457
|
+
const reader = this;
|
|
2458
|
+
return new Uint8Array(await reader.blob.slice(offset, offset + length).arrayBuffer());
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
class BlobWriter extends Stream {
|
|
2463
|
+
|
|
2464
|
+
constructor(contentType) {
|
|
2465
|
+
super();
|
|
2466
|
+
const writer = this;
|
|
2467
|
+
const transformStream = new TransformStream();
|
|
2468
|
+
const headers = [];
|
|
2469
|
+
if (contentType) {
|
|
2470
|
+
headers.push(["content-type", contentType]);
|
|
2471
|
+
}
|
|
2472
|
+
Object.defineProperty(writer, "writable", {
|
|
2473
|
+
get() {
|
|
2474
|
+
return transformStream.writable;
|
|
2475
|
+
}
|
|
2476
|
+
});
|
|
2477
|
+
writer.blob = new Response(transformStream.readable, { headers }).blob();
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
getData() {
|
|
2481
|
+
return this.blob;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
class TextReader extends BlobReader {
|
|
2486
|
+
|
|
2487
|
+
constructor(text) {
|
|
2488
|
+
super(new Blob([text], { type: CONTENT_TYPE_TEXT_PLAIN }));
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
class TextWriter extends BlobWriter {
|
|
2493
|
+
|
|
2494
|
+
constructor(encoding) {
|
|
2495
|
+
super(encoding);
|
|
2496
|
+
Object.assign(this, {
|
|
2497
|
+
encoding,
|
|
2498
|
+
utf8: !encoding || encoding.toLowerCase() == "utf-8"
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
async getData() {
|
|
2503
|
+
const {
|
|
2504
|
+
encoding,
|
|
2505
|
+
utf8
|
|
2506
|
+
} = this;
|
|
2507
|
+
const blob = await super.getData();
|
|
2508
|
+
if (blob.text && utf8) {
|
|
2509
|
+
return blob.text();
|
|
2510
|
+
} else {
|
|
2511
|
+
const reader = new FileReader();
|
|
2512
|
+
return new Promise((resolve, reject) => {
|
|
2513
|
+
reader.onload = ({ target }) => resolve(target.result);
|
|
2514
|
+
reader.onerror = () => reject(reader.error);
|
|
2515
|
+
reader.readAsText(blob, encoding);
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
class FetchReader extends Reader {
|
|
2522
|
+
|
|
2523
|
+
constructor(url, options) {
|
|
2524
|
+
super();
|
|
2525
|
+
const reader = this;
|
|
2526
|
+
reader.url = url;
|
|
2527
|
+
reader.preventHeadRequest = options.preventHeadRequest;
|
|
2528
|
+
reader.useRangeHeader = options.useRangeHeader;
|
|
2529
|
+
reader.forceRangeRequests = options.forceRangeRequests;
|
|
2530
|
+
reader.options = options = Object.assign({}, options);
|
|
2531
|
+
delete options.preventHeadRequest;
|
|
2532
|
+
delete options.useRangeHeader;
|
|
2533
|
+
delete options.forceRangeRequests;
|
|
2534
|
+
delete options.useXHR;
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
async init() {
|
|
2538
|
+
super.init();
|
|
2539
|
+
await initHttpReader(this, sendFetchRequest, getFetchRequestData);
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
readUint8Array(index, length) {
|
|
2543
|
+
return readUint8ArrayHttpReader(this, index, length, sendFetchRequest, getFetchRequestData);
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
class XHRReader extends Reader {
|
|
2548
|
+
|
|
2549
|
+
constructor(url, options) {
|
|
2550
|
+
super();
|
|
2551
|
+
const reader = this;
|
|
2552
|
+
reader.url = url;
|
|
2553
|
+
reader.preventHeadRequest = options.preventHeadRequest;
|
|
2554
|
+
reader.useRangeHeader = options.useRangeHeader;
|
|
2555
|
+
reader.forceRangeRequests = options.forceRangeRequests;
|
|
2556
|
+
reader.options = options;
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
async init() {
|
|
2560
|
+
super.init();
|
|
2561
|
+
await initHttpReader(this, sendXMLHttpRequest, getXMLHttpRequestData);
|
|
2562
|
+
}
|
|
2563
|
+
|
|
2564
|
+
readUint8Array(index, length) {
|
|
2565
|
+
return readUint8ArrayHttpReader(this, index, length, sendXMLHttpRequest, getXMLHttpRequestData);
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
2570
|
+
if (isHttpFamily(httpReader.url) && (httpReader.useRangeHeader || httpReader.forceRangeRequests)) {
|
|
2571
|
+
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
|
|
2572
|
+
if (!httpReader.forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
2573
|
+
throw new Error(ERR_HTTP_RANGE);
|
|
2574
|
+
} else {
|
|
2575
|
+
let contentSize;
|
|
2576
|
+
const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
2577
|
+
if (contentRangeHeader) {
|
|
2578
|
+
const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
|
|
2579
|
+
if (splitHeader.length) {
|
|
2580
|
+
const headerValue = splitHeader[1];
|
|
2581
|
+
if (headerValue && headerValue != "*") {
|
|
2582
|
+
contentSize = Number(headerValue);
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
if (contentSize === undefined) {
|
|
2587
|
+
await getContentLength(httpReader, sendRequest, getRequestData);
|
|
2588
|
+
} else {
|
|
2589
|
+
httpReader.size = contentSize;
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
} else {
|
|
2593
|
+
await getContentLength(httpReader, sendRequest, getRequestData);
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
|
|
2598
|
+
if (httpReader.useRangeHeader || httpReader.forceRangeRequests) {
|
|
2599
|
+
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
|
|
2600
|
+
if (response.status != 206) {
|
|
2601
|
+
throw new Error(ERR_HTTP_RANGE);
|
|
2602
|
+
}
|
|
2603
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
2604
|
+
} else {
|
|
2605
|
+
if (!httpReader.data) {
|
|
2606
|
+
await getRequestData(httpReader, httpReader.options);
|
|
2607
|
+
}
|
|
2608
|
+
return new Uint8Array(httpReader.data.subarray(index, index + length));
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
function getRangeHeaders(httpReader, index = 0, length = 1) {
|
|
2613
|
+
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
function getHeaders(httpReader) {
|
|
2617
|
+
const headers = httpReader.options.headers;
|
|
2618
|
+
if (headers) {
|
|
2619
|
+
if (Symbol.iterator in headers) {
|
|
2620
|
+
return Object.fromEntries(headers);
|
|
2621
|
+
} else {
|
|
2622
|
+
return headers;
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
async function getFetchRequestData(httpReader) {
|
|
2628
|
+
await getRequestData(httpReader, sendFetchRequest);
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
async function getXMLHttpRequestData(httpReader) {
|
|
2632
|
+
await getRequestData(httpReader, sendXMLHttpRequest);
|
|
2633
|
+
}
|
|
2634
|
+
|
|
2635
|
+
async function getRequestData(httpReader, sendRequest) {
|
|
2636
|
+
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getHeaders(httpReader));
|
|
2637
|
+
httpReader.data = new Uint8Array(await response.arrayBuffer());
|
|
2638
|
+
if (!httpReader.size) {
|
|
2639
|
+
httpReader.size = httpReader.data.length;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
async function getContentLength(httpReader, sendRequest, getRequestData) {
|
|
2644
|
+
if (httpReader.preventHeadRequest) {
|
|
2645
|
+
await getRequestData(httpReader, httpReader.options);
|
|
2646
|
+
} else {
|
|
2647
|
+
const response = await sendRequest(HTTP_METHOD_HEAD, httpReader, getHeaders(httpReader));
|
|
2648
|
+
const contentLength = response.headers.get(HTTP_HEADER_CONTENT_LENGTH);
|
|
2649
|
+
if (contentLength) {
|
|
2650
|
+
httpReader.size = Number(contentLength);
|
|
2651
|
+
} else {
|
|
2652
|
+
await getRequestData(httpReader, httpReader.options);
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
async function sendFetchRequest(method, { options, url }, headers) {
|
|
2658
|
+
const response = await fetch(url, Object.assign({}, options, { method, headers }));
|
|
2659
|
+
if (response.status < 400) {
|
|
2660
|
+
return response;
|
|
2661
|
+
} else {
|
|
2662
|
+
throw response.status == 416 ? new Error(ERR_HTTP_RANGE) : new Error(ERR_HTTP_STATUS + (response.statusText || response.status));
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
function sendXMLHttpRequest(method, { url }, headers) {
|
|
2667
|
+
return new Promise((resolve, reject) => {
|
|
2668
|
+
const request = new XMLHttpRequest();
|
|
2669
|
+
request.addEventListener("load", () => {
|
|
2670
|
+
if (request.status < 400) {
|
|
2671
|
+
const headers = [];
|
|
2672
|
+
request.getAllResponseHeaders().trim().split(/[\r\n]+/).forEach(header => {
|
|
2673
|
+
const splitHeader = header.trim().split(/\s*:\s*/);
|
|
2674
|
+
splitHeader[0] = splitHeader[0].trim().replace(/^[a-z]|-[a-z]/g, value => value.toUpperCase());
|
|
2675
|
+
headers.push(splitHeader);
|
|
2676
|
+
});
|
|
2677
|
+
resolve({
|
|
2678
|
+
status: request.status,
|
|
2679
|
+
arrayBuffer: () => request.response,
|
|
2680
|
+
headers: new Map(headers)
|
|
2681
|
+
});
|
|
2682
|
+
} else {
|
|
2683
|
+
reject(request.status == 416 ? new Error(ERR_HTTP_RANGE) : new Error(ERR_HTTP_STATUS + (request.statusText || request.status)));
|
|
2684
|
+
}
|
|
2685
|
+
}, false);
|
|
2686
|
+
request.addEventListener("error", event => reject(event.detail.error), false);
|
|
2687
|
+
request.open(method, url);
|
|
2688
|
+
if (headers) {
|
|
2689
|
+
for (const entry of Object.entries(headers)) {
|
|
2690
|
+
request.setRequestHeader(entry[0], entry[1]);
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
request.responseType = "arraybuffer";
|
|
2694
|
+
request.send();
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
class HttpReader extends Reader {
|
|
2699
|
+
|
|
2700
|
+
constructor(url, options = {}) {
|
|
2701
|
+
super();
|
|
2702
|
+
const reader = this;
|
|
2703
|
+
reader.url = url;
|
|
2704
|
+
reader.reader = options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options);
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
set size(value) {
|
|
2708
|
+
// ignored
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
get size() {
|
|
2712
|
+
return this.reader.size;
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
async init() {
|
|
2716
|
+
super.init();
|
|
2717
|
+
await this.reader.init();
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
readUint8Array(index, length) {
|
|
2721
|
+
return this.reader.readUint8Array(index, length);
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
class HttpRangeReader extends HttpReader {
|
|
2726
|
+
|
|
2727
|
+
constructor(url, options = {}) {
|
|
2728
|
+
options.useRangeHeader = true;
|
|
2729
|
+
super(url, options);
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2733
|
+
|
|
2734
|
+
class Uint8ArrayReader extends Reader {
|
|
2735
|
+
|
|
2736
|
+
constructor(array) {
|
|
2737
|
+
super();
|
|
2738
|
+
this.array = array;
|
|
2739
|
+
this.size = array.length;
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
readUint8Array(index, length) {
|
|
2743
|
+
return this.array.slice(index, index + length);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2747
|
+
class Uint8ArrayWriter extends Writer {
|
|
2748
|
+
|
|
2749
|
+
init(initSize = 0) {
|
|
2750
|
+
super.init();
|
|
2751
|
+
const writer = this;
|
|
2752
|
+
writer.offset = 0;
|
|
2753
|
+
writer.array = new Uint8Array(initSize);
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
writeUint8Array(array) {
|
|
2757
|
+
const writer = this;
|
|
2758
|
+
if (writer.offset + array.length > writer.array.length) {
|
|
2759
|
+
const previousArray = writer.array;
|
|
2760
|
+
writer.array = new Uint8Array(previousArray.length + array.length);
|
|
2761
|
+
writer.array.set(previousArray);
|
|
2762
|
+
}
|
|
2763
|
+
writer.array.set(array, writer.offset);
|
|
2764
|
+
writer.offset += array.length;
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
getData() {
|
|
2768
|
+
return this.array;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
class SplitZipReader extends Reader {
|
|
2773
|
+
|
|
2774
|
+
constructor(readers) {
|
|
2775
|
+
super();
|
|
2776
|
+
this.readers = readers;
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
async init() {
|
|
2780
|
+
super.init();
|
|
2781
|
+
const reader = this;
|
|
2782
|
+
const { readers } = reader;
|
|
2783
|
+
reader.lastDiskNumber = 0;
|
|
2784
|
+
await Promise.all(readers.map(async diskReader => {
|
|
2785
|
+
await diskReader.init();
|
|
2786
|
+
reader.size += diskReader.size;
|
|
2787
|
+
}));
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
async readUint8Array(offset, length, diskNumber = 0) {
|
|
2791
|
+
const reader = this;
|
|
2792
|
+
const { readers } = this;
|
|
2793
|
+
let result;
|
|
2794
|
+
let currentDiskNumber = diskNumber;
|
|
2795
|
+
if (currentDiskNumber == -1) {
|
|
2796
|
+
currentDiskNumber = readers.length - 1;
|
|
2797
|
+
}
|
|
2798
|
+
let currentReaderOffset = offset;
|
|
2799
|
+
while (currentReaderOffset >= readers[currentDiskNumber].size) {
|
|
2800
|
+
currentReaderOffset -= readers[currentDiskNumber].size;
|
|
2801
|
+
currentDiskNumber++;
|
|
2802
|
+
}
|
|
2803
|
+
const currentReader = readers[currentDiskNumber];
|
|
2804
|
+
const currentReaderSize = currentReader.size;
|
|
2805
|
+
if (currentReaderOffset + length <= currentReaderSize) {
|
|
2806
|
+
result = await readUint8Array(currentReader, currentReaderOffset, length);
|
|
2807
|
+
} else {
|
|
2808
|
+
const chunkLength = currentReaderSize - currentReaderOffset;
|
|
2809
|
+
result = new Uint8Array(length);
|
|
2810
|
+
result.set(await readUint8Array(currentReader, currentReaderOffset, chunkLength));
|
|
2811
|
+
result.set(await reader.readUint8Array(offset + chunkLength, length - chunkLength, diskNumber), chunkLength);
|
|
2812
|
+
}
|
|
2813
|
+
reader.lastDiskNumber = Math.max(currentDiskNumber, reader.lastDiskNumber);
|
|
2814
|
+
return result;
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
function isHttpFamily(url) {
|
|
2819
|
+
const { baseURL } = getConfiguration();
|
|
2820
|
+
const { protocol } = new URL(url, baseURL);
|
|
2821
|
+
return protocol == "http:" || protocol == "https:";
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
async function initStream(stream, initSize) {
|
|
2825
|
+
if (stream.init && !stream.initialized) {
|
|
2826
|
+
await stream.init(initSize);
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
function readUint8Array(reader, offset, size, diskNumber) {
|
|
2831
|
+
return reader.readUint8Array(offset, size, diskNumber);
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
/*
|
|
2835
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2836
|
+
|
|
2837
|
+
Redistribution and use in source and binary forms, with or without
|
|
2838
|
+
modification, are permitted provided that the following conditions are met:
|
|
2839
|
+
|
|
2840
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
2841
|
+
this list of conditions and the following disclaimer.
|
|
2842
|
+
|
|
2843
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2844
|
+
notice, this list of conditions and the following disclaimer in
|
|
2845
|
+
the documentation and/or other materials provided with the distribution.
|
|
2846
|
+
|
|
2847
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
2848
|
+
derived from this software without specific prior written permission.
|
|
2849
|
+
|
|
2850
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
2851
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
2852
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
2853
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
2854
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
2855
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
2856
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
2857
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
2858
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
2859
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2860
|
+
*/
|
|
2861
|
+
|
|
2862
|
+
const MAX_32_BITS = 0xffffffff;
|
|
2863
|
+
const MAX_16_BITS = 0xffff;
|
|
2864
|
+
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
2865
|
+
const COMPRESSION_METHOD_STORE = 0x00;
|
|
2866
|
+
const COMPRESSION_METHOD_AES = 0x63;
|
|
2867
|
+
|
|
2868
|
+
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
2869
|
+
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
2870
|
+
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
2871
|
+
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
2872
|
+
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
2873
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
2874
|
+
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
2875
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
2876
|
+
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
2877
|
+
const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
2878
|
+
|
|
2879
|
+
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
2880
|
+
|
|
2881
|
+
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
2882
|
+
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
2883
|
+
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
2884
|
+
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
2885
|
+
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
2886
|
+
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
2887
|
+
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
2888
|
+
|
|
2889
|
+
const BITFLAG_ENCRYPTED = 0x01;
|
|
2890
|
+
const BITFLAG_LEVEL = 0x06;
|
|
2891
|
+
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
2892
|
+
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
2893
|
+
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
2894
|
+
|
|
2895
|
+
const VERSION_DEFLATE = 0x14;
|
|
2896
|
+
const VERSION_ZIP64 = 0x2D;
|
|
2897
|
+
const VERSION_AES = 0x33;
|
|
2898
|
+
|
|
2899
|
+
const DIRECTORY_SIGNATURE = "/";
|
|
2900
|
+
|
|
2901
|
+
const MAX_DATE = new Date(2107, 11, 31);
|
|
2902
|
+
const MIN_DATE = new Date(1980, 0, 1);
|
|
2903
|
+
|
|
2904
|
+
/*
|
|
2905
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2906
|
+
|
|
2907
|
+
Redistribution and use in source and binary forms, with or without
|
|
2908
|
+
modification, are permitted provided that the following conditions are met:
|
|
2909
|
+
|
|
2910
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
2911
|
+
this list of conditions and the following disclaimer.
|
|
2912
|
+
|
|
2913
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2914
|
+
notice, this list of conditions and the following disclaimer in
|
|
2915
|
+
the documentation and/or other materials provided with the distribution.
|
|
2916
|
+
|
|
2917
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
2918
|
+
derived from this software without specific prior written permission.
|
|
2919
|
+
|
|
2920
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
2921
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
2922
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
2923
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
2924
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
2925
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
2926
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
2927
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
2928
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
2929
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2930
|
+
*/
|
|
2931
|
+
|
|
2932
|
+
/* global TextDecoder */
|
|
2933
|
+
|
|
2934
|
+
const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
|
|
2935
|
+
const VALID_CP437 = CP437.length == 256;
|
|
2936
|
+
|
|
2937
|
+
function decodeCP437(stringValue) {
|
|
2938
|
+
if (VALID_CP437) {
|
|
2939
|
+
let result = "";
|
|
2940
|
+
for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
|
|
2941
|
+
result += CP437[stringValue[indexCharacter]];
|
|
2942
|
+
}
|
|
2943
|
+
return result;
|
|
2944
|
+
} else {
|
|
2945
|
+
return new TextDecoder().decode(stringValue);
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
/*
|
|
2950
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2951
|
+
|
|
2952
|
+
Redistribution and use in source and binary forms, with or without
|
|
2953
|
+
modification, are permitted provided that the following conditions are met:
|
|
2954
|
+
|
|
2955
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
2956
|
+
this list of conditions and the following disclaimer.
|
|
2957
|
+
|
|
2958
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2959
|
+
notice, this list of conditions and the following disclaimer in
|
|
2960
|
+
the documentation and/or other materials provided with the distribution.
|
|
2961
|
+
|
|
2962
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
2963
|
+
derived from this software without specific prior written permission.
|
|
2964
|
+
|
|
2965
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
2966
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
2967
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
2968
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
2969
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
2970
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
2971
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
2972
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
2973
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
2974
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2975
|
+
*/
|
|
2976
|
+
|
|
2977
|
+
function decodeText(value, encoding) {
|
|
2978
|
+
if (encoding && encoding.trim().toLowerCase() == "cp437") {
|
|
2979
|
+
return decodeCP437(value);
|
|
2980
|
+
} else {
|
|
2981
|
+
return new TextDecoder(encoding).decode(value);
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
/*
|
|
2986
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2987
|
+
|
|
2988
|
+
Redistribution and use in source and binary forms, with or without
|
|
2989
|
+
modification, are permitted provided that the following conditions are met:
|
|
2990
|
+
|
|
2991
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
2992
|
+
this list of conditions and the following disclaimer.
|
|
2993
|
+
|
|
2994
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2995
|
+
notice, this list of conditions and the following disclaimer in
|
|
2996
|
+
the documentation and/or other materials provided with the distribution.
|
|
2997
|
+
|
|
2998
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
2999
|
+
derived from this software without specific prior written permission.
|
|
3000
|
+
|
|
3001
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
3002
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
3003
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
3004
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
3005
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
3006
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
3007
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
3008
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
3009
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
3010
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3011
|
+
*/
|
|
3012
|
+
|
|
3013
|
+
const PROPERTY_NAMES = [
|
|
3014
|
+
"filename", "rawFilename", "directory", "encrypted", "compressedSize", "uncompressedSize",
|
|
3015
|
+
"lastModDate", "rawLastModDate", "comment", "rawComment", "signature", "extraField",
|
|
3016
|
+
"rawExtraField", "bitFlag", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
|
|
3017
|
+
"extraFieldAES", "filenameUTF8", "commentUTF8", "offset", "zip64", "compressionMethod",
|
|
3018
|
+
"extraFieldNTFS", "lastAccessDate", "creationDate", "extraFieldExtendedTimestamp",
|
|
3019
|
+
"version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute"];
|
|
3020
|
+
|
|
3021
|
+
class Entry {
|
|
3022
|
+
|
|
3023
|
+
constructor(data) {
|
|
3024
|
+
PROPERTY_NAMES.forEach(name => this[name] = data[name]);
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
}
|
|
3028
|
+
|
|
3029
|
+
/*
|
|
3030
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
3031
|
+
|
|
3032
|
+
Redistribution and use in source and binary forms, with or without
|
|
3033
|
+
modification, are permitted provided that the following conditions are met:
|
|
3034
|
+
|
|
3035
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
3036
|
+
this list of conditions and the following disclaimer.
|
|
3037
|
+
|
|
3038
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
3039
|
+
notice, this list of conditions and the following disclaimer in
|
|
3040
|
+
the documentation and/or other materials provided with the distribution.
|
|
3041
|
+
|
|
3042
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
3043
|
+
derived from this software without specific prior written permission.
|
|
3044
|
+
|
|
3045
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
3046
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
3047
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
3048
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
3049
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
3050
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
3051
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
3052
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
3053
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
3054
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3055
|
+
*/
|
|
3056
|
+
|
|
3057
|
+
const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
|
|
3058
|
+
const ERR_BAD_FORMAT = "File format is not recognized";
|
|
3059
|
+
const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
|
|
3060
|
+
const ERR_EOCDR_ZIP64_NOT_FOUND = "End of Zip64 central directory not found";
|
|
3061
|
+
const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = "End of Zip64 central directory locator not found";
|
|
3062
|
+
const ERR_CENTRAL_DIRECTORY_NOT_FOUND = "Central directory header not found";
|
|
3063
|
+
const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
|
|
3064
|
+
const ERR_EXTRAFIELD_ZIP64_NOT_FOUND = "Zip64 extra field not found";
|
|
3065
|
+
const ERR_ENCRYPTED = "File contains encrypted entry";
|
|
3066
|
+
const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
|
|
3067
|
+
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
3068
|
+
const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
3069
|
+
const CHARSET_UTF8 = "utf-8";
|
|
3070
|
+
const CHARSET_CP437 = "cp437";
|
|
3071
|
+
const ZIP64_PROPERTIES = [
|
|
3072
|
+
["uncompressedSize", MAX_32_BITS],
|
|
3073
|
+
["compressedSize", MAX_32_BITS],
|
|
3074
|
+
["offset", MAX_32_BITS],
|
|
3075
|
+
["diskNumberStart", MAX_16_BITS]
|
|
3076
|
+
];
|
|
3077
|
+
const ZIP64_EXTRACTION = {
|
|
3078
|
+
[MAX_16_BITS]: {
|
|
3079
|
+
getValue: getUint32,
|
|
3080
|
+
bytes: 4
|
|
3081
|
+
},
|
|
3082
|
+
[MAX_32_BITS]: {
|
|
3083
|
+
getValue: getBigUint64,
|
|
3084
|
+
bytes: 8
|
|
3085
|
+
}
|
|
3086
|
+
};
|
|
3087
|
+
|
|
3088
|
+
class ZipReader {
|
|
3089
|
+
|
|
3090
|
+
constructor(reader, options = {}) {
|
|
3091
|
+
if (reader instanceof ReadableStream) {
|
|
3092
|
+
reader = {
|
|
3093
|
+
readable: reader
|
|
3094
|
+
};
|
|
3095
|
+
}
|
|
3096
|
+
Object.assign(this, {
|
|
3097
|
+
reader,
|
|
3098
|
+
options,
|
|
3099
|
+
config: getConfiguration()
|
|
3100
|
+
});
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
async* getEntriesGenerator(options = {}) {
|
|
3104
|
+
const zipReader = this;
|
|
3105
|
+
let { reader } = zipReader;
|
|
3106
|
+
const { config } = zipReader;
|
|
3107
|
+
await initStream(reader);
|
|
3108
|
+
if (reader.size === undefined || !reader.readUint8Array) {
|
|
3109
|
+
if (Array.isArray(reader)) {
|
|
3110
|
+
reader = new SplitZipReader(reader);
|
|
3111
|
+
} else {
|
|
3112
|
+
reader = new BlobReader(await new Response(reader.readable).blob());
|
|
3113
|
+
}
|
|
3114
|
+
await initStream(reader);
|
|
3115
|
+
}
|
|
3116
|
+
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
3117
|
+
throw new Error(ERR_BAD_FORMAT);
|
|
3118
|
+
}
|
|
3119
|
+
reader.chunkSize = getChunkSize(config);
|
|
3120
|
+
const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, reader.size, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS * 16);
|
|
3121
|
+
if (!endOfDirectoryInfo) {
|
|
3122
|
+
const signatureArray = await readUint8Array(reader, 0, 4);
|
|
3123
|
+
const signatureView = getDataView$1(signatureArray);
|
|
3124
|
+
if (getUint32(signatureView) == SPLIT_ZIP_FILE_SIGNATURE) {
|
|
3125
|
+
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
3126
|
+
} else {
|
|
3127
|
+
throw new Error(ERR_EOCDR_NOT_FOUND);
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
const { lastDiskNumber } = reader;
|
|
3131
|
+
const endOfDirectoryView = getDataView$1(endOfDirectoryInfo);
|
|
3132
|
+
let directoryDataLength = getUint32(endOfDirectoryView, 12);
|
|
3133
|
+
let directoryDataOffset = getUint32(endOfDirectoryView, 16);
|
|
3134
|
+
const commentOffset = endOfDirectoryInfo.offset;
|
|
3135
|
+
const commentLength = getUint16(endOfDirectoryView, 20);
|
|
3136
|
+
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
3137
|
+
let diskNumber = getUint16(endOfDirectoryView, 4);
|
|
3138
|
+
if (lastDiskNumber !== undefined && diskNumber != lastDiskNumber) {
|
|
3139
|
+
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
3140
|
+
}
|
|
3141
|
+
let filesLength = getUint16(endOfDirectoryView, 8);
|
|
3142
|
+
let prependedDataLength = 0;
|
|
3143
|
+
let startOffset = 0;
|
|
3144
|
+
if (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS) {
|
|
3145
|
+
const endOfDirectoryLocatorArray = await readUint8Array(reader, endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH);
|
|
3146
|
+
const endOfDirectoryLocatorView = getDataView$1(endOfDirectoryLocatorArray);
|
|
3147
|
+
if (getUint32(endOfDirectoryLocatorView, 0) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
|
|
3148
|
+
throw new Error(ERR_EOCDR_ZIP64_NOT_FOUND);
|
|
3149
|
+
}
|
|
3150
|
+
directoryDataOffset = getBigUint64(endOfDirectoryLocatorView, 8);
|
|
3151
|
+
let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH, -1);
|
|
3152
|
+
let endOfDirectoryView = getDataView$1(endOfDirectoryArray);
|
|
3153
|
+
const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
3154
|
+
if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
|
|
3155
|
+
const originalDirectoryDataOffset = directoryDataOffset;
|
|
3156
|
+
directoryDataOffset = expectedDirectoryDataOffset;
|
|
3157
|
+
prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
|
|
3158
|
+
endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH, -1);
|
|
3159
|
+
endOfDirectoryView = getDataView$1(endOfDirectoryArray);
|
|
3160
|
+
}
|
|
3161
|
+
if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
|
|
3162
|
+
throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
|
|
3163
|
+
}
|
|
3164
|
+
if (diskNumber == MAX_16_BITS) {
|
|
3165
|
+
diskNumber = getUint32(endOfDirectoryView, 16);
|
|
3166
|
+
}
|
|
3167
|
+
if (filesLength == MAX_16_BITS) {
|
|
3168
|
+
filesLength = getBigUint64(endOfDirectoryView, 32);
|
|
3169
|
+
}
|
|
3170
|
+
if (directoryDataLength == MAX_32_BITS) {
|
|
3171
|
+
directoryDataLength = getBigUint64(endOfDirectoryView, 40);
|
|
3172
|
+
}
|
|
3173
|
+
directoryDataOffset -= directoryDataLength;
|
|
3174
|
+
}
|
|
3175
|
+
if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
|
|
3176
|
+
throw new Error(ERR_BAD_FORMAT);
|
|
3177
|
+
}
|
|
3178
|
+
let offset = 0;
|
|
3179
|
+
let directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength, diskNumber);
|
|
3180
|
+
let directoryView = getDataView$1(directoryArray);
|
|
3181
|
+
if (directoryDataLength) {
|
|
3182
|
+
const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - directoryDataLength;
|
|
3183
|
+
if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
|
|
3184
|
+
const originalDirectoryDataOffset = directoryDataOffset;
|
|
3185
|
+
directoryDataOffset = expectedDirectoryDataOffset;
|
|
3186
|
+
prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
|
|
3187
|
+
directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength, diskNumber);
|
|
3188
|
+
directoryView = getDataView$1(directoryArray);
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
|
|
3192
|
+
throw new Error(ERR_BAD_FORMAT);
|
|
3193
|
+
}
|
|
3194
|
+
const filenameEncoding = getOptionValue$1(zipReader, options, "filenameEncoding");
|
|
3195
|
+
const commentEncoding = getOptionValue$1(zipReader, options, "commentEncoding");
|
|
3196
|
+
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
3197
|
+
const fileEntry = new ZipEntry(reader, config, zipReader.options);
|
|
3198
|
+
if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
3199
|
+
throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);
|
|
3200
|
+
}
|
|
3201
|
+
readCommonHeader(fileEntry, directoryView, offset + 6);
|
|
3202
|
+
const languageEncodingFlag = Boolean(fileEntry.bitFlag.languageEncodingFlag);
|
|
3203
|
+
const filenameOffset = offset + 46;
|
|
3204
|
+
const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
|
|
3205
|
+
const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
|
|
3206
|
+
const versionMadeBy = getUint16(directoryView, offset + 4);
|
|
3207
|
+
const msDosCompatible = (versionMadeBy & 0) == 0;
|
|
3208
|
+
const rawFilename = directoryArray.subarray(filenameOffset, extraFieldOffset);
|
|
3209
|
+
const commentLength = getUint16(directoryView, offset + 32);
|
|
3210
|
+
const endOffset = commentOffset + commentLength;
|
|
3211
|
+
const rawComment = directoryArray.subarray(commentOffset, endOffset);
|
|
3212
|
+
const filenameUTF8 = languageEncodingFlag;
|
|
3213
|
+
const commentUTF8 = languageEncodingFlag;
|
|
3214
|
+
const directory = msDosCompatible && ((getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK);
|
|
3215
|
+
const offsetFileEntry = getUint32(directoryView, offset + 42) + prependedDataLength;
|
|
3216
|
+
Object.assign(fileEntry, {
|
|
3217
|
+
versionMadeBy,
|
|
3218
|
+
msDosCompatible,
|
|
3219
|
+
compressedSize: 0,
|
|
3220
|
+
uncompressedSize: 0,
|
|
3221
|
+
commentLength,
|
|
3222
|
+
directory,
|
|
3223
|
+
offset: offsetFileEntry,
|
|
3224
|
+
diskNumberStart: getUint16(directoryView, offset + 34),
|
|
3225
|
+
internalFileAttribute: getUint16(directoryView, offset + 36),
|
|
3226
|
+
externalFileAttribute: getUint32(directoryView, offset + 38),
|
|
3227
|
+
rawFilename,
|
|
3228
|
+
filenameUTF8,
|
|
3229
|
+
commentUTF8,
|
|
3230
|
+
rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
|
|
3231
|
+
});
|
|
3232
|
+
const [filename, comment] = await Promise.all([
|
|
3233
|
+
decodeText(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
|
|
3234
|
+
decodeText(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
|
|
3235
|
+
]);
|
|
3236
|
+
Object.assign(fileEntry, {
|
|
3237
|
+
rawComment,
|
|
3238
|
+
filename,
|
|
3239
|
+
comment,
|
|
3240
|
+
directory: directory || filename.endsWith(DIRECTORY_SIGNATURE)
|
|
3241
|
+
});
|
|
3242
|
+
startOffset = Math.max(offsetFileEntry, startOffset);
|
|
3243
|
+
await readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
|
|
3244
|
+
const entry = new Entry(fileEntry);
|
|
3245
|
+
entry.getData = (writer, options) => fileEntry.getData(writer, entry, options);
|
|
3246
|
+
offset = endOffset;
|
|
3247
|
+
const { onprogress } = options;
|
|
3248
|
+
if (onprogress) {
|
|
3249
|
+
try {
|
|
3250
|
+
await onprogress(indexFile + 1, filesLength, new Entry(fileEntry));
|
|
3251
|
+
} catch (_error) {
|
|
3252
|
+
// ignored
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
yield entry;
|
|
3256
|
+
}
|
|
3257
|
+
const extractPrependedData = getOptionValue$1(zipReader, options, "extractPrependedData");
|
|
3258
|
+
const extractAppendedData = getOptionValue$1(zipReader, options, "extractAppendedData");
|
|
3259
|
+
if (extractPrependedData) {
|
|
3260
|
+
zipReader.prependedData = startOffset > 0 ? await readUint8Array(reader, 0, startOffset) : new Uint8Array();
|
|
3261
|
+
}
|
|
3262
|
+
zipReader.comment = commentLength ? await readUint8Array(reader, commentOffset + END_OF_CENTRAL_DIR_LENGTH, commentLength) : new Uint8Array();
|
|
3263
|
+
if (extractAppendedData) {
|
|
3264
|
+
zipReader.appendedData = appendedDataOffset < reader.size ? await readUint8Array(reader, appendedDataOffset, reader.size - appendedDataOffset) : new Uint8Array();
|
|
3265
|
+
}
|
|
3266
|
+
return true;
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
async getEntries(options = {}) {
|
|
3270
|
+
const entries = [];
|
|
3271
|
+
for await (const entry of this.getEntriesGenerator(options)) {
|
|
3272
|
+
entries.push(entry);
|
|
3273
|
+
}
|
|
3274
|
+
return entries;
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
async close() {
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
class ZipEntry {
|
|
3282
|
+
|
|
3283
|
+
constructor(reader, config, options) {
|
|
3284
|
+
Object.assign(this, {
|
|
3285
|
+
reader,
|
|
3286
|
+
config,
|
|
3287
|
+
options
|
|
3288
|
+
});
|
|
3289
|
+
}
|
|
3290
|
+
|
|
3291
|
+
async getData(writer, fileEntry, options = {}) {
|
|
3292
|
+
const zipEntry = this;
|
|
3293
|
+
const {
|
|
3294
|
+
reader,
|
|
3295
|
+
offset,
|
|
3296
|
+
diskNumberStart,
|
|
3297
|
+
extraFieldAES,
|
|
3298
|
+
compressionMethod,
|
|
3299
|
+
config,
|
|
3300
|
+
bitFlag,
|
|
3301
|
+
signature,
|
|
3302
|
+
rawLastModDate,
|
|
3303
|
+
uncompressedSize,
|
|
3304
|
+
compressedSize
|
|
3305
|
+
} = zipEntry;
|
|
3306
|
+
const localDirectory = zipEntry.localDirectory = {};
|
|
3307
|
+
let dataArray = await readUint8Array(reader, offset, 30, diskNumberStart);
|
|
3308
|
+
const dataView = getDataView$1(dataArray);
|
|
3309
|
+
let password = getOptionValue$1(zipEntry, options, "password");
|
|
3310
|
+
password = password && password.length && password;
|
|
3311
|
+
if (extraFieldAES) {
|
|
3312
|
+
if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
|
|
3313
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {
|
|
3317
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
3318
|
+
}
|
|
3319
|
+
if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
3320
|
+
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
3321
|
+
}
|
|
3322
|
+
readCommonHeader(localDirectory, dataView, 4);
|
|
3323
|
+
dataArray = await readUint8Array(reader, offset, 30 + localDirectory.filenameLength + localDirectory.extraFieldLength, diskNumberStart);
|
|
3324
|
+
localDirectory.rawExtraField = dataArray.subarray(30 + localDirectory.filenameLength);
|
|
3325
|
+
await readCommonFooter(zipEntry, localDirectory, dataView, 4);
|
|
3326
|
+
Object.assign(fileEntry, {
|
|
3327
|
+
lastAccessDate: localDirectory.lastAccessDate,
|
|
3328
|
+
creationDate: localDirectory.creationDate
|
|
3329
|
+
});
|
|
3330
|
+
const encrypted = zipEntry.encrypted && localDirectory.encrypted;
|
|
3331
|
+
const zipCrypto = encrypted && !extraFieldAES;
|
|
3332
|
+
if (encrypted) {
|
|
3333
|
+
if (!zipCrypto && extraFieldAES.strength === undefined) {
|
|
3334
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
3335
|
+
} else if (!password) {
|
|
3336
|
+
throw new Error(ERR_ENCRYPTED);
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
const dataOffset = offset + 30 + localDirectory.filenameLength + localDirectory.extraFieldLength;
|
|
3340
|
+
const readable = reader.readable;
|
|
3341
|
+
readable.diskNumberStart = diskNumberStart;
|
|
3342
|
+
readable.offset = dataOffset;
|
|
3343
|
+
const size = readable.size = compressedSize;
|
|
3344
|
+
if (writer instanceof WritableStream) {
|
|
3345
|
+
writer = {
|
|
3346
|
+
writable: writer
|
|
3347
|
+
};
|
|
3348
|
+
}
|
|
3349
|
+
const { writable } = writer;
|
|
3350
|
+
if (writable.size === undefined) {
|
|
3351
|
+
writable.size = 0;
|
|
3352
|
+
}
|
|
3353
|
+
const signal = getOptionValue$1(zipEntry, options, "signal");
|
|
3354
|
+
await initStream(writer, uncompressedSize);
|
|
3355
|
+
const { onstart, onprogress, onend } = options;
|
|
3356
|
+
const workerOptions = {
|
|
3357
|
+
options: {
|
|
3358
|
+
codecType: CODEC_INFLATE,
|
|
3359
|
+
password,
|
|
3360
|
+
zipCrypto,
|
|
3361
|
+
encryptionStrength: extraFieldAES && extraFieldAES.strength,
|
|
3362
|
+
signed: getOptionValue$1(zipEntry, options, "checkSignature"),
|
|
3363
|
+
passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
|
|
3364
|
+
signature,
|
|
3365
|
+
compressed: compressionMethod != 0,
|
|
3366
|
+
encrypted,
|
|
3367
|
+
useWebWorkers: getOptionValue$1(zipEntry, options, "useWebWorkers"),
|
|
3368
|
+
useCompressionStream: getOptionValue$1(zipEntry, options, "useCompressionStream"),
|
|
3369
|
+
transferStreams: getOptionValue$1(zipEntry, options, "transferStreams")
|
|
3370
|
+
},
|
|
3371
|
+
config,
|
|
3372
|
+
streamOptions: { signal, size, onstart, onprogress, onend }
|
|
3373
|
+
};
|
|
3374
|
+
writable.size += (await runWorker({ readable, writable }, workerOptions)).size;
|
|
3375
|
+
const preventClose = getOptionValue$1(zipEntry, options, "preventClose");
|
|
3376
|
+
if (!preventClose) {
|
|
3377
|
+
await writable.close();
|
|
3378
|
+
}
|
|
3379
|
+
return writer.getData ? writer.getData() : writable;
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
function readCommonHeader(directory, dataView, offset) {
|
|
3384
|
+
const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
|
|
3385
|
+
const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
|
|
3386
|
+
const rawLastModDate = getUint32(dataView, offset + 6);
|
|
3387
|
+
Object.assign(directory, {
|
|
3388
|
+
encrypted,
|
|
3389
|
+
version: getUint16(dataView, offset),
|
|
3390
|
+
bitFlag: {
|
|
3391
|
+
level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
|
|
3392
|
+
dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
|
|
3393
|
+
languageEncodingFlag: (rawBitFlag & BITFLAG_LANG_ENCODING_FLAG) == BITFLAG_LANG_ENCODING_FLAG
|
|
3394
|
+
},
|
|
3395
|
+
rawLastModDate,
|
|
3396
|
+
lastModDate: getDate(rawLastModDate),
|
|
3397
|
+
filenameLength: getUint16(dataView, offset + 22),
|
|
3398
|
+
extraFieldLength: getUint16(dataView, offset + 24)
|
|
3399
|
+
});
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
async function readCommonFooter(fileEntry, directory, dataView, offset) {
|
|
3403
|
+
const { rawExtraField } = directory;
|
|
3404
|
+
const extraField = directory.extraField = new Map();
|
|
3405
|
+
const rawExtraFieldView = getDataView$1(new Uint8Array(rawExtraField));
|
|
3406
|
+
let offsetExtraField = 0;
|
|
3407
|
+
try {
|
|
3408
|
+
while (offsetExtraField < rawExtraField.length) {
|
|
3409
|
+
const type = getUint16(rawExtraFieldView, offsetExtraField);
|
|
3410
|
+
const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
|
|
3411
|
+
extraField.set(type, {
|
|
3412
|
+
type,
|
|
3413
|
+
data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
|
|
3414
|
+
});
|
|
3415
|
+
offsetExtraField += 4 + size;
|
|
3416
|
+
}
|
|
3417
|
+
} catch (_error) {
|
|
3418
|
+
// ignored
|
|
3419
|
+
}
|
|
3420
|
+
const compressionMethod = getUint16(dataView, offset + 4);
|
|
3421
|
+
Object.assign(directory, {
|
|
3422
|
+
signature: getUint32(dataView, offset + 10),
|
|
3423
|
+
uncompressedSize: getUint32(dataView, offset + 18),
|
|
3424
|
+
compressedSize: getUint32(dataView, offset + 14)
|
|
3425
|
+
});
|
|
3426
|
+
const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
|
|
3427
|
+
if (extraFieldZip64) {
|
|
3428
|
+
readExtraFieldZip64(extraFieldZip64, directory);
|
|
3429
|
+
directory.extraFieldZip64 = extraFieldZip64;
|
|
3430
|
+
}
|
|
3431
|
+
const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
|
|
3432
|
+
if (extraFieldUnicodePath) {
|
|
3433
|
+
await readExtraFieldUnicode(extraFieldUnicodePath, "filename", "rawFilename", directory, fileEntry);
|
|
3434
|
+
directory.extraFieldUnicodePath = extraFieldUnicodePath;
|
|
3435
|
+
}
|
|
3436
|
+
const extraFieldUnicodeComment = extraField.get(EXTRAFIELD_TYPE_UNICODE_COMMENT);
|
|
3437
|
+
if (extraFieldUnicodeComment) {
|
|
3438
|
+
await readExtraFieldUnicode(extraFieldUnicodeComment, "comment", "rawComment", directory, fileEntry);
|
|
3439
|
+
directory.extraFieldUnicodeComment = extraFieldUnicodeComment;
|
|
3440
|
+
}
|
|
3441
|
+
const extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);
|
|
3442
|
+
if (extraFieldAES) {
|
|
3443
|
+
readExtraFieldAES(extraFieldAES, directory, compressionMethod);
|
|
3444
|
+
directory.extraFieldAES = extraFieldAES;
|
|
3445
|
+
} else {
|
|
3446
|
+
directory.compressionMethod = compressionMethod;
|
|
3447
|
+
}
|
|
3448
|
+
const extraFieldNTFS = extraField.get(EXTRAFIELD_TYPE_NTFS);
|
|
3449
|
+
if (extraFieldNTFS) {
|
|
3450
|
+
readExtraFieldNTFS(extraFieldNTFS, directory);
|
|
3451
|
+
directory.extraFieldNTFS = extraFieldNTFS;
|
|
3452
|
+
}
|
|
3453
|
+
const extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
|
|
3454
|
+
if (extraFieldExtendedTimestamp) {
|
|
3455
|
+
readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory);
|
|
3456
|
+
directory.extraFieldExtendedTimestamp = extraFieldExtendedTimestamp;
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
function readExtraFieldZip64(extraFieldZip64, directory) {
|
|
3461
|
+
directory.zip64 = true;
|
|
3462
|
+
const extraFieldView = getDataView$1(extraFieldZip64.data);
|
|
3463
|
+
const missingProperties = ZIP64_PROPERTIES.filter(([propertyName, max]) => directory[propertyName] == max);
|
|
3464
|
+
for (let indexMissingProperty = 0, offset = 0; indexMissingProperty < missingProperties.length; indexMissingProperty++) {
|
|
3465
|
+
const [propertyName, max] = missingProperties[indexMissingProperty];
|
|
3466
|
+
if (directory[propertyName] == max) {
|
|
3467
|
+
const extraction = ZIP64_EXTRACTION[max];
|
|
3468
|
+
directory[propertyName] = extraFieldZip64[propertyName] = extraction.getValue(extraFieldView, offset);
|
|
3469
|
+
offset += extraction.bytes;
|
|
3470
|
+
} else if (extraFieldZip64[propertyName]) {
|
|
3471
|
+
throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
|
|
3476
|
+
async function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName, directory, fileEntry) {
|
|
3477
|
+
const extraFieldView = getDataView$1(extraFieldUnicode.data);
|
|
3478
|
+
const crc32 = new Crc32();
|
|
3479
|
+
crc32.append(fileEntry[rawPropertyName]);
|
|
3480
|
+
const dataViewSignature = getDataView$1(new Uint8Array(4));
|
|
3481
|
+
dataViewSignature.setUint32(0, crc32.get(), true);
|
|
3482
|
+
Object.assign(extraFieldUnicode, {
|
|
3483
|
+
version: getUint8(extraFieldView, 0),
|
|
3484
|
+
signature: getUint32(extraFieldView, 1),
|
|
3485
|
+
[propertyName]: await decodeText(extraFieldUnicode.data.subarray(5)),
|
|
3486
|
+
valid: !fileEntry.bitFlag.languageEncodingFlag && extraFieldUnicode.signature == getUint32(dataViewSignature, 0)
|
|
3487
|
+
});
|
|
3488
|
+
if (extraFieldUnicode.valid) {
|
|
3489
|
+
directory[propertyName] = extraFieldUnicode[propertyName];
|
|
3490
|
+
directory[propertyName + "UTF8"] = true;
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
|
|
3494
|
+
function readExtraFieldAES(extraFieldAES, directory, compressionMethod) {
|
|
3495
|
+
const extraFieldView = getDataView$1(extraFieldAES.data);
|
|
3496
|
+
const strength = getUint8(extraFieldView, 4);
|
|
3497
|
+
Object.assign(extraFieldAES, {
|
|
3498
|
+
vendorVersion: getUint8(extraFieldView, 0),
|
|
3499
|
+
vendorId: getUint8(extraFieldView, 2),
|
|
3500
|
+
strength,
|
|
3501
|
+
originalCompressionMethod: compressionMethod,
|
|
3502
|
+
compressionMethod: getUint16(extraFieldView, 5)
|
|
3503
|
+
});
|
|
3504
|
+
directory.compressionMethod = extraFieldAES.compressionMethod;
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
function readExtraFieldNTFS(extraFieldNTFS, directory) {
|
|
3508
|
+
const extraFieldView = getDataView$1(extraFieldNTFS.data);
|
|
3509
|
+
let offsetExtraField = 4;
|
|
3510
|
+
let tag1Data;
|
|
3511
|
+
try {
|
|
3512
|
+
while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
|
|
3513
|
+
const tagValue = getUint16(extraFieldView, offsetExtraField);
|
|
3514
|
+
const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
|
|
3515
|
+
if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
|
|
3516
|
+
tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
|
|
3517
|
+
}
|
|
3518
|
+
offsetExtraField += 4 + attributeSize;
|
|
3519
|
+
}
|
|
3520
|
+
} catch (_error) {
|
|
3521
|
+
// ignored
|
|
3522
|
+
}
|
|
3523
|
+
try {
|
|
3524
|
+
if (tag1Data && tag1Data.length == 24) {
|
|
3525
|
+
const tag1View = getDataView$1(tag1Data);
|
|
3526
|
+
const rawLastModDate = tag1View.getBigUint64(0, true);
|
|
3527
|
+
const rawLastAccessDate = tag1View.getBigUint64(8, true);
|
|
3528
|
+
const rawCreationDate = tag1View.getBigUint64(16, true);
|
|
3529
|
+
Object.assign(extraFieldNTFS, {
|
|
3530
|
+
rawLastModDate,
|
|
3531
|
+
rawLastAccessDate,
|
|
3532
|
+
rawCreationDate
|
|
3533
|
+
});
|
|
3534
|
+
const lastModDate = getDateNTFS(rawLastModDate);
|
|
3535
|
+
const lastAccessDate = getDateNTFS(rawLastAccessDate);
|
|
3536
|
+
const creationDate = getDateNTFS(rawCreationDate);
|
|
3537
|
+
const extraFieldData = { lastModDate, lastAccessDate, creationDate };
|
|
3538
|
+
Object.assign(extraFieldNTFS, extraFieldData);
|
|
3539
|
+
Object.assign(directory, extraFieldData);
|
|
3540
|
+
}
|
|
3541
|
+
} catch (_error) {
|
|
3542
|
+
// ignored
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
|
|
3546
|
+
function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory) {
|
|
3547
|
+
const extraFieldView = getDataView$1(extraFieldExtendedTimestamp.data);
|
|
3548
|
+
const flags = getUint8(extraFieldView, 0);
|
|
3549
|
+
const timeProperties = [];
|
|
3550
|
+
const timeRawProperties = [];
|
|
3551
|
+
if ((flags & 0x1) == 0x1) {
|
|
3552
|
+
timeProperties.push("lastModDate");
|
|
3553
|
+
timeRawProperties.push("rawLastModDate");
|
|
3554
|
+
}
|
|
3555
|
+
if ((flags & 0x2) == 0x2) {
|
|
3556
|
+
timeProperties.push("lastAccessDate");
|
|
3557
|
+
timeRawProperties.push("rawLastAccessDate");
|
|
3558
|
+
}
|
|
3559
|
+
if ((flags & 0x4) == 0x4) {
|
|
3560
|
+
timeProperties.push("creationDate");
|
|
3561
|
+
timeRawProperties.push("rawCreationDate");
|
|
3562
|
+
}
|
|
3563
|
+
let offset = 1;
|
|
3564
|
+
timeProperties.forEach((propertyName, indexProperty) => {
|
|
3565
|
+
if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
|
|
3566
|
+
const time = getUint32(extraFieldView, offset);
|
|
3567
|
+
directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date(time * 1000);
|
|
3568
|
+
const rawPropertyName = timeRawProperties[indexProperty];
|
|
3569
|
+
extraFieldExtendedTimestamp[rawPropertyName] = time;
|
|
3570
|
+
}
|
|
3571
|
+
offset += 4;
|
|
3572
|
+
});
|
|
3573
|
+
}
|
|
3574
|
+
|
|
3575
|
+
async function seekSignature(reader, signature, startOffset, minimumBytes, maximumLength) {
|
|
3576
|
+
const signatureArray = new Uint8Array(4);
|
|
3577
|
+
const signatureView = getDataView$1(signatureArray);
|
|
3578
|
+
setUint32$1(signatureView, 0, signature);
|
|
3579
|
+
const maximumBytes = minimumBytes + maximumLength;
|
|
3580
|
+
return (await seek(minimumBytes)) || await seek(Math.min(maximumBytes, startOffset));
|
|
3581
|
+
|
|
3582
|
+
async function seek(length) {
|
|
3583
|
+
const offset = startOffset - length;
|
|
3584
|
+
const bytes = await readUint8Array(reader, offset, length);
|
|
3585
|
+
for (let indexByte = bytes.length - minimumBytes; indexByte >= 0; indexByte--) {
|
|
3586
|
+
if (bytes[indexByte] == signatureArray[0] && bytes[indexByte + 1] == signatureArray[1] &&
|
|
3587
|
+
bytes[indexByte + 2] == signatureArray[2] && bytes[indexByte + 3] == signatureArray[3]) {
|
|
3588
|
+
return {
|
|
3589
|
+
offset: offset + indexByte,
|
|
3590
|
+
buffer: bytes.slice(indexByte, indexByte + minimumBytes).buffer
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3597
|
+
function getOptionValue$1(zipReader, options, name) {
|
|
3598
|
+
return options[name] === undefined ? zipReader.options[name] : options[name];
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
function getDate(timeRaw) {
|
|
3602
|
+
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
|
|
3603
|
+
try {
|
|
3604
|
+
return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
|
|
3605
|
+
} catch (_error) {
|
|
3606
|
+
// ignored
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
function getDateNTFS(timeRaw) {
|
|
3611
|
+
return new Date((Number((timeRaw / BigInt(10000)) - BigInt(11644473600000))));
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
function getUint8(view, offset) {
|
|
3615
|
+
return view.getUint8(offset);
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
function getUint16(view, offset) {
|
|
3619
|
+
return view.getUint16(offset, true);
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
function getUint32(view, offset) {
|
|
3623
|
+
return view.getUint32(offset, true);
|
|
3624
|
+
}
|
|
3625
|
+
|
|
3626
|
+
function getBigUint64(view, offset) {
|
|
3627
|
+
return Number(view.getBigUint64(offset, true));
|
|
3628
|
+
}
|
|
3629
|
+
|
|
3630
|
+
function setUint32$1(view, offset, value) {
|
|
3631
|
+
view.setUint32(offset, value, true);
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
function getDataView$1(array) {
|
|
3635
|
+
return new DataView(array.buffer);
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
/*
|
|
3639
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
3640
|
+
|
|
3641
|
+
Redistribution and use in source and binary forms, with or without
|
|
3642
|
+
modification, are permitted provided that the following conditions are met:
|
|
3643
|
+
|
|
3644
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
3645
|
+
this list of conditions and the following disclaimer.
|
|
3646
|
+
|
|
3647
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
3648
|
+
notice, this list of conditions and the following disclaimer in
|
|
3649
|
+
the documentation and/or other materials provided with the distribution.
|
|
3650
|
+
|
|
3651
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
3652
|
+
derived from this software without specific prior written permission.
|
|
3653
|
+
|
|
3654
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
3655
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
3656
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
3657
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
3658
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
3659
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
3660
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
3661
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
3662
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
3663
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3664
|
+
*/
|
|
3665
|
+
|
|
3666
|
+
const ERR_DUPLICATED_NAME = "File already exists";
|
|
3667
|
+
const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
|
|
3668
|
+
const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
|
|
3669
|
+
const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
|
|
3670
|
+
const ERR_INVALID_VERSION = "Version exceeds 65535";
|
|
3671
|
+
const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
|
|
3672
|
+
const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
|
|
3673
|
+
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
3674
|
+
const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
|
|
3675
|
+
|
|
3676
|
+
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
3677
|
+
const EXTRAFIELD_LENGTH_ZIP64 = 24;
|
|
3678
|
+
|
|
3679
|
+
let workers = 0;
|
|
3680
|
+
const pendingEntries = [];
|
|
3681
|
+
|
|
3682
|
+
class ZipWriter {
|
|
3683
|
+
|
|
3684
|
+
constructor(writer, options = {}) {
|
|
3685
|
+
if (writer instanceof WritableStream) {
|
|
3686
|
+
writer = { writable: writer };
|
|
3687
|
+
}
|
|
3688
|
+
if (writer.writable.size === undefined) {
|
|
3689
|
+
writer.writable.size = 0;
|
|
3690
|
+
}
|
|
3691
|
+
Object.assign(this, {
|
|
3692
|
+
writer,
|
|
3693
|
+
options,
|
|
3694
|
+
config: getConfiguration(),
|
|
3695
|
+
files: new Map(),
|
|
3696
|
+
filenames: new Set(),
|
|
3697
|
+
offset: writer.writable.size,
|
|
3698
|
+
pendingEntriesSize: 0,
|
|
3699
|
+
pendingAddFileCalls: new Set()
|
|
3700
|
+
});
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
async add(name = "", reader, options = {}) {
|
|
3704
|
+
const zipWriter = this;
|
|
3705
|
+
const {
|
|
3706
|
+
pendingAddFileCalls,
|
|
3707
|
+
config
|
|
3708
|
+
} = zipWriter;
|
|
3709
|
+
if (workers < config.maxWorkers) {
|
|
3710
|
+
workers++;
|
|
3711
|
+
} else {
|
|
3712
|
+
await new Promise(resolve => pendingEntries.push(resolve));
|
|
3713
|
+
}
|
|
3714
|
+
let promiseAddFile;
|
|
3715
|
+
try {
|
|
3716
|
+
name = name.trim();
|
|
3717
|
+
if (zipWriter.filenames.has(name)) {
|
|
3718
|
+
throw new Error(ERR_DUPLICATED_NAME);
|
|
3719
|
+
}
|
|
3720
|
+
zipWriter.filenames.add(name);
|
|
3721
|
+
promiseAddFile = addFile(zipWriter, name, reader, options);
|
|
3722
|
+
pendingAddFileCalls.add(promiseAddFile);
|
|
3723
|
+
return await promiseAddFile;
|
|
3724
|
+
} catch (error) {
|
|
3725
|
+
zipWriter.filenames.delete(name);
|
|
3726
|
+
throw error;
|
|
3727
|
+
} finally {
|
|
3728
|
+
pendingAddFileCalls.delete(promiseAddFile);
|
|
3729
|
+
const pendingEntry = pendingEntries.shift();
|
|
3730
|
+
if (pendingEntry) {
|
|
3731
|
+
pendingEntry();
|
|
3732
|
+
} else {
|
|
3733
|
+
workers--;
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
|
|
3738
|
+
async close(comment = new Uint8Array(), options = {}) {
|
|
3739
|
+
const { pendingAddFileCalls, writer } = this;
|
|
3740
|
+
const { writable } = writer;
|
|
3741
|
+
while (pendingAddFileCalls.size) {
|
|
3742
|
+
await Promise.all(Array.from(pendingAddFileCalls));
|
|
3743
|
+
}
|
|
3744
|
+
await closeFile(this, comment, options);
|
|
3745
|
+
if (!writer.preventClose && !options.preventClose) {
|
|
3746
|
+
await writable.close();
|
|
3747
|
+
}
|
|
3748
|
+
return writer.getData ? writer.getData() : writable;
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
|
|
3752
|
+
async function addFile(zipWriter, name, reader, options) {
|
|
3753
|
+
name = name.trim();
|
|
3754
|
+
if (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {
|
|
3755
|
+
name += DIRECTORY_SIGNATURE;
|
|
3756
|
+
} else {
|
|
3757
|
+
options.directory = name.endsWith(DIRECTORY_SIGNATURE);
|
|
3758
|
+
}
|
|
3759
|
+
const rawFilename = encodeText(name);
|
|
3760
|
+
if (getLength(rawFilename) > MAX_16_BITS) {
|
|
3761
|
+
throw new Error(ERR_INVALID_ENTRY_NAME);
|
|
3762
|
+
}
|
|
3763
|
+
const comment = options.comment || "";
|
|
3764
|
+
const rawComment = encodeText(comment);
|
|
3765
|
+
if (getLength(rawComment) > MAX_16_BITS) {
|
|
3766
|
+
throw new Error(ERR_INVALID_ENTRY_COMMENT);
|
|
3767
|
+
}
|
|
3768
|
+
const version = zipWriter.options.version || options.version || 0;
|
|
3769
|
+
if (version > MAX_16_BITS) {
|
|
3770
|
+
throw new Error(ERR_INVALID_VERSION);
|
|
3771
|
+
}
|
|
3772
|
+
const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
|
|
3773
|
+
if (versionMadeBy > MAX_16_BITS) {
|
|
3774
|
+
throw new Error(ERR_INVALID_VERSION);
|
|
3775
|
+
}
|
|
3776
|
+
const lastModDate = getOptionValue(zipWriter, options, "lastModDate") || new Date();
|
|
3777
|
+
const lastAccessDate = getOptionValue(zipWriter, options, "lastAccessDate");
|
|
3778
|
+
const creationDate = getOptionValue(zipWriter, options, "creationDate");
|
|
3779
|
+
const password = getOptionValue(zipWriter, options, "password");
|
|
3780
|
+
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
3781
|
+
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
3782
|
+
if (password !== undefined && encryptionStrength !== undefined && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
3783
|
+
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
3784
|
+
}
|
|
3785
|
+
let rawExtraField = new Uint8Array();
|
|
3786
|
+
const { extraField } = options;
|
|
3787
|
+
if (extraField) {
|
|
3788
|
+
let extraFieldSize = 0;
|
|
3789
|
+
let offset = 0;
|
|
3790
|
+
extraField.forEach(data => extraFieldSize += 4 + getLength(data));
|
|
3791
|
+
rawExtraField = new Uint8Array(extraFieldSize);
|
|
3792
|
+
extraField.forEach((data, type) => {
|
|
3793
|
+
if (type > MAX_16_BITS) {
|
|
3794
|
+
throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
|
|
3795
|
+
}
|
|
3796
|
+
if (getLength(data) > MAX_16_BITS) {
|
|
3797
|
+
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
3798
|
+
}
|
|
3799
|
+
arraySet(rawExtraField, new Uint16Array([type]), offset);
|
|
3800
|
+
arraySet(rawExtraField, new Uint16Array([getLength(data)]), offset + 2);
|
|
3801
|
+
arraySet(rawExtraField, data, offset + 4);
|
|
3802
|
+
offset += 4 + getLength(data);
|
|
3803
|
+
});
|
|
3804
|
+
}
|
|
3805
|
+
let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
|
|
3806
|
+
if (extendedTimestamp === undefined) {
|
|
3807
|
+
extendedTimestamp = true;
|
|
3808
|
+
}
|
|
3809
|
+
let maximumCompressedSize = 0;
|
|
3810
|
+
let maximumEntrySize = 0;
|
|
3811
|
+
let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
|
|
3812
|
+
if (keepOrder === undefined) {
|
|
3813
|
+
keepOrder = true;
|
|
3814
|
+
}
|
|
3815
|
+
let uncompressedSize = 0;
|
|
3816
|
+
let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
|
|
3817
|
+
if (msDosCompatible === undefined) {
|
|
3818
|
+
msDosCompatible = true;
|
|
3819
|
+
}
|
|
3820
|
+
const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
|
|
3821
|
+
const externalFileAttribute = getOptionValue(zipWriter, options, "externalFileAttribute") || 0;
|
|
3822
|
+
let zip64 = getOptionValue(zipWriter, options, "zip64");
|
|
3823
|
+
if (reader) {
|
|
3824
|
+
if (reader instanceof ReadableStream) {
|
|
3825
|
+
reader = {
|
|
3826
|
+
readable: reader
|
|
3827
|
+
};
|
|
3828
|
+
}
|
|
3829
|
+
await initStream(reader);
|
|
3830
|
+
if (reader.size === undefined) {
|
|
3831
|
+
options.dataDescriptor = true;
|
|
3832
|
+
if (zip64 === undefined) {
|
|
3833
|
+
zip64 = true;
|
|
3834
|
+
}
|
|
3835
|
+
} else {
|
|
3836
|
+
uncompressedSize = reader.size;
|
|
3837
|
+
}
|
|
3838
|
+
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
3839
|
+
}
|
|
3840
|
+
if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
|
|
3841
|
+
uncompressedSize >= MAX_32_BITS ||
|
|
3842
|
+
maximumCompressedSize >= MAX_32_BITS) {
|
|
3843
|
+
if (zip64 === false || !keepOrder) {
|
|
3844
|
+
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
3845
|
+
} else {
|
|
3846
|
+
zip64 = true;
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
zip64 = zip64 || false;
|
|
3850
|
+
const level = getOptionValue(zipWriter, options, "level");
|
|
3851
|
+
const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
|
|
3852
|
+
const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
|
|
3853
|
+
let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
|
|
3854
|
+
let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
|
|
3855
|
+
const signal = getOptionValue(zipWriter, options, "signal");
|
|
3856
|
+
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
3857
|
+
if (dataDescriptor === undefined) {
|
|
3858
|
+
dataDescriptor = true;
|
|
3859
|
+
}
|
|
3860
|
+
if (dataDescriptor && dataDescriptorSignature === undefined) {
|
|
3861
|
+
dataDescriptorSignature = false;
|
|
3862
|
+
}
|
|
3863
|
+
options = Object.assign({}, options, {
|
|
3864
|
+
rawFilename,
|
|
3865
|
+
rawComment,
|
|
3866
|
+
version,
|
|
3867
|
+
versionMadeBy,
|
|
3868
|
+
lastModDate,
|
|
3869
|
+
lastAccessDate,
|
|
3870
|
+
creationDate,
|
|
3871
|
+
rawExtraField,
|
|
3872
|
+
zip64,
|
|
3873
|
+
password,
|
|
3874
|
+
level,
|
|
3875
|
+
useWebWorkers,
|
|
3876
|
+
encryptionStrength,
|
|
3877
|
+
extendedTimestamp,
|
|
3878
|
+
zipCrypto,
|
|
3879
|
+
bufferedWrite,
|
|
3880
|
+
keepOrder,
|
|
3881
|
+
dataDescriptor,
|
|
3882
|
+
dataDescriptorSignature,
|
|
3883
|
+
signal,
|
|
3884
|
+
msDosCompatible,
|
|
3885
|
+
internalFileAttribute,
|
|
3886
|
+
externalFileAttribute,
|
|
3887
|
+
useCompressionStream
|
|
3888
|
+
});
|
|
3889
|
+
const headerInfo = getHeaderInfo(options);
|
|
3890
|
+
const dataDescriptorInfo = getDataDescriptorInfo(options);
|
|
3891
|
+
maximumEntrySize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray) + maximumCompressedSize;
|
|
3892
|
+
zipWriter.pendingEntriesSize += maximumEntrySize;
|
|
3893
|
+
let fileEntry;
|
|
3894
|
+
try {
|
|
3895
|
+
fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
|
|
3896
|
+
} catch (error) {
|
|
3897
|
+
if (!error.corruptedEntry && maximumEntrySize) {
|
|
3898
|
+
zipWriter.pendingEntriesSize -= maximumEntrySize;
|
|
3899
|
+
}
|
|
3900
|
+
throw error;
|
|
3901
|
+
}
|
|
3902
|
+
Object.assign(fileEntry, { name, comment, extraField });
|
|
3903
|
+
return new Entry(fileEntry);
|
|
3904
|
+
}
|
|
3905
|
+
|
|
3906
|
+
async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
3907
|
+
const {
|
|
3908
|
+
files,
|
|
3909
|
+
writer
|
|
3910
|
+
} = zipWriter;
|
|
3911
|
+
const {
|
|
3912
|
+
keepOrder,
|
|
3913
|
+
dataDescriptor,
|
|
3914
|
+
zipCrypto,
|
|
3915
|
+
signal
|
|
3916
|
+
} = options;
|
|
3917
|
+
const previousFileEntry = Array.from(files.values()).pop();
|
|
3918
|
+
let fileEntry = {};
|
|
3919
|
+
let bufferedWrite;
|
|
3920
|
+
let releaseLockWriter;
|
|
3921
|
+
let releaseLockCurrentFileEntry;
|
|
3922
|
+
let writingBufferedEntryData;
|
|
3923
|
+
let writingEntryData;
|
|
3924
|
+
let fileWriter;
|
|
3925
|
+
files.set(name, fileEntry);
|
|
3926
|
+
try {
|
|
3927
|
+
let lockPreviousFileEntry;
|
|
3928
|
+
if (keepOrder) {
|
|
3929
|
+
lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
|
|
3930
|
+
requestLockCurrentFileEntry();
|
|
3931
|
+
}
|
|
3932
|
+
if (options.bufferedWrite || zipWriter.lockWriter || !dataDescriptor) {
|
|
3933
|
+
fileWriter = new BlobWriter();
|
|
3934
|
+
fileWriter.writable.size = 0;
|
|
3935
|
+
bufferedWrite = true;
|
|
3936
|
+
await initStream(writer);
|
|
3937
|
+
} else {
|
|
3938
|
+
fileWriter = writer;
|
|
3939
|
+
zipWriter.lockWriter = Promise.resolve();
|
|
3940
|
+
releaseLockWriter = () => delete zipWriter.lockWriter;
|
|
3941
|
+
}
|
|
3942
|
+
await initStream(fileWriter);
|
|
3943
|
+
if (!bufferedWrite) {
|
|
3944
|
+
await lockPreviousFileEntry;
|
|
3945
|
+
}
|
|
3946
|
+
writingEntryData = true;
|
|
3947
|
+
fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
|
|
3948
|
+
writingEntryData = false;
|
|
3949
|
+
files.set(name, fileEntry);
|
|
3950
|
+
fileEntry.filename = name;
|
|
3951
|
+
if (bufferedWrite) {
|
|
3952
|
+
await fileWriter.writable.close();
|
|
3953
|
+
let blob = await fileWriter.getData();
|
|
3954
|
+
await lockPreviousFileEntry;
|
|
3955
|
+
await requestLockWriter();
|
|
3956
|
+
writingBufferedEntryData = true;
|
|
3957
|
+
const { writable } = writer;
|
|
3958
|
+
if (!dataDescriptor) {
|
|
3959
|
+
const arrayBuffer = await sliceAsArrayBuffer(blob, 0, 26);
|
|
3960
|
+
const arrayBufferView = new DataView(arrayBuffer);
|
|
3961
|
+
if (!fileEntry.encrypted || zipCrypto) {
|
|
3962
|
+
setUint32(arrayBufferView, 14, fileEntry.signature);
|
|
3963
|
+
}
|
|
3964
|
+
if (fileEntry.zip64) {
|
|
3965
|
+
setUint32(arrayBufferView, 18, MAX_32_BITS);
|
|
3966
|
+
setUint32(arrayBufferView, 22, MAX_32_BITS);
|
|
3967
|
+
} else {
|
|
3968
|
+
setUint32(arrayBufferView, 18, fileEntry.compressedSize);
|
|
3969
|
+
setUint32(arrayBufferView, 22, fileEntry.uncompressedSize);
|
|
3970
|
+
}
|
|
3971
|
+
await writeData(writable, new Uint8Array(arrayBuffer));
|
|
3972
|
+
blob = blob.slice(arrayBuffer.byteLength);
|
|
3973
|
+
}
|
|
3974
|
+
await blob.stream().pipeTo(writable, { preventClose: true, signal });
|
|
3975
|
+
writingBufferedEntryData = false;
|
|
3976
|
+
}
|
|
3977
|
+
fileEntry.offset = zipWriter.offset;
|
|
3978
|
+
if (fileEntry.zip64) {
|
|
3979
|
+
const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
|
|
3980
|
+
setBigUint64(rawExtraFieldZip64View, 20, BigInt(fileEntry.offset));
|
|
3981
|
+
} else if (fileEntry.offset >= MAX_32_BITS) {
|
|
3982
|
+
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
3983
|
+
}
|
|
3984
|
+
zipWriter.offset += fileEntry.length;
|
|
3985
|
+
return fileEntry;
|
|
3986
|
+
} catch (error) {
|
|
3987
|
+
if ((bufferedWrite && writingBufferedEntryData) || (!bufferedWrite && writingEntryData)) {
|
|
3988
|
+
zipWriter.hasCorruptedEntries = true;
|
|
3989
|
+
if (error) {
|
|
3990
|
+
error.corruptedEntry = true;
|
|
3991
|
+
}
|
|
3992
|
+
if (bufferedWrite) {
|
|
3993
|
+
zipWriter.offset += fileWriter.writable.size;
|
|
3994
|
+
} else {
|
|
3995
|
+
zipWriter.offset = fileWriter.writable.size;
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
files.delete(name);
|
|
3999
|
+
throw error;
|
|
4000
|
+
} finally {
|
|
4001
|
+
if (releaseLockCurrentFileEntry) {
|
|
4002
|
+
releaseLockCurrentFileEntry();
|
|
4003
|
+
}
|
|
4004
|
+
if (releaseLockWriter) {
|
|
4005
|
+
releaseLockWriter();
|
|
4006
|
+
}
|
|
4007
|
+
}
|
|
4008
|
+
|
|
4009
|
+
function requestLockCurrentFileEntry() {
|
|
4010
|
+
fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
|
|
4011
|
+
}
|
|
4012
|
+
|
|
4013
|
+
async function requestLockWriter() {
|
|
4014
|
+
const { lockWriter } = zipWriter;
|
|
4015
|
+
if (lockWriter) {
|
|
4016
|
+
await lockWriter.then(() => delete zipWriter.lockWriter);
|
|
4017
|
+
return requestLockWriter();
|
|
4018
|
+
} else {
|
|
4019
|
+
zipWriter.lockWriter = new Promise(resolve => releaseLockWriter = resolve);
|
|
4020
|
+
}
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
4023
|
+
|
|
4024
|
+
async function createFileEntry(reader, writer, pendingFileEntry, entryInfo, config, options) {
|
|
4025
|
+
const {
|
|
4026
|
+
headerInfo,
|
|
4027
|
+
dataDescriptorInfo
|
|
4028
|
+
} = entryInfo;
|
|
4029
|
+
const {
|
|
4030
|
+
localHeaderArray,
|
|
4031
|
+
headerArray,
|
|
4032
|
+
lastModDate,
|
|
4033
|
+
rawLastModDate,
|
|
4034
|
+
encrypted,
|
|
4035
|
+
compressed,
|
|
4036
|
+
version,
|
|
4037
|
+
compressionMethod,
|
|
4038
|
+
rawExtraFieldExtendedTimestamp,
|
|
4039
|
+
rawExtraFieldNTFS,
|
|
4040
|
+
rawExtraFieldAES
|
|
4041
|
+
} = headerInfo;
|
|
4042
|
+
const { dataDescriptorArray } = dataDescriptorInfo;
|
|
4043
|
+
const {
|
|
4044
|
+
rawFilename,
|
|
4045
|
+
lastAccessDate,
|
|
4046
|
+
creationDate,
|
|
4047
|
+
password,
|
|
4048
|
+
level,
|
|
4049
|
+
zip64,
|
|
4050
|
+
zipCrypto,
|
|
4051
|
+
dataDescriptor,
|
|
4052
|
+
directory,
|
|
4053
|
+
versionMadeBy,
|
|
4054
|
+
rawComment,
|
|
4055
|
+
rawExtraField,
|
|
4056
|
+
useWebWorkers,
|
|
4057
|
+
onstart,
|
|
4058
|
+
onprogress,
|
|
4059
|
+
onend,
|
|
4060
|
+
signal,
|
|
4061
|
+
encryptionStrength,
|
|
4062
|
+
extendedTimestamp,
|
|
4063
|
+
msDosCompatible,
|
|
4064
|
+
internalFileAttribute,
|
|
4065
|
+
externalFileAttribute,
|
|
4066
|
+
useCompressionStream
|
|
4067
|
+
} = options;
|
|
4068
|
+
const fileEntry = {
|
|
4069
|
+
lock: pendingFileEntry.lock,
|
|
4070
|
+
versionMadeBy,
|
|
4071
|
+
zip64,
|
|
4072
|
+
directory: Boolean(directory),
|
|
4073
|
+
filenameUTF8: true,
|
|
4074
|
+
rawFilename,
|
|
4075
|
+
commentUTF8: true,
|
|
4076
|
+
rawComment,
|
|
4077
|
+
rawExtraFieldExtendedTimestamp,
|
|
4078
|
+
rawExtraFieldNTFS,
|
|
4079
|
+
rawExtraFieldAES,
|
|
4080
|
+
rawExtraField,
|
|
4081
|
+
extendedTimestamp,
|
|
4082
|
+
msDosCompatible,
|
|
4083
|
+
internalFileAttribute,
|
|
4084
|
+
externalFileAttribute
|
|
4085
|
+
};
|
|
4086
|
+
let uncompressedSize = 0;
|
|
4087
|
+
let signature;
|
|
4088
|
+
let compressedSize = 0;
|
|
4089
|
+
const { writable } = writer;
|
|
4090
|
+
if (reader) {
|
|
4091
|
+
reader.chunkSize = getChunkSize(config);
|
|
4092
|
+
await writeData(writable, localHeaderArray);
|
|
4093
|
+
const readable = reader.readable;
|
|
4094
|
+
const size = readable.size = reader.size;
|
|
4095
|
+
const workerOptions = {
|
|
4096
|
+
options: {
|
|
4097
|
+
codecType: CODEC_DEFLATE,
|
|
4098
|
+
level,
|
|
4099
|
+
password,
|
|
4100
|
+
encryptionStrength,
|
|
4101
|
+
zipCrypto: encrypted && zipCrypto,
|
|
4102
|
+
passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
|
|
4103
|
+
signed: true,
|
|
4104
|
+
compressed,
|
|
4105
|
+
encrypted,
|
|
4106
|
+
useWebWorkers,
|
|
4107
|
+
useCompressionStream,
|
|
4108
|
+
transferStreams: false
|
|
4109
|
+
},
|
|
4110
|
+
config,
|
|
4111
|
+
streamOptions: { signal, size, onstart, onprogress, onend }
|
|
4112
|
+
};
|
|
4113
|
+
const result = await runWorker({ readable, writable }, workerOptions);
|
|
4114
|
+
writable.size += result.size;
|
|
4115
|
+
signature = result.signature;
|
|
4116
|
+
uncompressedSize = reader.size = readable.size;
|
|
4117
|
+
compressedSize = result.size;
|
|
4118
|
+
} else {
|
|
4119
|
+
await writeData(writable, localHeaderArray);
|
|
4120
|
+
}
|
|
4121
|
+
const rawExtraFieldZip64 = zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array();
|
|
4122
|
+
if (reader) {
|
|
4123
|
+
setEntryInfo({
|
|
4124
|
+
signature,
|
|
4125
|
+
rawExtraFieldZip64,
|
|
4126
|
+
compressedSize,
|
|
4127
|
+
uncompressedSize,
|
|
4128
|
+
headerInfo,
|
|
4129
|
+
dataDescriptorInfo
|
|
4130
|
+
}, options);
|
|
4131
|
+
}
|
|
4132
|
+
if (dataDescriptor) {
|
|
4133
|
+
await writeData(writable, dataDescriptorArray);
|
|
4134
|
+
}
|
|
4135
|
+
Object.assign(fileEntry, {
|
|
4136
|
+
compressedSize,
|
|
4137
|
+
lastModDate,
|
|
4138
|
+
rawLastModDate,
|
|
4139
|
+
creationDate,
|
|
4140
|
+
lastAccessDate,
|
|
4141
|
+
encrypted,
|
|
4142
|
+
length: getLength(localHeaderArray, dataDescriptorArray) + compressedSize,
|
|
4143
|
+
compressionMethod,
|
|
4144
|
+
version,
|
|
4145
|
+
headerArray,
|
|
4146
|
+
signature,
|
|
4147
|
+
rawExtraFieldZip64
|
|
4148
|
+
});
|
|
4149
|
+
return fileEntry;
|
|
4150
|
+
}
|
|
4151
|
+
|
|
4152
|
+
function getHeaderInfo(options) {
|
|
4153
|
+
const {
|
|
4154
|
+
rawFilename,
|
|
4155
|
+
lastModDate,
|
|
4156
|
+
lastAccessDate,
|
|
4157
|
+
creationDate,
|
|
4158
|
+
password,
|
|
4159
|
+
level,
|
|
4160
|
+
zip64,
|
|
4161
|
+
zipCrypto,
|
|
4162
|
+
dataDescriptor,
|
|
4163
|
+
directory,
|
|
4164
|
+
rawExtraField,
|
|
4165
|
+
encryptionStrength,
|
|
4166
|
+
extendedTimestamp,
|
|
4167
|
+
} = options;
|
|
4168
|
+
const compressed = level !== 0 && !directory;
|
|
4169
|
+
const encrypted = Boolean(password && getLength(password));
|
|
4170
|
+
let rawExtraFieldAES;
|
|
4171
|
+
if (encrypted && !zipCrypto) {
|
|
4172
|
+
rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
|
|
4173
|
+
const extraFieldAESView = getDataView(rawExtraFieldAES);
|
|
4174
|
+
setUint16(extraFieldAESView, 0, EXTRAFIELD_TYPE_AES);
|
|
4175
|
+
arraySet(rawExtraFieldAES, EXTRAFIELD_DATA_AES, 2);
|
|
4176
|
+
setUint8(extraFieldAESView, 8, encryptionStrength);
|
|
4177
|
+
} else {
|
|
4178
|
+
rawExtraFieldAES = new Uint8Array();
|
|
4179
|
+
}
|
|
4180
|
+
let rawExtraFieldNTFS;
|
|
4181
|
+
let rawExtraFieldExtendedTimestamp;
|
|
4182
|
+
if (extendedTimestamp) {
|
|
4183
|
+
rawExtraFieldExtendedTimestamp = new Uint8Array(9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0));
|
|
4184
|
+
const extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);
|
|
4185
|
+
setUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
|
|
4186
|
+
setUint16(extraFieldExtendedTimestampView, 2, getLength(rawExtraFieldExtendedTimestamp) - 4);
|
|
4187
|
+
const extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
|
|
4188
|
+
setUint8(extraFieldExtendedTimestampView, 4, extraFieldExtendedTimestampFlag);
|
|
4189
|
+
setUint32(extraFieldExtendedTimestampView, 5, Math.floor(lastModDate.getTime() / 1000));
|
|
4190
|
+
if (lastAccessDate) {
|
|
4191
|
+
setUint32(extraFieldExtendedTimestampView, 9, Math.floor(lastAccessDate.getTime() / 1000));
|
|
4192
|
+
}
|
|
4193
|
+
if (creationDate) {
|
|
4194
|
+
setUint32(extraFieldExtendedTimestampView, 13, Math.floor(creationDate.getTime() / 1000));
|
|
4195
|
+
}
|
|
4196
|
+
try {
|
|
4197
|
+
rawExtraFieldNTFS = new Uint8Array(36);
|
|
4198
|
+
const extraFieldNTFSView = getDataView(rawExtraFieldNTFS);
|
|
4199
|
+
const lastModTimeNTFS = getTimeNTFS(lastModDate);
|
|
4200
|
+
setUint16(extraFieldNTFSView, 0, EXTRAFIELD_TYPE_NTFS);
|
|
4201
|
+
setUint16(extraFieldNTFSView, 2, 32);
|
|
4202
|
+
setUint16(extraFieldNTFSView, 8, EXTRAFIELD_TYPE_NTFS_TAG1);
|
|
4203
|
+
setUint16(extraFieldNTFSView, 10, 24);
|
|
4204
|
+
setBigUint64(extraFieldNTFSView, 12, lastModTimeNTFS);
|
|
4205
|
+
setBigUint64(extraFieldNTFSView, 20, getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
|
|
4206
|
+
setBigUint64(extraFieldNTFSView, 28, getTimeNTFS(creationDate) || lastModTimeNTFS);
|
|
4207
|
+
} catch (_error) {
|
|
4208
|
+
rawExtraFieldNTFS = new Uint8Array();
|
|
4209
|
+
}
|
|
4210
|
+
} else {
|
|
4211
|
+
rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
|
|
4212
|
+
}
|
|
4213
|
+
let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
|
|
4214
|
+
if (dataDescriptor) {
|
|
4215
|
+
bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
|
|
4216
|
+
}
|
|
4217
|
+
let compressionMethod = COMPRESSION_METHOD_STORE;
|
|
4218
|
+
if (compressed) {
|
|
4219
|
+
compressionMethod = COMPRESSION_METHOD_DEFLATE;
|
|
4220
|
+
}
|
|
4221
|
+
let version = options.version || VERSION_DEFLATE;
|
|
4222
|
+
if (zip64) {
|
|
4223
|
+
version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
|
|
4224
|
+
}
|
|
4225
|
+
if (encrypted) {
|
|
4226
|
+
bitFlag = bitFlag | BITFLAG_ENCRYPTED;
|
|
4227
|
+
if (!zipCrypto) {
|
|
4228
|
+
version = version > VERSION_AES ? version : VERSION_AES;
|
|
4229
|
+
compressionMethod = COMPRESSION_METHOD_AES;
|
|
4230
|
+
if (compressed) {
|
|
4231
|
+
rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
}
|
|
4235
|
+
const headerArray = new Uint8Array(26);
|
|
4236
|
+
const headerView = getDataView(headerArray);
|
|
4237
|
+
setUint16(headerView, 0, version);
|
|
4238
|
+
setUint16(headerView, 2, bitFlag);
|
|
4239
|
+
setUint16(headerView, 4, compressionMethod);
|
|
4240
|
+
const dateArray = new Uint32Array(1);
|
|
4241
|
+
const dateView = getDataView(dateArray);
|
|
4242
|
+
let lastModDateMsDos;
|
|
4243
|
+
if (lastModDate < MIN_DATE) {
|
|
4244
|
+
lastModDateMsDos = MIN_DATE;
|
|
4245
|
+
} else if (lastModDate > MAX_DATE) {
|
|
4246
|
+
lastModDateMsDos = MAX_DATE;
|
|
4247
|
+
} else {
|
|
4248
|
+
lastModDateMsDos = lastModDate;
|
|
4249
|
+
}
|
|
4250
|
+
setUint16(dateView, 0, (((lastModDateMsDos.getHours() << 6) | lastModDateMsDos.getMinutes()) << 5) | lastModDateMsDos.getSeconds() / 2);
|
|
4251
|
+
setUint16(dateView, 2, ((((lastModDateMsDos.getFullYear() - 1980) << 4) | (lastModDateMsDos.getMonth() + 1)) << 5) | lastModDateMsDos.getDate());
|
|
4252
|
+
const rawLastModDate = dateArray[0];
|
|
4253
|
+
setUint32(headerView, 6, rawLastModDate);
|
|
4254
|
+
setUint16(headerView, 22, getLength(rawFilename));
|
|
4255
|
+
const extraFieldLength = getLength(rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraField);
|
|
4256
|
+
setUint16(headerView, 24, extraFieldLength);
|
|
4257
|
+
const localHeaderArray = new Uint8Array(30 + getLength(rawFilename) + extraFieldLength);
|
|
4258
|
+
const localHeaderView = getDataView(localHeaderArray);
|
|
4259
|
+
setUint32(localHeaderView, 0, LOCAL_FILE_HEADER_SIGNATURE);
|
|
4260
|
+
arraySet(localHeaderArray, headerArray, 4);
|
|
4261
|
+
arraySet(localHeaderArray, rawFilename, 30);
|
|
4262
|
+
arraySet(localHeaderArray, rawExtraFieldAES, 30 + getLength(rawFilename));
|
|
4263
|
+
arraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + getLength(rawFilename, rawExtraFieldAES));
|
|
4264
|
+
arraySet(localHeaderArray, rawExtraFieldNTFS, 30 + getLength(rawFilename, rawExtraFieldAES, rawExtraFieldExtendedTimestamp));
|
|
4265
|
+
arraySet(localHeaderArray, rawExtraField, 30 + getLength(rawFilename, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS));
|
|
4266
|
+
return {
|
|
4267
|
+
localHeaderArray,
|
|
4268
|
+
headerArray,
|
|
4269
|
+
headerView,
|
|
4270
|
+
lastModDate,
|
|
4271
|
+
rawLastModDate,
|
|
4272
|
+
encrypted,
|
|
4273
|
+
compressed,
|
|
4274
|
+
version,
|
|
4275
|
+
compressionMethod,
|
|
4276
|
+
rawExtraFieldExtendedTimestamp,
|
|
4277
|
+
rawExtraFieldNTFS,
|
|
4278
|
+
rawExtraFieldAES
|
|
4279
|
+
};
|
|
4280
|
+
}
|
|
4281
|
+
|
|
4282
|
+
function getDataDescriptorInfo(options) {
|
|
4283
|
+
const {
|
|
4284
|
+
zip64,
|
|
4285
|
+
dataDescriptor,
|
|
4286
|
+
dataDescriptorSignature
|
|
4287
|
+
} = options;
|
|
4288
|
+
let dataDescriptorArray = new Uint8Array();
|
|
4289
|
+
let dataDescriptorView, dataDescriptorOffset = 0;
|
|
4290
|
+
if (dataDescriptor) {
|
|
4291
|
+
dataDescriptorArray = new Uint8Array(zip64 ? (dataDescriptorSignature ? 24 : 20) : (dataDescriptorSignature ? 16 : 12));
|
|
4292
|
+
dataDescriptorView = getDataView(dataDescriptorArray);
|
|
4293
|
+
if (dataDescriptorSignature) {
|
|
4294
|
+
dataDescriptorOffset = 4;
|
|
4295
|
+
setUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
return {
|
|
4299
|
+
dataDescriptorArray,
|
|
4300
|
+
dataDescriptorView,
|
|
4301
|
+
dataDescriptorOffset
|
|
4302
|
+
};
|
|
4303
|
+
}
|
|
4304
|
+
|
|
4305
|
+
function setEntryInfo(entryInfo, options) {
|
|
4306
|
+
const {
|
|
4307
|
+
signature,
|
|
4308
|
+
rawExtraFieldZip64,
|
|
4309
|
+
compressedSize,
|
|
4310
|
+
uncompressedSize,
|
|
4311
|
+
headerInfo,
|
|
4312
|
+
dataDescriptorInfo
|
|
4313
|
+
} = entryInfo;
|
|
4314
|
+
const {
|
|
4315
|
+
headerView,
|
|
4316
|
+
encrypted
|
|
4317
|
+
} = headerInfo;
|
|
4318
|
+
const {
|
|
4319
|
+
dataDescriptorView,
|
|
4320
|
+
dataDescriptorOffset
|
|
4321
|
+
} = dataDescriptorInfo;
|
|
4322
|
+
const {
|
|
4323
|
+
zip64,
|
|
4324
|
+
zipCrypto,
|
|
4325
|
+
dataDescriptor
|
|
4326
|
+
} = options;
|
|
4327
|
+
if ((!encrypted || zipCrypto) && signature !== undefined) {
|
|
4328
|
+
setUint32(headerView, 10, signature);
|
|
4329
|
+
if (dataDescriptor) {
|
|
4330
|
+
setUint32(dataDescriptorView, dataDescriptorOffset, signature);
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
if (zip64) {
|
|
4334
|
+
const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
|
|
4335
|
+
setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
|
|
4336
|
+
setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
|
|
4337
|
+
setUint32(headerView, 14, MAX_32_BITS);
|
|
4338
|
+
setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
|
|
4339
|
+
setUint32(headerView, 18, MAX_32_BITS);
|
|
4340
|
+
setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
|
|
4341
|
+
if (dataDescriptor) {
|
|
4342
|
+
setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
|
|
4343
|
+
setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
|
|
4344
|
+
}
|
|
4345
|
+
} else {
|
|
4346
|
+
setUint32(headerView, 14, compressedSize);
|
|
4347
|
+
setUint32(headerView, 18, uncompressedSize);
|
|
4348
|
+
if (dataDescriptor) {
|
|
4349
|
+
setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
|
|
4350
|
+
setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
|
|
4355
|
+
async function closeFile(zipWriter, comment, options) {
|
|
4356
|
+
const { files } = zipWriter;
|
|
4357
|
+
let offset = 0;
|
|
4358
|
+
let directoryDataLength = 0;
|
|
4359
|
+
let directoryOffset = zipWriter.offset;
|
|
4360
|
+
let filesLength = files.size;
|
|
4361
|
+
for (const [, {
|
|
4362
|
+
rawFilename,
|
|
4363
|
+
rawExtraFieldZip64,
|
|
4364
|
+
rawExtraFieldAES,
|
|
4365
|
+
rawExtraField,
|
|
4366
|
+
rawComment,
|
|
4367
|
+
rawExtraFieldExtendedTimestamp,
|
|
4368
|
+
rawExtraFieldNTFS
|
|
4369
|
+
}] of files) {
|
|
4370
|
+
directoryDataLength += 46 +
|
|
4371
|
+
getLength(
|
|
4372
|
+
rawFilename,
|
|
4373
|
+
rawComment,
|
|
4374
|
+
rawExtraFieldZip64,
|
|
4375
|
+
rawExtraFieldAES,
|
|
4376
|
+
rawExtraFieldExtendedTimestamp,
|
|
4377
|
+
rawExtraFieldNTFS,
|
|
4378
|
+
rawExtraField);
|
|
4379
|
+
}
|
|
4380
|
+
let zip64 = options.zip64 || zipWriter.options.zip64 || false;
|
|
4381
|
+
if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
|
|
4382
|
+
if (options.zip64 === false || zipWriter.options.zip64 === false) {
|
|
4383
|
+
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
4384
|
+
} else {
|
|
4385
|
+
zip64 = true;
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4388
|
+
const directoryArray = new Uint8Array(directoryDataLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH));
|
|
4389
|
+
const directoryView = getDataView(directoryArray);
|
|
4390
|
+
for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
|
|
4391
|
+
const {
|
|
4392
|
+
offset: fileEntryOffset,
|
|
4393
|
+
rawFilename,
|
|
4394
|
+
rawExtraFieldZip64,
|
|
4395
|
+
rawExtraFieldAES,
|
|
4396
|
+
rawExtraFieldNTFS,
|
|
4397
|
+
rawExtraField,
|
|
4398
|
+
rawComment,
|
|
4399
|
+
versionMadeBy,
|
|
4400
|
+
headerArray,
|
|
4401
|
+
directory,
|
|
4402
|
+
zip64,
|
|
4403
|
+
msDosCompatible,
|
|
4404
|
+
internalFileAttribute,
|
|
4405
|
+
externalFileAttribute,
|
|
4406
|
+
extendedTimestamp,
|
|
4407
|
+
lastModDate
|
|
4408
|
+
} = fileEntry;
|
|
4409
|
+
let rawExtraFieldExtendedTimestamp;
|
|
4410
|
+
if (extendedTimestamp) {
|
|
4411
|
+
rawExtraFieldExtendedTimestamp = new Uint8Array(9);
|
|
4412
|
+
const extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);
|
|
4413
|
+
setUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
|
|
4414
|
+
setUint16(extraFieldExtendedTimestampView, 2, getLength(rawExtraFieldExtendedTimestamp) - 4);
|
|
4415
|
+
setUint8(extraFieldExtendedTimestampView, 4, 0x1);
|
|
4416
|
+
setUint32(extraFieldExtendedTimestampView, 5, Math.floor(lastModDate.getTime() / 1000));
|
|
4417
|
+
} else {
|
|
4418
|
+
rawExtraFieldExtendedTimestamp = new Uint8Array();
|
|
4419
|
+
}
|
|
4420
|
+
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraField);
|
|
4421
|
+
setUint32(directoryView, offset, CENTRAL_FILE_HEADER_SIGNATURE);
|
|
4422
|
+
setUint16(directoryView, offset + 4, versionMadeBy);
|
|
4423
|
+
arraySet(directoryArray, headerArray, offset + 6);
|
|
4424
|
+
setUint16(directoryView, offset + 30, extraFieldLength);
|
|
4425
|
+
setUint16(directoryView, offset + 32, getLength(rawComment));
|
|
4426
|
+
setUint16(directoryView, offset + 36, internalFileAttribute);
|
|
4427
|
+
if (externalFileAttribute) {
|
|
4428
|
+
setUint32(directoryView, offset + 38, externalFileAttribute);
|
|
4429
|
+
} else if (directory && msDosCompatible) {
|
|
4430
|
+
setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
|
|
4431
|
+
}
|
|
4432
|
+
if (zip64) {
|
|
4433
|
+
setUint32(directoryView, offset + 42, MAX_32_BITS);
|
|
4434
|
+
} else {
|
|
4435
|
+
setUint32(directoryView, offset + 42, fileEntryOffset);
|
|
4436
|
+
}
|
|
4437
|
+
arraySet(directoryArray, rawFilename, offset + 46);
|
|
4438
|
+
arraySet(directoryArray, rawExtraFieldZip64, offset + 46 + getLength(rawFilename));
|
|
4439
|
+
arraySet(directoryArray, rawExtraFieldAES, offset + 46 + getLength(rawFilename, rawExtraFieldZip64));
|
|
4440
|
+
arraySet(directoryArray, rawExtraFieldExtendedTimestamp, offset + 46 + getLength(rawFilename, rawExtraFieldZip64, rawExtraFieldAES));
|
|
4441
|
+
arraySet(directoryArray, rawExtraFieldNTFS, offset + 46 + getLength(rawFilename, rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp));
|
|
4442
|
+
arraySet(directoryArray, rawExtraField, offset + 46 + getLength(rawFilename, rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS));
|
|
4443
|
+
arraySet(directoryArray, rawComment, offset + 46 + getLength(rawFilename) + extraFieldLength);
|
|
4444
|
+
offset += 46 + getLength(rawFilename, rawComment) + extraFieldLength;
|
|
4445
|
+
if (options.onprogress) {
|
|
4446
|
+
try {
|
|
4447
|
+
await options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
|
|
4448
|
+
} catch (_error) {
|
|
4449
|
+
// ignored
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
if (zip64) {
|
|
4454
|
+
setUint32(directoryView, offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
|
|
4455
|
+
setBigUint64(directoryView, offset + 4, BigInt(44));
|
|
4456
|
+
setUint16(directoryView, offset + 12, 45);
|
|
4457
|
+
setUint16(directoryView, offset + 14, 45);
|
|
4458
|
+
setBigUint64(directoryView, offset + 24, BigInt(filesLength));
|
|
4459
|
+
setBigUint64(directoryView, offset + 32, BigInt(filesLength));
|
|
4460
|
+
setBigUint64(directoryView, offset + 40, BigInt(directoryDataLength));
|
|
4461
|
+
setBigUint64(directoryView, offset + 48, BigInt(directoryOffset));
|
|
4462
|
+
setUint32(directoryView, offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
|
|
4463
|
+
setBigUint64(directoryView, offset + 64, BigInt(directoryOffset) + BigInt(directoryDataLength));
|
|
4464
|
+
setUint32(directoryView, offset + 72, ZIP64_TOTAL_NUMBER_OF_DISKS);
|
|
4465
|
+
filesLength = MAX_16_BITS;
|
|
4466
|
+
directoryOffset = MAX_32_BITS;
|
|
4467
|
+
directoryDataLength = MAX_32_BITS;
|
|
4468
|
+
offset += 76;
|
|
4469
|
+
}
|
|
4470
|
+
setUint32(directoryView, offset, END_OF_CENTRAL_DIR_SIGNATURE);
|
|
4471
|
+
setUint16(directoryView, offset + 8, filesLength);
|
|
4472
|
+
setUint16(directoryView, offset + 10, filesLength);
|
|
4473
|
+
setUint32(directoryView, offset + 12, directoryDataLength);
|
|
4474
|
+
setUint32(directoryView, offset + 16, directoryOffset);
|
|
4475
|
+
const commentLength = getLength(comment);
|
|
4476
|
+
if (commentLength) {
|
|
4477
|
+
if (commentLength <= MAX_16_BITS) {
|
|
4478
|
+
setUint16(directoryView, offset + 20, commentLength);
|
|
4479
|
+
} else {
|
|
4480
|
+
throw new Error(ERR_INVALID_COMMENT);
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
const { writable } = zipWriter.writer;
|
|
4484
|
+
await initStream(zipWriter.writer);
|
|
4485
|
+
await writeData(writable, directoryArray);
|
|
4486
|
+
if (commentLength) {
|
|
4487
|
+
await writeData(writable, comment);
|
|
4488
|
+
}
|
|
4489
|
+
}
|
|
4490
|
+
|
|
4491
|
+
function sliceAsArrayBuffer(blob, start, end) {
|
|
4492
|
+
if (start || end) {
|
|
4493
|
+
return blob.slice(start, end).arrayBuffer();
|
|
4494
|
+
} else {
|
|
4495
|
+
return blob.arrayBuffer();
|
|
4496
|
+
}
|
|
4497
|
+
}
|
|
4498
|
+
|
|
4499
|
+
async function writeData(writable, array) {
|
|
4500
|
+
const streamWriter = writable.getWriter();
|
|
4501
|
+
await streamWriter.ready;
|
|
4502
|
+
writable.size += getLength(array);
|
|
4503
|
+
await streamWriter.write(array);
|
|
4504
|
+
streamWriter.releaseLock();
|
|
4505
|
+
}
|
|
4506
|
+
|
|
4507
|
+
function getTimeNTFS(date) {
|
|
4508
|
+
if (date) {
|
|
4509
|
+
return ((BigInt(date.getTime()) + BigInt(11644473600000)) * BigInt(10000));
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
|
|
4513
|
+
function getOptionValue(zipWriter, options, name) {
|
|
4514
|
+
return options[name] === undefined ? zipWriter.options[name] : options[name];
|
|
4515
|
+
}
|
|
4516
|
+
|
|
4517
|
+
function getMaximumCompressedSize(uncompressedSize) {
|
|
4518
|
+
return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
|
|
4519
|
+
}
|
|
4520
|
+
|
|
4521
|
+
function setUint8(view, offset, value) {
|
|
4522
|
+
view.setUint8(offset, value);
|
|
4523
|
+
}
|
|
4524
|
+
|
|
4525
|
+
function setUint16(view, offset, value) {
|
|
4526
|
+
view.setUint16(offset, value, true);
|
|
4527
|
+
}
|
|
4528
|
+
|
|
4529
|
+
function setUint32(view, offset, value) {
|
|
4530
|
+
view.setUint32(offset, value, true);
|
|
4531
|
+
}
|
|
4532
|
+
|
|
4533
|
+
function setBigUint64(view, offset, value) {
|
|
4534
|
+
view.setBigUint64(offset, value, true);
|
|
4535
|
+
}
|
|
4536
|
+
|
|
4537
|
+
function arraySet(array, typedArray, offset) {
|
|
4538
|
+
array.set(typedArray, offset);
|
|
4539
|
+
}
|
|
4540
|
+
|
|
4541
|
+
function getDataView(array) {
|
|
4542
|
+
return new DataView(array.buffer);
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4545
|
+
function getLength(...arrayLikes) {
|
|
4546
|
+
let result = 0;
|
|
4547
|
+
arrayLikes.forEach(arrayLike => arrayLike && (result += arrayLike.length));
|
|
4548
|
+
return result;
|
|
4549
|
+
}
|
|
4550
|
+
|
|
4551
|
+
/*
|
|
4552
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
4553
|
+
|
|
4554
|
+
Redistribution and use in source and binary forms, with or without
|
|
4555
|
+
modification, are permitted provided that the following conditions are met:
|
|
4556
|
+
|
|
4557
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
4558
|
+
this list of conditions and the following disclaimer.
|
|
4559
|
+
|
|
4560
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
4561
|
+
notice, this list of conditions and the following disclaimer in
|
|
4562
|
+
the documentation and/or other materials provided with the distribution.
|
|
4563
|
+
|
|
4564
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
4565
|
+
derived from this software without specific prior written permission.
|
|
4566
|
+
|
|
4567
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4568
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4569
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4570
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4571
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
4572
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
4573
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
4574
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
4575
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
4576
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4577
|
+
*/
|
|
4578
|
+
|
|
4579
|
+
let baseURL;
|
|
4580
|
+
try {
|
|
4581
|
+
baseURL = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('zip.js', document.baseURI).href));
|
|
4582
|
+
} catch (error) {
|
|
4583
|
+
// ignored
|
|
4584
|
+
}
|
|
4585
|
+
configure({ baseURL });
|
|
4586
|
+
e(configure);
|
|
4587
|
+
|
|
4588
|
+
exports.BlobReader = BlobReader;
|
|
4589
|
+
exports.BlobWriter = BlobWriter;
|
|
4590
|
+
exports.Data64URIReader = Data64URIReader;
|
|
4591
|
+
exports.Data64URIWriter = Data64URIWriter;
|
|
4592
|
+
exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
|
|
4593
|
+
exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
|
|
4594
|
+
exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
|
|
4595
|
+
exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
|
|
4596
|
+
exports.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND;
|
|
4597
|
+
exports.ERR_EOCDR_NOT_FOUND = ERR_EOCDR_NOT_FOUND;
|
|
4598
|
+
exports.ERR_EOCDR_ZIP64_NOT_FOUND = ERR_EOCDR_ZIP64_NOT_FOUND;
|
|
4599
|
+
exports.ERR_EXTRAFIELD_ZIP64_NOT_FOUND = ERR_EXTRAFIELD_ZIP64_NOT_FOUND;
|
|
4600
|
+
exports.ERR_HTTP_RANGE = ERR_HTTP_RANGE;
|
|
4601
|
+
exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
|
|
4602
|
+
exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
|
|
4603
|
+
exports.ERR_INVALID_ENTRY_COMMENT = ERR_INVALID_ENTRY_COMMENT;
|
|
4604
|
+
exports.ERR_INVALID_ENTRY_NAME = ERR_INVALID_ENTRY_NAME;
|
|
4605
|
+
exports.ERR_INVALID_EXTRAFIELD_DATA = ERR_INVALID_EXTRAFIELD_DATA;
|
|
4606
|
+
exports.ERR_INVALID_EXTRAFIELD_TYPE = ERR_INVALID_EXTRAFIELD_TYPE;
|
|
4607
|
+
exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
|
|
4608
|
+
exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
|
|
4609
|
+
exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
|
|
4610
|
+
exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
|
|
4611
|
+
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
4612
|
+
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
|
|
4613
|
+
exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
|
|
4614
|
+
exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
|
|
4615
|
+
exports.HttpRangeReader = HttpRangeReader;
|
|
4616
|
+
exports.HttpReader = HttpReader;
|
|
4617
|
+
exports.Reader = Reader;
|
|
4618
|
+
exports.SplitZipReader = SplitZipReader;
|
|
4619
|
+
exports.TextReader = TextReader;
|
|
4620
|
+
exports.TextWriter = TextWriter;
|
|
4621
|
+
exports.Uint8ArrayReader = Uint8ArrayReader;
|
|
4622
|
+
exports.Uint8ArrayWriter = Uint8ArrayWriter;
|
|
4623
|
+
exports.Writer = Writer;
|
|
4624
|
+
exports.ZipReader = ZipReader;
|
|
4625
|
+
exports.ZipWriter = ZipWriter;
|
|
4626
|
+
exports.configure = configure;
|
|
4627
|
+
exports.getMimeType = getMimeType;
|
|
4628
|
+
exports.initShimAsyncCodec = initShimAsyncCodec;
|
|
4629
|
+
exports.initStream = initStream;
|
|
4630
|
+
exports.readUint8Array = readUint8Array;
|
|
4631
|
+
exports.terminateWorkers = terminateWorkers;
|
|
4632
|
+
|
|
4633
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4634
|
+
|
|
4635
|
+
}));
|