@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.js CHANGED
@@ -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
+ }
2021
2103
 
2022
- function startWatchdog() {
2023
- stopWatchdog();
2024
- watchdogTimeout = setTimeout(() => rejectTrailerReady(new Error(ERR_INVALID_UNCOMPRESSED_SIZE)), GZIP_OUTPUT_STALL_TIMEOUT);
2104
+ function onReadSettled() {
2105
+ readPending = false;
2106
+ }
2107
+
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;
2063
2170
  }
2064
- gzipCrc32 = new Crc32();
2065
- readable = pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, gzipCrc32);
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
+ }
2184
+ }
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);
@@ -3716,10 +3838,11 @@
3716
3838
 
3717
3839
  createReadable(options) {
3718
3840
  const reader = this;
3719
- const { useRangeHeader, forceRangeRequests, size } = reader;
3841
+ const { useRangeHeader, forceRangeRequests, size, eocdCache } = reader;
3720
3842
  if ((useRangeHeader || forceRangeRequests) && size !== UNDEFINED_VALUE) {
3721
3843
  const { offset = 0, size: readSize = size - offset } = options || {};
3722
- if (readSize > 0 && offset < size) {
3844
+ const cached = eocdCache && offset >= size - eocdCache.length;
3845
+ if (readSize > 0 && offset < size && !cached) {
3723
3846
  return createRangeReadable(reader, offset, Math.min(readSize, size - offset));
3724
3847
  }
3725
3848
  }
@@ -5278,8 +5401,8 @@
5278
5401
  const passThroughCompression = Boolean(passThrough);
5279
5402
  const passThroughEncryption = passThrough === true;
5280
5403
  checkPasswordOption(password, rawPassword);
5281
- password = password && password.length && password;
5282
- rawPassword = rawPassword && rawPassword.length && rawPassword;
5404
+ password = password && password.length ? password : UNDEFINED_VALUE;
5405
+ rawPassword = rawPassword && rawPassword.length ? rawPassword : UNDEFINED_VALUE;
5283
5406
  if (extraFieldAES) {
5284
5407
  if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
5285
5408
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
@@ -6040,7 +6163,7 @@
6040
6163
  async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDataSize) {
6041
6164
  const { size } = reader;
6042
6165
  const anchoredLength = Math.min(size, END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS);
6043
- const remoteProbeBudget = { count: MAX_END_OF_CENTRAL_DIR_PROBES };
6166
+ const remoteProbeBudget = { remaining: MAX_END_OF_CENTRAL_DIR_PROBES };
6044
6167
  let endOfDirectoryInfo;
6045
6168
  let plausibleEndOfDirectoryInfo;
6046
6169
  let endOfDirectoryReachingEndCount = 0;
@@ -6133,8 +6256,8 @@
6133
6256
  if (signatureOffset >= anchoredOffset) {
6134
6257
  return getUint32$1(view, signatureOffset - anchoredOffset);
6135
6258
  }
6136
- if (remoteProbeBudget.count > 0) {
6137
- remoteProbeBudget.count--;
6259
+ if (remoteProbeBudget.remaining > 0) {
6260
+ remoteProbeBudget.remaining--;
6138
6261
  const signatureArray = await readUint8Array(reader, signatureOffset, 4);
6139
6262
  return getUint32$1(getDataView(signatureArray), 0);
6140
6263
  }
@@ -7050,9 +7173,11 @@
7050
7173
  const passThrough = checkPassThroughOption(getOptionValue(zipWriter, options, OPTION_PASS_THROUGH));
7051
7174
  const passThroughCompression = Boolean(passThrough);
7052
7175
  const passThroughEncryption = passThrough === true;
7053
- const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
7054
- const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
7176
+ let password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
7177
+ let rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
7055
7178
  checkPasswordOption(password, rawPassword);
7179
+ password = password && password.length ? password : UNDEFINED_VALUE;
7180
+ rawPassword = rawPassword && rawPassword.length ? rawPassword : UNDEFINED_VALUE;
7056
7181
  const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
7057
7182
  const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
7058
7183
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
@@ -8750,7 +8875,7 @@
8750
8875
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8751
8876
  */
8752
8877
 
8753
- const VERSION = "2.15.0";
8878
+ const VERSION = "2.16.1";
8754
8879
 
8755
8880
  /*
8756
8881
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9229,7 +9354,7 @@
9229
9354
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9230
9355
  */
9231
9356
 
9232
- /* global TransformStream */
9357
+ /* global ReadableStream, WritableStream */
9233
9358
 
9234
9359
  const FORMAT_DEFLATE = "deflate";
9235
9360
  const FORMAT_DEFLATE_RAW = "deflate-raw";
@@ -9264,137 +9389,195 @@
9264
9389
  const level = (typeof options.level === "number") ? options.level : -1;
9265
9390
  const outBufferSize = (typeof options.outBuffer === "number") ? options.outBuffer : 64 * 1024;
9266
9391
  const inBufferSize = (typeof options.inBufferSize === "number") ? options.inBufferSize : 64 * 1024;
9267
-
9268
- return new TransformStream({
9269
- start() {
9392
+ const state = { out: 0, in: 0, inBufferSize: 0, streamHandle: 0 };
9393
+ let readableController, writableController, resolveWrite, cancelReason;
9394
+ let backpressure = true;
9395
+ let cancelled = false;
9396
+ initStream();
9397
+ const readable = new ReadableStream({
9398
+ start(controller) {
9399
+ readableController = controller;
9400
+ },
9401
+ pull() {
9402
+ backpressure = false;
9403
+ resumeWrite();
9404
+ },
9405
+ cancel(reason) {
9406
+ cancelled = true;
9407
+ cancelReason = reason;
9408
+ disposeStream(state);
9409
+ writableController.error(reason);
9410
+ resumeWrite();
9411
+ }
9412
+ }, { highWaterMark: 0 });
9413
+ const writable = new WritableStream({
9414
+ start(controller) {
9415
+ writableController = controller;
9416
+ },
9417
+ async write(chunk) {
9418
+ if (backpressure) {
9419
+ await new Promise(resolve => resolveWrite = resolve);
9420
+ }
9421
+ if (cancelled) {
9422
+ throw cancelReason;
9423
+ }
9270
9424
  try {
9271
- let result;
9272
- this.out = malloc(outBufferSize);
9273
- this.in = malloc(inBufferSize);
9274
- this.inBufferSize = inBufferSize;
9275
- if (!this.out || !this.in) {
9276
- throw new Error("allocation failed");
9277
- }
9278
- if (isCompress) {
9279
- this._process = wasm$1.deflate_process;
9280
- this._last_consumed = wasm$1.deflate_last_consumed;
9281
- this._end = wasm$1.deflate_end;
9282
- this.streamHandle = wasm$1.deflate_new();
9283
- if (type === FORMAT_GZIP) {
9284
- result = wasm$1.deflate_init_gzip(this.streamHandle, level);
9285
- } else if (type === FORMAT_DEFLATE_RAW) {
9286
- result = wasm$1.deflate_init_raw(this.streamHandle, level);
9287
- } else {
9288
- result = wasm$1.deflate_init(this.streamHandle, level);
9289
- }
9290
- } else {
9291
- if (type === FORMAT_DEFLATE64_RAW) {
9292
- this._process = wasm$1.inflate9_process;
9293
- this._last_consumed = wasm$1.inflate9_last_consumed;
9294
- this._end = wasm$1.inflate9_end;
9295
- this.streamHandle = wasm$1.inflate9_new();
9296
- result = wasm$1.inflate9_init_raw(this.streamHandle);
9297
- } else {
9298
- this._process = wasm$1.inflate_process;
9299
- this._last_consumed = wasm$1.inflate_last_consumed;
9300
- this._end = wasm$1.inflate_end;
9301
- this.streamHandle = wasm$1.inflate_new();
9302
- if (type === FORMAT_DEFLATE_RAW) {
9303
- result = wasm$1.inflate_init_raw(this.streamHandle);
9304
- } else if (type === FORMAT_GZIP) {
9305
- result = wasm$1.inflate_init_gzip(this.streamHandle);
9306
- } else {
9307
- result = wasm$1.inflate_init(this.streamHandle);
9308
- }
9309
- }
9310
- }
9311
- if (result !== 0) {
9312
- throw new Error("init failed:" + result);
9313
- }
9425
+ processChunk(chunk);
9314
9426
  } catch (error) {
9315
- disposeStream(this);
9427
+ disposeStream(state);
9428
+ readableController.error(error);
9316
9429
  throw error;
9317
9430
  }
9318
9431
  },
9319
- transform(chunk, controller) {
9432
+ close() {
9433
+ if (cancelled) {
9434
+ return;
9435
+ }
9320
9436
  try {
9321
- const buffer = chunk;
9322
- const heap = new Uint8Array(memory.buffer);
9323
- const process = this._process;
9324
- const last_consumed = this._last_consumed;
9325
- const out = this.out;
9326
- let offset = 0;
9327
- while (offset < buffer.length) {
9328
- const toRead = Math.min(buffer.length - offset, 32 * 1024);
9329
- if (!this.in || this.inBufferSize < toRead) {
9330
- if (this.in && free) {
9331
- free(this.in);
9332
- this.in = 0;
9333
- }
9334
- this.in = malloc(toRead);
9335
- this.inBufferSize = toRead;
9336
- if (!this.in) {
9337
- throw new Error("allocation failed");
9338
- }
9339
- }
9340
- heap.set(buffer.subarray(offset, offset + toRead), this.in);
9341
- const result = process(this.streamHandle, this.in, toRead, out, outBufferSize, 0);
9342
- // checked before the byte count is used, so a status code can never be read as one
9343
- const code = (result >> 24) & 0xff;
9344
- const signedCode = (code & 0x80) ? code - 256 : code;
9345
- if (signedCode < 0) {
9346
- throw new Error("process error:" + signedCode);
9347
- }
9348
- const prod = result & 0x00ffffff;
9349
- if (prod) {
9350
- controller.enqueue(heap.slice(out, out + prod));
9351
- }
9352
- const consumed = last_consumed(this.streamHandle);
9353
- if (consumed === 0 && prod === 0) {
9354
- break;
9355
- }
9356
- offset += consumed;
9357
- }
9437
+ flushStream();
9358
9438
  } catch (error) {
9359
- disposeStream(this);
9360
- controller.error(error);
9439
+ disposeStream(state);
9440
+ readableController.error(error);
9441
+ throw error;
9442
+ }
9443
+ const result = disposeStream(state);
9444
+ if (result !== 0) {
9445
+ const error = new Error("end error:" + result);
9446
+ readableController.error(error);
9447
+ throw error;
9361
9448
  }
9449
+ readableController.close();
9362
9450
  },
9363
- flush(controller) {
9364
- try {
9365
- const heap = new Uint8Array(memory.buffer);
9366
- const process = this._process;
9367
- const out = this.out;
9368
- while (true) {
9369
- const result = process(this.streamHandle, 0, 0, out, outBufferSize, 4);
9370
- const code = (result >> 24) & 0xff;
9371
- const signedCode = (code & 0x80) ? code - 256 : code;
9372
- if (signedCode < 0) {
9373
- throw new Error("process error:" + signedCode);
9374
- }
9375
- const produced = result & 0x00ffffff;
9376
- if (produced) {
9377
- controller.enqueue(heap.slice(out, out + produced));
9378
- }
9379
- if (code === 1 || produced === 0) {
9380
- break;
9451
+ abort(reason) {
9452
+ disposeStream(state);
9453
+ readableController.error(reason);
9454
+ }
9455
+ }, { highWaterMark: 1 });
9456
+ return { readable, writable };
9457
+
9458
+ function initStream() {
9459
+ try {
9460
+ let result;
9461
+ state.out = malloc(outBufferSize);
9462
+ state.in = malloc(inBufferSize);
9463
+ state.inBufferSize = inBufferSize;
9464
+ if (!state.out || !state.in) {
9465
+ throw new Error("allocation failed");
9466
+ }
9467
+ if (isCompress) {
9468
+ state._process = wasm$1.deflate_process;
9469
+ state._last_consumed = wasm$1.deflate_last_consumed;
9470
+ state._end = wasm$1.deflate_end;
9471
+ state.streamHandle = wasm$1.deflate_new();
9472
+ if (type === FORMAT_GZIP) {
9473
+ result = wasm$1.deflate_init_gzip(state.streamHandle, level);
9474
+ } else if (type === FORMAT_DEFLATE_RAW) {
9475
+ result = wasm$1.deflate_init_raw(state.streamHandle, level);
9476
+ } else {
9477
+ result = wasm$1.deflate_init(state.streamHandle, level);
9478
+ }
9479
+ } else {
9480
+ if (type === FORMAT_DEFLATE64_RAW) {
9481
+ state._process = wasm$1.inflate9_process;
9482
+ state._last_consumed = wasm$1.inflate9_last_consumed;
9483
+ state._end = wasm$1.inflate9_end;
9484
+ state.streamHandle = wasm$1.inflate9_new();
9485
+ result = wasm$1.inflate9_init_raw(state.streamHandle);
9486
+ } else {
9487
+ state._process = wasm$1.inflate_process;
9488
+ state._last_consumed = wasm$1.inflate_last_consumed;
9489
+ state._end = wasm$1.inflate_end;
9490
+ state.streamHandle = wasm$1.inflate_new();
9491
+ if (type === FORMAT_DEFLATE_RAW) {
9492
+ result = wasm$1.inflate_init_raw(state.streamHandle);
9493
+ } else if (type === FORMAT_GZIP) {
9494
+ result = wasm$1.inflate_init_gzip(state.streamHandle);
9495
+ } else {
9496
+ result = wasm$1.inflate_init(state.streamHandle);
9381
9497
  }
9382
9498
  }
9383
- } catch (error) {
9384
- controller.error(error);
9385
- } finally {
9386
- const result = disposeStream(this);
9387
- if (result !== 0) {
9388
- controller.error(new Error("end error:" + result));
9499
+ }
9500
+ if (result !== 0) {
9501
+ throw new Error("init failed:" + result);
9502
+ }
9503
+ } catch (error) {
9504
+ disposeStream(state);
9505
+ throw error;
9506
+ }
9507
+ }
9508
+
9509
+ function processChunk(chunk) {
9510
+ const heap = new Uint8Array(memory.buffer);
9511
+ const process = state._process;
9512
+ const last_consumed = state._last_consumed;
9513
+ const out = state.out;
9514
+ let offset = 0;
9515
+ while (offset < chunk.length) {
9516
+ const toRead = Math.min(chunk.length - offset, 32 * 1024);
9517
+ if (!state.in || state.inBufferSize < toRead) {
9518
+ if (state.in && free) {
9519
+ free(state.in);
9520
+ state.in = 0;
9521
+ }
9522
+ state.in = malloc(toRead);
9523
+ state.inBufferSize = toRead;
9524
+ if (!state.in) {
9525
+ throw new Error("allocation failed");
9389
9526
  }
9390
9527
  }
9391
- },
9392
- cancel() {
9393
- // release the stream handle and buffers when the pipeline is aborted,
9394
- // they would be leaked in the process-lifetime wasm heap otherwise
9395
- disposeStream(this);
9528
+ heap.set(chunk.subarray(offset, offset + toRead), state.in);
9529
+ const result = process(state.streamHandle, state.in, toRead, out, outBufferSize, 0);
9530
+ // checked before the byte count is used, so a status code can never be read as one
9531
+ const code = (result >> 24) & 0xff;
9532
+ const signedCode = (code & 0x80) ? code - 256 : code;
9533
+ if (signedCode < 0) {
9534
+ throw new Error("process error:" + signedCode);
9535
+ }
9536
+ const prod = result & 0x00ffffff;
9537
+ if (prod) {
9538
+ enqueue(heap.slice(out, out + prod));
9539
+ }
9540
+ const consumed = last_consumed(state.streamHandle);
9541
+ if (consumed === 0 && prod === 0) {
9542
+ break;
9543
+ }
9544
+ offset += consumed;
9396
9545
  }
9397
- });
9546
+ }
9547
+
9548
+ function flushStream() {
9549
+ const heap = new Uint8Array(memory.buffer);
9550
+ const process = state._process;
9551
+ const out = state.out;
9552
+ while (true) {
9553
+ const result = process(state.streamHandle, 0, 0, out, outBufferSize, 4);
9554
+ const code = (result >> 24) & 0xff;
9555
+ const signedCode = (code & 0x80) ? code - 256 : code;
9556
+ if (signedCode < 0) {
9557
+ throw new Error("process error:" + signedCode);
9558
+ }
9559
+ const produced = result & 0x00ffffff;
9560
+ if (produced) {
9561
+ enqueue(heap.slice(out, out + produced));
9562
+ }
9563
+ if (code === 1 || produced === 0) {
9564
+ break;
9565
+ }
9566
+ }
9567
+ }
9568
+
9569
+ function enqueue(chunk) {
9570
+ backpressure = true;
9571
+ readableController.enqueue(chunk);
9572
+ }
9573
+
9574
+ function resumeWrite() {
9575
+ if (resolveWrite) {
9576
+ const resolve = resolveWrite;
9577
+ resolveWrite = null;
9578
+ resolve();
9579
+ }
9580
+ }
9398
9581
 
9399
9582
  function disposeStream(state) {
9400
9583
  let endResult = 0;