@zip.js/zip.js 2.8.35 → 2.8.36

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/index.cjs CHANGED
@@ -214,7 +214,7 @@ function resetConfiguration() {
214
214
  Object.assign(config, DEFAULT_CONFIGURATION);
215
215
  }
216
216
 
217
- function t$1(t){const e='(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:i,Uint32Array:c,Int32Array:a,Map:f,DataView:l,Promise:u,TextEncoder:w,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:g,DecompressionStream:v}=self,b=void 0,S="undefined",k="function",z=new o,C=[[],[],[],[],[],[],[],[]];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)e=1&e?e>>>1^3988292384:e>>>1;C[0][t]=e}for(let t=0;256>t;t++)for(let e=1;8>e;e++){const n=C[e-1][t];C[e][t]=n>>>8^C[0][255&n]}const[A,I,x,P,R,U,M,_]=C;class B{constructor(t){this.o=t||-1}append(t){let e=0|this.o;const n=0|t.length;let s=0;if(n>=8&&t.buffer){const r=new l(t.buffer,t.byteOffset,n),o=n-8;for(;o>=s;s+=8){const t=e^r.getInt32(s,!0),n=r.getInt32(s+4,!0);e=_[255&t]^M[t>>>8&255]^U[t>>>16&255]^R[t>>>24&255]^P[255&n]^x[n>>>8&255]^I[n>>>16&255]^A[n>>>24&255]}}for(;n>s;s++)e=e>>>8^A[255&(e^t[s])];this.o=e}get(){return~this.o}}class D extends d{constructor(){let t;const e=new B;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new l(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}function V(t,e){const n=new o(t.length+e.length);return n.set(t),n.set(e,t.length),n}const W={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=W.l(n);return 32===s?t.concat(e):W.h(e,s,0|n,t.slice(0,t.length-1))},m(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+W.l(n)},v(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=W.S(e,t[n-1]&2147483648>>e-1,1)),t},S:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,l:t=>s.round(t/1099511627776)||32,h(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=W.l(r);return s.push(W.S(e+o&31,e+o>32?n:s.pop(),1)),s}},K={bytes:{C(t){const e=W.m(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},A(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(W.S(8*(3&n),s)),e}}},E=class{constructor(t){const e=this;e.blockSize=512,e.I=[1732584193,4023233417,2562383102,271733878,3285377520],e.P=[1518500249,1859775393,2400959708,3395469782],t?(e.R=t.R.slice(0),e.U=t.U.slice(0),e.M=t.M):e.reset()}reset(){const t=this;return t.R=t.I.slice(0),t.U=[],t.M=0,t}update(t){const e=this;"string"==typeof t&&(t=K._.A(t));const n=e.U=W.concat(e.U,t),s=e.M,o=e.M=s+W.m(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const i=new c(n);let a=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.B(i.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),e}D(){const t=this;let e=t.U;const n=t.R;e=W.concat(e,[W.S(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.M/4294967296)),e.push(0|t.M);e.length;)t.B(e.splice(0,16));return t.reset(),n}V(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}B(e){const n=this,r=n.R,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let i=r[0],c=r[1],a=r[2],f=r[3],l=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.W(5,i)+n.V(t,c,a,f)+l+o[t]+n.P[s.floor(t/20)]|0;l=f,f=a,a=n.W(30,c),c=i,i=e}r[0]=r[0]+i|0,r[1]=r[1]+c|0,r[2]=r[2]+a|0,r[3]=r[3]+f|0,r[4]=r[4]+l|0}},L={importKey:t=>new L.K(K.bytes.A(t)),L(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let i,c,a,f,u;const w=new ArrayBuffer(o),h=new l(w);let p=0;const d=W;for(e=K.bytes.A(e),u=1;(o||1)>p;u++){for(i=c=t.encrypt(d.concat(e,[u])),a=1;n>a;a++)for(c=t.encrypt(c),f=0;f<c.length;f++)i[f]^=c[f];for(a=0;(o||1)>p&&a<i.length;a++)h.setInt32(p,i[a]),p+=4}return w.slice(0,s/8)},K:class{constructor(t){const e=this,n=e.O=E,s=[[],[]];e.T=[new n,new n];const r=e.T[0].blockSize/32;t.length>r&&(t=(new n).update(t).D());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.T[0].update(s[0]),e.T[1].update(s[1]),e.j=new n(e.T[0])}reset(){const t=this;t.j=new t.O(t.T[0]),t.H=!1}update(t){this.H=!0,this.j.update(t)}digest(){const t=this,e=t.j.D(),n=new t.O(t.T[1]).update(e).D();return t.reset(),n}encrypt(t){if(this.H)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},O=typeof h!=S&&typeof h.getRandomValues==k,T="Invalid password",j="Invalid signature",H="zipjs-abort-check-password";function Z(t){if(O)return h.getRandomValues(t);throw new r("Crypto API not supported")}const F=16,N={name:"PBKDF2"},q=e.assign({hash:{name:"HMAC"}},N),G=e.assign({iterations:1e3,hash:{name:"SHA-1"}},N),J=["deriveBits"],Q=[8,12,16],X=[16,24,32],Y=10,$=[0,0,0,0],tt=typeof h!=S,et=tt&&h.subtle,nt=tt&&typeof et!=S,st=K.bytes,rt=class{constructor(t){const e=this;e.Z=[[[],[],[],[],[]],[[],[],[],[],[]]],e.Z[0][0][0]||e.F();const n=e.Z[0][4],s=e.Z[1],o=t.length;let i,c,a,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.P=[c=t.slice(0),a=[]],i=o;4*o+28>i;i++){let t=c[i-1];(i%o===0||8===o&&i%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],i%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),c[i]=c[i-o]^t}for(let t=0;i;t++,i--){const e=c[3&t?i:i-4];a[t]=4>=i||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.N(t,0)}decrypt(t){return this.N(t,1)}F(){const t=this.Z[0],e=this.Z[1],n=t[4],s=e[4],r=[],o=[];let i,c,a,f;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=i=0;!n[l];l^=c||1,i=o[i]||1){let o=i^i<<1^i<<2^i<<3^i<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,f=r[a=r[c=r[l]]];let u=16843009*f^65537*a^257*c^16843008*l,w=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=w=w<<24^w>>>8,e[n][o]=u=u<<24^u>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}N(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.P[e],s=n.length/4-2,o=[0,0,0,0],i=this.Z[e],c=i[0],a=i[1],f=i[2],l=i[3],u=i[4];let w,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],g=t[e?1:3]^n[3],v=4;for(let t=0;s>t;t++)w=c[d>>>24]^a[y>>16&255]^f[m>>8&255]^l[255&g]^n[v],h=c[y>>>24]^a[m>>16&255]^f[g>>8&255]^l[255&d]^n[v+1],p=c[m>>>24]^a[g>>16&255]^f[d>>8&255]^l[255&y]^n[v+2],g=c[g>>>24]^a[d>>16&255]^f[y>>8&255]^l[255&m]^n[v+3],v+=4,d=w,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=u[d>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&g]^n[v++],w=d,d=y,y=m,m=g,g=w;return o}},ot=class{constructor(t,e){this.G=t,this.J=e,this.X=e}reset(){this.X=this.J}update(t){return this.Y(this.G,t,this.X)}$(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}et(t){0===(t[0]=this.$(t[0]))&&(t[1]=this.$(t[1]))}Y(t,e,n){let s;if(!(s=e.length))return[];const r=W.m(e);for(let r=0;s>r;r+=4){this.et(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return W.v(e,r)}},it=L.K;let ct=tt&&nt&&typeof et.importKey==k,at=tt&&nt&&typeof et.deriveBits==k;class ft extends d{constructor({password:t,rawPassword:e,encryptionStrength:n,checkPasswordOnly:s}){super({start(){ut(this,t,e,n)},async transform(t,e){const n=this,{password:i,strength:c,nt:a,ready:f}=n;i?(await(async(t,e,n,s)=>{const o=await ht(t,e,n,dt(s,0,Q[e])),i=dt(s,Q[e]);if(o[0]!=i[0]||o[1]!=i[1])throw new r(T)})(n,c,i,dt(t,0,Q[c]+2)),t=dt(t,Q[c]+2),s?e.error(new r(H)):a()):await f;const l=new o(t.length-Y-(t.length-Y)%F);e.enqueue(wt(n,t,l,0,Y,!0))},async flush(t){const{st:e,ot:n,pending:s,ready:o}=this;if(n&&e){await o;const i=dt(s,0,s.length-Y),c=dt(s,s.length-Y);let a=z;if(i.length){const t=mt(st,i);n.update(t);const s=e.update(t);a=yt(st,s)}const f=dt(yt(st,n.digest()),0,Y);let l=s.length<Y?1:0;for(let t=0;Y>t;t++)l|=f[t]^c[t];if(l)throw new r(j);t.enqueue(a)}}})}}class lt extends d{constructor({password:t,rawPassword:e,encryptionStrength:n}){let s;super({start(){ut(this,t,e,n)},async transform(t,e){const n=this,{password:s,strength:r,nt:i,ready:c}=n;let a=z;s?(a=await(async(t,e,n)=>{const s=Z(new o(Q[e]));return V(s,await ht(t,e,n,s))})(n,r,s),i()):await c;const f=new o(a.length+t.length-t.length%F);f.set(a,0),e.enqueue(wt(n,t,f,a.length,0))},async flush(t){const{st:e,ot:n,pending:r,ready:o}=this;if(n&&e){await o;let i=z;if(r.length){const t=e.update(mt(st,r));n.update(t),i=yt(st,t)}s.signature=yt(st,n.digest()).slice(0,Y),t.enqueue(V(i,s.signature))}}}),s=this}}function ut(t,n,s,r){e.assign(t,{ready:new u(e=>t.nt=e),password:pt(n,s),strength:r-1,pending:z})}function wt(t,e,n,s,r,i){const{st:c,ot:a,pending:f}=t;f.length&&(e=V(f,e));const l=e.length-r;let u;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(l-l%F)),u=0;l-F>=u;u+=F){const t=mt(st,dt(e,u,u+F));i&&a.update(t);const r=c.update(t);i||a.update(r),n.set(yt(st,r),u+s)}return t.pending=dt(e,u),n}async function ht(n,s,r,i){n.password=null;const c=await(async(t,e,n,s,r)=>{if(!ct)return L.importKey(e);try{return await et.importKey("raw",e,n,!1,r)}catch{return ct=!1,L.importKey(e)}})(0,r,q,0,J),a=await(async(t,e,n)=>{if(!at)return L.L(e,t.salt,G.iterations,n);try{return await et.deriveBits(t,e,n)}catch{return at=!1,L.L(e,t.salt,G.iterations,n)}})(e.assign({salt:i},G),c,8*(2*X[s]+2)),f=new o(a),l=mt(st,dt(f,0,X[s])),u=mt(st,dt(f,X[s],2*X[s])),w=dt(f,2*X[s]);return e.assign(n,{keys:{key:l,it:u,passwordVerification:w},st:new ot(new rt(l),t.from($)),ot:new it(u)}),w}function pt(t,e){return e===b?(t=>{if(typeof w==S){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new w).encode(t)})(t):e}function dt(t,e,n){return t.subarray(e,n)}function yt(t,e){return t.C(e)}function mt(t,e){return t.A(e)}class gt extends d{constructor({password:t,rawPassword:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){bt(this,t,e,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=St(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e.at(-1)^n.passwordVerification))throw new r(T);t=t.subarray(12)}s?e.error(new r(H)):e.enqueue(St(n,t))}})}}class vt extends d{constructor({password:t,rawPassword:e,passwordVerification:n}){super({start(){bt(this,t,e,n)},transform(t,e){const n=this;let s,r;if(n.password||n.rawPassword){n.password=n.rawPassword=null;const e=Z(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(kt(n,e),0),r=12}else s=new o(t.length),r=0;s.set(kt(n,t),r),e.enqueue(s)}})}}function bt(t,n,s,r){e.assign(t,{password:n,rawPassword:s,passwordVerification:r}),((t,n,s)=>{const r=[305419896,591751049,878082192];if(e.assign(t,{keys:r,ct:new B(r[0]),ft:new B(r[2])}),s)for(let e=0;e<s.length;e++)zt(t,s[e]);else for(let e=0;e<n.length;e++)zt(t,n.charCodeAt(e))})(t,n,s)}function St(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,n[s]);return n}function kt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,e[s]);return n}function zt(t,e){let[,n]=t.keys;t.ct.append([e]);const r=~t.ct.get();n=It(s.imul(It(n+At(r)),134775813)+1),t.ft.append([n>>>24]);const o=~t.ft.get();t.keys=[r,n,o]}function Ct(t){const e=2|t.keys[2];return At(s.imul(e,1^e)>>>8)}function At(t){return 255&t}function It(t){return 4294967295&t}class xt extends d{constructor(t,{chunkSize:e,CompressionStreamZlib:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:i,zipCrypto:c,signed:a,level:f,deflate64:u}=t,w=this;let h,p,d,y=super.readable;const m=a&&r&&!u&&(!o||c)&&!(!i||!s);o&&!c||!a||m||(h=new D,y=_t(y,h)),r&&(m?(d=new Pt,y=Bt(y,new s("gzip")),y=_t(y,d)):y=Mt(y,i,{level:f,chunkSize:e},s,n,s)),o&&(c?y=_t(y,new vt(t)):(p=new lt(t),y=_t(y,p))),Ut(w,y,()=>{let t;o&&!c&&(t=p.signature),o&&!c||!a||(t=m?d.signature:new l(h.value.buffer).getUint32(0)),w.signature=t})}}class Pt extends d{constructor(){let t,e=10,n=new o(0);super({transform(t,r){if(e){const n=s.min(e,t.length);if(e-=n,!(t=t.subarray(n)).length)return}const o=n.length+t.length;if(8>=o)return void(n=V(n,t));const i=o-8,c=s.min(i,n.length);r.enqueue(V(n.subarray(0,c),t.subarray(0,i-c))),n=V(n.subarray(c),t.subarray(i-c))},flush(){const e=new l((s=n).buffer,s.byteOffset,s.byteLength);var s;t.signature=e.getUint32(0,!0),t.uncompressedSize=e.getUint32(4,!0)}}),t=this}}class Rt extends d{constructor(t,{chunkSize:e,DecompressionStreamZlib:n,DecompressionStream:s}){super({});const{zipCrypto:o,encrypted:i,signed:c,signature:a,compressed:f,useCompressionStream:u,deflate64:w}=t;let h,p,d=super.readable;i&&(o?d=_t(d,new gt(t)):(p=new ft(t),d=_t(d,p))),f&&(d=Mt(d,u,{chunkSize:e,deflate64:w},s,n,s),d=(t=>{const e=t.getReader();return new y({async pull(t){let n;try{n=await e.read()}catch(t){if(t&&t.message)throw t;const e=new r("Invalid compressed data");throw e.cause=t,e}const{value:s,done:o}=n;o?t.close():t.enqueue(s)},cancel:t=>e.cancel(t)})})(d)),i&&!o||!c||(h=new D,d=_t(d,h)),Ut(this,d,()=>{if((!i||o)&&c){const t=new l(h.value.buffer);if(a!=t.getUint32(0,!1))throw new r(j)}})}}function Ut(t,n,s){n=_t(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Mt(t,e,n,s,r,o){const i=e&&s?s:r||o,c=n.deflate64?"deflate64-raw":"deflate-raw";let a;try{a=new i(c,n)}catch(t){if(!e)throw t;if(r)a=new r(c,n);else{if(!o)throw t;a=new o(c,n)}}return Bt(t,a)}function _t(t,e){return t.pipeThrough(e)}function Bt(t,e){const n=e.writable.getWriter(),s=t.getReader();return(async()=>{try{for(;;){await n.ready;const t=await s.read();if(t.done){await n.close();break}await n.write(t.value)}}catch(t){await(async(t,e)=>{try{await t.abort(e)}catch{}})(n,t),await(async(t,e)=>{try{await t.cancel(e)}catch{}})(s,t)}})(),e.readable}const Dt="data",Vt="close";class Wt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let i;o.startsWith("deflate")?i=xt:o.startsWith("inflate")&&(i=Rt),s.outputSize=0;let c=0;const a=new i(t,n),f=super.readable,l=new d({transform(t,e){t&&t.length&&(c+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:c})}}),u=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize!==b&&s.outputSize>t.outputSize))throw new r("Invalid uncompressed size")},flush(){const{signature:t}=a;e.assign(s,{signature:t,inputSize:c})}});e.defineProperty(s,"readable",{get:()=>f.pipeThrough(l).pipeThrough(a).pipeThrough(u)})}}class Kt extends d{constructor(t){const e=[];let n=0;function s(){const s=new o(t);let r=0;for(;t>r;){const n=e[0],o=t-r;n.length>o?(s.set(n.subarray(0,o),r),e[0]=n.subarray(o),r+=o):(s.set(n,r),r+=n.length,e.shift())}return n-=t,s}1>t&&(t=65536),super({transform(r,o){for(e.push(r),n+=r.length;n>t;)o.enqueue(s())},flush(t){n&&t.enqueue(((t,e)=>{const n=new o(e);let s=0;for(const e of t)n.set(e,s),s+=e.length;return n})(e,n))}})}}let Et=2;try{typeof navigator!=S&&navigator.hardwareConcurrency&&(Et=navigator.hardwareConcurrency)}catch{}const Lt=new f,Ot=new f;let Tt,jt,Ht,Zt,Ft,Nt=0;async function qt(t){let e,r;try{const{options:o,config:i}=t;if(!o.useCompressionStream)try{await self.initModule(t.config)}catch{o.useCompressionStream=!0}i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream;const c={highWaterMark:1},a=t.readable||new y({async pull(t){const e=new u(t=>Lt.set(Nt,t));Gt({type:"pull",messageId:Nt}),Nt=(Nt+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},c);r=t.writable||new m({async write(t){let e;const s=new u(t=>e=t);Ot.set(Nt,e),Gt({type:Dt,value:t,messageId:Nt}),Nt=(Nt+1)%n.MAX_SAFE_INTEGER,await s}},c),e=new Wt(o,i),Tt=new AbortController;const{signal:f}=Tt;await a.pipeThrough(e).pipeThrough(new Kt((t=>s.max(t.chunkSize,64))(i))).pipeTo(r,{signal:f,preventClose:!0,preventAbort:!0}),await r.getWriter().close();const{signature:l,inputSize:w,outputSize:h}=e;Gt({type:Vt,result:{signature:l,inputSize:w,outputSize:h}})}catch(t){if(t.outputSize=e?e.outputSize:0,r&&!r.locked)try{await r.getWriter().close()}catch{}Jt(t)}}function Gt(t){let{value:e}=t;if(e)if(e.length)try{t.value=(n=e,n.byteOffset||n.byteLength!=n.buffer.byteLength?new o(n):n).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var n}function Jt(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:i}=t;p({error:{message:e,stack:n,code:s,name:o,outputSize:i}})}function Qt(t,e,n={}){const i="number"==typeof n.level?n.level:-1,c="number"==typeof n.outBuffer?n.outBuffer:65536,a="number"==typeof n.inBufferSize?n.inBufferSize:65536;return new d({start(){try{let n;if(this.lt=Ht(c),this.in=Ht(a),this.inBufferSize=a,!this.lt||!this.in)throw new r("allocation failed");if(this.ut=new o(c),t?(this.wt=jt.deflate_process,this.ht=jt.deflate_last_consumed,this.yt=jt.deflate_end,this.gt=jt.deflate_new(),n="gzip"===e?jt.deflate_init_gzip(this.gt,i):"deflate-raw"===e?jt.deflate_init_raw(this.gt,i):jt.deflate_init(this.gt,i)):"deflate64-raw"===e?(this.wt=jt.inflate9_process,this.ht=jt.inflate9_last_consumed,this.yt=jt.inflate9_end,this.gt=jt.inflate9_new(),n=jt.inflate9_init_raw(this.gt)):(this.wt=jt.inflate_process,this.ht=jt.inflate_last_consumed,this.yt=jt.inflate_end,this.gt=jt.inflate_new(),n="deflate-raw"===e?jt.inflate_init_raw(this.gt):"gzip"===e?jt.inflate_init_gzip(this.gt):jt.inflate_init(this.gt)),0!==n)throw new r("init failed:"+n)}catch(t){throw f(this),t}},transform(e,n){try{const i=e,a=new o(Ft.buffer),f=this.wt,l=this.ht,u=this.lt,w=this.ut;let h=0;for(;h<i.length;){const e=s.min(i.length-h,32768);if((!this.in||this.inBufferSize<e)&&(this.in&&Zt&&(Zt(this.in),this.in=0),this.in=Ht(e),this.inBufferSize=e,!this.in))throw new r("allocation failed");a.set(i.subarray(h,h+e),this.in);const o=f(this.gt,this.in,e,u,c,0),p=16777215&o;if(p&&(w.set(a.subarray(u,u+p),0),n.enqueue(w.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=l(this.gt);if(0===d)break;h+=d}}catch(t){f(this),n.error(t)}},flush(e){try{const n=new o(Ft.buffer),s=this.wt,i=this.lt,a=this.ut;for(;;){const o=s(this.gt,0,0,i,c,4),f=16777215&o,l=o>>24&255;if(!t){const t=128&l?l-256:l;if(0>t)throw new r("process error:"+t)}if(f&&(a.set(n.subarray(i,i+f),0),e.enqueue(a.slice(0,f))),1===l||0===f)break}}catch(t){e.error(t)}finally{const t=f(this);0!==t&&e.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let e=0;return t.gt&&t.yt&&(e=t.yt(t.gt)),t.gt=0,t.in&&Zt&&Zt(t.in),t.in=0,t.lt&&Zt&&Zt(t.lt),t.lt=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&qt(t),e==Dt){const t=Lt.get(n);Lt.delete(n),t({value:s||new o,done:r})}if("ack"==e){const t=Ot.get(n);Ot.delete(n),t()}e==Vt&&Tt.abort()}catch(t){Jt(t)}});class Xt{constructor(t="deflate",e){return Qt(!0,t,e)}}class Yt{constructor(t="deflate",e){return Qt(!1,t,e)}}Xt.vt=!0,Yt.vt=!0;let $t=!1;self.initModule=async t=>{try{const e=await(async(t,{baseURI:e})=>{if(!$t){let n,s;try{try{s=new URL(t,e)}catch{}const r=await fetch(s);n=await r.arrayBuffer()}catch(e){if(!t.startsWith("data:application/wasm;base64,"))throw e;n=(t=>{const e=t.split(",")[1],n=atob(e),s=n.length,r=new o(s);for(let t=0;s>t;++t)r[t]=n.charCodeAt(t);return r.buffer})(t)}(t=>{if(jt=t,({malloc:Ht,free:Zt,memory:Ft}=jt),"function"!=typeof Ht||"function"!=typeof Zt||!Ft)throw jt=Ht=Zt=Ft=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports),$t=!0}})(t.wasmURI,t);return t.CompressionStreamZlib=Xt,t.DecompressionStreamZlib=Yt,e}catch{}}});\n';t({workerURI:t=>{const n="text/javascript";if(t){const t=new Blob([e],{type:n});return URL.createObjectURL(t)}return "data:"+n+","+encodeURIComponent(e)}});}
217
+ function t$1(t){const e='(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:i,Uint32Array:c,Int32Array:a,Map:f,DataView:l,Promise:u,TextEncoder:w,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:g,DecompressionStream:v}=self,b=void 0,S="undefined",k="function",z=new o,C=[[],[],[],[],[],[],[],[]];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)e=1&e?e>>>1^3988292384:e>>>1;C[0][t]=e}for(let t=0;256>t;t++)for(let e=1;8>e;e++){const n=C[e-1][t];C[e][t]=n>>>8^C[0][255&n]}const[A,I,x,P,R,U,M,_]=C;class B{constructor(t){this.o=t||-1}append(t){let e=0|this.o;const n=0|t.length;let s=0;if(n>=8&&t.buffer){const r=new l(t.buffer,t.byteOffset,n),o=n-8;for(;o>=s;s+=8){const t=e^r.getInt32(s,!0),n=r.getInt32(s+4,!0);e=_[255&t]^M[t>>>8&255]^U[t>>>16&255]^R[t>>>24&255]^P[255&n]^x[n>>>8&255]^I[n>>>16&255]^A[n>>>24&255]}}for(;n>s;s++)e=e>>>8^A[255&(e^t[s])];this.o=e}get(){return~this.o}}class D extends d{constructor(){let t;const e=new B;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new l(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}function V(t,e){const n=new o(t.length+e.length);return n.set(t),n.set(e,t.length),n}const W={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=W.l(n);return 32===s?t.concat(e):W.h(e,s,0|n,t.slice(0,t.length-1))},m(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+W.l(n)},v(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=W.S(e,t[n-1]&2147483648>>e-1,1)),t},S:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,l:t=>s.round(t/1099511627776)||32,h(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=W.l(r);return s.push(W.S(e+o&31,e+o>32?n:s.pop(),1)),s}},K={bytes:{C(t){const e=W.m(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},A(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(W.S(8*(3&n),s)),e}}},E=class{constructor(t){const e=this;e.blockSize=512,e.I=[1732584193,4023233417,2562383102,271733878,3285377520],e.P=[1518500249,1859775393,2400959708,3395469782],t?(e.R=t.R.slice(0),e.U=t.U.slice(0),e.M=t.M):e.reset()}reset(){const t=this;return t.R=t.I.slice(0),t.U=[],t.M=0,t}update(t){const e=this;"string"==typeof t&&(t=K._.A(t));const n=e.U=W.concat(e.U,t),s=e.M,o=e.M=s+W.m(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const i=new c(n);let a=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.B(i.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),e}D(){const t=this;let e=t.U;const n=t.R;e=W.concat(e,[W.S(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.M/4294967296)),e.push(0|t.M);e.length;)t.B(e.splice(0,16));return t.reset(),n}V(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}B(e){const n=this,r=n.R,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let i=r[0],c=r[1],a=r[2],f=r[3],l=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.W(5,i)+n.V(t,c,a,f)+l+o[t]+n.P[s.floor(t/20)]|0;l=f,f=a,a=n.W(30,c),c=i,i=e}r[0]=r[0]+i|0,r[1]=r[1]+c|0,r[2]=r[2]+a|0,r[3]=r[3]+f|0,r[4]=r[4]+l|0}},L={importKey:t=>new L.K(K.bytes.A(t)),L(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let i,c,a,f,u;const w=new ArrayBuffer(o),h=new l(w);let p=0;const d=W;for(e=K.bytes.A(e),u=1;(o||1)>p;u++){for(i=c=t.encrypt(d.concat(e,[u])),a=1;n>a;a++)for(c=t.encrypt(c),f=0;f<c.length;f++)i[f]^=c[f];for(a=0;(o||1)>p&&a<i.length;a++)h.setInt32(p,i[a]),p+=4}return w.slice(0,s/8)},K:class{constructor(t){const e=this,n=e.O=E,s=[[],[]];e.T=[new n,new n];const r=e.T[0].blockSize/32;t.length>r&&(t=(new n).update(t).D());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.T[0].update(s[0]),e.T[1].update(s[1]),e.j=new n(e.T[0])}reset(){const t=this;t.j=new t.O(t.T[0]),t.H=!1}update(t){this.H=!0,this.j.update(t)}digest(){const t=this,e=t.j.D(),n=new t.O(t.T[1]).update(e).D();return t.reset(),n}encrypt(t){if(this.H)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},O=typeof h!=S&&typeof h.getRandomValues==k,T="Invalid password",j="Invalid signature",H="zipjs-abort-check-password";function Z(t){if(O)return h.getRandomValues(t);throw new r("Crypto API not supported")}const F=16,N={name:"PBKDF2"},q=e.assign({hash:{name:"HMAC"}},N),G=e.assign({iterations:1e3,hash:{name:"SHA-1"}},N),J=["deriveBits"],Q=[8,12,16],X=[16,24,32],Y=10,$=[0,0,0,0],tt=typeof h!=S,et=tt&&h.subtle,nt=tt&&typeof et!=S,st=K.bytes,rt=class{constructor(t){const e=this;e.Z=[[[],[],[],[],[]],[[],[],[],[],[]]],e.Z[0][0][0]||e.F();const n=e.Z[0][4],s=e.Z[1],o=t.length;let i,c,a,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.P=[c=t.slice(0),a=[]],i=o;4*o+28>i;i++){let t=c[i-1];(i%o===0||8===o&&i%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],i%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),c[i]=c[i-o]^t}for(let t=0;i;t++,i--){const e=c[3&t?i:i-4];a[t]=4>=i||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.N(t,0)}decrypt(t){return this.N(t,1)}F(){const t=this.Z[0],e=this.Z[1],n=t[4],s=e[4],r=[],o=[];let i,c,a,f;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=i=0;!n[l];l^=c||1,i=o[i]||1){let o=i^i<<1^i<<2^i<<3^i<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,f=r[a=r[c=r[l]]];let u=16843009*f^65537*a^257*c^16843008*l,w=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=w=w<<24^w>>>8,e[n][o]=u=u<<24^u>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}N(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.P[e],s=n.length/4-2,o=[0,0,0,0],i=this.Z[e],c=i[0],a=i[1],f=i[2],l=i[3],u=i[4];let w,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],g=t[e?1:3]^n[3],v=4;for(let t=0;s>t;t++)w=c[d>>>24]^a[y>>16&255]^f[m>>8&255]^l[255&g]^n[v],h=c[y>>>24]^a[m>>16&255]^f[g>>8&255]^l[255&d]^n[v+1],p=c[m>>>24]^a[g>>16&255]^f[d>>8&255]^l[255&y]^n[v+2],g=c[g>>>24]^a[d>>16&255]^f[y>>8&255]^l[255&m]^n[v+3],v+=4,d=w,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=u[d>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&g]^n[v++],w=d,d=y,y=m,m=g,g=w;return o}},ot=class{constructor(t,e){this.G=t,this.J=e,this.X=e}reset(){this.X=this.J}update(t){return this.Y(this.G,t,this.X)}$(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}et(t){0===(t[0]=this.$(t[0]))&&(t[1]=this.$(t[1]))}Y(t,e,n){let s;if(!(s=e.length))return[];const r=W.m(e);for(let r=0;s>r;r+=4){this.et(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return W.v(e,r)}},it=L.K;let ct=tt&&nt&&typeof et.importKey==k,at=tt&&nt&&typeof et.deriveBits==k;class ft extends d{constructor({password:t,rawPassword:e,encryptionStrength:n,checkPasswordOnly:s}){super({start(){ut(this,t,e,n)},async transform(t,e){const n=this,{password:i,strength:c,nt:a,ready:f}=n;i?(await(async(t,e,n,s)=>{const o=await ht(t,e,n,dt(s,0,Q[e])),i=dt(s,Q[e]);if(o[0]!=i[0]||o[1]!=i[1])throw new r(T)})(n,c,i,dt(t,0,Q[c]+2)),t=dt(t,Q[c]+2),s?e.error(new r(H)):a()):await f;const l=new o(t.length-Y-(t.length-Y)%F);e.enqueue(wt(n,t,l,0,Y,!0))},async flush(t){const{st:e,ot:n,pending:s,ready:o}=this;if(n&&e){await o;const i=dt(s,0,s.length-Y),c=dt(s,s.length-Y);let a=z;if(i.length){const t=mt(st,i);n.update(t);const s=e.update(t);a=yt(st,s)}const f=dt(yt(st,n.digest()),0,Y);let l=s.length<Y?1:0;for(let t=0;Y>t;t++)l|=f[t]^c[t];if(l)throw new r(j);t.enqueue(a)}}})}}class lt extends d{constructor({password:t,rawPassword:e,encryptionStrength:n}){let s;super({start(){ut(this,t,e,n)},async transform(t,e){const n=this,{password:s,strength:r,nt:i,ready:c}=n;let a=z;s?(a=await(async(t,e,n)=>{const s=Z(new o(Q[e]));return V(s,await ht(t,e,n,s))})(n,r,s),i()):await c;const f=new o(a.length+t.length-t.length%F);f.set(a,0),e.enqueue(wt(n,t,f,a.length,0))},async flush(t){const{st:e,ot:n,pending:r,ready:o}=this;if(n&&e){await o;let i=z;if(r.length){const t=e.update(mt(st,r));n.update(t),i=yt(st,t)}s.signature=yt(st,n.digest()).slice(0,Y),t.enqueue(V(i,s.signature))}}}),s=this}}function ut(t,n,s,r){e.assign(t,{ready:new u(e=>t.nt=e),password:pt(n,s),strength:r-1,pending:z})}function wt(t,e,n,s,r,i){const{st:c,ot:a,pending:f}=t;f.length&&(e=V(f,e));const l=e.length-r;let u;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(l-l%F)),u=0;l-F>=u;u+=F){const t=mt(st,dt(e,u,u+F));i&&a.update(t);const r=c.update(t);i||a.update(r),n.set(yt(st,r),u+s)}return t.pending=dt(e,u),n}async function ht(n,s,r,i){n.password=null;const c=await(async(t,e,n,s,r)=>{if(!ct)return L.importKey(e);try{return await et.importKey("raw",e,n,!1,r)}catch{return ct=!1,L.importKey(e)}})(0,r,q,0,J),a=await(async(t,e,n)=>{if(!at)return L.L(e,t.salt,G.iterations,n);try{return await et.deriveBits(t,e,n)}catch{return at=!1,L.L(e,t.salt,G.iterations,n)}})(e.assign({salt:i},G),c,8*(2*X[s]+2)),f=new o(a),l=mt(st,dt(f,0,X[s])),u=mt(st,dt(f,X[s],2*X[s])),w=dt(f,2*X[s]);return e.assign(n,{keys:{key:l,it:u,passwordVerification:w},st:new ot(new rt(l),t.from($)),ot:new it(u)}),w}function pt(t,e){return e===b?(t=>{if(typeof w==S){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new w).encode(t)})(t):e}function dt(t,e,n){return t.subarray(e,n)}function yt(t,e){return t.C(e)}function mt(t,e){return t.A(e)}class gt extends d{constructor({password:t,rawPassword:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){bt(this,t,e,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=St(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e.at(-1)^n.passwordVerification))throw new r(T);t=t.subarray(12)}s?e.error(new r(H)):e.enqueue(St(n,t))}})}}class vt extends d{constructor({password:t,rawPassword:e,passwordVerification:n}){super({start(){bt(this,t,e,n)},transform(t,e){const n=this;let s,r;if(n.password||n.rawPassword){n.password=n.rawPassword=null;const e=Z(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(kt(n,e),0),r=12}else s=new o(t.length),r=0;s.set(kt(n,t),r),e.enqueue(s)}})}}function bt(t,n,s,r){e.assign(t,{password:n,rawPassword:s,passwordVerification:r}),((t,n,s)=>{const r=[305419896,591751049,878082192];if(e.assign(t,{keys:r,ct:new B(r[0]),ft:new B(r[2])}),s)for(let e=0;e<s.length;e++)zt(t,s[e]);else for(let e=0;e<n.length;e++)zt(t,n.charCodeAt(e))})(t,n,s)}function St(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,n[s]);return n}function kt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,e[s]);return n}function zt(t,e){let[,n]=t.keys;t.ct.append([e]);const r=~t.ct.get();n=It(s.imul(It(n+At(r)),134775813)+1),t.ft.append([n>>>24]);const o=~t.ft.get();t.keys=[r,n,o]}function Ct(t){const e=2|t.keys[2];return At(s.imul(e,1^e)>>>8)}function At(t){return 255&t}function It(t){return 4294967295&t}class xt extends d{constructor(t,{chunkSize:e,CompressionStreamZlib:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:i,zipCrypto:c,signed:a,level:f,deflate64:u}=t,w=this;let h,p,d,y=super.readable;const m=a&&r&&!u&&(!o||c)&&!(!i||!s);o&&!c||!a||m||(h=new D,y=_t(y,h)),r&&(m?(d=new Pt,y=Bt(y,new s("gzip")),y=_t(y,d)):y=Mt(y,i,{level:f,chunkSize:e},s,n,s)),o&&(c?y=_t(y,new vt(t)):(p=new lt(t),y=_t(y,p))),Ut(w,y,()=>{let t;o&&!c&&(t=p.signature),o&&!c||!a||(t=m?d.signature:new l(h.value.buffer).getUint32(0)),w.signature=t})}}class Pt extends d{constructor(){let t,e=10,n=new o(0);super({transform(t,r){if(e){const n=s.min(e,t.length);if(e-=n,!(t=t.subarray(n)).length)return}const o=n.length+t.length;if(8>=o)return void(n=V(n,t));const i=o-8,c=s.min(i,n.length);r.enqueue(V(n.subarray(0,c),t.subarray(0,i-c))),n=V(n.subarray(c),t.subarray(i-c))},flush(){const e=new l((s=n).buffer,s.byteOffset,s.byteLength);var s;t.signature=e.getUint32(0,!0),t.uncompressedSize=e.getUint32(4,!0)}}),t=this}}class Rt extends d{constructor(t,{chunkSize:e,DecompressionStreamZlib:n,DecompressionStream:s}){super({});const{zipCrypto:o,encrypted:i,signed:c,signature:a,compressed:f,useCompressionStream:u,deflate64:w}=t;let h,p,d=super.readable;i&&(o?d=_t(d,new gt(t)):(p=new ft(t),d=_t(d,p))),f&&(d=Mt(d,u,{chunkSize:e,deflate64:w},s,n,s),d=(t=>{const e=t.getReader();return new y({async pull(t){let n;try{n=await e.read()}catch(t){if(t&&t.message)throw t;const e=new r("Invalid compressed data");throw e.cause=t,e}const{value:s,done:o}=n;o?t.close():t.enqueue(s)},cancel:t=>e.cancel(t)})})(d)),i&&!o||!c||(h=new D,d=_t(d,h)),Ut(this,d,()=>{if((!i||o)&&c){const t=new l(h.value.buffer);if(a!=t.getUint32(0,!1))throw new r(j)}})}}function Ut(t,n,s){n=_t(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Mt(t,e,n,s,r,o){const i=e&&s?s:r||o,c=n.deflate64?"deflate64-raw":"deflate-raw";let a;try{a=new i(c,n)}catch(t){if(!e)throw t;if(r)a=new r(c,n);else{if(!o)throw t;a=new o(c,n)}}return Bt(t,a)}function _t(t,e){return t.pipeThrough(e)}function Bt(t,e){const n=e.writable.getWriter(),s=t.getReader();return(async()=>{try{for(;;){await n.ready;const t=await s.read();if(t.done){await n.close();break}await n.write(t.value)}}catch(t){await(async(t,e)=>{try{await t.abort(e)}catch{}})(n,t),await(async(t,e)=>{try{await t.cancel(e)}catch{}})(s,t)}})(),e.readable}const Dt="data",Vt="close";class Wt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let i;o.startsWith("deflate")?i=xt:o.startsWith("inflate")&&(i=Rt),s.outputSize=0;let c=0;const a=new i(t,n),f=super.readable,l=new d({transform(t,e){t&&t.length&&(c+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:c})}}),u=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize!==b&&s.outputSize>t.outputSize))throw new r("Invalid uncompressed size")},flush(){const{signature:t}=a;e.assign(s,{signature:t,inputSize:c})}});e.defineProperty(s,"readable",{get:()=>f.pipeThrough(l).pipeThrough(a).pipeThrough(u)})}}class Kt extends d{constructor(t){const e=[];let s=0;function r(){const n=new o(t);let r=0;for(;t>r;){const s=e[0],o=t-r;s.length>o?(n.set(s.subarray(0,o),r),e[0]=s.subarray(o),r+=o):(n.set(s,r),r+=s.length,e.shift())}return s-=t,n}n.isFinite(t)&&t>=1||(t=65536),super({transform(n,o){for(e.push(n),s+=n.length;s>t;)o.enqueue(r())},flush(t){s&&t.enqueue(((t,e)=>{const n=new o(e);let s=0;for(const e of t)n.set(e,s),s+=e.length;return n})(e,s))}})}}let Et=2;try{typeof navigator!=S&&navigator.hardwareConcurrency&&(Et=navigator.hardwareConcurrency)}catch{}const Lt=new f,Ot=new f;let Tt,jt,Ht,Zt,Ft,Nt=0;async function qt(t){let e,r;try{const{options:o,config:i}=t;if(!o.useCompressionStream)try{await self.initModule(t.config)}catch{o.useCompressionStream=!0}i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream;const c={highWaterMark:1},a=t.readable||new y({async pull(t){const e=new u(t=>Lt.set(Nt,t));Gt({type:"pull",messageId:Nt}),Nt=(Nt+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},c);r=t.writable||new m({async write(t){let e;const s=new u(t=>e=t);Ot.set(Nt,e),Gt({type:Dt,value:t,messageId:Nt}),Nt=(Nt+1)%n.MAX_SAFE_INTEGER,await s}},c),e=new Wt(o,i),Tt=new AbortController;const{signal:f}=Tt;await a.pipeThrough(e).pipeThrough(new Kt((t=>s.max(t.chunkSize,64))(i))).pipeTo(r,{signal:f,preventClose:!0,preventAbort:!0}),await r.getWriter().close();const{signature:l,inputSize:w,outputSize:h}=e;Gt({type:Vt,result:{signature:l,inputSize:w,outputSize:h}})}catch(t){if(t.outputSize=e?e.outputSize:0,r&&!r.locked)try{await r.getWriter().close()}catch{}Jt(t)}}function Gt(t){let{value:e}=t;if(e)if(e.length)try{t.value=(n=e,n.byteOffset||n.byteLength!=n.buffer.byteLength?new o(n):n).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var n}function Jt(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:i}=t;p({error:{message:e,stack:n,code:s,name:o,outputSize:i}})}function Qt(t,e,n={}){const i="number"==typeof n.level?n.level:-1,c="number"==typeof n.outBuffer?n.outBuffer:65536,a="number"==typeof n.inBufferSize?n.inBufferSize:65536;return new d({start(){try{let n;if(this.lt=Ht(c),this.in=Ht(a),this.inBufferSize=a,!this.lt||!this.in)throw new r("allocation failed");if(this.ut=new o(c),t?(this.wt=jt.deflate_process,this.ht=jt.deflate_last_consumed,this.yt=jt.deflate_end,this.gt=jt.deflate_new(),n="gzip"===e?jt.deflate_init_gzip(this.gt,i):"deflate-raw"===e?jt.deflate_init_raw(this.gt,i):jt.deflate_init(this.gt,i)):"deflate64-raw"===e?(this.wt=jt.inflate9_process,this.ht=jt.inflate9_last_consumed,this.yt=jt.inflate9_end,this.gt=jt.inflate9_new(),n=jt.inflate9_init_raw(this.gt)):(this.wt=jt.inflate_process,this.ht=jt.inflate_last_consumed,this.yt=jt.inflate_end,this.gt=jt.inflate_new(),n="deflate-raw"===e?jt.inflate_init_raw(this.gt):"gzip"===e?jt.inflate_init_gzip(this.gt):jt.inflate_init(this.gt)),0!==n)throw new r("init failed:"+n)}catch(t){throw f(this),t}},transform(e,n){try{const i=e,a=new o(Ft.buffer),f=this.wt,l=this.ht,u=this.lt,w=this.ut;let h=0;for(;h<i.length;){const e=s.min(i.length-h,32768);if((!this.in||this.inBufferSize<e)&&(this.in&&Zt&&(Zt(this.in),this.in=0),this.in=Ht(e),this.inBufferSize=e,!this.in))throw new r("allocation failed");a.set(i.subarray(h,h+e),this.in);const o=f(this.gt,this.in,e,u,c,0),p=16777215&o;if(p&&(w.set(a.subarray(u,u+p),0),n.enqueue(w.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=l(this.gt);if(0===d)break;h+=d}}catch(t){f(this),n.error(t)}},flush(e){try{const n=new o(Ft.buffer),s=this.wt,i=this.lt,a=this.ut;for(;;){const o=s(this.gt,0,0,i,c,4),f=16777215&o,l=o>>24&255;if(!t){const t=128&l?l-256:l;if(0>t)throw new r("process error:"+t)}if(f&&(a.set(n.subarray(i,i+f),0),e.enqueue(a.slice(0,f))),1===l||0===f)break}}catch(t){e.error(t)}finally{const t=f(this);0!==t&&e.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let e=0;return t.gt&&t.yt&&(e=t.yt(t.gt)),t.gt=0,t.in&&Zt&&Zt(t.in),t.in=0,t.lt&&Zt&&Zt(t.lt),t.lt=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&qt(t),e==Dt){const t=Lt.get(n);Lt.delete(n),t({value:s||new o,done:r})}if("ack"==e){const t=Ot.get(n);Ot.delete(n),t()}e==Vt&&Tt.abort()}catch(t){Jt(t)}});class Xt{constructor(t="deflate",e){return Qt(!0,t,e)}}class Yt{constructor(t="deflate",e){return Qt(!1,t,e)}}Xt.vt=!0,Yt.vt=!0;let $t=!1;self.initModule=async t=>{try{const e=await(async(t,{baseURI:e})=>{if(!$t){let n,s;try{try{s=new URL(t,e)}catch{}const r=await fetch(s);n=await r.arrayBuffer()}catch(e){if(!t.startsWith("data:application/wasm;base64,"))throw e;n=(t=>{const e=t.split(",")[1],n=atob(e),s=n.length,r=new o(s);for(let t=0;s>t;++t)r[t]=n.charCodeAt(t);return r.buffer})(t)}(t=>{if(jt=t,({malloc:Ht,free:Zt,memory:Ft}=jt),"function"!=typeof Ht||"function"!=typeof Zt||!Ft)throw jt=Ht=Zt=Ft=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports),$t=!0}})(t.wasmURI,t);return t.CompressionStreamZlib=Xt,t.DecompressionStreamZlib=Yt,e}catch{}}});\n';t({workerURI:t=>{const n="text/javascript";if(t){const t=new Blob([e],{type:n});return URL.createObjectURL(t)}return "data:"+n+","+encodeURIComponent(e)}});}
218
218
 
