@zip.js/zip.js 2.15.0 → 2.16.1

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.
Files changed (44) hide show
  1. package/BENCHMARKS.md +4 -2
  2. package/deno.json +1 -1
  3. package/dist/zip-core-external.js +410 -227
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +234 -109
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +552 -237
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +377 -118
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +552 -237
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +379 -120
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +554 -237
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +236 -111
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +236 -111
  20. package/dist/zip-native.min.js +1 -1
  21. package/dist/zip-web-worker-native.js +1 -1
  22. package/dist/zip-web-worker.js +1 -1
  23. package/dist/zip.js +411 -228
  24. package/dist/zip.min.js +1 -1
  25. package/eslint.config.mjs +1 -1
  26. package/index-native.cjs +379 -120
  27. package/index-native.min.js +1 -1
  28. package/index.cjs +554 -237
  29. package/index.d.cts +143 -16
  30. package/index.d.ts +143 -16
  31. package/index.min.js +1 -1
  32. package/lib/core/io.js +3 -2
  33. package/lib/core/streams/aes-crypto-stream.js +60 -17
  34. package/lib/core/streams/zip-crypto-stream.js +7 -7
  35. package/lib/core/streams/zip-entry-stream.js +146 -73
  36. package/lib/core/streams/zlib-wasm/zlib-streams.js +176 -118
  37. package/lib/core/util/compatible-streams.js +10 -5
  38. package/lib/core/version.js +1 -1
  39. package/lib/core/web-worker-inline-native.js +1 -1
  40. package/lib/core/web-worker-inline-wasm.js +1 -1
  41. package/lib/core/zip-fs.js +144 -10
  42. package/lib/core/zip-reader.js +5 -5
  43. package/lib/core/zip-writer.js +4 -2
  44. package/package.json +3 -2
package/dist/zip-fs.js CHANGED
@@ -223,7 +223,7 @@
223
223
  const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
224
224
  const ERR_INVALID_PASS_THROUGH_VALUE = "Invalid passThrough option (must be a boolean or 'compressed')";
225
225
  const ERR_ABORTED = "The operation was aborted";
226
- const ABORT_ERROR_NAME = "AbortError";
226
+ const ABORT_ERROR_NAME$1 = "AbortError";
227
227
 
228
228
  function checkFunctionOption(value) {
229
229
  if (value && typeof value != FUNCTION_TYPE) {
@@ -241,7 +241,7 @@
241
241
 
242
242
  function throwIfAborted(signal) {
243
243
  if (signal && signal.aborted) {
244
- throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
244
+ throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME$1) : signal.reason;
245
245
  }
246
246
  }
247
247
 
@@ -445,7 +445,7 @@
445
445
  Object.assign(config, DEFAULT_CONFIGURATION);
446
446
  }
447
447
 
