@zip.js/zip.js 2.8.30 → 2.8.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/deno.json +5 -4
  2. package/dist/zip-core.js +133 -334
  3. package/dist/zip-core.min.js +1 -1
  4. package/dist/zip-fs-core.js +115 -277
  5. package/dist/zip-fs-core.min.js +1 -1
  6. package/dist/zip-fs-native.js +170 -373
  7. package/dist/zip-fs-native.min.js +1 -1
  8. package/dist/zip-fs.js +169 -372
  9. package/dist/zip-fs.min.js +1 -1
  10. package/dist/zip-legacy.js +138 -339
  11. package/dist/zip-legacy.min.js +1 -1
  12. package/dist/zip-module.wasm +0 -0
  13. package/dist/zip-native.js +141 -342
  14. package/dist/zip-native.min.js +1 -1
  15. package/dist/zip-web-worker-native.js +1 -1
  16. package/dist/zip-web-worker.js +1 -1
  17. package/dist/zip.js +140 -341
  18. package/dist/zip.min.js +1 -1
  19. package/index-native.cjs +170 -373
  20. package/index-native.min.js +1 -1
  21. package/index.cjs +169 -372
  22. package/index.d.cts +2814 -0
  23. package/index.d.ts +238 -0
  24. package/index.min.js +1 -1
  25. package/lib/core/codec-worker.js +0 -10
  26. package/lib/core/configuration.js +21 -33
  27. package/lib/core/constants.js +3 -0
  28. package/lib/core/io.js +11 -19
  29. package/lib/core/streams/aes-crypto-stream.js +16 -20
  30. package/lib/core/streams/common-crypto.js +0 -2
  31. package/lib/core/streams/zip-crypto-stream.js +12 -16
  32. package/lib/core/streams/zip-entry-stream.js +2 -32
  33. package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
  34. package/lib/core/streams/zlib-wasm/zlib-streams-loader.js +1 -3
  35. package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
  36. package/lib/core/util/base64.js +68 -0
  37. package/lib/core/util/decode-text.js +0 -1
  38. package/lib/core/util/default-mime-type.js +0 -3
  39. package/lib/core/util/inflate.js +194 -0
  40. package/lib/core/util/mime-type.js +26 -22
  41. package/lib/core/util/opfs-temp-stream.js +1 -37
  42. package/lib/core/web-worker-inline-native.js +1 -1
  43. package/lib/core/web-worker-inline-template-native.js +5 -5
  44. package/lib/core/web-worker-inline-wasm.js +1 -1
  45. package/lib/core/zip-fs.js +6 -13
  46. package/lib/core/zip-reader.js +48 -127
  47. package/lib/core/zip-writer.js +27 -45
  48. package/lib/core/zlib-streams-inline-template.js +3 -2
  49. package/lib/core/zlib-streams-inline.js +1 -1
  50. package/lib/zip-core-base.js +3 -1
  51. package/package.json +9 -6
  52. package/reserved-property-names.js +50 -0
  53. package/lib/core/util/mini-lz.js +0 -198
@@ -26,22 +26,22 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- /* global Blob, URL, atob */
29
+ /* global Blob, URL */
30
30
  /* eslint-disable quotes */
31
- import { decompress } from "./util/mini-lz.js";
31
+ import { inflateRaw } from "./util/inflate.js";
32
+ import { base64Decode, base64Encode } from "./util/base64.js";
32
33
 
