@zip.js/zip.js 2.9.0 → 2.11.0

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 (50) hide show
  1. package/README.md +40 -0
  2. package/deno.json +1 -1
  3. package/dist/zip-core-external.js +17 -46
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +16 -46
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +170 -88
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +171 -88
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +170 -88
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +174 -91
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +175 -92
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +18 -48
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-module.wasm +0 -0
  20. package/dist/zip-native.js +19 -49
  21. package/dist/zip-native.min.js +1 -1
  22. package/dist/zip-web-worker-native.js +1 -1
  23. package/dist/zip-web-worker.js +1 -1
  24. package/dist/zip.js +20 -50
  25. package/dist/zip.min.js +1 -1
  26. package/index-native.cjs +174 -91
  27. package/index-native.min.js +1 -1
  28. package/index.cjs +175 -92
  29. package/index.d.cts +92 -44
  30. package/index.d.ts +92 -44
  31. package/index.min.js +1 -1
  32. package/lib/core/codec-pool.js +0 -2
  33. package/lib/core/codec-registry.js +2 -0
  34. package/lib/core/streams/codec-stream.js +0 -2
  35. package/lib/core/streams/common-crypto.js +1 -3
  36. package/lib/core/streams/zip-entry-stream.js +2 -5
  37. package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
  38. package/lib/core/streams/zlib-wasm/zlib-streams.js +1 -1
  39. package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
  40. package/lib/core/util/decode-cp437.js +4 -11
  41. package/lib/core/version.js +1 -1
  42. package/lib/core/web-worker-inline-native.js +1 -1
  43. package/lib/core/web-worker-inline-wasm.js +1 -1
  44. package/lib/core/zip-entry.js +0 -6
  45. package/lib/core/zip-fs.js +155 -44
  46. package/lib/core/zip-reader.js +1 -6
  47. package/lib/core/zip-writer.js +4 -19
  48. package/lib/core/zlib-streams-inline.js +1 -1
  49. package/lib/zip-core-reader.js +0 -1
  50. package/package.json +1 -1
