@zip.js/zip.js 2.8.49 → 2.8.50
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 +1 -1
- package/dist/zip-core-external.js +333 -203
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +339 -203
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +420 -214
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +212 -450
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +420 -214
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +426 -214
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +426 -214
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +339 -203
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +339 -203
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +339 -203
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +425 -213
- package/index-native.min.js +1 -1
- package/index.cjs +425 -213
- package/index.d.cts +124 -2
- package/index.d.ts +124 -2
- package/index.min.js +1 -1
- package/lib/core/codec-registry.js +2 -2
- package/lib/core/codec-worker-web.js +436 -0
- package/lib/core/codec-worker.js +23 -404
- package/lib/core/constants.js +5 -1
- package/lib/core/io.js +2 -1
- package/lib/core/options.js +8 -0
- package/lib/core/zip-fs.js +88 -12
- package/lib/core/zip-reader.js +90 -16
- package/lib/core/zip-writer.js +36 -13
- package/lib/zip-core-reader.js +6 -0
- package/lib/zip-core-writer.js +4 -0
- package/package.json +1 -1
package/dist/zip-fs.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.zip = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
const { Array, Object, String, Number, BigInt, Math, Date, Map, Set, Response, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, document, crypto, btoa, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream, navigator, Worker } = typeof globalThis !== 'undefined' ? globalThis : this || self;
|
|
7
|
+
const { Array, Object, String, Number, BigInt, Math, Date, Map, Set, Response, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, document, crypto, btoa, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream, navigator, Worker, Symbol, setTimeout, clearTimeout, structuredClone } = typeof globalThis !== 'undefined' ? globalThis : this || self;
|
|
8
8
|
|
|
9
9
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
10
|
/*
|
|
@@ -117,6 +117,8 @@
|
|
|
117
117
|
const UNDEFINED_TYPE = "undefined";
|
|
118
118
|
const FUNCTION_TYPE = "function";
|
|
119
119
|
const OBJECT_TYPE = "object";
|
|
120
|
+
const STRING_TYPE = "string";
|
|
121
|
+
const NUMBER_TYPE = "number";
|
|
120
122
|
|
|
121
123
|
const EMPTY_UINT8_ARRAY = new Uint8Array();
|
|
122
124
|
|
|
@@ -248,7 +250,7 @@
|
|
|
248
250
|
const t$1=new Uint8Array(288);t$1.fill(8,0,144),t$1.fill(9,144,256),t$1.fill(7,256,280),t$1.fill(8,280,288),new Uint8Array(30).fill(5);const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n$1=t=>t({workerURI:t=>{const n="text/javascript";let s='(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:c,Uint32Array:i,Int32Array:a,Map:f,DataView:l,Promise:w,TextEncoder:u,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;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,M,P,D,F,B]=C;class R{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=B[255&t]^F[t>>>8&255]^D[t>>>16&255]^P[t>>>24&255]^M[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 U extends d{constructor(){let t;const e=new R;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 W(t,e){const n=new o(t.length+e.length);return n.set(t),n.set(e,t.length),n}function _(t){return new l(t.buffer,t.byteOffset,t.byteLength)}const T={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=T.l(n);return 32===s?t.concat(e):T.h(e,s,0|n,t.slice(0,t.length-1))},bitLength(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+T.l(n)},m(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]=T.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=T.l(r);return s.push(T.S(e+o&31,e+o>32?n:s.pop(),1)),s}},V={bytes:{v(t){const e=T.bitLength(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},C(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(T.S(8*(3&n),s)),e}}},K=class{constructor(t){const e=this;e.blockSize=512,e.A=[1732584193,4023233417,2562383102,271733878,3285377520],e.I=[1518500249,1859775393,2400959708,3395469782],t?(e.M=t.M.slice(0),e.P=t.P.slice(0),e.D=t.D):e.reset()}reset(){const t=this;return t.M=t.A.slice(0),t.P=[],t.D=0,t}update(t){const e=this;"string"==typeof t&&(t=V.F.C(t));const n=e.P=T.concat(e.P,t),s=e.D,o=e.D=s+T.bitLength(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new i(n);let a=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.B(c.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),e}R(){const t=this;let e=t.P;const n=t.M;e=T.concat(e,[T.S(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.D/4294967296)),e.push(0|t.D);e.length;)t.B(e.splice(0,16));return t.reset(),n}U(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}B(e){const n=this,r=n.M,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let c=r[0],i=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,c)+n.U(t,i,a,f)+l+o[t]+n.I[s.floor(t/20)]|0;l=f,f=a,a=n.W(30,i),i=c,c=e}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]+l|0}},E={importKey:t=>new E._(V.bytes.C(t)),T(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 c,i,a,f,w;const u=new ArrayBuffer(o),h=new l(u);let p=0;const d=T;for(e=V.bytes.C(e),w=1;(o||1)>p;w++){for(c=i=t.encrypt(d.concat(e,[w])),a=1;n>a;a++)for(i=t.encrypt(i),f=0;f<i.length;f++)c[f]^=i[f];for(a=0;(o||1)>p&&a<c.length;a++)h.setInt32(p,c[a]),p+=4}return u.slice(0,s/8)},_:class{constructor(t){const e=this,n=e.V=K,s=[[],[]];e.K=[new n,new n];const r=e.K[0].blockSize/32;t.length>r&&(t=(new n).update(t).R());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.K[0].update(s[0]),e.K[1].update(s[1]),e.L=new n(e.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,e=t.L.R(),n=new t.V(t.K[1]).update(e).R();return t.reset(),n}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=e.assign({hash:{name:"HMAC"}},J),X=e.assign({iterations:1e3,hash:{name:"SHA-1"}},J),Y=["deriveBits"],Z=[8,12,16],$=[16,24,32],tt=10,et=[0,0,0,0],nt=typeof h!=b,st=nt&&h.subtle,rt=nt&&typeof st!=b,ot=V.bytes,ct=class{constructor(t){const e=this;e.j=[[[],[],[],[],[]],[[],[],[],[],[]]],e.j[0][0][0]||e.H();const n=e.j[0][4],s=e.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(e.I=[i=t.slice(0),a=[]],c=o;4*o+28>c;c++){let t=i[c-1];(c%o===0||8===o&&c%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[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 e=i[3&t?c:c-4];a[t]=4>=c||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)}H(){const t=this.j[0],e=this.j[1],n=t[4],s=e[4],r=[],o=[];let c,i,a,f;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=c=0;!n[l];l^=i||1,c=o[c]||1){let o=c^c<<1^c<<2^c<<3^c<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,f=r[a=r[i=r[l]]];let w=16843009*f^65537*a^257*i^16843008*l,u=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=u=u<<24^u>>>8,e[n][o]=w=w<<24^w>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}N(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.I[e],s=n.length/4-2,o=[0,0,0,0],c=this.j[e],i=c[0],a=c[1],f=c[2],l=c[3],w=c[4];let u,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],S=t[e?1:3]^n[3],g=4;for(let t=0;s>t;t++)u=i[d>>>24]^a[y>>16&255]^f[m>>8&255]^l[255&S]^n[g],h=i[y>>>24]^a[m>>16&255]^f[S>>8&255]^l[255&d]^n[g+1],p=i[m>>>24]^a[S>>16&255]^f[d>>8&255]^l[255&y]^n[g+2],S=i[S>>>24]^a[d>>16&255]^f[y>>8&255]^l[255&m]^n[g+3],g+=4,d=u,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=w[d>>>24]<<24^w[y>>16&255]<<16^w[m>>8&255]<<8^w[255&S]^n[g++],u=d,d=y,y=m,m=S,S=u;return o}},it=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)}Z(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}$(t){0===(t[0]=this.Z(t[0]))&&(t[1]=this.Z(t[1]))}Y(t,e,n){let s;if(!(s=e.length))return[];const r=T.bitLength(e);for(let r=0;s>r;r+=4){this.$(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 T.m(e,r)}},at=E._;let ft=nt&&rt&&typeof st.importKey==k,lt=nt&&rt&&typeof st.deriveBits==k;class wt extends d{constructor({password:t,rawPassword:e,encryptionStrength:n,checkPasswordOnly:s,checkAuthenticationCode:c=!0}){super({start(){ht(this,t,e,n)},async transform(t,e){const n=this,{password:c,strength:i,et:a,ready:f}=n;c?(await(async(t,e,n,s)=>{const o=await dt(t,e,n,mt(s,0,Z[e])),c=mt(s,Z[e]);if(o[0]!=c[0]||o[1]!=c[1])throw new r(O)})(n,i,c,mt(t,0,Z[i]+2)),t=mt(t,Z[i]+2),s?e.error(new r(N)):a()):await f;const l=new o(t.length-tt-(t.length-tt)%G);e.enqueue(pt(n,t,l,0,tt,!0))},async flush(t){const{nt:e,st:n,pending:s,ready:o}=this;if(n&&e){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);n.update(t);const s=e.update(t);f=St(ot,s)}const l=mt(St(ot,n.digest()),0,tt);let w=s.length<tt?1:0;for(let t=0;tt>t;t++)w|=l[t]^a[t];if(w&&c)throw new r(H);t.enqueue(f)}}})}}class ut extends d{constructor({password:t,rawPassword:e,encryptionStrength:n}){super({start(){ht(this,t,e,n)},async transform(t,e){const n=this,{password:s,strength:r,et:c,ready:i}=n;let a=z;s?(a=await(async(t,e,n)=>{const s=q(new o(Z[e]));return W(s,await dt(t,e,n,s))})(n,r,s),c()):await i;const f=new o(a.length+t.length-t.length%G);f.set(a,0),e.enqueue(pt(n,t,f,a.length,0))},async flush(t){const{nt:e,st:n,pending:s,ready:r}=this;if(n&&e){await r;let o=z;if(s.length){const t=e.update(gt(ot,s));n.update(t),o=St(ot,t)}const c=St(ot,n.digest()).slice(0,tt);t.enqueue(W(o,c))}}})}}function ht(t,n,s,r){e.assign(t,{ready:new w(e=>t.et=e),password:yt(n,s),strength:r-1,pending:z})}function pt(t,e,n,s,r,c){const{nt:i,st:a,pending:f}=t;f.length&&(e=W(f,e));const l=e.length-r;let w;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(l-l%G)),w=0;l-G>=w;w+=G){const t=gt(ot,mt(e,w,w+G));c&&a.update(t);const r=i.update(t);c||a.update(r),n.set(St(ot,r),w+s)}return t.pending=mt(e,w),n}async function dt(n,s,r,c){n.password=null;const i=await(async(t,e,n,s,r)=>{if(!ft)return E.importKey(e);try{return await st.importKey("raw",e,n,!1,r)}catch{return ft=!1,E.importKey(e)}})(0,r,Q,0,Y),a=await(async(t,e,n)=>{if(!lt)return E.T(e,t.salt,X.iterations,n);try{return await st.deriveBits(t,e,n)}catch{return lt=!1,E.T(e,t.salt,X.iterations,n)}})(e.assign({salt:c},X),i,8*(2*$[s]+2)),f=new o(a),l=gt(ot,mt(f,0,$[s])),w=gt(ot,mt(f,$[s],2*$[s])),u=mt(f,2*$[s]);return e.assign(n,{keys:{key:l,ot:w,passwordVerification:u},nt:new it(new ct(l),t.from(et)),st:new at(w)}),u}function yt(t,e){return e===v?(t=>{if(typeof u==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 u).encode(t)})(t):e}function mt(t,e,n){return t.subarray(e,n)}function St(t,e){return t.v(e)}function gt(t,e){return t.C(e)}class vt extends d{constructor({password:t,rawPassword:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){kt(this,t,e,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=zt(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e[11]^n.passwordVerification))throw new r(O);t=t.subarray(12)}s?e.error(new r(N)):e.enqueue(zt(n,t))}})}}class bt extends d{constructor({password:t,rawPassword:e,passwordVerification:n}){super({start(){kt(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=q(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(Ct(n,e),0),r=12}else s=new o(t.length),r=0;s.set(Ct(n,t),r),e.enqueue(s)}})}}function kt(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(r[0]),it:new R(r[2])}),s)for(let e=0;e<s.length;e++)At(t,s[e]);else for(let e=0;e<n.length;e++)At(t,n.charCodeAt(e))})(t,n,s)}function zt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=It(t)^e[s],At(t,n[s]);return n}function Ct(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=It(t)^e[s],At(t,e[s]);return n}function At(t,e){let[,n]=t.keys;t.ct.append([e]);const r=~t.ct.get();n=Mt(s.imul(Mt(n+xt(r)),134775813)+1),t.it.append([n>>>24]);const o=~t.it.get();t.keys=[r,n,o]}function It(t){const e=2|t.keys[2];return xt(s.imul(e,1^e)>>>8)}function xt(t){return 255&t}function Mt(t){return 4294967295&t}const Pt=new f;function Dt(t){return Pt.get(t)}const Ft="Invalid uncompressed size",Bt=j,Rt="deflate-raw",Ut="gzip",Wt=[31,139,8];class _t extends d{constructor(t,{chunkSize:e,CompressionStreamFallback:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:c,zipCrypto:i,computeCrc32:a,level:f,deflate64:w,format:u,compressionMethod:h}=t,p=this;let d,y,m,S=super.readable;const g=u&&Dt(u),v=a&&r&&!w&&!g&&(!o||i)&&!(!c||!s);if(o&&!i||!a||v||(d=new U,S=jt(S,d)),r)if(g)S=Ht(S,Lt(g.CompressionStream,u,{level:f,chunkSize:e,compressionMethod:h}));else if(v)m=new Tt,S=Ht(S,new s(Ut)),S=jt(S,m);else try{S=Ot(S,c,{level:f,chunkSize:e},s,n)}catch(t){let e;try{e=new s(Ut)}catch{throw t}S=Ht(S,e),S=jt(S,new Tt)}o&&(i?S=jt(S,new bt(t)):(y=new ut(t),S=jt(S,y))),Et(p,S,()=>{o&&!i||!a||(p.crc32=v?m.crc32:new l(d.value.buffer).getUint32(0))})}}class Tt 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=W(n,t));const c=o-8,i=s.min(c,n.length);r.enqueue(W(n.subarray(0,i),t.subarray(0,c-i))),n=W(n.subarray(i),t.subarray(c-i))},flush(){const e=_(n);t.crc32=e.getUint32(0,!0),t.uncompressedSize=e.getUint32(4,!0)}}),t=this}}class Vt extends d{constructor(t,{chunkSize:e,DecompressionStreamFallback:n,DecompressionStream:s}){super({});const{zipCrypto:c,encrypted:i,checkCrc32:a,crc32:f,compressed:u,useCompressionStream:h,deflate64:p,format:m,compressionMethod:S,rawBitFlag:g,outputSize:b}=t;let k,z,C=super.readable;if(i&&(c?C=jt(C,new vt(t)):(z=new wt(t),C=jt(C,z))),u){const t=m&&Dt(m);if(t)C=Ht(C,Lt(t.DecompressionStream,m,{chunkSize:e,compressionMethod:S,rawBitFlag:g,uncompressedSize:b}));else try{C=Ot(C,h,{chunkSize:e,deflate64:p},s,n)}catch(t){if(p||b===v)throw t;let e;try{e=new s(Ut)}catch{throw t}C=((t,e,n)=>{const s=new R;let c,i,a,f=0,l=!1;const u=new w((t,e)=>{i=t,a=e});u.catch(()=>{}),n||i();const h=new d({start(t){const e=new o(10);e.set(Wt),t.enqueue(e)},transform(t,e){e.enqueue(t)},async flush(t){l=!0,y();try{await u}finally{m()}const e=new o(8),r=_(e);r.setUint32(0,s.get(),!0),r.setUint32(4,n,!0),t.enqueue(e)},cancel(t){a(t)}}),p=new d({transform(t,e){s.append(t),f+=t.length,n>f?l&&y():i(),e.enqueue(t)},cancel(t){a(t)}});return t=jt(t,h),jt(t=Ht(t,e),p);function y(){m(),c=setTimeout(()=>a(new r(Ft)),5e3)}function m(){clearTimeout(c)}})(C,e,b)}C=(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)})})(C)}a&&(k=new U,C=jt(C,k)),Et(this,C,()=>{if(a){const t=new l(k.value.buffer);if(f!=t.getUint32(0,!1))throw new r(Bt)}})}}const Kt=new f;function Et(t,n,s){n=jt(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Lt(t,e,n){if(!t)throw new r("Compression method not supported");return new t(e,n)}function Ot(t,e,n,s,r){const o=e&&s?s:r||s,c=n.deflate64?"deflate64-raw":Rt;let i;try{i=new o(c,n)}catch(t){if(!e||!r||o==r)throw t;i=new r(c,n)}return Ht(t,i)}function jt(t,e){return(t=>{if(t instanceof y)return t;const e=t.getReader();return new y({async pull(t){const{value:n,done:s}=await e.read();s?t.close():t.enqueue(n)},cancel:t=>e.cancel(t)})})(t).pipeThrough(e)}function Ht(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 Nt="data",qt="close",Gt="deflate";class Jt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let c;o.startsWith(Gt)?c=_t:o.startsWith("inflate")&&(c=Vt),s.outputSize=0;let i=0;const a=new c(t,n),f=super.readable,l=new d({transform(t,e){t&&t.length&&(i+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:i})}}),w=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(Ft)},flush(){const{crc32:t}=a;e.assign(s,{crc32:t,inputSize:i})}});e.defineProperty(s,"readable",{get:()=>f.pipeThrough(l).pipeThrough(a).pipeThrough(w)})}}class Qt 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 Xt=2;try{typeof navigator!=b&&navigator.hardwareConcurrency&&(Xt=navigator.hardwareConcurrency)}catch{}const Yt=new f,Zt=new f;let $t,te,ee,ne,se,re,oe=0;async function ce(t){let e,o;try{const{options:c,config:i}=t;if(c.format)try{await(async(t,e)=>{!Pt.has(t)&&e&&((t,e)=>{const{CompressionStream:n,DecompressionStream:s}=e;if(typeof n!=k&&typeof s!=k)throw new r("Invalid codec module");Pt.set(t,{CompressionStream:n,DecompressionStream:s})})(t,await(import(e)))})(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(!((t,e)=>{if(!t)return!1;let n=Kt.get(t);n||(n=new f,Kt.set(t,n));let s=n.get(e);if(s===v){try{new t(e),s=!0}catch{s=!1}n.set(e,s)}return s})(c.codecType.startsWith(Gt)?i.CompressionStream:i.DecompressionStream,Rt))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},l=t.readable||new y({async pull(t){const e=new w(t=>Yt.set(oe,t));ie({type:"pull",messageId:oe}),oe=(oe+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 w(t=>e=t);Zt.set(oe,e),ie({type:Nt,value:t,messageId:oe}),oe=(oe+1)%n.MAX_SAFE_INTEGER,await s}},a),e=new Jt(c,i),$t=new AbortController;const{signal:u}=$t;await l.pipeThrough(e).pipeThrough(new Qt((t=>s.max(t.chunkSize,64))(i))).pipeTo(o,{signal:u,preventClose:!0,preventAbort:!0}),await o.getWriter().close();const{crc32:h,inputSize:p,outputSize:d}=e;ie({type:qt,result:{crc32:h,inputSize:p,outputSize:d}})}catch(t){if(t.outputSize=e?e.outputSize:0,o&&!o.locked)try{await o.getWriter().close()}catch{}ae(t)}}function ie(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 ae(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:c,cause:i,codecImportFailed:a}=t,f={message:e,stack:n,code:s,name:o,outputSize:c};i&&(f.cause={name:i.name,message:i.message}),a&&(f.codecImportFailed=!0),p({error:f})}function fe(t,e,n={}){if(!te){const t=new r("WASM module not loaded");throw t.cause=re,t}const c="number"==typeof n.level?n.level:-1,i="number"==typeof n.outBuffer?n.outBuffer:65536,a="number"==typeof n.inBufferSize?n.inBufferSize:65536;return new d({start(){try{let n;if(this.ft=ee(i),this.in=ee(a),this.inBufferSize=a,!this.ft||!this.in)throw new r("allocation failed");if(this.lt=new o(i),t?(this.wt=te.deflate_process,this.ut=te.deflate_last_consumed,this.ht=te.deflate_end,this.yt=te.deflate_new(),n="gzip"===e?te.deflate_init_gzip(this.yt,c):"deflate-raw"===e?te.deflate_init_raw(this.yt,c):te.deflate_init(this.yt,c)):"deflate64-raw"===e?(this.wt=te.inflate9_process,this.ut=te.inflate9_last_consumed,this.ht=te.inflate9_end,this.yt=te.inflate9_new(),n=te.inflate9_init_raw(this.yt)):(this.wt=te.inflate_process,this.ut=te.inflate_last_consumed,this.ht=te.inflate_end,this.yt=te.inflate_new(),n="deflate-raw"===e?te.inflate_init_raw(this.yt):"gzip"===e?te.inflate_init_gzip(this.yt):te.inflate_init(this.yt)),0!==n)throw new r("init failed:"+n)}catch(t){throw f(this),t}},transform(e,n){try{const c=e,a=new o(se.buffer),f=this.wt,l=this.ut,w=this.ft,u=this.lt;let h=0;for(;h<c.length;){const e=s.min(c.length-h,32768);if((!this.in||this.inBufferSize<e)&&(this.in&&ne&&(ne(this.in),this.in=0),this.in=ee(e),this.inBufferSize=e,!this.in))throw new r("allocation failed");a.set(c.subarray(h,h+e),this.in);const o=f(this.yt,this.in,e,w,i,0),p=16777215&o;if(p&&(u.set(a.subarray(w,w+p),0),n.enqueue(u.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=l(this.yt);if(0===d)break;h+=d}}catch(t){f(this),n.error(t)}},flush(e){try{const n=new o(se.buffer),s=this.wt,c=this.ft,a=this.lt;for(;;){const o=s(this.yt,0,0,c,i,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(c,c+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.yt&&t.ht&&(e=t.ht(t.yt)),t.yt=0,t.in&&ne&&ne(t.in),t.in=0,t.ft&&ne&&ne(t.ft),t.ft=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&ce(t),e==Nt){const t=Yt.get(n);Yt.delete(n),t({value:s||new o,done:r})}if("ack"==e){const t=Zt.get(n);Zt.delete(n),t()}e==qt&&$t.abort()}catch(t){ae(t)}}),p({type:"ready"});class le{constructor(t="deflate",e){return fe(!0,t,e)}}class we{constructor(t="deflate",e){return fe(!1,t,e)}}le.St=!0,we.St=!0;let ue=!1;((t={})=>{const{init:e}=t,n=t.CompressionStreamFallback||t.CompressionStreamZlib,s=t.DecompressionStreamFallback||t.DecompressionStreamZlib;self.initModule=async t=>{e&&await e(t),n&&(t.CompressionStreamFallback=n),s&&(t.DecompressionStreamFallback=s)}})({CompressionStreamFallback:le,DecompressionStreamFallback:we,init:t=>(async(t,{baseURI:e})=>{if(!ue)try{await(async(t,e)=>{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(te=t,({malloc:ee,free:ne,memory:se}=te),"function"!=typeof ee||"function"!=typeof ne||!se)throw te=ee=ne=se=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports)})(t,e),ue=!0}catch(t){throw(t=>{re=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,"+(t=>{let n="";const s=t.length;let r=0;for(;s>r+2;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)}});
|
|
249
251
|
|
|
250
252
|
/*
|
|
251
|
-
Copyright (c)
|
|
253
|
+
Copyright (c) 2026 Gildas Lormeau. All rights reserved.
|
|
252
254
|
|
|
253
255
|
Redistribution and use in source and binary forms, with or without
|
|
254
256
|
modification, are permitted provided that the following conditions are met:
|
|
@@ -276,72 +278,19 @@
|
|
|
276
278
|
*/
|
|
277
279
|
|
|
278
280
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const RESERVED_COMPRESSION_METHODS = [
|
|
285
|
-
COMPRESSION_METHOD_STORE,
|
|
286
|
-
COMPRESSION_METHOD_DEFLATE,
|
|
287
|
-
COMPRESSION_METHOD_DEFLATE_64,
|
|
288
|
-
COMPRESSION_METHOD_AES
|
|
289
|
-
];
|
|
290
|
-
|
|
291
|
-
const registeredCodecs = new Map();
|
|
292
|
-
const codecStreams = new Map();
|
|
293
|
-
|
|
294
|
-
function registerCodec(codec = {}) {
|
|
295
|
-
const { compressionMethod, format, codecURI, CompressionStream, DecompressionStream, versionNeeded } = codec;
|
|
296
|
-
if (!Number.isInteger(compressionMethod) || compressionMethod < 0 || compressionMethod > MAX_16_BITS ||
|
|
297
|
-
typeof format != STRING_TYPE || !format.length) {
|
|
298
|
-
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
299
|
-
}
|
|
300
|
-
if (RESERVED_COMPRESSION_METHODS.includes(compressionMethod)) {
|
|
301
|
-
throw new Error(ERR_RESERVED_COMPRESSION_METHOD);
|
|
302
|
-
}
|
|
303
|
-
const hasStreams = typeof CompressionStream == FUNCTION_TYPE || typeof DecompressionStream == FUNCTION_TYPE;
|
|
304
|
-
if (!hasStreams && (typeof codecURI != STRING_TYPE || !codecURI.length)) {
|
|
305
|
-
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
306
|
-
}
|
|
307
|
-
registeredCodecs.set(compressionMethod, { compressionMethod, format, codecURI, versionNeeded });
|
|
308
|
-
if (hasStreams) {
|
|
309
|
-
setCodecStreams(format, { CompressionStream, DecompressionStream });
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function unregisterCodec(compressionMethod) {
|
|
314
|
-
const codec = registeredCodecs.get(compressionMethod);
|
|
315
|
-
if (codec) {
|
|
316
|
-
registeredCodecs.delete(compressionMethod);
|
|
317
|
-
let formatUsed;
|
|
318
|
-
registeredCodecs.forEach(otherCodec => formatUsed = formatUsed || otherCodec.format == codec.format);
|
|
319
|
-
if (!formatUsed) {
|
|
320
|
-
codecStreams.delete(codec.format);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function getRegisteredCodec(compressionMethod) {
|
|
326
|
-
return registeredCodecs.get(compressionMethod);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function getCodecStreams(format) {
|
|
330
|
-
return codecStreams.get(format);
|
|
281
|
+
function concat(first, second) {
|
|
282
|
+
const result = new Uint8Array(first.length + second.length);
|
|
283
|
+
result.set(first);
|
|
284
|
+
result.set(second, first.length);
|
|
285
|
+
return result;
|
|
331
286
|
}
|
|
332
287
|
|
|
333
|
-
function
|
|
334
|
-
|
|
335
|
-
if (typeof CompressionStream != FUNCTION_TYPE && typeof DecompressionStream != FUNCTION_TYPE) {
|
|
336
|
-
throw new Error(ERR_INVALID_CODEC_MODULE);
|
|
337
|
-
}
|
|
338
|
-
codecStreams.set(format, { CompressionStream, DecompressionStream });
|
|
288
|
+
function toExactUint8Array(array) {
|
|
289
|
+
return array.byteOffset || array.byteLength != array.buffer.byteLength ? new Uint8Array(array) : array;
|
|
339
290
|
}
|
|
340
291
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
setCodecStreams(format, await import(/* webpackIgnore: true */ /* @vite-ignore */ codecURI));
|
|
344
|
-
}
|
|
292
|
+
function getDataView(array) {
|
|
293
|
+
return new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
345
294
|
}
|
|
346
295
|
|
|
347
296
|
/*
|
|
@@ -526,50 +475,6 @@
|
|
|
526
475
|
}
|
|
527
476
|
}
|
|
528
477
|
|
|
529
|
-
/*
|
|
530
|
-
Copyright (c) 2026 Gildas Lormeau. All rights reserved.
|
|
531
|
-
|
|
532
|
-
Redistribution and use in source and binary forms, with or without
|
|
533
|
-
modification, are permitted provided that the following conditions are met:
|
|
534
|
-
|
|
535
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
536
|
-
this list of conditions and the following disclaimer.
|
|
537
|
-
|
|
538
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
539
|
-
notice, this list of conditions and the following disclaimer in
|
|
540
|
-
the documentation and/or other materials provided with the distribution.
|
|
541
|
-
|
|
542
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
543
|
-
derived from this software without specific prior written permission.
|
|
544
|
-
|
|
545
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
546
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
547
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
548
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
549
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
550
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
551
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
552
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
553
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
554
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
555
|
-
*/
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
function concat(first, second) {
|
|
559
|
-
const result = new Uint8Array(first.length + second.length);
|
|
560
|
-
result.set(first);
|
|
561
|
-
result.set(second, first.length);
|
|
562
|
-
return result;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function toExactUint8Array(array) {
|
|
566
|
-
return array.byteOffset || array.byteLength != array.buffer.byteLength ? new Uint8Array(array) : array;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function getDataView(array) {
|
|
570
|
-
return new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
478
|
// Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl
|
|
574
479
|
|
|
575
480
|
// deno-lint-ignore-file no-this-alias
|
|
@@ -1939,6 +1844,102 @@
|
|
|
1939
1844
|
});
|
|
1940
1845
|
}
|
|
1941
1846
|
|
|
1847
|
+
/*
|
|
1848
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
1849
|
+
|
|
1850
|
+
Redistribution and use in source and binary forms, with or without
|
|
1851
|
+
modification, are permitted provided that the following conditions are met:
|
|
1852
|
+
|
|
1853
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1854
|
+
this list of conditions and the following disclaimer.
|
|
1855
|
+
|
|
1856
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1857
|
+
notice, this list of conditions and the following disclaimer in
|
|
1858
|
+
the documentation and/or other materials provided with the distribution.
|
|
1859
|
+
|
|
1860
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1861
|
+
derived from this software without specific prior written permission.
|
|
1862
|
+
|
|
1863
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1864
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1865
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1866
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1867
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1868
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1869
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1870
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1871
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1872
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1873
|
+
*/
|
|
1874
|
+
|
|
1875
|
+
|
|
1876
|
+
const ERR_INVALID_CODEC_DEFINITION = "Invalid codec definition";
|
|
1877
|
+
const ERR_RESERVED_COMPRESSION_METHOD = "Reserved compression method";
|
|
1878
|
+
const ERR_INVALID_CODEC_MODULE = "Invalid codec module";
|
|
1879
|
+
|
|
1880
|
+
const RESERVED_COMPRESSION_METHODS = [
|
|
1881
|
+
COMPRESSION_METHOD_STORE,
|
|
1882
|
+
COMPRESSION_METHOD_DEFLATE,
|
|
1883
|
+
COMPRESSION_METHOD_DEFLATE_64,
|
|
1884
|
+
COMPRESSION_METHOD_AES
|
|
1885
|
+
];
|
|
1886
|
+
|
|
1887
|
+
const registeredCodecs = new Map();
|
|
1888
|
+
const codecStreams = new Map();
|
|
1889
|
+
|
|
1890
|
+
function registerCodec(codec = {}) {
|
|
1891
|
+
const { compressionMethod, format, codecURI, CompressionStream, DecompressionStream, versionNeeded } = codec;
|
|
1892
|
+
if (!Number.isInteger(compressionMethod) || compressionMethod < 0 || compressionMethod > MAX_16_BITS ||
|
|
1893
|
+
typeof format != STRING_TYPE || !format.length) {
|
|
1894
|
+
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
1895
|
+
}
|
|
1896
|
+
if (RESERVED_COMPRESSION_METHODS.includes(compressionMethod)) {
|
|
1897
|
+
throw new Error(ERR_RESERVED_COMPRESSION_METHOD);
|
|
1898
|
+
}
|
|
1899
|
+
const hasStreams = typeof CompressionStream == FUNCTION_TYPE || typeof DecompressionStream == FUNCTION_TYPE;
|
|
1900
|
+
if (!hasStreams && (typeof codecURI != STRING_TYPE || !codecURI.length)) {
|
|
1901
|
+
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
1902
|
+
}
|
|
1903
|
+
registeredCodecs.set(compressionMethod, { compressionMethod, format, codecURI, versionNeeded });
|
|
1904
|
+
if (hasStreams) {
|
|
1905
|
+
setCodecStreams(format, { CompressionStream, DecompressionStream });
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
function unregisterCodec(compressionMethod) {
|
|
1910
|
+
const codec = registeredCodecs.get(compressionMethod);
|
|
1911
|
+
if (codec) {
|
|
1912
|
+
registeredCodecs.delete(compressionMethod);
|
|
1913
|
+
let formatUsed;
|
|
1914
|
+
registeredCodecs.forEach(otherCodec => formatUsed = formatUsed || otherCodec.format == codec.format);
|
|
1915
|
+
if (!formatUsed) {
|
|
1916
|
+
codecStreams.delete(codec.format);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
function getRegisteredCodec(compressionMethod) {
|
|
1922
|
+
return registeredCodecs.get(compressionMethod);
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
function getCodecStreams(format) {
|
|
1926
|
+
return codecStreams.get(format);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
function setCodecStreams(format, streams) {
|
|
1930
|
+
const { CompressionStream, DecompressionStream } = streams;
|
|
1931
|
+
if (typeof CompressionStream != FUNCTION_TYPE && typeof DecompressionStream != FUNCTION_TYPE) {
|
|
1932
|
+
throw new Error(ERR_INVALID_CODEC_MODULE);
|
|
1933
|
+
}
|
|
1934
|
+
codecStreams.set(format, { CompressionStream, DecompressionStream });
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
async function ensureCodecStreams(format, codecURI) {
|
|
1938
|
+
if (!codecStreams.has(format) && codecURI) {
|
|
1939
|
+
setCodecStreams(format, await import(/* webpackIgnore: true */ /* @vite-ignore */ codecURI));
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1942
1943
|
/*
|
|
1943
1944
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
1944
1945
|
|
|
@@ -2492,8 +2493,8 @@
|
|
|
2492
2493
|
1. Redistributions of source code must retain the above copyright notice,
|
|
2493
2494
|
this list of conditions and the following disclaimer.
|
|
2494
2495
|
|
|
2495
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
2496
|
-
notice, this list of conditions and the following disclaimer in
|
|
2496
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2497
|
+
notice, this list of conditions and the following disclaimer in
|
|
2497
2498
|
the documentation and/or other materials provided with the distribution.
|
|
2498
2499
|
|
|
2499
2500
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -2512,24 +2513,19 @@
|
|
|
2512
2513
|
*/
|
|
2513
2514
|
|
|
2514
2515
|
|
|
2515
|
-
const MODULE_WORKER_OPTIONS = { type: "module" };
|
|
2516
|
-
const ERROR_EVENT_TYPE = "error";
|
|
2517
|
-
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2518
2516
|
const ERR_WORKER_STARTUP_TIMEOUT = "Worker startup timeout";
|
|
2519
2517
|
|
|
2520
|
-
let webWorkerSupported,
|
|
2521
|
-
let transferStreamsSupported = true;
|
|
2522
|
-
try {
|
|
2523
|
-
transferStreamsSupported = typeof structuredClone == FUNCTION_TYPE && structuredClone(new DOMException("", "AbortError")).code !== UNDEFINED_VALUE;
|
|
2524
|
-
} catch {
|
|
2525
|
-
// ignored
|
|
2526
|
-
}
|
|
2518
|
+
let webWorkerSupported, createWorkerFailed, webWorkerBackend;
|
|
2527
2519
|
let initModule$1 = () => { };
|
|
2528
2520
|
|
|
2529
2521
|
function configureWorker({ initModule: initModuleFunction }) {
|
|
2530
2522
|
initModule$1 = initModuleFunction;
|
|
2531
2523
|
}
|
|
2532
2524
|
|
|
2525
|
+
function setWebWorkerBackend(backend) {
|
|
2526
|
+
webWorkerBackend = backend;
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2533
2529
|
async function supportsDeflate(config) {
|
|
2534
2530
|
const { CompressionStream: NativeStream, CompressionStreamFallback: FallbackStream } = config;
|
|
2535
2531
|
if (FallbackStream && !FallbackStream.requiresModule) {
|
|
@@ -2554,6 +2550,14 @@
|
|
|
2554
2550
|
createWorkerFailed = false;
|
|
2555
2551
|
}
|
|
2556
2552
|
|
|
2553
|
+
function disableWebWorker(workerData) {
|
|
2554
|
+
if (workerData.createWorker) {
|
|
2555
|
+
createWorkerFailed = true;
|
|
2556
|
+
} else {
|
|
2557
|
+
webWorkerSupported = false;
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2557
2561
|
class CodecWorker {
|
|
2558
2562
|
|
|
2559
2563
|
constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI, createWorker }, onTaskFinished) {
|
|
@@ -2606,7 +2610,7 @@
|
|
|
2606
2610
|
// deno-lint-ignore valid-typeof
|
|
2607
2611
|
webWorkerSupported = typeof Worker != UNDEFINED_TYPE;
|
|
2608
2612
|
}
|
|
2609
|
-
return (useWebWorkers && ((webWorkerSupported && workerURI) || createWorker) ?
|
|
2613
|
+
return (useWebWorkers && webWorkerBackend && ((webWorkerSupported && workerURI) || createWorker) ? webWorkerBackend : createWorkerInterface)(workerData, config);
|
|
2610
2614
|
}
|
|
2611
2615
|
}
|
|
2612
2616
|
|
|
@@ -2650,60 +2654,6 @@
|
|
|
2650
2654
|
};
|
|
2651
2655
|
}
|
|
2652
2656
|
|
|
2653
|
-
function createWebWorkerInterface(workerData, config) {
|
|
2654
|
-
const { baseURI, chunkSize, workerStartupTimeout } = config;
|
|
2655
|
-
let { wasmURI } = config;
|
|
2656
|
-
|
|
2657
|
-
if (!workerData.interface) {
|
|
2658
|
-
// deno-lint-ignore valid-typeof
|
|
2659
|
-
if (typeof wasmURI == FUNCTION_TYPE) {
|
|
2660
|
-
wasmURI = wasmURI();
|
|
2661
|
-
}
|
|
2662
|
-
let worker;
|
|
2663
|
-
try {
|
|
2664
|
-
worker = getWebWorker(workerData.workerURI, baseURI, workerData);
|
|
2665
|
-
} catch {
|
|
2666
|
-
if (workerData.createWorker) {
|
|
2667
|
-
createWorkerFailed = true;
|
|
2668
|
-
} else {
|
|
2669
|
-
webWorkerSupported = false;
|
|
2670
|
-
}
|
|
2671
|
-
return createWorkerInterface(workerData, config);
|
|
2672
|
-
}
|
|
2673
|
-
Object.assign(workerData, {
|
|
2674
|
-
worker,
|
|
2675
|
-
workerAlive: false,
|
|
2676
|
-
terminated: false,
|
|
2677
|
-
interface: {
|
|
2678
|
-
run: async () => {
|
|
2679
|
-
try {
|
|
2680
|
-
return await runWebWorker(workerData, { chunkSize, wasmURI, baseURI, workerStartupTimeout });
|
|
2681
|
-
} catch (error) {
|
|
2682
|
-
if (error && error.workerStartupFailed) {
|
|
2683
|
-
if (workerData.createWorker) {
|
|
2684
|
-
createWorkerFailed = true;
|
|
2685
|
-
} else {
|
|
2686
|
-
webWorkerSupported = false;
|
|
2687
|
-
}
|
|
2688
|
-
releaseWorkerStreams(workerData);
|
|
2689
|
-
return runWorker$1(workerData, config);
|
|
2690
|
-
}
|
|
2691
|
-
if (error && error.codecImportFailed) {
|
|
2692
|
-
if (workerData.reader) {
|
|
2693
|
-
releaseWorkerStreams(workerData);
|
|
2694
|
-
return runWorker$1(workerData, config);
|
|
2695
|
-
}
|
|
2696
|
-
workerData.onTaskFinished();
|
|
2697
|
-
}
|
|
2698
|
-
throw error;
|
|
2699
|
-
}
|
|
2700
|
-
}
|
|
2701
|
-
}
|
|
2702
|
-
});
|
|
2703
|
-
}
|
|
2704
|
-
return workerData.interface;
|
|
2705
|
-
}
|
|
2706
|
-
|
|
2707
2657
|
async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
|
|
2708
2658
|
let codecStream;
|
|
2709
2659
|
try {
|
|
@@ -2752,6 +2702,95 @@
|
|
|
2752
2702
|
}
|
|
2753
2703
|
}
|
|
2754
2704
|
|
|
2705
|
+
/*
|
|
2706
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
2707
|
+
|
|
2708
|
+
Redistribution and use in source and binary forms, with or without
|
|
2709
|
+
modification, are permitted provided that the following conditions are met:
|
|
2710
|
+
|
|
2711
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
2712
|
+
this list of conditions and the following disclaimer.
|
|
2713
|
+
|
|
2714
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2715
|
+
notice, this list of conditions and the following disclaimer in
|
|
2716
|
+
the documentation and/or other materials provided with the distribution.
|
|
2717
|
+
|
|
2718
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
2719
|
+
derived from this software without specific prior written permission.
|
|
2720
|
+
|
|
2721
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
2722
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
2723
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
2724
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
2725
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
2726
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
2727
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
2728
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
2729
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
2730
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2731
|
+
*/
|
|
2732
|
+
|
|
2733
|
+
|
|
2734
|
+
const MODULE_WORKER_OPTIONS = { type: "module" };
|
|
2735
|
+
const ERROR_EVENT_TYPE = "error";
|
|
2736
|
+
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2737
|
+
|
|
2738
|
+
let webWorkerSource, webWorkerURI, webWorkerOptions;
|
|
2739
|
+
let transferStreamsSupported = true;
|
|
2740
|
+
try {
|
|
2741
|
+
transferStreamsSupported = typeof structuredClone == FUNCTION_TYPE && structuredClone(new DOMException("", "AbortError")).code !== UNDEFINED_VALUE;
|
|
2742
|
+
} catch {
|
|
2743
|
+
// ignored
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2746
|
+
setWebWorkerBackend(createWebWorkerInterface);
|
|
2747
|
+
|
|
2748
|
+
function createWebWorkerInterface(workerData, config) {
|
|
2749
|
+
const { baseURI, chunkSize, workerStartupTimeout } = config;
|
|
2750
|
+
let { wasmURI } = config;
|
|
2751
|
+
|
|
2752
|
+
if (!workerData.interface) {
|
|
2753
|
+
// deno-lint-ignore valid-typeof
|
|
2754
|
+
if (typeof wasmURI == FUNCTION_TYPE) {
|
|
2755
|
+
wasmURI = wasmURI();
|
|
2756
|
+
}
|
|
2757
|
+
let worker;
|
|
2758
|
+
try {
|
|
2759
|
+
worker = getWebWorker(workerData.workerURI, baseURI, workerData);
|
|
2760
|
+
} catch {
|
|
2761
|
+
disableWebWorker(workerData);
|
|
2762
|
+
return createWorkerInterface(workerData, config);
|
|
2763
|
+
}
|
|
2764
|
+
Object.assign(workerData, {
|
|
2765
|
+
worker,
|
|
2766
|
+
workerAlive: false,
|
|
2767
|
+
terminated: false,
|
|
2768
|
+
interface: {
|
|
2769
|
+
run: async () => {
|
|
2770
|
+
try {
|
|
2771
|
+
return await runWebWorker(workerData, { chunkSize, wasmURI, baseURI, workerStartupTimeout });
|
|
2772
|
+
} catch (error) {
|
|
2773
|
+
if (error && error.workerStartupFailed) {
|
|
2774
|
+
disableWebWorker(workerData);
|
|
2775
|
+
releaseWorkerStreams(workerData);
|
|
2776
|
+
return runWorker$1(workerData, config);
|
|
2777
|
+
}
|
|
2778
|
+
if (error && error.codecImportFailed) {
|
|
2779
|
+
if (workerData.reader) {
|
|
2780
|
+
releaseWorkerStreams(workerData);
|
|
2781
|
+
return runWorker$1(workerData, config);
|
|
2782
|
+
}
|
|
2783
|
+
workerData.onTaskFinished();
|
|
2784
|
+
}
|
|
2785
|
+
throw error;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
return workerData.interface;
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2755
2794
|
async function runWebWorker(workerData, config) {
|
|
2756
2795
|
let resolveResult, rejectResult;
|
|
2757
2796
|
const result = new Promise((resolve, reject) => {
|
|
@@ -3628,7 +3667,7 @@
|
|
|
3628
3667
|
forceRangeRequests,
|
|
3629
3668
|
combineSizeEocd
|
|
3630
3669
|
} = httpReader;
|
|
3631
|
-
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest ==
|
|
3670
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == UNDEFINED_TYPE || preventHeadRequest)) {
|
|
3632
3671
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
|
|
3633
3672
|
const acceptRanges = response.headers.get(HTTP_HEADER_ACCEPT_RANGES);
|
|
3634
3673
|
if (!forceRangeRequests && (!acceptRanges || acceptRanges.toLowerCase() != HTTP_RANGE_UNIT)) {
|
|
@@ -4481,9 +4520,13 @@
|
|
|
4481
4520
|
const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
|
|
4482
4521
|
const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
|
|
4483
4522
|
const OPTION_STRICTNESS = "strictness";
|
|
4523
|
+
const OPTION_FILENAME_VALIDATION = "filenameValidation";
|
|
4524
|
+
const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
|
|
4484
4525
|
const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
|
|
4485
4526
|
const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
|
|
4486
4527
|
const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
|
|
4528
|
+
const TEXT_TYPE_FILENAME = "filename";
|
|
4529
|
+
const TEXT_TYPE_COMMENT = "comment";
|
|
4487
4530
|
const STRICTNESS_STRICT = "strict";
|
|
4488
4531
|
const STRICTNESS_BALANCED = "balanced";
|
|
4489
4532
|
const STRICTNESS_TOLERANT = "tolerant";
|
|
@@ -4530,6 +4573,11 @@
|
|
|
4530
4573
|
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
4531
4574
|
const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
|
|
4532
4575
|
const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
|
|
4576
|
+
const ERR_UNSAFE_FILENAME = "Unsafe filename";
|
|
4577
|
+
const ERR_INVALID_STRICTNESS = "Invalid strictness (must be 'strict', 'balanced' or 'tolerant')";
|
|
4578
|
+
const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
|
|
4579
|
+
const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
|
|
4580
|
+
const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
|
|
4533
4581
|
const CHARSET_UTF8 = "utf-8";
|
|
4534
4582
|
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
|
|
4535
4583
|
const CHARSET_CP437 = "cp437";
|
|
@@ -4551,6 +4599,10 @@
|
|
|
4551
4599
|
bytes: 8
|
|
4552
4600
|
}
|
|
4553
4601
|
};
|
|
4602
|
+
const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
|
|
4603
|
+
const CENTRAL_DIRECTORY_UNREACHABLE = 0;
|
|
4604
|
+
const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
|
|
4605
|
+
const CENTRAL_DIRECTORY_REACHABLE = 2;
|
|
4554
4606
|
|
|
4555
4607
|
class ZipReader {
|
|
4556
4608
|
|
|
@@ -4579,6 +4631,8 @@
|
|
|
4579
4631
|
const checkAmbiguity = strictness == STRICTNESS_STRICT;
|
|
4580
4632
|
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
4581
4633
|
const maxAppendedDataSize = getMaxAppendedDataSize(getOptionValue$1(zipReader, options, OPTION_MAX_APPENDED_DATA_SIZE), strictness);
|
|
4634
|
+
const filenameValidation = getFilenameValidation(getOptionValue$1(zipReader, options, OPTION_FILENAME_VALIDATION), strictness);
|
|
4635
|
+
const normalizeFilename = getOptionValue$1(zipReader, options, OPTION_NORMALIZE_FILENAME);
|
|
4582
4636
|
const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
|
|
4583
4637
|
if (!endOfDirectoryInfo) {
|
|
4584
4638
|
const signatureArray = await readUint8Array(reader, 0, 4);
|
|
@@ -4772,11 +4826,22 @@
|
|
|
4772
4826
|
const decode = getOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
|
|
4773
4827
|
const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
|
|
4774
4828
|
const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
|
|
4775
|
-
let filename = decode(rawFilename, rawFilenameEncoding);
|
|
4829
|
+
let filename = decode(rawFilename, rawFilenameEncoding, TEXT_TYPE_FILENAME);
|
|
4776
4830
|
if (filename === UNDEFINED_VALUE) {
|
|
4777
4831
|
filename = decodeText(rawFilename, rawFilenameEncoding);
|
|
4778
4832
|
}
|
|
4779
|
-
|
|
4833
|
+
if (normalizeFilename) {
|
|
4834
|
+
const normalizedFilename = normalizeFilename(filename);
|
|
4835
|
+
if (normalizedFilename !== UNDEFINED_VALUE) {
|
|
4836
|
+
filename = normalizedFilename;
|
|
4837
|
+
}
|
|
4838
|
+
}
|
|
4839
|
+
if (isUnsafeFilename(filename, filenameValidation)) {
|
|
4840
|
+
const error = new Error(ERR_UNSAFE_FILENAME);
|
|
4841
|
+
error.filename = filename;
|
|
4842
|
+
throw error;
|
|
4843
|
+
}
|
|
4844
|
+
let comment = decode(rawComment, rawCommentEncoding, TEXT_TYPE_COMMENT);
|
|
4780
4845
|
if (comment === UNDEFINED_VALUE) {
|
|
4781
4846
|
comment = decodeText(rawComment, rawCommentEncoding);
|
|
4782
4847
|
}
|
|
@@ -4837,10 +4902,10 @@
|
|
|
4837
4902
|
entry.getData = (writer, options) => fileEntry.getData(writer, entry, zipReader.readRanges, options);
|
|
4838
4903
|
entry.arrayBuffer = async options => {
|
|
4839
4904
|
const writer = new TransformStream();
|
|
4840
|
-
const
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
return
|
|
4905
|
+
const arrayBufferPromise = streamToBlob(writer.readable).then(blob => blob.arrayBuffer());
|
|
4906
|
+
arrayBufferPromise.catch(() => { });
|
|
4907
|
+
await fileEntry.getData(writer, entry, zipReader.readRanges, options);
|
|
4908
|
+
return arrayBufferPromise;
|
|
4844
4909
|
};
|
|
4845
4910
|
offset = endOffset;
|
|
4846
4911
|
const { onprogress } = options;
|
|
@@ -5091,7 +5156,7 @@
|
|
|
5091
5156
|
readRanges
|
|
5092
5157
|
});
|
|
5093
5158
|
}
|
|
5094
|
-
let writable;
|
|
5159
|
+
let writable, abortError;
|
|
5095
5160
|
try {
|
|
5096
5161
|
if (!checkOverlappingEntryOnly) {
|
|
5097
5162
|
if (checkPasswordOnly) {
|
|
@@ -5111,12 +5176,22 @@
|
|
|
5111
5176
|
writer.size += error.outputSize;
|
|
5112
5177
|
}
|
|
5113
5178
|
if (!checkPasswordOnly || error.message != ERR_ABORT_CHECK_PASSWORD) {
|
|
5179
|
+
abortError = error;
|
|
5114
5180
|
throw error;
|
|
5115
5181
|
}
|
|
5116
5182
|
} finally {
|
|
5117
5183
|
const preventClose = getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5118
5184
|
if (!preventClose && writable && !writable.locked) {
|
|
5119
|
-
|
|
5185
|
+
const writableWriter = writable.getWriter();
|
|
5186
|
+
if (abortError) {
|
|
5187
|
+
try {
|
|
5188
|
+
await writableWriter.abort(abortError);
|
|
5189
|
+
} catch {
|
|
5190
|
+
// the error being propagated is more relevant; ignored
|
|
5191
|
+
}
|
|
5192
|
+
} else {
|
|
5193
|
+
await writableWriter.close();
|
|
5194
|
+
}
|
|
5120
5195
|
}
|
|
5121
5196
|
}
|
|
5122
5197
|
return checkPasswordOnly || checkOverlappingEntryOnly ? UNDEFINED_VALUE : writer.getData ? writer.getData() : writable;
|
|
@@ -5496,16 +5571,51 @@
|
|
|
5496
5571
|
return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
|
|
5497
5572
|
}
|
|
5498
5573
|
|
|
5574
|
+
function isStrictnessValue(value) {
|
|
5575
|
+
return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
|
|
5576
|
+
}
|
|
5577
|
+
|
|
5499
5578
|
function getStrictness(strictness, checkAmbiguity) {
|
|
5500
5579
|
if (strictness === UNDEFINED_VALUE) {
|
|
5501
5580
|
return checkAmbiguity ? STRICTNESS_STRICT : STRICTNESS_BALANCED;
|
|
5502
5581
|
}
|
|
5582
|
+
if (!isStrictnessValue(strictness)) {
|
|
5583
|
+
throw new Error(ERR_INVALID_STRICTNESS);
|
|
5584
|
+
}
|
|
5503
5585
|
return strictness;
|
|
5504
5586
|
}
|
|
5505
5587
|
|
|
5588
|
+
function getFilenameValidation(filenameValidation, strictness) {
|
|
5589
|
+
if (filenameValidation === UNDEFINED_VALUE) {
|
|
5590
|
+
return strictness;
|
|
5591
|
+
}
|
|
5592
|
+
if (!isStrictnessValue(filenameValidation)) {
|
|
5593
|
+
throw new Error(ERR_INVALID_FILENAME_VALIDATION);
|
|
5594
|
+
}
|
|
5595
|
+
return filenameValidation;
|
|
5596
|
+
}
|
|
5597
|
+
|
|
5598
|
+
function isUnsafeFilename(filename, filenameValidation) {
|
|
5599
|
+
if (filenameValidation == STRICTNESS_TOLERANT) {
|
|
5600
|
+
return false;
|
|
5601
|
+
}
|
|
5602
|
+
const pathParts = filename.split("/");
|
|
5603
|
+
if (pathParts.length > 1 && pathParts[pathParts.length - 1] === "") {
|
|
5604
|
+
pathParts.pop();
|
|
5605
|
+
}
|
|
5606
|
+
if (pathParts.includes("..") || filename.startsWith("/") || filename.startsWith("\\\\") || DRIVE_LETTER_REGEXP.test(filename)) {
|
|
5607
|
+
return true;
|
|
5608
|
+
}
|
|
5609
|
+
return filenameValidation == STRICTNESS_STRICT && (pathParts.includes(".") || pathParts.includes(""));
|
|
5610
|
+
}
|
|
5611
|
+
|
|
5506
5612
|
function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
|
|
5507
5613
|
if (maxAppendedDataSize !== UNDEFINED_VALUE) {
|
|
5508
|
-
|
|
5614
|
+
const size = toNumber$1(maxAppendedDataSize);
|
|
5615
|
+
if (typeof size != NUMBER_TYPE || Number.isNaN(size) || size < 0) {
|
|
5616
|
+
throw new Error(ERR_INVALID_MAX_APPENDED_DATA_SIZE);
|
|
5617
|
+
}
|
|
5618
|
+
return size;
|
|
5509
5619
|
}
|
|
5510
5620
|
if (strictness == STRICTNESS_STRICT) {
|
|
5511
5621
|
return 0;
|
|
@@ -5516,12 +5626,6 @@
|
|
|
5516
5626
|
return MAX_16_BITS;
|
|
5517
5627
|
}
|
|
5518
5628
|
|
|
5519
|
-
const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
|
|
5520
|
-
|
|
5521
|
-
const CENTRAL_DIRECTORY_UNREACHABLE = 0;
|
|
5522
|
-
const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
|
|
5523
|
-
const CENTRAL_DIRECTORY_REACHABLE = 2;
|
|
5524
|
-
|
|
5525
5629
|
async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDataSize) {
|
|
5526
5630
|
const { size } = reader;
|
|
5527
5631
|
const anchoredLength = Math.min(size, END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS);
|
|
@@ -5657,6 +5761,10 @@
|
|
|
5657
5761
|
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
5658
5762
|
}
|
|
5659
5763
|
|
|
5764
|
+
function toNumber$1(value) {
|
|
5765
|
+
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
5766
|
+
}
|
|
5767
|
+
|
|
5660
5768
|
function getDate(timeRaw) {
|
|
5661
5769
|
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
|
|
5662
5770
|
return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
|
|
@@ -5695,12 +5803,16 @@
|
|
|
5695
5803
|
ERR_INVALID_AUTHENTICATION_CODE: ERR_INVALID_AUTHENTICATION_CODE,
|
|
5696
5804
|
ERR_INVALID_COMPRESSED_DATA: ERR_INVALID_COMPRESSED_DATA,
|
|
5697
5805
|
ERR_INVALID_CRC32: ERR_INVALID_CRC32,
|
|
5806
|
+
ERR_INVALID_FILENAME_VALIDATION: ERR_INVALID_FILENAME_VALIDATION,
|
|
5807
|
+
ERR_INVALID_MAX_APPENDED_DATA_SIZE: ERR_INVALID_MAX_APPENDED_DATA_SIZE,
|
|
5698
5808
|
ERR_INVALID_PASSWORD: ERR_INVALID_PASSWORD,
|
|
5699
5809
|
ERR_INVALID_SIGNATURE: ERR_INVALID_SIGNATURE,
|
|
5810
|
+
ERR_INVALID_STRICTNESS: ERR_INVALID_STRICTNESS,
|
|
5700
5811
|
ERR_INVALID_UNCOMPRESSED_SIZE: ERR_INVALID_UNCOMPRESSED_SIZE,
|
|
5701
5812
|
ERR_LOCAL_FILE_HEADER_NOT_FOUND: ERR_LOCAL_FILE_HEADER_NOT_FOUND,
|
|
5702
5813
|
ERR_OVERLAPPING_ENTRY: ERR_OVERLAPPING_ENTRY,
|
|
5703
5814
|
ERR_SPLIT_ZIP_FILE: ERR_SPLIT_ZIP_FILE,
|
|
5815
|
+
ERR_UNSAFE_FILENAME: ERR_UNSAFE_FILENAME,
|
|
5704
5816
|
ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION$1,
|
|
5705
5817
|
ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
|
|
5706
5818
|
ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
|
|
@@ -5762,6 +5874,8 @@
|
|
|
5762
5874
|
const ERR_INVALID_UNIX_ID_SIZE = "uid/gid must be 0..65535 for unixExtraFieldType 'unix' (use 'infozip' for larger ids)";
|
|
5763
5875
|
const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
|
|
5764
5876
|
const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
|
|
5877
|
+
const ERR_INVALID_LEVEL = "Invalid level (must be integer 0..9)";
|
|
5878
|
+
const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
|
|
5765
5879
|
const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
|
|
5766
5880
|
|
|
5767
5881
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
@@ -5769,6 +5883,7 @@
|
|
|
5769
5883
|
const VENDOR_VERSION_AE_1 = 1;
|
|
5770
5884
|
const INFOZIP_EXTRA_FIELD_TYPE$1 = "infozip";
|
|
5771
5885
|
const UNIX_EXTRA_FIELD_TYPE = "unix";
|
|
5886
|
+
const MAX_LEVEL = 9;
|
|
5772
5887
|
|
|
5773
5888
|
let workers = 0;
|
|
5774
5889
|
const pendingEntries = [];
|
|
@@ -5931,7 +6046,8 @@
|
|
|
5931
6046
|
|
|
5932
6047
|
remove(entry) {
|
|
5933
6048
|
const { filenames, files } = this;
|
|
5934
|
-
|
|
6049
|
+
// deno-lint-ignore valid-typeof
|
|
6050
|
+
if (typeof entry == STRING_TYPE) {
|
|
5935
6051
|
entry = files.get(entry);
|
|
5936
6052
|
}
|
|
5937
6053
|
if (entry && entry.filename !== UNDEFINED_VALUE) {
|
|
@@ -6069,20 +6185,20 @@
|
|
|
6069
6185
|
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
6070
6186
|
let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? 20 : 768);
|
|
6071
6187
|
const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
|
|
6072
|
-
const uid =
|
|
6073
|
-
const gid =
|
|
6074
|
-
let unixMode =
|
|
6188
|
+
const uid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UID);
|
|
6189
|
+
const gid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_GID);
|
|
6190
|
+
let unixMode = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UNIX_MODE);
|
|
6075
6191
|
let unixExtraFieldType = getOptionValue(zipWriter, options, OPTION_UNIX_EXTRA_FIELD_TYPE);
|
|
6076
6192
|
let setuid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETUID);
|
|
6077
6193
|
let setgid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETGID);
|
|
6078
6194
|
let sticky = getOptionValue(zipWriter, options, PROPERTY_NAME_STICKY);
|
|
6079
|
-
if (uid !== UNDEFINED_VALUE && (uid < 0 || uid > MAX_32_BITS)) {
|
|
6195
|
+
if (uid !== UNDEFINED_VALUE && (!Number.isInteger(uid) || uid < 0 || uid > MAX_32_BITS)) {
|
|
6080
6196
|
throw new Error(ERR_INVALID_UID);
|
|
6081
6197
|
}
|
|
6082
|
-
if (gid !== UNDEFINED_VALUE && (gid < 0 || gid > MAX_32_BITS)) {
|
|
6198
|
+
if (gid !== UNDEFINED_VALUE && (!Number.isInteger(gid) || gid < 0 || gid > MAX_32_BITS)) {
|
|
6083
6199
|
throw new Error(ERR_INVALID_GID);
|
|
6084
6200
|
}
|
|
6085
|
-
if (unixMode !== UNDEFINED_VALUE && (unixMode < 0 || unixMode > MAX_16_BITS)) {
|
|
6201
|
+
if (unixMode !== UNDEFINED_VALUE && (!Number.isInteger(unixMode) || unixMode < 0 || unixMode > MAX_16_BITS)) {
|
|
6086
6202
|
throw new Error(ERR_INVALID_UNIX_MODE);
|
|
6087
6203
|
}
|
|
6088
6204
|
if (unixExtraFieldType !== UNDEFINED_VALUE && unixExtraFieldType !== INFOZIP_EXTRA_FIELD_TYPE$1 && unixExtraFieldType !== UNIX_EXTRA_FIELD_TYPE) {
|
|
@@ -6194,7 +6310,7 @@
|
|
|
6194
6310
|
|
|
6195
6311
|
function resolveMetadata(zipWriter, name, options) {
|
|
6196
6312
|
const encode = getOptionValue(zipWriter, options, OPTION_ENCODE_TEXT, encodeText);
|
|
6197
|
-
let rawFilename = encode(name);
|
|
6313
|
+
let rawFilename = encode(name, TEXT_TYPE_FILENAME);
|
|
6198
6314
|
if (rawFilename === UNDEFINED_VALUE) {
|
|
6199
6315
|
rawFilename = encodeText(name);
|
|
6200
6316
|
}
|
|
@@ -6202,7 +6318,7 @@
|
|
|
6202
6318
|
throw new Error(ERR_INVALID_ENTRY_NAME);
|
|
6203
6319
|
}
|
|
6204
6320
|
const comment = options[PROPERTY_NAME_COMMENT] || "";
|
|
6205
|
-
let rawComment = encode(comment);
|
|
6321
|
+
let rawComment = encode(comment, TEXT_TYPE_COMMENT);
|
|
6206
6322
|
if (rawComment === UNDEFINED_VALUE) {
|
|
6207
6323
|
rawComment = encodeText(comment);
|
|
6208
6324
|
}
|
|
@@ -6222,8 +6338,11 @@
|
|
|
6222
6338
|
if (!passThrough) {
|
|
6223
6339
|
password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
6224
6340
|
rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
6341
|
+
if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
|
|
6342
|
+
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
6343
|
+
}
|
|
6225
6344
|
}
|
|
6226
|
-
const encryptionStrength =
|
|
6345
|
+
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
6227
6346
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
6228
6347
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
6229
6348
|
const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
|
|
@@ -6241,7 +6360,10 @@
|
|
|
6241
6360
|
compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE && !registeredCodec) {
|
|
6242
6361
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
6243
6362
|
}
|
|
6244
|
-
let level =
|
|
6363
|
+
let level = getNumberOptionValue(zipWriter, options, OPTION_LEVEL);
|
|
6364
|
+
if (level !== UNDEFINED_VALUE && (!Number.isInteger(level) || level < 0 || level > MAX_LEVEL)) {
|
|
6365
|
+
throw new Error(ERR_INVALID_LEVEL);
|
|
6366
|
+
}
|
|
6245
6367
|
if (zipWriter.options[OPTION_USDZ]) {
|
|
6246
6368
|
if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
|
|
6247
6369
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
|
|
@@ -6262,7 +6384,7 @@
|
|
|
6262
6384
|
useCompressionStream = false;
|
|
6263
6385
|
}
|
|
6264
6386
|
const zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
6265
|
-
if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
|
|
6387
|
+
if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(Number.isInteger(encryptionStrength) && encryptionStrength >= 1 && encryptionStrength <= 3)) {
|
|
6266
6388
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
6267
6389
|
}
|
|
6268
6390
|
const rawExtraField = serializeExtraField(options[PROPERTY_NAME_EXTRA_FIELD]);
|
|
@@ -7456,6 +7578,14 @@
|
|
|
7456
7578
|
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7457
7579
|
}
|
|
7458
7580
|
|
|
7581
|
+
function getNumberOptionValue(zipWriter, options, name, defaultValue) {
|
|
7582
|
+
return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
|
|
7583
|
+
}
|
|
7584
|
+
|
|
7585
|
+
function toNumber(value) {
|
|
7586
|
+
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
7587
|
+
}
|
|
7588
|
+
|
|
7459
7589
|
function getMaximumCompressedSize(uncompressedSize) {
|
|
7460
7590
|
return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
|
|
7461
7591
|
}
|
|
@@ -8473,6 +8603,7 @@
|
|
|
8473
8603
|
|
|
8474
8604
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
8475
8605
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
8606
|
+
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
8476
8607
|
const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
|
|
8477
8608
|
const INTERPRETED_EXTRA_FIELD_TYPES = new Set([
|
|
8478
8609
|
EXTRAFIELD_TYPE_ZIP64,
|
|
@@ -8581,8 +8712,9 @@
|
|
|
8581
8712
|
const uncompressedSize = zipEntry.data ? zipEntry.data.uncompressedSize : reader.size;
|
|
8582
8713
|
await Promise.all([initStream(reader), initStream(writer, uncompressedSize)]);
|
|
8583
8714
|
const { readable } = reader;
|
|
8715
|
+
const { signal } = options;
|
|
8584
8716
|
zipEntry.uncompressedSize = reader.size;
|
|
8585
|
-
await toCompatibleReadable(readable).pipeTo(toCompatibleWritable(writer.writable));
|
|
8717
|
+
await toCompatibleReadable(readable).pipeTo(toCompatibleWritable(writer.writable), { signal });
|
|
8586
8718
|
return writer.getData ? writer.getData() : writer.writable;
|
|
8587
8719
|
}
|
|
8588
8720
|
}
|
|
@@ -8849,7 +8981,7 @@
|
|
|
8849
8981
|
for (const entry of entries) {
|
|
8850
8982
|
let parent = this;
|
|
8851
8983
|
try {
|
|
8852
|
-
const path = entry.filename.split("/");
|
|
8984
|
+
const path = entry.filename.split("/").filter(pathPart => pathPart != "" && pathPart != ".");
|
|
8853
8985
|
const name = path.pop();
|
|
8854
8986
|
path.forEach(pathPart => {
|
|
8855
8987
|
const previousParent = parent;
|
|
@@ -9224,6 +9356,39 @@
|
|
|
9224
9356
|
}
|
|
9225
9357
|
}
|
|
9226
9358
|
|
|
9359
|
+
function forwardAbort(signal, abortController) {
|
|
9360
|
+
if (!signal) {
|
|
9361
|
+
return () => { };
|
|
9362
|
+
}
|
|
9363
|
+
if (signal.aborted) {
|
|
9364
|
+
abortController.abort(signal.reason);
|
|
9365
|
+
return () => { };
|
|
9366
|
+
}
|
|
9367
|
+
const abort = () => abortController.abort(signal.reason);
|
|
9368
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
9369
|
+
return () => signal.removeEventListener("abort", abort);
|
|
9370
|
+
}
|
|
9371
|
+
|
|
9372
|
+
function isExportAborted(error) {
|
|
9373
|
+
return Boolean(error) && error.message == ERR_ABORT_EXPORT;
|
|
9374
|
+
}
|
|
9375
|
+
|
|
9376
|
+
function aggregateEntryErrors(errors) {
|
|
9377
|
+
const [error] = errors;
|
|
9378
|
+
const otherErrors = errors
|
|
9379
|
+
.slice(1)
|
|
9380
|
+
.flatMap(otherError => [otherError, ...(otherError && otherError.entryErrors || [])])
|
|
9381
|
+
.filter(otherError => otherError !== error);
|
|
9382
|
+
if (otherErrors.length) {
|
|
9383
|
+
try {
|
|
9384
|
+
error.entryErrors = [...(error.entryErrors || []), ...otherErrors];
|
|
9385
|
+
} catch {
|
|
9386
|
+
// ignored
|
|
9387
|
+
}
|
|
9388
|
+
}
|
|
9389
|
+
return error;
|
|
9390
|
+
}
|
|
9391
|
+
|
|
9227
9392
|
function getUserExtraField(extraField) {
|
|
9228
9393
|
if (extraField) {
|
|
9229
9394
|
const userExtraField = new Map();
|
|
@@ -9344,8 +9509,9 @@
|
|
|
9344
9509
|
function addFileSystemHandle(zipEntry, handle, options) {
|
|
9345
9510
|
return addFile(zipEntry, handle, []);
|
|
9346
9511
|
|
|
9347
|
-
async function addFile(parentEntry, handle, addedEntries) {
|
|
9512
|
+
async function addFile(parentEntry, handle, addedEntries, parentName = "") {
|
|
9348
9513
|
if (handle) {
|
|
9514
|
+
const entryName = parentName ? parentName + "/" + handle.name : handle.name;
|
|
9349
9515
|
try {
|
|
9350
9516
|
if (handle.isFile || handle.isDirectory) {
|
|
9351
9517
|
handle = await transformToFileSystemhandle(handle);
|
|
@@ -9367,12 +9533,18 @@
|
|
|
9367
9533
|
const directoryEntry = parentEntry.addDirectory(handle.name);
|
|
9368
9534
|
addedEntries.push(directoryEntry);
|
|
9369
9535
|
for await (const childHandle of handle.values()) {
|
|
9370
|
-
await addFile(directoryEntry, childHandle, addedEntries);
|
|
9536
|
+
await addFile(directoryEntry, childHandle, addedEntries, entryName);
|
|
9371
9537
|
}
|
|
9372
9538
|
}
|
|
9373
9539
|
} catch (error) {
|
|
9374
|
-
|
|
9375
|
-
|
|
9540
|
+
try {
|
|
9541
|
+
if (error.entryName === UNDEFINED_VALUE) {
|
|
9542
|
+
error.entryName = entryName;
|
|
9543
|
+
}
|
|
9544
|
+
} catch {
|
|
9545
|
+
// ignored
|
|
9546
|
+
}
|
|
9547
|
+
throw error;
|
|
9376
9548
|
}
|
|
9377
9549
|
}
|
|
9378
9550
|
return addedEntries;
|
|
@@ -9382,15 +9554,32 @@
|
|
|
9382
9554
|
async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
|
|
9383
9555
|
const totalSize = getTotalSize([zipEntry], "uncompressedSize");
|
|
9384
9556
|
const writtenSizes = new Map();
|
|
9385
|
-
|
|
9557
|
+
const abortController = new AbortController();
|
|
9558
|
+
const { signal } = abortController;
|
|
9559
|
+
const releaseSignal = forwardAbort(options.signal, abortController);
|
|
9560
|
+
const exportedEntryNames = [];
|
|
9561
|
+
try {
|
|
9562
|
+
await exportChildren(zipEntry, directoryHandle);
|
|
9563
|
+
} catch (error) {
|
|
9564
|
+
try {
|
|
9565
|
+
error.exportedEntryNames = exportedEntryNames;
|
|
9566
|
+
} catch {
|
|
9567
|
+
// ignored
|
|
9568
|
+
}
|
|
9569
|
+
throw error;
|
|
9570
|
+
} finally {
|
|
9571
|
+
releaseSignal();
|
|
9572
|
+
}
|
|
9386
9573
|
return directoryHandle;
|
|
9387
9574
|
|
|
9388
9575
|
async function exportChildren(entry, parentHandle) {
|
|
9389
9576
|
if (options.concurrent) {
|
|
9390
9577
|
const results = await Promise.allSettled(entry.children.map(child => exportChild(child, parentHandle)));
|
|
9391
|
-
const
|
|
9392
|
-
if (
|
|
9393
|
-
|
|
9578
|
+
const rejectedResults = results.filter(result => result.status == "rejected");
|
|
9579
|
+
if (rejectedResults.length) {
|
|
9580
|
+
const failedResults = rejectedResults.filter(result => !isExportAborted(result.reason));
|
|
9581
|
+
const reportedResults = failedResults.length ? failedResults : rejectedResults;
|
|
9582
|
+
throw aggregateEntryErrors(reportedResults.map(result => result.reason));
|
|
9394
9583
|
}
|
|
9395
9584
|
} else {
|
|
9396
9585
|
for (const child of entry.children) {
|
|
@@ -9400,6 +9589,12 @@
|
|
|
9400
9589
|
}
|
|
9401
9590
|
|
|
9402
9591
|
async function exportChild(child, parentHandle) {
|
|
9592
|
+
if (signal.aborted) {
|
|
9593
|
+
if (isExportAborted(signal.reason)) {
|
|
9594
|
+
return;
|
|
9595
|
+
}
|
|
9596
|
+
throw signal.reason;
|
|
9597
|
+
}
|
|
9403
9598
|
try {
|
|
9404
9599
|
if (child.directory) {
|
|
9405
9600
|
const childDirectoryHandle = await parentHandle.getDirectoryHandle(child.name, { create: true });
|
|
@@ -9408,6 +9603,7 @@
|
|
|
9408
9603
|
const fileHandle = await parentHandle.getFileHandle(child.name, { create: true });
|
|
9409
9604
|
const writable = await fileHandle.createWritable();
|
|
9410
9605
|
await child.getData({ writable }, Object.assign({}, options, {
|
|
9606
|
+
signal,
|
|
9411
9607
|
onprogress: async progress => {
|
|
9412
9608
|
if (options.onprogress) {
|
|
9413
9609
|
writtenSizes.set(child.id, progress);
|
|
@@ -9419,9 +9615,19 @@
|
|
|
9419
9615
|
}
|
|
9420
9616
|
}
|
|
9421
9617
|
}));
|
|
9618
|
+
exportedEntryNames.push(child.getRelativeName(zipEntry));
|
|
9422
9619
|
}
|
|
9423
9620
|
} catch (error) {
|
|
9424
|
-
|
|
9621
|
+
abortController.abort(new Error(ERR_ABORT_EXPORT));
|
|
9622
|
+
try {
|
|
9623
|
+
if (error.entryName === UNDEFINED_VALUE) {
|
|
9624
|
+
error.entryName = child.getRelativeName(zipEntry);
|
|
9625
|
+
error.entryId = child.id;
|
|
9626
|
+
}
|
|
9627
|
+
} catch {
|
|
9628
|
+
// ignored
|
|
9629
|
+
}
|
|
9630
|
+
throw error;
|
|
9425
9631
|
}
|
|
9426
9632
|
}
|
|
9427
9633
|
}
|
|
@@ -9624,12 +9830,17 @@
|
|
|
9624
9830
|
exports.ERR_INVALID_ENTRY_NAME = ERR_INVALID_ENTRY_NAME;
|
|
9625
9831
|
exports.ERR_INVALID_EXTRAFIELD_DATA = ERR_INVALID_EXTRAFIELD_DATA;
|
|
9626
9832
|
exports.ERR_INVALID_EXTRAFIELD_TYPE = ERR_INVALID_EXTRAFIELD_TYPE;
|
|
9833
|
+
exports.ERR_INVALID_FILENAME_VALIDATION = ERR_INVALID_FILENAME_VALIDATION;
|
|
9627
9834
|
exports.ERR_INVALID_GID = ERR_INVALID_GID;
|
|
9835
|
+
exports.ERR_INVALID_LEVEL = ERR_INVALID_LEVEL;
|
|
9836
|
+
exports.ERR_INVALID_MAX_APPENDED_DATA_SIZE = ERR_INVALID_MAX_APPENDED_DATA_SIZE;
|
|
9628
9837
|
exports.ERR_INVALID_MSDOS_ATTRIBUTES = ERR_INVALID_MSDOS_ATTRIBUTES;
|
|
9629
9838
|
exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
|
|
9630
9839
|
exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
|
|
9840
|
+
exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
|
|
9631
9841
|
exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
|
|
9632
9842
|
exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
|
|
9843
|
+
exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
|
|
9633
9844
|
exports.ERR_INVALID_UID = ERR_INVALID_UID;
|
|
9634
9845
|
exports.ERR_INVALID_UNCOMPRESSED_SIZE = ERR_INVALID_UNCOMPRESSED_SIZE;
|
|
9635
9846
|
exports.ERR_INVALID_UNIX_EXTRA_FIELD_TYPE = ERR_INVALID_UNIX_EXTRA_FIELD_TYPE;
|
|
@@ -9644,6 +9855,7 @@
|
|
|
9644
9855
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
9645
9856
|
exports.ERR_UNDEFINED_READER = ERR_UNDEFINED_READER;
|
|
9646
9857
|
exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
|
|
9858
|
+
exports.ERR_UNSAFE_FILENAME = ERR_UNSAFE_FILENAME;
|
|
9647
9859
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION$1;
|
|
9648
9860
|
exports.ERR_UNSUPPORTED_CONTEXT = ERR_UNSUPPORTED_CONTEXT;
|
|
9649
9861
|
exports.ERR_UNSUPPORTED_CRYPTO_API = ERR_UNSUPPORTED_CRYPTO_API;
|