@zip.js/zip.js 2.8.36 → 2.8.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +4 -2
- package/dist/zip-core.js +356 -63
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core.js +301 -63
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-native.js +359 -66
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +357 -64
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +358 -65
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +359 -66
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +357 -64
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +359 -66
- package/index-native.min.js +1 -1
- package/index.cjs +357 -64
- package/index.d.cts +126 -4
- package/index.d.ts +126 -4
- package/index.min.js +1 -1
- package/lib/core/codec-pool.js +21 -4
- package/lib/core/codec-registry.js +116 -0
- package/lib/core/codec-worker.js +94 -18
- package/lib/core/configuration.js +2 -0
- package/lib/core/constants.js +5 -1
- package/lib/core/options.js +2 -0
- package/lib/core/streams/codec-stream.js +6 -2
- package/lib/core/streams/zip-entry-stream.js +50 -16
- package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
- package/lib/core/web-worker-base.js +30 -8
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-reader.js +29 -3
- package/lib/core/zip-writer.js +68 -25
- package/lib/zip-core-base.js +7 -0
- package/lib/zip-core-reader.js +2 -1
- package/lib/zip-core-writer.js +1 -0
- package/package.json +1 -1
- package/worker-message-property-names.js +1 -1
package/dist/zip-fs.js
CHANGED
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
47
47
|
const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
|
|
48
48
|
const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
|
|
49
|
+
const ARCHIVE_EXTRA_DATA_SIGNATURE = 0x08064b50;
|
|
49
50
|
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
50
51
|
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
51
52
|
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
@@ -77,6 +78,7 @@
|
|
|
77
78
|
const BITFLAG_LEVEL_FAST_MASK = 0b100;
|
|
78
79
|
const BITFLAG_LEVEL_SUPER_FAST_MASK = 0b110;
|
|
79
80
|
const BITFLAG_DATA_DESCRIPTOR = 0b1000;
|
|
81
|
+
const BITFLAG_STRONG_ENCRYPTION = 0b1000000;
|
|
80
82
|
const BITFLAG_LANG_ENCODING_FLAG = 0b100000000000;
|
|
81
83
|
const FILE_ATTR_MSDOS_DIR_MASK = 0b10000;
|
|
82
84
|
const FILE_ATTR_MSDOS_READONLY_MASK = 0x01;
|
|
@@ -104,7 +106,7 @@
|
|
|
104
106
|
const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
|
|
105
107
|
const LOCAL_HEADER_COMMON_OFFSET = 4;
|
|
106
108
|
|
|
107
|
-
const MAX_DATE = new Date(2107, 11, 31);
|
|
109
|
+
const MAX_DATE = new Date(2107, 11, 31, 23, 59, 58);
|
|
108
110
|
const MIN_DATE = new Date(1980, 0, 1);
|
|
109
111
|
|
|
110
112
|
const UNDEFINED_VALUE = undefined;
|
|
@@ -160,6 +162,7 @@
|
|
|
160
162
|
maxWorkers,
|
|
161
163
|
terminateWorkerTimeout: 5000,
|
|
162
164
|
workerStarvationTimeout: 5000,
|
|
165
|
+
workerStartupTimeout: 5000,
|
|
163
166
|
useWebWorkers: true,
|
|
164
167
|
useCompressionStream: true,
|
|
165
168
|
transferStreams: true,
|
|
@@ -175,6 +178,7 @@
|
|
|
175
178
|
"maxWorkers",
|
|
176
179
|
"terminateWorkerTimeout",
|
|
177
180
|
"workerStarvationTimeout",
|
|
181
|
+
"workerStartupTimeout",
|
|
178
182
|
"useCompressionStream",
|
|
179
183
|
"useWebWorkers",
|
|
180
184
|
"transferStreams",
|
|
@@ -220,7 +224,104 @@
|
|
|
220
224
|
Object.assign(config, DEFAULT_CONFIGURATION);
|
|
221
225
|
}
|
|
222
226
|
|
|
223
|
-
function t$1(t){const e='(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:i,Uint32Array:c,Int32Array:a,Map:f,DataView:l,Promise:u,TextEncoder:w,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:g,DecompressionStream:v}=self,b=void 0,S="undefined",k="function",z=new o,C=[[],[],[],[],[],[],[],[]];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)e=1&e?e>>>1^3988292384:e>>>1;C[0][t]=e}for(let t=0;256>t;t++)for(let e=1;8>e;e++){const n=C[e-1][t];C[e][t]=n>>>8^C[0][255&n]}const[A,I,x,P,R,U,M,_]=C;class B{constructor(t){this.o=t||-1}append(t){let e=0|this.o;const n=0|t.length;let s=0;if(n>=8&&t.buffer){const r=new l(t.buffer,t.byteOffset,n),o=n-8;for(;o>=s;s+=8){const t=e^r.getInt32(s,!0),n=r.getInt32(s+4,!0);e=_[255&t]^M[t>>>8&255]^U[t>>>16&255]^R[t>>>24&255]^P[255&n]^x[n>>>8&255]^I[n>>>16&255]^A[n>>>24&255]}}for(;n>s;s++)e=e>>>8^A[255&(e^t[s])];this.o=e}get(){return~this.o}}class D extends d{constructor(){let t;const e=new B;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new l(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}function V(t,e){const n=new o(t.length+e.length);return n.set(t),n.set(e,t.length),n}const W={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=W.l(n);return 32===s?t.concat(e):W.h(e,s,0|n,t.slice(0,t.length-1))},m(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+W.l(n)},v(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=W.S(e,t[n-1]&2147483648>>e-1,1)),t},S:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,l:t=>s.round(t/1099511627776)||32,h(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=W.l(r);return s.push(W.S(e+o&31,e+o>32?n:s.pop(),1)),s}},K={bytes:{C(t){const e=W.m(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},A(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(W.S(8*(3&n),s)),e}}},E=class{constructor(t){const e=this;e.blockSize=512,e.I=[1732584193,4023233417,2562383102,271733878,3285377520],e.P=[1518500249,1859775393,2400959708,3395469782],t?(e.R=t.R.slice(0),e.U=t.U.slice(0),e.M=t.M):e.reset()}reset(){const t=this;return t.R=t.I.slice(0),t.U=[],t.M=0,t}update(t){const e=this;"string"==typeof t&&(t=K._.A(t));const n=e.U=W.concat(e.U,t),s=e.M,o=e.M=s+W.m(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const i=new c(n);let a=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.B(i.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),e}D(){const t=this;let e=t.U;const n=t.R;e=W.concat(e,[W.S(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.M/4294967296)),e.push(0|t.M);e.length;)t.B(e.splice(0,16));return t.reset(),n}V(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}B(e){const n=this,r=n.R,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let i=r[0],c=r[1],a=r[2],f=r[3],l=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.W(5,i)+n.V(t,c,a,f)+l+o[t]+n.P[s.floor(t/20)]|0;l=f,f=a,a=n.W(30,c),c=i,i=e}r[0]=r[0]+i|0,r[1]=r[1]+c|0,r[2]=r[2]+a|0,r[3]=r[3]+f|0,r[4]=r[4]+l|0}},L={importKey:t=>new L.K(K.bytes.A(t)),L(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let i,c,a,f,u;const w=new ArrayBuffer(o),h=new l(w);let p=0;const d=W;for(e=K.bytes.A(e),u=1;(o||1)>p;u++){for(i=c=t.encrypt(d.concat(e,[u])),a=1;n>a;a++)for(c=t.encrypt(c),f=0;f<c.length;f++)i[f]^=c[f];for(a=0;(o||1)>p&&a<i.length;a++)h.setInt32(p,i[a]),p+=4}return w.slice(0,s/8)},K:class{constructor(t){const e=this,n=e.O=E,s=[[],[]];e.T=[new n,new n];const r=e.T[0].blockSize/32;t.length>r&&(t=(new n).update(t).D());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.T[0].update(s[0]),e.T[1].update(s[1]),e.j=new n(e.T[0])}reset(){const t=this;t.j=new t.O(t.T[0]),t.H=!1}update(t){this.H=!0,this.j.update(t)}digest(){const t=this,e=t.j.D(),n=new t.O(t.T[1]).update(e).D();return t.reset(),n}encrypt(t){if(this.H)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},O=typeof h!=S&&typeof h.getRandomValues==k,T="Invalid password",j="Invalid signature",H="zipjs-abort-check-password";function Z(t){if(O)return h.getRandomValues(t);throw new r("Crypto API not supported")}const F=16,N={name:"PBKDF2"},q=e.assign({hash:{name:"HMAC"}},N),G=e.assign({iterations:1e3,hash:{name:"SHA-1"}},N),J=["deriveBits"],Q=[8,12,16],X=[16,24,32],Y=10,$=[0,0,0,0],tt=typeof h!=S,et=tt&&h.subtle,nt=tt&&typeof et!=S,st=K.bytes,rt=class{constructor(t){const e=this;e.Z=[[[],[],[],[],[]],[[],[],[],[],[]]],e.Z[0][0][0]||e.F();const n=e.Z[0][4],s=e.Z[1],o=t.length;let i,c,a,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.P=[c=t.slice(0),a=[]],i=o;4*o+28>i;i++){let t=c[i-1];(i%o===0||8===o&&i%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],i%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),c[i]=c[i-o]^t}for(let t=0;i;t++,i--){const e=c[3&t?i:i-4];a[t]=4>=i||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.N(t,0)}decrypt(t){return this.N(t,1)}F(){const t=this.Z[0],e=this.Z[1],n=t[4],s=e[4],r=[],o=[];let i,c,a,f;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=i=0;!n[l];l^=c||1,i=o[i]||1){let o=i^i<<1^i<<2^i<<3^i<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,f=r[a=r[c=r[l]]];let u=16843009*f^65537*a^257*c^16843008*l,w=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=w=w<<24^w>>>8,e[n][o]=u=u<<24^u>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}N(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.P[e],s=n.length/4-2,o=[0,0,0,0],i=this.Z[e],c=i[0],a=i[1],f=i[2],l=i[3],u=i[4];let w,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],g=t[e?1:3]^n[3],v=4;for(let t=0;s>t;t++)w=c[d>>>24]^a[y>>16&255]^f[m>>8&255]^l[255&g]^n[v],h=c[y>>>24]^a[m>>16&255]^f[g>>8&255]^l[255&d]^n[v+1],p=c[m>>>24]^a[g>>16&255]^f[d>>8&255]^l[255&y]^n[v+2],g=c[g>>>24]^a[d>>16&255]^f[y>>8&255]^l[255&m]^n[v+3],v+=4,d=w,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=u[d>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&g]^n[v++],w=d,d=y,y=m,m=g,g=w;return o}},ot=class{constructor(t,e){this.G=t,this.J=e,this.X=e}reset(){this.X=this.J}update(t){return this.Y(this.G,t,this.X)}$(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}et(t){0===(t[0]=this.$(t[0]))&&(t[1]=this.$(t[1]))}Y(t,e,n){let s;if(!(s=e.length))return[];const r=W.m(e);for(let r=0;s>r;r+=4){this.et(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return W.v(e,r)}},it=L.K;let ct=tt&&nt&&typeof et.importKey==k,at=tt&&nt&&typeof et.deriveBits==k;class ft extends d{constructor({password:t,rawPassword:e,encryptionStrength:n,checkPasswordOnly:s}){super({start(){ut(this,t,e,n)},async transform(t,e){const n=this,{password:i,strength:c,nt:a,ready:f}=n;i?(await(async(t,e,n,s)=>{const o=await ht(t,e,n,dt(s,0,Q[e])),i=dt(s,Q[e]);if(o[0]!=i[0]||o[1]!=i[1])throw new r(T)})(n,c,i,dt(t,0,Q[c]+2)),t=dt(t,Q[c]+2),s?e.error(new r(H)):a()):await f;const l=new o(t.length-Y-(t.length-Y)%F);e.enqueue(wt(n,t,l,0,Y,!0))},async flush(t){const{st:e,ot:n,pending:s,ready:o}=this;if(n&&e){await o;const i=dt(s,0,s.length-Y),c=dt(s,s.length-Y);let a=z;if(i.length){const t=mt(st,i);n.update(t);const s=e.update(t);a=yt(st,s)}const f=dt(yt(st,n.digest()),0,Y);let l=s.length<Y?1:0;for(let t=0;Y>t;t++)l|=f[t]^c[t];if(l)throw new r(j);t.enqueue(a)}}})}}class lt extends d{constructor({password:t,rawPassword:e,encryptionStrength:n}){let s;super({start(){ut(this,t,e,n)},async transform(t,e){const n=this,{password:s,strength:r,nt:i,ready:c}=n;let a=z;s?(a=await(async(t,e,n)=>{const s=Z(new o(Q[e]));return V(s,await ht(t,e,n,s))})(n,r,s),i()):await c;const f=new o(a.length+t.length-t.length%F);f.set(a,0),e.enqueue(wt(n,t,f,a.length,0))},async flush(t){const{st:e,ot:n,pending:r,ready:o}=this;if(n&&e){await o;let i=z;if(r.length){const t=e.update(mt(st,r));n.update(t),i=yt(st,t)}s.signature=yt(st,n.digest()).slice(0,Y),t.enqueue(V(i,s.signature))}}}),s=this}}function ut(t,n,s,r){e.assign(t,{ready:new u(e=>t.nt=e),password:pt(n,s),strength:r-1,pending:z})}function wt(t,e,n,s,r,i){const{st:c,ot:a,pending:f}=t;f.length&&(e=V(f,e));const l=e.length-r;let u;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(l-l%F)),u=0;l-F>=u;u+=F){const t=mt(st,dt(e,u,u+F));i&&a.update(t);const r=c.update(t);i||a.update(r),n.set(yt(st,r),u+s)}return t.pending=dt(e,u),n}async function ht(n,s,r,i){n.password=null;const c=await(async(t,e,n,s,r)=>{if(!ct)return L.importKey(e);try{return await et.importKey("raw",e,n,!1,r)}catch{return ct=!1,L.importKey(e)}})(0,r,q,0,J),a=await(async(t,e,n)=>{if(!at)return L.L(e,t.salt,G.iterations,n);try{return await et.deriveBits(t,e,n)}catch{return at=!1,L.L(e,t.salt,G.iterations,n)}})(e.assign({salt:i},G),c,8*(2*X[s]+2)),f=new o(a),l=mt(st,dt(f,0,X[s])),u=mt(st,dt(f,X[s],2*X[s])),w=dt(f,2*X[s]);return e.assign(n,{keys:{key:l,it:u,passwordVerification:w},st:new ot(new rt(l),t.from($)),ot:new it(u)}),w}function pt(t,e){return e===b?(t=>{if(typeof w==S){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new w).encode(t)})(t):e}function dt(t,e,n){return t.subarray(e,n)}function yt(t,e){return t.C(e)}function mt(t,e){return t.A(e)}class gt extends d{constructor({password:t,rawPassword:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){bt(this,t,e,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=St(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e.at(-1)^n.passwordVerification))throw new r(T);t=t.subarray(12)}s?e.error(new r(H)):e.enqueue(St(n,t))}})}}class vt extends d{constructor({password:t,rawPassword:e,passwordVerification:n}){super({start(){bt(this,t,e,n)},transform(t,e){const n=this;let s,r;if(n.password||n.rawPassword){n.password=n.rawPassword=null;const e=Z(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(kt(n,e),0),r=12}else s=new o(t.length),r=0;s.set(kt(n,t),r),e.enqueue(s)}})}}function bt(t,n,s,r){e.assign(t,{password:n,rawPassword:s,passwordVerification:r}),((t,n,s)=>{const r=[305419896,591751049,878082192];if(e.assign(t,{keys:r,ct:new B(r[0]),ft:new B(r[2])}),s)for(let e=0;e<s.length;e++)zt(t,s[e]);else for(let e=0;e<n.length;e++)zt(t,n.charCodeAt(e))})(t,n,s)}function St(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,n[s]);return n}function kt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,e[s]);return n}function zt(t,e){let[,n]=t.keys;t.ct.append([e]);const r=~t.ct.get();n=It(s.imul(It(n+At(r)),134775813)+1),t.ft.append([n>>>24]);const o=~t.ft.get();t.keys=[r,n,o]}function Ct(t){const e=2|t.keys[2];return At(s.imul(e,1^e)>>>8)}function At(t){return 255&t}function It(t){return 4294967295&t}class xt extends d{constructor(t,{chunkSize:e,CompressionStreamZlib:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:i,zipCrypto:c,signed:a,level:f,deflate64:u}=t,w=this;let h,p,d,y=super.readable;const m=a&&r&&!u&&(!o||c)&&!(!i||!s);o&&!c||!a||m||(h=new D,y=_t(y,h)),r&&(m?(d=new Pt,y=Bt(y,new s("gzip")),y=_t(y,d)):y=Mt(y,i,{level:f,chunkSize:e},s,n,s)),o&&(c?y=_t(y,new vt(t)):(p=new lt(t),y=_t(y,p))),Ut(w,y,()=>{let t;o&&!c&&(t=p.signature),o&&!c||!a||(t=m?d.signature:new l(h.value.buffer).getUint32(0)),w.signature=t})}}class Pt extends d{constructor(){let t,e=10,n=new o(0);super({transform(t,r){if(e){const n=s.min(e,t.length);if(e-=n,!(t=t.subarray(n)).length)return}const o=n.length+t.length;if(8>=o)return void(n=V(n,t));const i=o-8,c=s.min(i,n.length);r.enqueue(V(n.subarray(0,c),t.subarray(0,i-c))),n=V(n.subarray(c),t.subarray(i-c))},flush(){const e=new l((s=n).buffer,s.byteOffset,s.byteLength);var s;t.signature=e.getUint32(0,!0),t.uncompressedSize=e.getUint32(4,!0)}}),t=this}}class Rt extends d{constructor(t,{chunkSize:e,DecompressionStreamZlib:n,DecompressionStream:s}){super({});const{zipCrypto:o,encrypted:i,signed:c,signature:a,compressed:f,useCompressionStream:u,deflate64:w}=t;let h,p,d=super.readable;i&&(o?d=_t(d,new gt(t)):(p=new ft(t),d=_t(d,p))),f&&(d=Mt(d,u,{chunkSize:e,deflate64:w},s,n,s),d=(t=>{const e=t.getReader();return new y({async pull(t){let n;try{n=await e.read()}catch(t){if(t&&t.message)throw t;const e=new r("Invalid compressed data");throw e.cause=t,e}const{value:s,done:o}=n;o?t.close():t.enqueue(s)},cancel:t=>e.cancel(t)})})(d)),i&&!o||!c||(h=new D,d=_t(d,h)),Ut(this,d,()=>{if((!i||o)&&c){const t=new l(h.value.buffer);if(a!=t.getUint32(0,!1))throw new r(j)}})}}function Ut(t,n,s){n=_t(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Mt(t,e,n,s,r,o){const i=e&&s?s:r||o,c=n.deflate64?"deflate64-raw":"deflate-raw";let a;try{a=new i(c,n)}catch(t){if(!e)throw t;if(r)a=new r(c,n);else{if(!o)throw t;a=new o(c,n)}}return Bt(t,a)}function _t(t,e){return t.pipeThrough(e)}function Bt(t,e){const n=e.writable.getWriter(),s=t.getReader();return(async()=>{try{for(;;){await n.ready;const t=await s.read();if(t.done){await n.close();break}await n.write(t.value)}}catch(t){await(async(t,e)=>{try{await t.abort(e)}catch{}})(n,t),await(async(t,e)=>{try{await t.cancel(e)}catch{}})(s,t)}})(),e.readable}const Dt="data",Vt="close";class Wt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let i;o.startsWith("deflate")?i=xt:o.startsWith("inflate")&&(i=Rt),s.outputSize=0;let c=0;const a=new i(t,n),f=super.readable,l=new d({transform(t,e){t&&t.length&&(c+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:c})}}),u=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize!==b&&s.outputSize>t.outputSize))throw new r("Invalid uncompressed size")},flush(){const{signature:t}=a;e.assign(s,{signature:t,inputSize:c})}});e.defineProperty(s,"readable",{get:()=>f.pipeThrough(l).pipeThrough(a).pipeThrough(u)})}}class Kt extends d{constructor(t){const e=[];let s=0;function r(){const n=new o(t);let r=0;for(;t>r;){const s=e[0],o=t-r;s.length>o?(n.set(s.subarray(0,o),r),e[0]=s.subarray(o),r+=o):(n.set(s,r),r+=s.length,e.shift())}return s-=t,n}n.isFinite(t)&&t>=1||(t=65536),super({transform(n,o){for(e.push(n),s+=n.length;s>t;)o.enqueue(r())},flush(t){s&&t.enqueue(((t,e)=>{const n=new o(e);let s=0;for(const e of t)n.set(e,s),s+=e.length;return n})(e,s))}})}}let Et=2;try{typeof navigator!=S&&navigator.hardwareConcurrency&&(Et=navigator.hardwareConcurrency)}catch{}const Lt=new f,Ot=new f;let Tt,jt,Ht,Zt,Ft,Nt=0;async function qt(t){let e,r;try{const{options:o,config:i}=t;if(!o.useCompressionStream)try{await self.initModule(t.config)}catch{o.useCompressionStream=!0}i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream;const c={highWaterMark:1},a=t.readable||new y({async pull(t){const e=new u(t=>Lt.set(Nt,t));Gt({type:"pull",messageId:Nt}),Nt=(Nt+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},c);r=t.writable||new m({async write(t){let e;const s=new u(t=>e=t);Ot.set(Nt,e),Gt({type:Dt,value:t,messageId:Nt}),Nt=(Nt+1)%n.MAX_SAFE_INTEGER,await s}},c),e=new Wt(o,i),Tt=new AbortController;const{signal:f}=Tt;await a.pipeThrough(e).pipeThrough(new Kt((t=>s.max(t.chunkSize,64))(i))).pipeTo(r,{signal:f,preventClose:!0,preventAbort:!0}),await r.getWriter().close();const{signature:l,inputSize:w,outputSize:h}=e;Gt({type:Vt,result:{signature:l,inputSize:w,outputSize:h}})}catch(t){if(t.outputSize=e?e.outputSize:0,r&&!r.locked)try{await r.getWriter().close()}catch{}Jt(t)}}function Gt(t){let{value:e}=t;if(e)if(e.length)try{t.value=(n=e,n.byteOffset||n.byteLength!=n.buffer.byteLength?new o(n):n).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var n}function Jt(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:i}=t;p({error:{message:e,stack:n,code:s,name:o,outputSize:i}})}function Qt(t,e,n={}){const i="number"==typeof n.level?n.level:-1,c="number"==typeof n.outBuffer?n.outBuffer:65536,a="number"==typeof n.inBufferSize?n.inBufferSize:65536;return new d({start(){try{let n;if(this.lt=Ht(c),this.in=Ht(a),this.inBufferSize=a,!this.lt||!this.in)throw new r("allocation failed");if(this.ut=new o(c),t?(this.wt=jt.deflate_process,this.ht=jt.deflate_last_consumed,this.yt=jt.deflate_end,this.gt=jt.deflate_new(),n="gzip"===e?jt.deflate_init_gzip(this.gt,i):"deflate-raw"===e?jt.deflate_init_raw(this.gt,i):jt.deflate_init(this.gt,i)):"deflate64-raw"===e?(this.wt=jt.inflate9_process,this.ht=jt.inflate9_last_consumed,this.yt=jt.inflate9_end,this.gt=jt.inflate9_new(),n=jt.inflate9_init_raw(this.gt)):(this.wt=jt.inflate_process,this.ht=jt.inflate_last_consumed,this.yt=jt.inflate_end,this.gt=jt.inflate_new(),n="deflate-raw"===e?jt.inflate_init_raw(this.gt):"gzip"===e?jt.inflate_init_gzip(this.gt):jt.inflate_init(this.gt)),0!==n)throw new r("init failed:"+n)}catch(t){throw f(this),t}},transform(e,n){try{const i=e,a=new o(Ft.buffer),f=this.wt,l=this.ht,u=this.lt,w=this.ut;let h=0;for(;h<i.length;){const e=s.min(i.length-h,32768);if((!this.in||this.inBufferSize<e)&&(this.in&&Zt&&(Zt(this.in),this.in=0),this.in=Ht(e),this.inBufferSize=e,!this.in))throw new r("allocation failed");a.set(i.subarray(h,h+e),this.in);const o=f(this.gt,this.in,e,u,c,0),p=16777215&o;if(p&&(w.set(a.subarray(u,u+p),0),n.enqueue(w.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=l(this.gt);if(0===d)break;h+=d}}catch(t){f(this),n.error(t)}},flush(e){try{const n=new o(Ft.buffer),s=this.wt,i=this.lt,a=this.ut;for(;;){const o=s(this.gt,0,0,i,c,4),f=16777215&o,l=o>>24&255;if(!t){const t=128&l?l-256:l;if(0>t)throw new r("process error:"+t)}if(f&&(a.set(n.subarray(i,i+f),0),e.enqueue(a.slice(0,f))),1===l||0===f)break}}catch(t){e.error(t)}finally{const t=f(this);0!==t&&e.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let e=0;return t.gt&&t.yt&&(e=t.yt(t.gt)),t.gt=0,t.in&&Zt&&Zt(t.in),t.in=0,t.lt&&Zt&&Zt(t.lt),t.lt=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&qt(t),e==Dt){const t=Lt.get(n);Lt.delete(n),t({value:s||new o,done:r})}if("ack"==e){const t=Ot.get(n);Ot.delete(n),t()}e==Vt&&Tt.abort()}catch(t){Jt(t)}});class Xt{constructor(t="deflate",e){return Qt(!0,t,e)}}class Yt{constructor(t="deflate",e){return Qt(!1,t,e)}}Xt.vt=!0,Yt.vt=!0;let $t=!1;self.initModule=async t=>{try{const e=await(async(t,{baseURI:e})=>{if(!$t){let n,s;try{try{s=new URL(t,e)}catch{}const r=await fetch(s);n=await r.arrayBuffer()}catch(e){if(!t.startsWith("data:application/wasm;base64,"))throw e;n=(t=>{const e=t.split(",")[1],n=atob(e),s=n.length,r=new o(s);for(let t=0;s>t;++t)r[t]=n.charCodeAt(t);return r.buffer})(t)}(t=>{if(jt=t,({malloc:Ht,free:Zt,memory:Ft}=jt),"function"!=typeof Ht||"function"!=typeof Zt||!Ft)throw jt=Ht=Zt=Ft=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports),$t=!0}})(t.wasmURI,t);return t.CompressionStreamZlib=Xt,t.DecompressionStreamZlib=Yt,e}catch{}}});\n';t({workerURI:t=>{const n="text/javascript";if(t){const t=new Blob([e],{type:n});return URL.createObjectURL(t)}return "data:"+n+","+encodeURIComponent(e)}});}
|
|
227
|
+
function t$1(t){const e='(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:i,Uint32Array:c,Int32Array:a,Map:f,DataView:l,Promise:u,TextEncoder:w,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:g,DecompressionStream:S}=self,v=void 0,b="undefined",k="function",z=new o,C=[[],[],[],[],[],[],[],[]];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)e=1&e?e>>>1^3988292384:e>>>1;C[0][t]=e}for(let t=0;256>t;t++)for(let e=1;8>e;e++){const n=C[e-1][t];C[e][t]=n>>>8^C[0][255&n]}const[A,I,x,P,D,R,U,M]=C;class _{constructor(t){this.o=t||-1}append(t){let e=0|this.o;const n=0|t.length;let s=0;if(n>=8&&t.buffer){const r=new l(t.buffer,t.byteOffset,n),o=n-8;for(;o>=s;s+=8){const t=e^r.getInt32(s,!0),n=r.getInt32(s+4,!0);e=M[255&t]^U[t>>>8&255]^R[t>>>16&255]^D[t>>>24&255]^P[255&n]^x[n>>>8&255]^I[n>>>16&255]^A[n>>>24&255]}}for(;n>s;s++)e=e>>>8^A[255&(e^t[s])];this.o=e}get(){return~this.o}}class B extends d{constructor(){let t;const e=new _;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new l(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}function V(t,e){const n=new o(t.length+e.length);return n.set(t),n.set(e,t.length),n}const W={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=W.l(n);return 32===s?t.concat(e):W.h(e,s,0|n,t.slice(0,t.length-1))},m(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+W.l(n)},S(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=W.v(e,t[n-1]&2147483648>>e-1,1)),t},v:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,l:t=>s.round(t/1099511627776)||32,h(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=W.l(r);return s.push(W.v(e+o&31,e+o>32?n:s.pop(),1)),s}},K={bytes:{C(t){const e=W.m(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},A(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(W.v(8*(3&n),s)),e}}},E=class{constructor(t){const e=this;e.blockSize=512,e.I=[1732584193,4023233417,2562383102,271733878,3285377520],e.P=[1518500249,1859775393,2400959708,3395469782],t?(e.D=t.D.slice(0),e.R=t.R.slice(0),e.U=t.U):e.reset()}reset(){const t=this;return t.D=t.I.slice(0),t.R=[],t.U=0,t}update(t){const e=this;"string"==typeof t&&(t=K.M.A(t));const n=e.R=W.concat(e.R,t),s=e.U,o=e.U=s+W.m(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const i=new c(n);let a=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e._(i.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),e}B(){const t=this;let e=t.R;const n=t.D;e=W.concat(e,[W.v(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.U/4294967296)),e.push(0|t.U);e.length;)t._(e.splice(0,16));return t.reset(),n}V(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}_(e){const n=this,r=n.D,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let i=r[0],c=r[1],a=r[2],f=r[3],l=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.W(5,i)+n.V(t,c,a,f)+l+o[t]+n.P[s.floor(t/20)]|0;l=f,f=a,a=n.W(30,c),c=i,i=e}r[0]=r[0]+i|0,r[1]=r[1]+c|0,r[2]=r[2]+a|0,r[3]=r[3]+f|0,r[4]=r[4]+l|0}},L={importKey:t=>new L.K(K.bytes.A(t)),L(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let i,c,a,f,u;const w=new ArrayBuffer(o),h=new l(w);let p=0;const d=W;for(e=K.bytes.A(e),u=1;(o||1)>p;u++){for(i=c=t.encrypt(d.concat(e,[u])),a=1;n>a;a++)for(c=t.encrypt(c),f=0;f<c.length;f++)i[f]^=c[f];for(a=0;(o||1)>p&&a<i.length;a++)h.setInt32(p,i[a]),p+=4}return w.slice(0,s/8)},K:class{constructor(t){const e=this,n=e.O=E,s=[[],[]];e.T=[new n,new n];const r=e.T[0].blockSize/32;t.length>r&&(t=(new n).update(t).B());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.T[0].update(s[0]),e.T[1].update(s[1]),e.j=new n(e.T[0])}reset(){const t=this;t.j=new t.O(t.T[0]),t.H=!1}update(t){this.H=!0,this.j.update(t)}digest(){const t=this,e=t.j.B(),n=new t.O(t.T[1]).update(e).B();return t.reset(),n}encrypt(t){if(this.H)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},O=typeof h!=b&&typeof h.getRandomValues==k,T="Invalid password",j="Invalid signature",H="zipjs-abort-check-password";function Z(t){if(O)return h.getRandomValues(t);throw new r("Crypto API not supported")}const F=16,N={name:"PBKDF2"},q=e.assign({hash:{name:"HMAC"}},N),G=e.assign({iterations:1e3,hash:{name:"SHA-1"}},N),J=["deriveBits"],Q=[8,12,16],X=[16,24,32],Y=10,$=[0,0,0,0],tt=typeof h!=b,et=tt&&h.subtle,nt=tt&&typeof et!=b,st=K.bytes,rt=class{constructor(t){const e=this;e.Z=[[[],[],[],[],[]],[[],[],[],[],[]]],e.Z[0][0][0]||e.F();const n=e.Z[0][4],s=e.Z[1],o=t.length;let i,c,a,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.P=[c=t.slice(0),a=[]],i=o;4*o+28>i;i++){let t=c[i-1];(i%o===0||8===o&&i%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],i%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),c[i]=c[i-o]^t}for(let t=0;i;t++,i--){const e=c[3&t?i:i-4];a[t]=4>=i||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.N(t,0)}decrypt(t){return this.N(t,1)}F(){const t=this.Z[0],e=this.Z[1],n=t[4],s=e[4],r=[],o=[];let i,c,a,f;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=i=0;!n[l];l^=c||1,i=o[i]||1){let o=i^i<<1^i<<2^i<<3^i<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,f=r[a=r[c=r[l]]];let u=16843009*f^65537*a^257*c^16843008*l,w=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=w=w<<24^w>>>8,e[n][o]=u=u<<24^u>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}N(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.P[e],s=n.length/4-2,o=[0,0,0,0],i=this.Z[e],c=i[0],a=i[1],f=i[2],l=i[3],u=i[4];let w,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],g=t[e?1:3]^n[3],S=4;for(let t=0;s>t;t++)w=c[d>>>24]^a[y>>16&255]^f[m>>8&255]^l[255&g]^n[S],h=c[y>>>24]^a[m>>16&255]^f[g>>8&255]^l[255&d]^n[S+1],p=c[m>>>24]^a[g>>16&255]^f[d>>8&255]^l[255&y]^n[S+2],g=c[g>>>24]^a[d>>16&255]^f[y>>8&255]^l[255&m]^n[S+3],S+=4,d=w,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=u[d>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&g]^n[S++],w=d,d=y,y=m,m=g,g=w;return o}},ot=class{constructor(t,e){this.G=t,this.J=e,this.X=e}reset(){this.X=this.J}update(t){return this.Y(this.G,t,this.X)}$(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}et(t){0===(t[0]=this.$(t[0]))&&(t[1]=this.$(t[1]))}Y(t,e,n){let s;if(!(s=e.length))return[];const r=W.m(e);for(let r=0;s>r;r+=4){this.et(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return W.S(e,r)}},it=L.K;let ct=tt&&nt&&typeof et.importKey==k,at=tt&&nt&&typeof et.deriveBits==k;class ft extends d{constructor({password:t,rawPassword:e,encryptionStrength:n,checkPasswordOnly:s}){super({start(){ut(this,t,e,n)},async transform(t,e){const n=this,{password:i,strength:c,nt:a,ready:f}=n;i?(await(async(t,e,n,s)=>{const o=await ht(t,e,n,dt(s,0,Q[e])),i=dt(s,Q[e]);if(o[0]!=i[0]||o[1]!=i[1])throw new r(T)})(n,c,i,dt(t,0,Q[c]+2)),t=dt(t,Q[c]+2),s?e.error(new r(H)):a()):await f;const l=new o(t.length-Y-(t.length-Y)%F);e.enqueue(wt(n,t,l,0,Y,!0))},async flush(t){const{st:e,ot:n,pending:s,ready:o}=this;if(n&&e){await o;const i=dt(s,0,s.length-Y),c=dt(s,s.length-Y);let a=z;if(i.length){const t=mt(st,i);n.update(t);const s=e.update(t);a=yt(st,s)}const f=dt(yt(st,n.digest()),0,Y);let l=s.length<Y?1:0;for(let t=0;Y>t;t++)l|=f[t]^c[t];if(l)throw new r(j);t.enqueue(a)}}})}}class lt extends d{constructor({password:t,rawPassword:e,encryptionStrength:n}){let s;super({start(){ut(this,t,e,n)},async transform(t,e){const n=this,{password:s,strength:r,nt:i,ready:c}=n;let a=z;s?(a=await(async(t,e,n)=>{const s=Z(new o(Q[e]));return V(s,await ht(t,e,n,s))})(n,r,s),i()):await c;const f=new o(a.length+t.length-t.length%F);f.set(a,0),e.enqueue(wt(n,t,f,a.length,0))},async flush(t){const{st:e,ot:n,pending:r,ready:o}=this;if(n&&e){await o;let i=z;if(r.length){const t=e.update(mt(st,r));n.update(t),i=yt(st,t)}s.signature=yt(st,n.digest()).slice(0,Y),t.enqueue(V(i,s.signature))}}}),s=this}}function ut(t,n,s,r){e.assign(t,{ready:new u(e=>t.nt=e),password:pt(n,s),strength:r-1,pending:z})}function wt(t,e,n,s,r,i){const{st:c,ot:a,pending:f}=t;f.length&&(e=V(f,e));const l=e.length-r;let u;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(l-l%F)),u=0;l-F>=u;u+=F){const t=mt(st,dt(e,u,u+F));i&&a.update(t);const r=c.update(t);i||a.update(r),n.set(yt(st,r),u+s)}return t.pending=dt(e,u),n}async function ht(n,s,r,i){n.password=null;const c=await(async(t,e,n,s,r)=>{if(!ct)return L.importKey(e);try{return await et.importKey("raw",e,n,!1,r)}catch{return ct=!1,L.importKey(e)}})(0,r,q,0,J),a=await(async(t,e,n)=>{if(!at)return L.L(e,t.salt,G.iterations,n);try{return await et.deriveBits(t,e,n)}catch{return at=!1,L.L(e,t.salt,G.iterations,n)}})(e.assign({salt:i},G),c,8*(2*X[s]+2)),f=new o(a),l=mt(st,dt(f,0,X[s])),u=mt(st,dt(f,X[s],2*X[s])),w=dt(f,2*X[s]);return e.assign(n,{keys:{key:l,it:u,passwordVerification:w},st:new ot(new rt(l),t.from($)),ot:new it(u)}),w}function pt(t,e){return e===v?(t=>{if(typeof w==b){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new w).encode(t)})(t):e}function dt(t,e,n){return t.subarray(e,n)}function yt(t,e){return t.C(e)}function mt(t,e){return t.A(e)}class gt extends d{constructor({password:t,rawPassword:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){vt(this,t,e,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=bt(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e.at(-1)^n.passwordVerification))throw new r(T);t=t.subarray(12)}s?e.error(new r(H)):e.enqueue(bt(n,t))}})}}class St extends d{constructor({password:t,rawPassword:e,passwordVerification:n}){super({start(){vt(this,t,e,n)},transform(t,e){const n=this;let s,r;if(n.password||n.rawPassword){n.password=n.rawPassword=null;const e=Z(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(kt(n,e),0),r=12}else s=new o(t.length),r=0;s.set(kt(n,t),r),e.enqueue(s)}})}}function vt(t,n,s,r){e.assign(t,{password:n,rawPassword:s,passwordVerification:r}),((t,n,s)=>{const r=[305419896,591751049,878082192];if(e.assign(t,{keys:r,ct:new _(r[0]),ft:new _(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 bt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,n[s]);return n}function kt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=Ct(t)^e[s],zt(t,e[s]);return n}function zt(t,e){let[,n]=t.keys;t.ct.append([e]);const r=~t.ct.get();n=It(s.imul(It(n+At(r)),134775813)+1),t.ft.append([n>>>24]);const o=~t.ft.get();t.keys=[r,n,o]}function Ct(t){const e=2|t.keys[2];return At(s.imul(e,1^e)>>>8)}function At(t){return 255&t}function It(t){return 4294967295&t}const xt=new f;function Pt(t){return xt.get(t)}const Dt="deflate-raw";class Rt extends d{constructor(t,{chunkSize:e,CompressionStreamZlib:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:i,zipCrypto:c,signed:a,level:f,deflate64:u,format:w}=t,h=this;let p,d,y,m=super.readable;const g=w&&Pt(w),S=a&&r&&!u&&!g&&(!o||c)&&!(!i||!s);o&&!c||!a||S||(p=new B,m=Kt(m,p)),r&&(g?m=Et(m,Vt(g.CompressionStream,w,{level:f,chunkSize:e})):S?(y=new Ut,m=Et(m,new s("gzip")),m=Kt(m,y)):m=Wt(m,i,{level:f,chunkSize:e},s,n)),o&&(c?m=Kt(m,new St(t)):(d=new lt(t),m=Kt(m,d))),Bt(h,m,()=>{let t;o&&!c&&(t=d.signature),o&&!c||!a||(t=S?y.signature:new l(p.value.buffer).getUint32(0)),h.signature=t})}}class Ut extends d{constructor(){let t,e=10,n=new o(0);super({transform(t,r){if(e){const n=s.min(e,t.length);if(e-=n,!(t=t.subarray(n)).length)return}const o=n.length+t.length;if(8>=o)return void(n=V(n,t));const i=o-8,c=s.min(i,n.length);r.enqueue(V(n.subarray(0,c),t.subarray(0,i-c))),n=V(n.subarray(c),t.subarray(i-c))},flush(){const e=new l((s=n).buffer,s.byteOffset,s.byteLength);var s;t.signature=e.getUint32(0,!0),t.uncompressedSize=e.getUint32(4,!0)}}),t=this}}class Mt extends d{constructor(t,{chunkSize:e,DecompressionStreamZlib:n,DecompressionStream:s}){super({});const{zipCrypto:o,encrypted:i,signed:c,signature:a,compressed:f,useCompressionStream:u,deflate64:w,format:h}=t;let p,d,m=super.readable;if(i&&(o?m=Kt(m,new gt(t)):(d=new ft(t),m=Kt(m,d))),f){const t=h&&Pt(h);m=t?Et(m,Vt(t.DecompressionStream,h,{chunkSize:e})):Wt(m,u,{chunkSize:e,deflate64:w},s,n),m=(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)})})(m)}i&&!o||!c||(p=new B,m=Kt(m,p)),Bt(this,m,()=>{if((!i||o)&&c){const t=new l(p.value.buffer);if(a!=t.getUint32(0,!1))throw new r(j)}})}}const _t=new f;function Bt(t,n,s){n=Kt(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Vt(t,e,n){if(!t)throw new r("Compression method not supported");return new t(e,n)}function Wt(t,e,n,s,r){const o=e&&s?s:r||s,i=n.deflate64?"deflate64-raw":Dt;let c;try{c=new o(i,n)}catch(t){if(!e||!r||o==r)throw t;c=new r(i,n)}return Et(t,c)}function Kt(t,e){return t.pipeThrough(e)}function Et(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 Lt="data",Ot="close",Tt="deflate";class jt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let i;o.startsWith(Tt)?i=Rt:o.startsWith("inflate")&&(i=Mt),s.outputSize=0;let c=0;const a=new i(t,n),f=super.readable,l=new d({transform(t,e){t&&t.length&&(c+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:c})}}),u=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize!==v&&s.outputSize>t.outputSize))throw new r("Invalid uncompressed size")},flush(){const{signature:t}=a;e.assign(s,{signature:t,inputSize:c})}});e.defineProperty(s,"readable",{get:()=>f.pipeThrough(l).pipeThrough(a).pipeThrough(u)})}}class Ht extends d{constructor(t){const e=[];let s=0;function r(){const n=new o(t);let r=0;for(;t>r;){const s=e[0],o=t-r;s.length>o?(n.set(s.subarray(0,o),r),e[0]=s.subarray(o),r+=o):(n.set(s,r),r+=s.length,e.shift())}return s-=t,n}n.isFinite(t)&&t>=1||(t=65536),super({transform(n,o){for(e.push(n),s+=n.length;s>t;)o.enqueue(r())},flush(t){s&&t.enqueue(((t,e)=>{const n=new o(e);let s=0;for(const e of t)n.set(e,s),s+=e.length;return n})(e,s))}})}}let Zt=2;try{typeof navigator!=b&&navigator.hardwareConcurrency&&(Zt=navigator.hardwareConcurrency)}catch{}const Ft=new f,Nt=new f;let qt,Gt,Jt,Qt,Xt,Yt=0;async function $t(t){let e,o;try{const{options:i,config:c}=t;if(i.format&&await(async(t,e)=>{!xt.has(t)&&e&&((t,e)=>{const{CompressionStream:n,DecompressionStream:s}=e;if(typeof n!=k&&typeof s!=k)throw new r("Invalid codec module");xt.set(t,{CompressionStream:n,DecompressionStream:s})})(t,await(import(e)))})(i.format,i.codecURI),c.CompressionStream=self.CompressionStream,c.DecompressionStream=self.DecompressionStream,i.compressed&&!i.format)if(i.useCompressionStream){if(!(t=>{if(!t)return!1;let e=_t.get(t);if(e===v){try{new t(Dt),e=!0}catch{e=!1}_t.set(t,e)}return e})(i.codecType.startsWith(Tt)?c.CompressionStream:c.DecompressionStream))try{await self.initModule(t.config)}catch{}}else try{await self.initModule(t.config)}catch{i.useCompressionStream=!0}const a={highWaterMark:1},f=t.readable||new y({async pull(t){const e=new u(t=>Ft.set(Yt,t));te({type:"pull",messageId:Yt}),Yt=(Yt+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},a);o=t.writable||new m({async write(t){let e;const s=new u(t=>e=t);Nt.set(Yt,e),te({type:Lt,value:t,messageId:Yt}),Yt=(Yt+1)%n.MAX_SAFE_INTEGER,await s}},a),e=new jt(i,c),qt=new AbortController;const{signal:l}=qt;await f.pipeThrough(e).pipeThrough(new Ht((t=>s.max(t.chunkSize,64))(c))).pipeTo(o,{signal:l,preventClose:!0,preventAbort:!0}),await o.getWriter().close();const{signature:w,inputSize:h,outputSize:p}=e;te({type:Ot,result:{signature:w,inputSize:h,outputSize:p}})}catch(t){if(t.outputSize=e?e.outputSize:0,o&&!o.locked)try{await o.getWriter().close()}catch{}ee(t)}}function te(t){const{value:e}=t;if(e)if(e.length)try{t.value=(n=e,n.byteOffset||n.byteLength!=n.buffer.byteLength?new o(n):n).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var n}function ee(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 ne(t,e,n={}){const i="number"==typeof n.level?n.level:-1,c="number"==typeof n.outBuffer?n.outBuffer:65536,a="number"==typeof n.inBufferSize?n.inBufferSize:65536;return new d({start(){try{let n;if(this.lt=Jt(c),this.in=Jt(a),this.inBufferSize=a,!this.lt||!this.in)throw new r("allocation failed");if(this.ut=new o(c),t?(this.wt=Gt.deflate_process,this.ht=Gt.deflate_last_consumed,this.yt=Gt.deflate_end,this.gt=Gt.deflate_new(),n="gzip"===e?Gt.deflate_init_gzip(this.gt,i):"deflate-raw"===e?Gt.deflate_init_raw(this.gt,i):Gt.deflate_init(this.gt,i)):"deflate64-raw"===e?(this.wt=Gt.inflate9_process,this.ht=Gt.inflate9_last_consumed,this.yt=Gt.inflate9_end,this.gt=Gt.inflate9_new(),n=Gt.inflate9_init_raw(this.gt)):(this.wt=Gt.inflate_process,this.ht=Gt.inflate_last_consumed,this.yt=Gt.inflate_end,this.gt=Gt.inflate_new(),n="deflate-raw"===e?Gt.inflate_init_raw(this.gt):"gzip"===e?Gt.inflate_init_gzip(this.gt):Gt.inflate_init(this.gt)),0!==n)throw new r("init failed:"+n)}catch(t){throw f(this),t}},transform(e,n){try{const i=e,a=new o(Xt.buffer),f=this.wt,l=this.ht,u=this.lt,w=this.ut;let h=0;for(;h<i.length;){const e=s.min(i.length-h,32768);if((!this.in||this.inBufferSize<e)&&(this.in&&Qt&&(Qt(this.in),this.in=0),this.in=Jt(e),this.inBufferSize=e,!this.in))throw new r("allocation failed");a.set(i.subarray(h,h+e),this.in);const o=f(this.gt,this.in,e,u,c,0),p=16777215&o;if(p&&(w.set(a.subarray(u,u+p),0),n.enqueue(w.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=l(this.gt);if(0===d)break;h+=d}}catch(t){f(this),n.error(t)}},flush(e){try{const n=new o(Xt.buffer),s=this.wt,i=this.lt,a=this.ut;for(;;){const o=s(this.gt,0,0,i,c,4),f=16777215&o,l=o>>24&255;if(!t){const t=128&l?l-256:l;if(0>t)throw new r("process error:"+t)}if(f&&(a.set(n.subarray(i,i+f),0),e.enqueue(a.slice(0,f))),1===l||0===f)break}}catch(t){e.error(t)}finally{const t=f(this);0!==t&&e.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let e=0;return t.gt&&t.yt&&(e=t.yt(t.gt)),t.gt=0,t.in&&Qt&&Qt(t.in),t.in=0,t.lt&&Qt&&Qt(t.lt),t.lt=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&$t(t),e==Lt){const t=Ft.get(n);Ft.delete(n),t({value:s||new o,done:r})}if("ack"==e){const t=Nt.get(n);Nt.delete(n),t()}e==Ot&&qt.abort()}catch(t){ee(t)}}),p({type:"ready"});class se{constructor(t="deflate",e){return ne(!0,t,e)}}class re{constructor(t="deflate",e){return ne(!1,t,e)}}se.St=!0,re.St=!0;let oe=!1;self.initModule=async t=>{try{const e=await(async(t,{baseURI:e})=>{if(!oe){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(Gt=t,({malloc:Jt,free:Qt,memory:Xt}=Gt),"function"!=typeof Jt||"function"!=typeof Qt||!Xt)throw Gt=Jt=Qt=Xt=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports),oe=!0}})(t.wasmURI,t);return t.CompressionStreamZlib=se,t.DecompressionStreamZlib=re,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)}});}
|
|
228
|
+
|
|
229
|
+
/*
|
|
230
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
231
|
+
|
|
232
|
+
Redistribution and use in source and binary forms, with or without
|
|
233
|
+
modification, are permitted provided that the following conditions are met:
|
|
234
|
+
|
|
235
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
236
|
+
this list of conditions and the following disclaimer.
|
|
237
|
+
|
|
238
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
239
|
+
notice, this list of conditions and the following disclaimer in
|
|
240
|
+
the documentation and/or other materials provided with the distribution.
|
|
241
|
+
|
|
242
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
243
|
+
derived from this software without specific prior written permission.
|
|
244
|
+
|
|
245
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
246
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
247
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
248
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
249
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
250
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
251
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
252
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
253
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
254
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
const ERR_INVALID_CODEC_DEFINITION = "Invalid codec definition";
|
|
259
|
+
const ERR_RESERVED_COMPRESSION_METHOD = "Reserved compression method";
|
|
260
|
+
const ERR_INVALID_CODEC_MODULE = "Invalid codec module";
|
|
261
|
+
|
|
262
|
+
const STRING_TYPE = "string";
|
|
263
|
+
const RESERVED_COMPRESSION_METHODS = [
|
|
264
|
+
COMPRESSION_METHOD_STORE,
|
|
265
|
+
COMPRESSION_METHOD_DEFLATE,
|
|
266
|
+
COMPRESSION_METHOD_DEFLATE_64,
|
|
267
|
+
COMPRESSION_METHOD_AES
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
const registeredCodecs = new Map();
|
|
271
|
+
const codecStreams = new Map();
|
|
272
|
+
|
|
273
|
+
function registerCodec(codec = {}) {
|
|
274
|
+
const { compressionMethod, format, codecURI, CompressionStream, DecompressionStream, versionNeeded } = codec;
|
|
275
|
+
if (!Number.isInteger(compressionMethod) || compressionMethod < 0 || compressionMethod > MAX_16_BITS ||
|
|
276
|
+
typeof format != STRING_TYPE || !format.length) {
|
|
277
|
+
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
278
|
+
}
|
|
279
|
+
if (RESERVED_COMPRESSION_METHODS.includes(compressionMethod)) {
|
|
280
|
+
throw new Error(ERR_RESERVED_COMPRESSION_METHOD);
|
|
281
|
+
}
|
|
282
|
+
const hasStreams = typeof CompressionStream == FUNCTION_TYPE || typeof DecompressionStream == FUNCTION_TYPE;
|
|
283
|
+
if (!hasStreams && (typeof codecURI != STRING_TYPE || !codecURI.length)) {
|
|
284
|
+
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
285
|
+
}
|
|
286
|
+
registeredCodecs.set(compressionMethod, { compressionMethod, format, codecURI, versionNeeded });
|
|
287
|
+
if (hasStreams) {
|
|
288
|
+
setCodecStreams(format, { CompressionStream, DecompressionStream });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function unregisterCodec(compressionMethod) {
|
|
293
|
+
const codec = registeredCodecs.get(compressionMethod);
|
|
294
|
+
if (codec) {
|
|
295
|
+
registeredCodecs.delete(compressionMethod);
|
|
296
|
+
let formatUsed;
|
|
297
|
+
registeredCodecs.forEach(otherCodec => formatUsed = formatUsed || otherCodec.format == codec.format);
|
|
298
|
+
if (!formatUsed) {
|
|
299
|
+
codecStreams.delete(codec.format);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function getRegisteredCodec(compressionMethod) {
|
|
305
|
+
return registeredCodecs.get(compressionMethod);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function getCodecStreams(format) {
|
|
309
|
+
return codecStreams.get(format);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function setCodecStreams(format, streams) {
|
|
313
|
+
const { CompressionStream, DecompressionStream } = streams;
|
|
314
|
+
if (typeof CompressionStream != FUNCTION_TYPE && typeof DecompressionStream != FUNCTION_TYPE) {
|
|
315
|
+
throw new Error(ERR_INVALID_CODEC_MODULE);
|
|
316
|
+
}
|
|
317
|
+
codecStreams.set(format, { CompressionStream, DecompressionStream });
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async function ensureCodecStreams(format, codecURI) {
|
|
321
|
+
if (!codecStreams.has(format) && codecURI) {
|
|
322
|
+
setCodecStreams(format, await import(codecURI));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
224
325
|
|
|
225
326
|
/*
|
|
226
327
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -1758,6 +1859,7 @@
|
|
|
1758
1859
|
|
|
1759
1860
|
const ERR_INVALID_UNCOMPRESSED_SIZE = "Invalid uncompressed size";
|
|
1760
1861
|
const ERR_INVALID_COMPRESSED_DATA = "Invalid compressed data";
|
|
1862
|
+
const ERR_UNSUPPORTED_COMPRESSION$2 = "Compression method not supported";
|
|
1761
1863
|
const FORMAT_DEFLATE_RAW = "deflate-raw";
|
|
1762
1864
|
const FORMAT_DEFLATE64_RAW = "deflate64-raw";
|
|
1763
1865
|
const FORMAT_GZIP = "gzip";
|
|
@@ -1768,23 +1870,26 @@
|
|
|
1768
1870
|
|
|
1769
1871
|
constructor(options, { chunkSize, CompressionStreamZlib, CompressionStream }) {
|
|
1770
1872
|
super({});
|
|
1771
|
-
const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64 } = options;
|
|
1873
|
+
const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64, format } = options;
|
|
1772
1874
|
const stream = this;
|
|
1773
1875
|
let crc32Stream, encryptionStream, gzipCrc32Stream;
|
|
1774
1876
|
let readable = super.readable;
|
|
1775
|
-
const
|
|
1877
|
+
const codecStreams = format && getCodecStreams(format);
|
|
1878
|
+
const useGzipCrc32 = signed && compressed && !deflate64 && !codecStreams && (!encrypted || zipCrypto) &&
|
|
1776
1879
|
Boolean(useCompressionStream && CompressionStream);
|
|
1777
1880
|
if ((!encrypted || zipCrypto) && signed && !useGzipCrc32) {
|
|
1778
1881
|
crc32Stream = new Crc32Stream();
|
|
1779
1882
|
readable = pipeThrough(readable, crc32Stream);
|
|
1780
1883
|
}
|
|
1781
1884
|
if (compressed) {
|
|
1782
|
-
if (
|
|
1885
|
+
if (codecStreams) {
|
|
1886
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.CompressionStream, format, { level, chunkSize }));
|
|
1887
|
+
} else if (useGzipCrc32) {
|
|
1783
1888
|
gzipCrc32Stream = new GzipToRawDeflateStream();
|
|
1784
1889
|
readable = pipeThroughBackpressured(readable, new CompressionStream(FORMAT_GZIP));
|
|
1785
1890
|
readable = pipeThrough(readable, gzipCrc32Stream);
|
|
1786
1891
|
} else {
|
|
1787
|
-
readable =
|
|
1892
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStream, CompressionStreamZlib);
|
|
1788
1893
|
}
|
|
1789
1894
|
}
|
|
1790
1895
|
if (encrypted) {
|
|
@@ -1853,7 +1958,7 @@
|
|
|
1853
1958
|
|
|
1854
1959
|
constructor(options, { chunkSize, DecompressionStreamZlib, DecompressionStream }) {
|
|
1855
1960
|
super({});
|
|
1856
|
-
const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64 } = options;
|
|
1961
|
+
const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64, format } = options;
|
|
1857
1962
|
let crc32Stream, decryptionStream;
|
|
1858
1963
|
let readable = super.readable;
|
|
1859
1964
|
if (encrypted) {
|
|
@@ -1865,7 +1970,12 @@
|
|
|
1865
1970
|
}
|
|
1866
1971
|
}
|
|
1867
1972
|
if (compressed) {
|
|
1868
|
-
|
|
1973
|
+
const codecStreams = format && getCodecStreams(format);
|
|
1974
|
+
if (codecStreams) {
|
|
1975
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize }));
|
|
1976
|
+
} else {
|
|
1977
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamZlib);
|
|
1978
|
+
}
|
|
1869
1979
|
readable = mapInflateStreamError(readable);
|
|
1870
1980
|
}
|
|
1871
1981
|
if ((!encrypted || zipCrypto) && signed) {
|
|
@@ -1883,6 +1993,25 @@
|
|
|
1883
1993
|
}
|
|
1884
1994
|
}
|
|
1885
1995
|
|
|
1996
|
+
const deflateRawSupportByStream = new Map();
|
|
1997
|
+
|
|
1998
|
+
function supportsDeflateRaw(StreamClass) {
|
|
1999
|
+
if (!StreamClass) {
|
|
2000
|
+
return false;
|
|
2001
|
+
}
|
|
2002
|
+
let supported = deflateRawSupportByStream.get(StreamClass);
|
|
2003
|
+
if (supported === UNDEFINED_VALUE) {
|
|
2004
|
+
try {
|
|
2005
|
+
new StreamClass(FORMAT_DEFLATE_RAW);
|
|
2006
|
+
supported = true;
|
|
2007
|
+
} catch {
|
|
2008
|
+
supported = false;
|
|
2009
|
+
}
|
|
2010
|
+
deflateRawSupportByStream.set(StreamClass, supported);
|
|
2011
|
+
}
|
|
2012
|
+
return supported;
|
|
2013
|
+
}
|
|
2014
|
+
|
|
1886
2015
|
function setReadable(stream, readable, flush) {
|
|
1887
2016
|
readable = pipeThrough(readable, new TransformStream({ flush }));
|
|
1888
2017
|
Object.defineProperty(stream, "readable", {
|
|
@@ -1892,21 +2021,24 @@
|
|
|
1892
2021
|
});
|
|
1893
2022
|
}
|
|
1894
2023
|
|
|
1895
|
-
function
|
|
1896
|
-
|
|
2024
|
+
function createCodecStream(CodecStreamClass, format, options) {
|
|
2025
|
+
if (!CodecStreamClass) {
|
|
2026
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION$2);
|
|
2027
|
+
}
|
|
2028
|
+
return new CodecStreamClass(format, options);
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
function pipeThroughCompressionStream(readable, useCompressionStream, options, CompressionStreamNative, CompressionStreamZlib) {
|
|
2032
|
+
const Stream = useCompressionStream && CompressionStreamNative ?
|
|
2033
|
+
CompressionStreamNative :
|
|
2034
|
+
CompressionStreamZlib || CompressionStreamNative;
|
|
1897
2035
|
const format = options.deflate64 ? FORMAT_DEFLATE64_RAW : FORMAT_DEFLATE_RAW;
|
|
1898
2036
|
let codecStream;
|
|
1899
2037
|
try {
|
|
1900
2038
|
codecStream = new Stream(format, options);
|
|
1901
2039
|
} catch (error) {
|
|
1902
|
-
if (useCompressionStream) {
|
|
1903
|
-
|
|
1904
|
-
codecStream = new CompressionStreamZlib(format, options);
|
|
1905
|
-
} else if (CompressionStream) {
|
|
1906
|
-
codecStream = new CompressionStream(format, options);
|
|
1907
|
-
} else {
|
|
1908
|
-
throw error;
|
|
1909
|
-
}
|
|
2040
|
+
if (useCompressionStream && CompressionStreamZlib && Stream != CompressionStreamZlib) {
|
|
2041
|
+
codecStream = new CompressionStreamZlib(format, options);
|
|
1910
2042
|
} else {
|
|
1911
2043
|
throw error;
|
|
1912
2044
|
}
|
|
@@ -2167,6 +2299,7 @@
|
|
|
2167
2299
|
const MODULE_WORKER_OPTIONS = { type: "module" };
|
|
2168
2300
|
const ERROR_EVENT_TYPE = "error";
|
|
2169
2301
|
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2302
|
+
const ERR_WORKER_STARTUP_TIMEOUT = "Worker startup timeout";
|
|
2170
2303
|
|
|
2171
2304
|
let webWorkerSupported, webWorkerSource, webWorkerURI, webWorkerOptions;
|
|
2172
2305
|
let transferStreamsSupported = true;
|
|
@@ -2181,6 +2314,10 @@
|
|
|
2181
2314
|
initModule$1 = initModuleFunction;
|
|
2182
2315
|
}
|
|
2183
2316
|
|
|
2317
|
+
function resetWebWorkerSupport() {
|
|
2318
|
+
webWorkerSupported = UNDEFINED_VALUE;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2184
2321
|
class CodecWorker {
|
|
2185
2322
|
|
|
2186
2323
|
constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI }, onTaskFinished) {
|
|
@@ -2274,7 +2411,7 @@
|
|
|
2274
2411
|
}
|
|
2275
2412
|
|
|
2276
2413
|
function createWebWorkerInterface(workerData, config) {
|
|
2277
|
-
const { baseURI, chunkSize } = config;
|
|
2414
|
+
const { baseURI, chunkSize, workerStartupTimeout } = config;
|
|
2278
2415
|
let { wasmURI } = config;
|
|
2279
2416
|
|
|
2280
2417
|
if (!workerData.interface) {
|
|
@@ -2291,9 +2428,26 @@
|
|
|
2291
2428
|
}
|
|
2292
2429
|
Object.assign(workerData, {
|
|
2293
2430
|
worker,
|
|
2431
|
+
workerAlive: false,
|
|
2294
2432
|
terminated: false,
|
|
2295
2433
|
interface: {
|
|
2296
|
-
run: () =>
|
|
2434
|
+
run: async () => {
|
|
2435
|
+
try {
|
|
2436
|
+
return await runWebWorker(workerData, { chunkSize, wasmURI, baseURI, workerStartupTimeout });
|
|
2437
|
+
} catch (error) {
|
|
2438
|
+
if (error && error.workerStartupFailed) {
|
|
2439
|
+
webWorkerSupported = false;
|
|
2440
|
+
const { reader } = workerData;
|
|
2441
|
+
if (reader) {
|
|
2442
|
+
reader.releaseLock();
|
|
2443
|
+
}
|
|
2444
|
+
workerData.reader = null;
|
|
2445
|
+
workerData.writer = null;
|
|
2446
|
+
return runWorker$1(workerData, config);
|
|
2447
|
+
}
|
|
2448
|
+
throw error;
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2297
2451
|
}
|
|
2298
2452
|
});
|
|
2299
2453
|
}
|
|
@@ -2303,15 +2457,23 @@
|
|
|
2303
2457
|
async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
|
|
2304
2458
|
let codecStream;
|
|
2305
2459
|
try {
|
|
2306
|
-
if (!options.
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
config
|
|
2313
|
-
|
|
2314
|
-
|
|
2460
|
+
if (options.compressed && !options.format) {
|
|
2461
|
+
const deflate = options.codecType.startsWith(CODEC_DEFLATE);
|
|
2462
|
+
const ZlibStream = deflate ? config.CompressionStreamZlib : config.DecompressionStreamZlib;
|
|
2463
|
+
const NativeStream = deflate ? config.CompressionStream : config.DecompressionStream;
|
|
2464
|
+
if (!options.useCompressionStream) {
|
|
2465
|
+
try {
|
|
2466
|
+
await initModule$1(config);
|
|
2467
|
+
} catch {
|
|
2468
|
+
if (!ZlibStream || ZlibStream.requiresModule) {
|
|
2469
|
+
options.useCompressionStream = true;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
} else if (ZlibStream && ZlibStream.requiresModule && !supportsDeflateRaw(NativeStream)) {
|
|
2473
|
+
try {
|
|
2474
|
+
await initModule$1(config);
|
|
2475
|
+
} catch {
|
|
2476
|
+
// ignored
|
|
2315
2477
|
}
|
|
2316
2478
|
}
|
|
2317
2479
|
}
|
|
@@ -2380,6 +2542,10 @@
|
|
|
2380
2542
|
writer: writable.getWriter()
|
|
2381
2543
|
});
|
|
2382
2544
|
}
|
|
2545
|
+
const { workerStartupTimeout } = config;
|
|
2546
|
+
if (!workerData.workerAlive && Number.isFinite(workerStartupTimeout) && workerStartupTimeout >= 0) {
|
|
2547
|
+
workerData.startupTimeout = setTimeout(() => onStartupTimeout(workerData), workerStartupTimeout);
|
|
2548
|
+
}
|
|
2383
2549
|
try {
|
|
2384
2550
|
const resultValue = await result;
|
|
2385
2551
|
await closeWritable();
|
|
@@ -2492,28 +2658,68 @@
|
|
|
2492
2658
|
} else {
|
|
2493
2659
|
worker = new Worker(webWorkerURI, webWorkerOptions);
|
|
2494
2660
|
}
|
|
2495
|
-
worker.addEventListener(MESSAGE_EVENT_TYPE, event =>
|
|
2661
|
+
worker.addEventListener(MESSAGE_EVENT_TYPE, event => {
|
|
2662
|
+
workerData.workerAlive = true;
|
|
2663
|
+
clearStartupTimeout(workerData);
|
|
2664
|
+
onMessage(event, workerData);
|
|
2665
|
+
});
|
|
2496
2666
|
worker.addEventListener(ERROR_EVENT_TYPE, event => onWorkerError(event, workerData));
|
|
2497
2667
|
worker.addEventListener(MESSAGE_ERROR_EVENT_TYPE, event => onWorkerError(event, workerData));
|
|
2498
2668
|
return worker;
|
|
2499
2669
|
}
|
|
2500
2670
|
|
|
2671
|
+
function onStartupTimeout(workerData) {
|
|
2672
|
+
workerData.startupTimeout = null;
|
|
2673
|
+
if (workerData.workerAlive) {
|
|
2674
|
+
return;
|
|
2675
|
+
}
|
|
2676
|
+
const { rejectResult, writer } = workerData;
|
|
2677
|
+
terminateWorker$1(workerData);
|
|
2678
|
+
workerData.worker = null;
|
|
2679
|
+
if (rejectResult) {
|
|
2680
|
+
const error = new Error(ERR_WORKER_STARTUP_TIMEOUT);
|
|
2681
|
+
error.workerStartupFailed = true;
|
|
2682
|
+
rejectResult(error);
|
|
2683
|
+
if (writer) {
|
|
2684
|
+
writer.releaseLock();
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
|
|
2689
|
+
function clearStartupTimeout(workerData) {
|
|
2690
|
+
const { startupTimeout } = workerData;
|
|
2691
|
+
if (startupTimeout) {
|
|
2692
|
+
clearTimeout(startupTimeout);
|
|
2693
|
+
workerData.startupTimeout = null;
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2501
2697
|
function onWorkerError(event, workerData) {
|
|
2502
2698
|
if (event.preventDefault) {
|
|
2503
2699
|
event.preventDefault();
|
|
2504
2700
|
}
|
|
2505
|
-
|
|
2701
|
+
clearStartupTimeout(workerData);
|
|
2702
|
+
const { workerAlive, rejectResult, writer, onTaskFinished } = workerData;
|
|
2506
2703
|
terminateWorker$1(workerData);
|
|
2704
|
+
if (!workerAlive) {
|
|
2705
|
+
workerData.worker = null;
|
|
2706
|
+
}
|
|
2507
2707
|
if (rejectResult) {
|
|
2508
|
-
|
|
2708
|
+
let error = event.error || new Error(event.message || ERROR_EVENT_TYPE);
|
|
2709
|
+
if (!workerAlive) {
|
|
2710
|
+
error = Object.assign(new Error(error.message || ERROR_EVENT_TYPE), { workerStartupFailed: true });
|
|
2711
|
+
}
|
|
2712
|
+
rejectResult(error);
|
|
2509
2713
|
if (writer) {
|
|
2510
2714
|
writer.releaseLock();
|
|
2511
2715
|
}
|
|
2512
|
-
|
|
2716
|
+
if (workerAlive) {
|
|
2717
|
+
onTaskFinished();
|
|
2718
|
+
}
|
|
2513
2719
|
}
|
|
2514
2720
|
}
|
|
2515
2721
|
|
|
2516
|
-
function sendMessage(message, { worker, writer, transferStreams }) {
|
|
2722
|
+
function sendMessage(message, { worker, writer, transferStreams, workerAlive }) {
|
|
2517
2723
|
try {
|
|
2518
2724
|
const { value, readable, writable } = message;
|
|
2519
2725
|
const transferables = [];
|
|
@@ -2521,7 +2727,7 @@
|
|
|
2521
2727
|
message.value = toExactUint8Array(value);
|
|
2522
2728
|
transferables.push(message.value.buffer);
|
|
2523
2729
|
}
|
|
2524
|
-
if (transferStreams && transferStreamsSupported) {
|
|
2730
|
+
if (transferStreams && transferStreamsSupported && workerAlive) {
|
|
2525
2731
|
if (readable) {
|
|
2526
2732
|
transferables.push(readable);
|
|
2527
2733
|
}
|
|
@@ -2640,11 +2846,18 @@
|
|
|
2640
2846
|
|
|
2641
2847
|
async function runWorker(stream, workerOptions) {
|
|
2642
2848
|
const { options, config } = workerOptions;
|
|
2643
|
-
const { transferStreams, useWebWorkers, useCompressionStream, compressed, signed, encrypted } = options;
|
|
2849
|
+
const { transferStreams, useWebWorkers, useCompressionStream, compressed, signed, encrypted, format, codecURI } = options;
|
|
2644
2850
|
const { workerURI, maxWorkers } = config;
|
|
2851
|
+
if (format) {
|
|
2852
|
+
if (codecURI) {
|
|
2853
|
+
options.codecURI = resolveCodecURI(codecURI, config.baseURI);
|
|
2854
|
+
}
|
|
2855
|
+
await ensureCodecStreams(format, options.codecURI);
|
|
2856
|
+
}
|
|
2645
2857
|
workerOptions.transferStreams = transferStreams || (transferStreams === UNDEFINED_VALUE && config.transferStreams);
|
|
2646
2858
|
const streamCopy = !compressed && !signed && !encrypted;
|
|
2647
|
-
|
|
2859
|
+
const workerSupported = format === UNDEFINED_VALUE || Boolean(options.codecURI);
|
|
2860
|
+
workerOptions.useWebWorkers = !streamCopy && workerSupported && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
2648
2861
|
workerOptions.workerURI = workerOptions.useWebWorkers && workerURI ? workerURI : UNDEFINED_VALUE;
|
|
2649
2862
|
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
2650
2863
|
return (await getWorker()).run();
|
|
@@ -2684,6 +2897,14 @@
|
|
|
2684
2897
|
}
|
|
2685
2898
|
}
|
|
2686
2899
|
|
|
2900
|
+
function resolveCodecURI(codecURI, baseURI) {
|
|
2901
|
+
try {
|
|
2902
|
+
return new URL(codecURI, baseURI).toString();
|
|
2903
|
+
} catch {
|
|
2904
|
+
return codecURI;
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2687
2908
|
function armStarvationTimeout() {
|
|
2688
2909
|
if (!starvationTimeout && pendingRequests.length && Number.isFinite(starvationDelay) && starvationDelay >= 0) {
|
|
2689
2910
|
starvationTimeout = setTimeout(onWorkerStarvation, starvationDelay);
|
|
@@ -2744,6 +2965,7 @@
|
|
|
2744
2965
|
clearTerminateTimeout(workerData);
|
|
2745
2966
|
return workerData.terminate();
|
|
2746
2967
|
}));
|
|
2968
|
+
resetWebWorkerSupport();
|
|
2747
2969
|
}
|
|
2748
2970
|
|
|
2749
2971
|
/*
|
|
@@ -3967,6 +4189,7 @@
|
|
|
3967
4189
|
const OPTION_PREVENT_CLOSE = "preventClose";
|
|
3968
4190
|
const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
|
|
3969
4191
|
const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
|
|
4192
|
+
const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
|
|
3970
4193
|
const OPTION_KEEP_ORDER = "keepOrder";
|
|
3971
4194
|
const OPTION_LEVEL = "level";
|
|
3972
4195
|
const OPTION_BUFFERED_WRITE = "bufferedWrite";
|
|
@@ -4026,6 +4249,7 @@
|
|
|
4026
4249
|
const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
4027
4250
|
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
4028
4251
|
const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
|
|
4252
|
+
const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
|
|
4029
4253
|
const CHARSET_UTF8 = "utf-8";
|
|
4030
4254
|
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
|
|
4031
4255
|
const CHARSET_CP437 = "cp437";
|
|
@@ -4103,6 +4327,7 @@
|
|
|
4103
4327
|
let prependedDataLength = 0;
|
|
4104
4328
|
let startOffset;
|
|
4105
4329
|
let zip64EndOfDirectory;
|
|
4330
|
+
let zip64EndOfDirectoryVersion2;
|
|
4106
4331
|
const requiresZip64 = directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS;
|
|
4107
4332
|
if (directoryDataOffset != MAX_32_BITS && diskNumber != MAX_16_BITS) {
|
|
4108
4333
|
directoryDataOffset += getDiskOffset$1(reader, diskNumber);
|
|
@@ -4132,6 +4357,7 @@
|
|
|
4132
4357
|
throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
|
|
4133
4358
|
}
|
|
4134
4359
|
zip64EndOfDirectory = true;
|
|
4360
|
+
zip64EndOfDirectoryVersion2 = getBigUint64(endOfDirectoryView, 4) > ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12;
|
|
4135
4361
|
if (lastDiskNumber == MAX_16_BITS) {
|
|
4136
4362
|
lastDiskNumber = getUint32(endOfDirectoryView, 16);
|
|
4137
4363
|
} else if (checkAmbiguity && lastDiskNumber != getUint32(endOfDirectoryView, 16)) {
|
|
@@ -4211,6 +4437,9 @@
|
|
|
4211
4437
|
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
4212
4438
|
const fileEntry = new ZipEntry$1(reader, config, zipReader.options);
|
|
4213
4439
|
if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
4440
|
+
if (indexFile == 0 && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
|
|
4441
|
+
throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
|
|
4442
|
+
}
|
|
4214
4443
|
throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);
|
|
4215
4444
|
}
|
|
4216
4445
|
readCommonHeader(fileEntry, directoryView, offset + 6);
|
|
@@ -4438,7 +4667,8 @@
|
|
|
4438
4667
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4439
4668
|
}
|
|
4440
4669
|
}
|
|
4441
|
-
|
|
4670
|
+
const registeredCodec = passThrough ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
4671
|
+
if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64 && !registeredCodec) && !passThrough) {
|
|
4442
4672
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4443
4673
|
}
|
|
4444
4674
|
if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
@@ -4477,7 +4707,10 @@
|
|
|
4477
4707
|
fileEntry.zipCrypto = zipCrypto;
|
|
4478
4708
|
}
|
|
4479
4709
|
if (encrypted) {
|
|
4480
|
-
if (
|
|
4710
|
+
if ((localDirectory.rawBitFlag & BITFLAG_STRONG_ENCRYPTION) == BITFLAG_STRONG_ENCRYPTION) {
|
|
4711
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4712
|
+
}
|
|
4713
|
+
if (!zipCrypto && (extraFieldAES.strength < 1 || extraFieldAES.strength > 3)) {
|
|
4481
4714
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4482
4715
|
} else if (!password && !rawPassword) {
|
|
4483
4716
|
throw new Error(ERR_ENCRYPTED);
|
|
@@ -4516,6 +4749,8 @@
|
|
|
4516
4749
|
useCompressionStream,
|
|
4517
4750
|
transferStreams: getOptionValue$1(zipEntry, options, OPTION_TRANSFER_STREAMS),
|
|
4518
4751
|
deflate64,
|
|
4752
|
+
format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
|
|
4753
|
+
codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
|
|
4519
4754
|
checkPasswordOnly
|
|
4520
4755
|
},
|
|
4521
4756
|
config,
|
|
@@ -4568,6 +4803,16 @@
|
|
|
4568
4803
|
}
|
|
4569
4804
|
};
|
|
4570
4805
|
|
|
4806
|
+
function detectEncryptedCentralDirectory(directoryView) {
|
|
4807
|
+
const maxOffset = Math.min(directoryView.byteLength, 1024) - 3;
|
|
4808
|
+
for (let offset = 0; offset < maxOffset; offset++) {
|
|
4809
|
+
if (getUint32(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
|
|
4810
|
+
return true;
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4813
|
+
return false;
|
|
4814
|
+
}
|
|
4815
|
+
|
|
4571
4816
|
function readCommonHeader(directory, dataView, offset) {
|
|
4572
4817
|
const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
|
|
4573
4818
|
const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
|
|
@@ -5082,6 +5327,7 @@
|
|
|
5082
5327
|
ERR_BAD_FORMAT: ERR_BAD_FORMAT,
|
|
5083
5328
|
ERR_CENTRAL_DIRECTORY_NOT_FOUND: ERR_CENTRAL_DIRECTORY_NOT_FOUND,
|
|
5084
5329
|
ERR_ENCRYPTED: ERR_ENCRYPTED,
|
|
5330
|
+
ERR_ENCRYPTED_CENTRAL_DIRECTORY: ERR_ENCRYPTED_CENTRAL_DIRECTORY,
|
|
5085
5331
|
ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
|
|
5086
5332
|
ERR_EOCDR_NOT_FOUND: ERR_EOCDR_NOT_FOUND,
|
|
5087
5333
|
ERR_EXTRAFIELD_ZIP64_NOT_FOUND: ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
|
|
@@ -5133,6 +5379,7 @@
|
|
|
5133
5379
|
const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
|
|
5134
5380
|
const ERR_INVALID_VERSION = "Version exceeds 65535";
|
|
5135
5381
|
const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
|
|
5382
|
+
const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
|
|
5136
5383
|
const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
|
|
5137
5384
|
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
5138
5385
|
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
@@ -5493,7 +5740,11 @@
|
|
|
5493
5740
|
if (versionMadeBy > MAX_16_BITS) {
|
|
5494
5741
|
throw new Error(ERR_INVALID_VERSION);
|
|
5495
5742
|
}
|
|
5496
|
-
let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES
|
|
5743
|
+
let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES);
|
|
5744
|
+
const externalFileAttributesProvided = externalFileAttributes !== UNDEFINED_VALUE;
|
|
5745
|
+
if (!externalFileAttributesProvided) {
|
|
5746
|
+
externalFileAttributes = 0;
|
|
5747
|
+
}
|
|
5497
5748
|
if (!options[PROPERTY_NAME_DIRECTORY] && name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
5498
5749
|
options[PROPERTY_NAME_DIRECTORY] = true;
|
|
5499
5750
|
}
|
|
@@ -5502,13 +5753,13 @@
|
|
|
5502
5753
|
if (!name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
5503
5754
|
name += DIRECTORY_SIGNATURE;
|
|
5504
5755
|
}
|
|
5505
|
-
if (
|
|
5756
|
+
if (!externalFileAttributesProvided) {
|
|
5506
5757
|
externalFileAttributes = FILE_ATTR_MSDOS_DIR_MASK;
|
|
5507
5758
|
if (!msDosCompatible) {
|
|
5508
5759
|
externalFileAttributes |= (FILE_ATTR_UNIX_TYPE_DIR | FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_DEFAULT_MASK) << 16;
|
|
5509
5760
|
}
|
|
5510
5761
|
}
|
|
5511
|
-
} else if (!msDosCompatible &&
|
|
5762
|
+
} else if (!msDosCompatible && !externalFileAttributesProvided) {
|
|
5512
5763
|
if (executable) {
|
|
5513
5764
|
externalFileAttributes = (FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_DEFAULT_MASK) << 16;
|
|
5514
5765
|
} else {
|
|
@@ -5517,6 +5768,7 @@
|
|
|
5517
5768
|
}
|
|
5518
5769
|
let unixExternalUpper;
|
|
5519
5770
|
if (!msDosCompatible) {
|
|
5771
|
+
const unixModeProvided = unixMode !== UNDEFINED_VALUE || Boolean(setuid || setgid || sticky);
|
|
5520
5772
|
unixExternalUpper = (externalFileAttributes >> 16) & MAX_16_BITS;
|
|
5521
5773
|
unixMode = unixMode === UNDEFINED_VALUE ? unixExternalUpper : (unixMode & MAX_16_BITS);
|
|
5522
5774
|
if (setuid) {
|
|
@@ -5534,10 +5786,12 @@
|
|
|
5534
5786
|
} else {
|
|
5535
5787
|
sticky = Boolean(unixMode & FILE_ATTR_UNIX_STICKY_MASK);
|
|
5536
5788
|
}
|
|
5537
|
-
if (
|
|
5538
|
-
|
|
5789
|
+
if (!externalFileAttributesProvided || unixModeProvided) {
|
|
5790
|
+
if (directory) {
|
|
5791
|
+
unixMode |= FILE_ATTR_UNIX_TYPE_DIR;
|
|
5792
|
+
}
|
|
5793
|
+
externalFileAttributes = ((unixMode & MAX_16_BITS) << 16) | (externalFileAttributes & MAX_16_BITS);
|
|
5539
5794
|
}
|
|
5540
|
-
externalFileAttributes = ((unixMode & MAX_16_BITS) << 16) | (externalFileAttributes & MAX_8_BITS);
|
|
5541
5795
|
}
|
|
5542
5796
|
({ msdosAttributesRaw, msdosAttributes } = normalizeMsdosAttributes(msdosAttributesRaw, msdosAttributes));
|
|
5543
5797
|
if (hasMsDosProvided) {
|
|
@@ -5597,6 +5851,7 @@
|
|
|
5597
5851
|
const encryptionStrength = getOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
5598
5852
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
5599
5853
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
5854
|
+
const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
|
|
5600
5855
|
const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
|
|
5601
5856
|
const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
|
|
5602
5857
|
const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
|
|
@@ -5606,11 +5861,20 @@
|
|
|
5606
5861
|
const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
|
|
5607
5862
|
const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
|
|
5608
5863
|
const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
|
|
5864
|
+
const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
5609
5865
|
if (!passThrough && compressionMethod !== UNDEFINED_VALUE &&
|
|
5610
|
-
compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE) {
|
|
5866
|
+
compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE && !registeredCodec) {
|
|
5611
5867
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
5612
5868
|
}
|
|
5613
5869
|
let level = getOptionValue(zipWriter, options, OPTION_LEVEL);
|
|
5870
|
+
if (zipWriter.options[OPTION_USDZ]) {
|
|
5871
|
+
if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
|
|
5872
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
|
|
5873
|
+
}
|
|
5874
|
+
if (level === UNDEFINED_VALUE && compressionMethod === UNDEFINED_VALUE) {
|
|
5875
|
+
level = 0;
|
|
5876
|
+
}
|
|
5877
|
+
}
|
|
5614
5878
|
let useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
|
|
5615
5879
|
let dataDescriptor = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR);
|
|
5616
5880
|
if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
|
|
@@ -5622,7 +5886,7 @@
|
|
|
5622
5886
|
if (level !== UNDEFINED_VALUE && level != 6) {
|
|
5623
5887
|
useCompressionStream = false;
|
|
5624
5888
|
}
|
|
5625
|
-
if (!useCompressionStream && (zipWriter.config.CompressionStream === UNDEFINED_VALUE && zipWriter.config.CompressionStreamZlib === UNDEFINED_VALUE)) {
|
|
5889
|
+
if (!useCompressionStream && !registeredCodec && (zipWriter.config.CompressionStream === UNDEFINED_VALUE && zipWriter.config.CompressionStreamZlib === UNDEFINED_VALUE)) {
|
|
5626
5890
|
level = 0;
|
|
5627
5891
|
}
|
|
5628
5892
|
const zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
@@ -5666,6 +5930,7 @@
|
|
|
5666
5930
|
encryptionStrength,
|
|
5667
5931
|
zipCrypto,
|
|
5668
5932
|
extendedTimestamp,
|
|
5933
|
+
ntfsTimestamp,
|
|
5669
5934
|
keepOrder,
|
|
5670
5935
|
useWebWorkers,
|
|
5671
5936
|
transferStreams,
|
|
@@ -5675,6 +5940,9 @@
|
|
|
5675
5940
|
signal,
|
|
5676
5941
|
useUnicodeFileNames,
|
|
5677
5942
|
compressionMethod,
|
|
5943
|
+
format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
|
|
5944
|
+
codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
|
|
5945
|
+
codecVersionNeeded: registeredCodec ? registeredCodec.versionNeeded : UNDEFINED_VALUE,
|
|
5678
5946
|
level,
|
|
5679
5947
|
useCompressionStream,
|
|
5680
5948
|
dataDescriptor,
|
|
@@ -5971,7 +6239,9 @@
|
|
|
5971
6239
|
msdosAttributesRaw,
|
|
5972
6240
|
msdosAttributes,
|
|
5973
6241
|
useCompressionStream,
|
|
5974
|
-
passThrough
|
|
6242
|
+
passThrough,
|
|
6243
|
+
format,
|
|
6244
|
+
codecURI
|
|
5975
6245
|
} = options;
|
|
5976
6246
|
const fileEntry = {
|
|
5977
6247
|
lock,
|
|
@@ -6031,7 +6301,9 @@
|
|
|
6031
6301
|
encrypted: encrypted && !passThrough,
|
|
6032
6302
|
useWebWorkers,
|
|
6033
6303
|
useCompressionStream,
|
|
6034
|
-
transferStreams
|
|
6304
|
+
transferStreams,
|
|
6305
|
+
format,
|
|
6306
|
+
codecURI
|
|
6035
6307
|
},
|
|
6036
6308
|
config,
|
|
6037
6309
|
streamOptions: { signal, size, onstart, onprogress, onend }
|
|
@@ -6103,6 +6375,7 @@
|
|
|
6103
6375
|
rawExtraField,
|
|
6104
6376
|
encryptionStrength,
|
|
6105
6377
|
extendedTimestamp,
|
|
6378
|
+
ntfsTimestamp,
|
|
6106
6379
|
passThrough,
|
|
6107
6380
|
encrypted,
|
|
6108
6381
|
zip64UncompressedSize,
|
|
@@ -6148,7 +6421,8 @@
|
|
|
6148
6421
|
let extraFieldExtendedTimestampFlag;
|
|
6149
6422
|
if (extendedTimestamp) {
|
|
6150
6423
|
const lastModTimeUnix = getTimeUnix(lastModDate);
|
|
6151
|
-
|
|
6424
|
+
const lastModTimeUnixInRange = inUnixTimeRange(lastModTimeUnix);
|
|
6425
|
+
if (lastModTimeUnixInRange) {
|
|
6152
6426
|
const extraFieldTimestampLength = 9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0);
|
|
6153
6427
|
const extraFieldTimestamp = createRecordWriter(extraFieldTimestampLength);
|
|
6154
6428
|
extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
|
|
@@ -6166,19 +6440,26 @@
|
|
|
6166
6440
|
} else {
|
|
6167
6441
|
rawExtraFieldExtendedTimestamp = EMPTY_UINT8_ARRAY;
|
|
6168
6442
|
}
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6443
|
+
const writeExtraFieldNTFS = ntfsTimestamp === UNDEFINED_VALUE ?
|
|
6444
|
+
!lastModTimeUnixInRange || Boolean(lastAccessDate || creationDate) :
|
|
6445
|
+
ntfsTimestamp;
|
|
6446
|
+
if (writeExtraFieldNTFS) {
|
|
6447
|
+
try {
|
|
6448
|
+
const lastModTimeNTFS = getTimeNTFS(lastModDate);
|
|
6449
|
+
const extraFieldNTFS = createRecordWriter(36);
|
|
6450
|
+
extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS);
|
|
6451
|
+
extraFieldNTFS.uint16(32);
|
|
6452
|
+
extraFieldNTFS.skip(4);
|
|
6453
|
+
extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
|
|
6454
|
+
extraFieldNTFS.uint16(24);
|
|
6455
|
+
extraFieldNTFS.uint64(lastModTimeNTFS);
|
|
6456
|
+
extraFieldNTFS.uint64(getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
|
|
6457
|
+
extraFieldNTFS.uint64(getTimeNTFS(creationDate) || lastModTimeNTFS);
|
|
6458
|
+
rawExtraFieldNTFS = extraFieldNTFS.array;
|
|
6459
|
+
} catch {
|
|
6460
|
+
rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
|
|
6461
|
+
}
|
|
6462
|
+
} else {
|
|
6182
6463
|
rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
|
|
6183
6464
|
}
|
|
6184
6465
|
} else {
|
|
@@ -6216,6 +6497,10 @@
|
|
|
6216
6497
|
if (compressionMethod === UNDEFINED_VALUE) {
|
|
6217
6498
|
compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
|
|
6218
6499
|
}
|
|
6500
|
+
const { codecVersionNeeded } = options;
|
|
6501
|
+
if (compressed && codecVersionNeeded !== UNDEFINED_VALUE) {
|
|
6502
|
+
version = version > codecVersionNeeded ? version : codecVersionNeeded;
|
|
6503
|
+
}
|
|
6219
6504
|
if (zip64) {
|
|
6220
6505
|
version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
|
|
6221
6506
|
}
|
|
@@ -6229,6 +6514,7 @@
|
|
|
6229
6514
|
if (extraFieldLength > MAX_16_BITS) {
|
|
6230
6515
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
6231
6516
|
}
|
|
6517
|
+
const dosLastModDate = new Date(Math.ceil(lastModDate.getTime() / 2000) * 2000);
|
|
6232
6518
|
const {
|
|
6233
6519
|
headerArray,
|
|
6234
6520
|
headerView,
|
|
@@ -6238,7 +6524,7 @@
|
|
|
6238
6524
|
bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
|
|
6239
6525
|
compressionMethod,
|
|
6240
6526
|
uncompressedSize,
|
|
6241
|
-
lastModDate:
|
|
6527
|
+
lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
|
|
6242
6528
|
rawFilename,
|
|
6243
6529
|
zip64CompressedSize,
|
|
6244
6530
|
zip64UncompressedSize,
|
|
@@ -10368,11 +10654,14 @@
|
|
|
10368
10654
|
exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
|
|
10369
10655
|
exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
|
|
10370
10656
|
exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
|
|
10657
|
+
exports.ERR_ENCRYPTED_CENTRAL_DIRECTORY = ERR_ENCRYPTED_CENTRAL_DIRECTORY;
|
|
10371
10658
|
exports.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND;
|
|
10372
10659
|
exports.ERR_EOCDR_NOT_FOUND = ERR_EOCDR_NOT_FOUND;
|
|
10373
10660
|
exports.ERR_EXTRAFIELD_ZIP64_NOT_FOUND = ERR_EXTRAFIELD_ZIP64_NOT_FOUND;
|
|
10374
10661
|
exports.ERR_HTTP_RANGE = ERR_HTTP_RANGE;
|
|
10375
10662
|
exports.ERR_HTTP_RESOURCE_CHANGED = ERR_HTTP_RESOURCE_CHANGED;
|
|
10663
|
+
exports.ERR_INVALID_CODEC_DEFINITION = ERR_INVALID_CODEC_DEFINITION;
|
|
10664
|
+
exports.ERR_INVALID_CODEC_MODULE = ERR_INVALID_CODEC_MODULE;
|
|
10376
10665
|
exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
|
|
10377
10666
|
exports.ERR_INVALID_COMPRESSED_DATA = ERR_INVALID_COMPRESSED_DATA;
|
|
10378
10667
|
exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
|
|
@@ -10387,11 +10676,13 @@
|
|
|
10387
10676
|
exports.ERR_ITERATOR_COMPLETED_TOO_SOON = ERR_ITERATOR_COMPLETED_TOO_SOON;
|
|
10388
10677
|
exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
|
|
10389
10678
|
exports.ERR_OVERLAPPING_ENTRY = ERR_OVERLAPPING_ENTRY;
|
|
10679
|
+
exports.ERR_RESERVED_COMPRESSION_METHOD = ERR_RESERVED_COMPRESSION_METHOD;
|
|
10390
10680
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
10391
10681
|
exports.ERR_UNDEFINED_READER = ERR_UNDEFINED_READER;
|
|
10392
10682
|
exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
|
|
10393
10683
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION$1;
|
|
10394
10684
|
exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
|
|
10685
|
+
exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
|
|
10395
10686
|
exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
|
|
10396
10687
|
exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;
|
|
10397
10688
|
exports.ERR_ZIP_NOT_EMPTY = ERR_ZIP_NOT_EMPTY;
|
|
@@ -10415,7 +10706,9 @@
|
|
|
10415
10706
|
exports.createSyncAccessHandleTempStream = createSyncAccessHandleTempStream;
|
|
10416
10707
|
exports.fs = fs;
|
|
10417
10708
|
exports.getMimeType = getMimeType;
|
|
10709
|
+
exports.registerCodec = registerCodec;
|
|
10418
10710
|
exports.resetConfiguration = resetConfiguration;
|
|
10419
10711
|
exports.terminateWorkers = terminateWorkersAndModule;
|
|
10712
|
+
exports.unregisterCodec = unregisterCodec;
|
|
10420
10713
|
|
|
10421
10714
|
}));
|