@@ -1 +1 @@
1
- const t=new Uint8Array(288);t.fill(8,0,144),t.fill(9,144,256),t.fill(7,256,280),t.fill(8,280,288),new Uint8Array(30).fill(5);const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=t=>t({workerURI:t=>{const n="text/javascript";let s='!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";const{Array:t,Object:n,Number:e,Math:s,Error:r,Uint8Array:o,Uint16Array:c,Uint32Array:i,Int32Array:a,Map:f,DataView:u,Promise:l,TextEncoder:w,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:S,DecompressionStream:g}=self,v=void 0,b="undefined",k="function",z=new o,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,B,D,F]=C;class R{constructor(t){this.o=t||-1}append(t){let n=0|this.o;const e=0|t.length;let s=0;if(e>=8&&t.buffer){const r=new u(t.buffer,t.byteOffset,e),o=e-8;for(;s<=o;s+=8){const t=n^r.getInt32(s,!0),e=r.getInt32(s+4,!0);n=F[255&t]^D[t>>>8&255]^B[t>>>16&255]^P[t>>>24&255]^M[255&e]^x[e>>>8&255]^A[e>>>16&255]^I[e>>>24&255]}}for(;s<e;s++)n=n>>>8^I[255&(n^t[s])];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 o(4);new u(e.buffer).setUint32(0,n.get()),t.value=e}}),t=this}}function W(t,n){const e=new o(t.length+n.length);return e.set(t),e.set(n,t.length),e}function _(t){return new u(t.buffer,t.byteOffset,t.byteLength)}const T={concat(t,n){if(0===t.length||0===n.length)return t.concat(n);const e=t[t.length-1],s=T.l(e);return 32===s?t.concat(n):T.h(n,s,0|e,t.slice(0,t.length-1))},bitLength(t){const n=t.length;if(0===n)return 0;const e=t[n-1];return 32*(n-1)+T.l(e)},m(t,n){if(32*t.length<n)return t;const e=(t=t.slice(0,s.ceil(n/32))).length;return n&=31,e>0&&n&&(t[e-1]=T.S(n,t[e-1]&2147483648>>n-1,1)),t},S:(t,n,e)=>32===t?n:(e?0|n:n<<32-t)+1099511627776*t,l:t=>s.round(t/1099511627776)||32,h(t,n,e,s){for(void 0===s&&(s=[]);n>=32;n-=32)s.push(e),e=0;if(0===n)return s.concat(t);for(let r=0;r<t.length;r++)s.push(e|t[r]>>>n),e=t[r]<<32-n;const r=t.length?t[t.length-1]:0,o=T.l(r);return s.push(T.S(n+o&31,n+o>32?e:s.pop(),1)),s}},V={bytes:{v(t){const n=T.bitLength(t)/8,e=new o(n);let s;for(let r=0;r<n;r++)3&r||(s=t[r/4]),e[r]=s>>>24,s<<=8;return e},C(t){const n=[];let e,s=0;for(e=0;e<t.length;e++)s=s<<8|t[e],3&~e||(n.push(s),s=0);return 3&e&&n.push(T.S(8*(3&e),s)),n}}},K=class{constructor(t){const n=this;n.blockSize=512,n.I=[1732584193,4023233417,2562383102,271733878,3285377520],n.A=[1518500249,1859775393,2400959708,3395469782],t?(n.M=t.M.slice(0),n.P=t.P.slice(0),n.B=t.B):n.reset()}reset(){const t=this;return t.M=t.I.slice(0),t.P=[],t.B=0,t}update(t){const n=this;"string"==typeof t&&(t=V.D.C(t));const e=n.P=T.concat(n.P,t),s=n.B,o=n.B=s+T.bitLength(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new i(e);let a=0;for(let t=n.blockSize+s-(n.blockSize+s&n.blockSize-1);t<=o;t+=n.blockSize)n.F(c.subarray(16*a,16*(a+1))),a+=1;return e.splice(0,16*a),n}R(){const t=this;let n=t.P;const e=t.M;n=T.concat(n,[T.S(1,1)]);for(let t=n.length+2;15&t;t++)n.push(0);for(n.push(s.floor(t.B/4294967296)),n.push(0|t.B);n.length;)t.F(n.splice(0,16));return t.reset(),e}U(t,n,e,s){return t<=19?n&e|~n&s:t<=39?n^e^s:t<=59?n&e|n&s|e&s:t<=79?n^e^s:void 0}W(t,n){return n<<t|n>>>32-t}F(n){const e=this,r=e.M,o=t(80);for(let t=0;t<16;t++)o[t]=n[t];let c=r[0],i=r[1],a=r[2],f=r[3],u=r[4];for(let t=0;t<=79;t++){t>=16&&(o[t]=e.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const n=e.W(5,c)+e.U(t,i,a,f)+u+o[t]+e.A[s.floor(t/20)]|0;u=f,f=a,a=e.W(30,i),i=c,c=n}r[0]=r[0]+c|0,r[1]=r[1]+i|0,r[2]=r[2]+a|0,r[3]=r[3]+f|0,r[4]=r[4]+u|0}},E={importKey:t=>new E._(V.bytes.C(t)),T(t,n,e,s){if(e=e||1e4,s<0||e<0)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let c,i,a,f,l;const w=new ArrayBuffer(o),h=new u(w);let p=0;const d=T;for(n=V.bytes.C(n),l=1;p<(o||1);l++){for(c=i=t.encrypt(d.concat(n,[l])),a=1;a<e;a++)for(i=t.encrypt(i),f=0;f<i.length;f++)c[f]^=i[f];for(a=0;p<(o||1)&&a<c.length;a++)h.setInt32(p,c[a]),p+=4}return w.slice(0,s/8)},_:class{constructor(t){const n=this,e=n.V=K,s=[[],[]];n.K=[new e,new e];const r=n.K[0].blockSize/32;t.length>r&&(t=(new e).update(t).R());for(let n=0;n<r;n++)s[0][n]=909522486^t[n],s[1][n]=1549556828^t[n];n.K[0].update(s[0]),n.K[1].update(s[1]),n.L=new e(n.K[0])}reset(){const t=this;t.L=new t.V(t.K[0]),t.O=!1}update(t){this.O=!0,this.L.update(t)}digest(){const t=this,n=t.L.R(),e=new t.V(t.K[1]).update(n).R();return t.reset(),e}encrypt(t){if(this.O)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},L=typeof h!=b&&typeof h.getRandomValues==k,O="Invalid password",j="Invalid signature",H=j,N="zipjs-abort-check-password";function q(t){if(L)return h.getRandomValues(t);throw new r("Crypto API not supported")}const G=16,J={name:"PBKDF2"},Q=n.assign({hash:{name:"HMAC"}},J),X=n.assign({iterations:1e3,hash:{name:"SHA-1"}},J),Y=["deriveBits"],Z=[8,12,16],$=[16,24,32],tt=10,nt=[0,0,0,0],et=typeof h!=b,st=et&&h.subtle,rt=et&&typeof st!=b,ot=V.bytes,ct=class{constructor(t){const n=this;n.j=[[[],[],[],[],[]],[[],[],[],[],[]]],n.j[0][0][0]||n.H();const e=n.j[0][4],s=n.j[1],o=t.length;let c,i,a,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(n.A=[i=t.slice(0),a=[]],c=o;c<4*o+28;c++){let t=i[c-1];(c%o===0||8===o&&c%o===4)&&(t=e[t>>>24]<<24^e[t>>16&255]<<16^e[t>>8&255]<<8^e[255&t],c%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),i[c]=i[c-o]^t}for(let t=0;c;t++,c--){const n=i[3&t?c:c-4];a[t]=c<=4||t<4?n:s[0][e[n>>>24]]^s[1][e[n>>16&255]]^s[2][e[n>>8&255]]^s[3][e[255&n]]}}encrypt(t){return this.N(t,0)}decrypt(t){return this.N(t,1)}H(){const t=this.j[0],n=this.j[1],e=t[4],s=n[4],r=[],o=[];let c,i,a,f;for(let t=0;t<256;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let u=c=0;!e[u];u^=i||1,c=o[c]||1){let o=c^c<<1^c<<2^c<<3^c<<4;o=o>>8^255&o^99,e[u]=o,s[o]=u,f=r[a=r[i=r[u]]];let l=16843009*f^65537*a^257*i^16843008*u,w=257*r[o]^16843008*o;for(let e=0;e<4;e++)t[e][u]=w=w<<24^w>>>8,n[e][o]=l=l<<24^l>>>8}for(let e=0;e<5;e++)t[e]=t[e].slice(0),n[e]=n[e].slice(0)}N(t,n){if(4!==t.length)throw new r("invalid aes block size");const e=this.A[n],s=e.length/4-2,o=[0,0,0,0],c=this.j[n],i=c[0],a=c[1],f=c[2],u=c[3],l=c[4];let w,h,p,d=t[0]^e[0],y=t[n?3:1]^e[1],m=t[2]^e[2],S=t[n?1:3]^e[3],g=4;for(let t=0;t<s;t++)w=i[d>>>24]^a[y>>16&255]^f[m>>8&255]^u[255&S]^e[g],h=i[y>>>24]^a[m>>16&255]^f[S>>8&255]^u[255&d]^e[g+1],p=i[m>>>24]^a[S>>16&255]^f[d>>8&255]^u[255&y]^e[g+2],S=i[S>>>24]^a[d>>16&255]^f[y>>8&255]^u[255&m]^e[g+3],g+=4,d=w,y=h,m=p;for(let t=0;t<4;t++)o[n?3&-t:t]=l[d>>>24]<<24^l[y>>16&255]<<16^l[m>>8&255]<<8^l[255&S]^e[g++],w=d,d=y,y=m,m=S,S=w;return o}},it=class{constructor(t,n){this.G=t,this.J=n,this.X=n}reset(){this.X=this.J}update(t){return this.Y(this.G,t,this.X)}Z(t){if(255&~(t>>24))t+=1<<24;else{let n=t>>16&255,e=t>>8&255,s=255&t;255===n?(n=0,255===e?(e=0,255===s?s=0:++s):++e):++n,t=0,t+=n<<16,t+=e<<8,t+=s}return t}$(t){0===(t[0]=this.Z(t[0]))&&(t[1]=this.Z(t[1]))}Y(t,n,e){let s;if(!(s=n.length))return[];const r=T.bitLength(n);for(let r=0;r<s;r+=4){this.$(e);const s=t.encrypt(e);n[r]^=s[0],n[r+1]^=s[1],n[r+2]^=s[2],n[r+3]^=s[3]}return T.m(n,r)}},at=E._;let ft=et&&rt&&typeof st.importKey==k,ut=et&&rt&&typeof st.deriveBits==k;class lt extends d{constructor({password:t,rawPassword:n,encryptionStrength:e,checkPasswordOnly:s,checkAuthenticationCode:c=!0}){super({start(){ht(this,t,n,e)},async transform(t,n){const e=this,{password:c,strength:i,nt:a,ready:f}=e;c?(await async function(t,n,e,s){const o=await dt(t,n,e,mt(s,0,Z[n])),c=mt(s,Z[n]);if(o[0]!=c[0]||o[1]!=c[1])throw new r(O)}(e,i,c,mt(t,0,Z[i]+2)),t=mt(t,Z[i]+2),s?n.error(new r(N)):a()):await f;const u=new o(t.length-tt-(t.length-tt)%G);n.enqueue(pt(e,t,u,0,tt,!0))},async flush(t){const{et:n,st:e,ot:s,ready:o}=this;if(e&&n){await o;const i=mt(s,0,s.length-tt),a=mt(s,s.length-tt);let f=z;if(i.length){const t=gt(ot,i);e.update(t);const s=n.update(t);f=St(ot,s)}const u=mt(St(ot,e.digest()),0,tt);let l=s.length<tt?1:0;for(let t=0;t<tt;t++)l|=u[t]^a[t];if(l&&c)throw new r(H);t.enqueue(f)}}})}}class wt extends d{constructor({password:t,rawPassword:n,encryptionStrength:e}){super({start(){ht(this,t,n,e)},async transform(t,n){const e=this,{password:s,strength:r,nt:c,ready:i}=e;let a=z;s?(a=await async function(t,n,e){const s=q(new o(Z[n]));return W(s,await dt(t,n,e,s))}(e,r,s),c()):await i;const f=new o(a.length+t.length-t.length%G);f.set(a,0),n.enqueue(pt(e,t,f,a.length,0))},async flush(t){const{et:n,st:e,ot:s,ready:r}=this;if(e&&n){await r;let o=z;if(s.length){const t=n.update(gt(ot,s));e.update(t),o=St(ot,t)}const c=St(ot,e.digest()).slice(0,tt);t.enqueue(W(o,c))}}})}}function ht(t,e,s,r){n.assign(t,{ready:new l(n=>t.nt=n),password:yt(e,s),strength:r-1,ot:z})}function pt(t,n,e,s,r,c){const{et:i,st:a,ot:f}=t;f.length&&(n=W(f,n));const u=n.length-r;let l;for(e=function(t,n){if(n&&n>t.length){const e=t;(t=new o(n)).set(e,0)}return t}(e,s+(u-u%G)),l=0;l<=u-G;l+=G){const t=gt(ot,mt(n,l,l+G));c&&a.update(t);const r=i.update(t);c||a.update(r),e.set(St(ot,r),l+s)}return t.ot=mt(n,l),e}async function dt(e,s,r,c){e.password=null;const i=await async function(t,n,e,s,r){if(!ft)return E.importKey(n);try{return await st.importKey("raw",n,e,!1,r)}catch{return ft=!1,E.importKey(n)}}(0,r,Q,0,Y),a=await async function(t,n,e){if(!ut)return E.T(n,t.salt,X.iterations,e);try{return await st.deriveBits(t,n,e)}catch{return ut=!1,E.T(n,t.salt,X.iterations,e)}}(n.assign({salt:c},X),i,8*(2*$[s]+2)),f=new o(a),u=gt(ot,mt(f,0,$[s])),l=gt(ot,mt(f,$[s],2*$[s])),w=mt(f,2*$[s]);return n.assign(e,{keys:{key:u,ct:l,passwordVerification:w},et:new it(new ct(u),t.from(nt)),st:new at(l)}),w}function yt(t,n){return n===v?function(t){if(typeof w==b){t=unescape(encodeURIComponent(t));const n=new o(t.length);for(let e=0;e<n.length;e++)n[e]=t.charCodeAt(e);return n}return(new w).encode(t)}(t):n}function mt(t,n,e){return t.subarray(n,e)}function St(t,n){return t.v(n)}function gt(t,n){return t.C(n)}class vt extends d{constructor({password:t,rawPassword:n,passwordVerification:e,checkPasswordOnly:s}){super({start(){kt(this,t,n,e)},transform(t,n){const e=this;if(e.password||e.rawPassword){const n=zt(e,t.subarray(0,12));if(e.password=e.rawPassword=null,0!=(n[11]^e.passwordVerification))throw new r(O);t=t.subarray(12)}s?n.error(new r(N)):n.enqueue(zt(e,t))}})}}class bt extends d{constructor({password:t,rawPassword:n,passwordVerification:e}){super({start(){kt(this,t,n,e)},transform(t,n){const e=this;let s,r;if(e.password||e.rawPassword){e.password=e.rawPassword=null;const n=q(new o(12));n[11]=e.passwordVerification,s=new o(t.length+n.length),s.set(Ct(e,n),0),r=12}else s=new o(t.length),r=0;s.set(Ct(e,t),r),n.enqueue(s)}})}}function kt(t,e,s,r){n.assign(t,{password:e,rawPassword:s,passwordVerification:r}),function(t,e,s){const r=[305419896,591751049,878082192];if(n.assign(t,{keys:r,it:new R(r[0]),ft:new R(r[2])}),s)for(let n=0;n<s.length;n++)It(t,s[n]);else for(let n=0;n<e.length;n++)It(t,e.charCodeAt(n))}(t,e,s)}function zt(t,n){const e=new o(n.length);for(let s=0;s<n.length;s++)e[s]=At(t)^n[s],It(t,e[s]);return e}function Ct(t,n){const e=new o(n.length);for(let s=0;s<n.length;s++)e[s]=At(t)^n[s],It(t,n[s]);return e}function It(t,n){let[,e]=t.keys;t.it.append([n]);const r=~t.it.get();e=Mt(s.imul(Mt(e+xt(r)),134775813)+1),t.ft.append([e>>>24]);const o=~t.ft.get();t.keys=[r,e,o]}function At(t){const n=2|t.keys[2];return xt(s.imul(n,1^n)>>>8)}function xt(t){return 255&t}function Mt(t){return 4294967295&t}function Pt(t){if(t instanceof y)return t;const n=t.getReader();return new y({async pull(t){const{value:e,done:s}=await n.read();s?t.close():t.enqueue(e)},cancel:t=>n.cancel(t)})}const Bt=new f;function Dt(t){return Bt.get(t)}const Ft="Invalid uncompressed size",Rt=j,Ut="deflate-raw",Wt="gzip",_t=[31,139,8];class Tt extends d{constructor(t,{chunkSize:n,CompressionStreamFallback:e,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:c,zipCrypto:i,computeCrc32:a,level:f,deflate64:l,format:w,compressionMethod:h,inputSize:p}=t,d=this;let y,m,S,g=super.readable;const v=w&&Dt(w),b=a&&r&&!l&&!v&&(!o||i)&&Boolean(c&&s);if(o&&!i||!a||b||(y=new U,g=Ht(g,y)),r)if(v)g=Nt(g,Ot(v.CompressionStream,w,{level:f,chunkSize:n,compressionMethod:h,uncompressedSize:p}));else if(b)S=new Vt,g=Nt(g,new s(Wt)),g=Ht(g,S);else try{g=jt(g,c,{level:f,chunkSize:n},s,e)}catch(t){let n;try{n=new s(Wt)}catch{throw t}g=Nt(g,n),g=Ht(g,new Vt)}o&&(i?g=Ht(g,new bt(t)):(m=new wt(t),g=Ht(g,m))),Lt(d,g,()=>{o&&!i||!a||(d.crc32=b?S.crc32:new u(y.value.buffer).getUint32(0))})}}class Vt extends d{constructor(){let t,n=10,e=new o(0);super({transform(t,r){if(n){const e=s.min(n,t.length);if(n-=e,!(t=t.subarray(e)).length)return}const o=e.length+t.length;if(o<=8)return void(e=W(e,t));const c=o-8,i=s.min(c,e.length);r.enqueue(W(e.subarray(0,i),t.subarray(0,c-i))),e=W(e.subarray(i),t.subarray(c-i))},flush(){const n=_(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:s}){super({});const{zipCrypto:c,encrypted:i,checkCrc32:a,crc32:f,compressed:w,useCompressionStream:h,deflate64:p,format:m,compressionMethod:S,rawBitFlag:g,outputSize:b}=t;let k,z,C=super.readable;if(i&&(c?C=Ht(C,new vt(t)):(z=new lt(t),C=Ht(C,z))),w){const t=m&&Dt(m);if(t)C=Nt(C,Ot(t.DecompressionStream,m,{chunkSize:n,compressionMethod:S,rawBitFlag:g,uncompressedSize:b}));else try{C=jt(C,h,{chunkSize:n,deflate64:p},s,e)}catch(t){if(p||b===v)throw t;let n;try{n=new s(Wt)}catch{throw t}C=function(t,n,e){const s=new R;let c,i,a,f=0,u=!1;const w=new l((t,n)=>{i=t,a=n});w.catch(()=>{}),e||i();const h=new d({start(t){const n=new o(10);n.set(_t),t.enqueue(n)},transform(t,n){n.enqueue(t)},async flush(t){u=!0,y();try{await w}finally{m()}const n=new o(8),r=_(n);r.setUint32(0,s.get(),!0),r.setUint32(4,e,!0),t.enqueue(n)},cancel(t){a(t)}}),p=new d({transform(t,n){s.append(t),f+=t.length,f>=e?i():u&&y(),n.enqueue(t)},cancel(t){a(t)}});return t=Ht(t,h),Ht(t=Nt(t,n),p);function y(){m(),c=setTimeout(()=>a(new r(Ft)),5e3)}function m(){clearTimeout(c)}}(C,n,b)}C=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:s,done:o}=e;o?t.close():t.enqueue(s)},cancel:t=>n.cancel(t)})}(C)}a&&(k=new U,C=Ht(C,k)),Lt(this,C,()=>{if(a){const t=new u(k.value.buffer);if(f!=t.getUint32(0,!1))throw new r(Rt)}})}}const Et=new f;function Lt(t,e,s){e=Ht(e,new d({flush:s})),n.defineProperty(t,"readable",{get:()=>e})}function Ot(t,n,e){if(!t)throw new r("Compression method not supported");return new t(n,e)}function jt(t,n,e,s,r){const o=n&&s?s:r||s,c=e.deflate64?"deflate64-raw":Ut;let i;try{i=new o(c,e)}catch(t){if(!n||!r||o==r)throw t;i=new r(c,e)}return Nt(t,i)}function Ht(t,n){return Pt(t).pipeThrough(n)}function Nt(t,n){const e=n.writable.getWriter(),s=t.getReader();return async function(){try{for(;;){await e.ready;const t=await s.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{}}(s,t)}}(),n.readable}const qt="data",Gt="close",Jt="deflate";class Qt extends d{constructor(t,e){super({});const s=this,{codecType:o}=t;let c;o.startsWith(Jt)?c=Tt:o.startsWith("inflate")&&(c=Kt),s.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(s,{inputSize:i})}}),l=new d({transform(n,e){if(n&&n.length&&(e.enqueue(n),s.outputSize+=n.length,t.outputSize!==v&&s.outputSize>t.outputSize))throw new r(Ft)},flush(){const{crc32:t}=a;n.assign(s,{crc32:t,inputSize:i})}});n.defineProperty(s,"readable",{get:()=>f.pipeThrough(u).pipeThrough(a).pipeThrough(l)})}}class Xt extends d{constructor(t){const n=[];let s=0;function r(){const e=new o(t);let r=0;for(;r<t;){const s=n[0],o=t-r;s.length<=o?(e.set(s,r),r+=s.length,n.shift()):(e.set(s.subarray(0,o),r),n[0]=s.subarray(o),r+=o)}return s-=t,e}(!e.isFinite(t)||t<1)&&(t=65536),super({transform(e,o){for(n.push(e),s+=e.length;s>t;)o.enqueue(r())},flush(t){s&&t.enqueue(function(t,n){const e=new o(n);let s=0;for(const n of t)e.set(n,s),s+=n.length;return e}(n,s))}})}}let Yt=2;try{typeof navigator!=b&&navigator.hardwareConcurrency&&(Yt=navigator.hardwareConcurrency)}catch{}const Zt=new f,$t=new f;let tn,nn=0;async function en(t){let n,o;try{const{options:c,config:i}=t;if(c.format)try{await async function(t,n){!Bt.has(t)&&n&&function(t,n){const{CompressionStream:e,DecompressionStream:s}=n;if(typeof e!=k&&typeof s!=k)throw new r("Invalid codec module");Bt.set(t,{CompressionStream:e,DecompressionStream:s})}(t,await(import(n)))}(c.format,c.codecURI)}catch(t){throw t.codecImportFailed=!0,t}if(i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream,c.compressed&&!c.format)if(c.useCompressionStream){if(!function(t,n){if(!t)return!1;let e=Et.get(t);e||(e=new f,Et.set(t,e));let s=e.get(n);if(s===v){try{new t(n),s=!0}catch{s=!1}e.set(n,s)}return s}(c.codecType.startsWith(Jt)?i.CompressionStream:i.DecompressionStream,Ut))try{await self.initModule(t.config)}catch{}}else try{await self.initModule(t.config)}catch{c.useCompressionStream=!0}!i.CompressionStreamFallback&&i.CompressionStreamZlib&&(i.CompressionStreamFallback=i.CompressionStreamZlib),!i.DecompressionStreamFallback&&i.DecompressionStreamZlib&&(i.DecompressionStreamFallback=i.DecompressionStreamZlib);const a={highWaterMark:1},u=t.readable?Pt(t.readable):new y({async pull(t){const n=new l(t=>Zt.set(nn,t));sn({type:"pull",messageId:nn}),nn=(nn+1)%e.MAX_SAFE_INTEGER;const{value:s,done:r}=await n;t.enqueue(s),r&&t.close()}},a);o=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 s=new l(t=>n=t);$t.set(nn,n),sn({type:qt,value:t,messageId:nn}),nn=(nn+1)%e.MAX_SAFE_INTEGER,await s}},a),n=new Qt(c,i),tn=new AbortController;const{signal:w}=tn;await u.pipeThrough(n).pipeThrough(new Xt(function(t){return r="string"==typeof(n=r=t.chunkSize)&&n.trim()?e(n):n,e.isInteger(r)&&r>=1?s.max(r,64):65536;var n,r}(i))).pipeTo(o,{signal:w,preventClose:!0,preventAbort:!0}),await o.getWriter().close();const{crc32:h,inputSize:p,outputSize:d}=n;sn({type:Gt,result:{crc32:h,inputSize:p,outputSize:d}})}catch(t){if(t.outputSize=n?n.outputSize:0,o&&!o.locked)try{await o.getWriter().close()}catch{}rn(t)}}function sn(t){const{value:n}=t;if(n)if(n.length)try{t.value=(e=n,e.byteOffset||e.byteLength!=e.buffer.byteLength?new o(e):e).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var e}function rn(t=new r("Unknown error")){const{message:n,stack:e,code:s,name:o,outputSize:c,cause:i,codecImportFailed:a}=t,f={message:n,stack:e,code:s,name:o,outputSize:c};i&&(f.cause={name:i.name,message:i.message}),a&&(f.codecImportFailed=!0),p({error:f})}addEventListener("message",({data:t})=>{const{type:n,messageId:e,value:s,done:r}=t;try{if("start"==n&&en(t),n==qt){const t=Zt.get(e);Zt.delete(e),t({value:s||new o,done:r})}if("ack"==n){const t=$t.get(e);$t.delete(e),t()}n==Gt&&tn.abort()}catch(t){rn(t)}}),p({type:"ready"});const on="deflate",cn="deflate-raw",an="deflate64-raw",fn="gzip";let un,ln,wn,hn,pn;function dn(t,n,e={}){if(!un){const t=new r("WASM module not loaded");throw t.cause=pn,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.ut=ln(i),this.in=ln(a),this.inBufferSize=a,!this.ut||!this.in)throw new r("allocation failed");if(this.lt=new o(i),t?(this.wt=un.deflate_process,this.ht=un.deflate_last_consumed,this.yt=un.deflate_end,this.St=un.deflate_new(),e=n===fn?un.deflate_init_gzip(this.St,c):n===cn?un.deflate_init_raw(this.St,c):un.deflate_init(this.St,c)):n===an?(this.wt=un.inflate9_process,this.ht=un.inflate9_last_consumed,this.yt=un.inflate9_end,this.St=un.inflate9_new(),e=un.inflate9_init_raw(this.St)):(this.wt=un.inflate_process,this.ht=un.inflate_last_consumed,this.yt=un.inflate_end,this.St=un.inflate_new(),e=n===cn?un.inflate_init_raw(this.St):n===fn?un.inflate_init_gzip(this.St):un.inflate_init(this.St)),0!==e)throw new r("init failed:"+e)}catch(t){throw f(this),t}},transform(n,e){try{const c=n,a=new o(hn.buffer),f=this.wt,u=this.ht,l=this.ut,w=this.lt;let h=0;for(;h<c.length;){const n=s.min(c.length-h,32768);if((!this.in||this.inBufferSize<n)&&(this.in&&wn&&(wn(this.in),this.in=0),this.in=ln(n),this.inBufferSize=n,!this.in))throw new r("allocation failed");a.set(c.subarray(h,h+n),this.in);const o=f(this.St,this.in,n,l,i,0),p=16777215&o;if(p&&(w.set(a.subarray(l,l+p),0),e.enqueue(w.slice(0,p))),!t){const t=o>>24&255,n=128&t?t-256:t;if(n<0)throw new r("process error:"+n)}const d=u(this.St);if(0===d)break;h+=d}}catch(t){f(this),e.error(t)}},flush(n){try{const e=new o(hn.buffer),s=this.wt,c=this.ut,a=this.lt;for(;;){const o=s(this.St,0,0,c,i,4),f=16777215&o,u=o>>24&255;if(!t){const t=128&u?u-256:u;if(t<0)throw new r("process error:"+t)}if(f&&(a.set(e.subarray(c,c+f),0),n.enqueue(a.slice(0,f))),1===u||0===f)break}}catch(t){n.error(t)}finally{const t=f(this);0!==t&&n.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let n=0;return t.St&&t.yt&&(n=t.yt(t.St)),t.St=0,t.in&&wn&&wn(t.in),t.in=0,t.ut&&wn&&wn(t.ut),t.ut=0,n}}class yn{constructor(t=on,n){return dn(!0,t,n)}}class mn{constructor(t=on,n){return dn(!1,t,n)}}yn.gt=!0,mn.gt=!0,yn.vt=[on,cn,fn],mn.vt=[on,cn,fn,an];let Sn=!1;!function(t={}){const{init:n}=t,e=t.CompressionStreamFallback||t.CompressionStreamZlib,s=t.DecompressionStreamFallback||t.DecompressionStreamZlib;self.initModule=async t=>{n&&await n(t),e&&(t.CompressionStreamFallback=e),s&&(t.DecompressionStreamFallback=s)}}({CompressionStreamFallback:yn,DecompressionStreamFallback:mn,init:t=>async function(t,{baseURI:n}){if(!Sn)try{await async function(t,n){let e,s;try{try{s=new URL(t,n)}catch{}const r=await fetch(s);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),s=e.length,r=new o(s);for(let t=0;t<s;++t)r[t]=e.charCodeAt(t);return r.buffer}(t)}!function(t){if(un=t,({malloc:ln,free:wn,memory:hn}=un),"function"!=typeof ln||"function"!=typeof wn||!hn)throw un=ln=wn=hn=null,new r("Invalid WASM module")}((await WebAssembly.instantiate(e)).instance.exports)}(t,n),Sn=!0}catch(t){throw function(t){pn=t}(t),t}}(t.wasmURI,t)})});\n';if("string"==typeof s&&(s=(new TextEncoder).encode(s)),t){const t=new Blob([s],{type:n});return URL.createObjectURL(t)}return"data:"+n+";base64,"+function(t){let n="";const s=t.length;let r=0;for(;r+2<s;r+=3){const s=t[r]<<16|t[r+1]<<8|t[r+2];n+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+e[63&s]}const o=s-r;if(1===o){const s=t[r]<<16;n+=e[s>>18&63]+e[s>>12&63]+"=="}else if(2===o){const s=t[r]<<16|t[r+1]<<8;n+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+"="}return n}(s)}});export{n as configureWebWorker};
1
+ const t=new Uint8Array(288);t.fill(8,0,144),t.fill(9,144,256),t.fill(7,256,280),t.fill(8,280,288),new Uint8Array(30).fill(5);const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=t=>t({workerURI:t=>{const n="text/javascript";let s='!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";const{Array:t,Object:n,Number:e,Math:s,Error:r,Uint8Array:o,Uint16Array:c,Uint32Array:i,Int32Array:a,Map:f,DataView:u,Promise:l,TextEncoder:w,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:S,DecompressionStream:g}=self,v=void 0,b="undefined",k="function",z=new o,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,B,D,F]=C;class R{constructor(t){this.o=t||-1}append(t){let n=0|this.o;const e=0|t.length;let s=0;if(e>=8&&t.buffer){const r=new u(t.buffer,t.byteOffset,e),o=e-8;for(;s<=o;s+=8){const t=n^r.getInt32(s,!0),e=r.getInt32(s+4,!0);n=F[255&t]^D[t>>>8&255]^B[t>>>16&255]^P[t>>>24&255]^M[255&e]^x[e>>>8&255]^A[e>>>16&255]^I[e>>>24&255]}}for(;s<e;s++)n=n>>>8^I[255&(n^t[s])];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 o(4);new u(e.buffer).setUint32(0,n.get()),t.value=e}}),t=this}}function W(t,n){const e=new o(t.length+n.length);return e.set(t),e.set(n,t.length),e}function _(t){return new u(t.buffer,t.byteOffset,t.byteLength)}const T={concat(t,n){if(0===t.length||0===n.length)return t.concat(n);const e=t[t.length-1],s=T.l(e);return 32===s?t.concat(n):T.h(n,s,0|e,t.slice(0,t.length-1))},bitLength(t){const n=t.length;if(0===n)return 0;const e=t[n-1];return 32*(n-1)+T.l(e)},m(t,n){if(32*t.length<n)return t;const e=(t=t.slice(0,s.ceil(n/32))).length;return n&=31,e>0&&n&&(t[e-1]=T.S(n,t[e-1]&2147483648>>n-1,1)),t},S:(t,n,e)=>32===t?n:(e?0|n:n<<32-t)+1099511627776*t,l:t=>s.round(t/1099511627776)||32,h(t,n,e,s){for(void 0===s&&(s=[]);n>=32;n-=32)s.push(e),e=0;if(0===n)return s.concat(t);for(let r=0;r<t.length;r++)s.push(e|t[r]>>>n),e=t[r]<<32-n;const r=t.length?t[t.length-1]:0,o=T.l(r);return s.push(T.S(n+o&31,n+o>32?e:s.pop(),1)),s}},V={bytes:{v(t){const n=T.bitLength(t)/8,e=new o(n);let s;for(let r=0;r<n;r++)3&r||(s=t[r/4]),e[r]=s>>>24,s<<=8;return e},C(t){const n=[];let e,s=0;for(e=0;e<t.length;e++)s=s<<8|t[e],3&~e||(n.push(s),s=0);return 3&e&&n.push(T.S(8*(3&e),s)),n}}},K=class{constructor(t){const n=this;n.blockSize=512,n.I=[1732584193,4023233417,2562383102,271733878,3285377520],n.A=[1518500249,1859775393,2400959708,3395469782],t?(n.M=t.M.slice(0),n.P=t.P.slice(0),n.B=t.B):n.reset()}reset(){const t=this;return t.M=t.I.slice(0),t.P=[],t.B=0,t}update(t){const n=this;"string"==typeof t&&(t=V.D.C(t));const e=n.P=T.concat(n.P,t),s=n.B,o=n.B=s+T.bitLength(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new i(e);let a=0;for(let t=n.blockSize+s-(n.blockSize+s&n.blockSize-1);t<=o;t+=n.blockSize)n.F(c.subarray(16*a,16*(a+1))),a+=1;return e.splice(0,16*a),n}R(){const t=this;let n=t.P;const e=t.M;n=T.concat(n,[T.S(1,1)]);for(let t=n.length+2;15&t;t++)n.push(0);for(n.push(s.floor(t.B/4294967296)),n.push(0|t.B);n.length;)t.F(n.splice(0,16));return t.reset(),e}U(t,n,e,s){return t<=19?n&e|~n&s:t<=39?n^e^s:t<=59?n&e|n&s|e&s:t<=79?n^e^s:void 0}W(t,n){return n<<t|n>>>32-t}F(n){const e=this,r=e.M,o=t(80);for(let t=0;t<16;t++)o[t]=n[t];let c=r[0],i=r[1],a=r[2],f=r[3],u=r[4];for(let t=0;t<=79;t++){t>=16&&(o[t]=e.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const n=e.W(5,c)+e.U(t,i,a,f)+u+o[t]+e.A[s.floor(t/20)]|0;u=f,f=a,a=e.W(30,i),i=c,c=n}r[0]=r[0]+c|0,r[1]=r[1]+i|0,r[2]=r[2]+a|0,r[3]=r[3]+f|0,r[4]=r[4]+u|0}},E={importKey:t=>new E._(V.bytes.C(t)),T(t,n,e,s){if(e=e||1e4,s<0||e<0)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let c,i,a,f,l;const w=new ArrayBuffer(o),h=new u(w);let p=0;const d=T;for(n=V.bytes.C(n),l=1;p<(o||1);l++){for(c=i=t.encrypt(d.concat(n,[l])),a=1;a<e;a++)for(i=t.encrypt(i),f=0;f<i.length;f++)c[f]^=i[f];for(a=0;p<(o||1)&&a<c.length;a++)h.setInt32(p,c[a]),p+=4}return w.slice(0,s/8)},_:class{constructor(t){const n=this,e=n.V=K,s=[[],[]];n.K=[new e,new e];const r=n.K[0].blockSize/32;t.length>r&&(t=(new e).update(t).R());for(let n=0;n<r;n++)s[0][n]=909522486^t[n],s[1][n]=1549556828^t[n];n.K[0].update(s[0]),n.K[1].update(s[1]),n.L=new e(n.K[0])}reset(){const t=this;t.L=new t.V(t.K[0]),t.O=!1}update(t){this.O=!0,this.L.update(t)}digest(){const t=this,n=t.L.R(),e=new t.V(t.K[1]).update(n).R();return t.reset(),e}encrypt(t){if(this.O)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},L=typeof h!=b&&typeof h.getRandomValues==k,O="Invalid password",j="zipjs-abort-check-password";function H(t){if(L)return h.getRandomValues(t);throw new r("Crypto API not supported")}const N=16,q={name:"PBKDF2"},G=n.assign({hash:{name:"HMAC"}},q),J=n.assign({iterations:1e3,hash:{name:"SHA-1"}},q),Q=["deriveBits"],X=[8,12,16],Y=[16,24,32],Z=10,$=[0,0,0,0],tt=typeof h!=b,nt=tt&&h.subtle,et=tt&&typeof nt!=b,st=V.bytes,rt=class{constructor(t){const n=this;n.j=[[[],[],[],[],[]],[[],[],[],[],[]]],n.j[0][0][0]||n.H();const e=n.j[0][4],s=n.j[1],o=t.length;let c,i,a,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(n.A=[i=t.slice(0),a=[]],c=o;c<4*o+28;c++){let t=i[c-1];(c%o===0||8===o&&c%o===4)&&(t=e[t>>>24]<<24^e[t>>16&255]<<16^e[t>>8&255]<<8^e[255&t],c%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),i[c]=i[c-o]^t}for(let t=0;c;t++,c--){const n=i[3&t?c:c-4];a[t]=c<=4||t<4?n:s[0][e[n>>>24]]^s[1][e[n>>16&255]]^s[2][e[n>>8&255]]^s[3][e[255&n]]}}encrypt(t){return this.N(t,0)}decrypt(t){return this.N(t,1)}H(){const t=this.j[0],n=this.j[1],e=t[4],s=n[4],r=[],o=[];let c,i,a,f;for(let t=0;t<256;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let u=c=0;!e[u];u^=i||1,c=o[c]||1){let o=c^c<<1^c<<2^c<<3^c<<4;o=o>>8^255&o^99,e[u]=o,s[o]=u,f=r[a=r[i=r[u]]];let l=16843009*f^65537*a^257*i^16843008*u,w=257*r[o]^16843008*o;for(let e=0;e<4;e++)t[e][u]=w=w<<24^w>>>8,n[e][o]=l=l<<24^l>>>8}for(let e=0;e<5;e++)t[e]=t[e].slice(0),n[e]=n[e].slice(0)}N(t,n){if(4!==t.length)throw new r("invalid aes block size");const e=this.A[n],s=e.length/4-2,o=[0,0,0,0],c=this.j[n],i=c[0],a=c[1],f=c[2],u=c[3],l=c[4];let w,h,p,d=t[0]^e[0],y=t[n?3:1]^e[1],m=t[2]^e[2],S=t[n?1:3]^e[3],g=4;for(let t=0;t<s;t++)w=i[d>>>24]^a[y>>16&255]^f[m>>8&255]^u[255&S]^e[g],h=i[y>>>24]^a[m>>16&255]^f[S>>8&255]^u[255&d]^e[g+1],p=i[m>>>24]^a[S>>16&255]^f[d>>8&255]^u[255&y]^e[g+2],S=i[S>>>24]^a[d>>16&255]^f[y>>8&255]^u[255&m]^e[g+3],g+=4,d=w,y=h,m=p;for(let t=0;t<4;t++)o[n?3&-t:t]=l[d>>>24]<<24^l[y>>16&255]<<16^l[m>>8&255]<<8^l[255&S]^e[g++],w=d,d=y,y=m,m=S,S=w;return o}},ot=class{constructor(t,n){this.G=t,this.J=n,this.X=n}reset(){this.X=this.J}update(t){return this.Y(this.G,t,this.X)}Z(t){if(255&~(t>>24))t+=1<<24;else{let n=t>>16&255,e=t>>8&255,s=255&t;255===n?(n=0,255===e?(e=0,255===s?s=0:++s):++e):++n,t=0,t+=n<<16,t+=e<<8,t+=s}return t}$(t){0===(t[0]=this.Z(t[0]))&&(t[1]=this.Z(t[1]))}Y(t,n,e){let s;if(!(s=n.length))return[];const r=T.bitLength(n);for(let r=0;r<s;r+=4){this.$(e);const s=t.encrypt(e);n[r]^=s[0],n[r+1]^=s[1],n[r+2]^=s[2],n[r+3]^=s[3]}return T.m(n,r)}},ct=E._;let it=tt&&et&&typeof nt.importKey==k,at=tt&&et&&typeof nt.deriveBits==k;class ft extends d{constructor({password:t,rawPassword:n,encryptionStrength:e,checkPasswordOnly:s,checkAuthenticationCode:c=!0}){super({start(){lt(this,t,n,e)},async transform(t,n){const e=this,{password:c,strength:i,nt:a,ready:f}=e;c?(await async function(t,n,e,s){const o=await ht(t,n,e,dt(s,0,X[n])),c=dt(s,X[n]);if(o[0]!=c[0]||o[1]!=c[1])throw new r(O)}(e,i,c,dt(t,0,X[i]+2)),t=dt(t,X[i]+2),s?n.error(new r(j)):a()):await f;const u=new o(t.length-Z-(t.length-Z)%N);n.enqueue(wt(e,t,u,0,Z,!0))},async flush(t){const{et:n,st:e,ot:s,ready:o}=this;if(e&&n){await o;const i=dt(s,0,s.length-Z),a=dt(s,s.length-Z);let f=z;if(i.length){const t=mt(st,i);e.update(t);const s=n.update(t);f=yt(st,s)}const u=dt(yt(st,e.digest()),0,Z);let l=s.length<Z?1:0;for(let t=0;t<Z;t++)l|=u[t]^a[t];if(l&&c)throw new r("Invalid authentication code");t.enqueue(f)}}})}}class ut extends d{constructor({password:t,rawPassword:n,encryptionStrength:e}){super({start(){lt(this,t,n,e)},async transform(t,n){const e=this,{password:s,strength:r,nt:c,ready:i}=e;let a=z;s?(a=await async function(t,n,e){const s=H(new o(X[n]));return W(s,await ht(t,n,e,s))}(e,r,s),c()):await i;const f=new o(a.length+t.length-t.length%N);f.set(a,0),n.enqueue(wt(e,t,f,a.length,0))},async flush(t){const{et:n,st:e,ot:s,ready:r}=this;if(e&&n){await r;let o=z;if(s.length){const t=n.update(mt(st,s));e.update(t),o=yt(st,t)}const c=yt(st,e.digest()).slice(0,Z);t.enqueue(W(o,c))}}})}}function lt(t,e,s,r){n.assign(t,{ready:new l(n=>t.nt=n),password:pt(e,s),strength:r-1,ot:z})}function wt(t,n,e,s,r,c){const{et:i,st:a,ot:f}=t;f.length&&(n=W(f,n));const u=n.length-r;let l;for(e=function(t,n){if(n&&n>t.length){const e=t;(t=new o(n)).set(e,0)}return t}(e,s+(u-u%N)),l=0;l<=u-N;l+=N){const t=mt(st,dt(n,l,l+N));c&&a.update(t);const r=i.update(t);c||a.update(r),e.set(yt(st,r),l+s)}return t.ot=dt(n,l),e}async function ht(e,s,r,c){e.password=null;const i=await async function(t,n,e,s,r){if(!it)return E.importKey(n);try{return await nt.importKey("raw",n,e,!1,r)}catch{return it=!1,E.importKey(n)}}(0,r,G,0,Q),a=await async function(t,n,e){if(!at)return E.T(n,t.salt,J.iterations,e);try{return await nt.deriveBits(t,n,e)}catch{return at=!1,E.T(n,t.salt,J.iterations,e)}}(n.assign({salt:c},J),i,8*(2*Y[s]+2)),f=new o(a),u=mt(st,dt(f,0,Y[s])),l=mt(st,dt(f,Y[s],2*Y[s])),w=dt(f,2*Y[s]);return n.assign(e,{keys:{key:u,ct:l,passwordVerification:w},et:new ot(new rt(u),t.from($)),st:new ct(l)}),w}function pt(t,n){return n===v?function(t){if(typeof w==b){t=unescape(encodeURIComponent(t));const n=new o(t.length);for(let e=0;e<n.length;e++)n[e]=t.charCodeAt(e);return n}return(new w).encode(t)}(t):n}function dt(t,n,e){return t.subarray(n,e)}function yt(t,n){return t.v(n)}function mt(t,n){return t.C(n)}class St extends d{constructor({password:t,rawPassword:n,passwordVerification:e,checkPasswordOnly:s}){super({start(){vt(this,t,n,e)},transform(t,n){const e=this;if(e.password||e.rawPassword){const n=bt(e,t.subarray(0,12));if(e.password=e.rawPassword=null,0!=(n[11]^e.passwordVerification))throw new r(O);t=t.subarray(12)}s?n.error(new r(j)):n.enqueue(bt(e,t))}})}}class gt extends d{constructor({password:t,rawPassword:n,passwordVerification:e}){super({start(){vt(this,t,n,e)},transform(t,n){const e=this;let s,r;if(e.password||e.rawPassword){e.password=e.rawPassword=null;const n=H(new o(12));n[11]=e.passwordVerification,s=new o(t.length+n.length),s.set(kt(e,n),0),r=12}else s=new o(t.length),r=0;s.set(kt(e,t),r),n.enqueue(s)}})}}function vt(t,e,s,r){n.assign(t,{password:e,rawPassword:s,passwordVerification:r}),function(t,e,s){const r=[305419896,591751049,878082192];if(n.assign(t,{keys:r,it:new R(r[0]),ft:new R(r[2])}),s)for(let n=0;n<s.length;n++)zt(t,s[n]);else for(let n=0;n<e.length;n++)zt(t,e.charCodeAt(n))}(t,e,s)}function bt(t,n){const e=new o(n.length);for(let s=0;s<n.length;s++)e[s]=Ct(t)^n[s],zt(t,e[s]);return e}function kt(t,n){const e=new o(n.length);for(let s=0;s<n.length;s++)e[s]=Ct(t)^n[s],zt(t,n[s]);return e}function zt(t,n){let[,e]=t.keys;t.it.append([n]);const r=~t.it.get();e=At(s.imul(At(e+It(r)),134775813)+1),t.ft.append([e>>>24]);const o=~t.ft.get();t.keys=[r,e,o]}function Ct(t){const n=2|t.keys[2];return It(s.imul(n,1^n)>>>8)}function It(t){return 255&t}function At(t){return 4294967295&t}function xt(t){if(t instanceof y)return t;const n=t.getReader();return new y({async pull(t){const{value:e,done:s}=await n.read();s?t.close():t.enqueue(e)},cancel:t=>n.cancel(t)})}const Mt=new f;function Pt(t){return Mt.get(t)}const Bt="Invalid uncompressed size",Dt="deflate-raw",Ft="gzip",Rt=[31,139,8];class Ut extends d{constructor(t,{chunkSize:n,CompressionStreamFallback:e,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:c,zipCrypto:i,computeCrc32:a,level:f,deflate64:l,format:w,compressionMethod:h,inputSize:p}=t,d=this;let y,m,S,g=super.readable;const v=w&&Pt(w),b=a&&r&&!l&&!v&&(!o||i)&&Boolean(c&&s);if(o&&!i||!a||b||(y=new U,g=Lt(g,y)),r)if(v)g=Ot(g,Kt(v.CompressionStream,w,{level:f,chunkSize:n,compressionMethod:h,uncompressedSize:p}));else if(b)S=new Wt,g=Ot(g,new s(Ft)),g=Lt(g,S);else try{g=Et(g,c,{level:f,chunkSize:n},s,e)}catch(t){let n;try{n=new s(Ft)}catch{throw t}g=Ot(g,n),g=Lt(g,new Wt)}o&&(i?g=Lt(g,new gt(t)):(m=new ut(t),g=Lt(g,m))),Vt(d,g,()=>{o&&!i||!a||(d.crc32=b?S.crc32:new u(y.value.buffer).getUint32(0))})}}class Wt extends d{constructor(){let t,n=10,e=new o(0);super({transform(t,r){if(n){const e=s.min(n,t.length);if(n-=e,!(t=t.subarray(e)).length)return}const o=e.length+t.length;if(o<=8)return void(e=W(e,t));const c=o-8,i=s.min(c,e.length);r.enqueue(W(e.subarray(0,i),t.subarray(0,c-i))),e=W(e.subarray(i),t.subarray(c-i))},flush(){const n=_(e);t.crc32=n.getUint32(0,!0),t.uncompressedSize=n.getUint32(4,!0)}}),t=this}}class _t extends d{constructor(t,{chunkSize:n,DecompressionStreamFallback:e,DecompressionStream:s}){super({});const{zipCrypto:c,encrypted:i,checkCrc32:a,crc32:f,compressed:w,useCompressionStream:h,deflate64:p,format:m,compressionMethod:S,rawBitFlag:g,outputSize:b}=t;let k,z,C=super.readable;if(i&&(c?C=Lt(C,new St(t)):(z=new ft(t),C=Lt(C,z))),w){const t=m&&Pt(m);if(t)C=Ot(C,Kt(t.DecompressionStream,m,{chunkSize:n,compressionMethod:S,rawBitFlag:g,uncompressedSize:b}));else try{C=Et(C,h,{chunkSize:n,deflate64:p},s,e)}catch(t){if(p||b===v)throw t;let n;try{n=new s(Ft)}catch{throw t}C=function(t,n,e){const s=new R;let c,i,a,f=0,u=!1;const w=new l((t,n)=>{i=t,a=n});w.catch(()=>{}),e||i();const h=new d({start(t){const n=new o(10);n.set(Rt),t.enqueue(n)},transform(t,n){n.enqueue(t)},async flush(t){u=!0,y();try{await w}finally{m()}const n=new o(8),r=_(n);r.setUint32(0,s.get(),!0),r.setUint32(4,e,!0),t.enqueue(n)},cancel(t){a(t)}}),p=new d({transform(t,n){s.append(t),f+=t.length,f>=e?i():u&&y(),n.enqueue(t)},cancel(t){a(t)}});return t=Lt(t,h),Lt(t=Ot(t,n),p);function y(){m(),c=setTimeout(()=>a(new r(Bt)),5e3)}function m(){clearTimeout(c)}}(C,n,b)}C=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:s,done:o}=e;o?t.close():t.enqueue(s)},cancel:t=>n.cancel(t)})}(C)}a&&(k=new U,C=Lt(C,k)),Vt(this,C,()=>{if(a){const t=new u(k.value.buffer);if(f!=t.getUint32(0,!1))throw new r("Invalid CRC32")}})}}const Tt=new f;function Vt(t,e,s){e=Lt(e,new d({flush:s})),n.defineProperty(t,"readable",{get:()=>e})}function Kt(t,n,e){if(!t)throw new r("Compression method not supported");return new t(n,e)}function Et(t,n,e,s,r){const o=n&&s?s:r||s,c=e.deflate64?"deflate64-raw":Dt;let i;try{i=new o(c,e)}catch(t){if(!n||!r||o==r)throw t;i=new r(c,e)}return Ot(t,i)}function Lt(t,n){return xt(t).pipeThrough(n)}function Ot(t,n){const e=n.writable.getWriter(),s=t.getReader();return async function(){try{for(;;){await e.ready;const t=await s.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{}}(s,t)}}(),n.readable}const jt="data",Ht="close",Nt="deflate";class qt extends d{constructor(t,e){super({});const s=this,{codecType:o}=t;let c;o.startsWith(Nt)?c=Ut:o.startsWith("inflate")&&(c=_t),s.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(s,{inputSize:i})}}),l=new d({transform(n,e){if(n&&n.length&&(e.enqueue(n),s.outputSize+=n.length,t.outputSize!==v&&s.outputSize>t.outputSize))throw new r(Bt)},flush(){const{crc32:t}=a;n.assign(s,{crc32:t,inputSize:i})}});n.defineProperty(s,"readable",{get:()=>f.pipeThrough(u).pipeThrough(a).pipeThrough(l)})}}class Gt extends d{constructor(t){const n=[];let s=0;function r(){const e=new o(t);let r=0;for(;r<t;){const s=n[0],o=t-r;s.length<=o?(e.set(s,r),r+=s.length,n.shift()):(e.set(s.subarray(0,o),r),n[0]=s.subarray(o),r+=o)}return s-=t,e}(!e.isFinite(t)||t<1)&&(t=65536),super({transform(e,o){for(n.push(e),s+=e.length;s>t;)o.enqueue(r())},flush(t){s&&t.enqueue(function(t,n){const e=new o(n);let s=0;for(const n of t)e.set(n,s),s+=n.length;return e}(n,s))}})}}let Jt=2;try{typeof navigator!=b&&navigator.hardwareConcurrency&&(Jt=navigator.hardwareConcurrency)}catch{}const Qt=new f,Xt=new f;let Yt,Zt=0;async function $t(t){let n,o;try{const{options:c,config:i}=t;if(c.format)try{await async function(t,n){!Mt.has(t)&&n&&function(t,n){const{CompressionStream:e,DecompressionStream:s}=n;if(typeof e!=k&&typeof s!=k)throw new r("Invalid codec module");Mt.set(t,{CompressionStream:e,DecompressionStream:s})}(t,await(import(n)))}(c.format,c.codecURI)}catch(t){throw t.codecImportFailed=!0,t}if(i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream,c.compressed&&!c.format)if(c.useCompressionStream){if(!function(t,n){if(!t)return!1;let e=Tt.get(t);e||(e=new f,Tt.set(t,e));let s=e.get(n);if(s===v){try{new t(n),s=!0}catch{s=!1}e.set(n,s)}return s}(c.codecType.startsWith(Nt)?i.CompressionStream:i.DecompressionStream,Dt))try{await self.initModule(t.config)}catch{}}else try{await self.initModule(t.config)}catch{c.useCompressionStream=!0}!i.CompressionStreamFallback&&i.CompressionStreamZlib&&(i.CompressionStreamFallback=i.CompressionStreamZlib),!i.DecompressionStreamFallback&&i.DecompressionStreamZlib&&(i.DecompressionStreamFallback=i.DecompressionStreamZlib);const a={highWaterMark:1},u=t.readable?xt(t.readable):new y({async pull(t){const n=new l(t=>Qt.set(Zt,t));tn({type:"pull",messageId:Zt}),Zt=(Zt+1)%e.MAX_SAFE_INTEGER;const{value:s,done:r}=await n;t.enqueue(s),r&&t.close()}},a);o=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 s=new l(t=>n=t);Xt.set(Zt,n),tn({type:jt,value:t,messageId:Zt}),Zt=(Zt+1)%e.MAX_SAFE_INTEGER,await s}},a),n=new qt(c,i),Yt=new AbortController;const{signal:w}=Yt;await u.pipeThrough(n).pipeThrough(new Gt(function(t){return r="string"==typeof(n=r=t.chunkSize)&&n.trim()?e(n):n,e.isInteger(r)&&r>=1?s.max(r,64):65536;var n,r}(i))).pipeTo(o,{signal:w,preventClose:!0,preventAbort:!0}),await o.getWriter().close();const{crc32:h,inputSize:p,outputSize:d}=n;tn({type:Ht,result:{crc32:h,inputSize:p,outputSize:d}})}catch(t){if(t.outputSize=n?n.outputSize:0,o&&!o.locked)try{await o.getWriter().close()}catch{}nn(t)}}function tn(t){const{value:n}=t;if(n)if(n.length)try{t.value=(e=n,e.byteOffset||e.byteLength!=e.buffer.byteLength?new o(e):e).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var e}function nn(t=new r("Unknown error")){const{message:n,stack:e,code:s,name:o,outputSize:c,cause:i,codecImportFailed:a}=t,f={message:n,stack:e,code:s,name:o,outputSize:c};i&&(f.cause={name:i.name,message:i.message}),a&&(f.codecImportFailed=!0),p({error:f})}addEventListener("message",({data:t})=>{const{type:n,messageId:e,value:s,done:r}=t;try{if("start"==n&&$t(t),n==jt){const t=Qt.get(e);Qt.delete(e),t({value:s||new o,done:r})}if("ack"==n){const t=Xt.get(e);Xt.delete(e),t()}n==Ht&&Yt.abort()}catch(t){nn(t)}}),p({type:"ready"});const en="deflate",sn="deflate-raw",rn="deflate64-raw",on="gzip";let cn,an,fn,un,ln;function wn(t,n,e={}){if(!cn){const t=new r("WASM module not loaded");throw t.cause=ln,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.ut=an(i),this.in=an(a),this.inBufferSize=a,!this.ut||!this.in)throw new r("allocation failed");if(this.lt=new o(i),t?(this.wt=cn.deflate_process,this.ht=cn.deflate_last_consumed,this.yt=cn.deflate_end,this.St=cn.deflate_new(),e=n===on?cn.deflate_init_gzip(this.St,c):n===sn?cn.deflate_init_raw(this.St,c):cn.deflate_init(this.St,c)):n===rn?(this.wt=cn.inflate9_process,this.ht=cn.inflate9_last_consumed,this.yt=cn.inflate9_end,this.St=cn.inflate9_new(),e=cn.inflate9_init_raw(this.St)):(this.wt=cn.inflate_process,this.ht=cn.inflate_last_consumed,this.yt=cn.inflate_end,this.St=cn.inflate_new(),e=n===sn?cn.inflate_init_raw(this.St):n===on?cn.inflate_init_gzip(this.St):cn.inflate_init(this.St)),0!==e)throw new r("init failed:"+e)}catch(t){throw f(this),t}},transform(n,e){try{const c=n,a=new o(un.buffer),f=this.wt,u=this.ht,l=this.ut,w=this.lt;let h=0;for(;h<c.length;){const n=s.min(c.length-h,32768);if((!this.in||this.inBufferSize<n)&&(this.in&&fn&&(fn(this.in),this.in=0),this.in=an(n),this.inBufferSize=n,!this.in))throw new r("allocation failed");a.set(c.subarray(h,h+n),this.in);const o=f(this.St,this.in,n,l,i,0),p=16777215&o;if(p&&(w.set(a.subarray(l,l+p),0),e.enqueue(w.slice(0,p))),!t){const t=o>>24&255,n=128&t?t-256:t;if(n<0)throw new r("process error:"+n)}const d=u(this.St);if(0===d&&0===p)break;h+=d}}catch(t){f(this),e.error(t)}},flush(n){try{const e=new o(un.buffer),s=this.wt,c=this.ut,a=this.lt;for(;;){const o=s(this.St,0,0,c,i,4),f=16777215&o,u=o>>24&255;if(!t){const t=128&u?u-256:u;if(t<0)throw new r("process error:"+t)}if(f&&(a.set(e.subarray(c,c+f),0),n.enqueue(a.slice(0,f))),1===u||0===f)break}}catch(t){n.error(t)}finally{const t=f(this);0!==t&&n.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let n=0;return t.St&&t.yt&&(n=t.yt(t.St)),t.St=0,t.in&&fn&&fn(t.in),t.in=0,t.ut&&fn&&fn(t.ut),t.ut=0,n}}class hn{constructor(t=en,n){return wn(!0,t,n)}}class pn{constructor(t=en,n){return wn(!1,t,n)}}hn.gt=!0,pn.gt=!0,hn.vt=[en,sn,on],pn.vt=[en,sn,on,rn];let dn=!1;!function(t={}){const{init:n}=t,e=t.CompressionStreamFallback||t.CompressionStreamZlib,s=t.DecompressionStreamFallback||t.DecompressionStreamZlib;self.initModule=async t=>{n&&await n(t),e&&(t.CompressionStreamFallback=e),s&&(t.DecompressionStreamFallback=s)}}({CompressionStreamFallback:hn,DecompressionStreamFallback:pn,init:t=>async function(t,{baseURI:n}){if(!dn)try{await async function(t,n){let e,s;try{try{s=new URL(t,n)}catch{}const r=await fetch(s);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),s=e.length,r=new o(s);for(let t=0;t<s;++t)r[t]=e.charCodeAt(t);return r.buffer}(t)}!function(t){if(cn=t,({malloc:an,free:fn,memory:un}=cn),"function"!=typeof an||"function"!=typeof fn||!un)throw cn=an=fn=un=null,new r("Invalid WASM module")}((await WebAssembly.instantiate(e)).instance.exports)}(t,n),dn=!0}catch(t){throw function(t){ln=t}(t),t}}(t.wasmURI,t)})});\n';if("string"==typeof s&&(s=(new TextEncoder).encode(s)),t){const t=new Blob([s],{type:n});return URL.createObjectURL(t)}return"data:"+n+";base64,"+function(t){let n="";const s=t.length;let r=0;for(;r+2<s;r+=3){const s=t[r]<<16|t[r+1]<<8|t[r+2];n+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+e[63&s]}const o=s-r;if(1===o){const s=t[r]<<16;n+=e[s>>18&63]+e[s>>12&63]+"=="}else if(2===o){const s=t[r]<<16|t[r+1]<<8;n+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+"="}return n}(s)}});export{n as configureWebWorker};
@@ -42,8 +42,6 @@ const PROPERTY_NAME_CREATION_DATE = "creationDate";
42
42
  const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