219
219
  /*
220
220
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
@@ -2079,7 +2079,7 @@ class ChunkStream extends TransformStream {
2079
2079
  constructor(chunkSize) {
2080
2080
  const pendingChunks = [];
2081
2081
  let pendingLength = 0;
2082
- if (!(chunkSize >= 1)) {
2082
+ if (!Number.isFinite(chunkSize) || chunkSize < 1) {
2083
2083
  chunkSize = DEFAULT_CHUNK_SIZE;
2084
2084
  }
2085
2085
  super({
@@ -2788,6 +2788,7 @@ const HTTP_METHOD_HEAD = "HEAD";
2788
2788
  const HTTP_METHOD_GET = "GET";
2789
2789
  const HTTP_RANGE_UNIT = "bytes";
2790
2790
  const DEFAULT_BUFFER_SIZE = 256 * 1024;
2791
+ const DEFAULT_MAXIMUM_RANGE_SIZE = 16 * 1024 * 1024;
2791
2792
 
2792
2793
  const PROPERTY_NAME_WRITABLE = "writable";
2793
2794
  const DISK_BOUNDARY = Symbol();
@@ -3100,6 +3101,7 @@ function createHttpReader(httpReader, url, options) {
3100
3101
  forceRangeRequests,
3101
3102
  combineSizeEocd,
3102
3103
  checkResourceChanges = true,
3104
+ maximumRangeSize = DEFAULT_MAXIMUM_RANGE_SIZE,
3103
3105
  fetch
3104
3106
  } = options;
3105
3107
  options = Object.assign({}, options);
@@ -3108,6 +3110,7 @@ function createHttpReader(httpReader, url, options) {
3108
3110
  delete options.forceRangeRequests;
3109
3111
  delete options.combineSizeEocd;
3110
3112
  delete options.checkResourceChanges;
3113
+ delete options.maximumRangeSize;
3111
3114
  delete options.useXHR;
3112
3115
  delete options.fetch;
3113
3116
  Object.assign(httpReader, {
@@ -3118,6 +3121,7 @@ function createHttpReader(httpReader, url, options) {
3118
3121
  forceRangeRequests,
3119
3122
  combineSizeEocd,
3120
3123
  checkResourceChanges,
3124
+ maximumRangeSize,
3121
3125
  fetch
3122
3126
  });
3123
3127
  }
@@ -3203,40 +3207,31 @@ async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest,
3203
3207
 
3204
3208
  function createRangeReadable(httpReader, offset, size) {
3205
3209
  let bodyReader;
3210
+ let windowOffset = offset;
3211
+ let windowRemainingLength = 0;
3206
3212
  let remainingLength = size;
3207
3213
  return new ReadableStream({
3208
- async start() {
3209
- const response = await sendFetchRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, offset, size));
3210
- if (response.status != 206) {
3211
- throw new Error(ERR_HTTP_RANGE);
3212
- }
3213
- const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
3214
- if (contentRangeHeader) {
3215
- const rangeStart = Number(contentRangeHeader.trim().split(/[\s-]+/)[1]);
3216
- if (!Number.isNaN(rangeStart) && rangeStart != offset) {
3217
- throw new Error(ERR_HTTP_RANGE);
3218
- }
3219
- }
3220
- checkResourceValidators(httpReader, response);
3221
- setResourceValidators(httpReader, response);
3222
- bodyReader = response.body.getReader();
3214
+ start() {
3215
+ return openWindow();
3223
3216
  },
3224
3217
  async pull(controller) {
3218
+ if (!bodyReader) {
3219
+ await openWindow();
3220
+ }
3225
3221
  const { value, done } = await bodyReader.read();
3226
3222
  if (done) {
3227
- if (remainingLength) {
3228
- throw new Error(ERR_HTTP_RANGE);
3229
- }
3230
- controller.close();
3231
- } else {
3232
- const chunk = value.length > remainingLength ? value.subarray(0, remainingLength) : value;
3233
- remainingLength -= chunk.length;
3234
- if (chunk.length) {
3235
- controller.enqueue(chunk);
3236
- }
3223
+ throw new Error(ERR_HTTP_RANGE);
3224
+ }
3225
+ const chunk = value.length > windowRemainingLength ? value.subarray(0, windowRemainingLength) : value;
3226
+ windowRemainingLength -= chunk.length;
3227
+ remainingLength -= chunk.length;
3228
+ if (chunk.length) {
3229
+ controller.enqueue(chunk);
3230
+ }
3231
+ if (!windowRemainingLength) {
3232
+ await closeWindow();
3237
3233
  if (!remainingLength) {
3238
3234
  controller.close();
3239
- await bodyReader.cancel();
3240
3235
  }
3241
3236
  }
3242
3237
  },
@@ -3244,6 +3239,32 @@ function createRangeReadable(httpReader, offset, size) {
3244
3239
  return bodyReader && bodyReader.cancel(reason);
3245
3240
  }
3246
3241
  });
3242
+
3243
+ async function openWindow() {
3244
+ const windowLength = Math.min(httpReader.maximumRangeSize, remainingLength);
3245
+ const response = await sendFetchRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, windowOffset, windowLength));
3246
+ if (response.status != 206) {
3247
+ throw new Error(ERR_HTTP_RANGE);
3248
+ }
3249
+ const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
3250
+ if (contentRangeHeader) {
3251
+ const rangeStart = Number(contentRangeHeader.trim().split(/[\s-]+/)[1]);
3252
+ if (!Number.isNaN(rangeStart) && rangeStart != windowOffset) {
3253
+ throw new Error(ERR_HTTP_RANGE);
3254
+ }
3255
+ }
3256
+ checkResourceValidators(httpReader, response);
3257
+ setResourceValidators(httpReader, response);
3258
+ windowOffset += windowLength;
3259
+ windowRemainingLength = windowLength;
3260
+ bodyReader = response.body.getReader();
3261
+ }
3262
+
3263
+ async function closeWindow() {
3264
+ const currentBodyReader = bodyReader;
3265
+ bodyReader = UNDEFINED_VALUE;
3266
+ await currentBodyReader.cancel();
3267
+ }
3247
3268
  }
3248
3269
 
3249
3270
  function getContentRangeSize(response) {
package/index.d.cts CHANGED
@@ -662,6 +662,14 @@ export interface HttpRangeOptions {
662
662
  * @defaultValue true
663
663
  */
664
664
  checkResourceChanges?: boolean;
665
+ /**
666
+ * The maximum size in bytes of the range requests sent to read the data of an entry. The data is
667
+ * read with as many range requests as necessary, each response body being streamed, so that the
668
+ * size of a request never depends on the size of the entry.
669
+ *
670
+ * @defaultValue 16777216
671
+ */
672
+ maximumRangeSize?: number;
665
673
  }
666
674
 
667
675
  /**
package/index.d.ts CHANGED
@@ -662,6 +662,14 @@ export interface HttpRangeOptions {
662
662
  * @defaultValue true
663
663
  */
664
664
  checkResourceChanges?: boolean;
665
+ /**
666
+ * The maximum size in bytes of the range requests sent to read the data of an entry. The data is
667
+ * read with as many range requests as necessary, each response body being streamed, so that the
668
+ * size of a request never depends on the size of the entry.
669
+ *
670
+ * @defaultValue 16777216
671
+ */
672
+ maximumRangeSize?: number;
665
673
  }
666
674
 
667
675
  /**