448
- const t$1=new Uint8Array(288);t$1.fill(8,0,144),t$1.fill(9,144,256),t$1.fill(7,256,280),t$1.fill(8,280,288),new Uint8Array(30).fill(5);const n$1="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e$1=t=>t({workerURI:t=>{const e="text/javascript";let r='!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";const{Array:t,Object:n,Number:e,Math:o,Error:r,Uint8Array:s,Uint16Array:c,Uint32Array:i,Int32Array:a,Map:f,DataView:u,Promise:w,TextEncoder:l,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:S,DecompressionStream:g}=self,v=void 0,z="undefined",b="function",k=new s,C=[[],[],[],[],[],[],[],[]];for(let t=0;t<256;t++){let n=t;for(let t=0;t<8;t++)n=1&n?n>>>1^3988292384:n>>>1;C[0][t]=n}for(let t=0;t<256;t++)for(let n=1;n<8;n++){const e=C[n-1][t];C[n][t]=e>>>8^C[0][255&e]}const[I,A,x,M,P,D,F,E]=C;class R{constructor(t){this.o=t||-1}append(t){let n=0|this.o;const e=0|t.length;let o=0;if(e>=8&&t.buffer){const r=new u(t.buffer,t.byteOffset,e),s=e-8;for(;o<=s;o+=8){const t=n^r.getInt32(o,!0),e=r.getInt32(o+4,!0);n=E[255&t]^F[t>>>8&255]^D[t>>>16&255]^P[t>>>24&255]^M[255&e]^x[e>>>8&255]^A[e>>>16&255]^I[e>>>24&255]}}for(;o<e;o++)n=n>>>8^I[255&(n^t[o])];this.o=n}get(){return~this.o}}class U extends d{constructor(){let t;const n=new R;super({transform(t,e){n.append(t),e.enqueue(t)},flush(){const e=new s(4);new u(e.buffer).setUint32(0,n.get()),t.value=e}}),t=this}}function B(t,n){const e=new s(t.length+n.length);return e.set(t),e.set(n,t.length),e}function T(t){return new u(t.buffer,t.byteOffset,t.byteLength)}const V=64,W=20,j=new s([128]),K=new s(1),O=new a([1732584193,4023233417,2562383102,271733878,3285377520]),H=new s(256),L=new a(256),N=new a(256),q=new a(256),G=new a(256);let J=!1;function Q(t,n){!function(){if(!J){let t=1,n=1;do{t=255&(t^t<<1^(128&t?27:0)),n=255&(n^n<<1),n=255&(n^n<<2),n=255&(n^n<<4),128&n&&(n^=9),H[t]=255&(n^(n<<1|n>>7)^(n<<2|n>>6)^(n<<3|n>>5)^(n<<4|n>>4)^99)}while(1!=t);H[0]=99;for(let t=0;t<256;t++){const n=H[t],e=$(n),o=e<<24|n<<16|n<<8|e^n;L[t]=o,N[t]=o>>>8|o<<24,q[t]=o>>>16|o<<16,G[t]=o>>>24|o<<8}J=!0}}();const e=new a(60),o=function(t,n){const e=t.length>>2,o=e+6,r=4*(o+1);let s=1;for(let o=0;o<e;o++)n[o]=t[4*o]<<24|t[4*o+1]<<16|t[4*o+2]<<8|t[4*o+3];for(let t=e;t<r;t++){let o=n[t-1];t%e==0?(o=Y(o<<8|o>>>24)^s<<24,s=$(s)):e>6&&t%e==4&&(o=Y(o)),n[t]=n[t-e]^o}return o}(t,e),r=new a(4),s=X(n);let c=0,i=0,f=0,w=0;return{process(t,n){n&&s.update(t,0,t.length),function(t){const n=new u(t.buffer,t.byteOffset,t.byteLength),e=t.length;let o=0;for(;o+16<=e;o+=16)l(),n.setInt32(o,n.getInt32(o)^r[0]),n.setInt32(o+4,n.getInt32(o+4)^r[1]),n.setInt32(o+8,n.getInt32(o+8)^r[2]),n.setInt32(o+12,n.getInt32(o+12)^r[3]);if(o<e){l();for(let n=0;o<e;o++,n++)t[o]^=r[n>>2]>>>24-8*(3&n)}}(t),n||s.update(t,0,t.length)},digest:()=>s.digest()};function l(){c=c+1|0,c||(i=i+1|0,i||(f=f+1|0,f||(w=w+1|0)));let t=Z(c)^e[0],n=Z(i)^e[1],s=Z(f)^e[2],a=Z(w)^e[3],u=L[t>>>24]^N[n>>>16&255]^q[s>>>8&255]^G[255&a]^e[4],l=L[n>>>24]^N[s>>>16&255]^q[a>>>8&255]^G[255&t]^e[5],h=L[s>>>24]^N[a>>>16&255]^q[t>>>8&255]^G[255&n]^e[6],p=L[a>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&s]^e[7];t=L[u>>>24]^N[l>>>16&255]^q[h>>>8&255]^G[255&p]^e[8],n=L[l>>>24]^N[h>>>16&255]^q[p>>>8&255]^G[255&u]^e[9],s=L[h>>>24]^N[p>>>16&255]^q[u>>>8&255]^G[255&l]^e[10],a=L[p>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&h]^e[11],u=L[t>>>24]^N[n>>>16&255]^q[s>>>8&255]^G[255&a]^e[12],l=L[n>>>24]^N[s>>>16&255]^q[a>>>8&255]^G[255&t]^e[13],h=L[s>>>24]^N[a>>>16&255]^q[t>>>8&255]^G[255&n]^e[14],p=L[a>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&s]^e[15],t=L[u>>>24]^N[l>>>16&255]^q[h>>>8&255]^G[255&p]^e[16],n=L[l>>>24]^N[h>>>16&255]^q[p>>>8&255]^G[255&u]^e[17],s=L[h>>>24]^N[p>>>16&255]^q[u>>>8&255]^G[255&l]^e[18],a=L[p>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&h]^e[19],u=L[t>>>24]^N[n>>>16&255]^q[s>>>8&255]^G[255&a]^e[20],l=L[n>>>24]^N[s>>>16&255]^q[a>>>8&255]^G[255&t]^e[21],h=L[s>>>24]^N[a>>>16&255]^q[t>>>8&255]^G[255&n]^e[22],p=L[a>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&s]^e[23],t=L[u>>>24]^N[l>>>16&255]^q[h>>>8&255]^G[255&p]^e[24],n=L[l>>>24]^N[h>>>16&255]^q[p>>>8&255]^G[255&u]^e[25],s=L[h>>>24]^N[p>>>16&255]^q[u>>>8&255]^G[255&l]^e[26],a=L[p>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&h]^e[27],u=L[t>>>24]^N[n>>>16&255]^q[s>>>8&255]^G[255&a]^e[28],l=L[n>>>24]^N[s>>>16&255]^q[a>>>8&255]^G[255&t]^e[29],h=L[s>>>24]^N[a>>>16&255]^q[t>>>8&255]^G[255&n]^e[30],p=L[a>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&s]^e[31],t=L[u>>>24]^N[l>>>16&255]^q[h>>>8&255]^G[255&p]^e[32],n=L[l>>>24]^N[h>>>16&255]^q[p>>>8&255]^G[255&u]^e[33],s=L[h>>>24]^N[p>>>16&255]^q[u>>>8&255]^G[255&l]^e[34],a=L[p>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&h]^e[35],u=L[t>>>24]^N[n>>>16&255]^q[s>>>8&255]^G[255&a]^e[36],l=L[n>>>24]^N[s>>>16&255]^q[a>>>8&255]^G[255&t]^e[37],h=L[s>>>24]^N[a>>>16&255]^q[t>>>8&255]^G[255&n]^e[38],p=L[a>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&s]^e[39];let d=40;o>10&&(t=L[u>>>24]^N[l>>>16&255]^q[h>>>8&255]^G[255&p]^e[40],n=L[l>>>24]^N[h>>>16&255]^q[p>>>8&255]^G[255&u]^e[41],s=L[h>>>24]^N[p>>>16&255]^q[u>>>8&255]^G[255&l]^e[42],a=L[p>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&h]^e[43],u=L[t>>>24]^N[n>>>16&255]^q[s>>>8&255]^G[255&a]^e[44],l=L[n>>>24]^N[s>>>16&255]^q[a>>>8&255]^G[255&t]^e[45],h=L[s>>>24]^N[a>>>16&255]^q[t>>>8&255]^G[255&n]^e[46],p=L[a>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&s]^e[47],d=48),o>12&&(t=L[u>>>24]^N[l>>>16&255]^q[h>>>8&255]^G[255&p]^e[48],n=L[l>>>24]^N[h>>>16&255]^q[p>>>8&255]^G[255&u]^e[49],s=L[h>>>24]^N[p>>>16&255]^q[u>>>8&255]^G[255&l]^e[50],a=L[p>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&h]^e[51],u=L[t>>>24]^N[n>>>16&255]^q[s>>>8&255]^G[255&a]^e[52],l=L[n>>>24]^N[s>>>16&255]^q[a>>>8&255]^G[255&t]^e[53],h=L[s>>>24]^N[a>>>16&255]^q[t>>>8&255]^G[255&n]^e[54],p=L[a>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&s]^e[55],d=56),r[0]=(H[u>>>24]<<24|H[l>>>16&255]<<16|H[h>>>8&255]<<8|H[255&p])^e[d],r[1]=(H[l>>>24]<<24|H[h>>>16&255]<<16|H[p>>>8&255]<<8|H[255&u])^e[d+1],r[2]=(H[h>>>24]<<24|H[p>>>16&255]<<16|H[u>>>8&255]<<8|H[255&l])^e[d+2],r[3]=(H[p>>>24]<<24|H[u>>>16&255]<<16|H[l>>>8&255]<<8|H[255&h])^e[d+3]}}function X(t){const n=function(){const t=new a(O),n=new a(16),e=new s(V),r=new u(e.buffer),c=new s(8);let i=0,f=0;return{update:w,digest:function(){const n=8*f,e=o.floor(n/4294967296),r=n>>>0;for(w(j,0,1);56!=i;)w(K,0,1);c[0]=e>>>24,c[1]=e>>>16,c[2]=e>>>8,c[3]=e,c[4]=r>>>24,c[5]=r>>>16,c[6]=r>>>8,c[7]=r,w(c,0,8);const a=new s(W),l=new u(a.buffer);for(let n=0;n<t.length;n++)l.setInt32(4*n,t[n]);return t.set(O),i=0,f=0,a}};function w(t,n,o){const s=n+o;if(f+=o,i){for(;n<s&&i<V;)e[i++]=t[n++];i==V&&(l(r,0),i=0)}if(n+V<=s){const e=new u(t.buffer,t.byteOffset,t.byteLength);for(;n+V<=s;n+=V)l(e,n)}for(;n<s;)e[i++]=t[n++]}function l(e,o){for(let t=0;t<16;t++)n[t]=e.getInt32(o+4*t);let r,s=t[0],c=t[1],i=t[2],a=t[3],f=t[4];for(let t=0;t<15;t+=5)f=(s<<5|s>>>27)+((i^a)&c^a)+f+1518500249+n[t]|0,c=c<<30|c>>>2,a=(f<<5|f>>>27)+((c^i)&s^i)+a+1518500249+n[t+1]|0,s=s<<30|s>>>2,i=(a<<5|a>>>27)+((s^c)&f^c)+i+1518500249+n[t+2]|0,f=f<<30|f>>>2,c=(i<<5|i>>>27)+((f^s)&a^s)+c+1518500249+n[t+3]|0,a=a<<30|a>>>2,s=(c<<5|c>>>27)+((a^f)&i^f)+s+1518500249+n[t+4]|0,i=i<<30|i>>>2;f=(s<<5|s>>>27)+((i^a)&c^a)+f+1518500249+n[15]|0,c=c<<30|c>>>2,r=n[13]^n[8]^n[2]^n[0],r=r<<1|r>>>31,n[0]=r,a=(f<<5|f>>>27)+((c^i)&s^i)+a+1518500249+r|0,s=s<<30|s>>>2,r=n[14]^n[9]^n[3]^n[1],r=r<<1|r>>>31,n[1]=r,i=(a<<5|a>>>27)+((s^c)&f^c)+i+1518500249+r|0,f=f<<30|f>>>2,r=n[15]^n[10]^n[4]^n[2],r=r<<1|r>>>31,n[2]=r,c=(i<<5|i>>>27)+((f^s)&a^s)+c+1518500249+r|0,a=a<<30|a>>>2,r=n[0]^n[11]^n[5]^n[3],r=r<<1|r>>>31,n[3]=r,s=(c<<5|c>>>27)+((a^f)&i^f)+s+1518500249+r|0,i=i<<30|i>>>2;for(let t=20;t<40;t+=5)r=n[t-3&15]^n[t-8&15]^n[t-14&15]^n[15&t],r=r<<1|r>>>31,n[15&t]=r,f=(s<<5|s>>>27)+(c^i^a)+f+1859775393+r|0,c=c<<30|c>>>2,r=n[t-2&15]^n[t-7&15]^n[t-13&15]^n[t+1&15],r=r<<1|r>>>31,n[t+1&15]=r,a=(f<<5|f>>>27)+(s^c^i)+a+1859775393+r|0,s=s<<30|s>>>2,r=n[t-1&15]^n[t-6&15]^n[t-12&15]^n[t+2&15],r=r<<1|r>>>31,n[t+2&15]=r,i=(a<<5|a>>>27)+(f^s^c)+i+1859775393+r|0,f=f<<30|f>>>2,r=n[15&t]^n[t-5&15]^n[t-11&15]^n[t+3&15],r=r<<1|r>>>31,n[t+3&15]=r,c=(i<<5|i>>>27)+(a^f^s)+c+1859775393+r|0,a=a<<30|a>>>2,r=n[t+1&15]^n[t-4&15]^n[t-10&15]^n[t+4&15],r=r<<1|r>>>31,n[t+4&15]=r,s=(c<<5|c>>>27)+(i^a^f)+s+1859775393+r|0,i=i<<30|i>>>2;for(let t=40;t<60;t+=5)r=n[t-3&15]^n[t-8&15]^n[t-14&15]^n[15&t],r=r<<1|r>>>31,n[15&t]=r,f=(s<<5|s>>>27)+(c&i|(c|i)&a)+f+2400959708+r|0,c=c<<30|c>>>2,r=n[t-2&15]^n[t-7&15]^n[t-13&15]^n[t+1&15],r=r<<1|r>>>31,n[t+1&15]=r,a=(f<<5|f>>>27)+(s&c|(s|c)&i)+a+2400959708+r|0,s=s<<30|s>>>2,r=n[t-1&15]^n[t-6&15]^n[t-12&15]^n[t+2&15],r=r<<1|r>>>31,n[t+2&15]=r,i=(a<<5|a>>>27)+(f&s|(f|s)&c)+i+2400959708+r|0,f=f<<30|f>>>2,r=n[15&t]^n[t-5&15]^n[t-11&15]^n[t+3&15],r=r<<1|r>>>31,n[t+3&15]=r,c=(i<<5|i>>>27)+(a&f|(a|f)&s)+c+2400959708+r|0,a=a<<30|a>>>2,r=n[t+1&15]^n[t-4&15]^n[t-10&15]^n[t+4&15],r=r<<1|r>>>31,n[t+4&15]=r,s=(c<<5|c>>>27)+(i&a|(i|a)&f)+s+2400959708+r|0,i=i<<30|i>>>2;for(let t=60;t<80;t+=5)r=n[t-3&15]^n[t-8&15]^n[t-14&15]^n[15&t],r=r<<1|r>>>31,n[15&t]=r,f=(s<<5|s>>>27)+(c^i^a)+f+3395469782+r|0,c=c<<30|c>>>2,r=n[t-2&15]^n[t-7&15]^n[t-13&15]^n[t+1&15],r=r<<1|r>>>31,n[t+1&15]=r,a=(f<<5|f>>>27)+(s^c^i)+a+3395469782+r|0,s=s<<30|s>>>2,r=n[t-1&15]^n[t-6&15]^n[t-12&15]^n[t+2&15],r=r<<1|r>>>31,n[t+2&15]=r,i=(a<<5|a>>>27)+(f^s^c)+i+3395469782+r|0,f=f<<30|f>>>2,r=n[15&t]^n[t-5&15]^n[t-11&15]^n[t+3&15],r=r<<1|r>>>31,n[t+3&15]=r,c=(i<<5|i>>>27)+(a^f^s)+c+3395469782+r|0,a=a<<30|a>>>2,r=n[t+1&15]^n[t-4&15]^n[t-10&15]^n[t+4&15],r=r<<1|r>>>31,n[t+4&15]=r,s=(c<<5|c>>>27)+(i^a^f)+s+3395469782+r|0,i=i<<30|i>>>2;t[0]=t[0]+s|0,t[1]=t[1]+c|0,t[2]=t[2]+i|0,t[3]=t[3]+a|0,t[4]=t[4]+f|0}}(),e=new s(V),r=new s(V);t.length>V&&(n.update(t,0,t.length),t=n.digest());for(let n=0;n<V;n++){const o=n<t.length?t[n]:0;e[n]=54^o,r[n]=92^o}return n.update(e,0,V),{update(t,e,o){n.update(t,e,o)},digest(){const t=n.digest();n.update(r,0,V),n.update(t,0,W);const o=n.digest();return n.update(e,0,V),o}}}function Y(t){return H[t>>>24]<<24|H[t>>>16&255]<<16|H[t>>>8&255]<<8|H[255&t]}function Z(t){return t<<24|(65280&t)<<8|t>>>8&65280|t>>>24}function $(t){return 255&(t<<1^27*(t>>7))}const _=typeof h!=z&&typeof h.getRandomValues==b,tt="Invalid password",nt="zipjs-abort-check-password";function et(t){if(_)return h.getRandomValues(t);throw new r("Crypto API not supported")}const ot={name:"PBKDF2"},rt=n.assign({hash:{name:"HMAC"}},ot),st=n.assign({iterations:1e3,hash:{name:"SHA-1"}},ot),ct=["deriveBits"],it=[8,12,16],at=[16,24,32],ft=10,ut=typeof h!=z,wt=ut&&h.subtle;let lt=ut&&typeof wt!=z&&typeof wt.importKey==b&&typeof wt.deriveBits==b,ht=Q;class pt extends d{constructor({password:t,rawPassword:n,encryptionStrength:e,checkPasswordOnly:o,checkAuthenticationCode:c=!0}){super({start(){yt(this,t,n,e)},async transform(t,n){const e=this,{password:c,strength:i,l:a,ready:f}=e;c?(await async function(t,n,e,o){const s=await gt(t,n,e,zt(o,0,it[n])),c=zt(o,it[n]);if(s[0]!=c[0]||s[1]!=c[1])throw St(t),new r(tt)}(e,i,c,zt(t,0,it[i]+2)),t=zt(t,it[i]+2),o?(St(e),n.error(new r(nt))):a()):await f;const u=new s(t.length-ft-(t.length-ft)%16);n.enqueue(mt(e,t,u,0,ft,!0))},async flush(t){const{h:n,m:e,ready:o}=this;if(n){await o;const i=zt(e,e.length-ft),a=new s(zt(e,0,e.length-ft));n.process(a,!0);const f=n.digest();let u=e.length<ft?1:0;for(let t=0;t<ft;t++)u|=f[t]^i[t];if(u&&c)throw new r("Invalid authentication code");t.enqueue(a)}},cancel(){St(this)}})}}class dt extends d{constructor({password:t,rawPassword:n,encryptionStrength:e}){super({start(){yt(this,t,n,e)},async transform(t,n){const e=this,{password:o,strength:r,l:c,ready:i}=e;let a=k;o?(a=await async function(t,n,e){const o=et(new s(it[n]));return B(o,await gt(t,n,e,o))}(e,r,o),c()):await i;const f=new s(a.length+t.length-t.length%16);f.set(a,0),n.enqueue(mt(e,t,f,a.length,0,!1))},async flush(t){const{h:n,m:e,ready:o}=this;if(n){await o;const r=new s(e);n.process(r,!1);const c=zt(n.digest(),0,ft);t.enqueue(B(r,c))}},cancel(){St(this)}})}}function yt(t,e,o,r){n.assign(t,{ready:new w(n=>t.l=n),password:vt(e,o),strength:r-1,m:k})}function mt(t,n,e,o,r,c){const{h:i,m:a}=t;a.length&&(n=B(a,n));const f=n.length-r,u=f-f%16;if(e=function(t,n){if(n&&n>t.length){const e=t;(t=new s(n)).set(e,0)}return t}(e,o+u),u){const t=zt(e,o,o+u);t.set(zt(n,0,u)),i.process(t,c)}return t.m=zt(n,u),e}function St({h:t}){t&&t.dispose&&t.dispose()}async function gt(t,e,r,c){t.password=null;const i=at[e],a=await async function(t,e,r){if(lt)try{const o=await wt.importKey("raw",t,rt,!1,ct);return new s(await wt.deriveBits(n.assign({salt:e},st),o,8*r))}catch{lt=!1}return function(t,n,e,r){const c=X(t),i=new s(r),a=new s(n.length+4),f=new u(a.buffer);a.set(n);for(let t=1,e=0;e<r;t++,e+=W){f.setUint32(n.length,t),c.update(a,0,a.length);let s=c.digest();const u=s.slice();for(let t=1;t<1e3;t++){c.update(s,0,W),s=c.digest();for(let t=0;t<W;t++)u[t]^=s[t]}i.set(u.subarray(0,o.min(W,r-e)),e)}return i}(t,e,0,r)}(r,c,2*i+2);return t.h=ht(zt(a,0,i),zt(a,i,2*i)),zt(a,2*i)}function vt(t,n){return n===v?function(t){if(typeof l==z){t=unescape(encodeURIComponent(t));const n=new s(t.length);for(let e=0;e<n.length;e++)n[e]=t.charCodeAt(e);return n}return(new l).encode(t)}(t):n}function zt(t,n,e){return t.subarray(n,e)}class bt extends d{constructor({password:t,rawPassword:n,passwordVerification:e,checkPasswordOnly:o}){super({start(){Ct(this,t,n,e)},transform(t,n){const e=this;if(e.password||e.rawPassword){const n=It(e,t.subarray(0,12));if(e.password=e.rawPassword=null,0!=(n[11]^e.passwordVerification))throw new r(tt);t=t.subarray(12)}o?n.error(new r(nt)):n.enqueue(It(e,t))}})}}class kt extends d{constructor({password:t,rawPassword:n,passwordVerification:e}){super({start(){Ct(this,t,n,e)},transform(t,n){const e=this;let o,r;if(e.password||e.rawPassword){e.password=e.rawPassword=null;const n=et(new s(12));n[11]=e.passwordVerification,o=new s(t.length+n.length),o.set(At(e,n),0),r=12}else o=new s(t.length),r=0;o.set(At(e,t),r),n.enqueue(o)}})}}function Ct(t,e,o,r){n.assign(t,{password:e,rawPassword:o,passwordVerification:r}),function(t,e,o){const r=[305419896,591751049,878082192];if(n.assign(t,{keys:r,S:new R(r[0]),v:new R(r[2])}),o)for(let n=0;n<o.length;n++)xt(t,o[n]);else for(let n=0;n<e.length;n++)xt(t,e.charCodeAt(n))}(t,e,o)}function It(t,n){const e=new s(n.length);for(let o=0;o<n.length;o++)e[o]=Mt(t)^n[o],xt(t,e[o]);return e}function At(t,n){const e=new s(n.length);for(let o=0;o<n.length;o++)e[o]=Mt(t)^n[o],xt(t,n[o]);return e}function xt(t,n){let[,e]=t.keys;t.S.append([n]);const r=~t.S.get();e=Dt(o.imul(Dt(e+Pt(r)),134775813)+1),t.v.append([e>>>24]);const s=~t.v.get();t.keys=[r,e,s]}function Mt(t){const n=2|t.keys[2];return Pt(o.imul(n,1^n)>>>8)}function Pt(t){return 255&t}function Dt(t){return 4294967295&t}function Ft(t){if(t instanceof y)return t;const n=t.getReader();return new y({async pull(t){const{value:e,done:o}=await n.read();o?t.close():t.enqueue(e)},cancel:t=>n.cancel(t)})}const Et=new f;function Rt(t){return Et.get(t)}const Ut="Invalid uncompressed size",Bt="deflate-raw",Tt="gzip",Vt=[31,139,8];class Wt extends d{constructor(t,{chunkSize:n,CompressionStreamFallback:e,CompressionStream:o}){super({});const{compressed:r,encrypted:s,useCompressionStream:c,zipCrypto:i,computeCrc32:a,level:f,deflate64:w,format:l,compressionMethod:h,inputSize:p}=t,d=this;let y,m,S,g=super.readable;const v=l&&Rt(l),z=function(t,n,e){return t&&n?n:e&&e.C?e:void 0}(c,o,e),b=a&&r&&!w&&!v&&(!s||i)&&Boolean(z);if(s&&!i||!a||b||(y=new U,g=qt(g,y)),r)if(v)g=Gt(g,Lt(v.CompressionStream,l,{level:f,chunkSize:n,compressionMethod:h,uncompressedSize:p}));else if(b)S=new jt,g=Gt(g,new z(Tt,{level:f,chunkSize:n})),g=qt(g,S);else try{g=Nt(g,c,{level:f,chunkSize:n},o,e)}catch(t){let n;try{n=new o(Tt)}catch{throw t}g=Gt(g,n),g=qt(g,new jt)}s&&(i?g=qt(g,new kt(t)):(m=new dt(t),g=qt(g,m))),Ht(d,g,()=>{s&&!i||!a||(d.crc32=b?S.crc32:new u(y.value.buffer).getUint32(0))})}}class jt extends d{constructor(){let t,n=10,e=new s(0);super({transform(t,r){if(n){const e=o.min(n,t.length);if(n-=e,!(t=t.subarray(e)).length)return}const s=e.length+t.length;if(s<=8)return void(e=B(e,t));const c=s-8,i=o.min(c,e.length);r.enqueue(B(e.subarray(0,i),t.subarray(0,c-i))),e=B(e.subarray(i),t.subarray(c-i))},flush(){const n=T(e);t.crc32=n.getUint32(0,!0),t.uncompressedSize=n.getUint32(4,!0)}}),t=this}}class Kt extends d{constructor(t,{chunkSize:n,DecompressionStreamFallback:e,DecompressionStream:o}){super({});const{zipCrypto:c,encrypted:i,checkCrc32:a,crc32:f,compressed:l,useCompressionStream:h,deflate64:p,format:m,compressionMethod:S,rawBitFlag:g,outputSize:z}=t;let b,k,C,I=super.readable;if(i&&(c?I=qt(I,new bt(t)):(k=new pt(t),I=qt(I,k))),l){const t=m&&Rt(m);if(t)I=Gt(I,Lt(t.DecompressionStream,m,{chunkSize:n,compressionMethod:S,rawBitFlag:g,uncompressedSize:z}));else try{I=Nt(I,h,{chunkSize:n,deflate64:p},o,e)}catch(t){if(p||z===v)throw t;let n;try{n=new o(Tt)}catch{throw t}C=new R,I=function(t,n,e,o){let c,i,a,f=0,u=!1;const l=new w((t,n)=>{i=t,a=n});l.catch(()=>{}),e||i();const h=new d({start(t){const n=new s(10);n.set(Vt),t.enqueue(n)},transform(t,n){n.enqueue(t)},async flush(t){u=!0,y();try{await l}finally{m()}const n=new s(8),r=T(n);r.setUint32(0,o.get(),!0),r.setUint32(4,e,!0),t.enqueue(n)},cancel(t){a(t)}}),p=new d({transform(t,n){o.append(t),f+=t.length,f>=e?i():u&&y(),n.enqueue(t)},cancel(t){a(t)}});return t=qt(t,h),qt(t=Gt(t,n),p);function y(){m(),c=setTimeout(()=>a(new r(Ut)),5e3)}function m(){clearTimeout(c)}}(I,n,z,C)}I=function(t){const n=t.getReader();return new y({async pull(t){let e;try{e=await n.read()}catch(t){if(t&&t.message)throw t;const n=new r("Invalid compressed data");throw n.cause=t,n}const{value:o,done:s}=e;s?t.close():t.enqueue(o)},cancel:t=>n.cancel(t)})}(I)}a&&!C&&(b=new U,I=qt(I,b)),Ht(this,I,()=>{if(a){const t=C?C.get()>>>0:new u(b.value.buffer).getUint32(0,!1);if(f!=t)throw new r("Invalid CRC32")}})}}const Ot=new f;function Ht(t,e,o){e=qt(e,new d({flush:o})),n.defineProperty(t,"readable",{get:()=>e})}function Lt(t,n,e){if(!t)throw new r("Compression method not supported");return new t(n,e)}function Nt(t,n,e,o,r){const s=n&&o?o:r||o,c=e.deflate64?"deflate64-raw":Bt;let i;try{i=new s(c,e)}catch(t){if(!n||!r||s==r)throw t;i=new r(c,e)}return Gt(t,i)}function qt(t,n){return Ft(t).pipeThrough(n)}function Gt(t,n){const e=n.writable.getWriter(),o=t.getReader();return async function(){try{for(;;){await e.ready;const t=await o.read();if(t.done){await e.close();break}await e.write(t.value)}}catch(t){await async function(t,n){try{await t.abort(n)}catch{}}(e,t),await async function(t,n){try{await t.cancel(n)}catch{}}(o,t)}}(),n.readable}const Jt="data",Qt="deflate";class Xt extends d{constructor(t,e){super({});const o=this,{codecType:s}=t;let c;s.startsWith(Qt)?c=Wt:s.startsWith("inflate")&&(c=Kt),o.outputSize=0;let i=0;const a=new c(t,e),f=super.readable,u=new d({transform(t,n){t&&t.length&&(i+=t.length,n.enqueue(t))},flush(){n.assign(o,{inputSize:i})}}),w=new d({transform(n,e){if(n&&n.length&&(e.enqueue(n),o.outputSize+=n.length,t.outputSize!==v&&o.outputSize>t.outputSize))throw new r(Ut)},flush(){const{crc32:t}=a;n.assign(o,{crc32:t,inputSize:i})}});n.defineProperty(o,"readable",{get:()=>f.pipeThrough(u).pipeThrough(a).pipeThrough(w)})}}class Yt extends d{constructor(t){const o=[];let r=0,c=0;function i(){const n=new s(t);let e=0;for(;e<t;){const r=o[0],s=t-e;r.length<=s?(n.set(r,e),e+=r.length,o.shift()):(n.set(r.subarray(0,s),e),o[0]=r.subarray(s),e+=s)}return r-=t,n}(!e.isFinite(t)||t<1)&&(t=65536),super({transform(n,e){for(o.push(n),r+=n.length;r>t;)c+=t,e.enqueue(i())},flush(t){r&&(c+=r,t.enqueue(function(t,n){const e=new s(n);let o=0;for(const n of t)e.set(n,o),o+=n.length;return e}(o,r)))}}),n.defineProperty(this,"outputSize",{get:()=>c})}}let Zt=2;try{typeof navigator!=z&&navigator.hardwareConcurrency&&(Zt=navigator.hardwareConcurrency)}catch{}function $t(t){return Boolean(t)&&"object"==typeof t}const _t=new f,tn=new f,nn=function(){try{return structuredClone(new r)instanceof r}catch{return!1}}();let en=0;async function on(t){let n,s,c;try{const{options:i,config:a}=t;if(i.format)try{await async function(t,n){!Et.has(t)&&n&&function(t,n){const{CompressionStream:e,DecompressionStream:o}=n;if(typeof e!=b&&typeof o!=b)throw new r("Invalid codec module");Et.set(t,{CompressionStream:e,DecompressionStream:o})}(t,await(import(n)))}(i.format,i.codecURI)}catch(t){if($t(t))try{t.codecImportFailed=!0}catch{}throw t}if(a.CompressionStream=self.CompressionStream,a.DecompressionStream=self.DecompressionStream,i.compressed&&!i.format)if(i.useCompressionStream){if(!function(t,n){if(!t)return!1;let e=Ot.get(t);e||(e=new f,Ot.set(t,e));let o=e.get(n);if(o===v){try{new t(n),o=!0}catch{o=!1}e.set(n,o)}return o}(i.codecType.startsWith(Qt)?a.CompressionStream:a.DecompressionStream,Bt))try{await self.initModule(t.config)}catch{}}else try{await self.initModule(t.config)}catch{i.useCompressionStream=!0}if(i.encrypted&&!i.zipCrypto)try{await self.initModule(t.config)}catch{}!a.CompressionStreamFallback&&a.CompressionStreamZlib&&(a.CompressionStreamFallback=a.CompressionStreamZlib),!a.DecompressionStreamFallback&&a.DecompressionStreamZlib&&(a.DecompressionStreamFallback=a.DecompressionStreamZlib);const u={highWaterMark:1},l=t.readable?Ft(t.readable):new y({async pull(t){const n=new w(t=>_t.set(en,t));rn({type:"pull",messageId:en}),en=(en+1)%e.MAX_SAFE_INTEGER;const{value:o,done:r}=await n;t.enqueue(o),r&&t.close()}},u);c=t.writable?function(t){if(t instanceof m)return t;const n=t.getWriter();return new m({write:t=>n.write(t),close:()=>n.close(),abort:t=>n.abort(t)})}(t.writable):new m({async write(t){let n;const o=new w(t=>n=t);tn.set(en,n),rn({type:Jt,value:t,messageId:en}),en=(en+1)%e.MAX_SAFE_INTEGER,await o}},u),n=new Xt(i,a),s=new Yt(function(t){return r="string"==typeof(n=r=t.chunkSize)&&n.trim()?e(n):n,e.isInteger(r)&&r>=1?o.max(r,64):65536;var n,r}(a)),await l.pipeThrough(n).pipeThrough(s).pipeTo(c,{preventClose:!0,preventAbort:!0}),await c.getWriter().close();const{crc32:h,inputSize:p,outputSize:d}=n;rn({type:"close",result:{crc32:h,inputSize:p,outputSize:d}})}catch(t){const n=s?s.outputSize:0;if($t(t))try{t.outputSize=n}catch{}if(c&&!c.locked)try{await c.getWriter().close()}catch{}sn(t,n)}}function rn(t){const{value:n}=t;if(n)if(n.length)try{t.value=(e=n,e.byteOffset||e.byteLength!=e.buffer.byteLength?new s(e):e).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var e}function sn(t,n){const{message:e,stack:o,code:s,name:c,outputSize:i,cause:a,codecImportFailed:f}=function(t=new r("Unknown error")){return $t(t)?t:new r(String(t))}(t),u={message:e,stack:o,code:s,name:c,outputSize:i===v?n:i};if(a&&(u.cause={name:a.name,message:a.message}),f&&(u.codecImportFailed=!0),nn)try{return void p({error:u,errorValue:{value:t}})}catch{}p({error:u})}addEventListener("message",({data:t})=>{const{type:n,messageId:e,value:o,done:r}=t;try{if("start"==n&&on(t),n==Jt){const t=_t.get(e);_t.delete(e),t({value:o||new s,done:r})}if("ack"==n){const t=tn.get(e);tn.delete(e),t()}}catch(t){sn(t)}}),p({type:"ready"});const cn="deflate",an="deflate-raw",fn="deflate64-raw",un="gzip";let wn,ln,hn,pn,dn;function yn(t,n,e={}){if(!wn){const t=new r("WASM module not loaded");throw t.cause=dn,t}const c="number"==typeof e.level?e.level:-1,i="number"==typeof e.outBuffer?e.outBuffer:65536,a="number"==typeof e.inBufferSize?e.inBufferSize:65536;return new d({start(){try{let e;if(this.I=ln(i),this.in=ln(a),this.inBufferSize=a,!this.I||!this.in)throw new r("allocation failed");if(t?(this.A=wn.deflate_process,this.M=wn.deflate_last_consumed,this.P=wn.deflate_end,this.D=wn.deflate_new(),e=n===un?wn.deflate_init_gzip(this.D,c):n===an?wn.deflate_init_raw(this.D,c):wn.deflate_init(this.D,c)):n===fn?(this.A=wn.inflate9_process,this.M=wn.inflate9_last_consumed,this.P=wn.inflate9_end,this.D=wn.inflate9_new(),e=wn.inflate9_init_raw(this.D)):(this.A=wn.inflate_process,this.M=wn.inflate_last_consumed,this.P=wn.inflate_end,this.D=wn.inflate_new(),e=n===an?wn.inflate_init_raw(this.D):n===un?wn.inflate_init_gzip(this.D):wn.inflate_init(this.D)),0!==e)throw new r("init failed:"+e)}catch(t){throw f(this),t}},transform(t,n){try{const e=t,c=new s(pn.buffer),a=this.A,f=this.M,u=this.I;let w=0;for(;w<e.length;){const t=o.min(e.length-w,32768);if((!this.in||this.inBufferSize<t)&&(this.in&&hn&&(hn(this.in),this.in=0),this.in=ln(t),this.inBufferSize=t,!this.in))throw new r("allocation failed");c.set(e.subarray(w,w+t),this.in);const s=a(this.D,this.in,t,u,i,0),l=s>>24&255,h=128&l?l-256:l;if(h<0)throw new r("process error:"+h);const p=16777215&s;p&&n.enqueue(c.slice(u,u+p));const d=f(this.D);if(0===d&&0===p)break;w+=d}}catch(t){f(this),n.error(t)}},flush(t){try{const n=new s(pn.buffer),e=this.A,o=this.I;for(;;){const s=e(this.D,0,0,o,i,4),c=s>>24&255,a=128&c?c-256:c;if(a<0)throw new r("process error:"+a);const f=16777215&s;if(f&&t.enqueue(n.slice(o,o+f)),1===c||0===f)break}}catch(n){t.error(n)}finally{const n=f(this);0!==n&&t.error(new r("end error:"+n))}},cancel(){f(this)}});function f(t){let n=0;return t.D&&t.P&&(n=t.P(t.D)),t.D=0,t.in&&hn&&hn(t.in),t.in=0,t.I&&hn&&hn(t.I),t.I=0,n}}class mn{constructor(t=cn,n){return yn(!0,t,n)}}class Sn{constructor(t=cn,n){return yn(!1,t,n)}}mn.C=!0,Sn.C=!0,mn.F=[cn,an,un],Sn.F=[cn,an,un,fn];const gn=65536;let vn,zn;function bn(t){return new s(t.memory.buffer)}let kn=!1;!function(t={}){const{init:n,R:e}=t,o=t.CompressionStreamFallback||t.CompressionStreamZlib,r=t.DecompressionStreamFallback||t.DecompressionStreamZlib;e&&(ht=e||Q),self.initModule=async t=>{n&&await n(t),o&&(t.CompressionStreamFallback=o),r&&(t.DecompressionStreamFallback=r)}}({CompressionStreamFallback:mn,DecompressionStreamFallback:Sn,R:function(t,n){const e=vn;let o=e?function(t,n,e){zn||(zn=t.malloc(gn));const o=zn?t.aes_hmac_new():0;if(o){const r=bn(t);if(r.set(n,zn),r.set(e,zn+n.length),t.aes_hmac_init(o,zn,n.length,zn+n.length,e.length))return t.aes_hmac_end(o,0),0}return o}(e,t,n):0;if(!o)return Q(t,n);const r=zn;return{process(t,n){for(let s=0;s<t.length;s+=gn){const c=t.subarray(s,s+gn),i=bn(e);i.set(c,r),e.aes_hmac_process(o,r,c.length,n?1:0),c.set(i.subarray(r,r+c.length))}},digest:()=>(e.aes_hmac_end(o,r),o=0,bn(e).slice(r,r+20)),dispose(){o&&(e.aes_hmac_end(o,0),o=0)}}},init:t=>async function(t,{baseURI:n}){if(!kn)try{await async function(t,n){let e,o;try{try{o=new URL(t,n)}catch{}const r=await fetch(o);e=await r.arrayBuffer()}catch(n){if(!t.startsWith("data:application/wasm;base64,"))throw n;e=function(t){const n=t.split(",")[1],e=atob(n),o=e.length,r=new s(o);for(let t=0;t<o;++t)r[t]=e.charCodeAt(t);return r.buffer}(t)}const c=await WebAssembly.instantiate(e);var i;(function(t){if(wn=t,({malloc:ln,free:hn,memory:pn}=wn),"function"!=typeof ln||"function"!=typeof hn||!pn)throw wn=ln=hn=pn=null,new r("Invalid WASM module")})(c.instance.exports),typeof(i=c.instance.exports).aes_hmac_new==b&&(vn=i,zn=0)}(t,n),kn=!0}catch(t){throw function(t){dn=t}(t),t}}(t.wasmURI,t)})});\n';if("string"==typeof r&&(r=(new TextEncoder).encode(r)),t){const t=new Blob([r],{type:e});return URL.createObjectURL(t)}return "data:"+e+";base64,"+function(t){let e="";const r=t.length;let s=0;for(;s+2<r;s+=3){const r=t[s]<<16|t[s+1]<<8|t[s+2];e+=n$1[r>>18&63]+n$1[r>>12&63]+n$1[r>>6&63]+n$1[63&r];}const o=r-s;if(1===o){const r=t[s]<<16;e+=n$1[r>>18&63]+n$1[r>>12&63]+"==";}else if(2===o){const r=t[s]<<16|t[s+1]<<8;e+=n$1[r>>18&63]+n$1[r>>12&63]+n$1[r>>6&63]+"=";}return e}(r)}});
448
+ const t$1=new Uint8Array(288);t$1.fill(8,0,144),t$1.fill(9,144,256),t$1.fill(7,256,280),t$1.fill(8,280,288),new Uint8Array(30).fill(5);const n$1="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e$1=t=>t({workerURI:t=>{const e="text/javascript";let r='!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";const{Array:t,Object:n,Number:e,Math:o,Error:r,Uint8Array:c,Uint16Array:s,Uint32Array:a,Int32Array:i,Map:f,DataView:u,Promise:w,TextEncoder:l,crypto:p,postMessage:d,TransformStream:h,ReadableStream:y,WritableStream:m,CompressionStream:S,DecompressionStream:g}=self,v=void 0,b="undefined",k="function",z=new c,C=[[],[],[],[],[],[],[],[]];for(let t=0;t<256;t++){let n=t;for(let t=0;t<8;t++)n=1&n?n>>>1^3988292384:n>>>1;C[0][t]=n}for(let t=0;t<256;t++)for(let n=1;n<8;n++){const e=C[n-1][t];C[n][t]=e>>>8^C[0][255&e]}const[I,A,M,x,P,D,F,B]=C;class E{constructor(t){this.o=t||-1}append(t){let n=0|this.o;const e=0|t.length;let o=0;if(e>=8&&t.buffer){const r=new u(t.buffer,t.byteOffset,e),c=e-8;for(;o<=c;o+=8){const t=n^r.getInt32(o,!0),e=r.getInt32(o+4,!0);n=B[255&t]^F[t>>>8&255]^D[t>>>16&255]^P[t>>>24&255]^x[255&e]^M[e>>>8&255]^A[e>>>16&255]^I[e>>>24&255]}}for(;o<e;o++)n=n>>>8^I[255&(n^t[o])];this.o=n}get(){return~this.o}}class R extends h{constructor(){let t;const n=new E;super({transform(t,e){n.append(t),e.enqueue(t)},flush(){const e=new c(4);new u(e.buffer).setUint32(0,n.get()),t.value=e}}),t=this}}function U(t,n){const e=new c(t.length+n.length);return e.set(t),e.set(n,t.length),e}function W(t){return new u(t.buffer,t.byteOffset,t.byteLength)}const V=64,K=20,j=new c([128]),H=new c(1),O=new i([1732584193,4023233417,2562383102,271733878,3285377520]),T=new c(256),L=new i(256),N=new i(256),q=new i(256),G=new i(256);let J=!1;function Q(t,n){!function(){if(!J){let t=1,n=1;do{t=255&(t^t<<1^(128&t?27:0)),n=255&(n^n<<1),n=255&(n^n<<2),n=255&(n^n<<4),128&n&&(n^=9),T[t]=255&(n^(n<<1|n>>7)^(n<<2|n>>6)^(n<<3|n>>5)^(n<<4|n>>4)^99)}while(1!=t);T[0]=99;for(let t=0;t<256;t++){const n=T[t],e=$(n),o=e<<24|n<<16|n<<8|e^n;L[t]=o,N[t]=o>>>8|o<<24,q[t]=o>>>16|o<<16,G[t]=o>>>24|o<<8}J=!0}}();const e=new i(60),o=function(t,n){const e=t.length>>2,o=e+6,r=4*(o+1);let c=1;for(let o=0;o<e;o++)n[o]=t[4*o]<<24|t[4*o+1]<<16|t[4*o+2]<<8|t[4*o+3];for(let t=e;t<r;t++){let o=n[t-1];t%e==0?(o=Y(o<<8|o>>>24)^c<<24,c=$(c)):e>6&&t%e==4&&(o=Y(o)),n[t]=n[t-e]^o}return o}(t,e),r=new i(4),c=X(n);let s=0,a=0,f=0,w=0;return{process(t,n){n&&c.update(t,0,t.length),function(t){const n=new u(t.buffer,t.byteOffset,t.byteLength),e=t.length;let o=0;for(;o+16<=e;o+=16)l(),n.setInt32(o,n.getInt32(o)^r[0]),n.setInt32(o+4,n.getInt32(o+4)^r[1]),n.setInt32(o+8,n.getInt32(o+8)^r[2]),n.setInt32(o+12,n.getInt32(o+12)^r[3]);if(o<e){l();for(let n=0;o<e;o++,n++)t[o]^=r[n>>2]>>>24-8*(3&n)}}(t),n||c.update(t,0,t.length)},digest:()=>c.digest()};function l(){s=s+1|0,s||(a=a+1|0,a||(f=f+1|0,f||(w=w+1|0)));let t=Z(s)^e[0],n=Z(a)^e[1],c=Z(f)^e[2],i=Z(w)^e[3],u=L[t>>>24]^N[n>>>16&255]^q[c>>>8&255]^G[255&i]^e[4],l=L[n>>>24]^N[c>>>16&255]^q[i>>>8&255]^G[255&t]^e[5],p=L[c>>>24]^N[i>>>16&255]^q[t>>>8&255]^G[255&n]^e[6],d=L[i>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&c]^e[7];t=L[u>>>24]^N[l>>>16&255]^q[p>>>8&255]^G[255&d]^e[8],n=L[l>>>24]^N[p>>>16&255]^q[d>>>8&255]^G[255&u]^e[9],c=L[p>>>24]^N[d>>>16&255]^q[u>>>8&255]^G[255&l]^e[10],i=L[d>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&p]^e[11],u=L[t>>>24]^N[n>>>16&255]^q[c>>>8&255]^G[255&i]^e[12],l=L[n>>>24]^N[c>>>16&255]^q[i>>>8&255]^G[255&t]^e[13],p=L[c>>>24]^N[i>>>16&255]^q[t>>>8&255]^G[255&n]^e[14],d=L[i>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&c]^e[15],t=L[u>>>24]^N[l>>>16&255]^q[p>>>8&255]^G[255&d]^e[16],n=L[l>>>24]^N[p>>>16&255]^q[d>>>8&255]^G[255&u]^e[17],c=L[p>>>24]^N[d>>>16&255]^q[u>>>8&255]^G[255&l]^e[18],i=L[d>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&p]^e[19],u=L[t>>>24]^N[n>>>16&255]^q[c>>>8&255]^G[255&i]^e[20],l=L[n>>>24]^N[c>>>16&255]^q[i>>>8&255]^G[255&t]^e[21],p=L[c>>>24]^N[i>>>16&255]^q[t>>>8&255]^G[255&n]^e[22],d=L[i>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&c]^e[23],t=L[u>>>24]^N[l>>>16&255]^q[p>>>8&255]^G[255&d]^e[24],n=L[l>>>24]^N[p>>>16&255]^q[d>>>8&255]^G[255&u]^e[25],c=L[p>>>24]^N[d>>>16&255]^q[u>>>8&255]^G[255&l]^e[26],i=L[d>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&p]^e[27],u=L[t>>>24]^N[n>>>16&255]^q[c>>>8&255]^G[255&i]^e[28],l=L[n>>>24]^N[c>>>16&255]^q[i>>>8&255]^G[255&t]^e[29],p=L[c>>>24]^N[i>>>16&255]^q[t>>>8&255]^G[255&n]^e[30],d=L[i>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&c]^e[31],t=L[u>>>24]^N[l>>>16&255]^q[p>>>8&255]^G[255&d]^e[32],n=L[l>>>24]^N[p>>>16&255]^q[d>>>8&255]^G[255&u]^e[33],c=L[p>>>24]^N[d>>>16&255]^q[u>>>8&255]^G[255&l]^e[34],i=L[d>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&p]^e[35],u=L[t>>>24]^N[n>>>16&255]^q[c>>>8&255]^G[255&i]^e[36],l=L[n>>>24]^N[c>>>16&255]^q[i>>>8&255]^G[255&t]^e[37],p=L[c>>>24]^N[i>>>16&255]^q[t>>>8&255]^G[255&n]^e[38],d=L[i>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&c]^e[39];let h=40;o>10&&(t=L[u>>>24]^N[l>>>16&255]^q[p>>>8&255]^G[255&d]^e[40],n=L[l>>>24]^N[p>>>16&255]^q[d>>>8&255]^G[255&u]^e[41],c=L[p>>>24]^N[d>>>16&255]^q[u>>>8&255]^G[255&l]^e[42],i=L[d>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&p]^e[43],u=L[t>>>24]^N[n>>>16&255]^q[c>>>8&255]^G[255&i]^e[44],l=L[n>>>24]^N[c>>>16&255]^q[i>>>8&255]^G[255&t]^e[45],p=L[c>>>24]^N[i>>>16&255]^q[t>>>8&255]^G[255&n]^e[46],d=L[i>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&c]^e[47],h=48),o>12&&(t=L[u>>>24]^N[l>>>16&255]^q[p>>>8&255]^G[255&d]^e[48],n=L[l>>>24]^N[p>>>16&255]^q[d>>>8&255]^G[255&u]^e[49],c=L[p>>>24]^N[d>>>16&255]^q[u>>>8&255]^G[255&l]^e[50],i=L[d>>>24]^N[u>>>16&255]^q[l>>>8&255]^G[255&p]^e[51],u=L[t>>>24]^N[n>>>16&255]^q[c>>>8&255]^G[255&i]^e[52],l=L[n>>>24]^N[c>>>16&255]^q[i>>>8&255]^G[255&t]^e[53],p=L[c>>>24]^N[i>>>16&255]^q[t>>>8&255]^G[255&n]^e[54],d=L[i>>>24]^N[t>>>16&255]^q[n>>>8&255]^G[255&c]^e[55],h=56),r[0]=(T[u>>>24]<<24|T[l>>>16&255]<<16|T[p>>>8&255]<<8|T[255&d])^e[h],r[1]=(T[l>>>24]<<24|T[p>>>16&255]<<16|T[d>>>8&255]<<8|T[255&u])^e[h+1],r[2]=(T[p>>>24]<<24|T[d>>>16&255]<<16|T[u>>>8&255]<<8|T[255&l])^e[h+2],r[3]=(T[d>>>24]<<24|T[u>>>16&255]<<16|T[l>>>8&255]<<8|T[255&p])^e[h+3]}}function X(t){const n=function(){const t=new i(O),n=new i(16),e=new c(V),r=new u(e.buffer),s=new c(8);let a=0,f=0;return{update:w,digest:function(){const n=8*f,e=o.floor(n/4294967296),r=n>>>0;for(w(j,0,1);56!=a;)w(H,0,1);s[0]=e>>>24,s[1]=e>>>16,s[2]=e>>>8,s[3]=e,s[4]=r>>>24,s[5]=r>>>16,s[6]=r>>>8,s[7]=r,w(s,0,8);const i=new c(K),l=new u(i.buffer);for(let n=0;n<t.length;n++)l.setInt32(4*n,t[n]);return t.set(O),a=0,f=0,i}};function w(t,n,o){const c=n+o;if(f+=o,a){for(;n<c&&a<V;)e[a++]=t[n++];a==V&&(l(r,0),a=0)}if(n+V<=c){const e=new u(t.buffer,t.byteOffset,t.byteLength);for(;n+V<=c;n+=V)l(e,n)}for(;n<c;)e[a++]=t[n++]}function l(e,o){for(let t=0;t<16;t++)n[t]=e.getInt32(o+4*t);let r,c=t[0],s=t[1],a=t[2],i=t[3],f=t[4];for(let t=0;t<15;t+=5)f=(c<<5|c>>>27)+((a^i)&s^i)+f+1518500249+n[t]|0,s=s<<30|s>>>2,i=(f<<5|f>>>27)+((s^a)&c^a)+i+1518500249+n[t+1]|0,c=c<<30|c>>>2,a=(i<<5|i>>>27)+((c^s)&f^s)+a+1518500249+n[t+2]|0,f=f<<30|f>>>2,s=(a<<5|a>>>27)+((f^c)&i^c)+s+1518500249+n[t+3]|0,i=i<<30|i>>>2,c=(s<<5|s>>>27)+((i^f)&a^f)+c+1518500249+n[t+4]|0,a=a<<30|a>>>2;f=(c<<5|c>>>27)+((a^i)&s^i)+f+1518500249+n[15]|0,s=s<<30|s>>>2,r=n[13]^n[8]^n[2]^n[0],r=r<<1|r>>>31,n[0]=r,i=(f<<5|f>>>27)+((s^a)&c^a)+i+1518500249+r|0,c=c<<30|c>>>2,r=n[14]^n[9]^n[3]^n[1],r=r<<1|r>>>31,n[1]=r,a=(i<<5|i>>>27)+((c^s)&f^s)+a+1518500249+r|0,f=f<<30|f>>>2,r=n[15]^n[10]^n[4]^n[2],r=r<<1|r>>>31,n[2]=r,s=(a<<5|a>>>27)+((f^c)&i^c)+s+1518500249+r|0,i=i<<30|i>>>2,r=n[0]^n[11]^n[5]^n[3],r=r<<1|r>>>31,n[3]=r,c=(s<<5|s>>>27)+((i^f)&a^f)+c+1518500249+r|0,a=a<<30|a>>>2;for(let t=20;t<40;t+=5)r=n[t-3&15]^n[t-8&15]^n[t-14&15]^n[15&t],r=r<<1|r>>>31,n[15&t]=r,f=(c<<5|c>>>27)+(s^a^i)+f+1859775393+r|0,s=s<<30|s>>>2,r=n[t-2&15]^n[t-7&15]^n[t-13&15]^n[t+1&15],r=r<<1|r>>>31,n[t+1&15]=r,i=(f<<5|f>>>27)+(c^s^a)+i+1859775393+r|0,c=c<<30|c>>>2,r=n[t-1&15]^n[t-6&15]^n[t-12&15]^n[t+2&15],r=r<<1|r>>>31,n[t+2&15]=r,a=(i<<5|i>>>27)+(f^c^s)+a+1859775393+r|0,f=f<<30|f>>>2,r=n[15&t]^n[t-5&15]^n[t-11&15]^n[t+3&15],r=r<<1|r>>>31,n[t+3&15]=r,s=(a<<5|a>>>27)+(i^f^c)+s+1859775393+r|0,i=i<<30|i>>>2,r=n[t+1&15]^n[t-4&15]^n[t-10&15]^n[t+4&15],r=r<<1|r>>>31,n[t+4&15]=r,c=(s<<5|s>>>27)+(a^i^f)+c+1859775393+r|0,a=a<<30|a>>>2;for(let t=40;t<60;t+=5)r=n[t-3&15]^n[t-8&15]^n[t-14&15]^n[15&t],r=r<<1|r>>>31,n[15&t]=r,f=(c<<5|c>>>27)+(s&a|(s|a)&i)+f+2400959708+r|0,s=s<<30|s>>>2,r=n[t-2&15]^n[t-7&15]^n[t-13&15]^n[t+1&15],r=r<<1|r>>>31,n[t+1&15]=r,i=(f<<5|f>>>27)+(c&s|(c|s)&a)+i+2400959708+r|0,c=c<<30|c>>>2,r=n[t-1&15]^n[t-6&15]^n[t-12&15]^n[t+2&15],r=r<<1|r>>>31,n[t+2&15]=r,a=(i<<5|i>>>27)+(f&c|(f|c)&s)+a+2400959708+r|0,f=f<<30|f>>>2,r=n[15&t]^n[t-5&15]^n[t-11&15]^n[t+3&15],r=r<<1|r>>>31,n[t+3&15]=r,s=(a<<5|a>>>27)+(i&f|(i|f)&c)+s+2400959708+r|0,i=i<<30|i>>>2,r=n[t+1&15]^n[t-4&15]^n[t-10&15]^n[t+4&15],r=r<<1|r>>>31,n[t+4&15]=r,c=(s<<5|s>>>27)+(a&i|(a|i)&f)+c+2400959708+r|0,a=a<<30|a>>>2;for(let t=60;t<80;t+=5)r=n[t-3&15]^n[t-8&15]^n[t-14&15]^n[15&t],r=r<<1|r>>>31,n[15&t]=r,f=(c<<5|c>>>27)+(s^a^i)+f+3395469782+r|0,s=s<<30|s>>>2,r=n[t-2&15]^n[t-7&15]^n[t-13&15]^n[t+1&15],r=r<<1|r>>>31,n[t+1&15]=r,i=(f<<5|f>>>27)+(c^s^a)+i+3395469782+r|0,c=c<<30|c>>>2,r=n[t-1&15]^n[t-6&15]^n[t-12&15]^n[t+2&15],r=r<<1|r>>>31,n[t+2&15]=r,a=(i<<5|i>>>27)+(f^c^s)+a+3395469782+r|0,f=f<<30|f>>>2,r=n[15&t]^n[t-5&15]^n[t-11&15]^n[t+3&15],r=r<<1|r>>>31,n[t+3&15]=r,s=(a<<5|a>>>27)+(i^f^c)+s+3395469782+r|0,i=i<<30|i>>>2,r=n[t+1&15]^n[t-4&15]^n[t-10&15]^n[t+4&15],r=r<<1|r>>>31,n[t+4&15]=r,c=(s<<5|s>>>27)+(a^i^f)+c+3395469782+r|0,a=a<<30|a>>>2;t[0]=t[0]+c|0,t[1]=t[1]+s|0,t[2]=t[2]+a|0,t[3]=t[3]+i|0,t[4]=t[4]+f|0}}(),e=new c(V),r=new c(V);t.length>V&&(n.update(t,0,t.length),t=n.digest());for(let n=0;n<V;n++){const o=n<t.length?t[n]:0;e[n]=54^o,r[n]=92^o}return n.update(e,0,V),{update(t,e,o){n.update(t,e,o)},digest(){const t=n.digest();n.update(r,0,V),n.update(t,0,K);const o=n.digest();return n.update(e,0,V),o}}}function Y(t){return T[t>>>24]<<24|T[t>>>16&255]<<16|T[t>>>8&255]<<8|T[255&t]}function Z(t){return t<<24|(65280&t)<<8|t>>>8&65280|t>>>24}function $(t){return 255&(t<<1^27*(t>>7))}const _=typeof p!=b&&typeof p.getRandomValues==k,tt="Invalid password",nt="zipjs-abort-check-password";function et(t){if(_)return p.getRandomValues(t);throw new r("Crypto API not supported")}const ot={name:"PBKDF2"},rt=n.assign({hash:{name:"HMAC"}},ot),ct=n.assign({iterations:1e3,hash:{name:"SHA-1"}},ot),st=["deriveBits"],at=[8,12,16],it=[16,24,32],ft=10,ut=typeof p!=b,wt=ut&&p.subtle;let lt=ut&&typeof wt!=b&&typeof wt.importKey==k&&typeof wt.deriveBits==k,pt=Q;class dt extends h{constructor({password:t,rawPassword:n,encryptionStrength:e,checkPasswordOnly:o,checkAuthenticationCode:s=!0}){const a={};super({start(){yt(a,t,n,e)},async transform(t,n){const{password:e,strength:s,l:i,ready:f}=a;if(e?(await async function(t,n,e,o){const c=await vt(t,n,e,kt(o,0,at[n])),s=kt(o,at[n]);if(c[0]!=s[0]||c[1]!=s[1])throw gt(t),new r(tt)}(a,s,e,kt(t,0,at[s]+2)),t=kt(t,at[s]+2),o?(gt(a),n.error(new r(nt))):i()):await f,a.h)return;const u=new c(t.length-ft-(t.length-ft)%16);n.enqueue(St(a,t,u,0,ft,!0))},async flush(t){const{m:n,S:e,ready:o}=a;if(n){if(await o,a.h)return;const i=kt(e,e.length-ft),f=new c(kt(e,0,e.length-ft));n.process(f,!0);const u=n.digest();let w=e.length<ft?1:0;for(let t=0;t<ft;t++)w|=u[t]^i[t];if(w&&s)return void t.error(new r("Invalid authentication code"));t.enqueue(f)}}}),mt(this,a)}}class ht extends h{constructor({password:t,rawPassword:n,encryptionStrength:e}){const o={};super({start(){yt(o,t,n,e)},async transform(t,n){const{password:e,strength:r,l:s,ready:a}=o;let i=z;if(e?(i=await async function(t,n,e){const o=et(new c(at[n]));return U(o,await vt(t,n,e,o))}(o,r,e),s()):await a,o.h)return;const f=new c(i.length+t.length-t.length%16);f.set(i,0),n.enqueue(St(o,t,f,i.length,0,!1))},async flush(t){const{m:n,S:e,ready:r}=o;if(n){if(await r,o.h)return;const s=new c(e);n.process(s,!1);const a=kt(n.digest(),0,ft);t.enqueue(U(s,a))}}}),mt(this,o)}}function yt(t,e,o,r){n.assign(t,{ready:new w(n=>t.l=n),password:bt(e,o),strength:r-1,S:z,h:!1})}function mt(t,e){const o=t.readable.getReader(),r=new y({async pull(t){try{const{value:n,done:e}=await o.read();e?t.close():t.enqueue(n)}catch(t){throw gt(e),o.cancel(t).catch(()=>{}),t}},cancel:t=>(gt(e),o.cancel(t))});n.defineProperty(t,"readable",{get:()=>r})}function St(t,n,e,o,r,s){const{m:a,S:i}=t;i.length&&(n=U(i,n));const f=n.length-r,u=f-f%16;if(e=function(t,n){if(n&&n>t.length){const e=t;(t=new c(n)).set(e,0)}return t}(e,o+u),u){const t=kt(e,o,o+u);t.set(kt(n,0,u)),a.process(t,s)}return t.S=kt(n,u),e}function gt(t){const{m:n}=t;t.h=!0,n&&n.dispose&&n.dispose()}async function vt(t,e,r,s){t.password=null;const a=it[e],i=await async function(t,e,r){if(lt)try{const o=await wt.importKey("raw",t,rt,!1,st);return new c(await wt.deriveBits(n.assign({salt:e},ct),o,8*r))}catch{lt=!1}return function(t,n,e,r){const s=X(t),a=new c(r),i=new c(n.length+4),f=new u(i.buffer);i.set(n);for(let t=1,e=0;e<r;t++,e+=K){f.setUint32(n.length,t),s.update(i,0,i.length);let c=s.digest();const u=c.slice();for(let t=1;t<1e3;t++){s.update(c,0,K),c=s.digest();for(let t=0;t<K;t++)u[t]^=c[t]}a.set(u.subarray(0,o.min(K,r-e)),e)}return a}(t,e,0,r)}(r,s,2*a+2);return t.m=pt(kt(i,0,a),kt(i,a,2*a)),t.h&&gt(t),kt(i,2*a)}function bt(t,n){return n===v?function(t){if(typeof l==b){t=unescape(encodeURIComponent(t));const n=new c(t.length);for(let e=0;e<n.length;e++)n[e]=t.charCodeAt(e);return n}return(new l).encode(t)}(t):n}function kt(t,n,e){return t.subarray(n,e)}class zt extends h{constructor({password:t,rawPassword:n,passwordVerification:e,checkPasswordOnly:o}){super({start(){It(this,t,n,e)},transform(t,n){const e=this;if(e.password||e.rawPassword){const n=At(e,t.subarray(0,12));if(e.password=e.rawPassword=null,0!=(n[11]^e.passwordVerification))throw new r(tt);t=t.subarray(12)}o?n.error(new r(nt)):n.enqueue(At(e,t))}})}}class Ct extends h{constructor({password:t,rawPassword:n,passwordVerification:e}){super({start(){It(this,t,n,e)},transform(t,n){const e=this;let o,r;if(e.password||e.rawPassword){e.password=e.rawPassword=null;const n=et(new c(12));n[11]=e.passwordVerification,o=new c(t.length+n.length),o.set(Mt(e,n),0),r=12}else o=new c(t.length),r=0;o.set(Mt(e,t),r),n.enqueue(o)}})}}function It(t,e,o,r){n.assign(t,{password:e,rawPassword:o,passwordVerification:r}),function(t,e,o){const r=[305419896,591751049,878082192];if(n.assign(t,{v:r,C:new E(r[0]),I:new E(r[2])}),o)for(let n=0;n<o.length;n++)xt(t,o[n]);else for(let n=0;n<e.length;n++)xt(t,e.charCodeAt(n))}(t,e,o)}function At(t,n){const e=new c(n.length);for(let o=0;o<n.length;o++)e[o]=Pt(t)^n[o],xt(t,e[o]);return e}function Mt(t,n){const e=new c(n.length);for(let o=0;o<n.length;o++)e[o]=Pt(t)^n[o],xt(t,n[o]);return e}function xt(t,n){let[,e]=t.v;t.C.append([n]);const r=~t.C.get();e=Ft(o.imul(Ft(e+Dt(r)),134775813)+1),t.I.append([e>>>24]);const c=~t.I.get();t.v=[r,e,c]}function Pt(t){const n=2|t.v[2];return Dt(o.imul(n,1^n)>>>8)}function Dt(t){return 255&t}function Ft(t){return 4294967295&t}function Bt(t){if(t instanceof y)return t;const n=t.getReader();return new y({async pull(t){try{const{value:e,done:o}=await n.read();o?t.close():t.enqueue(e)}catch(t){throw n.cancel(t).catch(()=>{}),t}},cancel:t=>n.cancel(t)})}const Et=new f;function Rt(t){return Et.get(t)}const Ut="Invalid uncompressed size",Wt="Invalid CRC32",Vt="deflate-raw",Kt="gzip",jt=[31,139,8];class Ht extends h{constructor(t,{chunkSize:n,CompressionStreamFallback:e,CompressionStream:o}){super({});const{compressed:r,encrypted:c,useCompressionStream:s,zipCrypto:a,computeCrc32:i,level:f,deflate64:w,format:l,compressionMethod:p,inputSize:d}=t,h=this;let y,m,S,g=super.readable;const v=l&&Rt(l),b=Gt(s,o,e),k=i&&r&&!w&&!v&&(!c||a)&&Boolean(b);if(c&&!a||!i||k||(y=new R,g=Qt(g,y)),r)if(v)g=Xt(g,qt(v.CompressionStream,l,{level:f,chunkSize:n,compressionMethod:p,uncompressedSize:d}));else if(k)S=new Ot,g=Xt(g,new b(Kt,{level:f,chunkSize:n})),g=Qt(g,S);else try{g=Jt(g,s,{level:f,chunkSize:n},o,e)}catch(t){if(!s&&e)throw t;let n;try{n=new o(Kt)}catch{throw t}g=Xt(g,n),g=Qt(g,new Ot)}c&&(a?g=Qt(g,new Ct(t)):(m=new ht(t),g=Qt(g,m))),Nt(h,g,()=>{c&&!a||!i||(h.crc32=k?S.crc32:new u(y.value.buffer).getUint32(0))})}}class Ot extends h{constructor(){let t,n=10,e=new c(0);super({transform(t,r){if(n){const e=o.min(n,t.length);if(n-=e,!(t=t.subarray(e)).length)return}const c=e.length+t.length;if(c<=8)return void(e=U(e,t));const s=c-8,a=o.min(s,e.length);r.enqueue(U(e.subarray(0,a),t.subarray(0,s-a))),e=U(e.subarray(a),t.subarray(s-a))},flush(){const n=W(e);t.crc32=n.getUint32(0,!0),t.uncompressedSize=n.getUint32(4,!0)}}),t=this}}class Tt extends h{constructor(t,{chunkSize:n,DecompressionStreamFallback:e,DecompressionStream:o}){super({});const{zipCrypto:s,encrypted:a,checkCrc32:i,crc32:f,compressed:l,useCompressionStream:p,deflate64:d,format:h,compressionMethod:m,rawBitFlag:S,outputSize:g}=t;let b,k,z,C=super.readable;if(a&&(s?C=Qt(C,new zt(t)):(k=new dt(t),C=Qt(C,k))),l){const t=h&&Rt(h);if(t)C=Xt(C,qt(t.DecompressionStream,h,{chunkSize:n,compressionMethod:m,rawBitFlag:S,uncompressedSize:g}));else{let t;const s=Gt(p,o,e);if(i&&!d&&f!==v&&g!==v&&s)try{t=new s(Kt,{chunkSize:n})}catch{t=v}if(!t)try{C=Jt(C,p,{chunkSize:n,deflate64:d},o,e)}catch(n){if(d||g===v||!p&&e)throw n;try{t=new o(Kt)}catch{throw n}}t&&(z=!0,C=function(t,n,e,o){const s=n.writable.getWriter(),a=n.readable.getReader(),i=o===v?new E:v;let f,u,l=0,p=!1,d=!1,h=!1,m=0,S=!1;const g=new w((t,n)=>{f=t,u=n});return g.catch(()=>{}),async function(){const n=t.getReader();try{const t=new c(10);for(t.set(jt),await s.write(t);;){await s.ready;const{value:t,done:e}=await n.read();if(e)break;await s.write(t)}p=!0,i&&(S&&k(),await g);const r=new c(8),a=W(r);a.setUint32(0,i?i.get():o,!0),a.setUint32(4,e,!0),d=!0,await s.write(r),await s.close()}catch(t){await Yt(s,t),await Zt(n,t)}}(),new y({async pull(t){try{const{value:n,done:o}=await function(){m++,S=!0;const t=a.read();return t.then(b,b),p&&i&&k(),t}();if(o)t.close();else{if(l+=n.length,l>e)throw new r(Ut);i&&i.append(n),t.enqueue(n)}}catch(t){throw u(t),await Zt(a,t),d?function(t){const n=new r(l==e?Wt:Ut);return n.cause=t,n}(t):t}},cancel:t=>(u(t),a.cancel(t))});function b(){S=!1}async function k(){if(!h){h=!0;const t=m;await new w(t=>{const{port1:n,port2:e}=new MessageChannel;e.onmessage=()=>{n.close(),e.close(),t()},n.postMessage(v)}),h=!1,S&&(m==t?f():k())}}}(C,t,g,f))}C=function(t){const n=t.getReader();return new y({async pull(t){try{const{value:e,done:o}=await n.read();o?t.close():t.enqueue(e)}catch(t){if(await Zt(n,t),t&&t.message)throw t;const e=new r("Invalid compressed data");throw e.cause=t,e}},cancel:t=>n.cancel(t)})}(C)}i&&!z&&(b=new R,C=Qt(C,b)),Nt(this,C,()=>{if(b){const t=new u(b.value.buffer).getUint32(0,!1);if(f!=t)throw new r(Wt)}})}}const Lt=new f;function Nt(t,e,o){e=Qt(e,new h({flush:o})),n.defineProperty(t,"readable",{get:()=>e})}function qt(t,n,e){if(!t)throw new r("Compression method not supported");return new t(n,e)}function Gt(t,n,e){return t&&n?n:e&&e.requiresModule?e:void 0}function Jt(t,n,e,o,r){const c=n&&o?o:r||o,s=e.deflate64?"deflate64-raw":Vt;let a;try{a=new c(s,e)}catch(t){if(!n||!r||c==r)throw t;a=new r(s,e)}return Xt(t,a)}function Qt(t,n){return Bt(t).pipeThrough(n)}function Xt(t,n){const e=n.writable.getWriter(),o=t.getReader();return async function(){try{for(;;){await e.ready;const t=await o.read();if(t.done){await e.close();break}await e.write(t.value)}}catch(t){await Yt(e,t),await Zt(o,t)}}(),n.readable}async function Yt(t,n){try{await t.abort(n)}catch{}}async function Zt(t,n){try{await t.cancel(n)}catch{}}const $t="data",_t="deflate";class tn extends h{constructor(t,e){super({});const o=this,{codecType:c}=t;let s;c.startsWith(_t)?s=Ht:c.startsWith("inflate")&&(s=Tt),o.outputSize=0;let a=0;const i=new s(t,e),f=super.readable,u=new h({transform(t,n){t&&t.length&&(a+=t.length,n.enqueue(t))},flush(){n.assign(o,{inputSize:a})}}),w=new h({transform(n,e){if(n&&n.length&&(e.enqueue(n),o.outputSize+=n.length,t.outputSize!==v&&o.outputSize>t.outputSize))throw new r(Ut)},flush(){const{crc32:t}=i;n.assign(o,{crc32:t,inputSize:a})}});n.defineProperty(o,"readable",{get:()=>f.pipeThrough(u).pipeThrough(i).pipeThrough(w)})}}class nn extends h{constructor(t){const o=[];let r=0,s=0;function a(){const n=new c(t);let e=0;for(;e<t;){const r=o[0],c=t-e;r.length<=c?(n.set(r,e),e+=r.length,o.shift()):(n.set(r.subarray(0,c),e),o[0]=r.subarray(c),e+=c)}return r-=t,n}(!e.isFinite(t)||t<1)&&(t=65536),super({transform(n,e){for(o.push(n),r+=n.length;r>t;)s+=t,e.enqueue(a())},flush(t){r&&(s+=r,t.enqueue(function(t,n){const e=new c(n);let o=0;for(const n of t)e.set(n,o),o+=n.length;return e}(o,r)))}}),n.defineProperty(this,"outputSize",{get:()=>s})}}let en=2;try{typeof navigator!=b&&navigator.hardwareConcurrency&&(en=navigator.hardwareConcurrency)}catch{}function on(t){return Boolean(t)&&"object"==typeof t}const rn=new f,cn=new f,sn=function(){try{return structuredClone(new r)instanceof r}catch{return!1}}();let an=0;async function fn(t){let n,c,s;try{const{options:a,config:i}=t;if(a.format)try{await async function(t,n){!Et.has(t)&&n&&function(t,n){const{CompressionStream:e,DecompressionStream:o}=n;if(typeof e!=k&&typeof o!=k)throw new r("Invalid codec module");Et.set(t,{CompressionStream:e,DecompressionStream:o})}(t,await(import(n)))}(a.format,a.codecURI)}catch(t){if(on(t))try{t.codecImportFailed=!0}catch{}throw t}if(i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream,a.compressed&&!a.format)if(a.useCompressionStream){if(!function(t,n){if(!t)return!1;let e=Lt.get(t);e||(e=new f,Lt.set(t,e));let o=e.get(n);if(o===v){try{new t(n),o=!0}catch{o=!1}e.set(n,o)}return o}(a.codecType.startsWith(_t)?i.CompressionStream:i.DecompressionStream,Vt))try{await self.initModule(t.config)}catch{}}else try{await self.initModule(t.config)}catch{a.useCompressionStream=!0}if(a.encrypted&&!a.zipCrypto)try{await self.initModule(t.config)}catch{}!i.CompressionStreamFallback&&i.CompressionStreamZlib&&(i.CompressionStreamFallback=i.CompressionStreamZlib),!i.DecompressionStreamFallback&&i.DecompressionStreamZlib&&(i.DecompressionStreamFallback=i.DecompressionStreamZlib);const u={highWaterMark:1},l=t.readable?Bt(t.readable):new y({async pull(t){const n=new w(t=>rn.set(an,t));un({type:"pull",messageId:an}),an=(an+1)%e.MAX_SAFE_INTEGER;const{value:o,done:r}=await n;t.enqueue(o),r&&t.close()}},u);s=t.writable?function(t){if(t instanceof m)return t;const n=t.getWriter();return new m({write:t=>n.write(t),close:()=>n.close(),abort:t=>n.abort(t)})}(t.writable):new m({async write(t){let n;const o=new w(t=>n=t);cn.set(an,n),un({type:$t,value:t,messageId:an}),an=(an+1)%e.MAX_SAFE_INTEGER,await o}},u),n=new tn(a,i),c=new nn(function(t){return r="string"==typeof(n=r=t.chunkSize)&&n.trim()?e(n):n,e.isInteger(r)&&r>=1?o.max(r,64):65536;var n,r}(i)),await l.pipeThrough(n).pipeThrough(c).pipeTo(s,{preventClose:!0,preventAbort:!0}),await s.getWriter().close();const{crc32:p,inputSize:d,outputSize:h}=n;un({type:"close",result:{crc32:p,inputSize:d,outputSize:h}})}catch(t){const n=c?c.outputSize:0;if(on(t))try{t.outputSize=n}catch{}if(s&&!s.locked)try{await s.getWriter().close()}catch{}wn(t,n)}}function un(t){const{value:n}=t;if(n)if(n.length)try{t.value=(e=n,e.byteOffset||e.byteLength!=e.buffer.byteLength?new c(e):e).buffer,d(t,[t.value])}catch{d(t)}else d(t);else d(t);var e}function wn(t,n){const{message:e,stack:o,code:c,name:s,outputSize:a,cause:i,codecImportFailed:f}=function(t=new r("Unknown error")){return on(t)?t:new r(String(t))}(t),u={message:e,stack:o,code:c,name:s,outputSize:a===v?n:a};if(i&&(u.cause={name:i.name,message:i.message}),f&&(u.codecImportFailed=!0),sn)try{return void d({error:u,errorValue:{value:t}})}catch{}d({error:u})}addEventListener("message",({data:t})=>{const{type:n,messageId:e,value:o,done:r}=t;try{if("start"==n&&fn(t),n==$t){const t=rn.get(e);rn.delete(e),t({value:o||new c,done:r})}if("ack"==n){const t=cn.get(e);cn.delete(e),t()}}catch(t){wn(t)}}),d({type:"ready"});const ln="deflate",pn="deflate-raw",dn="deflate64-raw",hn="gzip";let yn,mn,Sn,gn,vn;function bn(t,n,e={}){if(!yn){const t=new r("WASM module not loaded");throw t.cause=vn,t}const s="number"==typeof e.level?e.level:-1,a="number"==typeof e.outBuffer?e.outBuffer:65536,i="number"==typeof e.inBufferSize?e.inBufferSize:65536,f={A:0,in:0,inBufferSize:0,M:0};let u,l,p,d,h=!0,S=!1;return function(){try{let e;if(f.A=mn(a),f.in=mn(i),f.inBufferSize=i,!f.A||!f.in)throw new r("allocation failed");if(t?(f.P=yn.deflate_process,f.D=yn.deflate_last_consumed,f.F=yn.deflate_end,f.M=yn.deflate_new(),e=n===hn?yn.deflate_init_gzip(f.M,s):n===pn?yn.deflate_init_raw(f.M,s):yn.deflate_init(f.M,s)):n===dn?(f.P=yn.inflate9_process,f.D=yn.inflate9_last_consumed,f.F=yn.inflate9_end,f.M=yn.inflate9_new(),e=yn.inflate9_init_raw(f.M)):(f.P=yn.inflate_process,f.D=yn.inflate_last_consumed,f.F=yn.inflate_end,f.M=yn.inflate_new(),e=n===pn?yn.inflate_init_raw(f.M):n===hn?yn.inflate_init_gzip(f.M):yn.inflate_init(f.M)),0!==e)throw new r("init failed:"+e)}catch(t){throw b(f),t}}(),{readable:new y({start(t){u=t},pull(){h=!1,v()},cancel(t){S=!0,d=t,b(f),l.error(t),v()}},{highWaterMark:0}),writable:new m({start(t){l=t},async write(t){if(h&&await new w(t=>p=t),S)throw d;try{!function(t){const n=new c(gn.buffer),e=f.P,s=f.D,i=f.A;let u=0;for(;u<t.length;){const c=o.min(t.length-u,32768);if((!f.in||f.inBufferSize<c)&&(f.in&&Sn&&(Sn(f.in),f.in=0),f.in=mn(c),f.inBufferSize=c,!f.in))throw new r("allocation failed");n.set(t.subarray(u,u+c),f.in);const w=e(f.M,f.in,c,i,a,0),l=w>>24&255,p=128&l?l-256:l;if(p<0)throw new r("process error:"+p);const d=16777215&w;d&&g(n.slice(i,i+d));const h=s(f.M);if(0===h&&0===d)break;u+=h}}(t)}catch(t){throw b(f),u.error(t),t}},close(){if(S)return;try{!function(){const t=new c(gn.buffer),n=f.P,e=f.A;for(;;){const o=n(f.M,0,0,e,a,4),c=o>>24&255,s=128&c?c-256:c;if(s<0)throw new r("process error:"+s);const i=16777215&o;if(i&&g(t.slice(e,e+i)),1===c||0===i)break}}()}catch(t){throw b(f),u.error(t),t}const t=b(f);if(0!==t){const n=new r("end error:"+t);throw u.error(n),n}u.close()},abort(t){b(f),u.error(t)}},{highWaterMark:1})};function g(t){h=!0,u.enqueue(t)}function v(){if(p){const t=p;p=null,t()}}function b(t){let n=0;return t.M&&t.F&&(n=t.F(t.M)),t.M=0,t.in&&Sn&&Sn(t.in),t.in=0,t.A&&Sn&&Sn(t.A),t.A=0,n}}class kn{constructor(t=ln,n){return bn(!0,t,n)}}class zn{constructor(t=ln,n){return bn(!1,t,n)}}kn.requiresModule=!0,zn.requiresModule=!0,kn.supportedFormats=[ln,pn,hn],zn.supportedFormats=[ln,pn,hn,dn];const Cn=65536;let In,An;function Mn(t){return new c(t.memory.buffer)}let xn=!1;!function(t={}){const{init:n,B:e}=t,o=t.CompressionStreamFallback||t.CompressionStreamZlib,r=t.DecompressionStreamFallback||t.DecompressionStreamZlib;e&&(pt=e||Q),self.initModule=async t=>{n&&await n(t),o&&(t.CompressionStreamFallback=o),r&&(t.DecompressionStreamFallback=r)}}({CompressionStreamFallback:kn,DecompressionStreamFallback:zn,B:function(t,n){const e=In;let o=e?function(t,n,e){An||(An=t.malloc(Cn));const o=An?t.aes_hmac_new():0;if(o){const r=Mn(t);if(r.set(n,An),r.set(e,An+n.length),t.aes_hmac_init(o,An,n.length,An+n.length,e.length))return t.aes_hmac_end(o,0),0}return o}(e,t,n):0;if(!o)return Q(t,n);const r=An;return{process(t,n){for(let c=0;c<t.length;c+=Cn){const s=t.subarray(c,c+Cn),a=Mn(e);a.set(s,r),e.aes_hmac_process(o,r,s.length,n?1:0),s.set(a.subarray(r,r+s.length))}},digest:()=>(e.aes_hmac_end(o,r),o=0,Mn(e).slice(r,r+20)),dispose(){o&&(e.aes_hmac_end(o,0),o=0)}}},init:t=>async function(t,{baseURI:n}){if(!xn)try{await async function(t,n){let e,o;try{try{o=new URL(t,n)}catch{}const r=await fetch(o);e=await r.arrayBuffer()}catch(n){if(!t.startsWith("data:application/wasm;base64,"))throw n;e=function(t){const n=t.split(",")[1],e=atob(n),o=e.length,r=new c(o);for(let t=0;t<o;++t)r[t]=e.charCodeAt(t);return r.buffer}(t)}const s=await WebAssembly.instantiate(e);var a;(function(t){if(yn=t,({malloc:mn,free:Sn,memory:gn}=yn),"function"!=typeof mn||"function"!=typeof Sn||!gn)throw yn=mn=Sn=gn=null,new r("Invalid WASM module")})(s.instance.exports),typeof(a=s.instance.exports).aes_hmac_new==k&&(In=a,An=0)}(t,n),xn=!0}catch(t){throw function(t){vn=t}(t),t}}(t.wasmURI,t)})});\n';if("string"==typeof r&&(r=(new TextEncoder).encode(r)),t){const t=new Blob([r],{type:e});return URL.createObjectURL(t)}return "data:"+e+";base64,"+function(t){let e="";const r=t.length;let o=0;for(;o+2<r;o+=3){const r=t[o]<<16|t[o+1]<<8|t[o+2];e+=n$1[r>>18&63]+n$1[r>>12&63]+n$1[r>>6&63]+n$1[63&r];}const s=r-o;if(1===s){const r=t[o]<<16;e+=n$1[r>>18&63]+n$1[r>>12&63]+"==";}else if(2===s){const r=t[o]<<16|t[o+1]<<8;e+=n$1[r>>18&63]+n$1[r>>12&63]+n$1[r>>6&63]+"=";}return e}(r)}});
449
449
 