43
43
  const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES = "internalFileAttributes";
44
44
  const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttributes";
45
- const PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES = "internalFileAttribute";
46
- const PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttribute";
47
45
  const PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW = "msdosAttributesRaw";
48
46
  const PROPERTY_NAME_MSDOS_ATTRIBUTES = "msdosAttributes";
49
47
  const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
@@ -102,8 +100,6 @@ const PROPERTY_NAMES = [
102
100
  PROPERTY_NAME_DISK_NUMBER_START,
103
101
  PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
104
102
  PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
105
- PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES,
106
- PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES,
107
103
  PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW,
108
104
  PROPERTY_NAME_MSDOS_ATTRIBUTES,
109
105
  PROPERTY_NAME_MS_DOS_COMPATIBLE,
@@ -171,8 +167,6 @@ export {
171
167
  PROPERTY_NAME_RAW_CREATION_DATE,
172
168
  PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
173
169
  PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
174
- PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES,
175
- PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES,
176
170
  PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW,
177
171
  PROPERTY_NAME_MSDOS_ATTRIBUTES,
178
172
  PROPERTY_NAME_MS_DOS_COMPATIBLE,
@@ -80,7 +80,14 @@ import { toExactUint8Array } from "./util/array.js";
80
80
  import { toCompatibleReadable, toCompatibleWritable } from "./util/compatible-streams.js";
81
81
 
82
82
  const ERR_ENTRY_EXISTS = "Entry filename already exists";
83
+ const ERR_DUPLICATE_IMPORTED_ENTRY = "Duplicate entry filename in the imported zip file";
84
+ const ERR_INVALID_DUPLICATES = "Invalid duplicates option (must be \"throw\", \"keep-first\" or \"keep-last\")";
85
+ const ERR_ANCESTOR_ENTRY = "Entry is a ancestor of target entry";
83
86
  const ERR_READABLE_CONSUMED = "Readable stream already consumed";
87
+ const DUPLICATES_THROW = "throw";
88
+ const DUPLICATES_KEEP_FIRST = "keep-first";
89
+ const DUPLICATES_KEEP_LAST = "keep-last";
90
+ const DUPLICATES_VALUES = new Set([DUPLICATES_THROW, DUPLICATES_KEEP_FIRST, DUPLICATES_KEEP_LAST]);
84
91
  const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
85
92
  const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
86
93
  const ERR_ZIP_CRYPTO_LAST_MOD_DATE = "The last modification date of an entry encrypted with ZipCrypto cannot be changed when passThrough is set";
@@ -157,12 +164,26 @@ class ZipEntry {
157
164
  }
158
165
 
159
166
  rename(name) {
160
- const parent = this.parent;
161
- if (parent && parent.getChildByName(name)) {
162
- throw new Error(ERR_ENTRY_EXISTS);
163
- } else {
164
- this.name = name;
167
+ const zipEntry = this;
168
+ let parent = zipEntry.parent;
169
+ if (parent) {
170
+ const path = splitPath(name);
171
+ if (path) {
172
+ name = path.pop();
173
+ parent = getPathParent(parent, path, zipEntry);
174
+ }
175
+ const existingChild = parent.getChildByName(name);
176
+ if (existingChild && existingChild != zipEntry) {
177
+ throw new Error(ERR_ENTRY_EXISTS);
178
+ }
179
+ if (parent != zipEntry.parent) {
180
+ detach(zipEntry);
181
+ zipEntry.parent = parent;
182
+ parent.children.push(zipEntry);
183
+ registerEntries(zipEntry.fs, zipEntry);
184
+ }
165
185
  }
186
+ zipEntry.name = name;
166
187
  }
167
188
 
168
189
  setOptions(options) {
@@ -255,47 +276,47 @@ class ZipFileEntry extends ZipEntry {
255
276
  }
256
277
 
257
278
  replaceBlob(blob) {
258
- Object.assign(this, {
279
+ replaceContent(this, {
259
280
  data: blob,
260
281
  Reader: BlobReader,
261
282
  Writer: BlobWriter,
262
- reader: null
283
+ uncompressedSize: blob.size
263
284
  });
264
285
  }
265
286
 
266
287
  replaceText(text) {
267
- Object.assign(this, {
288
+ replaceContent(this, {
268
289
  data: text,
269
290
  Reader: TextReader,
270
291
  Writer: TextWriter,
271
- reader: null
292
+ uncompressedSize: getTextSize(text)
272
293
  });
273
294
  }
274
295
 
275
296
  replaceData64URI(dataURI) {
276
- Object.assign(this, {
297
+ replaceContent(this, {
277
298
  data: dataURI,
278
299
  Reader: Data64URIReader,
279
300
  Writer: Data64URIWriter,
280
- reader: null
301
+ uncompressedSize: getData64URISize(dataURI)
281
302
  });
282
303
  }
283
304
 
284
305
  replaceUint8Array(array) {
285
- Object.assign(this, {
306
+ replaceContent(this, {
286
307
  data: array,
287
308
  Reader: Uint8ArrayReader,
288
309
  Writer: Uint8ArrayWriter,
289
- reader: null
310
+ uncompressedSize: array.length
290
311
  });
291
312
  }
292
313
 
293
314
  replaceReadable(readable) {
294
- Object.assign(this, {
315
+ replaceContent(this, {
295
316
  data: null,
296
317
  Reader: getReadableReader(readable),
297
318
  Writer: null,
298
- reader: null
319
+ uncompressedSize: UNDEFINED_VALUE
299
320
  });
300
321
  }
301
322
  }
@@ -345,17 +366,12 @@ class ZipDirectoryEntry extends ZipEntry {
345
366
  }
346
367
 
347
368
  addData64URI(name, dataURI, options = {}) {
348
- let dataEnd = dataURI.length;
349
- while (dataURI.charAt(dataEnd - 1) == "=") {
350
- dataEnd--;
351
- }
352
- const dataStart = dataURI.indexOf(",") + 1;
353
369
  return addChild(this, name, {
354
370
  data: dataURI,
355
371
  Reader: Data64URIReader,
356
372
  Writer: Data64URIWriter,
357
373
  options,
358
- uncompressedSize: Math.floor((dataEnd - dataStart) * 0.75)
374
+ uncompressedSize: getData64URISize(dataURI)
359
375
  });
360
376
  }
361
377
 
@@ -463,6 +479,7 @@ class ZipDirectoryEntry extends ZipEntry {
463
479
  await initStream(reader);
464
480
  zipReader = new ZipReader(reader, options);
465
481
  }
482
+ const duplicates = checkDuplicatesOption(options.duplicates);
466
483
  const importedEntries = [];
467
484
  const entries = await zipReader.getEntries(options);
468
485
  for (const entry of entries) {
@@ -470,19 +487,42 @@ class ZipDirectoryEntry extends ZipEntry {
470
487
  try {
471
488
  const path = entry.filename.split("/").filter(pathPart => pathPart != "" && pathPart != ".");
472
489
  const name = path.pop();
473
- path.forEach(pathPart => {
490
+ let skippedEntry = false;
491
+ for (const pathPart of path) {
474
492
  const previousParent = parent;
475
493
  parent = parent.getChildByName(pathPart);
476
494
  if (parent) {
477
495
  if (!parent.directory) {
478
- throw new Error(ERR_ENTRY_EXISTS);
496
+ if (duplicates == DUPLICATES_KEEP_FIRST) {
497
+ skippedEntry = true;
498
+ break;
499
+ } else if (duplicates == DUPLICATES_KEEP_LAST) {
500
+ this.fs.remove(parent);
501
+ parent = new ZipDirectoryEntry(this.fs, pathPart, { data: null }, previousParent);
502
+ importedEntries.push(parent);
503
+ } else {
504
+ throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
505
+ }
479
506
  }
480
507
  } else {
481
508
  parent = new ZipDirectoryEntry(this.fs, pathPart, { data: null }, previousParent);
482
509
  importedEntries.push(parent);
483
510
  }
484
- });
511
+ }
512
+ if (skippedEntry) {
513
+ continue;
514
+ }
485
515
  if (!entry.directory) {
516
+ const existingChild = parent.getChildByName(name);
517
+ if (existingChild) {
518
+ if (duplicates == DUPLICATES_KEEP_FIRST) {
519
+ continue;
520
+ } else if (duplicates == DUPLICATES_KEEP_LAST) {
521
+ this.fs.remove(existingChild);
522
+ } else {
523
+ throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
524
+ }
525
+ }
486
526
  importedEntries.push(addChild(parent, name, {
487
527
  data: entry,
488
528
  Reader: getZipBlobReader(Object.assign({}, options)),
@@ -493,11 +533,17 @@ class ZipDirectoryEntry extends ZipEntry {
493
533
  let directoryEntry = parent;
494
534
  if (name) {
495
535
  directoryEntry = parent.getChildByName(name);
496
- if (directoryEntry) {
497
- if (!directoryEntry.directory) {
498
- throw new Error(ERR_ENTRY_EXISTS);
536
+ if (directoryEntry && !directoryEntry.directory) {
537
+ if (duplicates == DUPLICATES_KEEP_FIRST) {
538
+ continue;
539
+ } else if (duplicates == DUPLICATES_KEEP_LAST) {
540
+ this.fs.remove(directoryEntry);
541
+ directoryEntry = UNDEFINED_VALUE;
542
+ } else {
543
+ throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
499
544
  }
500
- } else {
545
+ }
546
+ if (!directoryEntry) {
501
547
  directoryEntry = new ZipDirectoryEntry(this.fs, name, { data: null }, parent);
502
548
  importedEntries.push(directoryEntry);
503
549
  }
@@ -507,6 +553,7 @@ class ZipDirectoryEntry extends ZipEntry {
507
553
  }
508
554
  }
509
555
  } catch (error) {
556
+ importedEntries.reverse().forEach(importedEntry => this.fs.remove(importedEntry));
510
557
  try {
511
558
  error.cause = {
512
559
  entry
@@ -625,7 +672,7 @@ class ZipFS {
625
672
  }
626
673
  }
627
674
  } else {
628
- throw new Error("Entry is a ancestor of target entry");
675
+ throw new Error(ERR_ANCESTOR_ENTRY);
629
676
  }
630
677
  } else {
631
678
  throw new Error("Target entry is not a directory");
@@ -637,7 +684,7 @@ class ZipFS {
637
684
  const path = fullname.split("/");
638
685
  let node = this.root;
639
686
  for (let index = 0; node && index < path.length; index++) {
640
- node = node.getChildByName(path[index]);
687
+ node = node.directory ? node.getChildByName(path[index]) : UNDEFINED_VALUE;
641
688
  }
642
689
  if (!node) {
643
690
  node = this.entries.find(entry => entry && (entry == this.root || entry.isDescendantOf(this.root)) &&
@@ -699,33 +746,27 @@ class ZipFS {
699
746
  }
700
747
 
701
748
  importBlob(blob, options) {
702
- resetFS(this);
703
- return this.root.importBlob(blob, options);
749
+ return resetAndImport(this, root => root.importBlob(blob, options));
704
750
  }
705
751
 
706
752
  importData64URI(dataURI, options) {
707
- resetFS(this);
708
- return this.root.importData64URI(dataURI, options);
753
+ return resetAndImport(this, root => root.importData64URI(dataURI, options));
709
754
  }
710
755
 
711
756
  importUint8Array(array, options) {
712
- resetFS(this);
713
- return this.root.importUint8Array(array, options);
757
+ return resetAndImport(this, root => root.importUint8Array(array, options));
714
758
  }
715
759
 
716
760
  importHttpContent(url, options) {
717
- resetFS(this);
718
- return this.root.importHttpContent(url, options);
761
+ return resetAndImport(this, root => root.importHttpContent(url, options));
719
762
  }
720
763
 
721
764
  importReadable(readable, options) {
722
- resetFS(this);
723
- return this.root.importReadable(readable, options);
765
+ return resetAndImport(this, root => root.importReadable(readable, options));
724
766
  }
725
767
 
726
768
  importZip(reader, options) {
727
- resetFS(this);
728
- return this.root.importZip(reader, options);
769
+ return resetAndImport(this, root => root.importZip(reader, options));
729
770
  }
730
771
 
731
772
  exportBlob(options) {
@@ -766,7 +807,7 @@ class ZipFS {
766
807
  }
767
808
 
768
809
  const fs = { FS: ZipFS, ZipDirectoryEntry, ZipFileEntry };
769
- export { ZipFS, ZipEntry, ZipFileEntry, ZipDirectoryEntry, fs, ERR_ENTRY_EXISTS, ERR_READABLE_CONSUMED, ERR_INVALID_PASS_THROUGH, ERR_INVALID_READER_OPTIONS, ERR_ZIP_CRYPTO_LAST_MOD_DATE, ERR_ABORTED };
810
+ export { ZipFS, ZipEntry, ZipFileEntry, ZipDirectoryEntry, fs, ERR_ENTRY_EXISTS, ERR_DUPLICATE_IMPORTED_ENTRY, ERR_INVALID_DUPLICATES, ERR_READABLE_CONSUMED, ERR_INVALID_PASS_THROUGH, ERR_INVALID_READER_OPTIONS, ERR_ZIP_CRYPTO_LAST_MOD_DATE, ERR_ABORTED };
770
811
 
771
812
  function getTotalSize(entries, getEntrySize) {
772
813
  let size = 0;
@@ -1046,6 +1087,25 @@ function checkReaderOptions(readerOptions) {
1046
1087
  return readerOptions;
1047
1088
  }
1048
1089
 
1090
+ function replaceContent(zipEntry, params) {
1091
+ const { uncompressedSize } = params;
1092
+ Object.assign(zipEntry, params, {
1093
+ reader: null,
1094
+ passThrough: UNDEFINED_VALUE,
1095
+ uncompressedSize: uncompressedSize === UNDEFINED_VALUE ? 0 : uncompressedSize,
1096
+ undeterminedSize: uncompressedSize === UNDEFINED_VALUE
1097
+ });
1098
+ }
1099
+
1100
+ function getData64URISize(dataURI) {
1101
+ let dataEnd = dataURI.length;
1102
+ while (dataURI.charAt(dataEnd - 1) == "=") {
1103
+ dataEnd--;
1104
+ }
1105
+ const dataStart = dataURI.indexOf(",") + 1;
1106
+ return Math.floor((dataEnd - dataStart) * 0.75);
1107
+ }
1108
+
1049
1109
  function isPassThrough(child, options) {
1050
1110
  const { readerOptions } = options;
1051
1111
  return Boolean(!child.directory && (child.passThrough || (readerOptions && readerOptions.passThrough)));
@@ -1335,6 +1395,15 @@ function resetFS(fs) {
1335
1395
  fs.root = new ZipDirectoryEntry(fs);
1336
1396
  }
1337
1397
 
1398
+ function resetAndImport(fs, importFunction) {
1399
+ const { entries, entryIdCounter, root } = fs;
1400
+ resetFS(fs);
1401
+ return importFunction(fs.root).catch(error => {
1402
+ Object.assign(fs, { entries, entryIdCounter, root });
1403
+ throw error;
1404
+ });
1405
+ }
1406
+
1338
1407
  function collectChildren(directory, recursive) {
1339
1408
  const children = [];
1340
1409
  const pendingDirectories = [directory];
@@ -1363,8 +1432,50 @@ function registerEntries(fs, entry) {
1363
1432
 
1364
1433
  function addChild(parent, name, params, directory) {
1365
1434
  if (parent.directory) {
1435
+ const path = splitPath(name);
1436
+ if (path) {
1437
+ name = path.pop();
1438
+ parent = getPathParent(parent, path);
1439
+ }
1366
1440
  return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new ZipFileEntry(parent.fs, name, params, parent);
1367
1441
  } else {
1368
1442
  throw new Error("Parent entry is not a directory");
1369
1443
  }
1370
- }
1444
+ }
1445
+
1446
+ function checkDuplicatesOption(duplicates) {
1447
+ if (duplicates === UNDEFINED_VALUE) {
1448
+ return DUPLICATES_THROW;
1449
+ } else if (DUPLICATES_VALUES.has(duplicates)) {
1450
+ return duplicates;
1451
+ } else {
1452
+ throw new Error(ERR_INVALID_DUPLICATES);
1453
+ }
1454
+ }
1455
+
1456
+ function splitPath(name) {
1457
+ if (name.includes("/")) {
1458
+ const path = name.split("/").filter(pathPart => pathPart != "" && pathPart != ".");
1459
+ if (path.length) {
1460
+ return path;
1461
+ }
1462
+ }
1463
+ }
1464
+
1465
+ function getPathParent(parent, path, movedEntry) {
1466
+ path.forEach(pathPart => {
1467
+ const previousParent = parent;
1468
+ parent = parent.getChildByName(pathPart);
1469
+ if (parent) {
1470
+ if (!parent.directory) {
1471
+ throw new Error(ERR_ENTRY_EXISTS);
1472
+ }
1473
+ if (movedEntry && (parent == movedEntry || parent.isDescendantOf(movedEntry))) {
1474
+ throw new Error(ERR_ANCESTOR_ENTRY);
1475
+ }
1476
+ } else {
1477
+ parent = new ZipDirectoryEntry(previousParent.fs, pathPart, { data: null }, previousParent);
1478
+ }
1479
+ });
1480
+ return parent;
1481
+ }
@@ -98,11 +98,10 @@ import {
98
98
  MIN_DATE
99
99
  } from "./constants.js";
100
100
  import { getConfiguration } from "./configuration.js";
101
- import { getRegisteredCodec } from "./codec-registry.js";
101
+ import { getRegisteredCodec, ERR_UNSUPPORTED_COMPRESSION } from "./codec-registry.js";
102
102
  import {
103
103
  runWorker,
104
104
  CODEC_INFLATE,
105
- ERR_INVALID_SIGNATURE,
106
105
  ERR_INVALID_CRC32,
107
106
  ERR_INVALID_AUTHENTICATION_CODE,
108
107
  ERR_INVALID_PASSWORD,
@@ -186,7 +185,6 @@ const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
186
185
  const ERR_EXTRAFIELD_ZIP64_NOT_FOUND = "Zip64 extra field not found";
187
186
  const ERR_ENCRYPTED = "File contains encrypted entry";
188
187
  const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
189
- const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
190
188
  const ERR_SPLIT_ZIP_FILE = "Split zip file";
191
189
  const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
192
190
  const ERR_ENTRY_DATA_OUT_OF_BOUNDS = "Entry data out of bounds";
@@ -567,8 +565,6 @@ class ZipReader {
567
565
  sticky,
568
566
  symlink,
569
567
  unixExternalUpper,
570
- internalFileAttribute: fileEntry.internalFileAttributes,
571
- externalFileAttribute: fileEntry.externalFileAttributes,
572
568
  executable,
573
569
  directory: modeIsDir || upperIsDir || (msDosCompatible && msdosAttributes.directory) || fileEntry.filename.endsWith(DIRECTORY_SIGNATURE),
574
570
  zipCrypto: fileEntry.encrypted && !fileEntry.extraFieldAES
@@ -737,7 +733,6 @@ export {
737
733
  ERR_ENCRYPTED,
738
734
  ERR_UNSUPPORTED_ENCRYPTION,
739
735
  ERR_UNSUPPORTED_COMPRESSION,
740
- ERR_INVALID_SIGNATURE,
741
736
  ERR_INVALID_CRC32,
742
737
  ERR_INVALID_AUTHENTICATION_CODE,
743
738
  ERR_INVALID_PASSWORD,
@@ -153,7 +153,7 @@ import {
153
153
  EMPTY_UINT8_ARRAY
154
154
  } from "./constants.js";
155
155
  import { getConfiguration } from "./configuration.js";
156
- import { getRegisteredCodec } from "./codec-registry.js";
156
+ import { getRegisteredCodec, ERR_UNSUPPORTED_COMPRESSION } from "./codec-registry.js";
157
157
  import { supportsDeflate } from "./codec-worker.js";
158
158
  import {
159
159
  CODEC_DEFLATE,
@@ -179,8 +179,6 @@ import {
179
179
  PROPERTY_NAME_CREATION_DATE,
180
180
  PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
181
181
  PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
182
- PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES,
183
- PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES,
184
182
  PROPERTY_NAME_MS_DOS_COMPATIBLE,
185
183
  PROPERTY_NAME_ZIP64,
186
184
  PROPERTY_NAME_ENCRYPTED,
@@ -257,7 +255,6 @@ const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
257
255
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
258
256
  const ERR_INVALID_EXTRAFIELD_DATA_TYPE = "Invalid extra field data (must be a Uint8Array)";
259
257
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
260
- const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
261
258
  const MIN_UNIX_TIME = -2147483648;
262
259
  const MAX_UNIX_TIME = 2147483647;
263
260
  const MIN_NTFS_TIME = BigInt(0);
@@ -735,9 +732,7 @@ async function addFile(zipWriter, name, reader, options) {
735
732
  Object.assign(fileEntry, {
736
733
  name,
737
734
  comment,
738
- extraField,
739
- [PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES]: fileEntry.internalFileAttributes,
740
- [PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES]: fileEntry.externalFileAttributes
735
+ extraField
741
736
  });
742
737
  return new Entry(fileEntry);
743
738
  }
@@ -784,7 +779,7 @@ function resolveAttributes(zipWriter, name, options) {
784
779
  if (versionMadeBy > MAX_16_BITS) {
785
780
  throw new Error(ERR_INVALID_VERSION);
786
781
  }
787
- let externalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES);
782
+ let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES);
788
783
  const externalFileAttributesProvided = externalFileAttributes !== UNDEFINED_VALUE;
789
784
  if (!externalFileAttributesProvided) {
790
785
  externalFileAttributes = 0;
@@ -894,7 +889,7 @@ function resolveMetadata(zipWriter, name, options) {
894
889
  const rawLastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE);
895
890
  const lastAccessDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
896
891
  const creationDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
897
- const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
892
+ const internalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, 0);
898
893
  const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
899
894
  const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
900
895
  const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
@@ -2363,16 +2358,6 @@ function getFunctionOptionValue(zipWriter, options, name) {
2363
2358
  return checkFunctionOption(getOptionValue(zipWriter, options, name));
2364
2359
  }
2365
2360
 
2366
- function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
2367
- const value = getAliasedValue(options, name, deprecatedName);
2368
- const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
2369
- return result === UNDEFINED_VALUE ? defaultValue : result;
2370
- }
2371
-
2372
- function getAliasedValue(options, name, deprecatedName) {
2373
- return options[name] === UNDEFINED_VALUE ? options[deprecatedName] : options[name];
2374
- }
2375
-
2376
2361
  function getNumberOptionValue(zipWriter, options, name, defaultValue) {
2377
2362
  return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
2378
2363
  }