33
34
  export function configureWebWorker(configure) {
34
35
  const code = `__workerCode__`;
35
36
  configure({
36
37
  workerURI: (useBlobURI) => {
37
38
  const type = "text/javascript";
38
- const base64Source = decompress(code);
39
+ const source = inflateRaw(base64Decode(code));
39
40
  if (useBlobURI) {
40
- const source = atob(base64Source);
41
41
  const blob = new Blob([source], { type });
42
42
  return URL.createObjectURL(blob);
43
43
  } else {
44
- return "data:" + type + ";base64," + base64Source;
44
+ return "data:" + type + ";base64," + base64Encode(source);
45
45
  }
46
46
  }
47
47
  });
@@ -1 +1 @@
1
- function t(t){const e='(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:i,Uint32Array:a,Int32Array:c,Map:w,DataView:f,Promise:l,TextEncoder:u,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:g,DecompressionStream:S}=self,b=void 0,k="undefined",v="function",z=[[],[],[],[],[],[],[],[]];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)e=1&e?e>>>1^3988292384:e>>>1;z[0][t]=e}for(let t=0;256>t;t++)for(let e=1;8>e;e++){const n=z[e-1][t];z[e][t]=n>>>8^z[0][255&n]}const[C,I,A,x,P,R,U,W]=z;class D{constructor(t){this.t=t||-1}append(t){let e=0|this.t;const n=0|t.length;let s=0;if(n>=8&&t.buffer){const r=new f(t.buffer,t.byteOffset,n),o=n-8;for(;o>=s;s+=8){const t=e^r.getInt32(s,!0),n=r.getInt32(s+4,!0);e=W[255&t]^U[t>>>8&255]^R[t>>>16&255]^P[t>>>24&255]^x[255&n]^A[n>>>8&255]^I[n>>>16&255]^C[n>>>24&255]}}for(;n>s;s++)e=e>>>8^C[255&(e^t[s])];this.t=e}get(){return~this.t}}class M extends d{constructor(){let t;const e=new D;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new f(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}const V={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=V.o(n);return 32===s?t.concat(e):V.i(e,s,0|n,t.slice(0,t.length-1))},l(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+V.o(n)},u(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=V.h(e,t[n-1]&2147483648>>e-1,1)),t},h:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,o:t=>s.round(t/1099511627776)||32,i(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=V.o(r);return s.push(V.h(e+o&31,e+o>32?n:s.pop(),1)),s}},_={bytes:{p(t){const e=V.l(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},m(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(V.h(8*(3&n),s)),e}}},B=class{constructor(t){const e=this;e.blockSize=512,e.S=[1732584193,4023233417,2562383102,271733878,3285377520],e.k=[1518500249,1859775393,2400959708,3395469782],t?(e.v=t.v.slice(0),e.C=t.C.slice(0),e.I=t.I):e.reset()}reset(){const t=this;return t.v=t.S.slice(0),t.C=[],t.I=0,t}update(t){const e=this;"string"==typeof t&&(t=_.A.m(t));const n=e.C=V.concat(e.C,t),s=e.I,o=e.I=s+V.l(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const i=new a(n);let c=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.P(i.subarray(16*c,16*(c+1))),c+=1;return n.splice(0,16*c),e}R(){const t=this;let e=t.C;const n=t.v;e=V.concat(e,[V.h(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.I/4294967296)),e.push(0|t.I);e.length;)t.P(e.splice(0,16));return t.reset(),n}U(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}P(e){const n=this,r=n.v,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let i=r[0],a=r[1],c=r[2],w=r[3],f=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.W(5,i)+n.U(t,a,c,w)+f+o[t]+n.k[s.floor(t/20)]|0;f=w,w=c,c=n.W(30,a),a=i,i=e}r[0]=r[0]+i|0,r[1]=r[1]+a|0,r[2]=r[2]+c|0,r[3]=r[3]+w|0,r[4]=r[4]+f|0}},T={importKey:t=>new T.D(_.bytes.m(t)),M(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let i,a,c,w,l;const u=new ArrayBuffer(o),h=new f(u);let p=0;const d=V;for(e=_.bytes.m(e),l=1;(o||1)>p;l++){for(i=a=t.encrypt(d.concat(e,[l])),c=1;n>c;c++)for(a=t.encrypt(a),w=0;w<a.length;w++)i[w]^=a[w];for(c=0;(o||1)>p&&c<i.length;c++)h.setInt32(p,i[c]),p+=4}return u.slice(0,s/8)},D:class{constructor(t){const e=this,n=e.V=B,s=[[],[]];e._=[new n,new n];const r=e._[0].blockSize/32;t.length>r&&(t=(new n).update(t).R());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e._[0].update(s[0]),e._[1].update(s[1]),e.B=new n(e._[0])}reset(){const t=this;t.B=new t.V(t._[0]),t.T=!1}update(t){this.T=!0,this.B.update(t)}digest(){const t=this,e=t.B.R(),n=new t.V(t._[1]).update(e).R();return t.reset(),n}encrypt(t){if(this.T)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},K=typeof h!=k&&typeof h.getRandomValues==v,j="Invalid password",E="Invalid signature",L="zipjs-abort-check-password";function O(t){if(K)return h.getRandomValues(t);throw new r("Crypto API not supported")}const H=16,Z={name:"PBKDF2"},F=e.assign({hash:{name:"HMAC"}},Z),N=e.assign({iterations:1e3,hash:{name:"SHA-1"}},Z),q=["deriveBits"],G=[8,12,16],J=[16,24,32],Q=10,X=[0,0,0,0],Y=typeof h!=k,$=Y&&h.subtle,tt=Y&&typeof $!=k,et=_.bytes,nt=class{constructor(t){const e=this;e.K=[[[],[],[],[],[]],[[],[],[],[],[]]],e.K[0][0][0]||e.j();const n=e.K[0][4],s=e.K[1],o=t.length;let i,a,c,w=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.k=[a=t.slice(0),c=[]],i=o;4*o+28>i;i++){let t=a[i-1];(i%o===0||8===o&&i%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],i%o===0&&(t=t<<8^t>>>24^w<<24,w=w<<1^283*(w>>7))),a[i]=a[i-o]^t}for(let t=0;i;t++,i--){const e=a[3&t?i:i-4];c[t]=4>=i||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.L(t,0)}decrypt(t){return this.L(t,1)}j(){const t=this.K[0],e=this.K[1],n=t[4],s=e[4],r=[],o=[];let i,a,c,w;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let f=i=0;!n[f];f^=a||1,i=o[i]||1){let o=i^i<<1^i<<2^i<<3^i<<4;o=o>>8^255&o^99,n[f]=o,s[o]=f,w=r[c=r[a=r[f]]];let l=16843009*w^65537*c^257*a^16843008*f,u=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][f]=u=u<<24^u>>>8,e[n][o]=l=l<<24^l>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}L(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.k[e],s=n.length/4-2,o=[0,0,0,0],i=this.K[e],a=i[0],c=i[1],w=i[2],f=i[3],l=i[4];let u,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],g=t[e?1:3]^n[3],S=4;for(let t=0;s>t;t++)u=a[d>>>24]^c[y>>16&255]^w[m>>8&255]^f[255&g]^n[S],h=a[y>>>24]^c[m>>16&255]^w[g>>8&255]^f[255&d]^n[S+1],p=a[m>>>24]^c[g>>16&255]^w[d>>8&255]^f[255&y]^n[S+2],g=a[g>>>24]^c[d>>16&255]^w[y>>8&255]^f[255&m]^n[S+3],S+=4,d=u,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=l[d>>>24]<<24^l[y>>16&255]<<16^l[m>>8&255]<<8^l[255&g]^n[S++],u=d,d=y,y=m,m=g,g=u;return o}},st=class{constructor(t,e){this.O=t,this.H=e,this.Z=e}reset(){this.Z=this.H}update(t){return this.F(this.O,t,this.Z)}N(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}q(t){0===(t[0]=this.N(t[0]))&&(t[1]=this.N(t[1]))}F(t,e,n){let s;if(!(s=e.length))return[];const r=V.l(e);for(let r=0;s>r;r+=4){this.q(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return V.u(e,r)}},rt=T.D;let ot=Y&&tt&&typeof $.importKey==v,it=Y&&tt&&typeof $.deriveBits==v;class at extends d{constructor({password:t,rawPassword:n,encryptionStrength:s,checkPasswordOnly:i}){super({start(){e.assign(this,{ready:new l(t=>this.G=t),password:lt(t,n),J:s-1,pending:new o})},async transform(t,e){const n=this,{password:s,J:a,G:c,ready:w}=n;s?(await(async(t,e,n,s)=>{const o=await ft(t,e,n,ht(s,0,G[e])),i=ht(s,G[e]);if(o[0]!=i[0]||o[1]!=i[1])throw new r(j)})(n,a,s,ht(t,0,G[a]+2)),t=ht(t,G[a]+2),i?e.error(new r(L)):c()):await w;const f=new o(t.length-Q-(t.length-Q)%H);e.enqueue(wt(n,t,f,0,Q,!0))},async flush(t){const{X:e,Y:n,pending:s,ready:i}=this;if(n&&e){await i;const a=ht(s,0,s.length-Q),c=ht(s,s.length-Q);let w=new o;if(a.length){const t=dt(et,a);n.update(t);const s=e.update(t);w=pt(et,s)}const f=ht(pt(et,n.digest()),0,Q);let l=s.length<Q?1:0;for(let t=0;Q>t;t++)l|=f[t]^c[t];if(l)throw new r(E);t.enqueue(w)}}})}}class ct extends d{constructor({password:t,rawPassword:n,encryptionStrength:s}){let r;super({start(){e.assign(this,{ready:new l(t=>this.G=t),password:lt(t,n),J:s-1,pending:new o})},async transform(t,e){const n=this,{password:s,J:r,G:i,ready:a}=n;let c=new o;s?(c=await(async(t,e,n)=>{const s=O(new o(G[e]));return ut(s,await ft(t,e,n,s))})(n,r,s),i()):await a;const w=new o(c.length+t.length-t.length%H);w.set(c,0),e.enqueue(wt(n,t,w,c.length,0))},async flush(t){const{X:e,Y:n,pending:s,ready:i}=this;if(n&&e){await i;let a=new o;if(s.length){const t=e.update(dt(et,s));n.update(t),a=pt(et,t)}r.signature=pt(et,n.digest()).slice(0,Q),t.enqueue(ut(a,r.signature))}}}),r=this}}function wt(t,e,n,s,r,i){const{X:a,Y:c,pending:w}=t;w.length&&(e=ut(w,e));const f=e.length-r;let l;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(f-f%H)),l=0;f-H>=l;l+=H){const t=dt(et,ht(e,l,l+H));i&&c.update(t);const r=a.update(t);i||c.update(r),n.set(pt(et,r),l+s)}return t.pending=ht(e,l),n}async function ft(n,s,r,i){n.password=null;const a=await(async(t,e,n,s,r)=>{if(!ot)return T.importKey(e);try{return await $.importKey("raw",e,n,!1,r)}catch{return ot=!1,T.importKey(e)}})(0,r,F,0,q),c=await(async(t,e,n)=>{if(!it)return T.M(e,t.salt,N.iterations,n);try{return await $.deriveBits(t,e,n)}catch{return it=!1,T.M(e,t.salt,N.iterations,n)}})(e.assign({salt:i},N),a,8*(2*J[s]+2)),w=new o(c),f=dt(et,ht(w,0,J[s])),l=dt(et,ht(w,J[s],2*J[s])),u=ht(w,2*J[s]);return e.assign(n,{keys:{key:f,$:l,passwordVerification:u},X:new st(new nt(f),t.from(X)),Y:new rt(l)}),u}function lt(t,e){return e===b?(t=>{if(typeof u==k){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new u).encode(t)})(t):e}function ut(t,e){let n=t;return t.length+e.length&&(n=new o(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function ht(t,e,n){return t.subarray(e,n)}function pt(t,e){return t.p(e)}function dt(t,e){return t.m(e)}class yt extends d{constructor({password:t,rawPassword:n,passwordVerification:s,checkPasswordOnly:o}){super({start(){e.assign(this,{password:t,rawPassword:n,passwordVerification:s}),bt(this,t,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=gt(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e.at(-1)^n.passwordVerification))throw new r(j);t=t.subarray(12)}o?e.error(new r(L)):e.enqueue(gt(n,t))}})}}class mt extends d{constructor({password:t,rawPassword:n,passwordVerification:s}){super({start(){e.assign(this,{password:t,rawPassword:n,passwordVerification:s}),bt(this,t,n)},transform(t,e){const n=this;let s,r;if(n.password||n.rawPassword){n.password=n.rawPassword=null;const e=O(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(St(n,e),0),r=12}else s=new o(t.length),r=0;s.set(St(n,t),r),e.enqueue(s)}})}}function gt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=vt(t)^e[s],kt(t,n[s]);return n}function St(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=vt(t)^e[s],kt(t,e[s]);return n}function bt(t,n,s){const r=[305419896,591751049,878082192];if(e.assign(t,{keys:r,tt:new D(r[0]),et:new D(r[2])}),s)for(let e=0;e<s.length;e++)kt(t,s[e]);else for(let e=0;e<n.length;e++)kt(t,n.charCodeAt(e))}function kt(t,e){let[,n]=t.keys;t.tt.append([e]);const r=~t.tt.get();n=Ct(s.imul(Ct(n+zt(r)),134775813)+1),t.et.append([n>>>24]);const o=~t.et.get();t.keys=[r,n,o]}function vt(t){const e=2|t.keys[2];return zt(s.imul(e,1^e)>>>8)}function zt(t){return 255&t}function Ct(t){return 4294967295&t}class It extends d{constructor(t,{chunkSize:e,nt:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:i,zipCrypto:a,signed:c,level:w,deflate64:l}=t,u=this;let h,p,d,y=super.readable;const m=c&&r&&!l&&(!o||a)&&!(!i||!s);o&&!a||!c||m||(h=new M,y=Ut(y,h)),r&&(m?(d=new At,y=Wt(y,new s("gzip")),y=Ut(y,d)):y=Rt(y,i,{level:w,chunkSize:e},s,n,s)),o&&(a?y=Ut(y,new mt(t)):(p=new ct(t),y=Ut(y,p))),Pt(u,y,()=>{let t;o&&!a&&(t=p.signature),o&&!a||!c||(t=m?d.signature:new f(h.value.buffer).getUint32(0)),u.signature=t})}}class At extends d{constructor(){let t,e=10,n=new o(0);super({transform(t,r){if(e){const n=s.min(e,t.length);if(e-=n,!(t=t.subarray(n)).length)return}const i=n.length+t.length;if(8>=i){const e=new o(i);return e.set(n),e.set(t,n.length),void(n=e)}const a=i-8,c=new o(a),w=s.min(a,n.length);c.set(n.subarray(0,w),0),a>w&&c.set(t.subarray(0,a-w),w),r.enqueue(c);const f=new o(8),l=n.length-w;l&&f.set(n.subarray(w),0),f.set(t.subarray(a-w),l),n=f},flush(){const e=new f(n.buffer,n.byteOffset,n.byteLength);t.signature=e.getUint32(0,!0),t.st=e.getUint32(4,!0)}}),t=this}}class xt extends d{constructor(t,{chunkSize:e,rt:n,DecompressionStream:s}){super({});const{zipCrypto:o,encrypted:i,signed:a,signature:c,compressed:w,useCompressionStream:l,deflate64:u}=t;let h,p,d=super.readable;i&&(o?d=Ut(d,new yt(t)):(p=new at(t),d=Ut(d,p))),w&&(d=Rt(d,l,{chunkSize:e,deflate64:u},s,n,s),d=(t=>{const e=t.getReader();return new y({async pull(t){let n;try{n=await e.read()}catch(t){if(t&&t.message)throw t;const e=new r("Invalid compressed data");throw e.cause=t,e}const{value:s,done:o}=n;o?t.close():t.enqueue(s)},cancel:t=>e.cancel(t)})})(d)),i&&!o||!a||(h=new M,d=Ut(d,h)),Pt(this,d,()=>{if((!i||o)&&a){const t=new f(h.value.buffer);if(c!=t.getUint32(0,!1))throw new r(E)}})}}function Pt(t,n,s){n=Ut(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Rt(t,e,n,s,r,o){const i=e&&s?s:r||o,a=n.deflate64?"deflate64-raw":"deflate-raw";let c;try{c=new i(a,n)}catch(t){if(!e)throw t;if(r)c=new r(a,n);else{if(!o)throw t;c=new o(a,n)}}return Wt(t,c)}function Ut(t,e){return t.pipeThrough(e)}function Wt(t,e){const n=e.writable.getWriter(),s=t.getReader();return(async()=>{try{for(;;){await n.ready;const t=await s.read();if(t.done){await n.close();break}await n.write(t.value)}}catch(t){await(async(t,e)=>{try{await t.abort(e)}catch{}})(n,t),await(async(t,e)=>{try{await t.cancel(e)}catch{}})(s,t)}})(),e.readable}const Dt="data",Mt="close";class Vt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let i;o.startsWith("deflate")?i=It:o.startsWith("inflate")&&(i=xt),s.outputSize=0;let a=0;const c=new i(t,n),w=super.readable,f=new d({transform(t,e){t&&t.length&&(a+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:a})}}),l=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize!==b&&s.outputSize>t.outputSize))throw new r("Invalid uncompressed size")},flush(){const{signature:t}=c;e.assign(s,{signature:t,inputSize:a})}});e.defineProperty(s,"readable",{get:()=>w.pipeThrough(f).pipeThrough(c).pipeThrough(l)})}}class _t extends d{constructor(t){let e;1>t&&(t=65536),super({transform:(n,s)=>{if(e){const t=new o(e.length+n.length);t.set(e),t.set(n,e.length),n=t,e=null}let r=0;for(;n.length-r>t;)s.enqueue(n.slice(r,r+t)),r+=t;e=r?n.slice(r):n},flush(t){e&&e.length&&t.enqueue(e)}})}}let Bt=2;try{typeof navigator!=k&&navigator.hardwareConcurrency&&(Bt=navigator.hardwareConcurrency)}catch{}const Tt={ot:"./core/web-worker-wasm.js",wasmURI:"./core/streams/zlib-wasm/zlib-streams.wasm",chunkSize:65536,it:Bt,ct:5e3,wt:5e3,ft:!0,useCompressionStream:!0,CompressionStream:typeof g!=k&&g,DecompressionStream:typeof S!=k&&S};e.assign({},Tt);const Kt=new w,jt=new w;let Et,Lt,Ot,Ht,Zt,Ft=0;async function Nt(t){let e,r;try{const{options:o,config:i}=t;if(!o.useCompressionStream)try{await self.initModule(t.config)}catch{o.useCompressionStream=!0}i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream;const a={highWaterMark:1},c=t.readable||new y({async pull(t){const e=new l(t=>Kt.set(Ft,t));qt({type:"pull",messageId:Ft}),Ft=(Ft+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},a);r=t.writable||new m({async write(t){let e;const s=new l(t=>e=t);jt.set(Ft,e),qt({type:Dt,value:t,messageId:Ft}),Ft=(Ft+1)%n.MAX_SAFE_INTEGER,await s}},a),e=new Vt(o,i),Et=new AbortController;const{signal:w}=Et;await c.pipeThrough(e).pipeThrough(new _t((t=>s.max(t.chunkSize,64))(i))).pipeTo(r,{signal:w,preventClose:!0,preventAbort:!0}),await r.getWriter().close();const{signature:f,inputSize:u,outputSize:h}=e;qt({type:Mt,result:{signature:f,inputSize:u,outputSize:h}})}catch(t){if(t.outputSize=e?e.outputSize:0,r&&!r.locked)try{await r.getWriter().close()}catch{}Gt(t)}}function qt(t){let{value:e}=t;if(e)if(e.length)try{e=new o(e),t.value=e.buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t)}function Gt(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:i}=t;p({error:{message:e,stack:n,code:s,name:o,outputSize:i}})}function Jt(t,e,n={}){const i="number"==typeof n.level?n.level:-1,a="number"==typeof n.lt?n.lt:65536,c="number"==typeof n.ut?n.ut:65536;return new d({start(){try{let n;if(this.ht=Ot(a),this.in=Ot(c),this.ut=c,!this.ht||!this.in)throw new r("allocation failed");if(this.dt=new o(a),t?(this.yt=Lt.deflate_process,this.gt=Lt.deflate_last_consumed,this.St=Lt.deflate_end,this.bt=Lt.deflate_new(),n="gzip"===e?Lt.deflate_init_gzip(this.bt,i):"deflate-raw"===e?Lt.deflate_init_raw(this.bt,i):Lt.deflate_init(this.bt,i)):"deflate64-raw"===e?(this.yt=Lt.inflate9_process,this.gt=Lt.inflate9_last_consumed,this.St=Lt.inflate9_end,this.bt=Lt.inflate9_new(),n=Lt.inflate9_init_raw(this.bt)):(this.yt=Lt.inflate_process,this.gt=Lt.inflate_last_consumed,this.St=Lt.inflate_end,this.bt=Lt.inflate_new(),n="deflate-raw"===e?Lt.inflate_init_raw(this.bt):"gzip"===e?Lt.inflate_init_gzip(this.bt):Lt.inflate_init(this.bt)),0!==n)throw new r("init failed:"+n)}catch(t){throw w(this),t}},transform(e,n){try{const i=e,c=new o(Zt.buffer),w=this.yt,f=this.gt,l=this.ht,u=this.dt;let h=0;for(;h<i.length;){const e=s.min(i.length-h,32768);if((!this.in||this.ut<e)&&(this.in&&Ht&&(Ht(this.in),this.in=0),this.in=Ot(e),this.ut=e,!this.in))throw new r("allocation failed");c.set(i.subarray(h,h+e),this.in);const o=w(this.bt,this.in,e,l,a,0),p=16777215&o;if(p&&(u.set(c.subarray(l,l+p),0),n.enqueue(u.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=f(this.bt);if(0===d)break;h+=d}}catch(t){w(this),n.error(t)}},flush(e){try{const n=new o(Zt.buffer),s=this.yt,i=this.ht,c=this.dt;for(;;){const o=s(this.bt,0,0,i,a,4),w=16777215&o,f=o>>24&255;if(!t){const t=128&f?f-256:f;if(0>t)throw new r("process error:"+t)}if(w&&(c.set(n.subarray(i,i+w),0),e.enqueue(c.slice(0,w))),1===f||0===w)break}}catch(t){e.error(t)}finally{const t=w(this);0!==t&&e.error(new r("end error:"+t))}},cancel(){w(this)}});function w(t){let e=0;return t.bt&&t.St&&(e=t.St(t.bt)),t.bt=0,t.in&&Ht&&Ht(t.in),t.in=0,t.ht&&Ht&&Ht(t.ht),t.ht=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&Nt(t),e==Dt){const t=Kt.get(n);Kt.delete(n),t({value:new o(s),done:r})}if("ack"==e){const t=jt.get(n);jt.delete(n),t()}e==Mt&&Et.abort()}catch(t){Gt(t)}});class Qt{constructor(t="deflate",e){return Jt(!0,t,e)}}class Xt{constructor(t="deflate",e){return Jt(!1,t,e)}}Qt.kt=!0,Xt.kt=!0;let Yt=!1;self.initModule=async t=>{try{const e=await(async(t,{baseURI:e})=>{if(!Yt){let n,s;try{try{s=new URL(t,e)}catch{}const r=await fetch(s);n=await r.arrayBuffer()}catch(e){if(!t.startsWith("data:application/wasm;base64,"))throw e;n=(t=>{const e=t.split(",")[1],n=atob(e),s=n.length,r=new o(s);for(let t=0;s>t;++t)r[t]=n.charCodeAt(t);return r.buffer})(t)}(t=>{if(Lt=t,({malloc:Ot,free:Ht,memory:Zt}=Lt),"function"!=typeof Ot||"function"!=typeof Ht||!Zt)throw Lt=Ot=Ht=Zt=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports),Yt=!0}})(t.wasmURI,t);return t.nt=Qt,t.rt=Xt,e}catch{}}});\n';t({workerURI:t=>{const n="text/javascript";if(t){const t=new Blob([e],{type:n});return URL.createObjectURL(t)}return"data:"+n+","+encodeURIComponent(e)}})}export{t as configureWebWorker};
1
+ function t(t){const e='(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:i,Uint32Array:a,Int32Array:c,Map:f,DataView:l,Promise:w,TextEncoder:u,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:g,DecompressionStream:S}=self,b=void 0,k="undefined",v="function",z=new o,C=[[],[],[],[],[],[],[],[]];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)e=1&e?e>>>1^3988292384:e>>>1;C[0][t]=e}for(let t=0;256>t;t++)for(let e=1;8>e;e++){const n=C[e-1][t];C[e][t]=n>>>8^C[0][255&n]}const[I,A,x,P,R,U,W,D]=C;class M{constructor(t){this.t=t||-1}append(t){let e=0|this.t;const n=0|t.length;let s=0;if(n>=8&&t.buffer){const r=new l(t.buffer,t.byteOffset,n),o=n-8;for(;o>=s;s+=8){const t=e^r.getInt32(s,!0),n=r.getInt32(s+4,!0);e=D[255&t]^W[t>>>8&255]^U[t>>>16&255]^R[t>>>24&255]^P[255&n]^x[n>>>8&255]^A[n>>>16&255]^I[n>>>24&255]}}for(;n>s;s++)e=e>>>8^I[255&(e^t[s])];this.t=e}get(){return~this.t}}class _ extends d{constructor(){let t;const e=new M;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new l(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}const B={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=B.o(n);return 32===s?t.concat(e):B.i(e,s,0|n,t.slice(0,t.length-1))},l(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+B.o(n)},u(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=B.h(e,t[n-1]&2147483648>>e-1,1)),t},h:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,o:t=>s.round(t/1099511627776)||32,i(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=B.o(r);return s.push(B.h(e+o&31,e+o>32?n:s.pop(),1)),s}},T={bytes:{p(t){const e=B.l(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},m(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(B.h(8*(3&n),s)),e}}},V=class{constructor(t){const e=this;e.blockSize=512,e.S=[1732584193,4023233417,2562383102,271733878,3285377520],e.k=[1518500249,1859775393,2400959708,3395469782],t?(e.v=t.v.slice(0),e.C=t.C.slice(0),e.I=t.I):e.reset()}reset(){const t=this;return t.v=t.S.slice(0),t.C=[],t.I=0,t}update(t){const e=this;"string"==typeof t&&(t=T.A.m(t));const n=e.C=B.concat(e.C,t),s=e.I,o=e.I=s+B.l(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const i=new a(n);let c=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.P(i.subarray(16*c,16*(c+1))),c+=1;return n.splice(0,16*c),e}R(){const t=this;let e=t.C;const n=t.v;e=B.concat(e,[B.h(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.I/4294967296)),e.push(0|t.I);e.length;)t.P(e.splice(0,16));return t.reset(),n}U(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}P(e){const n=this,r=n.v,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let i=r[0],a=r[1],c=r[2],f=r[3],l=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.W(5,i)+n.U(t,a,c,f)+l+o[t]+n.k[s.floor(t/20)]|0;l=f,f=c,c=n.W(30,a),a=i,i=e}r[0]=r[0]+i|0,r[1]=r[1]+a|0,r[2]=r[2]+c|0,r[3]=r[3]+f|0,r[4]=r[4]+l|0}},K={importKey:t=>new K.D(T.bytes.m(t)),M(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let i,a,c,f,w;const u=new ArrayBuffer(o),h=new l(u);let p=0;const d=B;for(e=T.bytes.m(e),w=1;(o||1)>p;w++){for(i=a=t.encrypt(d.concat(e,[w])),c=1;n>c;c++)for(a=t.encrypt(a),f=0;f<a.length;f++)i[f]^=a[f];for(c=0;(o||1)>p&&c<i.length;c++)h.setInt32(p,i[c]),p+=4}return u.slice(0,s/8)},D:class{constructor(t){const e=this,n=e._=V,s=[[],[]];e.B=[new n,new n];const r=e.B[0].blockSize/32;t.length>r&&(t=(new n).update(t).R());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.B[0].update(s[0]),e.B[1].update(s[1]),e.T=new n(e.B[0])}reset(){const t=this;t.T=new t._(t.B[0]),t.V=!1}update(t){this.V=!0,this.T.update(t)}digest(){const t=this,e=t.T.R(),n=new t._(t.B[1]).update(e).R();return t.reset(),n}encrypt(t){if(this.V)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},j=typeof h!=k&&typeof h.getRandomValues==v,E="Invalid password",L="Invalid signature",O="zipjs-abort-check-password";function H(t){if(j)return h.getRandomValues(t);throw new r("Crypto API not supported")}const Z=16,F={name:"PBKDF2"},N=e.assign({hash:{name:"HMAC"}},F),q=e.assign({iterations:1e3,hash:{name:"SHA-1"}},F),G=["deriveBits"],J=[8,12,16],Q=[16,24,32],X=10,Y=[0,0,0,0],$=typeof h!=k,tt=$&&h.subtle,et=$&&typeof tt!=k,nt=T.bytes,st=class{constructor(t){const e=this;e.K=[[[],[],[],[],[]],[[],[],[],[],[]]],e.K[0][0][0]||e.j();const n=e.K[0][4],s=e.K[1],o=t.length;let i,a,c,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.k=[a=t.slice(0),c=[]],i=o;4*o+28>i;i++){let t=a[i-1];(i%o===0||8===o&&i%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],i%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),a[i]=a[i-o]^t}for(let t=0;i;t++,i--){const e=a[3&t?i:i-4];c[t]=4>=i||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.L(t,0)}decrypt(t){return this.L(t,1)}j(){const t=this.K[0],e=this.K[1],n=t[4],s=e[4],r=[],o=[];let i,a,c,f;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=i=0;!n[l];l^=a||1,i=o[i]||1){let o=i^i<<1^i<<2^i<<3^i<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,f=r[c=r[a=r[l]]];let w=16843009*f^65537*c^257*a^16843008*l,u=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=u=u<<24^u>>>8,e[n][o]=w=w<<24^w>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}L(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.k[e],s=n.length/4-2,o=[0,0,0,0],i=this.K[e],a=i[0],c=i[1],f=i[2],l=i[3],w=i[4];let u,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],g=t[e?1:3]^n[3],S=4;for(let t=0;s>t;t++)u=a[d>>>24]^c[y>>16&255]^f[m>>8&255]^l[255&g]^n[S],h=a[y>>>24]^c[m>>16&255]^f[g>>8&255]^l[255&d]^n[S+1],p=a[m>>>24]^c[g>>16&255]^f[d>>8&255]^l[255&y]^n[S+2],g=a[g>>>24]^c[d>>16&255]^f[y>>8&255]^l[255&m]^n[S+3],S+=4,d=u,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=w[d>>>24]<<24^w[y>>16&255]<<16^w[m>>8&255]<<8^w[255&g]^n[S++],u=d,d=y,y=m,m=g,g=u;return o}},rt=class{constructor(t,e){this.O=t,this.H=e,this.Z=e}reset(){this.Z=this.H}update(t){return this.F(this.O,t,this.Z)}N(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}q(t){0===(t[0]=this.N(t[0]))&&(t[1]=this.N(t[1]))}F(t,e,n){let s;if(!(s=e.length))return[];const r=B.l(e);for(let r=0;s>r;r+=4){this.q(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return B.u(e,r)}},ot=K.D;let it=$&&et&&typeof tt.importKey==v,at=$&&et&&typeof tt.deriveBits==v;class ct extends d{constructor({password:t,rawPassword:e,encryptionStrength:n,checkPasswordOnly:s}){super({start(){lt(this,t,e,n)},async transform(t,e){const n=this,{password:i,G:a,J:c,ready:f}=n;i?(await(async(t,e,n,s)=>{const o=await ut(t,e,n,dt(s,0,J[e])),i=dt(s,J[e]);if(o[0]!=i[0]||o[1]!=i[1])throw new r(E)})(n,a,i,dt(t,0,J[a]+2)),t=dt(t,J[a]+2),s?e.error(new r(O)):c()):await f;const l=new o(t.length-X-(t.length-X)%Z);e.enqueue(wt(n,t,l,0,X,!0))},async flush(t){const{X:e,Y:n,pending:s,ready:o}=this;if(n&&e){await o;const i=dt(s,0,s.length-X),a=dt(s,s.length-X);let c=z;if(i.length){const t=mt(nt,i);n.update(t);const s=e.update(t);c=yt(nt,s)}const f=dt(yt(nt,n.digest()),0,X);let l=s.length<X?1:0;for(let t=0;X>t;t++)l|=f[t]^a[t];if(l)throw new r(L);t.enqueue(c)}}})}}class ft extends d{constructor({password:t,rawPassword:e,encryptionStrength:n}){let s;super({start(){lt(this,t,e,n)},async transform(t,e){const n=this,{password:s,G:r,J:i,ready:a}=n;let c=z;s?(c=await(async(t,e,n)=>{const s=H(new o(J[e]));return pt(s,await ut(t,e,n,s))})(n,r,s),i()):await a;const f=new o(c.length+t.length-t.length%Z);f.set(c,0),e.enqueue(wt(n,t,f,c.length,0))},async flush(t){const{X:e,Y:n,pending:r,ready:o}=this;if(n&&e){await o;let i=z;if(r.length){const t=e.update(mt(nt,r));n.update(t),i=yt(nt,t)}s.signature=yt(nt,n.digest()).slice(0,X),t.enqueue(pt(i,s.signature))}}}),s=this}}function lt(t,n,s,r){e.assign(t,{ready:new w(e=>t.J=e),password:ht(n,s),G:r-1,pending:z})}function wt(t,e,n,s,r,i){const{X:a,Y:c,pending:f}=t;f.length&&(e=pt(f,e));const l=e.length-r;let w;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(l-l%Z)),w=0;l-Z>=w;w+=Z){const t=mt(nt,dt(e,w,w+Z));i&&c.update(t);const r=a.update(t);i||c.update(r),n.set(yt(nt,r),w+s)}return t.pending=dt(e,w),n}async function ut(n,s,r,i){n.password=null;const a=await(async(t,e,n,s,r)=>{if(!it)return K.importKey(e);try{return await tt.importKey("raw",e,n,!1,r)}catch{return it=!1,K.importKey(e)}})(0,r,N,0,G),c=await(async(t,e,n)=>{if(!at)return K.M(e,t.salt,q.iterations,n);try{return await tt.deriveBits(t,e,n)}catch{return at=!1,K.M(e,t.salt,q.iterations,n)}})(e.assign({salt:i},q),a,8*(2*Q[s]+2)),f=new o(c),l=mt(nt,dt(f,0,Q[s])),w=mt(nt,dt(f,Q[s],2*Q[s])),u=dt(f,2*Q[s]);return e.assign(n,{keys:{key:l,$:w,passwordVerification:u},X:new rt(new st(l),t.from(Y)),Y:new ot(w)}),u}function ht(t,e){return e===b?(t=>{if(typeof u==k){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new u).encode(t)})(t):e}function pt(t,e){let n=t;return t.length+e.length&&(n=new o(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function dt(t,e,n){return t.subarray(e,n)}function yt(t,e){return t.p(e)}function mt(t,e){return t.m(e)}class gt extends d{constructor({password:t,rawPassword:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){bt(this,t,e,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=kt(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e.at(-1)^n.passwordVerification))throw new r(E);t=t.subarray(12)}s?e.error(new r(O)):e.enqueue(kt(n,t))}})}}class St extends d{constructor({password:t,rawPassword:e,passwordVerification:n}){super({start(){bt(this,t,e,n)},transform(t,e){const n=this;let s,r;if(n.password||n.rawPassword){n.password=n.rawPassword=null;const e=H(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(vt(n,e),0),r=12}else s=new o(t.length),r=0;s.set(vt(n,t),r),e.enqueue(s)}})}}function bt(t,n,s,r){e.assign(t,{password:n,rawPassword:s,passwordVerification:r}),((t,n,s)=>{const r=[305419896,591751049,878082192];if(e.assign(t,{keys:r,tt:new M(r[0]),et:new M(r[2])}),s)for(let e=0;e<s.length;e++)zt(t,s[e]);else for(let e=0;e<n.length;e++)zt(t,n.charCodeAt(e))})(t,n,s)}function kt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,n[s]);return n}function vt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,e[s]);return n}function zt(t,e){let[,n]=t.keys;t.tt.append([e]);const r=~t.tt.get();n=At(s.imul(At(n+It(r)),134775813)+1),t.et.append([n>>>24]);const o=~t.et.get();t.keys=[r,n,o]}function Ct(t){const e=2|t.keys[2];return It(s.imul(e,1^e)>>>8)}function It(t){return 255&t}function At(t){return 4294967295&t}class xt extends d{constructor(t,{chunkSize:e,nt:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:i,zipCrypto:a,signed:c,level:f,deflate64:w}=t,u=this;let h,p,d,y=super.readable;const m=c&&r&&!w&&(!o||a)&&!(!i||!s);o&&!a||!c||m||(h=new _,y=Dt(y,h)),r&&(m?(d=new Pt,y=Mt(y,new s("gzip")),y=Dt(y,d)):y=Wt(y,i,{level:f,chunkSize:e},s,n,s)),o&&(a?y=Dt(y,new St(t)):(p=new ft(t),y=Dt(y,p))),Ut(u,y,()=>{let t;o&&!a&&(t=p.signature),o&&!a||!c||(t=m?d.signature:new l(h.value.buffer).getUint32(0)),u.signature=t})}}class Pt extends d{constructor(){let t,e=10,n=new o(0);super({transform(t,r){if(e){const n=s.min(e,t.length);if(e-=n,!(t=t.subarray(n)).length)return}const i=n.length+t.length;if(8>=i){const e=new o(i);return e.set(n),e.set(t,n.length),void(n=e)}const a=i-8,c=new o(a),f=s.min(a,n.length);c.set(n.subarray(0,f),0),a>f&&c.set(t.subarray(0,a-f),f),r.enqueue(c);const l=new o(8),w=n.length-f;w&&l.set(n.subarray(f),0),l.set(t.subarray(a-f),w),n=l},flush(){const e=new l(n.buffer,n.byteOffset,n.byteLength);t.signature=e.getUint32(0,!0),t.st=e.getUint32(4,!0)}}),t=this}}class Rt extends d{constructor(t,{chunkSize:e,rt:n,DecompressionStream:s}){super({});const{zipCrypto:o,encrypted:i,signed:a,signature:c,compressed:f,useCompressionStream:w,deflate64:u}=t;let h,p,d=super.readable;i&&(o?d=Dt(d,new gt(t)):(p=new ct(t),d=Dt(d,p))),f&&(d=Wt(d,w,{chunkSize:e,deflate64:u},s,n,s),d=(t=>{const e=t.getReader();return new y({async pull(t){let n;try{n=await e.read()}catch(t){if(t&&t.message)throw t;const e=new r("Invalid compressed data");throw e.cause=t,e}const{value:s,done:o}=n;o?t.close():t.enqueue(s)},cancel:t=>e.cancel(t)})})(d)),i&&!o||!a||(h=new _,d=Dt(d,h)),Ut(this,d,()=>{if((!i||o)&&a){const t=new l(h.value.buffer);if(c!=t.getUint32(0,!1))throw new r(L)}})}}function Ut(t,n,s){n=Dt(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Wt(t,e,n,s,r,o){const i=e&&s?s:r||o,a=n.deflate64?"deflate64-raw":"deflate-raw";let c;try{c=new i(a,n)}catch(t){if(!e)throw t;if(r)c=new r(a,n);else{if(!o)throw t;c=new o(a,n)}}return Mt(t,c)}function Dt(t,e){return t.pipeThrough(e)}function Mt(t,e){const n=e.writable.getWriter(),s=t.getReader();return(async()=>{try{for(;;){await n.ready;const t=await s.read();if(t.done){await n.close();break}await n.write(t.value)}}catch(t){await(async(t,e)=>{try{await t.abort(e)}catch{}})(n,t),await(async(t,e)=>{try{await t.cancel(e)}catch{}})(s,t)}})(),e.readable}const _t="data",Bt="close";class Tt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let i;o.startsWith("deflate")?i=xt:o.startsWith("inflate")&&(i=Rt),s.outputSize=0;let a=0;const c=new i(t,n),f=super.readable,l=new d({transform(t,e){t&&t.length&&(a+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:a})}}),w=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize!==b&&s.outputSize>t.outputSize))throw new r("Invalid uncompressed size")},flush(){const{signature:t}=c;e.assign(s,{signature:t,inputSize:a})}});e.defineProperty(s,"readable",{get:()=>f.pipeThrough(l).pipeThrough(c).pipeThrough(w)})}}class Vt extends d{constructor(t){let e;1>t&&(t=65536),super({transform:(n,s)=>{if(e){const t=new o(e.length+n.length);t.set(e),t.set(n,e.length),n=t,e=null}let r=0;for(;n.length-r>t;)s.enqueue(n.slice(r,r+t)),r+=t;e=r?n.slice(r):n},flush(t){e&&e.length&&t.enqueue(e)}})}}let Kt=2;try{typeof navigator!=k&&navigator.hardwareConcurrency&&(Kt=navigator.hardwareConcurrency)}catch{}const jt={ot:"./core/web-worker-wasm.js",wasmURI:"./core/streams/zlib-wasm/zlib-streams.wasm",chunkSize:65536,it:Kt,ct:5e3,ft:5e3,lt:!0,useCompressionStream:!0,CompressionStream:typeof g!=k&&g,DecompressionStream:typeof S!=k&&S};e.assign({},jt);const Et=new f,Lt=new f;let Ot,Ht,Zt,Ft,Nt,qt=0;async function Gt(t){let e,r;try{const{options:o,config:i}=t;if(!o.useCompressionStream)try{await self.initModule(t.config)}catch{o.useCompressionStream=!0}i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream;const a={highWaterMark:1},c=t.readable||new y({async pull(t){const e=new w(t=>Et.set(qt,t));Jt({type:"pull",messageId:qt}),qt=(qt+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},a);r=t.writable||new m({async write(t){let e;const s=new w(t=>e=t);Lt.set(qt,e),Jt({type:_t,value:t,messageId:qt}),qt=(qt+1)%n.MAX_SAFE_INTEGER,await s}},a),e=new Tt(o,i),Ot=new AbortController;const{signal:f}=Ot;await c.pipeThrough(e).pipeThrough(new Vt((t=>s.max(t.chunkSize,64))(i))).pipeTo(r,{signal:f,preventClose:!0,preventAbort:!0}),await r.getWriter().close();const{signature:l,inputSize:u,outputSize:h}=e;Jt({type:Bt,result:{signature:l,inputSize:u,outputSize:h}})}catch(t){if(t.outputSize=e?e.outputSize:0,r&&!r.locked)try{await r.getWriter().close()}catch{}Qt(t)}}function Jt(t){let{value:e}=t;if(e)if(e.length)try{e=new o(e),t.value=e.buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t)}function Qt(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:i}=t;p({error:{message:e,stack:n,code:s,name:o,outputSize:i}})}function Xt(t,e,n={}){const i="number"==typeof n.level?n.level:-1,a="number"==typeof n.outBuffer?n.outBuffer:65536,c="number"==typeof n.inBufferSize?n.inBufferSize:65536;return new d({start(){try{let n;if(this.wt=Zt(a),this.in=Zt(c),this.inBufferSize=c,!this.wt||!this.in)throw new r("allocation failed");if(this.ut=new o(a),t?(this.ht=Ht.deflate_process,this.dt=Ht.deflate_last_consumed,this.yt=Ht.deflate_end,this.gt=Ht.deflate_new(),n="gzip"===e?Ht.deflate_init_gzip(this.gt,i):"deflate-raw"===e?Ht.deflate_init_raw(this.gt,i):Ht.deflate_init(this.gt,i)):"deflate64-raw"===e?(this.ht=Ht.inflate9_process,this.dt=Ht.inflate9_last_consumed,this.yt=Ht.inflate9_end,this.gt=Ht.inflate9_new(),n=Ht.inflate9_init_raw(this.gt)):(this.ht=Ht.inflate_process,this.dt=Ht.inflate_last_consumed,this.yt=Ht.inflate_end,this.gt=Ht.inflate_new(),n="deflate-raw"===e?Ht.inflate_init_raw(this.gt):"gzip"===e?Ht.inflate_init_gzip(this.gt):Ht.inflate_init(this.gt)),0!==n)throw new r("init failed:"+n)}catch(t){throw f(this),t}},transform(e,n){try{const i=e,c=new o(Nt.buffer),f=this.ht,l=this.dt,w=this.wt,u=this.ut;let h=0;for(;h<i.length;){const e=s.min(i.length-h,32768);if((!this.in||this.inBufferSize<e)&&(this.in&&Ft&&(Ft(this.in),this.in=0),this.in=Zt(e),this.inBufferSize=e,!this.in))throw new r("allocation failed");c.set(i.subarray(h,h+e),this.in);const o=f(this.gt,this.in,e,w,a,0),p=16777215&o;if(p&&(u.set(c.subarray(w,w+p),0),n.enqueue(u.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=l(this.gt);if(0===d)break;h+=d}}catch(t){f(this),n.error(t)}},flush(e){try{const n=new o(Nt.buffer),s=this.ht,i=this.wt,c=this.ut;for(;;){const o=s(this.gt,0,0,i,a,4),f=16777215&o,l=o>>24&255;if(!t){const t=128&l?l-256:l;if(0>t)throw new r("process error:"+t)}if(f&&(c.set(n.subarray(i,i+f),0),e.enqueue(c.slice(0,f))),1===l||0===f)break}}catch(t){e.error(t)}finally{const t=f(this);0!==t&&e.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let e=0;return t.gt&&t.yt&&(e=t.yt(t.gt)),t.gt=0,t.in&&Ft&&Ft(t.in),t.in=0,t.wt&&Ft&&Ft(t.wt),t.wt=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&Gt(t),e==_t){const t=Et.get(n);Et.delete(n),t({value:new o(s),done:r})}if("ack"==e){const t=Lt.get(n);Lt.delete(n),t()}e==Bt&&Ot.abort()}catch(t){Qt(t)}});class Yt{constructor(t="deflate",e){return Xt(!0,t,e)}}class $t{constructor(t="deflate",e){return Xt(!1,t,e)}}Yt.St=!0,$t.St=!0;let te=!1;self.initModule=async t=>{try{const e=await(async(t,{baseURI:e})=>{if(!te){let n,s;try{try{s=new URL(t,e)}catch{}const r=await fetch(s);n=await r.arrayBuffer()}catch(e){if(!t.startsWith("data:application/wasm;base64,"))throw e;n=(t=>{const e=t.split(",")[1],n=atob(e),s=n.length,r=new o(s);for(let t=0;s>t;++t)r[t]=n.charCodeAt(t);return r.buffer})(t)}(t=>{if(Ht=t,({malloc:Zt,free:Ft,memory:Nt}=Ht),"function"!=typeof Zt||"function"!=typeof Ft||!Nt)throw Ht=Zt=Ft=Nt=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports),te=!0}})(t.wasmURI,t);return t.nt=Yt,t.rt=$t,e}catch{}}});\n';t({workerURI:t=>{const n="text/javascript";if(t){const t=new Blob([e],{type:n});return URL.createObjectURL(t)}return"data:"+n+","+encodeURIComponent(e)}})}export{t as configureWebWorker};
@@ -78,8 +78,6 @@ class ZipEntry {
78
78
  uncompressedSize: params.uncompressedSize || 0,
79
79
  passThrough: params.passThrough
80
80
  });