450
450
  /*
451
451
  Copyright (c) 2026 Gildas Lormeau. All rights reserved.
@@ -1285,12 +1285,12 @@
1285
1285
  class AESDecryptionStream extends TransformStream {
1286
1286
 
1287
1287
  constructor({ password, rawPassword, encryptionStrength, checkPasswordOnly, checkAuthenticationCode = true }) {
1288
+ const aesCrypto = {};
1288
1289
  super({
1289
1290
  start() {
1290
- initAesCrypto(this, password, rawPassword, encryptionStrength);
1291
+ initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength);
1291
1292
  },
1292
1293
  async transform(chunk, controller) {
1293
- const aesCrypto = this;
1294
1294
  const {
1295
1295
  password,
1296
1296
  strength,
@@ -1309,6 +1309,9 @@
1309
1309
  } else {
1310
1310
  await ready;
1311
1311
  }
1312
+ if (aesCrypto.discarded) {
1313
+ return;
1314
+ }
1312
1315
  const output = new Uint8Array(chunk.length - AUTHENTICATION_CODE_LENGTH - ((chunk.length - AUTHENTICATION_CODE_LENGTH) % BLOCK_LENGTH));
1313
1316
  controller.enqueue(append(aesCrypto, chunk, output, 0, AUTHENTICATION_CODE_LENGTH, true));
1314
1317
  },
@@ -1317,9 +1320,12 @@
1317
1320
  engine,
1318
1321
  pendingInput,
1319
1322
  ready
1320
- } = this;
1323
+ } = aesCrypto;
1321
1324
  if (engine) {
1322
1325
  await ready;
1326
+ if (aesCrypto.discarded) {
1327
+ return;
1328
+ }
1323
1329
  const originalAuthenticationCode = subarray(pendingInput, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
1324
1330
  const decryptedChunkArray = new Uint8Array(subarray(pendingInput, 0, pendingInput.length - AUTHENTICATION_CODE_LENGTH));
1325
1331
  engine.process(decryptedChunkArray, true);
@@ -1329,27 +1335,26 @@
1329
1335
  invalidAuthenticationCode |= authenticationCode[indexByte] ^ originalAuthenticationCode[indexByte];
1330
1336
  }
1331
1337
  if (invalidAuthenticationCode && checkAuthenticationCode) {
1332
- throw new Error(ERR_INVALID_AUTHENTICATION_CODE);
1338
+ controller.error(new Error(ERR_INVALID_AUTHENTICATION_CODE));
1339
+ return;
1333
1340
  }
1334
1341
  controller.enqueue(decryptedChunkArray);
1335
1342
  }
1336
- },
1337
- cancel() {
1338
- disposeEngine(this);
1339
1343
  }
1340
1344
  });
1345
+ setDisposingReadable(this, aesCrypto);
1341
1346
  }
1342
1347
  }
1343
1348
 
1344
1349
  class AESEncryptionStream extends TransformStream {
1345
1350
 
1346
1351
  constructor({ password, rawPassword, encryptionStrength }) {
1352
+ const aesCrypto = {};
1347
1353
  super({
1348
1354
  start() {
1349
- initAesCrypto(this, password, rawPassword, encryptionStrength);
1355
+ initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength);
1350
1356
  },
1351
1357
  async transform(chunk, controller) {
1352
- const aesCrypto = this;
1353
1358
  const {
1354
1359
  password,
1355
1360
  strength,
@@ -1363,6 +1368,9 @@
1363
1368
  } else {
1364
1369
  await ready;
1365
1370
  }
1371
+ if (aesCrypto.discarded) {
1372
+ return;
1373
+ }
1366
1374
  const output = new Uint8Array(preamble.length + chunk.length - (chunk.length % BLOCK_LENGTH));
1367
1375
  output.set(preamble, 0);
1368
1376
  controller.enqueue(append(aesCrypto, chunk, output, preamble.length, 0, false));
@@ -1372,19 +1380,20 @@
1372
1380
  engine,
1373
1381
  pendingInput,
1374
1382
  ready
1375
- } = this;
1383
+ } = aesCrypto;
1376
1384
  if (engine) {
1377
1385
  await ready;
1386
+ if (aesCrypto.discarded) {
1387
+ return;
1388
+ }
1378
1389
  const encryptedChunkArray = new Uint8Array(pendingInput);
1379
1390
  engine.process(encryptedChunkArray, false);
1380
1391
  const authenticationCode = subarray(engine.digest(), 0, AUTHENTICATION_CODE_LENGTH);
1381
1392
  controller.enqueue(concat(encryptedChunkArray, authenticationCode));
1382
1393
  }
1383
- },
1384
- cancel() {
1385
- disposeEngine(this);
1386
1394
  }
1387
1395
  });
1396
+ setDisposingReadable(this, aesCrypto);
1388
1397
  }
1389
1398
  }
1390
1399
 
@@ -1397,7 +1406,37 @@
1397
1406
  ready: new Promise(resolve => aesCrypto.resolveReady = resolve),
1398
1407
  password: encodePassword(password, rawPassword),
1399
1408
  strength: encryptionStrength - 1,
1400
- pendingInput: EMPTY_UINT8_ARRAY
1409
+ pendingInput: EMPTY_UINT8_ARRAY,
1410
+ discarded: false
1411
+ });
1412
+ }
1413
+
1414
+ function setDisposingReadable(stream, aesCrypto) {
1415
+ const reader = stream.readable.getReader();
1416
+ const readable = new ReadableStream({
1417
+ async pull(controller) {
1418
+ try {
1419
+ const { value, done } = await reader.read();
1420
+ if (done) {
1421
+ controller.close();
1422
+ } else {
1423
+ controller.enqueue(value);
1424
+ }
1425
+ } catch (error) {
1426
+ disposeEngine(aesCrypto);
1427
+ reader.cancel(error).catch(() => { });
1428
+ throw error;
1429
+ }
1430
+ },
1431
+ cancel(reason) {
1432
+ disposeEngine(aesCrypto);
1433
+ return reader.cancel(reason);
1434
+ }
1435
+ });
1436
+ Object.defineProperty(stream, "readable", {
1437
+ get() {
1438
+ return readable;
1439
+ }
1401
1440
  });
1402
1441
  }
1403
1442
 
@@ -1430,7 +1469,9 @@
1430
1469
  }
1431
1470
  }
1432
1471
 
1433
- function disposeEngine({ engine }) {
1472
+ function disposeEngine(aesCrypto) {
1473
+ const { engine } = aesCrypto;
1474
+ aesCrypto.discarded = true;
1434
1475
  if (engine && engine.dispose) {
1435
1476
  engine.dispose();
1436
1477
  }
@@ -1447,6 +1488,9 @@
1447
1488
  const keyLength = KEY_LENGTH[strength];
1448
1489
  const compositeKey = await deriveKey(password, salt, keyLength * 2 + PASSWORD_VERIFICATION_LENGTH);
1449
1490
  aesCrypto.engine = createEngine$1(subarray(compositeKey, 0, keyLength), subarray(compositeKey, keyLength, keyLength * 2));
1491
+ if (aesCrypto.discarded) {
1492
+ disposeEngine(aesCrypto);
1493
+ }
1450
1494
  return subarray(compositeKey, keyLength * 2);
1451
1495
  }
1452
1496
 
@@ -1598,11 +1642,11 @@
1598
1642
  }
1599
1643
 
1600
1644
  function createKeys(target, password, rawPassword) {
1601
- const keys = [0x12345678, 0x23456789, 0x34567890];
1645
+ const cryptoKeys = [0x12345678, 0x23456789, 0x34567890];
1602
1646
  Object.assign(target, {
1603
- keys,
1604
- crcKey0: new Crc32(keys[0]),
1605
- crcKey2: new Crc32(keys[2])
1647
+ cryptoKeys,
1648
+ crcKey0: new Crc32(cryptoKeys[0]),
1649
+ crcKey2: new Crc32(cryptoKeys[2])
1606
1650
  });
1607
1651
  if (rawPassword) {
1608
1652
  for (let index = 0; index < rawPassword.length; index++) {
@@ -1616,17 +1660,17 @@
1616
1660
  }
1617
1661
 
1618
1662
  function updateKeys(target, byte) {
1619
- let [, key1] = target.keys;
1663
+ let [, key1] = target.cryptoKeys;
1620
1664
  target.crcKey0.append([byte]);
1621
1665
  const key0 = ~target.crcKey0.get();
1622
1666
  key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
1623
1667
  target.crcKey2.append([key1 >>> 24]);
1624
1668
  const key2 = ~target.crcKey2.get();
1625
- target.keys = [key0, key1, key2];
1669
+ target.cryptoKeys = [key0, key1, key2];
1626
1670
  }
1627
1671
 
1628
1672
  function getByte(target) {
1629
- const temp = target.keys[2] | 2;
1673
+ const temp = target.cryptoKeys[2] | 2;
1630
1674
  return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
1631
1675
  }
1632
1676
 
@@ -1674,11 +1718,16 @@
1674
1718
  const reader = readable.getReader();
1675
1719
  return new ReadableStream({
1676
1720
  async pull(controller) {
1677
- const { value, done } = await reader.read();
1678
- if (done) {
1679
- controller.close();
1680
- } else {
1681
- controller.enqueue(value);
1721
+ try {
1722
+ const { value, done } = await reader.read();
1723
+ if (done) {
1724
+ controller.close();
1725
+ } else {
1726
+ controller.enqueue(value);
1727
+ }
1728
+ } catch (error) {
1729
+ reader.cancel(error).catch(() => { });
1730
+ throw error;
1682
1731
  }
1683
1732
  },
1684
1733
  cancel(reason) {
@@ -1864,7 +1913,6 @@
1864
1913
  const GZIP_HEADER_LENGTH = 10;
1865
1914
  const GZIP_TRAILER_LENGTH = 8;
1866
1915
  const GZIP_HEADER_BYTES = [0x1f, 0x8b, 0x08];
1867
- const GZIP_OUTPUT_STALL_TIMEOUT = 5000;
1868
1916
 
1869
1917
  class DeflateStream extends TransformStream {
1870
1918
 
@@ -1875,7 +1923,7 @@
1875
1923
  let crc32Stream, encryptionStream, gzipCrc32Stream;
1876
1924
  let readable = super.readable;
1877
1925
  const codecStreams = format && getCodecStreams(format);
1878
- const GzipCompressionStream = getGzipCompressionStream(useCompressionStream, CompressionStream, CompressionStreamFallback);
1926
+ const GzipCompressionStream = getGzipCodecStream(useCompressionStream, CompressionStream, CompressionStreamFallback);
1879
1927
  const useGzipCrc32 = computeCrc32 && compressed && !deflate64 && !codecStreams && (!encrypted || zipCrypto) && Boolean(GzipCompressionStream);
1880
1928
  if ((!encrypted || zipCrypto) && computeCrc32 && !useGzipCrc32) {
1881
1929
  crc32Stream = new Crc32Stream();
@@ -1892,6 +1940,9 @@
1892
1940
  try {
1893
1941
  readable = pipeThroughCompressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStream, CompressionStreamFallback);
1894
1942
  } catch (error) {
1943
+ if (!useCompressionStream && CompressionStreamFallback) {
1944
+ throw error;
1945
+ }
1895
1946
  let gzipStream;
1896
1947
  try {
1897
1948
  gzipStream = new CompressionStream(FORMAT_GZIP$1);
@@ -1961,74 +2012,134 @@
1961
2012
  }
1962
2013
 
1963
2014
  function pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, crc32) {
2015
+ const writer = gzipStream.writable.getWriter();
2016
+ const reader = gzipStream.readable.getReader();
2017
+ const outputCrc32 = crc32 === UNDEFINED_VALUE ? new Crc32() : UNDEFINED_VALUE;
1964
2018
  let outputLength = 0;
1965
2019
  let inputDone = false;
1966
- let watchdogTimeout;
2020
+ let trailerWritten = false;
2021
+ let idleCheckArmed = false;
2022
+ let readCount = 0;
2023
+ let readPending = false;
1967
2024
  let resolveTrailerReady, rejectTrailerReady;
1968
2025
  const trailerReady = new Promise((resolve, reject) => {
1969
2026
  resolveTrailerReady = resolve;
1970
2027
  rejectTrailerReady = reject;
1971
2028
  });
1972
2029
  trailerReady.catch(() => { });
1973
- if (!outputSize) {
1974
- resolveTrailerReady();
1975
- }
1976
- const gzipWrapStream = new TransformStream({
1977
- start(controller) {
2030
+ pump();
2031
+ return new ReadableStream({
2032
+ async pull(controller) {
2033
+ try {
2034
+ const { value, done } = await read();
2035
+ if (done) {
2036
+ controller.close();
2037
+ } else {
2038
+ outputLength += value.length;
2039
+ if (outputLength > outputSize) {
2040
+ throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
2041
+ }
2042
+ if (outputCrc32) {
2043
+ outputCrc32.append(value);
2044
+ }
2045
+ controller.enqueue(value);
2046
+ }
2047
+ } catch (error) {
2048
+ rejectTrailerReady(error);
2049
+ await cancel(reader, error);
2050
+ throw trailerWritten ? getTrailerError(error) : error;
2051
+ }
2052
+ },
2053
+ cancel(reason) {
2054
+ rejectTrailerReady(reason);
2055
+ return reader.cancel(reason);
2056
+ }
2057
+ });
2058
+
2059
+ async function pump() {
2060
+ const inputReader = readable.getReader();
2061
+ try {
1978
2062
  const header = new Uint8Array(GZIP_HEADER_LENGTH);
1979
2063
  header.set(GZIP_HEADER_BYTES);
1980
- controller.enqueue(header);
1981
- },
1982
- transform(chunk, controller) {
1983
- controller.enqueue(chunk);
1984
- },
1985
- async flush(controller) {
2064
+ await writer.write(header);
2065
+ for (; ;) {
2066
+ await writer.ready;
2067
+ const { value, done } = await inputReader.read();
2068
+ if (done) {
2069
+ break;
2070
+ }
2071
+ await writer.write(value);
2072
+ }
1986
2073
  inputDone = true;
1987
- startWatchdog();
1988
- try {
2074
+ if (outputCrc32) {
2075
+ if (readPending) {
2076
+ armIdleCheck();
2077
+ }
1989
2078
  await trailerReady;
1990
- } finally {
1991
- stopWatchdog();
1992
2079
  }
1993
2080
  const trailer = new Uint8Array(GZIP_TRAILER_LENGTH);
1994
2081
  const dataView = getDataView(trailer);
1995
- dataView.setUint32(0, crc32.get(), true);
2082
+ dataView.setUint32(0, outputCrc32 ? outputCrc32.get() : crc32, true);
1996
2083
  dataView.setUint32(4, outputSize, true);
1997
- controller.enqueue(trailer);
1998
- },
1999
- cancel(reason) {
2000
- rejectTrailerReady(reason);
2084
+ trailerWritten = true;
2085
+ await writer.write(trailer);
2086
+ await writer.close();
2087
+ } catch (error) {
2088
+ await abort(writer, error);
2089
+ await cancel(inputReader, error);
2001
2090
  }
2002
- });
2003
- const outputStream = new TransformStream({
2004
- transform(chunk, controller) {
2005
- crc32.append(chunk);
2006
- outputLength += chunk.length;
2007
- if (outputLength >= outputSize) {
2008
- resolveTrailerReady();
2009
- } else if (inputDone) {
2010
- startWatchdog();
2011
- }
2012
- controller.enqueue(chunk);
2013
- },
2014
- cancel(reason) {
2015
- rejectTrailerReady(reason);
2091
+ }
2092
+
2093
+ function read() {
2094
+ readCount++;
2095
+ readPending = true;
2096
+ const result = reader.read();
2097
+ result.then(onReadSettled, onReadSettled);
2098
+ if (inputDone && outputCrc32) {
2099
+ armIdleCheck();
2016
2100
  }
2017
- });
2018
- readable = pipeThrough(readable, gzipWrapStream);
2019
- readable = pipeThroughBackpressured(readable, gzipStream);
2020
- return pipeThrough(readable, outputStream);
2101
+ return result;
2102
+ }
2103
+
2104
+ function onReadSettled() {
2105
+ readPending = false;
2106
+ }
2021
2107
 
2022
- function startWatchdog() {
2023
- stopWatchdog();
2024
- watchdogTimeout = setTimeout(() => rejectTrailerReady(new Error(ERR_INVALID_UNCOMPRESSED_SIZE)), GZIP_OUTPUT_STALL_TIMEOUT);
2108
+ async function armIdleCheck() {
2109
+ if (!idleCheckArmed) {
2110
+ idleCheckArmed = true;
2111
+ const count = readCount;
2112
+ await nextTask();
2113
+ idleCheckArmed = false;
2114
+ if (readPending) {
2115
+ if (readCount == count) {
2116
+ resolveTrailerReady();
2117
+ } else {
2118
+ armIdleCheck();
2119
+ }
2120
+ }
2121
+ }
2025
2122
  }
2026
2123
 
2027
- function stopWatchdog() {
2028
- clearTimeout(watchdogTimeout);
2124
+ function getTrailerError(error) {
2125
+ const trailerError = new Error(outputLength == outputSize ? ERR_INVALID_CRC32 : ERR_INVALID_UNCOMPRESSED_SIZE);
2126
+ trailerError.cause = error;
2127
+ return trailerError;
2029
2128
  }
2030
2129
  }
2031
2130
 
2131
+ function nextTask() {
2132
+ return new Promise(resolve => {
2133
+ const { port1, port2 } = new MessageChannel();
2134
+ port2.onmessage = () => {
2135
+ port1.close();
2136
+ port2.close();
2137
+ resolve();
2138
+ };
2139
+ port1.postMessage(UNDEFINED_VALUE);
2140
+ });
2141
+ }
2142
+
2032
2143
  class InflateStream extends TransformStream {
2033
2144
 
2034
2145
  constructor(options, { chunkSize, DecompressionStreamFallback, DecompressionStream }) {
@@ -2049,20 +2160,32 @@
2049
2160
  if (codecStreams) {
2050
2161
  readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize, compressionMethod, rawBitFlag, uncompressedSize: outputSize }));
2051
2162
  } else {
2052
- try {
2053
- readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamFallback);
2054
- } catch (error) {
2055
- if (deflate64 || outputSize === UNDEFINED_VALUE) {
2056
- throw error;
2057
- }
2058
- let gzipStream;
2163
+ let gzipStream;
2164
+ const GzipDecompressionStream = getGzipCodecStream(useCompressionStream, DecompressionStream, DecompressionStreamFallback);
2165
+ if (checkCrc32 && !deflate64 && crc32 !== UNDEFINED_VALUE && outputSize !== UNDEFINED_VALUE && GzipDecompressionStream) {
2059
2166
  try {
2060
- gzipStream = new DecompressionStream(FORMAT_GZIP$1);
2167
+ gzipStream = new GzipDecompressionStream(FORMAT_GZIP$1, { chunkSize });
2061
2168
  } catch {
2062
- throw error;
2169
+ gzipStream = UNDEFINED_VALUE;
2170
+ }
2171
+ }
2172
+ if (!gzipStream) {
2173
+ try {
2174
+ readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamFallback);
2175
+ } catch (error) {
2176
+ if (deflate64 || outputSize === UNDEFINED_VALUE || (!useCompressionStream && DecompressionStreamFallback)) {
2177
+ throw error;
2178
+ }
2179
+ try {
2180
+ gzipStream = new DecompressionStream(FORMAT_GZIP$1);
2181
+ } catch {
2182
+ throw error;
2183
+ }
2063
2184
  }
2064
- gzipCrc32 = new Crc32();
2065
- readable = pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, gzipCrc32);
2185
+ }
2186
+ if (gzipStream) {
2187
+ gzipCrc32 = true;
2188
+ readable = pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, crc32);
2066
2189
  }
2067
2190
  }
2068
2191
  readable = mapInflateStreamError(readable);
@@ -2072,8 +2195,8 @@
2072
2195
  readable = pipeThrough(readable, crc32Stream);
2073
2196
  }
2074
2197
  setReadable(this, readable, () => {
2075
- if (checkCrc32) {
2076
- const computedCrc32 = gzipCrc32 ? gzipCrc32.get() >>> 0 : new DataView(crc32Stream.value.buffer).getUint32(0, false);
2198
+ if (crc32Stream) {
2199
+ const computedCrc32 = new DataView(crc32Stream.value.buffer).getUint32(0, false);
2077
2200
  if (crc32 != computedCrc32) {
2078
2201
  throw new Error(ERR_INVALID_CRC32);
2079
2202
  }
@@ -2130,11 +2253,11 @@
2130
2253
  return new CodecStreamClass(format, options);
2131
2254
  }
2132
2255
 
2133
- function getGzipCompressionStream(useCompressionStream, CompressionStreamNative, CompressionStreamFallback) {
2134
- if (useCompressionStream && CompressionStreamNative) {
2135
- return CompressionStreamNative;
2136
- } else if (CompressionStreamFallback && CompressionStreamFallback.requiresModule) {
2137
- return CompressionStreamFallback;
2256
+ function getGzipCodecStream(useCompressionStream, CodecStreamNative, CodecStreamFallback) {
2257
+ if (useCompressionStream && CodecStreamNative) {
2258
+ return CodecStreamNative;
2259
+ } else if (CodecStreamFallback && CodecStreamFallback.requiresModule) {
2260
+ return CodecStreamFallback;
2138
2261
  }
2139
2262
  }
2140
2263
 
@@ -2204,10 +2327,15 @@
2204
2327
  const reader = readable.getReader();
2205
2328
  return new ReadableStream({
2206
2329
  async pull(controller) {
2207
- let result;
2208
2330
  try {
2209
- result = await reader.read();
2331
+ const { value, done } = await reader.read();
2332
+ if (done) {
2333
+ controller.close();
2334
+ } else {
2335
+ controller.enqueue(value);
2336
+ }
2210
2337
  } catch (error) {
2338
+ await cancel(reader, error);
2211
2339
  if (error && error.message) {
2212
2340
  throw error;
2213
2341
  }
@@ -2215,12 +2343,6 @@
2215
2343
  mappedError.cause = error;
2216
2344
  throw mappedError;
2217
2345
  }
2218
- const { value, done } = result;
2219
- if (done) {
2220
- controller.close();
2221
- } else {
2222
- controller.enqueue(value);
2223
- }
2224
2346
  },
2225
2347
  cancel(reason) {
2226
2348
  return reader.cancel(reason);
@@ -3736,10 +3858,11 @@
3736
3858
 
3737
3859
  createReadable(options) {
3738
3860
  const reader = this;
3739
- const { useRangeHeader, forceRangeRequests, size } = reader;
3861
+ const { useRangeHeader, forceRangeRequests, size, eocdCache } = reader;
3740
3862
  if ((useRangeHeader || forceRangeRequests) && size !== UNDEFINED_VALUE) {
3741
3863
  const { offset = 0, size: readSize = size - offset } = options || {};
3742
- if (readSize > 0 && offset < size) {
3864
+ const cached = eocdCache && offset >= size - eocdCache.length;
3865
+ if (readSize > 0 && offset < size && !cached) {
3743
3866
  return createRangeReadable(reader, offset, Math.min(readSize, size - offset));
3744
3867
  }
3745
3868
  }
@@ -5298,8 +5421,8 @@
5298
5421
  const passThroughCompression = Boolean(passThrough);
5299
5422
  const passThroughEncryption = passThrough === true;
5300
5423
  checkPasswordOption(password, rawPassword);
5301
- password = password && password.length && password;
5302
- rawPassword = rawPassword && rawPassword.length && rawPassword;
5424
+ password = password && password.length ? password : UNDEFINED_VALUE;
5425
+ rawPassword = rawPassword && rawPassword.length ? rawPassword : UNDEFINED_VALUE;
5303
5426
  if (extraFieldAES) {
5304
5427
  if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
5305
5428
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
@@ -6060,7 +6183,7 @@
6060
6183
  async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDataSize) {
6061
6184
  const { size } = reader;
6062
6185
  const anchoredLength = Math.min(size, END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS);
6063
- const remoteProbeBudget = { count: MAX_END_OF_CENTRAL_DIR_PROBES };
6186
+ const remoteProbeBudget = { remaining: MAX_END_OF_CENTRAL_DIR_PROBES };
6064
6187
  let endOfDirectoryInfo;
6065
6188
  let plausibleEndOfDirectoryInfo;
6066
6189
  let endOfDirectoryReachingEndCount = 0;
@@ -6153,8 +6276,8 @@
6153
6276
  if (signatureOffset >= anchoredOffset) {
6154
6277
  return getUint32$1(view, signatureOffset - anchoredOffset);
6155
6278
  }
6156
- if (remoteProbeBudget.count > 0) {
6157
- remoteProbeBudget.count--;
6279
+ if (remoteProbeBudget.remaining > 0) {
6280
+ remoteProbeBudget.remaining--;
6158
6281
  const signatureArray = await readUint8Array(reader, signatureOffset, 4);
6159
6282
  return getUint32$1(getDataView(signatureArray), 0);
6160
6283
  }
@@ -7070,9 +7193,11 @@
7070
7193
  const passThrough = checkPassThroughOption(getOptionValue(zipWriter, options, OPTION_PASS_THROUGH));
7071
7194
  const passThroughCompression = Boolean(passThrough);
7072
7195
  const passThroughEncryption = passThrough === true;
7073
- const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
7074
- const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
7196
+ let password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
7197
+ let rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
7075
7198
  checkPasswordOption(password, rawPassword);
7199
+ password = password && password.length ? password : UNDEFINED_VALUE;
7200
+ rawPassword = rawPassword && rawPassword.length ? rawPassword : UNDEFINED_VALUE;
7076
7201
  const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
7077
7202
  const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
7078
7203
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
@@ -8868,7 +8993,7 @@
8868
8993
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8869
8994
  */
