single-file-core 1.4.2 → 1.4.4
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/vendor/zip/zip.js
CHANGED
|
@@ -71,8 +71,8 @@ const MAX_DATE = new Date(2107, 11, 31);
|
|
|
71
71
|
const MIN_DATE = new Date(1980, 0, 1);
|
|
72
72
|
|
|
73
73
|
const UNDEFINED_VALUE = undefined;
|
|
74
|
-
const UNDEFINED_TYPE
|
|
75
|
-
const FUNCTION_TYPE
|
|
74
|
+
const UNDEFINED_TYPE = "undefined";
|
|
75
|
+
const FUNCTION_TYPE = "function";
|
|
76
76
|
|
|
77
77
|
/*
|
|
78
78
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -102,6 +102,7 @@ const FUNCTION_TYPE$1 = "function";
|
|
|
102
102
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
103
103
|
*/
|
|
104
104
|
|
|
105
|
+
|
|
105
106
|
class StreamAdapter {
|
|
106
107
|
|
|
107
108
|
constructor(Codec) {
|
|
@@ -152,10 +153,11 @@ class StreamAdapter {
|
|
|
152
153
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
153
154
|
*/
|
|
154
155
|
|
|
156
|
+
|
|
155
157
|
const MINIMUM_CHUNK_SIZE = 64;
|
|
156
158
|
let maxWorkers = 2;
|
|
157
159
|
try {
|
|
158
|
-
if (typeof navigator != UNDEFINED_TYPE
|
|
160
|
+
if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
|
|
159
161
|
maxWorkers = navigator.hardwareConcurrency;
|
|
160
162
|
}
|
|
161
163
|
} catch (_error) {
|
|
@@ -168,8 +170,8 @@ const DEFAULT_CONFIGURATION = {
|
|
|
168
170
|
useWebWorkers: true,
|
|
169
171
|
useCompressionStream: true,
|
|
170
172
|
workerScripts: UNDEFINED_VALUE,
|
|
171
|
-
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE
|
|
172
|
-
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE
|
|
173
|
+
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
|
|
174
|
+
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
|
|
173
175
|
};
|
|
174
176
|
|
|
175
177
|
const config = Object.assign({}, DEFAULT_CONFIGURATION);
|
|
@@ -238,7 +240,7 @@ function setIfDefined(propertyName, propertyValue) {
|
|
|
238
240
|
}
|
|
239
241
|
}
|
|
240
242
|
|
|
241
|
-
function e(e){const t=()=>URL.createObjectURL(new Blob(['const{Array:e,Object:t,Number:n,Math:r,Error:s,Uint8Array:a,Uint16Array:i,Uint32Array:o,Int32Array:l,Map:c,DataView:h,Promise:f,TextEncoder:u,crypto:p,postMessage:d,TransformStream:g,ReadableStream:w,WritableStream:v,CompressionStream:y,DecompressionStream:b}=self;class m{constructor(e){return class extends g{constructor(t,n){const r=new e(n);super({transform(e,t){t.enqueue(r.append(e))},flush(e){const t=r.flush();t&&e.enqueue(t)}})}}}}const _=[];for(let e=0;256>e;e++){let t=e;for(let e=0;8>e;e++)1&t?t=t>>>1^3988292384:t>>>=1;_[e]=t}class k{constructor(e){this.crc=e||-1}append(e){let t=0|this.crc;for(let n=0,r=0|e.length;r>n;n++)t=t>>>8^_[255&(t^e[n])];this.crc=t}get(){return~this.crc}}class S extends g{constructor(){let e;const t=new k;super({transform(e,n){t.append(e),n.enqueue(e)},flush(){const n=new a(4);new h(n.buffer).setUint32(0,t.get()),e.value=n}}),e=this}}const z={concat(e,t){if(0===e.length||0===t.length)return e.concat(t);const n=e[e.length-1],r=z.getPartial(n);return 32===r?e.concat(t):z._shiftRight(t,r,0|n,e.slice(0,e.length-1))},bitLength(e){const t=e.length;if(0===t)return 0;const n=e[t-1];return 32*(t-1)+z.getPartial(n)},clamp(e,t){if(32*e.length<t)return e;const n=(e=e.slice(0,r.ceil(t/32))).length;return t&=31,n>0&&t&&(e[n-1]=z.partial(t,e[n-1]&2147483648>>t-1,1)),e},partial:(e,t,n)=>32===e?t:(n?0|t:t<<32-e)+1099511627776*e,getPartial:e=>r.round(e/1099511627776)||32,_shiftRight(e,t,n,r){for(void 0===r&&(r=[]);t>=32;t-=32)r.push(n),n=0;if(0===t)return r.concat(e);for(let s=0;s<e.length;s++)r.push(n|e[s]>>>t),n=e[s]<<32-t;const s=e.length?e[e.length-1]:0,a=z.getPartial(s);return r.push(z.partial(t+a&31,t+a>32?n:r.pop(),1)),r}},D={bytes:{fromBits(e){const t=z.bitLength(e)/8,n=new a(t);let r;for(let s=0;t>s;s++)0==(3&s)&&(r=e[s/4]),n[s]=r>>>24,r<<=8;return n},toBits(e){const t=[];let n,r=0;for(n=0;n<e.length;n++)r=r<<8|e[n],3==(3&n)&&(t.push(r),r=0);return 3&n&&t.push(z.partial(8*(3&n),r)),t}}},C=class{constructor(e){const t=this;t.blockSize=512,t._init=[1732584193,4023233417,2562383102,271733878,3285377520],t._key=[1518500249,1859775393,2400959708,3395469782],e?(t._h=e._h.slice(0),t._buffer=e._buffer.slice(0),t._length=e._length):t.reset()}reset(){const e=this;return e._h=e._init.slice(0),e._buffer=[],e._length=0,e}update(e){const t=this;"string"==typeof e&&(e=D.utf8String.toBits(e));const n=t._buffer=z.concat(t._buffer,e),r=t._length,a=t._length=r+z.bitLength(e);if(a>9007199254740991)throw new s("Cannot hash more than 2^53 - 1 bits");const i=new o(n);let l=0;for(let e=t.blockSize+r-(t.blockSize+r&t.blockSize-1);a>=e;e+=t.blockSize)t._block(i.subarray(16*l,16*(l+1))),l+=1;return n.splice(0,16*l),t}finalize(){const e=this;let t=e._buffer;const n=e._h;t=z.concat(t,[z.partial(1,1)]);for(let e=t.length+2;15&e;e++)t.push(0);for(t.push(r.floor(e._length/4294967296)),t.push(0|e._length);t.length;)e._block(t.splice(0,16));return e.reset(),n}_f(e,t,n,r){return e>19?e>39?e>59?e>79?void 0:t^n^r:t&n|t&r|n&r:t^n^r:t&n|~t&r}_S(e,t){return t<<e|t>>>32-e}_block(t){const n=this,s=n._h,a=e(80);for(let e=0;16>e;e++)a[e]=t[e];let i=s[0],o=s[1],l=s[2],c=s[3],h=s[4];for(let e=0;79>=e;e++){16>e||(a[e]=n._S(1,a[e-3]^a[e-8]^a[e-14]^a[e-16]));const t=n._S(5,i)+n._f(e,o,l,c)+h+a[e]+n._key[r.floor(e/20)]|0;h=c,c=l,l=n._S(30,o),o=i,i=t}s[0]=s[0]+i|0,s[1]=s[1]+o|0,s[2]=s[2]+l|0,s[3]=s[3]+c|0,s[4]=s[4]+h|0}},I={getRandomValues(e){const t=new o(e.buffer),n=e=>{let t=987654321;const n=4294967295;return()=>(t=36969*(65535&t)+(t>>16)&n,(((t<<16)+(e=18e3*(65535&e)+(e>>16)&n)&n)/4294967296+.5)*(r.random()>.5?1:-1))};for(let s,a=0;a<e.length;a+=4){const e=n(4294967296*(s||r.random()));s=987654071*e(),t[a/4]=4294967296*e()|0}return e}},x={importKey:e=>new x.hmacSha1(D.bytes.toBits(e)),pbkdf2(e,t,n,r){if(n=n||1e4,0>r||0>n)throw new s("invalid params to pbkdf2");const a=1+(r>>5)<<2;let i,o,l,c,f;const u=new ArrayBuffer(a),p=new h(u);let d=0;const g=z;for(t=D.bytes.toBits(t),f=1;(a||1)>d;f++){for(i=o=e.encrypt(g.concat(t,[f])),l=1;n>l;l++)for(o=e.encrypt(o),c=0;c<o.length;c++)i[c]^=o[c];for(l=0;(a||1)>d&&l<i.length;l++)p.setInt32(d,i[l]),d+=4}return u.slice(0,r/8)},hmacSha1:class{constructor(e){const t=this,n=t._hash=C,r=[[],[]];t._baseHash=[new n,new n];const s=t._baseHash[0].blockSize/32;e.length>s&&(e=(new n).update(e).finalize());for(let t=0;s>t;t++)r[0][t]=909522486^e[t],r[1][t]=1549556828^e[t];t._baseHash[0].update(r[0]),t._baseHash[1].update(r[1]),t._resultHash=new n(t._baseHash[0])}reset(){const e=this;e._resultHash=new e._hash(e._baseHash[0]),e._updated=!1}update(e){this._updated=!0,this._resultHash.update(e)}digest(){const e=this,t=e._resultHash.finalize(),n=new e._hash(e._baseHash[1]).update(t).finalize();return e.reset(),n}encrypt(e){if(this._updated)throw new s("encrypt on already updated hmac called!");return this.update(e),this.digest(e)}}},A=void 0!==p&&"function"==typeof p.getRandomValues,T="Invalid password",R="Invalid signature",H="zipjs-abort-check-password";function q(e){return A?p.getRandomValues(e):I.getRandomValues(e)}const B=16,K={name:"PBKDF2"},V=t.assign({hash:{name:"HMAC"}},K),P=t.assign({iterations:1e3,hash:{name:"SHA-1"}},K),E=["deriveBits"],U=[8,12,16],W=[16,24,32],M=10,N=[0,0,0,0],O="undefined",F="function",L=typeof p!=O,j=L&&p.subtle,G=L&&typeof j!=O,X=D.bytes,J=class{constructor(e){const t=this;t._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],t._tables[0][0][0]||t._precompute();const n=t._tables[0][4],r=t._tables[1],a=e.length;let i,o,l,c=1;if(4!==a&&6!==a&&8!==a)throw new s("invalid aes key size");for(t._key=[o=e.slice(0),l=[]],i=a;4*a+28>i;i++){let e=o[i-1];(i%a==0||8===a&&i%a==4)&&(e=n[e>>>24]<<24^n[e>>16&255]<<16^n[e>>8&255]<<8^n[255&e],i%a==0&&(e=e<<8^e>>>24^c<<24,c=c<<1^283*(c>>7))),o[i]=o[i-a]^e}for(let e=0;i;e++,i--){const t=o[3&e?i:i-4];l[e]=4>=i||4>e?t:r[0][n[t>>>24]]^r[1][n[t>>16&255]]^r[2][n[t>>8&255]]^r[3][n[255&t]]}}encrypt(e){return this._crypt(e,0)}decrypt(e){return this._crypt(e,1)}_precompute(){const e=this._tables[0],t=this._tables[1],n=e[4],r=t[4],s=[],a=[];let i,o,l,c;for(let e=0;256>e;e++)a[(s[e]=e<<1^283*(e>>7))^e]=e;for(let h=i=0;!n[h];h^=o||1,i=a[i]||1){let a=i^i<<1^i<<2^i<<3^i<<4;a=a>>8^255&a^99,n[h]=a,r[a]=h,c=s[l=s[o=s[h]]];let f=16843009*c^65537*l^257*o^16843008*h,u=257*s[a]^16843008*a;for(let n=0;4>n;n++)e[n][h]=u=u<<24^u>>>8,t[n][a]=f=f<<24^f>>>8}for(let n=0;5>n;n++)e[n]=e[n].slice(0),t[n]=t[n].slice(0)}_crypt(e,t){if(4!==e.length)throw new s("invalid aes block size");const n=this._key[t],r=n.length/4-2,a=[0,0,0,0],i=this._tables[t],o=i[0],l=i[1],c=i[2],h=i[3],f=i[4];let u,p,d,g=e[0]^n[0],w=e[t?3:1]^n[1],v=e[2]^n[2],y=e[t?1:3]^n[3],b=4;for(let e=0;r>e;e++)u=o[g>>>24]^l[w>>16&255]^c[v>>8&255]^h[255&y]^n[b],p=o[w>>>24]^l[v>>16&255]^c[y>>8&255]^h[255&g]^n[b+1],d=o[v>>>24]^l[y>>16&255]^c[g>>8&255]^h[255&w]^n[b+2],y=o[y>>>24]^l[g>>16&255]^c[w>>8&255]^h[255&v]^n[b+3],b+=4,g=u,w=p,v=d;for(let e=0;4>e;e++)a[t?3&-e:e]=f[g>>>24]<<24^f[w>>16&255]<<16^f[v>>8&255]<<8^f[255&y]^n[b++],u=g,g=w,w=v,v=y,y=u;return a}},Q=class{constructor(e,t){this._prf=e,this._initIv=t,this._iv=t}reset(){this._iv=this._initIv}update(e){return this.calculate(this._prf,e,this._iv)}incWord(e){if(255==(e>>24&255)){let t=e>>16&255,n=e>>8&255,r=255&e;255===t?(t=0,255===n?(n=0,255===r?r=0:++r):++n):++t,e=0,e+=t<<16,e+=n<<8,e+=r}else e+=1<<24;return e}incCounter(e){0===(e[0]=this.incWord(e[0]))&&(e[1]=this.incWord(e[1]))}calculate(e,t,n){let r;if(!(r=t.length))return[];const s=z.bitLength(t);for(let s=0;r>s;s+=4){this.incCounter(n);const r=e.encrypt(n);t[s]^=r[0],t[s+1]^=r[1],t[s+2]^=r[2],t[s+3]^=r[3]}return z.clamp(t,s)}},Y=x.hmacSha1;let Z=L&&G&&typeof j.importKey==F,$=L&&G&&typeof j.deriveBits==F;class ee extends g{constructor({password:e,signed:n,encryptionStrength:r,checkPasswordOnly:i}){super({start(){t.assign(this,{ready:new f((e=>this.resolveReady=e)),password:e,signed:n,strength:r-1,pending:new a})},async transform(e,t){const n=this,{password:r,strength:o,resolveReady:l,ready:c}=n;r?(await(async(e,t,n,r)=>{const a=await re(e,t,n,ae(r,0,U[t])),i=ae(r,U[t]);if(a[0]!=i[0]||a[1]!=i[1])throw new s(T)})(n,o,r,ae(e,0,U[o]+2)),e=ae(e,U[o]+2),i?t.error(new s(H)):l()):await c;const h=new a(e.length-M-(e.length-M)%B);t.enqueue(ne(n,e,h,0,M,!0))},async flush(e){const{signed:t,ctr:n,hmac:r,pending:i,ready:o}=this;if(r&&n){await o;const l=ae(i,0,i.length-M),c=ae(i,i.length-M);let h=new a;if(l.length){const e=oe(X,l);r.update(e);const t=n.update(e);h=ie(X,t)}if(t){const e=ae(ie(X,r.digest()),0,M);for(let t=0;M>t;t++)if(e[t]!=c[t])throw new s(R)}e.enqueue(h)}}})}}class te extends g{constructor({password:e,encryptionStrength:n}){let r;super({start(){t.assign(this,{ready:new f((e=>this.resolveReady=e)),password:e,strength:n-1,pending:new a})},async transform(e,t){const n=this,{password:r,strength:s,resolveReady:i,ready:o}=n;let l=new a;r?(l=await(async(e,t,n)=>{const r=q(new a(U[t]));return se(r,await re(e,t,n,r))})(n,s,r),i()):await o;const c=new a(l.length+e.length-e.length%B);c.set(l,0),t.enqueue(ne(n,e,c,l.length,0))},async flush(e){const{ctr:t,hmac:n,pending:s,ready:i}=this;if(n&&t){await i;let o=new a;if(s.length){const e=t.update(oe(X,s));n.update(e),o=ie(X,e)}r.signature=ie(X,n.digest()).slice(0,M),e.enqueue(se(o,r.signature))}}}),r=this}}function ne(e,t,n,r,s,i){const{ctr:o,hmac:l,pending:c}=e,h=t.length-s;let f;for(c.length&&(t=se(c,t),n=((e,t)=>{if(t&&t>e.length){const n=e;(e=new a(t)).set(n,0)}return e})(n,h-h%B)),f=0;h-B>=f;f+=B){const e=oe(X,ae(t,f,f+B));i&&l.update(e);const s=o.update(e);i||l.update(s),n.set(ie(X,s),f+r)}return e.pending=ae(t,f),n}async function re(n,r,s,i){n.password=null;const o=(e=>{if(void 0===u){const t=new a((e=unescape(encodeURIComponent(e))).length);for(let n=0;n<t.length;n++)t[n]=e.charCodeAt(n);return t}return(new u).encode(e)})(s),l=await(async(e,t,n,r,s)=>{if(!Z)return x.importKey(t);try{return await j.importKey("raw",t,n,!1,s)}catch(e){return Z=!1,x.importKey(t)}})(0,o,V,0,E),c=await(async(e,t,n)=>{if(!$)return x.pbkdf2(t,e.salt,P.iterations,n);try{return await j.deriveBits(e,t,n)}catch(r){return $=!1,x.pbkdf2(t,e.salt,P.iterations,n)}})(t.assign({salt:i},P),l,8*(2*W[r]+2)),h=new a(c),f=oe(X,ae(h,0,W[r])),p=oe(X,ae(h,W[r],2*W[r])),d=ae(h,2*W[r]);return t.assign(n,{keys:{key:f,authentication:p,passwordVerification:d},ctr:new Q(new J(f),e.from(N)),hmac:new Y(p)}),d}function se(e,t){let n=e;return e.length+t.length&&(n=new a(e.length+t.length),n.set(e,0),n.set(t,e.length)),n}function ae(e,t,n){return e.subarray(t,n)}function ie(e,t){return e.fromBits(t)}function oe(e,t){return e.toBits(t)}class le extends g{constructor({password:e,passwordVerification:n,checkPasswordOnly:r}){super({start(){t.assign(this,{password:e,passwordVerification:n}),ue(this,e)},transform(e,t){const n=this;if(n.password){const t=he(n,e.subarray(0,12));if(n.password=null,t[11]!=n.passwordVerification)throw new s(T);e=e.subarray(12)}r?t.error(new s(H)):t.enqueue(he(n,e))}})}}class ce extends g{constructor({password:e,passwordVerification:n}){super({start(){t.assign(this,{password:e,passwordVerification:n}),ue(this,e)},transform(e,t){const n=this;let r,s;if(n.password){n.password=null;const t=q(new a(12));t[11]=n.passwordVerification,r=new a(e.length+t.length),r.set(fe(n,t),0),s=12}else r=new a(e.length),s=0;r.set(fe(n,e),s),t.enqueue(r)}})}}function he(e,t){const n=new a(t.length);for(let r=0;r<t.length;r++)n[r]=de(e)^t[r],pe(e,n[r]);return n}function fe(e,t){const n=new a(t.length);for(let r=0;r<t.length;r++)n[r]=de(e)^t[r],pe(e,t[r]);return n}function ue(e,n){const r=[305419896,591751049,878082192];t.assign(e,{keys:r,crcKey0:new k(r[0]),crcKey2:new k(r[2])});for(let t=0;t<n.length;t++)pe(e,n.charCodeAt(t))}function pe(e,t){let[n,s,a]=e.keys;e.crcKey0.append([t]),n=~e.crcKey0.get(),s=we(r.imul(we(s+ge(n)),134775813)+1),e.crcKey2.append([s>>>24]),a=~e.crcKey2.get(),e.keys=[n,s,a]}function de(e){const t=2|e.keys[2];return ge(r.imul(t,1^t)>>>8)}function ge(e){return 255&e}function we(e){return 4294967295&e}const ve="deflate-raw";class ye extends g{constructor(e,{chunkSize:t,CompressionStream:n,CompressionStreamNative:r}){super({});const{compressed:s,encrypted:a,useCompressionStream:i,zipCrypto:o,signed:l,level:c}=e,f=this;let u,p,d=me(super.readable);a&&!o||!l||(u=new S,d=Se(d,u)),s&&(d=ke(d,i,{level:c,chunkSize:t},r,n)),a&&(o?d=Se(d,new ce(e)):(p=new te(e),d=Se(d,p))),_e(f,d,(()=>{let e;a&&!o&&(e=p.signature),a&&!o||!l||(e=new h(u.value.buffer).getUint32(0)),f.signature=e}))}}class be extends g{constructor(e,{chunkSize:t,DecompressionStream:n,DecompressionStreamNative:r}){super({});const{zipCrypto:a,encrypted:i,signed:o,signature:l,compressed:c,useCompressionStream:f}=e;let u,p,d=me(super.readable);i&&(a?d=Se(d,new le(e)):(p=new ee(e),d=Se(d,p))),c&&(d=ke(d,f,{chunkSize:t},r,n)),i&&!a||!o||(u=new S,d=Se(d,u)),_e(this,d,(()=>{if((!i||a)&&o){const e=new h(u.value.buffer);if(l!=e.getUint32(0,!1))throw new s(R)}}))}}function me(e){return Se(e,new g({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function _e(e,n,r){n=Se(n,new g({flush:r})),t.defineProperty(e,"readable",{get:()=>n})}function ke(e,t,n,r,s){try{e=Se(e,new(t&&r?r:s)(ve,n))}catch(r){if(!t)throw r;e=Se(e,new s(ve,n))}return e}function Se(e,t){return e.pipeThrough(t)}const ze="data";class De extends g{constructor(e,n){super({});const r=this,{codecType:s}=e;let a;s.startsWith("deflate")?a=ye:s.startsWith("inflate")&&(a=be);let i=0;const o=new a(e,n),l=super.readable,c=new g({transform(e,t){e&&e.length&&(i+=e.length,t.enqueue(e))},flush(){const{signature:e}=o;t.assign(r,{signature:e,size:i})}});t.defineProperty(r,"readable",{get:()=>l.pipeThrough(o).pipeThrough(c)})}}const Ce=new c,Ie=new c;let xe=0;async function Ae(e){try{const{options:t,scripts:r,config:s}=e;r&&r.length&&importScripts.apply(void 0,r),self.initCodec&&self.initCodec(),s.CompressionStreamNative=self.CompressionStream,s.DecompressionStreamNative=self.DecompressionStream,self.Deflate&&(s.CompressionStream=new m(self.Deflate)),self.Inflate&&(s.DecompressionStream=new m(self.Inflate));const a={highWaterMark:1,size:()=>s.chunkSize},i=e.readable||new w({async pull(e){const t=new f((e=>Ce.set(xe,e)));Te({type:"pull",messageId:xe}),xe=(xe+1)%n.MAX_SAFE_INTEGER;const{value:r,done:s}=await t;e.enqueue(r),s&&e.close()}},a),o=e.writable||new v({async write(e){let t;const r=new f((e=>t=e));Ie.set(xe,t),Te({type:ze,value:e,messageId:xe}),xe=(xe+1)%n.MAX_SAFE_INTEGER,await r}},a),l=new De(t,s);await i.pipeThrough(l).pipeTo(o,{preventClose:!0,preventAbort:!0});try{await o.getWriter().close()}catch(e){}const{signature:c,size:h}=l;Te({type:"close",result:{signature:c,size:h}})}catch(e){Re(e)}}function Te(e){let{value:t}=e;if(t)if(t.length)try{t=new a(t),e.value=t.buffer,d(e,[e.value])}catch(t){d(e)}else d(e);else d(e)}function Re(e=new s("Unknown error")){const{message:t,stack:n,code:r,name:a}=e;d({error:{message:t,stack:n,code:r,name:a}})}addEventListener("message",(({data:e})=>{const{type:t,messageId:n,value:r,done:s}=e;try{if("start"==t&&Ae(e),t==ze){const e=Ce.get(n);Ce.delete(n),e({value:new a(r),done:s})}if("ack"==t){const e=Ie.get(n);Ie.delete(n),e()}}catch(e){Re(e)}}));var He=a,qe=i,Be=l,Ke=new He([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Ve=new He([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Pe=new He([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ee=(e,t)=>{for(var n=new qe(31),r=0;31>r;++r)n[r]=t+=1<<e[r-1];var s=new Be(n[30]);for(r=1;30>r;++r)for(var a=n[r];a<n[r+1];++a)s[a]=a-n[r]<<5|r;return{b:n,r:s}},Ue=Ee(Ke,2),We=Ue.b,Me=Ue.r;We[28]=258,Me[258]=28;for(var Ne=Ee(Ve,0),Oe=Ne.b,Fe=Ne.r,Le=new qe(32768),je=0;32768>je;++je){var Ge=(43690&je)>>1|(21845&je)<<1;Ge=(61680&(Ge=(52428&Ge)>>2|(13107&Ge)<<2))>>4|(3855&Ge)<<4,Le[je]=((65280&Ge)>>8|(255&Ge)<<8)>>1}var Xe=(e,t,n)=>{for(var r=e.length,s=0,a=new qe(t);r>s;++s)e[s]&&++a[e[s]-1];var i,o=new qe(t);for(s=1;t>s;++s)o[s]=o[s-1]+a[s-1]<<1;if(n){i=new qe(1<<t);var l=15-t;for(s=0;r>s;++s)if(e[s])for(var c=s<<4|e[s],h=t-e[s],f=o[e[s]-1]++<<h,u=f|(1<<h)-1;u>=f;++f)i[Le[f]>>l]=c}else for(i=new qe(r),s=0;r>s;++s)e[s]&&(i[s]=Le[o[e[s]-1]++]>>15-e[s]);return i},Je=new He(288);for(je=0;144>je;++je)Je[je]=8;for(je=144;256>je;++je)Je[je]=9;for(je=256;280>je;++je)Je[je]=7;for(je=280;288>je;++je)Je[je]=8;var Qe=new He(32);for(je=0;32>je;++je)Qe[je]=5;var Ye=Xe(Je,9,0),Ze=Xe(Je,9,1),$e=Xe(Qe,5,0),et=Xe(Qe,5,1),tt=e=>{for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},nt=(e,t,n)=>{var r=t/8|0;return(e[r]|e[r+1]<<8)>>(7&t)&n},rt=(e,t)=>{var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},st=e=>(e+7)/8|0,at=(e,t,n)=>((null==t||0>t)&&(t=0),(null==n||n>e.length)&&(n=e.length),new He(e.subarray(t,n))),it=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],ot=(e,t,n)=>{var r=new s(t||it[e]);if(r.code=e,s.captureStackTrace&&s.captureStackTrace(r,ot),!n)throw r;return r},lt=(e,t,n)=>{n<<=7&t;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},ct=(e,t,n)=>{n<<=7&t;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8,e[r+2]|=n>>16},ht=(e,t)=>{for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var s=n.length,a=n.slice();if(!s)return{t:vt,l:0};if(1==s){var i=new He(n[0].s+1);return i[n[0].s]=1,{t:i,l:1}}n.sort(((e,t)=>e.f-t.f)),n.push({s:-1,f:25001});var o=n[0],l=n[1],c=0,h=1,f=2;for(n[0]={s:-1,f:o.f+l.f,l:o,r:l};h!=s-1;)o=n[n[c].f<n[f].f?c++:f++],l=n[c!=h&&n[c].f<n[f].f?c++:f++],n[h++]={s:-1,f:o.f+l.f,l:o,r:l};var u=a[0].s;for(r=1;s>r;++r)a[r].s>u&&(u=a[r].s);var p=new qe(u+1),d=ft(n[h-1],p,0);if(d>t){r=0;var g=0,w=d-t,v=1<<w;for(a.sort(((e,t)=>p[t.s]-p[e.s]||e.f-t.f));s>r;++r){var y=a[r].s;if(p[y]<=t)break;g+=v-(1<<d-p[y]),p[y]=t}for(g>>=w;g>0;){var b=a[r].s;p[b]<t?g-=1<<t-p[b]++-1:++r}for(;r>=0&&g;--r){var m=a[r].s;p[m]==t&&(--p[m],++g)}d=t}return{t:new He(p),l:d}},ft=(e,t,n)=>-1==e.s?r.max(ft(e.l,t,n+1),ft(e.r,t,n+1)):t[e.s]=n,ut=e=>{for(var t=e.length;t&&!e[--t];);for(var n=new qe(++t),r=0,s=e[0],a=1,i=e=>{n[r++]=e},o=1;t>=o;++o)if(e[o]==s&&o!=t)++a;else{if(!s&&a>2){for(;a>138;a-=138)i(32754);a>2&&(i(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(i(s),--a;a>6;a-=6)i(8304);a>2&&(i(a-3<<5|8208),a=0)}for(;a--;)i(s);a=1,s=e[o]}return{c:n.subarray(0,r),n:t}},pt=(e,t)=>{for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},dt=(e,t,n)=>{var r=n.length,s=st(t+2);e[s]=255&r,e[s+1]=r>>8,e[s+2]=255^e[s],e[s+3]=255^e[s+1];for(var a=0;r>a;++a)e[s+a+4]=n[a];return 8*(s+4+r)},gt=(e,t,n,r,s,a,i,o,l,c,h)=>{lt(t,h++,n),++s[256];for(var f=ht(s,15),u=f.t,p=f.l,d=ht(a,15),g=d.t,w=d.l,v=ut(u),y=v.c,b=v.n,m=ut(g),_=m.c,k=m.n,S=new qe(19),z=0;z<y.length;++z)++S[31&y[z]];for(z=0;z<_.length;++z)++S[31&_[z]];for(var D=ht(S,7),C=D.t,I=D.l,x=19;x>4&&!C[Pe[x-1]];--x);var A,T,R,H,q=c+5<<3,B=pt(s,Je)+pt(a,Qe)+i,K=pt(s,u)+pt(a,g)+i+14+3*x+pt(S,C)+2*S[16]+3*S[17]+7*S[18];if(l>=0&&B>=q&&K>=q)return dt(t,h,e.subarray(l,l+c));if(lt(t,h,1+(B>K)),h+=2,B>K){A=Xe(u,p,0),T=u,R=Xe(g,w,0),H=g;var V=Xe(C,I,0);for(lt(t,h,b-257),lt(t,h+5,k-1),lt(t,h+10,x-4),h+=14,z=0;x>z;++z)lt(t,h+3*z,C[Pe[z]]);h+=3*x;for(var P=[y,_],E=0;2>E;++E){var U=P[E];for(z=0;z<U.length;++z){var W=31&U[z];lt(t,h,V[W]),h+=C[W],W>15&&(lt(t,h,U[z]>>5&127),h+=U[z]>>12)}}}else A=Ye,T=Je,R=$e,H=Qe;for(z=0;o>z;++z){var M=r[z];if(M>255){ct(t,h,A[257+(W=M>>18&31)]),h+=T[W+257],W>7&&(lt(t,h,M>>23&31),h+=Ke[W]);var N=31&M;ct(t,h,R[N]),h+=H[N],N>3&&(ct(t,h,M>>5&8191),h+=Ve[N])}else ct(t,h,A[M]),h+=T[M]}return ct(t,h,A[256]),h+T[256]},wt=new Be([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),vt=new He(0),yt=function(){function e(e,t){if("function"==typeof e&&(t=e,e={}),this.ondata=t,this.o=e||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new He(98304),this.o.dictionary){var n=this.o.dictionary.subarray(-32768);this.b.set(n,32768-n.length),this.s.i=32768-n.length}}return e.prototype.p=function(e,t){this.ondata(((e,t,n,s,a)=>{if(!a&&(a={l:1},t.dictionary)){var i=t.dictionary.subarray(-32768),o=new He(i.length+e.length);o.set(i),o.set(e,i.length),e=o,a.w=i.length}return((e,t,n,s,a,i)=>{var o=i.z||e.length,l=new He(0+o+5*(1+r.ceil(o/7e3))+0),c=l.subarray(0,l.length-0),h=i.l,f=7&(i.r||0);if(t){f&&(c[0]=i.r>>3);for(var u=wt[t-1],p=u>>13,d=8191&u,g=(1<<n)-1,w=i.p||new qe(32768),v=i.h||new qe(g+1),y=r.ceil(n/3),b=2*y,m=t=>(e[t]^e[t+1]<<y^e[t+2]<<b)&g,_=new Be(25e3),k=new qe(288),S=new qe(32),z=0,D=0,C=i.i||0,I=0,x=i.w||0,A=0;o>C+2;++C){var T=m(C),R=32767&C,H=v[T];if(w[R]=H,v[T]=R,C>=x){var q=o-C;if((z>7e3||I>24576)&&(q>423||!h)){f=gt(e,c,0,_,k,S,D,I,A,C-A,f),I=z=D=0,A=C;for(var B=0;286>B;++B)k[B]=0;for(B=0;30>B;++B)S[B]=0}var K=2,V=0,P=d,E=R-H&32767;if(q>2&&T==m(C-E))for(var U=r.min(p,q)-1,W=r.min(32767,C),M=r.min(258,q);W>=E&&--P&&R!=H;){if(e[C+K]==e[C+K-E]){for(var N=0;M>N&&e[C+N]==e[C+N-E];++N);if(N>K){if(K=N,V=E,N>U)break;var O=r.min(E,N-2),F=0;for(B=0;O>B;++B){var L=C-E+B&32767,j=L-w[L]&32767;j>F&&(F=j,H=L)}}}E+=(R=H)-(H=w[R])&32767}if(V){_[I++]=268435456|Me[K]<<18|Fe[V];var G=31&Me[K],X=31&Fe[V];D+=Ke[G]+Ve[X],++k[257+G],++S[X],x=C+K,++z}else _[I++]=e[C],++k[e[C]]}}for(C=r.max(C,x);o>C;++C)_[I++]=e[C],++k[e[C]];f=gt(e,c,h,_,k,S,D,I,A,C-A,f),h||(i.r=7&f|c[f/8|0]<<3,f-=7,i.h=v,i.p=w,i.i=C,i.w=x)}else{for(C=i.w||0;o+h>C;C+=65535){var J=C+65535;o>J||(c[f/8|0]=h,J=o),f=dt(c,f+1,e.subarray(C,J))}i.i=o}return at(l,0,0+st(f)+0)})(e,null==t.level?6:t.level,null==t.mem?r.ceil(1.5*r.max(8,r.min(13,r.log(e.length)))):12+t.mem,0,0,a)})(e,this.o,0,0,this.s),t)},e.prototype.push=function(e,t){this.ondata||ot(5),this.s.l&&ot(4);var n=e.length+this.s.z;if(n>this.b.length){if(n>2*this.b.length-32768){var r=new He(-32768&n);r.set(this.b.subarray(0,this.s.z)),this.b=r}var s=this.b.length-this.s.z;s&&(this.b.set(e.subarray(0,s),this.s.z),this.s.z=this.b.length,this.p(this.b,!1)),this.b.set(this.b.subarray(-32768)),this.b.set(e.subarray(s),32768),this.s.z=e.length-s+32768,this.s.i=32766,this.s.w=32768}else this.b.set(e,this.s.z),this.s.z+=e.length;this.s.l=1&t,(this.s.z>this.s.w+8191||t)&&(this.p(this.b,t||!1),this.s.w=this.s.i,this.s.i-=2)},e}(),bt=function(){function e(e,t){"function"==typeof e&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new He(32768),this.p=new He(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||ot(5),this.d&&ot(4),this.p.length){if(e.length){var t=new He(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}}else this.p=e},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=((e,t,n)=>{var s=e.length;if(!s||t.f&&!t.l)return n||new He(0);var a=!n,i=a||2!=t.i,o=t.i;a&&(n=new He(3*s));var l=e=>{var t=n.length;if(e>t){var s=new He(r.max(2*t,e));s.set(n),n=s}},c=t.f||0,h=t.p||0,f=t.b||0,u=t.l,p=t.d,d=t.m,g=t.n,w=8*s;do{if(!u){c=nt(e,h,1);var v=nt(e,h+1,3);if(h+=3,!v){var y=e[(A=st(h)+4)-4]|e[A-3]<<8,b=A+y;if(b>s){o&&ot(0);break}i&&l(f+y),n.set(e.subarray(A,b),f),t.b=f+=y,t.p=h=8*b,t.f=c;continue}if(1==v)u=Ze,p=et,d=9,g=5;else if(2==v){var m=nt(e,h,31)+257,_=nt(e,h+10,15)+4,k=m+nt(e,h+5,31)+1;h+=14;for(var S=new He(k),z=new He(19),D=0;_>D;++D)z[Pe[D]]=nt(e,h+3*D,7);h+=3*_;var C=tt(z),I=(1<<C)-1,x=Xe(z,C,1);for(D=0;k>D;){var A,T=x[nt(e,h,I)];if(h+=15&T,16>(A=T>>4))S[D++]=A;else{var R=0,H=0;for(16==A?(H=3+nt(e,h,3),h+=2,R=S[D-1]):17==A?(H=3+nt(e,h,7),h+=3):18==A&&(H=11+nt(e,h,127),h+=7);H--;)S[D++]=R}}var q=S.subarray(0,m),B=S.subarray(m);d=tt(q),g=tt(B),u=Xe(q,d,1),p=Xe(B,g,1)}else ot(1);if(h>w){o&&ot(0);break}}i&&l(f+131072);for(var K=(1<<d)-1,V=(1<<g)-1,P=h;;P=h){var E=(R=u[rt(e,h)&K])>>4;if((h+=15&R)>w){o&&ot(0);break}if(R||ot(2),256>E)n[f++]=E;else{if(256==E){P=h,u=null;break}var U=E-254;if(E>264){var W=Ke[D=E-257];U=nt(e,h,(1<<W)-1)+We[D],h+=W}var M=p[rt(e,h)&V],N=M>>4;if(M||ot(3),h+=15&M,B=Oe[N],N>3&&(W=Ve[N],B+=rt(e,h)&(1<<W)-1,h+=W),h>w){o&&ot(0);break}i&&l(f+131072);var O=f+U;if(B>f){var F=0-B,L=r.min(B,O);for(0>F+f&&ot(3);L>f;++f)n[f]=undefined[F+f]}for(;O>f;++f)n[f]=n[f-B]}}t.l=u,t.p=P,t.b=f,t.f=c,u&&(c=1,t.m=d,t.d=p,t.n=g)}while(!c);return f!=n.length&&a?at(n,0,f):n.subarray(0,f)})(this.p,this.s,this.o);this.ondata(at(n,t,this.s.b),this.d),this.o=at(n,this.s.b-32768),this.s.b=this.o.length,this.p=at(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),mt="undefined"!=typeof TextDecoder&&new TextDecoder;try{mt.decode(vt,{stream:!0})}catch(e){}function _t(e,n,r){return class{constructor(s){const i=this;var o,l;o=s,l="level",("function"==typeof t.hasOwn?t.hasOwn(o,l):o.hasOwnProperty(l))&&void 0===s.level&&delete s.level,i.codec=new e(t.assign({},n,s)),r(i.codec,(e=>{if(i.pendingData){const t=i.pendingData;i.pendingData=new a(t.length+e.length);const{pendingData:n}=i;n.set(t,0),n.set(e,t.length)}else i.pendingData=new a(e)}))}append(e){return this.codec.push(e),s(this)}flush(){return this.codec.push(new a,!0),s(this)}};function s(e){if(e.pendingData){const t=e.pendingData;return e.pendingData=null,t}return new a}}const{Deflate:kt,Inflate:St}=((e,t={},n)=>({Deflate:_t(e.Deflate,t.deflate,n),Inflate:_t(e.Inflate,t.inflate,n)}))({Deflate:yt,Inflate:bt},void 0,((e,t)=>e.ondata=t));self.initCodec=()=>{self.Deflate=kt,self.Inflate=St};\n'],{type:"text/javascript"}));e({workerScripts:{inflate:[t],deflate:[t]}});}
|
|
243
|
+
function e(e){const t=()=>URL.createObjectURL(new Blob(['const{Array:e,Object:t,Number:n,Math:s,Error:r,Uint8Array:a,Uint16Array:i,Uint32Array:o,Int32Array:l,Map:c,DataView:h,Promise:f,TextEncoder:u,crypto:p,postMessage:d,TransformStream:g,ReadableStream:w,WritableStream:y,CompressionStream:v,DecompressionStream:b}=self,m=void 0,_="undefined",S="function";class k{constructor(e){return class extends g{constructor(t,n){const s=new e(n);super({transform(e,t){t.enqueue(s.append(e))},flush(e){const t=s.flush();t&&e.enqueue(t)}})}}}}const z=[];for(let e=0;256>e;e++){let t=e;for(let e=0;8>e;e++)1&t?t=t>>>1^3988292384:t>>>=1;z[e]=t}class D{constructor(e){this.crc=e||-1}append(e){let t=0|this.crc;for(let n=0,s=0|e.length;s>n;n++)t=t>>>8^z[255&(t^e[n])];this.crc=t}get(){return~this.crc}}class C extends g{constructor(){let e;const t=new D;super({transform(e,n){t.append(e),n.enqueue(e)},flush(){const n=new a(4);new h(n.buffer).setUint32(0,t.get()),e.value=n}}),e=this}}const x={concat(e,t){if(0===e.length||0===t.length)return e.concat(t);const n=e[e.length-1],s=x.getPartial(n);return 32===s?e.concat(t):x._shiftRight(t,s,0|n,e.slice(0,e.length-1))},bitLength(e){const t=e.length;if(0===t)return 0;const n=e[t-1];return 32*(t-1)+x.getPartial(n)},clamp(e,t){if(32*e.length<t)return e;const n=(e=e.slice(0,s.ceil(t/32))).length;return t&=31,n>0&&t&&(e[n-1]=x.partial(t,e[n-1]&2147483648>>t-1,1)),e},partial:(e,t,n)=>32===e?t:(n?0|t:t<<32-e)+1099511627776*e,getPartial:e=>s.round(e/1099511627776)||32,_shiftRight(e,t,n,s){for(void 0===s&&(s=[]);t>=32;t-=32)s.push(n),n=0;if(0===t)return s.concat(e);for(let r=0;r<e.length;r++)s.push(n|e[r]>>>t),n=e[r]<<32-t;const r=e.length?e[e.length-1]:0,a=x.getPartial(r);return s.push(x.partial(t+a&31,t+a>32?n:s.pop(),1)),s}},I={bytes:{fromBits(e){const t=x.bitLength(e)/8,n=new a(t);let s;for(let r=0;t>r;r++)3&r||(s=e[r/4]),n[r]=s>>>24,s<<=8;return n},toBits(e){const t=[];let n,s=0;for(n=0;n<e.length;n++)s=s<<8|e[n],3&~n||(t.push(s),s=0);return 3&n&&t.push(x.partial(8*(3&n),s)),t}}},T=class{constructor(e){const t=this;t.blockSize=512,t._init=[1732584193,4023233417,2562383102,271733878,3285377520],t._key=[1518500249,1859775393,2400959708,3395469782],e?(t._h=e._h.slice(0),t._buffer=e._buffer.slice(0),t._length=e._length):t.reset()}reset(){const e=this;return e._h=e._init.slice(0),e._buffer=[],e._length=0,e}update(e){const t=this;"string"==typeof e&&(e=I.utf8String.toBits(e));const n=t._buffer=x.concat(t._buffer,e),s=t._length,a=t._length=s+x.bitLength(e);if(a>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const i=new o(n);let l=0;for(let e=t.blockSize+s-(t.blockSize+s&t.blockSize-1);a>=e;e+=t.blockSize)t._block(i.subarray(16*l,16*(l+1))),l+=1;return n.splice(0,16*l),t}finalize(){const e=this;let t=e._buffer;const n=e._h;t=x.concat(t,[x.partial(1,1)]);for(let e=t.length+2;15&e;e++)t.push(0);for(t.push(s.floor(e._length/4294967296)),t.push(0|e._length);t.length;)e._block(t.splice(0,16));return e.reset(),n}_f(e,t,n,s){return e>19?e>39?e>59?e>79?void 0:t^n^s:t&n|t&s|n&s:t^n^s:t&n|~t&s}_S(e,t){return t<<e|t>>>32-e}_block(t){const n=this,r=n._h,a=e(80);for(let e=0;16>e;e++)a[e]=t[e];let i=r[0],o=r[1],l=r[2],c=r[3],h=r[4];for(let e=0;79>=e;e++){16>e||(a[e]=n._S(1,a[e-3]^a[e-8]^a[e-14]^a[e-16]));const t=n._S(5,i)+n._f(e,o,l,c)+h+a[e]+n._key[s.floor(e/20)]|0;h=c,c=l,l=n._S(30,o),o=i,i=t}r[0]=r[0]+i|0,r[1]=r[1]+o|0,r[2]=r[2]+l|0,r[3]=r[3]+c|0,r[4]=r[4]+h|0}},A={getRandomValues(e){const t=new o(e.buffer),n=e=>{let t=987654321;const n=4294967295;return()=>(t=36969*(65535&t)+(t>>16)&n,(((t<<16)+(e=18e3*(65535&e)+(e>>16)&n)&n)/4294967296+.5)*(s.random()>.5?1:-1))};for(let r,a=0;a<e.length;a+=4){const e=n(4294967296*(r||s.random()));r=987654071*e(),t[a/4]=4294967296*e()|0}return e}},q={importKey:e=>new q.hmacSha1(I.bytes.toBits(e)),pbkdf2(e,t,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const a=1+(s>>5)<<2;let i,o,l,c,f;const u=new ArrayBuffer(a),p=new h(u);let d=0;const g=x;for(t=I.bytes.toBits(t),f=1;(a||1)>d;f++){for(i=o=e.encrypt(g.concat(t,[f])),l=1;n>l;l++)for(o=e.encrypt(o),c=0;c<o.length;c++)i[c]^=o[c];for(l=0;(a||1)>d&&l<i.length;l++)p.setInt32(d,i[l]),d+=4}return u.slice(0,s/8)},hmacSha1:class{constructor(e){const t=this,n=t._hash=T,s=[[],[]];t._baseHash=[new n,new n];const r=t._baseHash[0].blockSize/32;e.length>r&&(e=(new n).update(e).finalize());for(let t=0;r>t;t++)s[0][t]=909522486^e[t],s[1][t]=1549556828^e[t];t._baseHash[0].update(s[0]),t._baseHash[1].update(s[1]),t._resultHash=new n(t._baseHash[0])}reset(){const e=this;e._resultHash=new e._hash(e._baseHash[0]),e._updated=!1}update(e){this._updated=!0,this._resultHash.update(e)}digest(){const e=this,t=e._resultHash.finalize(),n=new e._hash(e._baseHash[1]).update(t).finalize();return e.reset(),n}encrypt(e){if(this._updated)throw new r("encrypt on already updated hmac called!");return this.update(e),this.digest(e)}}},R=typeof p!=_&&typeof p.getRandomValues==S,H="Invalid password",P="Invalid signature",B="zipjs-abort-check-password";function K(e){return R?p.getRandomValues(e):A.getRandomValues(e)}const V=16,E={name:"PBKDF2"},U=t.assign({hash:{name:"HMAC"}},E),W=t.assign({iterations:1e3,hash:{name:"SHA-1"}},E),M=["deriveBits"],N=[8,12,16],O=[16,24,32],F=10,L=[0,0,0,0],j=typeof p!=_,G=j&&p.subtle,X=j&&typeof G!=_,J=I.bytes,Q=class{constructor(e){const t=this;t._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],t._tables[0][0][0]||t._precompute();const n=t._tables[0][4],s=t._tables[1],a=e.length;let i,o,l,c=1;if(4!==a&&6!==a&&8!==a)throw new r("invalid aes key size");for(t._key=[o=e.slice(0),l=[]],i=a;4*a+28>i;i++){let e=o[i-1];(i%a==0||8===a&&i%a==4)&&(e=n[e>>>24]<<24^n[e>>16&255]<<16^n[e>>8&255]<<8^n[255&e],i%a==0&&(e=e<<8^e>>>24^c<<24,c=c<<1^283*(c>>7))),o[i]=o[i-a]^e}for(let e=0;i;e++,i--){const t=o[3&e?i:i-4];l[e]=4>=i||4>e?t:s[0][n[t>>>24]]^s[1][n[t>>16&255]]^s[2][n[t>>8&255]]^s[3][n[255&t]]}}encrypt(e){return this._crypt(e,0)}decrypt(e){return this._crypt(e,1)}_precompute(){const e=this._tables[0],t=this._tables[1],n=e[4],s=t[4],r=[],a=[];let i,o,l,c;for(let e=0;256>e;e++)a[(r[e]=e<<1^283*(e>>7))^e]=e;for(let h=i=0;!n[h];h^=o||1,i=a[i]||1){let a=i^i<<1^i<<2^i<<3^i<<4;a=a>>8^255&a^99,n[h]=a,s[a]=h,c=r[l=r[o=r[h]]];let f=16843009*c^65537*l^257*o^16843008*h,u=257*r[a]^16843008*a;for(let n=0;4>n;n++)e[n][h]=u=u<<24^u>>>8,t[n][a]=f=f<<24^f>>>8}for(let n=0;5>n;n++)e[n]=e[n].slice(0),t[n]=t[n].slice(0)}_crypt(e,t){if(4!==e.length)throw new r("invalid aes block size");const n=this._key[t],s=n.length/4-2,a=[0,0,0,0],i=this._tables[t],o=i[0],l=i[1],c=i[2],h=i[3],f=i[4];let u,p,d,g=e[0]^n[0],w=e[t?3:1]^n[1],y=e[2]^n[2],v=e[t?1:3]^n[3],b=4;for(let e=0;s>e;e++)u=o[g>>>24]^l[w>>16&255]^c[y>>8&255]^h[255&v]^n[b],p=o[w>>>24]^l[y>>16&255]^c[v>>8&255]^h[255&g]^n[b+1],d=o[y>>>24]^l[v>>16&255]^c[g>>8&255]^h[255&w]^n[b+2],v=o[v>>>24]^l[g>>16&255]^c[w>>8&255]^h[255&y]^n[b+3],b+=4,g=u,w=p,y=d;for(let e=0;4>e;e++)a[t?3&-e:e]=f[g>>>24]<<24^f[w>>16&255]<<16^f[y>>8&255]<<8^f[255&v]^n[b++],u=g,g=w,w=y,y=v,v=u;return a}},Y=class{constructor(e,t){this._prf=e,this._initIv=t,this._iv=t}reset(){this._iv=this._initIv}update(e){return this.calculate(this._prf,e,this._iv)}incWord(e){if(255&~(e>>24))e+=1<<24;else{let t=e>>16&255,n=e>>8&255,s=255&e;255===t?(t=0,255===n?(n=0,255===s?s=0:++s):++n):++t,e=0,e+=t<<16,e+=n<<8,e+=s}return e}incCounter(e){0===(e[0]=this.incWord(e[0]))&&(e[1]=this.incWord(e[1]))}calculate(e,t,n){let s;if(!(s=t.length))return[];const r=x.bitLength(t);for(let r=0;s>r;r+=4){this.incCounter(n);const s=e.encrypt(n);t[r]^=s[0],t[r+1]^=s[1],t[r+2]^=s[2],t[r+3]^=s[3]}return x.clamp(t,r)}},Z=q.hmacSha1;let $=j&&X&&typeof G.importKey==S,ee=j&&X&&typeof G.deriveBits==S;class te extends g{constructor({password:e,rawPassword:n,signed:s,encryptionStrength:i,checkPasswordOnly:o}){super({start(){t.assign(this,{ready:new f((e=>this.resolveReady=e)),password:ae(e,n),signed:s,strength:i-1,pending:new a})},async transform(e,t){const n=this,{password:s,strength:i,resolveReady:l,ready:c}=n;s?(await(async(e,t,n,s)=>{const a=await re(e,t,n,oe(s,0,N[t])),i=oe(s,N[t]);if(a[0]!=i[0]||a[1]!=i[1])throw new r(H)})(n,i,s,oe(e,0,N[i]+2)),e=oe(e,N[i]+2),o?t.error(new r(B)):l()):await c;const h=new a(e.length-F-(e.length-F)%V);t.enqueue(se(n,e,h,0,F,!0))},async flush(e){const{signed:t,ctr:n,hmac:s,pending:i,ready:o}=this;if(s&&n){await o;const l=oe(i,0,i.length-F),c=oe(i,i.length-F);let h=new a;if(l.length){const e=ce(J,l);s.update(e);const t=n.update(e);h=le(J,t)}if(t){const e=oe(le(J,s.digest()),0,F);for(let t=0;F>t;t++)if(e[t]!=c[t])throw new r(P)}e.enqueue(h)}}})}}class ne extends g{constructor({password:e,rawPassword:n,encryptionStrength:s}){let r;super({start(){t.assign(this,{ready:new f((e=>this.resolveReady=e)),password:ae(e,n),strength:s-1,pending:new a})},async transform(e,t){const n=this,{password:s,strength:r,resolveReady:i,ready:o}=n;let l=new a;s?(l=await(async(e,t,n)=>{const s=K(new a(N[t]));return ie(s,await re(e,t,n,s))})(n,r,s),i()):await o;const c=new a(l.length+e.length-e.length%V);c.set(l,0),t.enqueue(se(n,e,c,l.length,0))},async flush(e){const{ctr:t,hmac:n,pending:s,ready:i}=this;if(n&&t){await i;let o=new a;if(s.length){const e=t.update(ce(J,s));n.update(e),o=le(J,e)}r.signature=le(J,n.digest()).slice(0,F),e.enqueue(ie(o,r.signature))}}}),r=this}}function se(e,t,n,s,r,i){const{ctr:o,hmac:l,pending:c}=e,h=t.length-r;let f;for(c.length&&(t=ie(c,t),n=((e,t)=>{if(t&&t>e.length){const n=e;(e=new a(t)).set(n,0)}return e})(n,h-h%V)),f=0;h-V>=f;f+=V){const e=ce(J,oe(t,f,f+V));i&&l.update(e);const r=o.update(e);i||l.update(r),n.set(le(J,r),f+s)}return e.pending=oe(t,f),n}async function re(n,s,r,i){n.password=null;const o=await(async(e,t,n,s,r)=>{if(!$)return q.importKey(t);try{return await G.importKey("raw",t,n,!1,r)}catch(e){return $=!1,q.importKey(t)}})(0,r,U,0,M),l=await(async(e,t,n)=>{if(!ee)return q.pbkdf2(t,e.salt,W.iterations,n);try{return await G.deriveBits(e,t,n)}catch(s){return ee=!1,q.pbkdf2(t,e.salt,W.iterations,n)}})(t.assign({salt:i},W),o,8*(2*O[s]+2)),c=new a(l),h=ce(J,oe(c,0,O[s])),f=ce(J,oe(c,O[s],2*O[s])),u=oe(c,2*O[s]);return t.assign(n,{keys:{key:h,authentication:f,passwordVerification:u},ctr:new Y(new Q(h),e.from(L)),hmac:new Z(f)}),u}function ae(e,t){return t===m?(e=>{if(typeof u==_){const t=new a((e=unescape(encodeURIComponent(e))).length);for(let n=0;n<t.length;n++)t[n]=e.charCodeAt(n);return t}return(new u).encode(e)})(e):t}function ie(e,t){let n=e;return e.length+t.length&&(n=new a(e.length+t.length),n.set(e,0),n.set(t,e.length)),n}function oe(e,t,n){return e.subarray(t,n)}function le(e,t){return e.fromBits(t)}function ce(e,t){return e.toBits(t)}class he extends g{constructor({password:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){t.assign(this,{password:e,passwordVerification:n}),de(this,e)},transform(e,t){const n=this;if(n.password){const t=ue(n,e.subarray(0,12));if(n.password=null,t[11]!=n.passwordVerification)throw new r(H);e=e.subarray(12)}s?t.error(new r(B)):t.enqueue(ue(n,e))}})}}class fe extends g{constructor({password:e,passwordVerification:n}){super({start(){t.assign(this,{password:e,passwordVerification:n}),de(this,e)},transform(e,t){const n=this;let s,r;if(n.password){n.password=null;const t=K(new a(12));t[11]=n.passwordVerification,s=new a(e.length+t.length),s.set(pe(n,t),0),r=12}else s=new a(e.length),r=0;s.set(pe(n,e),r),t.enqueue(s)}})}}function ue(e,t){const n=new a(t.length);for(let s=0;s<t.length;s++)n[s]=we(e)^t[s],ge(e,n[s]);return n}function pe(e,t){const n=new a(t.length);for(let s=0;s<t.length;s++)n[s]=we(e)^t[s],ge(e,t[s]);return n}function de(e,n){const s=[305419896,591751049,878082192];t.assign(e,{keys:s,crcKey0:new D(s[0]),crcKey2:new D(s[2])});for(let t=0;t<n.length;t++)ge(e,n.charCodeAt(t))}function ge(e,t){let[n,r,a]=e.keys;e.crcKey0.append([t]),n=~e.crcKey0.get(),r=ve(s.imul(ve(r+ye(n)),134775813)+1),e.crcKey2.append([r>>>24]),a=~e.crcKey2.get(),e.keys=[n,r,a]}function we(e){const t=2|e.keys[2];return ye(s.imul(t,1^t)>>>8)}function ye(e){return 255&e}function ve(e){return 4294967295&e}const be="deflate-raw";class me extends g{constructor(e,{chunkSize:t,CompressionStream:n,CompressionStreamNative:s}){super({});const{compressed:r,encrypted:a,useCompressionStream:i,zipCrypto:o,signed:l,level:c}=e,f=this;let u,p,d=Se(super.readable);a&&!o||!l||(u=new C,d=De(d,u)),r&&(d=ze(d,i,{level:c,chunkSize:t},s,n)),a&&(o?d=De(d,new fe(e)):(p=new ne(e),d=De(d,p))),ke(f,d,(()=>{let e;a&&!o&&(e=p.signature),a&&!o||!l||(e=new h(u.value.buffer).getUint32(0)),f.signature=e}))}}class _e extends g{constructor(e,{chunkSize:t,DecompressionStream:n,DecompressionStreamNative:s}){super({});const{zipCrypto:a,encrypted:i,signed:o,signature:l,compressed:c,useCompressionStream:f}=e;let u,p,d=Se(super.readable);i&&(a?d=De(d,new he(e)):(p=new te(e),d=De(d,p))),c&&(d=ze(d,f,{chunkSize:t},s,n)),i&&!a||!o||(u=new C,d=De(d,u)),ke(this,d,(()=>{if((!i||a)&&o){const e=new h(u.value.buffer);if(l!=e.getUint32(0,!1))throw new r(P)}}))}}function Se(e){return De(e,new g({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function ke(e,n,s){n=De(n,new g({flush:s})),t.defineProperty(e,"readable",{get:()=>n})}function ze(e,t,n,s,r){try{e=De(e,new(t&&s?s:r)(be,n))}catch(s){if(!t)return e;try{e=De(e,new r(be,n))}catch(t){return e}}return e}function De(e,t){return e.pipeThrough(t)}const Ce="data",xe="close";class Ie extends g{constructor(e,n){super({});const s=this,{codecType:r}=e;let a;r.startsWith("deflate")?a=me:r.startsWith("inflate")&&(a=_e);let i=0,o=0;const l=new a(e,n),c=super.readable,h=new g({transform(e,t){e&&e.length&&(o+=e.length,t.enqueue(e))},flush(){t.assign(s,{inputSize:o})}}),f=new g({transform(e,t){e&&e.length&&(i+=e.length,t.enqueue(e))},flush(){const{signature:e}=l;t.assign(s,{signature:e,outputSize:i,inputSize:o})}});t.defineProperty(s,"readable",{get:()=>c.pipeThrough(h).pipeThrough(l).pipeThrough(f)})}}class Te extends g{constructor(e){let t;super({transform:function n(s,r){if(t){const e=new a(t.length+s.length);e.set(t),e.set(s,t.length),s=e,t=null}s.length>e?(r.enqueue(s.slice(0,e)),n(s.slice(e),r)):t=s},flush(e){t&&t.length&&e.enqueue(t)}})}}const Ae=new c,qe=new c;let Re,He=0,Pe=!0;async function Be(e){try{const{options:t,scripts:s,config:r}=e;if(s&&s.length)try{Pe?importScripts.apply(m,s):await Ke(s)}catch(e){Pe=!1,await Ke(s)}self.initCodec&&self.initCodec(),r.CompressionStreamNative=self.CompressionStream,r.DecompressionStreamNative=self.DecompressionStream,self.Deflate&&(r.CompressionStream=new k(self.Deflate)),self.Inflate&&(r.DecompressionStream=new k(self.Inflate));const a={highWaterMark:1},i=e.readable||new w({async pull(e){const t=new f((e=>Ae.set(He,e)));Ve({type:"pull",messageId:He}),He=(He+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await t;e.enqueue(s),r&&e.close()}},a),o=e.writable||new y({async write(e){let t;const s=new f((e=>t=e));qe.set(He,t),Ve({type:Ce,value:e,messageId:He}),He=(He+1)%n.MAX_SAFE_INTEGER,await s}},a),l=new Ie(t,r);Re=new AbortController;const{signal:c}=Re;await i.pipeThrough(l).pipeThrough(new Te(r.chunkSize)).pipeTo(o,{signal:c,preventClose:!0,preventAbort:!0}),await o.getWriter().close();const{signature:h,inputSize:u,outputSize:p}=l;Ve({type:xe,result:{signature:h,inputSize:u,outputSize:p}})}catch(e){Ee(e)}}async function Ke(e){for(const t of e)await import(t)}function Ve(e){let{value:t}=e;if(t)if(t.length)try{t=new a(t),e.value=t.buffer,d(e,[e.value])}catch(t){d(e)}else d(e);else d(e)}function Ee(e=new r("Unknown error")){const{message:t,stack:n,code:s,name:a}=e;d({error:{message:t,stack:n,code:s,name:a}})}addEventListener("message",(({data:e})=>{const{type:t,messageId:n,value:s,done:r}=e;try{if("start"==t&&Be(e),t==Ce){const e=Ae.get(n);Ae.delete(n),e({value:new a(s),done:r})}if("ack"==t){const e=qe.get(n);qe.delete(n),e()}t==xe&&Re.abort()}catch(e){Ee(e)}}));var Ue=a,We=i,Me=l,Ne=new Ue([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Oe=new Ue([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Fe=new Ue([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Le=(e,t)=>{for(var n=new We(31),s=0;31>s;++s)n[s]=t+=1<<e[s-1];var r=new Me(n[30]);for(s=1;30>s;++s)for(var a=n[s];a<n[s+1];++a)r[a]=a-n[s]<<5|s;return{b:n,r:r}},je=Le(Ne,2),Ge=je.b,Xe=je.r;Ge[28]=258,Xe[258]=28;for(var Je=Le(Oe,0),Qe=Je.b,Ye=Je.r,Ze=new We(32768),$e=0;32768>$e;++$e){var et=(43690&$e)>>1|(21845&$e)<<1;et=(61680&(et=(52428&et)>>2|(13107&et)<<2))>>4|(3855&et)<<4,Ze[$e]=((65280&et)>>8|(255&et)<<8)>>1}var tt=(e,t,n)=>{for(var s=e.length,r=0,a=new We(t);s>r;++r)e[r]&&++a[e[r]-1];var i,o=new We(t);for(r=1;t>r;++r)o[r]=o[r-1]+a[r-1]<<1;if(n){i=new We(1<<t);var l=15-t;for(r=0;s>r;++r)if(e[r])for(var c=r<<4|e[r],h=t-e[r],f=o[e[r]-1]++<<h,u=f|(1<<h)-1;u>=f;++f)i[Ze[f]>>l]=c}else for(i=new We(s),r=0;s>r;++r)e[r]&&(i[r]=Ze[o[e[r]-1]++]>>15-e[r]);return i},nt=new Ue(288);for($e=0;144>$e;++$e)nt[$e]=8;for($e=144;256>$e;++$e)nt[$e]=9;for($e=256;280>$e;++$e)nt[$e]=7;for($e=280;288>$e;++$e)nt[$e]=8;var st=new Ue(32);for($e=0;32>$e;++$e)st[$e]=5;var rt=tt(nt,9,0),at=tt(nt,9,1),it=tt(st,5,0),ot=tt(st,5,1),lt=e=>{for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},ct=(e,t,n)=>{var s=t/8|0;return(e[s]|e[s+1]<<8)>>(7&t)&n},ht=(e,t)=>{var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},ft=e=>(e+7)/8|0,ut=(e,t,n)=>((null==t||0>t)&&(t=0),(null==n||n>e.length)&&(n=e.length),new Ue(e.subarray(t,n))),pt=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],dt=(e,t,n)=>{var s=new r(t||pt[e]);if(s.code=e,r.captureStackTrace&&r.captureStackTrace(s,dt),!n)throw s;return s},gt=(e,t,n)=>{n<<=7&t;var s=t/8|0;e[s]|=n,e[s+1]|=n>>8},wt=(e,t,n)=>{n<<=7&t;var s=t/8|0;e[s]|=n,e[s+1]|=n>>8,e[s+2]|=n>>16},yt=(e,t)=>{for(var n=[],s=0;s<e.length;++s)e[s]&&n.push({s:s,f:e[s]});var r=n.length,a=n.slice();if(!r)return{t:zt,l:0};if(1==r){var i=new Ue(n[0].s+1);return i[n[0].s]=1,{t:i,l:1}}n.sort(((e,t)=>e.f-t.f)),n.push({s:-1,f:25001});var o=n[0],l=n[1],c=0,h=1,f=2;for(n[0]={s:-1,f:o.f+l.f,l:o,r:l};h!=r-1;)o=n[n[c].f<n[f].f?c++:f++],l=n[c!=h&&n[c].f<n[f].f?c++:f++],n[h++]={s:-1,f:o.f+l.f,l:o,r:l};var u=a[0].s;for(s=1;r>s;++s)a[s].s>u&&(u=a[s].s);var p=new We(u+1),d=vt(n[h-1],p,0);if(d>t){s=0;var g=0,w=d-t,y=1<<w;for(a.sort(((e,t)=>p[t.s]-p[e.s]||e.f-t.f));r>s;++s){var v=a[s].s;if(p[v]<=t)break;g+=y-(1<<d-p[v]),p[v]=t}for(g>>=w;g>0;){var b=a[s].s;p[b]<t?g-=1<<t-p[b]++-1:++s}for(;s>=0&&g;--s){var m=a[s].s;p[m]==t&&(--p[m],++g)}d=t}return{t:new Ue(p),l:d}},vt=(e,t,n)=>-1==e.s?s.max(vt(e.l,t,n+1),vt(e.r,t,n+1)):t[e.s]=n,bt=e=>{for(var t=e.length;t&&!e[--t];);for(var n=new We(++t),s=0,r=e[0],a=1,i=e=>{n[s++]=e},o=1;t>=o;++o)if(e[o]==r&&o!=t)++a;else{if(!r&&a>2){for(;a>138;a-=138)i(32754);a>2&&(i(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(i(r),--a;a>6;a-=6)i(8304);a>2&&(i(a-3<<5|8208),a=0)}for(;a--;)i(r);a=1,r=e[o]}return{c:n.subarray(0,s),n:t}},mt=(e,t)=>{for(var n=0,s=0;s<t.length;++s)n+=e[s]*t[s];return n},_t=(e,t,n)=>{var s=n.length,r=ft(t+2);e[r]=255&s,e[r+1]=s>>8,e[r+2]=255^e[r],e[r+3]=255^e[r+1];for(var a=0;s>a;++a)e[r+a+4]=n[a];return 8*(r+4+s)},St=(e,t,n,s,r,a,i,o,l,c,h)=>{gt(t,h++,n),++r[256];for(var f=yt(r,15),u=f.t,p=f.l,d=yt(a,15),g=d.t,w=d.l,y=bt(u),v=y.c,b=y.n,m=bt(g),_=m.c,S=m.n,k=new We(19),z=0;z<v.length;++z)++k[31&v[z]];for(z=0;z<_.length;++z)++k[31&_[z]];for(var D=yt(k,7),C=D.t,x=D.l,I=19;I>4&&!C[Fe[I-1]];--I);var T,A,q,R,H=c+5<<3,P=mt(r,nt)+mt(a,st)+i,B=mt(r,u)+mt(a,g)+i+14+3*I+mt(k,C)+2*k[16]+3*k[17]+7*k[18];if(l>=0&&P>=H&&B>=H)return _t(t,h,e.subarray(l,l+c));if(gt(t,h,1+(P>B)),h+=2,P>B){T=tt(u,p,0),A=u,q=tt(g,w,0),R=g;var K=tt(C,x,0);for(gt(t,h,b-257),gt(t,h+5,S-1),gt(t,h+10,I-4),h+=14,z=0;I>z;++z)gt(t,h+3*z,C[Fe[z]]);h+=3*I;for(var V=[v,_],E=0;2>E;++E){var U=V[E];for(z=0;z<U.length;++z){var W=31&U[z];gt(t,h,K[W]),h+=C[W],W>15&&(gt(t,h,U[z]>>5&127),h+=U[z]>>12)}}}else T=rt,A=nt,q=it,R=st;for(z=0;o>z;++z){var M=s[z];if(M>255){wt(t,h,T[257+(W=M>>18&31)]),h+=A[W+257],W>7&&(gt(t,h,M>>23&31),h+=Ne[W]);var N=31&M;wt(t,h,q[N]),h+=R[N],N>3&&(wt(t,h,M>>5&8191),h+=Oe[N])}else wt(t,h,T[M]),h+=A[M]}return wt(t,h,T[256]),h+A[256]},kt=new Me([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),zt=new Ue(0),Dt=function(){function e(e,t){if("function"==typeof e&&(t=e,e={}),this.ondata=t,this.o=e||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new Ue(98304),this.o.dictionary){var n=this.o.dictionary.subarray(-32768);this.b.set(n,32768-n.length),this.s.i=32768-n.length}}return e.prototype.p=function(e,t){this.ondata(((e,t,n,r,a)=>{if(!a&&(a={l:1},t.dictionary)){var i=t.dictionary.subarray(-32768),o=new Ue(i.length+e.length);o.set(i),o.set(e,i.length),e=o,a.w=i.length}return((e,t,n,r,a,i)=>{var o=i.z||e.length,l=new Ue(0+o+5*(1+s.ceil(o/7e3))+0),c=l.subarray(0,l.length-0),h=i.l,f=7&(i.r||0);if(t){f&&(c[0]=i.r>>3);for(var u=kt[t-1],p=u>>13,d=8191&u,g=(1<<n)-1,w=i.p||new We(32768),y=i.h||new We(g+1),v=s.ceil(n/3),b=2*v,m=t=>(e[t]^e[t+1]<<v^e[t+2]<<b)&g,_=new Me(25e3),S=new We(288),k=new We(32),z=0,D=0,C=i.i||0,x=0,I=i.w||0,T=0;o>C+2;++C){var A=m(C),q=32767&C,R=y[A];if(w[q]=R,y[A]=q,C>=I){var H=o-C;if((z>7e3||x>24576)&&(H>423||!h)){f=St(e,c,0,_,S,k,D,x,T,C-T,f),x=z=D=0,T=C;for(var P=0;286>P;++P)S[P]=0;for(P=0;30>P;++P)k[P]=0}var B=2,K=0,V=d,E=q-R&32767;if(H>2&&A==m(C-E))for(var U=s.min(p,H)-1,W=s.min(32767,C),M=s.min(258,H);W>=E&&--V&&q!=R;){if(e[C+B]==e[C+B-E]){for(var N=0;M>N&&e[C+N]==e[C+N-E];++N);if(N>B){if(B=N,K=E,N>U)break;var O=s.min(E,N-2),F=0;for(P=0;O>P;++P){var L=C-E+P&32767,j=L-w[L]&32767;j>F&&(F=j,R=L)}}}E+=(q=R)-(R=w[q])&32767}if(K){_[x++]=268435456|Xe[B]<<18|Ye[K];var G=31&Xe[B],X=31&Ye[K];D+=Ne[G]+Oe[X],++S[257+G],++k[X],I=C+B,++z}else _[x++]=e[C],++S[e[C]]}}for(C=s.max(C,I);o>C;++C)_[x++]=e[C],++S[e[C]];f=St(e,c,h,_,S,k,D,x,T,C-T,f),h||(i.r=7&f|c[f/8|0]<<3,f-=7,i.h=y,i.p=w,i.i=C,i.w=I)}else{for(C=i.w||0;o+h>C;C+=65535){var J=C+65535;o>J||(c[f/8|0]=h,J=o),f=_t(c,f+1,e.subarray(C,J))}i.i=o}return ut(l,0,0+ft(f)+0)})(e,null==t.level?6:t.level,null==t.mem?a.l?s.ceil(1.5*s.max(8,s.min(13,s.log(e.length)))):20:12+t.mem,0,0,a)})(e,this.o,0,0,this.s),t)},e.prototype.push=function(e,t){this.ondata||dt(5),this.s.l&&dt(4);var n=e.length+this.s.z;if(n>this.b.length){if(n>2*this.b.length-32768){var s=new Ue(-32768&n);s.set(this.b.subarray(0,this.s.z)),this.b=s}var r=this.b.length-this.s.z;this.b.set(e.subarray(0,r),this.s.z),this.s.z=this.b.length,this.p(this.b,!1),this.b.set(this.b.subarray(-32768)),this.b.set(e.subarray(r),32768),this.s.z=e.length-r+32768,this.s.i=32766,this.s.w=32768}else this.b.set(e,this.s.z),this.s.z+=e.length;this.s.l=1&t,(this.s.z>this.s.w+8191||t)&&(this.p(this.b,t||!1),this.s.w=this.s.i,this.s.i-=2)},e.prototype.flush=function(){this.ondata||dt(5),this.s.l&&dt(4),this.p(this.b,!1),this.s.w=this.s.i,this.s.i-=2},e}(),Ct=function(){function e(e,t){"function"==typeof e&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new Ue(32768),this.p=new Ue(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||dt(5),this.d&&dt(4),this.p.length){if(e.length){var t=new Ue(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}}else this.p=e},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=((e,t,n)=>{var r=e.length;if(!r||t.f&&!t.l)return n||new Ue(0);var a=!n,i=a||2!=t.i,o=t.i;a&&(n=new Ue(3*r));var l=e=>{var t=n.length;if(e>t){var r=new Ue(s.max(2*t,e));r.set(n),n=r}},c=t.f||0,h=t.p||0,f=t.b||0,u=t.l,p=t.d,d=t.m,g=t.n,w=8*r;do{if(!u){c=ct(e,h,1);var y=ct(e,h+1,3);if(h+=3,!y){var v=e[(T=ft(h)+4)-4]|e[T-3]<<8,b=T+v;if(b>r){o&&dt(0);break}i&&l(f+v),n.set(e.subarray(T,b),f),t.b=f+=v,t.p=h=8*b,t.f=c;continue}if(1==y)u=at,p=ot,d=9,g=5;else if(2==y){var m=ct(e,h,31)+257,_=ct(e,h+10,15)+4,S=m+ct(e,h+5,31)+1;h+=14;for(var k=new Ue(S),z=new Ue(19),D=0;_>D;++D)z[Fe[D]]=ct(e,h+3*D,7);h+=3*_;var C=lt(z),x=(1<<C)-1,I=tt(z,C,1);for(D=0;S>D;){var T,A=I[ct(e,h,x)];if(h+=15&A,16>(T=A>>4))k[D++]=T;else{var q=0,R=0;for(16==T?(R=3+ct(e,h,3),h+=2,q=k[D-1]):17==T?(R=3+ct(e,h,7),h+=3):18==T&&(R=11+ct(e,h,127),h+=7);R--;)k[D++]=q}}var H=k.subarray(0,m),P=k.subarray(m);d=lt(H),g=lt(P),u=tt(H,d,1),p=tt(P,g,1)}else dt(1);if(h>w){o&&dt(0);break}}i&&l(f+131072);for(var B=(1<<d)-1,K=(1<<g)-1,V=h;;V=h){var E=(q=u[ht(e,h)&B])>>4;if((h+=15&q)>w){o&&dt(0);break}if(q||dt(2),256>E)n[f++]=E;else{if(256==E){V=h,u=null;break}var U=E-254;if(E>264){var W=Ne[D=E-257];U=ct(e,h,(1<<W)-1)+Ge[D],h+=W}var M=p[ht(e,h)&K],N=M>>4;if(M||dt(3),h+=15&M,P=Qe[N],N>3&&(W=Oe[N],P+=ht(e,h)&(1<<W)-1,h+=W),h>w){o&&dt(0);break}i&&l(f+131072);var O=f+U;if(P>f){var F=0-P,L=s.min(P,O);for(0>F+f&&dt(3);L>f;++f)n[f]=(void 0)[F+f]}for(;O>f;++f)n[f]=n[f-P]}}t.l=u,t.p=V,t.b=f,t.f=c,u&&(c=1,t.m=d,t.d=p,t.n=g)}while(!c);return f!=n.length&&a?ut(n,0,f):n.subarray(0,f)})(this.p,this.s,this.o);this.ondata(ut(n,t,this.s.b),this.d),this.o=ut(n,this.s.b-32768),this.s.b=this.o.length,this.p=ut(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),xt="undefined"!=typeof TextDecoder&&new TextDecoder;try{xt.decode(zt,{stream:!0})}catch(e){}function It(e,n,s){return class{constructor(r){const i=this;var o,l;o=r,l="level",(typeof t.hasOwn===S?t.hasOwn(o,l):o.hasOwnProperty(l))&&r.level===m&&delete r.level,i.codec=new e(t.assign({},n,r)),s(i.codec,(e=>{if(i.pendingData){const t=i.pendingData;i.pendingData=new a(t.length+e.length);const{pendingData:n}=i;n.set(t,0),n.set(e,t.length)}else i.pendingData=new a(e)}))}append(e){return this.codec.push(e),r(this)}flush(){return this.codec.push(new a,!0),r(this)}};function r(e){if(e.pendingData){const t=e.pendingData;return e.pendingData=null,t}return new a}}const{Deflate:Tt,Inflate:At}=((e,t={},n)=>({Deflate:It(e.Deflate,t.deflate,n),Inflate:It(e.Inflate,t.inflate,n)}))({Deflate:Dt,Inflate:Ct},m,((e,t)=>e.ondata=t));self.initCodec=()=>{self.Deflate=Tt,self.Inflate=At};\n'],{type:"text/javascript"}));e({workerScripts:{inflate:[t],deflate:[t]}});}
|
|
242
244
|
|
|
243
245
|
/*
|
|
244
246
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -268,6 +270,7 @@ function e(e){const t=()=>URL.createObjectURL(new Blob(['const{Array:e,Object:t,
|
|
|
268
270
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
269
271
|
*/
|
|
270
272
|
|
|
273
|
+
|
|
271
274
|
function getMimeType() {
|
|
272
275
|
return "application/octet-stream";
|
|
273
276
|
}
|
|
@@ -281,7 +284,7 @@ function initShimAsyncCodec(library, options = {}, registerDataHandler) {
|
|
|
281
284
|
|
|
282
285
|
function objectHasOwn(object, propertyName) {
|
|
283
286
|
// eslint-disable-next-line no-prototype-builtins
|
|
284
|
-
return typeof Object.hasOwn ===
|
|
287
|
+
return typeof Object.hasOwn === FUNCTION_TYPE ? Object.hasOwn(object, propertyName) : object.hasOwnProperty(propertyName);
|
|
285
288
|
}
|
|
286
289
|
|
|
287
290
|
function createCodecClass(constructor, constructorOptions, registerDataHandler) {
|
|
@@ -300,7 +303,7 @@ function createCodecClass(constructor, constructorOptions, registerDataHandler)
|
|
|
300
303
|
codecAdapter.pendingData = new Uint8Array(data);
|
|
301
304
|
}
|
|
302
305
|
};
|
|
303
|
-
if (objectHasOwn(options, "level") && options.level ===
|
|
306
|
+
if (objectHasOwn(options, "level") && options.level === UNDEFINED_VALUE) {
|
|
304
307
|
delete options.level;
|
|
305
308
|
}
|
|
306
309
|
codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
|
|
@@ -415,6 +418,7 @@ class Crc32 {
|
|
|
415
418
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
416
419
|
*/
|
|
417
420
|
|
|
421
|
+
|
|
418
422
|
class Crc32Stream extends TransformStream {
|
|
419
423
|
|
|
420
424
|
constructor() {
|
|
@@ -464,8 +468,9 @@ class Crc32Stream extends TransformStream {
|
|
|
464
468
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
465
469
|
*/
|
|
466
470
|
|
|
471
|
+
|
|
467
472
|
function encodeText(value) {
|
|
468
|
-
if (typeof TextEncoder ==
|
|
473
|
+
if (typeof TextEncoder == UNDEFINED_TYPE) {
|
|
469
474
|
value = unescape(encodeURIComponent(value));
|
|
470
475
|
const result = new Uint8Array(value.length);
|
|
471
476
|
for (let i = 0; i < result.length; i++) {
|
|
@@ -1325,7 +1330,8 @@ misc.hmacSha1 = class {
|
|
|
1325
1330
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1326
1331
|
*/
|
|
1327
1332
|
|
|
1328
|
-
|
|
1333
|
+
|
|
1334
|
+
const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != UNDEFINED_TYPE && typeof crypto.getRandomValues == FUNCTION_TYPE;
|
|
1329
1335
|
|
|
1330
1336
|
const ERR_INVALID_PASSWORD = "Invalid password";
|
|
1331
1337
|
const ERR_INVALID_SIGNATURE = "Invalid signature";
|
|
@@ -1367,6 +1373,7 @@ function getRandomValues(array) {
|
|
|
1367
1373
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1368
1374
|
*/
|
|
1369
1375
|
|
|
1376
|
+
|
|
1370
1377
|
const BLOCK_LENGTH = 16;
|
|
1371
1378
|
const RAW_FORMAT = "raw";
|
|
1372
1379
|
const PBKDF2_ALGORITHM = { name: "PBKDF2" };
|
|
@@ -1379,8 +1386,6 @@ const SALT_LENGTH = [8, 12, 16];
|
|
|
1379
1386
|
const KEY_LENGTH = [16, 24, 32];
|
|
1380
1387
|
const SIGNATURE_LENGTH = 10;
|
|
1381
1388
|
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
1382
|
-
const UNDEFINED_TYPE = "undefined";
|
|
1383
|
-
const FUNCTION_TYPE = "function";
|
|
1384
1389
|
// deno-lint-ignore valid-typeof
|
|
1385
1390
|
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
|
|
1386
1391
|
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
@@ -1395,12 +1400,12 @@ let DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && type
|
|
|
1395
1400
|
|
|
1396
1401
|
class AESDecryptionStream extends TransformStream {
|
|
1397
1402
|
|
|
1398
|
-
constructor({ password, signed, encryptionStrength, checkPasswordOnly }) {
|
|
1403
|
+
constructor({ password, rawPassword, signed, encryptionStrength, checkPasswordOnly }) {
|
|
1399
1404
|
super({
|
|
1400
1405
|
start() {
|
|
1401
1406
|
Object.assign(this, {
|
|
1402
1407
|
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
1403
|
-
password,
|
|
1408
|
+
password: encodePassword(password, rawPassword),
|
|
1404
1409
|
signed,
|
|
1405
1410
|
strength: encryptionStrength - 1,
|
|
1406
1411
|
pending: new Uint8Array()
|
|
@@ -1464,14 +1469,14 @@ class AESDecryptionStream extends TransformStream {
|
|
|
1464
1469
|
|
|
1465
1470
|
class AESEncryptionStream extends TransformStream {
|
|
1466
1471
|
|
|
1467
|
-
constructor({ password, encryptionStrength }) {
|
|
1472
|
+
constructor({ password, rawPassword, encryptionStrength }) {
|
|
1468
1473
|
// deno-lint-ignore prefer-const
|
|
1469
1474
|
let stream;
|
|
1470
1475
|
super({
|
|
1471
1476
|
start() {
|
|
1472
1477
|
Object.assign(this, {
|
|
1473
1478
|
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
1474
|
-
password,
|
|
1479
|
+
password: encodePassword(password, rawPassword),
|
|
1475
1480
|
strength: encryptionStrength - 1,
|
|
1476
1481
|
pending: new Uint8Array()
|
|
1477
1482
|
});
|
|
@@ -1562,8 +1567,7 @@ async function createEncryptionKeys(encrypt, strength, password) {
|
|
|
1562
1567
|
|
|
1563
1568
|
async function createKeys$1(aesCrypto, strength, password, salt) {
|
|
1564
1569
|
aesCrypto.password = null;
|
|
1565
|
-
const
|
|
1566
|
-
const baseKey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
|
|
1570
|
+
const baseKey = await importKey(RAW_FORMAT, password, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
|
|
1567
1571
|
const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), baseKey, 8 * ((KEY_LENGTH[strength] * 2) + 2));
|
|
1568
1572
|
const compositeKey = new Uint8Array(derivedBits);
|
|
1569
1573
|
const key = toBits(codecBytes, subarray(compositeKey, 0, KEY_LENGTH[strength]));
|
|
@@ -1607,6 +1611,14 @@ async function deriveBits(algorithm, baseKey, length) {
|
|
|
1607
1611
|
}
|
|
1608
1612
|
}
|
|
1609
1613
|
|
|
1614
|
+
function encodePassword(password, rawPassword) {
|
|
1615
|
+
if (rawPassword === UNDEFINED_VALUE) {
|
|
1616
|
+
return encodeText(password);
|
|
1617
|
+
} else {
|
|
1618
|
+
return rawPassword;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1610
1622
|
function concat(leftArray, rightArray) {
|
|
1611
1623
|
let array = leftArray;
|
|
1612
1624
|
if (leftArray.length + rightArray.length) {
|
|
@@ -1665,6 +1677,7 @@ function toBits(codecBytes, chunk) {
|
|
|
1665
1677
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1666
1678
|
*/
|
|
1667
1679
|
|
|
1680
|
+
|
|
1668
1681
|
const HEADER_LENGTH = 12;
|
|
1669
1682
|
|
|
1670
1683
|
class ZipCryptoDecryptionStream extends TransformStream {
|
|
@@ -1812,6 +1825,7 @@ function getInt32(number) {
|
|
|
1812
1825
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1813
1826
|
*/
|
|
1814
1827
|
|
|
1828
|
+
|
|
1815
1829
|
const COMPRESSION_FORMAT = "deflate-raw";
|
|
1816
1830
|
|
|
1817
1831
|
class DeflateStream extends TransformStream {
|
|
@@ -1908,9 +1922,13 @@ function pipeThroughCommpressionStream(readable, useCompressionStream, options,
|
|
|
1908
1922
|
readable = pipeThrough(readable, new CompressionStream(COMPRESSION_FORMAT, options));
|
|
1909
1923
|
} catch (error) {
|
|
1910
1924
|
if (useCompressionStream) {
|
|
1911
|
-
|
|
1925
|
+
try {
|
|
1926
|
+
readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
|
|
1927
|
+
} catch (error) {
|
|
1928
|
+
return readable;
|
|
1929
|
+
}
|
|
1912
1930
|
} else {
|
|
1913
|
-
|
|
1931
|
+
return readable;
|
|
1914
1932
|
}
|
|
1915
1933
|
}
|
|
1916
1934
|
return readable;
|
|
@@ -1948,6 +1966,7 @@ function pipeThrough(readable, transformStream) {
|
|
|
1948
1966
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1949
1967
|
*/
|
|
1950
1968
|
|
|
1969
|
+
|
|
1951
1970
|
const MESSAGE_EVENT_TYPE = "message";
|
|
1952
1971
|
const MESSAGE_START = "start";
|
|
1953
1972
|
const MESSAGE_PULL = "pull";
|
|
@@ -1969,13 +1988,27 @@ class CodecStream extends TransformStream {
|
|
|
1969
1988
|
} else if (codecType.startsWith(CODEC_INFLATE)) {
|
|
1970
1989
|
Stream = InflateStream;
|
|
1971
1990
|
}
|
|
1972
|
-
let
|
|
1991
|
+
let outputSize = 0;
|
|
1992
|
+
let inputSize = 0;
|
|
1973
1993
|
const stream = new Stream(options, config);
|
|
1974
1994
|
const readable = super.readable;
|
|
1975
|
-
const
|
|
1995
|
+
const inputSizeStream = new TransformStream({
|
|
1976
1996
|
transform(chunk, controller) {
|
|
1977
1997
|
if (chunk && chunk.length) {
|
|
1978
|
-
|
|
1998
|
+
inputSize += chunk.length;
|
|
1999
|
+
controller.enqueue(chunk);
|
|
2000
|
+
}
|
|
2001
|
+
},
|
|
2002
|
+
flush() {
|
|
2003
|
+
Object.assign(codec, {
|
|
2004
|
+
inputSize
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
const outputSizeStream = new TransformStream({
|
|
2009
|
+
transform(chunk, controller) {
|
|
2010
|
+
if (chunk && chunk.length) {
|
|
2011
|
+
outputSize += chunk.length;
|
|
1979
2012
|
controller.enqueue(chunk);
|
|
1980
2013
|
}
|
|
1981
2014
|
},
|
|
@@ -1983,18 +2016,50 @@ class CodecStream extends TransformStream {
|
|
|
1983
2016
|
const { signature } = stream;
|
|
1984
2017
|
Object.assign(codec, {
|
|
1985
2018
|
signature,
|
|
1986
|
-
|
|
2019
|
+
outputSize,
|
|
2020
|
+
inputSize
|
|
1987
2021
|
});
|
|
1988
2022
|
}
|
|
1989
2023
|
});
|
|
1990
2024
|
Object.defineProperty(codec, "readable", {
|
|
1991
2025
|
get() {
|
|
1992
|
-
return readable.pipeThrough(stream).pipeThrough(
|
|
2026
|
+
return readable.pipeThrough(inputSizeStream).pipeThrough(stream).pipeThrough(outputSizeStream);
|
|
1993
2027
|
}
|
|
1994
2028
|
});
|
|
1995
2029
|
}
|
|
1996
2030
|
}
|
|
1997
2031
|
|
|
2032
|
+
class ChunkStream extends TransformStream {
|
|
2033
|
+
|
|
2034
|
+
constructor(chunkSize) {
|
|
2035
|
+
let pendingChunk;
|
|
2036
|
+
super({
|
|
2037
|
+
transform,
|
|
2038
|
+
flush(controller) {
|
|
2039
|
+
if (pendingChunk && pendingChunk.length) {
|
|
2040
|
+
controller.enqueue(pendingChunk);
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
});
|
|
2044
|
+
|
|
2045
|
+
function transform(chunk, controller) {
|
|
2046
|
+
if (pendingChunk) {
|
|
2047
|
+
const newChunk = new Uint8Array(pendingChunk.length + chunk.length);
|
|
2048
|
+
newChunk.set(pendingChunk);
|
|
2049
|
+
newChunk.set(chunk, pendingChunk.length);
|
|
2050
|
+
chunk = newChunk;
|
|
2051
|
+
pendingChunk = null;
|
|
2052
|
+
}
|
|
2053
|
+
if (chunk.length > chunkSize) {
|
|
2054
|
+
controller.enqueue(chunk.slice(0, chunkSize));
|
|
2055
|
+
transform(chunk.slice(chunkSize), controller);
|
|
2056
|
+
} else {
|
|
2057
|
+
pendingChunk = chunk;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
|
|
1998
2063
|
/*
|
|
1999
2064
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
2000
2065
|
|
|
@@ -2023,8 +2088,9 @@ class CodecStream extends TransformStream {
|
|
|
2023
2088
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2024
2089
|
*/
|
|
2025
2090
|
|
|
2091
|
+
|
|
2026
2092
|
// deno-lint-ignore valid-typeof
|
|
2027
|
-
|
|
2093
|
+
let WEB_WORKERS_SUPPORTED = typeof Worker != UNDEFINED_TYPE;
|
|
2028
2094
|
|
|
2029
2095
|
class CodecWorker {
|
|
2030
2096
|
|
|
@@ -2032,19 +2098,37 @@ class CodecWorker {
|
|
|
2032
2098
|
const { signal } = streamOptions;
|
|
2033
2099
|
Object.assign(workerData, {
|
|
2034
2100
|
busy: true,
|
|
2035
|
-
readable: readable
|
|
2101
|
+
readable: readable
|
|
2102
|
+
.pipeThrough(new ChunkStream(config.chunkSize))
|
|
2103
|
+
.pipeThrough(new ProgressWatcherStream(readable, streamOptions), { signal }),
|
|
2036
2104
|
writable,
|
|
2037
2105
|
options: Object.assign({}, options),
|
|
2038
2106
|
scripts,
|
|
2039
2107
|
transferStreams,
|
|
2040
2108
|
terminate() {
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
worker
|
|
2044
|
-
|
|
2045
|
-
|
|
2109
|
+
return new Promise(resolve => {
|
|
2110
|
+
const { worker, busy } = workerData;
|
|
2111
|
+
if (worker) {
|
|
2112
|
+
if (busy) {
|
|
2113
|
+
workerData.resolveTerminated = resolve;
|
|
2114
|
+
} else {
|
|
2115
|
+
worker.terminate();
|
|
2116
|
+
resolve();
|
|
2117
|
+
}
|
|
2118
|
+
workerData.interface = null;
|
|
2119
|
+
} else {
|
|
2120
|
+
resolve();
|
|
2121
|
+
}
|
|
2122
|
+
});
|
|
2046
2123
|
},
|
|
2047
2124
|
onTaskFinished() {
|
|
2125
|
+
const { resolveTerminated } = workerData;
|
|
2126
|
+
if (resolveTerminated) {
|
|
2127
|
+
workerData.resolveTerminated = null;
|
|
2128
|
+
workerData.terminated = true;
|
|
2129
|
+
workerData.worker.terminate();
|
|
2130
|
+
resolveTerminated();
|
|
2131
|
+
}
|
|
2048
2132
|
workerData.busy = false;
|
|
2049
2133
|
onTaskFinished(workerData);
|
|
2050
2134
|
}
|
|
@@ -2055,12 +2139,12 @@ class CodecWorker {
|
|
|
2055
2139
|
|
|
2056
2140
|
class ProgressWatcherStream extends TransformStream {
|
|
2057
2141
|
|
|
2058
|
-
constructor(readableSource, { onstart, onprogress, size, onend }
|
|
2142
|
+
constructor(readableSource, { onstart, onprogress, size, onend }) {
|
|
2059
2143
|
let chunkOffset = 0;
|
|
2060
2144
|
super({
|
|
2061
|
-
start() {
|
|
2145
|
+
async start() {
|
|
2062
2146
|
if (onstart) {
|
|
2063
|
-
callHandler(onstart, size);
|
|
2147
|
+
await callHandler(onstart, size);
|
|
2064
2148
|
}
|
|
2065
2149
|
},
|
|
2066
2150
|
async transform(chunk, controller) {
|
|
@@ -2070,13 +2154,13 @@ class ProgressWatcherStream extends TransformStream {
|
|
|
2070
2154
|
}
|
|
2071
2155
|
controller.enqueue(chunk);
|
|
2072
2156
|
},
|
|
2073
|
-
flush() {
|
|
2157
|
+
async flush() {
|
|
2074
2158
|
readableSource.size = chunkOffset;
|
|
2075
2159
|
if (onend) {
|
|
2076
|
-
callHandler(onend, chunkOffset);
|
|
2160
|
+
await callHandler(onend, chunkOffset);
|
|
2077
2161
|
}
|
|
2078
2162
|
}
|
|
2079
|
-
}
|
|
2163
|
+
});
|
|
2080
2164
|
}
|
|
2081
2165
|
}
|
|
2082
2166
|
|
|
@@ -2094,10 +2178,18 @@ function createWorkerInterface(workerData, config) {
|
|
|
2094
2178
|
};
|
|
2095
2179
|
}
|
|
2096
2180
|
|
|
2097
|
-
function createWebWorkerInterface(workerData,
|
|
2181
|
+
function createWebWorkerInterface(workerData, config) {
|
|
2182
|
+
const { baseURL, chunkSize } = config;
|
|
2098
2183
|
if (!workerData.interface) {
|
|
2184
|
+
let worker;
|
|
2185
|
+
try {
|
|
2186
|
+
worker = getWebWorker(workerData.scripts[0], baseURL, workerData);
|
|
2187
|
+
} catch (error) {
|
|
2188
|
+
WEB_WORKERS_SUPPORTED = false;
|
|
2189
|
+
return createWorkerInterface(workerData, config);
|
|
2190
|
+
}
|
|
2099
2191
|
Object.assign(workerData, {
|
|
2100
|
-
worker
|
|
2192
|
+
worker,
|
|
2101
2193
|
interface: {
|
|
2102
2194
|
run: () => runWebWorker(workerData, { chunkSize })
|
|
2103
2195
|
}
|
|
@@ -2107,16 +2199,18 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
|
2107
2199
|
}
|
|
2108
2200
|
|
|
2109
2201
|
async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
|
|
2110
|
-
const codecStream = new CodecStream(options, config);
|
|
2111
2202
|
try {
|
|
2203
|
+
const codecStream = new CodecStream(options, config);
|
|
2112
2204
|
await readable.pipeThrough(codecStream).pipeTo(writable, { preventClose: true, preventAbort: true });
|
|
2113
2205
|
const {
|
|
2114
2206
|
signature,
|
|
2115
|
-
|
|
2207
|
+
inputSize,
|
|
2208
|
+
outputSize
|
|
2116
2209
|
} = codecStream;
|
|
2117
2210
|
return {
|
|
2118
2211
|
signature,
|
|
2119
|
-
|
|
2212
|
+
inputSize,
|
|
2213
|
+
outputSize
|
|
2120
2214
|
};
|
|
2121
2215
|
} finally {
|
|
2122
2216
|
onTaskFinished();
|
|
@@ -2153,29 +2247,28 @@ async function runWebWorker(workerData, config) {
|
|
|
2153
2247
|
});
|
|
2154
2248
|
}
|
|
2155
2249
|
const resultValue = await result;
|
|
2156
|
-
|
|
2250
|
+
if (!streamsTransferred) {
|
|
2157
2251
|
await writable.getWriter().close();
|
|
2158
|
-
} catch (_error) {
|
|
2159
|
-
// ignored
|
|
2160
2252
|
}
|
|
2161
2253
|
await closed;
|
|
2162
2254
|
return resultValue;
|
|
2163
2255
|
}
|
|
2164
2256
|
|
|
2165
2257
|
function watchClosedStream(writableSource) {
|
|
2166
|
-
const writer = writableSource.getWriter();
|
|
2167
2258
|
let resolveStreamClosed;
|
|
2168
2259
|
const closed = new Promise(resolve => resolveStreamClosed = resolve);
|
|
2169
2260
|
const writable = new WritableStream({
|
|
2170
2261
|
async write(chunk) {
|
|
2262
|
+
const writer = writableSource.getWriter();
|
|
2171
2263
|
await writer.ready;
|
|
2172
2264
|
await writer.write(chunk);
|
|
2265
|
+
writer.releaseLock();
|
|
2173
2266
|
},
|
|
2174
2267
|
close() {
|
|
2175
|
-
writer.releaseLock();
|
|
2176
2268
|
resolveStreamClosed();
|
|
2177
2269
|
},
|
|
2178
2270
|
abort(reason) {
|
|
2271
|
+
const writer = writableSource.getWriter();
|
|
2179
2272
|
return writer.abort(reason);
|
|
2180
2273
|
}
|
|
2181
2274
|
});
|
|
@@ -2189,7 +2282,7 @@ function getWebWorker(url, baseURL, workerData) {
|
|
|
2189
2282
|
const workerOptions = { type: "module" };
|
|
2190
2283
|
let scriptUrl, worker;
|
|
2191
2284
|
// deno-lint-ignore valid-typeof
|
|
2192
|
-
if (typeof url == FUNCTION_TYPE
|
|
2285
|
+
if (typeof url == FUNCTION_TYPE) {
|
|
2193
2286
|
url = url();
|
|
2194
2287
|
}
|
|
2195
2288
|
try {
|
|
@@ -2216,7 +2309,12 @@ function sendMessage(message, { worker, writer, onTaskFinished, transferStreams
|
|
|
2216
2309
|
let { value, readable, writable } = message;
|
|
2217
2310
|
const transferables = [];
|
|
2218
2311
|
if (value) {
|
|
2219
|
-
|
|
2312
|
+
if (value.byteLength < value.buffer.byteLength) {
|
|
2313
|
+
message.value = value.buffer.slice(0, value.byteLength);
|
|
2314
|
+
}
|
|
2315
|
+
else {
|
|
2316
|
+
message.value = value.buffer;
|
|
2317
|
+
}
|
|
2220
2318
|
transferables.push(message.value);
|
|
2221
2319
|
}
|
|
2222
2320
|
if (transferStreams && transferStreamsSupported) {
|
|
@@ -2274,6 +2372,7 @@ async function onMessage({ data }, workerData) {
|
|
|
2274
2372
|
}
|
|
2275
2373
|
}
|
|
2276
2374
|
} catch (error) {
|
|
2375
|
+
sendMessage({ type: MESSAGE_CLOSE, messageId }, workerData);
|
|
2277
2376
|
close(error);
|
|
2278
2377
|
}
|
|
2279
2378
|
|
|
@@ -2318,6 +2417,7 @@ async function onMessage({ data }, workerData) {
|
|
|
2318
2417
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2319
2418
|
*/
|
|
2320
2419
|
|
|
2420
|
+
|
|
2321
2421
|
let pool = [];
|
|
2322
2422
|
const pendingRequests = [];
|
|
2323
2423
|
|
|
@@ -2326,26 +2426,28 @@ let indexWorker = 0;
|
|
|
2326
2426
|
async function runWorker(stream, workerOptions) {
|
|
2327
2427
|
const { options, config } = workerOptions;
|
|
2328
2428
|
const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
|
|
2329
|
-
const { workerScripts, maxWorkers
|
|
2429
|
+
const { workerScripts, maxWorkers } = config;
|
|
2330
2430
|
workerOptions.transferStreams = transferStreams || transferStreams === UNDEFINED_VALUE;
|
|
2331
2431
|
const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
|
|
2332
2432
|
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
2333
2433
|
workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
|
|
2334
2434
|
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2435
|
+
return (await getWorker()).run();
|
|
2436
|
+
|
|
2437
|
+
async function getWorker() {
|
|
2438
|
+
const workerData = pool.find(workerData => !workerData.busy);
|
|
2439
|
+
if (workerData) {
|
|
2440
|
+
clearTerminateTimeout(workerData);
|
|
2441
|
+
return new CodecWorker(workerData, stream, workerOptions, onTaskFinished);
|
|
2442
|
+
} else if (pool.length < maxWorkers) {
|
|
2443
|
+
const workerData = { indexWorker };
|
|
2444
|
+
indexWorker++;
|
|
2445
|
+
pool.push(workerData);
|
|
2446
|
+
return new CodecWorker(workerData, stream, workerOptions, onTaskFinished);
|
|
2447
|
+
} else {
|
|
2448
|
+
return new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
|
|
2449
|
+
}
|
|
2347
2450
|
}
|
|
2348
|
-
return worker.run();
|
|
2349
2451
|
|
|
2350
2452
|
function onTaskFinished(workerData) {
|
|
2351
2453
|
if (pendingRequests.length) {
|
|
@@ -2353,18 +2455,32 @@ async function runWorker(stream, workerOptions) {
|
|
|
2353
2455
|
resolve(new CodecWorker(workerData, stream, workerOptions, onTaskFinished));
|
|
2354
2456
|
} else if (workerData.worker) {
|
|
2355
2457
|
clearTerminateTimeout(workerData);
|
|
2356
|
-
|
|
2357
|
-
workerData.terminateTimeout = setTimeout(() => {
|
|
2358
|
-
pool = pool.filter(data => data != workerData);
|
|
2359
|
-
workerData.terminate();
|
|
2360
|
-
}, terminateWorkerTimeout);
|
|
2361
|
-
}
|
|
2458
|
+
terminateWorker(workerData, workerOptions);
|
|
2362
2459
|
} else {
|
|
2363
2460
|
pool = pool.filter(data => data != workerData);
|
|
2364
2461
|
}
|
|
2365
2462
|
}
|
|
2366
2463
|
}
|
|
2367
2464
|
|
|
2465
|
+
function terminateWorker(workerData, workerOptions) {
|
|
2466
|
+
const { config } = workerOptions;
|
|
2467
|
+
const { terminateWorkerTimeout } = config;
|
|
2468
|
+
if (Number.isFinite(terminateWorkerTimeout) && terminateWorkerTimeout >= 0) {
|
|
2469
|
+
if (workerData.terminated) {
|
|
2470
|
+
workerData.terminated = false;
|
|
2471
|
+
} else {
|
|
2472
|
+
workerData.terminateTimeout = setTimeout(async () => {
|
|
2473
|
+
pool = pool.filter(data => data != workerData);
|
|
2474
|
+
try {
|
|
2475
|
+
await workerData.terminate();
|
|
2476
|
+
} catch (_error) {
|
|
2477
|
+
// ignored
|
|
2478
|
+
}
|
|
2479
|
+
}, terminateWorkerTimeout);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2368
2484
|
function clearTerminateTimeout(workerData) {
|
|
2369
2485
|
const { terminateTimeout } = workerData;
|
|
2370
2486
|
if (terminateTimeout) {
|
|
@@ -2373,11 +2489,11 @@ function clearTerminateTimeout(workerData) {
|
|
|
2373
2489
|
}
|
|
2374
2490
|
}
|
|
2375
2491
|
|
|
2376
|
-
function terminateWorkers() {
|
|
2377
|
-
pool.
|
|
2492
|
+
async function terminateWorkers() {
|
|
2493
|
+
await Promise.allSettled(pool.map(workerData => {
|
|
2378
2494
|
clearTerminateTimeout(workerData);
|
|
2379
|
-
workerData.terminate();
|
|
2380
|
-
});
|
|
2495
|
+
return workerData.terminate();
|
|
2496
|
+
}));
|
|
2381
2497
|
}
|
|
2382
2498
|
|
|
2383
2499
|
/*
|
|
@@ -2408,6 +2524,7 @@ function terminateWorkers() {
|
|
|
2408
2524
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2409
2525
|
*/
|
|
2410
2526
|
|
|
2527
|
+
|
|
2411
2528
|
const ERR_HTTP_STATUS = "HTTP error ";
|
|
2412
2529
|
const ERR_HTTP_RANGE = "HTTP Range not supported";
|
|
2413
2530
|
const ERR_ITERATOR_COMPLETED_TOO_SOON = "Writer iterator completed too soon";
|
|
@@ -2635,7 +2752,7 @@ class FetchReader extends Reader {
|
|
|
2635
2752
|
|
|
2636
2753
|
constructor(url, options) {
|
|
2637
2754
|
super();
|
|
2638
|
-
|
|
2755
|
+
createHttpReader(this, url, options);
|
|
2639
2756
|
}
|
|
2640
2757
|
|
|
2641
2758
|
async init() {
|
|
@@ -2652,7 +2769,7 @@ class XHRReader extends Reader {
|
|
|
2652
2769
|
|
|
2653
2770
|
constructor(url, options) {
|
|
2654
2771
|
super();
|
|
2655
|
-
|
|
2772
|
+
createHttpReader(this, url, options);
|
|
2656
2773
|
}
|
|
2657
2774
|
|
|
2658
2775
|
async init() {
|
|
@@ -2665,39 +2782,47 @@ class XHRReader extends Reader {
|
|
|
2665
2782
|
}
|
|
2666
2783
|
}
|
|
2667
2784
|
|
|
2668
|
-
function
|
|
2785
|
+
function createHttpReader(httpReader, url, options) {
|
|
2669
2786
|
const {
|
|
2670
2787
|
preventHeadRequest,
|
|
2671
2788
|
useRangeHeader,
|
|
2672
|
-
forceRangeRequests
|
|
2789
|
+
forceRangeRequests,
|
|
2790
|
+
combineSizeEocd
|
|
2673
2791
|
} = options;
|
|
2674
2792
|
options = Object.assign({}, options);
|
|
2675
2793
|
delete options.preventHeadRequest;
|
|
2676
2794
|
delete options.useRangeHeader;
|
|
2677
2795
|
delete options.forceRangeRequests;
|
|
2796
|
+
delete options.combineSizeEocd;
|
|
2678
2797
|
delete options.useXHR;
|
|
2679
2798
|
Object.assign(httpReader, {
|
|
2680
2799
|
url,
|
|
2681
2800
|
options,
|
|
2682
2801
|
preventHeadRequest,
|
|
2683
2802
|
useRangeHeader,
|
|
2684
|
-
forceRangeRequests
|
|
2803
|
+
forceRangeRequests,
|
|
2804
|
+
combineSizeEocd
|
|
2685
2805
|
});
|
|
2686
2806
|
}
|
|
2687
2807
|
|
|
2688
2808
|
async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
2689
2809
|
const {
|
|
2690
2810
|
url,
|
|
2811
|
+
preventHeadRequest,
|
|
2691
2812
|
useRangeHeader,
|
|
2692
|
-
forceRangeRequests
|
|
2813
|
+
forceRangeRequests,
|
|
2814
|
+
combineSizeEocd
|
|
2693
2815
|
} = httpReader;
|
|
2694
|
-
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
|
|
2695
|
-
const
|
|
2696
|
-
if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
2816
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == "undefined" || preventHeadRequest)) {
|
|
2817
|
+
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
|
|
2818
|
+
if (!forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
2697
2819
|
throw new Error(ERR_HTTP_RANGE);
|
|
2698
2820
|
} else {
|
|
2821
|
+
if (combineSizeEocd) {
|
|
2822
|
+
httpReader.eocdCache = new Uint8Array(await response.arrayBuffer());
|
|
2823
|
+
}
|
|
2699
2824
|
let contentSize;
|
|
2700
|
-
const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
2825
|
+
const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
2701
2826
|
if (contentRangeHeader) {
|
|
2702
2827
|
const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
|
|
2703
2828
|
if (splitHeader.length) {
|
|
@@ -2722,9 +2847,14 @@ async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest,
|
|
|
2722
2847
|
const {
|
|
2723
2848
|
useRangeHeader,
|
|
2724
2849
|
forceRangeRequests,
|
|
2850
|
+
eocdCache,
|
|
2851
|
+
size,
|
|
2725
2852
|
options
|
|
2726
2853
|
} = httpReader;
|
|
2727
2854
|
if (useRangeHeader || forceRangeRequests) {
|
|
2855
|
+
if (eocdCache && index == size - END_OF_CENTRAL_DIR_LENGTH && length == END_OF_CENTRAL_DIR_LENGTH) {
|
|
2856
|
+
return eocdCache;
|
|
2857
|
+
}
|
|
2728
2858
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
|
|
2729
2859
|
if (response.status != 206) {
|
|
2730
2860
|
throw new Error(ERR_HTTP_RANGE);
|
|
@@ -2740,7 +2870,7 @@ async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest,
|
|
|
2740
2870
|
}
|
|
2741
2871
|
|
|
2742
2872
|
function getRangeHeaders(httpReader, index = 0, length = 1) {
|
|
2743
|
-
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
|
|
2873
|
+
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + (index < 0 ? index : index + "-" + (index + length - 1)) });
|
|
2744
2874
|
}
|
|
2745
2875
|
|
|
2746
2876
|
function getHeaders({ options }) {
|
|
@@ -2957,8 +3087,8 @@ class SplitDataWriter extends Stream {
|
|
|
2957
3087
|
|
|
2958
3088
|
constructor(writerGenerator, maxSize = 4294967295) {
|
|
2959
3089
|
super();
|
|
2960
|
-
const
|
|
2961
|
-
Object.assign(
|
|
3090
|
+
const writer = this;
|
|
3091
|
+
Object.assign(writer, {
|
|
2962
3092
|
diskNumber: 0,
|
|
2963
3093
|
diskOffset: 0,
|
|
2964
3094
|
size: 0,
|
|
@@ -2968,7 +3098,7 @@ class SplitDataWriter extends Stream {
|
|
|
2968
3098
|
let diskSourceWriter, diskWritable, diskWriter;
|
|
2969
3099
|
const writable = new WritableStream({
|
|
2970
3100
|
async write(chunk) {
|
|
2971
|
-
const { availableSize } =
|
|
3101
|
+
const { availableSize } = writer;
|
|
2972
3102
|
if (!diskWriter) {
|
|
2973
3103
|
const { value, done } = await writerGenerator.next();
|
|
2974
3104
|
if (done && !value) {
|
|
@@ -2977,9 +3107,9 @@ class SplitDataWriter extends Stream {
|
|
|
2977
3107
|
diskSourceWriter = value;
|
|
2978
3108
|
diskSourceWriter.size = 0;
|
|
2979
3109
|
if (diskSourceWriter.maxSize) {
|
|
2980
|
-
|
|
3110
|
+
writer.maxSize = diskSourceWriter.maxSize;
|
|
2981
3111
|
}
|
|
2982
|
-
|
|
3112
|
+
writer.availableSize = writer.maxSize;
|
|
2983
3113
|
await initStream(diskSourceWriter);
|
|
2984
3114
|
diskWritable = value.writable;
|
|
2985
3115
|
diskWriter = diskWritable.getWriter();
|
|
@@ -2988,8 +3118,8 @@ class SplitDataWriter extends Stream {
|
|
|
2988
3118
|
} else if (chunk.length >= availableSize) {
|
|
2989
3119
|
await writeChunk(chunk.slice(0, availableSize));
|
|
2990
3120
|
await closeDisk();
|
|
2991
|
-
|
|
2992
|
-
|
|
3121
|
+
writer.diskOffset += diskSourceWriter.size;
|
|
3122
|
+
writer.diskNumber++;
|
|
2993
3123
|
diskWriter = null;
|
|
2994
3124
|
await this.write(chunk.slice(availableSize));
|
|
2995
3125
|
} else {
|
|
@@ -3001,7 +3131,7 @@ class SplitDataWriter extends Stream {
|
|
|
3001
3131
|
await closeDisk();
|
|
3002
3132
|
}
|
|
3003
3133
|
});
|
|
3004
|
-
Object.defineProperty(
|
|
3134
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
3005
3135
|
get() {
|
|
3006
3136
|
return writable;
|
|
3007
3137
|
}
|
|
@@ -3013,8 +3143,8 @@ class SplitDataWriter extends Stream {
|
|
|
3013
3143
|
await diskWriter.ready;
|
|
3014
3144
|
await diskWriter.write(chunk);
|
|
3015
3145
|
diskSourceWriter.size += chunkLength;
|
|
3016
|
-
|
|
3017
|
-
|
|
3146
|
+
writer.size += chunkLength;
|
|
3147
|
+
writer.availableSize -= chunkLength;
|
|
3018
3148
|
}
|
|
3019
3149
|
}
|
|
3020
3150
|
|
|
@@ -3034,6 +3164,8 @@ function isHttpFamily(url) {
|
|
|
3034
3164
|
async function initStream(stream, initSize) {
|
|
3035
3165
|
if (stream.init && !stream.initialized) {
|
|
3036
3166
|
await stream.init(initSize);
|
|
3167
|
+
} else {
|
|
3168
|
+
return Promise.resolve();
|
|
3037
3169
|
}
|
|
3038
3170
|
}
|
|
3039
3171
|
|
|
@@ -3050,7 +3182,7 @@ function initReader(reader) {
|
|
|
3050
3182
|
}
|
|
3051
3183
|
|
|
3052
3184
|
function initWriter(writer) {
|
|
3053
|
-
if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE
|
|
3185
|
+
if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE) {
|
|
3054
3186
|
writer = new SplitDataWriter(writer);
|
|
3055
3187
|
}
|
|
3056
3188
|
if (writer instanceof WritableStream) {
|
|
@@ -3062,8 +3194,7 @@ function initWriter(writer) {
|
|
|
3062
3194
|
if (writable.size === UNDEFINED_VALUE) {
|
|
3063
3195
|
writable.size = 0;
|
|
3064
3196
|
}
|
|
3065
|
-
|
|
3066
|
-
if (!splitZipFile) {
|
|
3197
|
+
if (!(writer instanceof SplitDataWriter)) {
|
|
3067
3198
|
Object.assign(writer, {
|
|
3068
3199
|
diskNumber: 0,
|
|
3069
3200
|
diskOffset: 0,
|
|
@@ -3154,6 +3285,7 @@ function decodeCP437(stringValue) {
|
|
|
3154
3285
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3155
3286
|
*/
|
|
3156
3287
|
|
|
3288
|
+
|
|
3157
3289
|
function decodeText(value, encoding) {
|
|
3158
3290
|
if (encoding && encoding.trim().toLowerCase() == "cp437") {
|
|
3159
3291
|
return decodeCP437(value);
|
|
@@ -3236,8 +3368,8 @@ class Entry {
|
|
|
3236
3368
|
1. Redistributions of source code must retain the above copyright notice,
|
|
3237
3369
|
this list of conditions and the following disclaimer.
|
|
3238
3370
|
|
|
3239
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
3240
|
-
notice, this list of conditions and the following disclaimer in
|
|
3371
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
3372
|
+
notice, this list of conditions and the following disclaimer in
|
|
3241
3373
|
the documentation and/or other materials provided with the distribution.
|
|
3242
3374
|
|
|
3243
3375
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -3255,9 +3387,9 @@ class Entry {
|
|
|
3255
3387
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3256
3388
|
*/
|
|
3257
3389
|
|
|
3390
|
+
|
|
3258
3391
|
const ERR_BAD_FORMAT = "File format is not recognized";
|
|
3259
3392
|
const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
|
|
3260
|
-
const ERR_EOCDR_ZIP64_NOT_FOUND = "End of Zip64 central directory not found";
|
|
3261
3393
|
const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = "End of Zip64 central directory locator not found";
|
|
3262
3394
|
const ERR_CENTRAL_DIRECTORY_NOT_FOUND = "Central directory header not found";
|
|
3263
3395
|
const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
|
|
@@ -3333,40 +3465,39 @@ class ZipReader {
|
|
|
3333
3465
|
if (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS) {
|
|
3334
3466
|
const endOfDirectoryLocatorArray = await readUint8Array(reader, endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH);
|
|
3335
3467
|
const endOfDirectoryLocatorView = getDataView$1(endOfDirectoryLocatorArray);
|
|
3336
|
-
if (getUint32(endOfDirectoryLocatorView, 0)
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
endOfDirectoryView
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3468
|
+
if (getUint32(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
|
|
3469
|
+
directoryDataOffset = getBigUint64(endOfDirectoryLocatorView, 8);
|
|
3470
|
+
let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH, -1);
|
|
3471
|
+
let endOfDirectoryView = getDataView$1(endOfDirectoryArray);
|
|
3472
|
+
const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
3473
|
+
if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
|
|
3474
|
+
const originalDirectoryDataOffset = directoryDataOffset;
|
|
3475
|
+
directoryDataOffset = expectedDirectoryDataOffset;
|
|
3476
|
+
prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
|
|
3477
|
+
endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH, -1);
|
|
3478
|
+
endOfDirectoryView = getDataView$1(endOfDirectoryArray);
|
|
3479
|
+
}
|
|
3480
|
+
if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
|
|
3481
|
+
throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
|
|
3482
|
+
}
|
|
3483
|
+
if (lastDiskNumber == MAX_16_BITS) {
|
|
3484
|
+
lastDiskNumber = getUint32(endOfDirectoryView, 16);
|
|
3485
|
+
}
|
|
3486
|
+
if (diskNumber == MAX_16_BITS) {
|
|
3487
|
+
diskNumber = getUint32(endOfDirectoryView, 20);
|
|
3488
|
+
}
|
|
3489
|
+
if (filesLength == MAX_16_BITS) {
|
|
3490
|
+
filesLength = getBigUint64(endOfDirectoryView, 32);
|
|
3491
|
+
}
|
|
3492
|
+
if (directoryDataLength == MAX_32_BITS) {
|
|
3493
|
+
directoryDataLength = getBigUint64(endOfDirectoryView, 40);
|
|
3494
|
+
}
|
|
3495
|
+
directoryDataOffset -= directoryDataLength;
|
|
3364
3496
|
}
|
|
3365
|
-
directoryDataOffset -= directoryDataLength;
|
|
3366
3497
|
}
|
|
3367
3498
|
if (directoryDataOffset >= reader.size) {
|
|
3368
3499
|
prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
3369
|
-
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
3500
|
+
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
3370
3501
|
}
|
|
3371
3502
|
if (expectedLastDiskNumber != lastDiskNumber) {
|
|
3372
3503
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
@@ -3434,10 +3565,17 @@ class ZipReader {
|
|
|
3434
3565
|
commentUTF8,
|
|
3435
3566
|
rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
|
|
3436
3567
|
});
|
|
3437
|
-
const
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3568
|
+
const decode = getOptionValue$1(zipReader, options, "decodeText") || decodeText;
|
|
3569
|
+
const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
|
|
3570
|
+
const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
|
|
3571
|
+
let filename = decode(rawFilename, rawFilenameEncoding);
|
|
3572
|
+
if (filename === UNDEFINED_VALUE) {
|
|
3573
|
+
filename = decodeText(rawFilename, rawFilenameEncoding);
|
|
3574
|
+
}
|
|
3575
|
+
let comment = decode(rawComment, rawCommentEncoding);
|
|
3576
|
+
if (comment === UNDEFINED_VALUE) {
|
|
3577
|
+
comment = decodeText(rawComment, rawCommentEncoding);
|
|
3578
|
+
}
|
|
3441
3579
|
Object.assign(fileEntry, {
|
|
3442
3580
|
rawComment,
|
|
3443
3581
|
filename,
|
|
@@ -3483,6 +3621,34 @@ class ZipReader {
|
|
|
3483
3621
|
}
|
|
3484
3622
|
}
|
|
3485
3623
|
|
|
3624
|
+
class ZipReaderStream {
|
|
3625
|
+
|
|
3626
|
+
constructor(options = {}) {
|
|
3627
|
+
const { readable, writable } = new TransformStream();
|
|
3628
|
+
const gen = new ZipReader(readable, options).getEntriesGenerator();
|
|
3629
|
+
this.readable = new ReadableStream({
|
|
3630
|
+
async pull(controller) {
|
|
3631
|
+
const { done, value } = await gen.next();
|
|
3632
|
+
if (done)
|
|
3633
|
+
return controller.close();
|
|
3634
|
+
const chunk = {
|
|
3635
|
+
...value,
|
|
3636
|
+
readable: (function () {
|
|
3637
|
+
const { readable, writable } = new TransformStream();
|
|
3638
|
+
if (value.getData) {
|
|
3639
|
+
value.getData(writable);
|
|
3640
|
+
return readable;
|
|
3641
|
+
}
|
|
3642
|
+
})()
|
|
3643
|
+
};
|
|
3644
|
+
delete chunk.getData;
|
|
3645
|
+
controller.enqueue(chunk);
|
|
3646
|
+
}
|
|
3647
|
+
});
|
|
3648
|
+
this.writable = writable;
|
|
3649
|
+
}
|
|
3650
|
+
}
|
|
3651
|
+
|
|
3486
3652
|
class ZipEntry {
|
|
3487
3653
|
|
|
3488
3654
|
constructor(reader, config, options) {
|
|
@@ -3512,7 +3678,9 @@ class ZipEntry {
|
|
|
3512
3678
|
const dataArray = await readUint8Array(reader, offset, 30, diskNumberStart);
|
|
3513
3679
|
const dataView = getDataView$1(dataArray);
|
|
3514
3680
|
let password = getOptionValue$1(zipEntry, options, "password");
|
|
3681
|
+
let rawPassword = getOptionValue$1(zipEntry, options, "rawPassword");
|
|
3515
3682
|
password = password && password.length && password;
|
|
3683
|
+
rawPassword = rawPassword && rawPassword.length && rawPassword;
|
|
3516
3684
|
if (extraFieldAES) {
|
|
3517
3685
|
if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
|
|
3518
3686
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
@@ -3538,7 +3706,7 @@ class ZipEntry {
|
|
|
3538
3706
|
if (encrypted) {
|
|
3539
3707
|
if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
|
|
3540
3708
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
3541
|
-
} else if (!password) {
|
|
3709
|
+
} else if (!password && !rawPassword) {
|
|
3542
3710
|
throw new Error(ERR_ENCRYPTED);
|
|
3543
3711
|
}
|
|
3544
3712
|
}
|
|
@@ -3563,6 +3731,7 @@ class ZipEntry {
|
|
|
3563
3731
|
options: {
|
|
3564
3732
|
codecType: CODEC_INFLATE,
|
|
3565
3733
|
password,
|
|
3734
|
+
rawPassword,
|
|
3566
3735
|
zipCrypto,
|
|
3567
3736
|
encryptionStrength: extraFieldAES && extraFieldAES.strength,
|
|
3568
3737
|
signed: getOptionValue$1(zipEntry, options, "checkSignature"),
|
|
@@ -3592,7 +3761,7 @@ class ZipEntry {
|
|
|
3592
3761
|
await writable.getWriter().close();
|
|
3593
3762
|
}
|
|
3594
3763
|
}
|
|
3595
|
-
return checkPasswordOnly ?
|
|
3764
|
+
return checkPasswordOnly ? UNDEFINED_VALUE : writer.getData ? writer.getData() : writable;
|
|
3596
3765
|
}
|
|
3597
3766
|
}
|
|
3598
3767
|
|
|
@@ -3869,8 +4038,8 @@ function getDataView$1(array) {
|
|
|
3869
4038
|
1. Redistributions of source code must retain the above copyright notice,
|
|
3870
4039
|
this list of conditions and the following disclaimer.
|
|
3871
4040
|
|
|
3872
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
3873
|
-
notice, this list of conditions and the following disclaimer in
|
|
4041
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
4042
|
+
notice, this list of conditions and the following disclaimer in
|
|
3874
4043
|
the documentation and/or other materials provided with the distribution.
|
|
3875
4044
|
|
|
3876
4045
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -3888,6 +4057,7 @@ function getDataView$1(array) {
|
|
|
3888
4057
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3889
4058
|
*/
|
|
3890
4059
|
|
|
4060
|
+
|
|
3891
4061
|
const ERR_DUPLICATED_NAME = "File already exists";
|
|
3892
4062
|
const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
|
|
3893
4063
|
const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
|
|
@@ -3907,9 +4077,12 @@ class ZipWriter {
|
|
|
3907
4077
|
|
|
3908
4078
|
constructor(writer, options = {}) {
|
|
3909
4079
|
writer = initWriter(writer);
|
|
4080
|
+
const addSplitZipSignature =
|
|
4081
|
+
writer.availableSize !== UNDEFINED_VALUE && writer.availableSize > 0 && writer.availableSize !== Infinity &&
|
|
4082
|
+
writer.maxSize !== UNDEFINED_VALUE && writer.maxSize > 0 && writer.maxSize !== Infinity;
|
|
3910
4083
|
Object.assign(this, {
|
|
3911
4084
|
writer,
|
|
3912
|
-
addSplitZipSignature
|
|
4085
|
+
addSplitZipSignature,
|
|
3913
4086
|
options,
|
|
3914
4087
|
config: getConfiguration(),
|
|
3915
4088
|
files: new Map(),
|
|
@@ -3961,7 +4134,7 @@ class ZipWriter {
|
|
|
3961
4134
|
const { pendingAddFileCalls, writer } = this;
|
|
3962
4135
|
const { writable } = writer;
|
|
3963
4136
|
while (pendingAddFileCalls.size) {
|
|
3964
|
-
await Promise.
|
|
4137
|
+
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
3965
4138
|
}
|
|
3966
4139
|
await closeFile(this, comment, options);
|
|
3967
4140
|
const preventClose = getOptionValue(zipWriter, options, "preventClose");
|
|
@@ -3972,6 +4145,33 @@ class ZipWriter {
|
|
|
3972
4145
|
}
|
|
3973
4146
|
}
|
|
3974
4147
|
|
|
4148
|
+
class ZipWriterStream {
|
|
4149
|
+
|
|
4150
|
+
constructor(options = {}) {
|
|
4151
|
+
const { readable, writable } = new TransformStream();
|
|
4152
|
+
this.readable = readable;
|
|
4153
|
+
this.zipWriter = new ZipWriter(writable, options);
|
|
4154
|
+
}
|
|
4155
|
+
|
|
4156
|
+
transform(path) {
|
|
4157
|
+
const { readable, writable } = new TransformStream({
|
|
4158
|
+
flush: () => { this.zipWriter.close(); }
|
|
4159
|
+
});
|
|
4160
|
+
this.zipWriter.add(path, readable);
|
|
4161
|
+
return { readable: this.readable, writable };
|
|
4162
|
+
}
|
|
4163
|
+
|
|
4164
|
+
writable(path) {
|
|
4165
|
+
const { readable, writable } = new TransformStream();
|
|
4166
|
+
this.zipWriter.add(path, readable);
|
|
4167
|
+
return writable;
|
|
4168
|
+
}
|
|
4169
|
+
|
|
4170
|
+
close(comment = undefined, options = {}) {
|
|
4171
|
+
return this.zipWriter.close(comment, options);
|
|
4172
|
+
}
|
|
4173
|
+
}
|
|
4174
|
+
|
|
3975
4175
|
async function addFile(zipWriter, name, reader, options) {
|
|
3976
4176
|
name = name.trim();
|
|
3977
4177
|
if (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {
|
|
@@ -3979,12 +4179,19 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
3979
4179
|
} else {
|
|
3980
4180
|
options.directory = name.endsWith(DIRECTORY_SIGNATURE);
|
|
3981
4181
|
}
|
|
3982
|
-
const
|
|
4182
|
+
const encode = getOptionValue(zipWriter, options, "encodeText", encodeText);
|
|
4183
|
+
let rawFilename = encode(name);
|
|
4184
|
+
if (rawFilename === UNDEFINED_VALUE) {
|
|
4185
|
+
rawFilename = encodeText(name);
|
|
4186
|
+
}
|
|
3983
4187
|
if (getLength(rawFilename) > MAX_16_BITS) {
|
|
3984
4188
|
throw new Error(ERR_INVALID_ENTRY_NAME);
|
|
3985
4189
|
}
|
|
3986
4190
|
const comment = options.comment || "";
|
|
3987
|
-
|
|
4191
|
+
let rawComment = encode(comment);
|
|
4192
|
+
if (rawComment === UNDEFINED_VALUE) {
|
|
4193
|
+
rawComment = encodeText(comment);
|
|
4194
|
+
}
|
|
3988
4195
|
if (getLength(rawComment) > MAX_16_BITS) {
|
|
3989
4196
|
throw new Error(ERR_INVALID_ENTRY_COMMENT);
|
|
3990
4197
|
}
|
|
@@ -4003,6 +4210,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
4003
4210
|
const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
|
|
4004
4211
|
const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
|
|
4005
4212
|
const password = getOptionValue(zipWriter, options, "password");
|
|
4213
|
+
const rawPassword = getOptionValue(zipWriter, options, "rawPassword");
|
|
4006
4214
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
|
|
4007
4215
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
4008
4216
|
const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
|
|
@@ -4049,7 +4257,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
4049
4257
|
dataDescriptor = true;
|
|
4050
4258
|
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
4051
4259
|
zip64 = true;
|
|
4052
|
-
uncompressedSize = maximumCompressedSize = MAX_32_BITS;
|
|
4260
|
+
uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
|
|
4053
4261
|
}
|
|
4054
4262
|
} else {
|
|
4055
4263
|
uncompressedSize = reader.size;
|
|
@@ -4057,11 +4265,11 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
4057
4265
|
}
|
|
4058
4266
|
}
|
|
4059
4267
|
const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
|
|
4060
|
-
const zip64UncompressedSize = zip64Enabled || uncompressedSize
|
|
4061
|
-
const zip64CompressedSize = zip64Enabled || maximumCompressedSize
|
|
4062
|
-
const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset
|
|
4268
|
+
const zip64UncompressedSize = zip64Enabled || uncompressedSize > MAX_32_BITS;
|
|
4269
|
+
const zip64CompressedSize = zip64Enabled || maximumCompressedSize > MAX_32_BITS;
|
|
4270
|
+
const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset > MAX_32_BITS;
|
|
4063
4271
|
const supportZip64SplitFile = getOptionValue(zipWriter, options, "supportZip64SplitFile", true);
|
|
4064
|
-
const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize)
|
|
4272
|
+
const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) > MAX_16_BITS;
|
|
4065
4273
|
if (zip64Offset || zip64UncompressedSize || zip64CompressedSize || zip64DiskNumberStart) {
|
|
4066
4274
|
if (zip64 === false || !keepOrder) {
|
|
4067
4275
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
@@ -4085,7 +4293,8 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
4085
4293
|
zip64Offset,
|
|
4086
4294
|
zip64DiskNumberStart,
|
|
4087
4295
|
password,
|
|
4088
|
-
|
|
4296
|
+
rawPassword,
|
|
4297
|
+
level: !useCompressionStream && zipWriter.config.CompressionStream === UNDEFINED_VALUE ? 0 : level,
|
|
4089
4298
|
useWebWorkers,
|
|
4090
4299
|
encryptionStrength,
|
|
4091
4300
|
extendedTimestamp,
|
|
@@ -4140,6 +4349,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
4140
4349
|
let writingBufferedEntryData;
|
|
4141
4350
|
let writingEntryData;
|
|
4142
4351
|
let fileWriter;
|
|
4352
|
+
let blobPromise;
|
|
4143
4353
|
files.set(name, fileEntry);
|
|
4144
4354
|
try {
|
|
4145
4355
|
let lockPreviousFileEntry;
|
|
@@ -4148,7 +4358,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
4148
4358
|
requestLockCurrentFileEntry();
|
|
4149
4359
|
}
|
|
4150
4360
|
if ((options.bufferedWrite || zipWriter.writerLocked || (zipWriter.bufferedWrites && keepOrder) || !dataDescriptor) && !usdz) {
|
|
4151
|
-
fileWriter = new
|
|
4361
|
+
fileWriter = new TransformStream();
|
|
4362
|
+
blobPromise = new Response(fileWriter.readable).blob();
|
|
4152
4363
|
fileWriter.writable.size = 0;
|
|
4153
4364
|
bufferedWrite = true;
|
|
4154
4365
|
zipWriter.bufferedWrites++;
|
|
@@ -4184,7 +4395,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
4184
4395
|
fileEntry.filename = name;
|
|
4185
4396
|
if (bufferedWrite) {
|
|
4186
4397
|
await fileWriter.writable.getWriter().close();
|
|
4187
|
-
let blob = await
|
|
4398
|
+
let blob = await blobPromise;
|
|
4188
4399
|
await lockPreviousFileEntry;
|
|
4189
4400
|
await requestLockWriter();
|
|
4190
4401
|
writingBufferedEntryData = true;
|
|
@@ -4201,10 +4412,10 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
4201
4412
|
fileEntry.offset = zipWriter.offset - diskOffset;
|
|
4202
4413
|
if (fileEntry.zip64) {
|
|
4203
4414
|
setZip64ExtraInfo(fileEntry, options);
|
|
4204
|
-
} else if (fileEntry.offset
|
|
4415
|
+
} else if (fileEntry.offset > MAX_32_BITS) {
|
|
4205
4416
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
4206
4417
|
}
|
|
4207
|
-
zipWriter.offset += fileEntry.
|
|
4418
|
+
zipWriter.offset += fileEntry.size;
|
|
4208
4419
|
return fileEntry;
|
|
4209
4420
|
} catch (error) {
|
|
4210
4421
|
if ((bufferedWrite && writingBufferedEntryData) || (!bufferedWrite && writingEntryData)) {
|
|
@@ -4251,7 +4462,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
4251
4462
|
}
|
|
4252
4463
|
|
|
4253
4464
|
async function skipDiskIfNeeded(writable) {
|
|
4254
|
-
if (headerInfo.localHeaderArray
|
|
4465
|
+
if (getLength(headerInfo.localHeaderArray) > writer.availableSize) {
|
|
4255
4466
|
writer.availableSize = 0;
|
|
4256
4467
|
await writeData(writable, new Uint8Array());
|
|
4257
4468
|
}
|
|
@@ -4284,6 +4495,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
4284
4495
|
lastAccessDate,
|
|
4285
4496
|
creationDate,
|
|
4286
4497
|
password,
|
|
4498
|
+
rawPassword,
|
|
4287
4499
|
level,
|
|
4288
4500
|
zip64,
|
|
4289
4501
|
zip64UncompressedSize,
|
|
@@ -4340,6 +4552,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
4340
4552
|
options: {
|
|
4341
4553
|
codecType: CODEC_DEFLATE,
|
|
4342
4554
|
level,
|
|
4555
|
+
rawPassword,
|
|
4343
4556
|
password,
|
|
4344
4557
|
encryptionStrength,
|
|
4345
4558
|
zipCrypto: encrypted && zipCrypto,
|
|
@@ -4355,10 +4568,10 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
4355
4568
|
streamOptions: { signal, size, onstart, onprogress, onend }
|
|
4356
4569
|
};
|
|
4357
4570
|
const result = await runWorker({ readable, writable }, workerOptions);
|
|
4358
|
-
|
|
4571
|
+
uncompressedSize = result.inputSize;
|
|
4572
|
+
compressedSize = result.outputSize;
|
|
4359
4573
|
signature = result.signature;
|
|
4360
|
-
|
|
4361
|
-
compressedSize = result.size;
|
|
4574
|
+
writable.size += uncompressedSize;
|
|
4362
4575
|
} else {
|
|
4363
4576
|
await writeData(writable, localHeaderArray);
|
|
4364
4577
|
}
|
|
@@ -4400,7 +4613,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
4400
4613
|
creationDate,
|
|
4401
4614
|
lastAccessDate,
|
|
4402
4615
|
encrypted,
|
|
4403
|
-
|
|
4616
|
+
size: metadataSize + compressedSize,
|
|
4404
4617
|
compressionMethod,
|
|
4405
4618
|
version,
|
|
4406
4619
|
headerArray,
|
|
@@ -4421,6 +4634,7 @@ function getHeaderInfo(options) {
|
|
|
4421
4634
|
lastModDate,
|
|
4422
4635
|
lastAccessDate,
|
|
4423
4636
|
creationDate,
|
|
4637
|
+
rawPassword,
|
|
4424
4638
|
password,
|
|
4425
4639
|
level,
|
|
4426
4640
|
zip64,
|
|
@@ -4432,7 +4646,7 @@ function getHeaderInfo(options) {
|
|
|
4432
4646
|
extendedTimestamp
|
|
4433
4647
|
} = options;
|
|
4434
4648
|
const compressed = level !== 0 && !directory;
|
|
4435
|
-
const encrypted = Boolean(password && getLength(password));
|
|
4649
|
+
const encrypted = Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword)));
|
|
4436
4650
|
let version = options.version;
|
|
4437
4651
|
let rawExtraFieldAES;
|
|
4438
4652
|
if (encrypted && !zipCrypto) {
|
|
@@ -4555,7 +4769,7 @@ function appendExtraFieldUSDZ(entryInfo, zipWriterOffset) {
|
|
|
4555
4769
|
const { headerInfo } = entryInfo;
|
|
4556
4770
|
let { localHeaderArray, extraFieldLength } = headerInfo;
|
|
4557
4771
|
let localHeaderArrayView = getDataView(localHeaderArray);
|
|
4558
|
-
let extraBytesLength = 64 - ((zipWriterOffset + localHeaderArray
|
|
4772
|
+
let extraBytesLength = 64 - ((zipWriterOffset + getLength(localHeaderArray)) % 64);
|
|
4559
4773
|
if (extraBytesLength < 4) {
|
|
4560
4774
|
extraBytesLength += 64;
|
|
4561
4775
|
}
|
|
@@ -4564,9 +4778,9 @@ function appendExtraFieldUSDZ(entryInfo, zipWriterOffset) {
|
|
|
4564
4778
|
setUint16(extraFieldUSDZView, 0, EXTRAFIELD_TYPE_USDZ);
|
|
4565
4779
|
setUint16(extraFieldUSDZView, 2, extraBytesLength - 2);
|
|
4566
4780
|
const previousLocalHeaderArray = localHeaderArray;
|
|
4567
|
-
headerInfo.localHeaderArray = localHeaderArray = new Uint8Array(previousLocalHeaderArray
|
|
4781
|
+
headerInfo.localHeaderArray = localHeaderArray = new Uint8Array(getLength(previousLocalHeaderArray) + extraBytesLength);
|
|
4568
4782
|
arraySet(localHeaderArray, previousLocalHeaderArray);
|
|
4569
|
-
arraySet(localHeaderArray, rawExtraFieldUSDZ, previousLocalHeaderArray
|
|
4783
|
+
arraySet(localHeaderArray, rawExtraFieldUSDZ, getLength(previousLocalHeaderArray));
|
|
4570
4784
|
localHeaderArrayView = getDataView(localHeaderArray);
|
|
4571
4785
|
setUint16(localHeaderArrayView, 28, extraFieldLength + extraBytesLength);
|
|
4572
4786
|
entryInfo.metadataSize += extraBytesLength;
|
|
@@ -4628,7 +4842,7 @@ function setEntryInfo(entryInfo, options) {
|
|
|
4628
4842
|
if (zip64) {
|
|
4629
4843
|
const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
|
|
4630
4844
|
setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
|
|
4631
|
-
setUint16(rawExtraFieldZip64View, 2, rawExtraFieldZip64
|
|
4845
|
+
setUint16(rawExtraFieldZip64View, 2, getLength(rawExtraFieldZip64) - 4);
|
|
4632
4846
|
let rawExtraFieldZip64Offset = 4;
|
|
4633
4847
|
if (zip64UncompressedSize) {
|
|
4634
4848
|
setUint32(headerView, 18, MAX_32_BITS);
|
|
@@ -4815,7 +5029,7 @@ async function closeFile(zipWriter, comment, options) {
|
|
|
4815
5029
|
lastDiskNumber++;
|
|
4816
5030
|
}
|
|
4817
5031
|
let zip64 = getOptionValue(zipWriter, options, "zip64");
|
|
4818
|
-
if (directoryOffset
|
|
5032
|
+
if (directoryOffset > MAX_32_BITS || directoryDataLength > MAX_32_BITS || filesLength > MAX_16_BITS || lastDiskNumber > MAX_16_BITS) {
|
|
4819
5033
|
if (zip64 === false) {
|
|
4820
5034
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
4821
5035
|
} else {
|
|
@@ -4872,10 +5086,13 @@ async function closeFile(zipWriter, comment, options) {
|
|
|
4872
5086
|
|
|
4873
5087
|
async function writeData(writable, array) {
|
|
4874
5088
|
const streamWriter = writable.getWriter();
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
5089
|
+
try {
|
|
5090
|
+
await streamWriter.ready;
|
|
5091
|
+
writable.size += getLength(array);
|
|
5092
|
+
await streamWriter.write(array);
|
|
5093
|
+
} finally {
|
|
5094
|
+
streamWriter.releaseLock();
|
|
5095
|
+
}
|
|
4879
5096
|
}
|
|
4880
5097
|
|
|
4881
5098
|
function getTimeNTFS(date) {
|
|
@@ -4940,7 +5157,7 @@ function getLength(...arrayLikes) {
|
|
|
4940
5157
|
derived from this software without specific prior written permission.
|
|
4941
5158
|
|
|
4942
5159
|
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4943
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
5160
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4944
5161
|
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4945
5162
|
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4946
5163
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
@@ -4951,6 +5168,7 @@ function getLength(...arrayLikes) {
|
|
|
4951
5168
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4952
5169
|
*/
|
|
4953
5170
|
|
|
5171
|
+
|
|
4954
5172
|
let baseURL;
|
|
4955
5173
|
try {
|
|
4956
5174
|
baseURL = import.meta.url;
|
|
@@ -4960,4 +5178,4 @@ try {
|
|
|
4960
5178
|
configure({ baseURL });
|
|
4961
5179
|
e(configure);
|
|
4962
5180
|
|
|
4963
|
-
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND,
|
|
5181
|
+
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_INVALID_COMMENT, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_PASSWORD, ERR_INVALID_SIGNATURE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_SPLIT_ZIP_FILE, ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_FORMAT, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, SplitZipReader, SplitZipWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, getMimeType, initReader, initShimAsyncCodec, initStream, initWriter, readUint8Array, terminateWorkers };
|