81
- // detached entries (e.g. clones) are not registered until they are attached,
82
- // otherwise they could never be garbage collected
83
81
  if (parent || !fs.root) {
84
82
  fs.entries[zipEntry.id] = zipEntry;
85
83
  }
@@ -148,7 +146,7 @@ class ZipFileEntry extends ZipEntry {
148
146
  if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data)) {
149
147
  return zipEntry.data;
150
148
  } else {
151
- const reader = zipEntry.reader = new zipEntry.Reader(zipEntry.data, options);
149
+ const reader = zipEntry.reader = createReader(zipEntry.Reader, zipEntry.data, options);
152
150
  const uncompressedSize = zipEntry.data ? zipEntry.data.uncompressedSize : reader.size;
153
151
  await Promise.all([initStream(reader), initStream(writer, uncompressedSize)]);
154
152
  const { readable } = reader;
@@ -204,11 +202,7 @@ class ZipFileEntry extends ZipEntry {
204
202
  }
205
203
 
206
204
  async getArrayBuffer(options) {
207
- // this.data may be a string, a Uint8Array, a data URI or a Blob depending on how the entry
208
- // was created, so retrieve the bytes through getUint8Array rather than assuming a Blob; this
209
- // also applies the options (password, signal, onprogress...) like the other getData() getters
210
205
  const array = await this.getUint8Array(options);
211
- // return the backing buffer directly when the array spans it, slicing the exact bytes otherwise
212
206
  return array.byteOffset || array.byteLength != array.buffer.byteLength
213
207
  ? array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength)
214
208
  : array.buffer;
@@ -578,7 +572,6 @@ class FS {
578
572
  node = node.getChildByName(path[index]);
579
573
  }
580
574
  if (!node) {
581
- // exclude detached entries, e.g. clones registered in `entries` but not attached
582
575
  node = this.entries.find(entry => entry && (entry == this.root || entry.isDescendantOf(this.root)) &&
583
576
  entry.getRelativeName() == fullname);
584
577
  }
@@ -751,10 +744,13 @@ function getZipBlobReader(options) {
751
744
  };
752
745
  }