8870
8995
 
8871
- const VERSION = "2.15.0";
8996
+ const VERSION = "2.16.1";
8872
8997
 
8873
8998
  /*
8874
8999
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9347,7 +9472,7 @@
9347
9472
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9348
9473
  */
9349
9474
 
9350
- /* global TransformStream */
9475
+ /* global ReadableStream, WritableStream */
9351
9476
 
9352
9477
  const FORMAT_DEFLATE = "deflate";
9353
9478
  const FORMAT_DEFLATE_RAW = "deflate-raw";
@@ -9382,137 +9507,195 @@
9382
9507
  const level = (typeof options.level === "number") ? options.level : -1;
9383
9508
  const outBufferSize = (typeof options.outBuffer === "number") ? options.outBuffer : 64 * 1024;
9384
9509
  const inBufferSize = (typeof options.inBufferSize === "number") ? options.inBufferSize : 64 * 1024;
9385
-
9386
- return new TransformStream({
9387
- start() {
9510
+ const state = { out: 0, in: 0, inBufferSize: 0, streamHandle: 0 };
9511
+ let readableController, writableController, resolveWrite, cancelReason;
9512
+ let backpressure = true;
9513
+ let cancelled = false;
9514
+ initStream();
9515
+ const readable = new ReadableStream({
9516
+ start(controller) {
9517
+ readableController = controller;
9518
+ },
9519
+ pull() {
9520
+ backpressure = false;
9521
+ resumeWrite();
9522
+ },
9523
+ cancel(reason) {
9524
+ cancelled = true;
9525
+ cancelReason = reason;
9526
+ disposeStream(state);
9527
+ writableController.error(reason);
9528
+ resumeWrite();
9529
+ }
9530
+ }, { highWaterMark: 0 });
9531
+ const writable = new WritableStream({
9532
+ start(controller) {
9533
+ writableController = controller;
9534
+ },
9535
+ async write(chunk) {
9536
+ if (backpressure) {
9537
+ await new Promise(resolve => resolveWrite = resolve);
9538
+ }
9539
+ if (cancelled) {
9540
+ throw cancelReason;
9541
+ }
9388
9542
  try {
9389
- let result;
9390
- this.out = malloc(outBufferSize);
9391
- this.in = malloc(inBufferSize);
9392
- this.inBufferSize = inBufferSize;
9393
- if (!this.out || !this.in) {
9394
- throw new Error("allocation failed");
9395
- }
9396
- if (isCompress) {
9397
- this._process = wasm$1.deflate_process;
9398
- this._last_consumed = wasm$1.deflate_last_consumed;
9399
- this._end = wasm$1.deflate_end;
9400
- this.streamHandle = wasm$1.deflate_new();
9401
- if (type === FORMAT_GZIP) {
9402
- result = wasm$1.deflate_init_gzip(this.streamHandle, level);
9403
- } else if (type === FORMAT_DEFLATE_RAW) {
9404
- result = wasm$1.deflate_init_raw(this.streamHandle, level);
9405
- } else {
9406
- result = wasm$1.deflate_init(this.streamHandle, level);
9407
- }
9408
- } else {
9409
- if (type === FORMAT_DEFLATE64_RAW) {
9410
- this._process = wasm$1.inflate9_process;
9411
- this._last_consumed = wasm$1.inflate9_last_consumed;
9412
- this._end = wasm$1.inflate9_end;
9413
- this.streamHandle = wasm$1.inflate9_new();
9414
- result = wasm$1.inflate9_init_raw(this.streamHandle);
9415
- } else {
9416
- this._process = wasm$1.inflate_process;
9417
- this._last_consumed = wasm$1.inflate_last_consumed;
9418
- this._end = wasm$1.inflate_end;
9419
- this.streamHandle = wasm$1.inflate_new();
9420
- if (type === FORMAT_DEFLATE_RAW) {
9421
- result = wasm$1.inflate_init_raw(this.streamHandle);
9422
- } else if (type === FORMAT_GZIP) {
9423
- result = wasm$1.inflate_init_gzip(this.streamHandle);
9424
- } else {
9425
- result = wasm$1.inflate_init(this.streamHandle);
9426
- }
9427
- }
9428
- }
9429
- if (result !== 0) {
9430
- throw new Error("init failed:" + result);
9431
- }
9543
+ processChunk(chunk);
9432
9544
  } catch (error) {
9433
- disposeStream(this);
9545
+ disposeStream(state);
9546
+ readableController.error(error);
9434
9547
  throw error;
9435
9548
  }
9436
9549
  },
9437
- transform(chunk, controller) {
9550
+ close() {
9551
+ if (cancelled) {
9552
+ return;
9553
+ }
9438
9554
  try {
9439
- const buffer = chunk;
9440
- const heap = new Uint8Array(memory.buffer);
9441
- const process = this._process;
9442
- const last_consumed = this._last_consumed;
9443
- const out = this.out;
9444
- let offset = 0;
9445
- while (offset < buffer.length) {
9446
- const toRead = Math.min(buffer.length - offset, 32 * 1024);
9447
- if (!this.in || this.inBufferSize < toRead) {
9448
- if (this.in && free) {
9449
- free(this.in);
9450
- this.in = 0;
9451
- }
9452
- this.in = malloc(toRead);
9453
- this.inBufferSize = toRead;
9454
- if (!this.in) {
9455
- throw new Error("allocation failed");
9456
- }
9457
- }
9458
- heap.set(buffer.subarray(offset, offset + toRead), this.in);
9459
- const result = process(this.streamHandle, this.in, toRead, out, outBufferSize, 0);
9460
- // checked before the byte count is used, so a status code can never be read as one
9461
- const code = (result >> 24) & 0xff;
9462
- const signedCode = (code & 0x80) ? code - 256 : code;
9463
- if (signedCode < 0) {
9464
- throw new Error("process error:" + signedCode);
9465
- }
9466
- const prod = result & 0x00ffffff;
9467
- if (prod) {
9468
- controller.enqueue(heap.slice(out, out + prod));
9469
- }
9470
- const consumed = last_consumed(this.streamHandle);
9471
- if (consumed === 0 && prod === 0) {
9472
- break;
9473
- }
9474
- offset += consumed;
9475
- }
9555
+ flushStream();
9476
9556
  } catch (error) {
9477
- disposeStream(this);
9478
- controller.error(error);
9557
+ disposeStream(state);
9558
+ readableController.error(error);
9559
+ throw error;
9560
+ }
9561
+ const result = disposeStream(state);
9562
+ if (result !== 0) {
9563
+ const error = new Error("end error:" + result);
9564
+ readableController.error(error);
9565
+ throw error;
9479
9566
  }
9567
+ readableController.close();
9480
9568
  },
9481
- flush(controller) {
9482
- try {
9483
- const heap = new Uint8Array(memory.buffer);
9484
- const process = this._process;
9485
- const out = this.out;
9486
- while (true) {
9487
- const result = process(this.streamHandle, 0, 0, out, outBufferSize, 4);
9488
- const code = (result >> 24) & 0xff;
9489
- const signedCode = (code & 0x80) ? code - 256 : code;
9490
- if (signedCode < 0) {
9491
- throw new Error("process error:" + signedCode);
9492
- }
9493
- const produced = result & 0x00ffffff;
9494
- if (produced) {
9495
- controller.enqueue(heap.slice(out, out + produced));
9496
- }
9497
- if (code === 1 || produced === 0) {
9498
- break;
9569
+ abort(reason) {
9570
+ disposeStream(state);
9571
+ readableController.error(reason);
9572
+ }
9573
+ }, { highWaterMark: 1 });
9574
+ return { readable, writable };
9575
+
9576
+ function initStream() {
9577
+ try {
9578
+ let result;
9579
+ state.out = malloc(outBufferSize);
9580
+ state.in = malloc(inBufferSize);
9581
+ state.inBufferSize = inBufferSize;
9582
+ if (!state.out || !state.in) {
9583
+ throw new Error("allocation failed");
9584
+ }
9585
+ if (isCompress) {
9586
+ state._process = wasm$1.deflate_process;
9587
+ state._last_consumed = wasm$1.deflate_last_consumed;
9588
+ state._end = wasm$1.deflate_end;
9589
+ state.streamHandle = wasm$1.deflate_new();
9590
+ if (type === FORMAT_GZIP) {
9591
+ result = wasm$1.deflate_init_gzip(state.streamHandle, level);
9592
+ } else if (type === FORMAT_DEFLATE_RAW) {
9593
+ result = wasm$1.deflate_init_raw(state.streamHandle, level);
9594
+ } else {
9595
+ result = wasm$1.deflate_init(state.streamHandle, level);
9596
+ }
9597
+ } else {
9598
+ if (type === FORMAT_DEFLATE64_RAW) {
9599
+ state._process = wasm$1.inflate9_process;
9600
+ state._last_consumed = wasm$1.inflate9_last_consumed;
9601
+ state._end = wasm$1.inflate9_end;
9602
+ state.streamHandle = wasm$1.inflate9_new();
9603
+ result = wasm$1.inflate9_init_raw(state.streamHandle);
9604
+ } else {
9605
+ state._process = wasm$1.inflate_process;
9606
+ state._last_consumed = wasm$1.inflate_last_consumed;
9607
+ state._end = wasm$1.inflate_end;
9608
+ state.streamHandle = wasm$1.inflate_new();
9609
+ if (type === FORMAT_DEFLATE_RAW) {
9610
+ result = wasm$1.inflate_init_raw(state.streamHandle);
9611
+ } else if (type === FORMAT_GZIP) {
9612
+ result = wasm$1.inflate_init_gzip(state.streamHandle);
9613
+ } else {
9614
+ result = wasm$1.inflate_init(state.streamHandle);
9499
9615
  }
9500
9616
  }
9501
- } catch (error) {
9502
- controller.error(error);
9503
- } finally {
9504
- const result = disposeStream(this);
9505
- if (result !== 0) {
9506
- controller.error(new Error("end error:" + result));
9617
+ }
9618
+ if (result !== 0) {
9619
+ throw new Error("init failed:" + result);
9620
+ }
9621
+ } catch (error) {
9622
+ disposeStream(state);
9623
+ throw error;
9624
+ }
9625
+ }
9626
+
9627
+ function processChunk(chunk) {
9628
+ const heap = new Uint8Array(memory.buffer);
9629
+ const process = state._process;
9630
+ const last_consumed = state._last_consumed;
9631
+ const out = state.out;
9632
+ let offset = 0;
9633
+ while (offset < chunk.length) {
9634
+ const toRead = Math.min(chunk.length - offset, 32 * 1024);
9635
+ if (!state.in || state.inBufferSize < toRead) {
9636
+ if (state.in && free) {
9637
+ free(state.in);
9638
+ state.in = 0;
9639
+ }
9640
+ state.in = malloc(toRead);
9641
+ state.inBufferSize = toRead;
9642
+ if (!state.in) {
9643
+ throw new Error("allocation failed");
9507
9644
  }
9508
9645
  }
9509
- },
9510
- cancel() {
9511
- // release the stream handle and buffers when the pipeline is aborted,
9512
- // they would be leaked in the process-lifetime wasm heap otherwise
9513
- disposeStream(this);
9646
+ heap.set(chunk.subarray(offset, offset + toRead), state.in);
9647
+ const result = process(state.streamHandle, state.in, toRead, out, outBufferSize, 0);
9648
+ // checked before the byte count is used, so a status code can never be read as one
9649
+ const code = (result >> 24) & 0xff;
9650
+ const signedCode = (code & 0x80) ? code - 256 : code;
9651
+ if (signedCode < 0) {
9652
+ throw new Error("process error:" + signedCode);
9653
+ }
9654
+ const prod = result & 0x00ffffff;
9655
+ if (prod) {
9656
+ enqueue(heap.slice(out, out + prod));
9657
+ }
9658
+ const consumed = last_consumed(state.streamHandle);
9659
+ if (consumed === 0 && prod === 0) {
9660
+ break;
9661
+ }
9662
+ offset += consumed;
9514
9663
  }
9515
- });
9664
+ }
9665
+
9666
+ function flushStream() {
9667
+ const heap = new Uint8Array(memory.buffer);
9668
+ const process = state._process;
9669
+ const out = state.out;
9670
+ while (true) {
9671
+ const result = process(state.streamHandle, 0, 0, out, outBufferSize, 4);
9672
+ const code = (result >> 24) & 0xff;
9673
+ const signedCode = (code & 0x80) ? code - 256 : code;
9674
+ if (signedCode < 0) {
9675
+ throw new Error("process error:" + signedCode);
9676
+ }
9677
+ const produced = result & 0x00ffffff;
9678
+ if (produced) {
9679
+ enqueue(heap.slice(out, out + produced));
9680
+ }
9681
+ if (code === 1 || produced === 0) {
9682
+ break;
9683
+ }
9684
+ }
9685
+ }
9686
+
9687
+ function enqueue(chunk) {
9688
+ backpressure = true;
9689
+ readableController.enqueue(chunk);
9690
+ }
9691
+
9692
+ function resumeWrite() {
9693
+ if (resolveWrite) {
9694
+ const resolve = resolveWrite;
9695
+ resolveWrite = null;
9696
+ resolve();
9697
+ }
9698
+ }
9516
9699
 
9517
9700
  function disposeStream(state) {
9518
9701
  let endResult = 0;
@@ -9868,7 +10051,11 @@
9868
10051
  const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
9869
10052
  const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
9870
10053
  const ERR_UNSUPPORTED_PASS_THROUGH_VALUE = "The 'compressed' passThrough option is only supported by Entry#getData() and ZipWriter#add()";
10054
+ const ERR_INVALID_PASSWORDS = "Invalid passwords option (must be an array of strings)";
10055
+ const ERR_INVALID_REQUEST_PASSWORD = "Invalid requestPassword option (must be a function returning a string or undefined)";
9871
10056
  const ERR_ABORT_EXPORT = "zipjs-abort-export";
10057
+ const ABORT_ERROR_NAME = "AbortError";
10058
+ const EMPTY_RAW_PASSWORD = new Uint8Array(0);
9872
10059
 
9873
10060
  class ZipEntry {
9874
10061
 
@@ -10241,8 +10428,10 @@
10241
10428
  zipReader = new ZipReader(reader, options);
10242
10429
  }
10243
10430
  checkPassThroughValue(options.passThrough);
10431
+ checkPasswordCandidatesOptions(options);
10244
10432
  const duplicates = checkDuplicatesOption(options.duplicates);
10245
10433
  const importedEntries = [];
10434
+ const passwordState = { known: [] };
10246
10435
  const entries = await zipReader.getEntries(options);
10247
10436
  for (const entry of entries) {
10248
10437
  let parent = this;
@@ -10287,7 +10476,7 @@
10287
10476
  }
10288
10477
  importedEntries.push(addChild(parent, name, {
10289
10478
  data: entry,
10290
- Reader: getZipBlobReader(Object.assign({}, options)),
10479
+ Reader: getZipBlobReader(Object.assign({}, options), passwordState),
10291
10480
  uncompressedSize: options.passThrough ? entry.compressedSize : entry.uncompressedSize,
10292
10481
  passThrough: options.passThrough
10293
10482
  }));
@@ -10616,7 +10805,7 @@
10616
10805
  };
10617
10806
  }
10618
10807
 
10619
- function getZipBlobReader(options) {
10808
+ function getZipBlobReader(options, passwordState) {
10620
10809
  return class extends Reader {
10621
10810
 
10622
10811
  constructor(entry, options = {}) {
@@ -10629,12 +10818,12 @@
10629
10818
  const zipBlobReader = this;
10630
10819
  const readerOptions = Object.assign({}, options, zipBlobReader.options);
10631
10820
  const { checkOverlappingEntry, checkOverlappingEntryOnly } = readerOptions;
10632
- const data = await zipBlobReader.entry.getData(new BlobWriter(), Object.assign(readerOptions, {
10821
+ const data = await readEntryData(zipBlobReader.entry, Object.assign(readerOptions, {
10633
10822
  checkPasswordOnly: false,
10634
10823
  checkOverlappingEntry: checkOverlappingEntryOnly || checkOverlappingEntry,
10635
10824
  checkOverlappingEntryOnly: false,
10636
10825
  preventClose: false
10637
- }));
10826
+ }), passwordState);
10638
10827
  zipBlobReader.data = data;
10639
10828
  zipBlobReader.blobReader = new BlobReader(data);
10640
10829
  zipBlobReader.size = data.size;
@@ -10696,10 +10885,9 @@
10696
10885
  await initStream(reader);
10697
10886
  } catch (error) {
10698
10887
  try {
10888
+ error.entry = child;
10699
10889
  error.entryId = child.id;
10700
- error.cause = {
10701
- entry: child
10702
- };
10890
+ error.entryName = child.getRelativeName(entry);
10703
10891
  } catch {
10704
10892
  // ignored
10705
10893
  }
@@ -10791,10 +10979,136 @@
10791
10979
  }
10792
10980
  if (readerOptions) {
10793
10981
  checkPassThroughValue(readerOptions.passThrough);
10982
+ checkPasswordCandidatesOptions(readerOptions);
10794
10983
  }
10795
10984
  return readerOptions;
10796
10985
  }
10797
10986
 
10987
+ function checkPasswordCandidatesOptions(options) {
10988
+ const { passwords, requestPassword } = options;
10989
+ if (passwords && (!Array.isArray(passwords) || passwords.some(password => typeof password != STRING_TYPE))) {
10990
+ throw new Error(ERR_INVALID_PASSWORDS);
10991
+ }
10992
+ if (requestPassword && typeof requestPassword != FUNCTION_TYPE) {
10993
+ throw new Error(ERR_INVALID_REQUEST_PASSWORD);
10994
+ }
10995
+ }
10996
+
10997
+ async function readEntryData(entry, options, passwordState) {
10998
+ checkPasswordCandidatesOptions(options);
10999
+ const { passwords, requestPassword, signal } = options;
11000
+ options = Object.assign({}, options);
11001
+ delete options.passwords;
11002
+ delete options.requestPassword;
11003
+ if (!entry.encrypted || options.passThrough || (!passwords && !requestPassword)) {
11004
+ return entry.getData(new BlobWriter(), options);
11005
+ }
11006
+ const tried = new Set();
11007
+ let error;
11008
+ while (true) {
11009
+ for (const candidate of getPasswordCandidates(options, passwordState, passwords)) {
11010
+ if (!tried.has(candidate.key)) {
11011
+ const result = await tryPasswordCandidate(candidate);
11012
+ if (result.done) {
11013
+ return result.data;
11014
+ }
11015
+ error = result.error;
11016
+ }
11017
+ }
11018
+ if (!requestPassword) {
11019
+ break;
11020
+ }
11021
+ if (passwordState.pendingPrompt) {
11022
+ await passwordState.pendingPrompt;
11023
+ continue;
11024
+ }
11025
+ let release;
11026
+ passwordState.pendingPrompt = new Promise(resolve => release = resolve);
11027
+ try {
11028
+ const answer = await requestPassword(entry, error);
11029
+ if (answer === UNDEFINED_VALUE || answer === null) {
11030
+ break;
11031
+ }
11032
+ // deno-lint-ignore valid-typeof
11033
+ if (typeof answer != STRING_TYPE) {
11034
+ throw new Error(ERR_INVALID_REQUEST_PASSWORD);
11035
+ }
11036
+ const result = await tryPasswordCandidate(getPasswordCandidate(answer));
11037
+ if (result.done) {
11038
+ return result.data;
11039
+ }
11040
+ error = result.error;
11041
+ } finally {
11042
+ passwordState.pendingPrompt = UNDEFINED_VALUE;
11043
+ release();
11044
+ }
11045
+ }
11046
+ throw new Error(tried.size ? ERR_INVALID_PASSWORD : ERR_ENCRYPTED);
11047
+
11048
+ async function tryPasswordCandidate(candidate) {
11049
+ tried.add(candidate.key);
11050
+ const candidateOptions = Object.assign({}, options, candidate.options);
11051
+ if (entry.zipCrypto) {
11052
+ candidateOptions.checkCrc32 = true;
11053
+ try {
11054
+ await entry.getData(null, Object.assign({}, candidateOptions, { checkPasswordOnly: true }));
11055
+ } catch (probeError) {
11056
+ if (isInvalidPasswordError(probeError)) {
11057
+ return { done: false, error: probeError };
11058
+ }
11059
+ throw probeError;
11060
+ }
11061
+ }
11062
+ try {
11063
+ const data = await entry.getData(new BlobWriter(), candidateOptions);
11064
+ rememberPassword(passwordState, candidate);
11065
+ return { done: true, data };
11066
+ } catch (readError) {
11067
+ if (isAbortError(readError, signal) || (!entry.zipCrypto && !isInvalidPasswordError(readError))) {
11068
+ throw readError;
11069
+ }
11070
+ return { done: false, error: readError };
11071
+ }
11072
+ }
11073
+ }
11074
+
11075
+ function isInvalidPasswordError(error) {
11076
+ return isErrorObject(error) && error.message == ERR_INVALID_PASSWORD;
11077
+ }
11078
+
11079
+ function isAbortError(error, signal) {
11080
+ return Boolean(signal && signal.aborted) || (isErrorObject(error) && error.name == ABORT_ERROR_NAME);
11081
+ }
11082
+
11083
+ function getPasswordCandidates(options, passwordState, passwords) {
11084
+ const candidates = [];
11085
+ const { password, rawPassword } = options;
11086
+ if (rawPassword && rawPassword.length) {
11087
+ candidates.push({ key: rawPassword, options: { password: "", rawPassword } });
11088
+ }
11089
+ if (password) {
11090
+ candidates.push(getPasswordCandidate(password));
11091
+ }
11092
+ candidates.push(...passwordState.known);
11093
+ if (passwords) {
11094
+ candidates.push(...passwords.filter(password => password).map(getPasswordCandidate));
11095
+ }
11096
+ return candidates;
11097
+ }
11098
+
11099
+ function getPasswordCandidate(password) {
11100
+ return { key: password, options: { password, rawPassword: EMPTY_RAW_PASSWORD } };
11101
+ }
11102
+
11103
+ function rememberPassword(passwordState, candidate) {
11104
+ const { known } = passwordState;
11105
+ const index = known.findIndex(knownCandidate => knownCandidate.key === candidate.key);
11106
+ if (index != -1) {
11107
+ known.splice(index, 1);
11108
+ }
11109
+ known.unshift(candidate);
11110
+ }
11111
+
10798
11112
  function checkPassThroughValue(passThrough) {
10799
11113
  if (checkPassThroughOption(passThrough) === PASS_THROUGH_COMPRESSED) {
10800
11114
  throw new Error(ERR_UNSUPPORTED_PASS_THROUGH_VALUE);
@@ -10932,6 +11246,7 @@
10932
11246
  async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
10933
11247
  const { onstart, onprogress, onend } = options;
10934
11248
  checkPassThroughValue(options.passThrough);
11249
+ checkPasswordCandidatesOptions(options);
10935
11250
  const readerOptions = checkReaderOptions(options.readerOptions);
10936
11251
  const abortController = new AbortController();
10937
11252
  const { signal } = abortController;
@@ -11325,11 +11640,13 @@
11325
11640
  exports.ERR_INVALID_MSDOS_ATTRIBUTES = ERR_INVALID_MSDOS_ATTRIBUTES;
11326
11641
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
11327
11642
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
11643
+ exports.ERR_INVALID_PASSWORDS = ERR_INVALID_PASSWORDS;
11328
11644
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
11329
11645
  exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
11330
11646
  exports.ERR_INVALID_PASS_THROUGH_VALUE = ERR_INVALID_PASS_THROUGH_VALUE;
11331
11647
  exports.ERR_INVALID_READER = ERR_INVALID_READER;
11332
11648
  exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
11649
+ exports.ERR_INVALID_REQUEST_PASSWORD = ERR_INVALID_REQUEST_PASSWORD;
11333
11650
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
11334
11651
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
11335
11652
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;