753
746
 
747
+ function createReader(Reader, data, options) {
748
+ return Reader.prototype ? new Reader(data, options) : Reader(data, options);
749
+ }
750
+
754
751
  async function initReaders(entry, options) {
755
752
  const fileEntries = [];
756
753
  const pendingEntries = [entry];
757
- // per-export map so concurrent exports do not share (and lock) the same readers
758
754
  const readers = new Map();
759
755
  while (pendingEntries.length) {
760
756
  const pendingEntry = pendingEntries.pop();
@@ -767,7 +763,7 @@ async function initReaders(entry, options) {
767
763
  }
768
764
  }
769
765
  await Promise.all(fileEntries.map(async child => {
770
- const reader = child.reader = new child.Reader(child.data, options);
766
+ const reader = child.reader = createReader(child.Reader, child.data, options);
771
767
  readers.set(child, reader);
772
768
  try {
773
769
  await initStream(reader);
@@ -932,7 +928,6 @@ async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
932
928
  return directoryHandle;
933
929
 
934
930
  async function exportChildren(entry, parentHandle) {
935
- // Separate files have no ordering constraint, so they can be written concurrently on demand.
936
931
  if (options.concurrent) {
937
932
  const results = await Promise.allSettled(entry.children.map(child => exportChild(child, parentHandle)));
938
933
  const failedResult = results.find(result => result.status == "rejected");
@@ -954,8 +949,6 @@ async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
954
949
  } else {
955
950
  const fileHandle = await parentHandle.getFileHandle(child.name, { create: true });
956
951
  const writable = await fileHandle.createWritable();
957
- // getData() streams the entry's data into `writable` and closes it (a FileSystemWritableFileStream
958
- // only commits the file on close), applying options such as password, signal and onprogress.
959
952
  await child.getData({ writable }, Object.assign({}, options, {
960
953
  onprogress: async progress => {
961
954
  if (options.onprogress) {
@@ -82,7 +82,8 @@ import {
82
82
  COMPRESSION_METHOD_DEFLATE_64,
83
83
  FILE_ATTR_UNIX_SETUID_MASK,
84
84
  FILE_ATTR_UNIX_SETGID_MASK,
85
- FILE_ATTR_UNIX_STICKY_MASK
85
+ FILE_ATTR_UNIX_STICKY_MASK,
86
+ EMPTY_UINT8_ARRAY
86
87
  } from "./constants.js";
87
88
  import {
88
89
  getConfiguration,
@@ -164,8 +165,6 @@ const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
164
165
  const CHARSET_UTF8 = "utf-8";
165
166
  const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
166
167
  const CHARSET_CP437 = "cp437";
167
- // bits of the general purpose flag that change how an entry is interpreted; the level bits (1-2) are excluded
168
- // because they are informative only
169
168
  const BITFLAG_AMBIGUITY_MASK = BITFLAG_ENCRYPTED | BITFLAG_DATA_DESCRIPTOR | BITFLAG_LANG_ENCODING_FLAG;
170
169
  const ZIP64_PROPERTIES = [
171
170
  [PROPERTY_NAME_UNCOMPRESSED_SIZE, MAX_32_BITS],
@@ -207,7 +206,6 @@ class ZipReader {
207
206
  if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
208
207
  throw new Error(ERR_BAD_FORMAT);
209
208
  }
210
- reader.chunkSize = getChunkSize(config);
211
209
  const strictness = getStrictness(getOptionValue(zipReader, options, OPTION_STRICTNESS), getOptionValue(zipReader, options, OPTION_CHECK_AMBIGUITY));
212
210
  const checkAmbiguity = strictness == STRICTNESS_STRICT;
213
211
  const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
@@ -222,8 +220,6 @@ class ZipReader {
222
220
  throw new Error(ERR_EOCDR_NOT_FOUND);
223
221
  }
224
222
  }
225
- // two or more end-anchored records that each dereference to a valid central directory cannot be told
226
- // apart (see comment_length ⟺ EOF): the archive is genuinely ambiguous, so refuse rather than guess
227
223
  if (rejectAmbiguousEndOfDirectory && endOfDirectoryReachingEndCount > 1) {
228
224
  throwAmbiguousArchive("multiple end of central directory records");
229
225
  }
@@ -246,7 +242,7 @@ class ZipReader {
246
242
  if (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS) {
247
243
  const endOfDirectoryLocatorArray = endOfDirectoryInfo.offset >= ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH ?
248
244
  await readUint8Array(reader, endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH) :
249
- new Uint8Array();
245
+ EMPTY_UINT8_ARRAY;
250
246
  const endOfDirectoryLocatorView = getDataView(endOfDirectoryLocatorArray);
251
247
  if (endOfDirectoryLocatorArray.length == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH &&
252
248
  getUint32(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
@@ -313,12 +309,6 @@ class ZipReader {
313
309
  }
314
310
  const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength - (reader.lastDiskOffset || 0);
315
311
  if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
316
- // the reconciled offset (the directory ends exactly where the canonical record begins) is anchored
317
- // to the unforgeable end of the archive; the stored offset is not. Prefer the reconciled offset
318
- // unless the stored one points at a directory and the reconciled one does not — that exception
319
- // keeps a corrupt declared directory length from sending the read astray, while still moving off a
320
- // stored offset that only looks valid because an append remnant left the previous (identically
321
- // laid out) directory sitting there.
322
312
  const storedPointsAtDirectory = getUint32(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
323
313
  let reconcile = !storedPointsAtDirectory;
324
314
  if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
@@ -475,11 +465,11 @@ class ZipReader {
475
465
  const extractPrependedData = getOptionValue(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
476
466
  const extractAppendedData = getOptionValue(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
477
467
  if (extractPrependedData) {
478
- zipReader.prependedData = startOffset > 0 ? await readUint8Array(reader, 0, startOffset) : new Uint8Array();
468
+ zipReader.prependedData = startOffset > 0 ? await readUint8Array(reader, 0, startOffset) : EMPTY_UINT8_ARRAY;
479
469
  }
480
- zipReader.comment = commentLength ? await readUint8Array(reader, commentOffset + END_OF_CENTRAL_DIR_LENGTH, commentLength) : new Uint8Array();
470
+ zipReader.comment = commentLength ? await readUint8Array(reader, commentOffset + END_OF_CENTRAL_DIR_LENGTH, commentLength) : EMPTY_UINT8_ARRAY;
481
471
  if (extractAppendedData) {
482
- zipReader.appendedData = appendedDataOffset < reader.size ? await readUint8Array(reader, appendedDataOffset, reader.size - appendedDataOffset) : new Uint8Array();
472
+ zipReader.appendedData = appendedDataOffset < reader.size ? await readUint8Array(reader, appendedDataOffset, reader.size - appendedDataOffset) : EMPTY_UINT8_ARRAY;
483
473
  }
484
474
  return true;
485
475
  }
@@ -612,7 +602,7 @@ class ZipEntry {
612
602
  filenameLength
613
603
  } = localDirectory;
614
604
  const checkAmbiguity = getStrictness(getOptionValue(zipEntry, options, OPTION_STRICTNESS), getOptionValue(zipEntry, options, OPTION_CHECK_AMBIGUITY)) == STRICTNESS_STRICT;
615
- let rawLocalFilename = new Uint8Array();
605
+ let rawLocalFilename = EMPTY_UINT8_ARRAY;
616
606
  if (checkAmbiguity && (filenameLength || extraFieldLength)) {
617
607
  const trailingDataArray = await readUint8Array(reader, offset + HEADER_SIZE, filenameLength + extraFieldLength, diskNumberStart);
618
608
  rawLocalFilename = trailingDataArray.subarray(0, filenameLength);
@@ -620,7 +610,7 @@ class ZipEntry {
620
610
  } else {
621
611
  localDirectory.rawExtraField = extraFieldLength ?
622
612
  await readUint8Array(reader, offset + HEADER_SIZE + filenameLength, extraFieldLength, diskNumberStart) :
623
- new Uint8Array();
613
+ EMPTY_UINT8_ARRAY;
624
614
  }
625
615
  readCommonFooter(zipEntry, localDirectory, dataView, 4, true);
626
616
  if (checkAmbiguity) {
@@ -647,12 +637,7 @@ class ZipEntry {
647
637
  }
648
638
  const dataOffset = offset + HEADER_SIZE + filenameLength + extraFieldLength;
649
639
  const size = compressedSize;
650
- const readable = reader.readable;
651
- Object.assign(readable, {
652
- diskNumberStart,
653
- offset: dataOffset,
654
- size
655
- });
640
+ const readable = reader.createReadable({ offset: dataOffset, size, diskNumberStart, chunkSize: getChunkSize(config) });
656
641
  const signal = getOptionValue(zipEntry, options, OPTION_SIGNAL);
657
642
  const checkPasswordOnly = getOptionValue(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
658
643
  let checkOverlappingEntry = getOptionValue(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
@@ -923,7 +908,6 @@ function readExtraFieldUnix(extraField, directory, isInfoZip) {
923
908
  const view = getDataView(new Uint8Array(extraField.data));
924
909
  let uid, gid;
925
910
  if (isInfoZip) {
926
- // Info-ZIP New Unix "ux" field (0x7875): version + variable-length uid/gid
927
911
  let offset = 0;
928
912
  const version = getUint8(view, offset++);
929
913
  const uidSize = getUint8(view, offset++);
@@ -933,8 +917,6 @@ function readExtraFieldUnix(extraField, directory, isInfoZip) {
933
917
  gid = unpackUnixId(extraField.data.subarray(offset, offset + gidSize));
934
918
  Object.assign(extraField, { version, uid, gid });
935
919
  } else if (extraField.data.length >= 4) {
936
- // Info-ZIP Unix "Ux" field (0x7855): fixed 2-byte uid + gid (the file mode, if any, is
937
- // carried in the external file attributes, not here)
938
920
  uid = getUint16(view, 0);
939
921
  gid = getUint16(view, 2);
940
922
  Object.assign(extraField, { uid, gid });
@@ -986,7 +968,6 @@ function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory,
986
968
  timeProperties.forEach((propertyName, indexProperty) => {
987
969
  if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
988
970
  const time = getUint32(extraFieldView, offset);
989
- // the extended timestamp is a signed 32-bit time_t value
990
971
  directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date((time | 0) * 1000);
991
972
  const rawPropertyName = timeRawProperties[indexProperty];
992
973
  extraFieldExtendedTimestamp[rawPropertyName] = time;
@@ -1063,7 +1044,6 @@ async function detectOverlappingEntry({
1063
1044
 
1064
1045
  function getStrictness(strictness, checkAmbiguity) {
1065
1046
  if (strictness === UNDEFINED_VALUE) {
1066
- // `checkAmbiguity: true` is kept as a backward-compatible alias for the strictest mode
1067
1047
  return checkAmbiguity ? STRICTNESS_STRICT : STRICTNESS_BALANCED;
1068
1048
  }
1069
1049
  return strictness;
@@ -1074,81 +1054,45 @@ function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
1074
1054
  return maxAppendedDataSize;
1075
1055
  }
1076
1056
  if (strictness == STRICTNESS_STRICT) {
1077
- // the comment must reach the end of the file: no trailing data tolerated
1078
1057
  return 0;
1079
1058
  }
1080
1059
  if (strictness == STRICTNESS_TOLERANT) {
1081
1060
  return Infinity;
1082
1061
  }
1083
- // balanced: tolerate up to a legal comment's worth of trailing data (a 16-bit length); beyond that the
1084
- // trailing bytes cannot hide inside a comment, so they are treated as a second thing bolted onto the file
1085
1062
  return MAX_16_BITS;
1086
1063
  }
1087
1064
 
1088
- // cap on how many out-of-window central directory probes the scan below may issue. A legitimate archive needs
1089
- // at most a couple (the canonical record, plus one more to detect genuine ambiguity); every other reachability
1090
- // check is served from the tail window already in memory. The cap keeps an archive whose comment is stuffed
1091
- // with unreachable end-anchored records from forcing an unbounded number of (potentially remote) reads.
1092
1065
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
1093
1066
 
1094
- // reachability rankings for an end-anchored candidate record (see getCentralDirectoryReachability)
1095
1067
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
1096
1068
  const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
1097
1069
  const CENTRAL_DIRECTORY_REACHABLE = 2;
1098
1070
 
1099
- // Locates the authoritative end of central directory record. The canonical record is the last one whose
1100
- // declared comment reaches exactly the end of the file ("end-anchored") and that points to a central directory
1101
- // ("reachable"); earlier signatures (stale append remnants, bytes embedded in a comment) are ignored. When two
1102
- // or more end-anchored records point to a central directory the archive is ambiguous, and the count is returned
1103
- // so the caller can refuse it. A record that reaches the end of the file but points to no central directory (an
1104
- // empty archive) is only "plausible": it cannot be corroborated, so it never counts towards ambiguity and is
1105
- // chosen only when no reachable record exists — otherwise an empty record forged in a comment could outrank the
1106
- // genuine directory. When no record is end-anchored (appended data or an oversized comment), falls back to the
1107
- // last record within the tolerated window that points to a directory (see seekEndOfCentralDirectory).
1108
1071
  async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDataSize) {
1109
1072
  const { size } = reader;
1110
- // an end-anchored record can only live within the last END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS bytes,
1111
- // since the comment length that ties it to the end of the file is a 16-bit field
1112
1073
  const anchoredLength = Math.min(size, END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS);
1113
- const anchoredOffset = size - anchoredLength;
1114
- const anchoredArray = await readUint8Array(reader, anchoredOffset, anchoredLength);
1115
- const anchoredView = getDataView(anchoredArray);
1116
1074
  const remoteProbeBudget = { count: MAX_END_OF_CENTRAL_DIR_PROBES };
1117
1075
  let endOfDirectoryInfo;
1118
1076
  let plausibleEndOfDirectoryInfo;
1119
1077
  let endOfDirectoryReachingEndCount = 0;
1120
- for (let indexByte = anchoredArray.length - END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
1121
- if (getUint32(anchoredView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
1122
- const offset = anchoredOffset + indexByte;
1123
- const commentLength = getUint16(anchoredView, indexByte + 20);
1124
- // end-anchored: the declared comment extends exactly to the end of the file. The comment length is
1125
- // attacker-controlled, but the reconciliation against the (unforgeable) end of file is not.
1126
- if (offset + END_OF_CENTRAL_DIR_LENGTH + commentLength == size) {
1127
- const reachability = await getCentralDirectoryReachability(reader, anchoredView, anchoredOffset, indexByte, offset, size, remoteProbeBudget);
1128
- if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
1129
- if (!endOfDirectoryInfo) {
1130
- endOfDirectoryInfo = {
1131
- offset,
1132
- buffer: anchoredArray.slice(indexByte, indexByte + END_OF_CENTRAL_DIR_LENGTH).buffer
1133
- };
1134
- }
1135
- endOfDirectoryReachingEndCount++;
1136
- // the canonical record (highest offset) is found first; a second one is enough to flag ambiguity
1137
- if (!rejectAmbiguous || endOfDirectoryReachingEndCount > 1) {
1138
- break;
1139
- }
1140
- } else if (reachability == CENTRAL_DIRECTORY_PLAUSIBLE && !plausibleEndOfDirectoryInfo) {
1141
- plausibleEndOfDirectoryInfo = {
1142
- offset,
1143
- buffer: anchoredArray.slice(indexByte, indexByte + END_OF_CENTRAL_DIR_LENGTH).buffer
1144
- };
1078
+ for await (const [anchoredView, anchoredOffset, anchoredArray, indexByte, offset] of scanEndOfCentralDirectory(reader, anchoredLength)) {
1079
+ const commentLength = getUint16(anchoredView, indexByte + 20);
1080
+ if (offset + END_OF_CENTRAL_DIR_LENGTH + commentLength == size) {
1081
+ const reachability = await getCentralDirectoryReachability(reader, anchoredView, anchoredOffset, indexByte, offset, size, remoteProbeBudget);
1082
+ if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
1083
+ if (!endOfDirectoryInfo) {
1084
+ endOfDirectoryInfo = getEndOfCentralDirectoryInfo(anchoredArray, indexByte, offset);
1145
1085
  }
1086
+ endOfDirectoryReachingEndCount++;
1087
+ if (!rejectAmbiguous || endOfDirectoryReachingEndCount > 1) {
1088
+ break;
1089
+ }
1090
+ } else if (reachability == CENTRAL_DIRECTORY_PLAUSIBLE && !plausibleEndOfDirectoryInfo) {
1091
+ plausibleEndOfDirectoryInfo = getEndOfCentralDirectoryInfo(anchoredArray, indexByte, offset);
1146
1092
  }
1147
1093
  }
1148
1094
  }
1149
1095
  if (!endOfDirectoryInfo) {
1150
- // no record points to a directory: prefer a plausible (empty) end-anchored record before scanning the
1151
- // tolerated window for a bare signature
1152
1096
  endOfDirectoryInfo = plausibleEndOfDirectoryInfo;
1153
1097
  }
1154
1098
  if (!endOfDirectoryInfo) {
@@ -1157,69 +1101,53 @@ async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDat
1157
1101
  return { endOfDirectoryInfo, endOfDirectoryReachingEndCount };
1158
1102
  }
1159
1103
 
1160
- // Fallback for findEndOfCentralDirectory when no record is end-anchored: appended data or an oversized comment
1161
- // pushed the record's declared comment past the end of the file, so its position can no longer be reconciled
1162
- // against the end of the file. Scans the tolerated window from the end and returns the first record that points
1163
- // to a central directory, so a stray signature embedded in appended data cannot hijack discovery (which the
1164
- // anchored scan already prevents for anchored records). Falls back to the first plausible (empty) record, then
1165
- // to the last bare signature, so a degenerate archive still opens as before. The window ends at the file, so the
1166
- // same in-window / metered reads as the anchored scan apply.
1167
1104
  async function seekEndOfCentralDirectory(reader, maxAppendedDataSize, remoteProbeBudget) {
1168
1105
  const { size } = reader;
1169
1106
  const searchLength = Math.min(size, maxAppendedDataSize == Infinity ? size :
1170
1107
  END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS + maxAppendedDataSize);
1171
- const searchOffset = size - searchLength;
1172
- const searchArray = await readUint8Array(reader, searchOffset, searchLength);
1173
- const searchView = getDataView(searchArray);
1174
1108
  let firstSignatureInfo, plausibleInfo;
1175
- for (let indexByte = searchArray.length - END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
1176
- if (getUint32(searchView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
1177
- const offset = searchOffset + indexByte;
1178
- const record = { offset, buffer: searchArray.slice(indexByte, indexByte + END_OF_CENTRAL_DIR_LENGTH).buffer };
1179
- if (!firstSignatureInfo) {
1180
- firstSignatureInfo = record;
1181
- }
1182
- const reachability = await getCentralDirectoryReachability(reader, searchView, searchOffset, indexByte, offset, size, remoteProbeBudget);
1183
- if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
1184
- return record;
1185
- }
1186
- if (reachability == CENTRAL_DIRECTORY_PLAUSIBLE && !plausibleInfo) {
1187
- plausibleInfo = record;
1188
- }
1109
+ for await (const [searchView, searchOffset, searchArray, indexByte, offset] of scanEndOfCentralDirectory(reader, searchLength)) {
1110
+ const record = getEndOfCentralDirectoryInfo(searchArray, indexByte, offset);
1111
+ if (!firstSignatureInfo) {
1112
+ firstSignatureInfo = record;
1113
+ }
1114
+ const reachability = await getCentralDirectoryReachability(reader, searchView, searchOffset, indexByte, offset, size, remoteProbeBudget);
1115
+ if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
1116
+ return record;
1117
+ }
1118
+ if (reachability == CENTRAL_DIRECTORY_PLAUSIBLE && !plausibleInfo) {
1119
+ plausibleInfo = record;
1189
1120
  }
1190
1121
  }
1191
1122
  return plausibleInfo || firstSignatureInfo;
1192
1123
  }
1193
1124
 
1194
- // Ranks how strongly an end-anchored candidate record is backed by an actual central directory, used to decide
1195
- // which record is canonical and which count towards ambiguity. It is intentionally conservative and does not
1196
- // fully parse the directory (the caller does that for the canonical record):
1197
- // - REACHABLE: the record dereferences a central directory (a central file header signature at the
1198
- // reconciled offset), or, for a zip64 record, the zip64 locator that a genuine zip64 archive places
1199
- // immediately before it. Only these count towards ambiguity.
1200
- // - PLAUSIBLE: the record describes an empty archive, which has no central directory to dereference. Its
1201
- // fields are indistinguishable from an empty end of central directory record forged inside a comment, so it
1202
- // is accepted only as a last resort and never inflates the ambiguity count.
1203
- // - UNREACHABLE: neither — stale append remnant or signature bytes embedded in a comment.
1204
- // Signatures are read from the tail window (`view`, spanning `[anchoredOffset, size)`) when they fall inside it;
1205
- // only a target below the window costs a (possibly remote) read, metered by `remoteProbeBudget` so a stuffed
1206
- // comment cannot amplify into an unbounded number of requests.
1125
+ async function* scanEndOfCentralDirectory(reader, scanLength) {
1126
+ const scanOffset = reader.size - scanLength;
1127
+ const scanArray = await readUint8Array(reader, scanOffset, scanLength);
1128
+ const scanView = getDataView(scanArray);
1129
+ for (let indexByte = scanArray.length - END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
1130
+ if (getUint32(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
1131
+ yield [scanView, scanOffset, scanArray, indexByte, scanOffset + indexByte];
1132
+ }
1133
+ }
1134
+ }
1135
+
1136
+ function getEndOfCentralDirectoryInfo(scanArray, indexByte, offset) {
1137
+ return { offset, buffer: scanArray.slice(indexByte, indexByte + END_OF_CENTRAL_DIR_LENGTH).buffer };
1138
+ }
1139
+
1207
1140
  async function getCentralDirectoryReachability(reader, view, anchoredOffset, indexByte, offset, size, remoteProbeBudget) {
1208
1141
  const filesLength = getUint16(view, indexByte + 10);
1209
1142
  const directoryDataLength = getUint32(view, indexByte + 12);
1210
1143
  const directoryDataOffset = getUint32(view, indexByte + 16);
1211
1144
  if (filesLength == MAX_16_BITS || directoryDataLength == MAX_32_BITS || directoryDataOffset == MAX_32_BITS) {
1212
- // saturated fields imply a zip64 record; corroborate it with the zip64 end of central directory locator
1213
- // that sits immediately before it, so saturated bytes inside a comment cannot masquerade as one
1214
1145
  const locatorSignature = await readSignature(reader, view, anchoredOffset, offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, size, remoteProbeBudget);
1215
1146
  return locatorSignature == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE ? CENTRAL_DIRECTORY_REACHABLE : CENTRAL_DIRECTORY_UNREACHABLE;
1216
1147
  }
1217
1148
  if (!filesLength && !directoryDataLength) {
1218
- // a valid empty archive has no central directory to dereference
1219
1149
  return CENTRAL_DIRECTORY_PLAUSIBLE;
1220
1150
  }
1221
- // the central directory ends where this record starts; reconcile the stored offset against that actual
1222
- // position (see stored_cd_offset ⟺ eocd_pos − cd_size) so prepended data does not hide the directory
1223
1151
  for (const centralDirectoryOffset of [offset - directoryDataLength, directoryDataOffset]) {
1224
1152
  if (await readSignature(reader, view, anchoredOffset, centralDirectoryOffset, size, remoteProbeBudget) == CENTRAL_FILE_HEADER_SIGNATURE) {
1225
1153
  return CENTRAL_DIRECTORY_REACHABLE;
@@ -1228,15 +1156,11 @@ async function getCentralDirectoryReachability(reader, view, anchoredOffset, ind
1228
1156
  return CENTRAL_DIRECTORY_UNREACHABLE;
1229
1157
  }
1230
1158
 
1231
- // Reads a 4-byte little-endian signature at `signatureOffset`, served from the tail window (`view`, spanning
1232
- // `[anchoredOffset, size)`) when it falls inside it and otherwise from a metered (possibly remote) read. Returns
1233
- // UNDEFINED_VALUE when the position is out of range or the out-of-window read budget is exhausted.
1234
1159
  async function readSignature(reader, view, anchoredOffset, signatureOffset, size, remoteProbeBudget) {
1235
1160
  if (signatureOffset < 0 || signatureOffset + 4 > size) {
1236
1161
  return UNDEFINED_VALUE;
1237
1162
  }
1238
1163
  if (signatureOffset >= anchoredOffset) {
1239
- // the target sits inside the tail window already in memory: no extra read needed
1240
1164
  return getUint32(view, signatureOffset - anchoredOffset);
1241
1165
  }
1242
1166
  if (remoteProbeBudget.count > 0) {
@@ -1244,7 +1168,6 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
1244
1168
  const signatureArray = await readUint8Array(reader, signatureOffset, 4);
1245
1169
  return getUint32(getDataView(signatureArray), 0);
1246
1170
  }
1247
- // out of budget: leave this candidate unverified rather than issue another read
1248
1171
  return UNDEFINED_VALUE;
1249
1172
  }
1250
1173
 
@@ -1260,8 +1183,6 @@ function checkLocalDirectory(zipEntry, localDirectory, rawLocalFilename) {
1260
1183
  if (localDirectory.compressionMethod != zipEntry.compressionMethod) {
1261
1184
  throwAmbiguousArchive("mismatched local file header (compression method)");
1262
1185
  }
1263
- // when the data descriptor flag is set, the local signature and sizes are zeroed out; all-zero values are
1264
- // also tolerated when the flag is clear because some tools produce them (streaming writers predating bit 3)
1265
1186
  if (!localDirectory.bitFlag.dataDescriptor &&
1266
1187
  (localDirectory.signature || localDirectory.compressedSize || localDirectory.uncompressedSize) &&
1267
1188
  (localDirectory.signature != zipEntry.signature ||