@zip.js/zip.js 2.6.33 → 2.6.34
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/dist/z-worker-fflate.js +1 -1
- package/dist/z-worker-pako.js +1 -1
- package/dist/z-worker.js +1 -1
- package/dist/zip-fs-full.js +2479 -2364
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +1236 -1121
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +1235 -1120
- package/dist/zip-full.min.js +1 -1
- package/dist/zip-no-worker-deflate.min.js +1 -1
- package/dist/zip-no-worker-inflate.min.js +1 -1
- package/dist/zip-no-worker.min.js +1 -1
- package/dist/zip.js +1236 -1121
- package/dist/zip.min.js +1 -1
- package/index-fflate.js +3 -1
- package/index.cjs +2479 -2364
- package/index.d.ts +33 -2
- package/index.js +3 -1
- package/lib/core/codec-pool.js +2 -2
- package/lib/core/codec-worker.js +321 -0
- package/lib/core/configuration.js +3 -3
- package/lib/core/constants.js +6 -5
- package/lib/core/io.js +64 -1
- package/lib/core/streams/aes-crypto-stream.js +2 -0
- package/lib/core/streams/codec-stream.js +60 -13
- package/lib/core/streams/codecs/sjcl.js +1 -1
- package/lib/core/streams/stream-adapter.js +55 -0
- package/lib/core/streams/zip-crypto-stream.js +1 -0
- package/lib/core/streams/zip-entry-stream.js +1 -0
- package/lib/core/util/stream-codec-shim.js +2 -0
- package/lib/core/z-worker-core.js +21 -11
- package/lib/core/zip-entry.js +2 -1
- package/lib/core/zip-fs-core.js +1 -0
- package/lib/core/zip-reader.js +7 -5
- package/lib/core/zip-writer.js +88 -42
- package/lib/z-worker-inline.js +1 -1
- package/lib/zip.js +1 -1
- package/package.json +5 -5
- package/tests/all/test-http-split-zip.js +37 -0
- package/tests/all/test-split-zip.js +25 -22
- package/tests/tests-data.js +2 -1
- package/lib/core/codec-interface.js +0 -115
- package/lib/core/codec-pool-worker.js +0 -293
package/dist/zip-fs.js
CHANGED
|
@@ -34,37 +34,50 @@
|
|
|
34
34
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
t = (t >>> 1) ^ 0xEDB88320;
|
|
43
|
-
} else {
|
|
44
|
-
t = t >>> 1;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
table[i] = t;
|
|
48
|
-
}
|
|
37
|
+
const MAX_32_BITS = 0xffffffff;
|
|
38
|
+
const MAX_16_BITS = 0xffff;
|
|
39
|
+
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
40
|
+
const COMPRESSION_METHOD_STORE = 0x00;
|
|
41
|
+
const COMPRESSION_METHOD_AES = 0x63;
|
|
49
42
|
|
|
50
|
-
|
|
43
|
+
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
44
|
+
const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
|
|
45
|
+
const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
|
|
46
|
+
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
47
|
+
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
48
|
+
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
49
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
50
|
+
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
51
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
52
|
+
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
53
|
+
const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
56
|
+
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
57
|
+
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
58
|
+
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
59
|
+
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
60
|
+
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
61
|
+
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
55
62
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.crc = crc;
|
|
62
|
-
}
|
|
63
|
+
const BITFLAG_ENCRYPTED = 0x01;
|
|
64
|
+
const BITFLAG_LEVEL = 0x06;
|
|
65
|
+
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
66
|
+
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
67
|
+
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
const VERSION_DEFLATE = 0x14;
|
|
70
|
+
const VERSION_ZIP64 = 0x2D;
|
|
71
|
+
const VERSION_AES = 0x33;
|
|
72
|
+
|
|
73
|
+
const DIRECTORY_SIGNATURE = "/";
|
|
74
|
+
|
|
75
|
+
const MAX_DATE = new Date(2107, 11, 31);
|
|
76
|
+
const MIN_DATE = new Date(1980, 0, 1);
|
|
77
|
+
|
|
78
|
+
const UNDEFINED_VALUE = undefined;
|
|
79
|
+
const UNDEFINED_TYPE$1 = "undefined";
|
|
80
|
+
const FUNCTION_TYPE$1 = "function";
|
|
68
81
|
|
|
69
82
|
/*
|
|
70
83
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -94,21 +107,25 @@
|
|
|
94
107
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
95
108
|
*/
|
|
96
109
|
|
|
97
|
-
class
|
|
110
|
+
class StreamAdapter {
|
|
98
111
|
|
|
99
|
-
constructor() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
constructor(Codec) {
|
|
113
|
+
return class extends TransformStream {
|
|
114
|
+
constructor(options) {
|
|
115
|
+
const codec = new Codec(options);
|
|
116
|
+
super({
|
|
117
|
+
transform(chunk, controller) {
|
|
118
|
+
controller.enqueue(codec.append(chunk));
|
|
119
|
+
},
|
|
120
|
+
flush(controller) {
|
|
121
|
+
const chunk = codec.flush();
|
|
122
|
+
if (chunk) {
|
|
123
|
+
controller.enqueue(chunk);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
110
127
|
}
|
|
111
|
-
}
|
|
128
|
+
};
|
|
112
129
|
}
|
|
113
130
|
}
|
|
114
131
|
|
|
@@ -140,94 +157,397 @@
|
|
|
140
157
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
141
158
|
*/
|
|
142
159
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
160
|
+
const MINIMUM_CHUNK_SIZE = 64;
|
|
161
|
+
let maxWorkers = 2;
|
|
162
|
+
try {
|
|
163
|
+
if (typeof navigator != UNDEFINED_TYPE$1 && navigator.hardwareConcurrency) {
|
|
164
|
+
maxWorkers = navigator.hardwareConcurrency;
|
|
165
|
+
}
|
|
166
|
+
} catch (_error) {
|
|
167
|
+
// ignored
|
|
168
|
+
}
|
|
169
|
+
const DEFAULT_CONFIGURATION = {
|
|
170
|
+
chunkSize: 512 * 1024,
|
|
171
|
+
maxWorkers,
|
|
172
|
+
terminateWorkerTimeout: 5000,
|
|
173
|
+
useWebWorkers: true,
|
|
174
|
+
useCompressionStream: true,
|
|
175
|
+
workerScripts: UNDEFINED_VALUE,
|
|
176
|
+
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE$1 && CompressionStream,
|
|
177
|
+
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE$1 && DecompressionStream
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const config = Object.assign({}, DEFAULT_CONFIGURATION);
|
|
181
|
+
|
|
182
|
+
function getConfiguration() {
|
|
183
|
+
return config;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function getChunkSize(config) {
|
|
187
|
+
return Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function configure(configuration) {
|
|
191
|
+
const {
|
|
192
|
+
baseURL,
|
|
193
|
+
chunkSize,
|
|
194
|
+
maxWorkers,
|
|
195
|
+
terminateWorkerTimeout,
|
|
196
|
+
useCompressionStream,
|
|
197
|
+
useWebWorkers,
|
|
198
|
+
Deflate,
|
|
199
|
+
Inflate,
|
|
200
|
+
CompressionStream,
|
|
201
|
+
DecompressionStream,
|
|
202
|
+
workerScripts
|
|
203
|
+
} = configuration;
|
|
204
|
+
setIfDefined("baseURL", baseURL);
|
|
205
|
+
setIfDefined("chunkSize", chunkSize);
|
|
206
|
+
setIfDefined("maxWorkers", maxWorkers);
|
|
207
|
+
setIfDefined("terminateWorkerTimeout", terminateWorkerTimeout);
|
|
208
|
+
setIfDefined("useCompressionStream", useCompressionStream);
|
|
209
|
+
setIfDefined("useWebWorkers", useWebWorkers);
|
|
210
|
+
if (Deflate) {
|
|
211
|
+
config.CompressionStream = new StreamAdapter(Deflate);
|
|
212
|
+
}
|
|
213
|
+
if (Inflate) {
|
|
214
|
+
config.DecompressionStream = new StreamAdapter(Inflate);
|
|
215
|
+
}
|
|
216
|
+
setIfDefined("CompressionStream", CompressionStream);
|
|
217
|
+
setIfDefined("DecompressionStream", DecompressionStream);
|
|
218
|
+
if (workerScripts !== UNDEFINED_VALUE) {
|
|
219
|
+
const { deflate, inflate } = workerScripts;
|
|
220
|
+
if (deflate || inflate) {
|
|
221
|
+
if (!config.workerScripts) {
|
|
222
|
+
config.workerScripts = {};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (deflate) {
|
|
226
|
+
if (!Array.isArray(deflate)) {
|
|
227
|
+
throw new Error("workerScripts.deflate must be an array");
|
|
228
|
+
}
|
|
229
|
+
config.workerScripts.deflate = deflate;
|
|
230
|
+
}
|
|
231
|
+
if (inflate) {
|
|
232
|
+
if (!Array.isArray(inflate)) {
|
|
233
|
+
throw new Error("workerScripts.inflate must be an array");
|
|
234
|
+
}
|
|
235
|
+
config.workerScripts.inflate = inflate;
|
|
149
236
|
}
|
|
150
|
-
return result;
|
|
151
|
-
} else {
|
|
152
|
-
return new TextEncoder().encode(value);
|
|
153
237
|
}
|
|
154
238
|
}
|
|
155
239
|
|
|
156
|
-
|
|
240
|
+
function setIfDefined(propertyName, propertyValue) {
|
|
241
|
+
if (propertyValue !== UNDEFINED_VALUE) {
|
|
242
|
+
config[propertyName] = propertyValue;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
157
245
|
|
|
158
|
-
/*// deno-lint-ignore-file no-this-alias *
|
|
246
|
+
function e(e){const t=()=>URL.createObjectURL(new Blob(['const{Array:e,Object:t,Math:n,Error:r,Uint8Array:s,Uint16Array:i,Uint32Array:o,Int32Array:c,Map:f,DataView:a,Promise:l,TextEncoder:u,crypto:w,postMessage:h,TransformStream:d,ReadableStream:p,WritableStream:y,CompressionStream:m,DecompressionStream:b}=self;class g{constructor(e){return class extends d{constructor(t){const n=new e(t);super({transform(e,t){t.enqueue(n.append(e))},flush(e){const t=n.flush();t&&e.enqueue(t)}})}}}}const k=[];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;k[e]=t}class v{constructor(e){this.t=e||-1}append(e){let t=0|this.t;for(let n=0,r=0|e.length;r>n;n++)t=t>>>8^k[255&(t^e[n])];this.t=t}get(){return~this.t}}class S extends d{constructor(){const e=new v;super({transform(t){e.append(t)},flush(t){const n=new s(4);new a(n.buffer).setUint32(0,e.get()),t.enqueue(n)}})}}const z={concat(e,t){if(0===e.length||0===t.length)return e.concat(t);const n=e[e.length-1],r=z.i(n);return 32===r?e.concat(t):z.o(t,r,0|n,e.slice(0,e.length-1))},l(e){const t=e.length;if(0===t)return 0;const n=e[t-1];return 32*(t-1)+z.i(n)},u(e,t){if(32*e.length<t)return e;const r=(e=e.slice(0,n.ceil(t/32))).length;return t&=31,r>0&&t&&(e[r-1]=z.h(t,e[r-1]&2147483648>>t-1,1)),e},h:(e,t,n)=>32===e?t:(n?0|t:t<<32-e)+1099511627776*e,i:e=>n.round(e/1099511627776)||32,o(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,i=z.i(s);return r.push(z.h(t+i&31,t+i>32?n:r.pop(),1)),r}},_={p:{m(e){const t=z.l(e)/8,n=new s(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},g(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.h(8*(3&n),r)),t}}},C={k:function(e){e?(this.v=e.v.slice(0),this.S=e.S.slice(0),this._=e._):this.reset()}};C.k.prototype={blockSize:512,reset(){const e=this;return e.v=this.C.slice(0),e.S=[],e._=0,e},update(e){const t=this;"string"==typeof e&&(e=_.I.g(e));const n=t.S=z.concat(t.S,e),s=t._,i=t._=s+z.l(e);if(i>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new o(n);let f=0;for(let e=t.blockSize+s-(t.blockSize+s&t.blockSize-1);i>=e;e+=t.blockSize)t.A(c.subarray(16*f,16*(f+1))),f+=1;return n.splice(0,16*f),t},D(){const e=this;let t=e.S;const r=e.v;t=z.concat(t,[z.h(1,1)]);for(let e=t.length+2;15&e;e++)t.push(0);for(t.push(n.floor(e._/4294967296)),t.push(0|e._);t.length;)e.A(t.splice(0,16));return e.reset(),r},C:[1732584193,4023233417,2562383102,271733878,3285377520],V:[1518500249,1859775393,2400959708,3395469782],R:(e,t,n,r)=>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,B:(e,t)=>t<<e|t>>>32-e,A(t){const r=this,s=r.v,i=e(80);for(let e=0;16>e;e++)i[e]=t[e];let o=s[0],c=s[1],f=s[2],a=s[3],l=s[4];for(let e=0;79>=e;e++){16>e||(i[e]=r.B(1,i[e-3]^i[e-8]^i[e-14]^i[e-16]));const t=r.B(5,o)+r.R(e,c,f,a)+l+i[e]+r.V[n.floor(e/20)]|0;l=a,a=f,f=r.B(30,c),c=o,o=t}s[0]=s[0]+o|0,s[1]=s[1]+c|0,s[2]=s[2]+f|0,s[3]=s[3]+a|0,s[4]=s[4]+l|0}};const I={getRandomValues(e){const t=new o(e.buffer),r=e=>{let t=987654321;const r=4294967295;return()=>(t=36969*(65535&t)+(t>>16)&r,(((t<<16)+(e=18e3*(65535&e)+(e>>16)&r)&r)/4294967296+.5)*(n.random()>.5?1:-1))};for(let s,i=0;i<e.length;i+=4){const e=r(4294967296*(s||n.random()));s=987654071*e(),t[i/4]=4294967296*e()|0}return e}},x={importKey:e=>new x.M(_.p.g(e)),K(e,t,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const i=1+(s>>5)<<2;let o,c,f,l,u;const w=new ArrayBuffer(i),h=new a(w);let d=0;const p=z;for(t=_.p.g(t),u=1;(i||1)>d;u++){for(o=c=e.encrypt(p.concat(t,[u])),f=1;n>f;f++)for(c=e.encrypt(c),l=0;l<c.length;l++)o[l]^=c[l];for(f=0;(i||1)>d&&f<o.length;f++)h.setInt32(d,o[f]),d+=4}return w.slice(0,s/8)},M:class{constructor(e){const t=this,n=t.N=C.k,r=[[],[]],s=n.prototype.blockSize/32;t.P=[new n,new n],e.length>s&&(e=n.hash(e));for(let t=0;s>t;t++)r[0][t]=909522486^e[t],r[1][t]=1549556828^e[t];t.P[0].update(r[0]),t.P[1].update(r[1]),t.U=new n(t.P[0])}reset(){const e=this;e.U=new e.N(e.P[0]),e.T=!1}update(e){this.T=!0,this.U.update(e)}digest(){const e=this,t=e.U.D(),n=new e.N(e.P[1]).update(t).D();return e.reset(),n}encrypt(e){if(this.T)throw new r("encrypt on already updated hmac called!");return this.update(e),this.digest(e)}}},A=void 0!==w&&"function"==typeof w.getRandomValues;function D(e){return A?w.getRandomValues(e):I.getRandomValues(e)}const V={name:"PBKDF2"},R=t.assign({hash:{name:"HMAC"}},V),B=t.assign({iterations:1e3,hash:{name:"SHA-1"}},V),E=["deriveBits"],M=[8,12,16],K=[16,24,32],N=[0,0,0,0],P=void 0!==w,U=P&&w.subtle,T=P&&void 0!==U,W=P&&T&&"function"==typeof U.importKey,H=P&&T&&"function"==typeof U.deriveBits,L=_.p,j=class{constructor(e){const t=this;t.W=[[[],[],[],[],[]],[[],[],[],[],[]]],t.W[0][0][0]||t.H();const n=t.W[0][4],s=t.W[1],i=e.length;let o,c,f,a=1;if(4!==i&&6!==i&&8!==i)throw new r("invalid aes key size");for(t.V=[c=e.slice(0),f=[]],o=i;4*i+28>o;o++){let e=c[o-1];(o%i==0||8===i&&o%i==4)&&(e=n[e>>>24]<<24^n[e>>16&255]<<16^n[e>>8&255]<<8^n[255&e],o%i==0&&(e=e<<8^e>>>24^a<<24,a=a<<1^283*(a>>7))),c[o]=c[o-i]^e}for(let e=0;o;e++,o--){const t=c[3&e?o:o-4];f[e]=4>=o||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.L(e,0)}decrypt(e){return this.L(e,1)}H(){const e=this.W[0],t=this.W[1],n=e[4],r=t[4],s=[],i=[];let o,c,f,a;for(let e=0;256>e;e++)i[(s[e]=e<<1^283*(e>>7))^e]=e;for(let l=o=0;!n[l];l^=c||1,o=i[o]||1){let i=o^o<<1^o<<2^o<<3^o<<4;i=i>>8^255&i^99,n[l]=i,r[i]=l,a=s[f=s[c=s[l]]];let u=16843009*a^65537*f^257*c^16843008*l,w=257*s[i]^16843008*i;for(let n=0;4>n;n++)e[n][l]=w=w<<24^w>>>8,t[n][i]=u=u<<24^u>>>8}for(let n=0;5>n;n++)e[n]=e[n].slice(0),t[n]=t[n].slice(0)}L(e,t){if(4!==e.length)throw new r("invalid aes block size");const n=this.V[t],s=n.length/4-2,i=[0,0,0,0],o=this.W[t],c=o[0],f=o[1],a=o[2],l=o[3],u=o[4];let w,h,d,p=e[0]^n[0],y=e[t?3:1]^n[1],m=e[2]^n[2],b=e[t?1:3]^n[3],g=4;for(let e=0;s>e;e++)w=c[p>>>24]^f[y>>16&255]^a[m>>8&255]^l[255&b]^n[g],h=c[y>>>24]^f[m>>16&255]^a[b>>8&255]^l[255&p]^n[g+1],d=c[m>>>24]^f[b>>16&255]^a[p>>8&255]^l[255&y]^n[g+2],b=c[b>>>24]^f[p>>16&255]^a[y>>8&255]^l[255&m]^n[g+3],g+=4,p=w,y=h,m=d;for(let e=0;4>e;e++)i[t?3&-e:e]=u[p>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&b]^n[g++],w=p,p=y,y=m,m=b,b=w;return i}},F=class{constructor(e,t){this.j=e,this.F=t,this.O=t}reset(){this.O=this.F}update(e){return this.q(this.j,e,this.O)}G(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}J(e){0===(e[0]=this.G(e[0]))&&(e[1]=this.G(e[1]))}q(e,t,n){let r;if(!(r=t.length))return[];const s=z.l(t);for(let s=0;r>s;s+=4){this.J(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.u(t,s)}},O=x.M;class q extends d{constructor(e,n,i){super({start(){t.assign(this,{ready:new l((e=>this.X=e)),password:e,signed:n,Y:i-1,pending:new s})},async transform(e,t){const n=this,{password:i,Y:o,X:c,ready:f}=n;i?(await(async(e,t,n,s)=>{const i=await Q(e,t,n,Y(s,0,M[t])),o=Y(s,M[t]);if(i[0]!=o[0]||i[1]!=o[1])throw new r("Invalid password")})(n,o,i,Y(e,0,M[o]+2)),e=Y(e,M[o]+2),c()):await f;const a=new s(e.length-10-(e.length-10)%16);t.enqueue(J(n,e,a,0,10,!0))},async flush(e){const{signed:t,Z:n,$:i,pending:o,ready:c}=this;await c;const f=Y(o,0,o.length-10),a=Y(o,o.length-10);let l=new s;if(f.length){const e=$(L,f);i.update(e);const t=n.update(e);l=Z(L,t)}if(t){const e=Y(Z(L,i.digest()),0,10);for(let t=0;10>t;t++)if(e[t]!=a[t])throw new r("Invalid signature")}e.enqueue(l)}})}}class G extends d{constructor(e,n){let r;super({start(){t.assign(this,{ready:new l((e=>this.X=e)),password:e,Y:n-1,pending:new s})},async transform(e,t){const n=this,{password:r,Y:i,X:o,ready:c}=n;let f=new s;r?(f=await(async(e,t,n)=>{const r=D(new s(M[t]));return X(r,await Q(e,t,n,r))})(n,i,r),o()):await c;const a=new s(f.length+e.length-e.length%16);a.set(f,0),t.enqueue(J(n,e,a,f.length,0))},async flush(e){const{Z:t,$:n,pending:i,ready:o}=this;await o;let c=new s;if(i.length){const e=t.update($(L,i));n.update(e),c=Z(L,e)}r.signature=Z(L,n.digest()).slice(0,10),e.enqueue(X(c,r.signature))}}),r=this}}function J(e,t,n,r,i,o){const{Z:c,$:f,pending:a}=e,l=t.length-i;let u;for(a.length&&(t=X(a,t),n=((e,t)=>{if(t&&t>e.length){const n=e;(e=new s(t)).set(n,0)}return e})(n,l-l%16)),u=0;l-16>=u;u+=16){const e=$(L,Y(t,u,u+16));o&&f.update(e);const s=c.update(e);o||f.update(s),n.set(Z(L,s),u+r)}return e.pending=Y(t,u),n}async function Q(n,r,i,o){n.password=null;const c=(e=>{if(void 0===u){const t=new s((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)})(i),f=await((e,t,n,r,s)=>W?U.importKey("raw",t,n,!1,s):x.importKey(t))(0,c,R,0,E),a=await(async(e,t,n)=>H?await U.deriveBits(e,t,n):x.K(t,e.salt,B.iterations,n))(t.assign({salt:o},B),f,8*(2*K[r]+2)),l=new s(a),w=$(L,Y(l,0,K[r])),h=$(L,Y(l,K[r],2*K[r])),d=Y(l,2*K[r]);return t.assign(n,{keys:{key:w,ee:h,passwordVerification:d},Z:new F(new j(w),e.from(N)),$:new O(h)}),d}function X(e,t){let n=e;return e.length+t.length&&(n=new s(e.length+t.length),n.set(e,0),n.set(t,e.length)),n}function Y(e,t,n){return e.subarray(t,n)}function Z(e,t){return e.m(t)}function $(e,t){return e.g(t)}class ee extends d{constructor(e,n){super({start(){t.assign(this,{password:e,passwordVerification:n}),se(this,e)},transform(e,t){const n=this;if(n.password){const t=ne(n,e.subarray(0,12));if(n.password=null,t[11]!=n.passwordVerification)throw new r("Invalid password");e=e.subarray(12)}t.enqueue(ne(n,e))}})}}class te extends d{constructor(e,n){super({start(){t.assign(this,{password:e,passwordVerification:n}),se(this,e)},transform(e,t){const n=this;let r,i;if(n.password){n.password=null;const t=D(new s(12));t[11]=n.passwordVerification,r=new s(e.length+t.length),r.set(re(n,t),0),i=12}else r=new s(e.length),i=0;r.set(re(n,e),i),t.enqueue(r)}})}}function ne(e,t){const n=new s(t.length);for(let r=0;r<t.length;r++)n[r]=oe(e)^t[r],ie(e,n[r]);return n}function re(e,t){const n=new s(t.length);for(let r=0;r<t.length;r++)n[r]=oe(e)^t[r],ie(e,t[r]);return n}function se(e,n){const r=[305419896,591751049,878082192];t.assign(e,{keys:r,te:new v(r[0]),ne:new v(r[2])});for(let t=0;t<n.length;t++)ie(e,n.charCodeAt(t))}function ie(e,t){let[r,s,i]=e.keys;e.te.append([t]),r=~e.te.get(),s=fe(n.imul(fe(s+ce(r)),134775813)+1),e.ne.append([s>>>24]),i=~e.ne.get(),e.keys=[r,s,i]}function oe(e){const t=2|e.keys[2];return ce(n.imul(t,1^t)>>>8)}function ce(e){return 255&e}function fe(e){return 4294967295&e}class ae extends d{constructor(e,{chunkSize:t,CompressionStream:n,re:r}){super({});const{compressed:s,encrypted:i,useCompressionStream:o,password:c,passwordVerification:f,encryptionStrength:l,zipCrypto:u,signed:w,level:h}=e,d=this;let p,y,m=ue(super.readable);i&&!u||!w||([m,p]=m.tee(),p=de(p,new S)),s&&(m=he(m,o,{level:h,chunkSize:t},r,n)),i&&(u?m=de(m,new te(c,f)):(y=new G(c,l),m=de(m,y))),we(d,m,(async()=>{let e;i&&!u&&(e=y.signature),i&&!u||!w||(e=await p.getReader().read(),e=new a(e.value.buffer).getUint32(0)),d.signature=e}))}}class le extends d{constructor(e,{chunkSize:t,DecompressionStream:n,se:s}){super({});const{zipCrypto:i,encrypted:o,password:c,passwordVerification:f,signed:l,signature:u,encryptionStrength:w,compressed:h,useCompressionStream:d}=e;let p,y,m=ue(super.readable);o&&(i?m=de(m,new ee(c,f)):(y=new q(c,l,w),m=de(m,y))),h&&(m=he(m,d,{chunkSize:t},s,n)),o&&!i||!l||([m,p]=m.tee(),p=de(p,new S)),we(this,m,(async()=>{if((!o||i)&&l){const e=await p.getReader().read(),t=new a(e.value.buffer);if(u!=t.getUint32(0,!1))throw new r("Invalid signature")}}))}}function ue(e){return de(e,new d({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function we(e,n,r){n=de(n,new d({flush:r})),t.defineProperty(e,"readable",{get:()=>n})}function he(e,t,n,r,s){try{e=de(e,new(t&&r?r:s)("deflate-raw",n))}catch(r){if(!t)throw r;e=de(e,new s("deflate-raw",n))}return e}function de(e,t){return e.pipeThrough(t)}class pe extends d{constructor(e,n){super({});const r=this,{codecType:s}=e;let i;s.startsWith("deflate")?i=ae:s.startsWith("inflate")&&(i=le);let o=0;const c=new i(e,n),f=super.readable,a=new d({transform(e,t){e&&e.length&&(o+=e.length,t.enqueue(e))},flush(){const{signature:e}=c;t.assign(r,{signature:e,size:o})}});t.defineProperty(r,"readable",{get:()=>f.pipeThrough(c).pipeThrough(a)})}}const ye=new f,me=new f;let be=0;async function ge(e){try{const{options:t,scripts:n,config:r}=e;n&&n.length&&importScripts.apply(void 0,n),self.initCodec&&self.initCodec(),r.re=self.CompressionStream,r.se=self.DecompressionStream,self.Deflate&&(r.CompressionStream=new g(self.Deflate)),self.Inflate&&(r.DecompressionStream=new g(self.Inflate));const s={highWaterMark:1,size:()=>r.chunkSize},i=e.readable||new p({async pull(e){const t=new l((e=>ye.set(be,e)));ke({type:"pull",messageId:be}),be=(be+1)%Number.MAX_SAFE_INTEGER;const{value:n,done:r}=await t;e.enqueue(n),r&&e.close()}},s),o=e.writable||new y({async write(e){let t;const n=new l((e=>t=e));me.set(be,t),ke({type:"data",data:e,messageId:be}),be=(be+1)%Number.MAX_SAFE_INTEGER,await n}},s),c=new pe(t,r);await i.pipeThrough(c).pipeTo(o,{ie:!0});try{await o.close()}catch(e){}const{signature:f,size:a}=c;ke({type:"close",result:{signature:f,size:a}})}catch(e){ve(e)}}function ke(e){if(e.data){let{data:t}=e;if(t&&t.length)try{t=new s(t),e.data=t.buffer,h(e,[e.data])}catch(t){h(e)}else h(e)}else h(e)}function ve(e){const{message:t,stack:n,code:r,name:s}=e;h({error:{message:t,stack:n,code:r,name:s}})}function Se(t){return ze(t.map((([t,n])=>new e(t).fill(n,0,t))))}function ze(t){return t.reduce(((t,n)=>t.concat(e.isArray(n)?ze(n):n)),[])}addEventListener("message",(e=>{const t=e.data,{type:n,messageId:r,data:i,done:o}=t;try{if("start"==n&&ge(t),"data"==n){const e=ye.get(r);ye.delete(r),e({value:new s(i),done:o})}if("ack"==n){const e=me.get(r);me.delete(r),e()}}catch(e){ve(e)}}));const _e=[0,1,2,3].concat(...Se([[2,4],[2,5],[4,6],[4,7],[8,8],[8,9],[16,10],[16,11],[32,12],[32,13],[64,14],[64,15],[2,0],[1,16],[1,17],[2,18],[2,19],[4,20],[4,21],[8,22],[8,23],[16,24],[16,25],[32,26],[32,27],[64,28],[64,29]]));function Ce(){const e=this;function t(e,t){let n=0;do{n|=1&e,e>>>=1,n<<=1}while(--t>0);return n>>>1}e.oe=r=>{const s=e.ce,i=e.ae.fe,o=e.ae.le;let c,f,a,l=-1;for(r.ue=0,r.we=573,c=0;o>c;c++)0!==s[2*c]?(r.he[++r.ue]=l=c,r.de[c]=0):s[2*c+1]=0;for(;2>r.ue;)a=r.he[++r.ue]=2>l?++l:0,s[2*a]=1,r.de[a]=0,r.pe--,i&&(r.ye-=i[2*a+1]);for(e.me=l,c=n.floor(r.ue/2);c>=1;c--)r.be(s,c);a=o;do{c=r.he[1],r.he[1]=r.he[r.ue--],r.be(s,1),f=r.he[1],r.he[--r.we]=c,r.he[--r.we]=f,s[2*a]=s[2*c]+s[2*f],r.de[a]=n.max(r.de[c],r.de[f])+1,s[2*c+1]=s[2*f+1]=a,r.he[1]=a++,r.be(s,1)}while(r.ue>=2);r.he[--r.we]=r.he[1],(t=>{const n=e.ce,r=e.ae.fe,s=e.ae.ge,i=e.ae.ke,o=e.ae.ve;let c,f,a,l,u,w,h=0;for(l=0;15>=l;l++)t.Se[l]=0;for(n[2*t.he[t.we]+1]=0,c=t.we+1;573>c;c++)f=t.he[c],l=n[2*n[2*f+1]+1]+1,l>o&&(l=o,h++),n[2*f+1]=l,f>e.me||(t.Se[l]++,u=0,i>f||(u=s[f-i]),w=n[2*f],t.pe+=w*(l+u),r&&(t.ye+=w*(r[2*f+1]+u)));if(0!==h){do{for(l=o-1;0===t.Se[l];)l--;t.Se[l]--,t.Se[l+1]+=2,t.Se[o]--,h-=2}while(h>0);for(l=o;0!==l;l--)for(f=t.Se[l];0!==f;)a=t.he[--c],a>e.me||(n[2*a+1]!=l&&(t.pe+=(l-n[2*a+1])*n[2*a],n[2*a+1]=l),f--)}})(r),((e,n,r)=>{const s=[];let i,o,c,f=0;for(i=1;15>=i;i++)s[i]=f=f+r[i-1]<<1;for(o=0;n>=o;o++)c=e[2*o+1],0!==c&&(e[2*o]=t(s[c]++,c))})(s,e.me,r.Se)}}function Ie(e,t,n,r,s){const i=this;i.fe=e,i.ge=t,i.ke=n,i.le=r,i.ve=s}Ce.ze=[0,1,2,3,4,5,6,7].concat(...Se([[2,8],[2,9],[2,10],[2,11],[4,12],[4,13],[4,14],[4,15],[8,16],[8,17],[8,18],[8,19],[16,20],[16,21],[16,22],[16,23],[32,24],[32,25],[32,26],[31,27],[1,28]])),Ce._e=[0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224,0],Ce.Ce=[0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576],Ce.Ie=e=>256>e?_e[e]:_e[256+(e>>>7)],Ce.xe=[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],Ce.Ae=[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],Ce.De=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],Ce.Ve=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];const xe=Se([[144,8],[112,9],[24,7],[8,8]]);Ie.Re=ze([12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,19,275,147,403,83,339,211,467,51,307,179,435,115,371,243,499,11,267,139,395,75,331,203,459,43,299,171,427,107,363,235,491,27,283,155,411,91,347,219,475,59,315,187,443,123,379,251,507,7,263,135,391,71,327,199,455,39,295,167,423,103,359,231,487,23,279,151,407,87,343,215,471,55,311,183,439,119,375,247,503,15,271,143,399,79,335,207,463,47,303,175,431,111,367,239,495,31,287,159,415,95,351,223,479,63,319,191,447,127,383,255,511,0,64,32,96,16,80,48,112,8,72,40,104,24,88,56,120,4,68,36,100,20,84,52,116,3,131,67,195,35,163,99,227].map(((e,t)=>[e,xe[t]])));const Ae=Se([[30,5]]);function De(e,t,n,r,s){const i=this;i.Be=e,i.Ee=t,i.Me=n,i.Ke=r,i.Ne=s}Ie.Pe=ze([0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30,1,17,9,25,5,21,13,29,3,19,11,27,7,23].map(((e,t)=>[e,Ae[t]]))),Ie.Ue=new Ie(Ie.Re,Ce.xe,257,286,15),Ie.Te=new Ie(Ie.Pe,Ce.Ae,0,30,15),Ie.We=new Ie(null,Ce.De,0,19,7);const Ve=[new De(0,0,0,0,0),new De(4,4,8,4,1),new De(4,5,16,8,1),new De(4,6,32,32,1),new De(4,4,16,16,2),new De(8,16,32,32,2),new De(8,16,128,128,2),new De(8,32,128,256,2),new De(32,128,258,1024,2),new De(32,258,258,4096,2)],Re=["need dictionary","stream end","","","stream error","data error","","buffer error","",""];function Be(e,t,n,r){const s=e[2*t],i=e[2*n];return i>s||s==i&&r[t]<=r[n]}function Ee(){const e=this;let t,r,o,c,f,a,l,u,w,h,d,p,y,m,b,g,k,v,S,z,_,C,I,x,A,D,V,R,B,E,M,K,N;const P=new Ce,U=new Ce,T=new Ce;let W,H,L,j,F,O;function q(){let t;for(t=0;286>t;t++)M[2*t]=0;for(t=0;30>t;t++)K[2*t]=0;for(t=0;19>t;t++)N[2*t]=0;M[512]=1,e.pe=e.ye=0,H=L=0}function G(e,t){let n,r=-1,s=e[1],i=0,o=7,c=4;0===s&&(o=138,c=3),e[2*(t+1)+1]=65535;for(let f=0;t>=f;f++)n=s,s=e[2*(f+1)+1],++i<o&&n==s||(c>i?N[2*n]+=i:0!==n?(n!=r&&N[2*n]++,N[32]++):i>10?N[36]++:N[34]++,i=0,r=n,0===s?(o=138,c=3):n==s?(o=6,c=3):(o=7,c=4))}function J(t){e.He[e.pending++]=t}function Q(e){J(255&e),J(e>>>8&255)}function X(e,t){let n;const r=t;O>16-r?(n=e,F|=n<<O&65535,Q(F),F=n>>>16-O,O+=r-16):(F|=e<<O&65535,O+=r)}function Y(e,t){const n=2*e;X(65535&t[n],65535&t[n+1])}function Z(e,t){let n,r,s=-1,i=e[1],o=0,c=7,f=4;for(0===i&&(c=138,f=3),n=0;t>=n;n++)if(r=i,i=e[2*(n+1)+1],++o>=c||r!=i){if(f>o)do{Y(r,N)}while(0!=--o);else 0!==r?(r!=s&&(Y(r,N),o--),Y(16,N),X(o-3,2)):o>10?(Y(18,N),X(o-11,7)):(Y(17,N),X(o-3,3));o=0,s=r,0===i?(c=138,f=3):r==i?(c=6,f=3):(c=7,f=4)}}function $(){16==O?(Q(F),F=0,O=0):8>O||(J(255&F),F>>>=8,O-=8)}function ee(t,r){let s,i,o;if(e.Le[H]=t,e.je[H]=255&r,H++,0===t?M[2*r]++:(L++,t--,M[2*(Ce.ze[r]+256+1)]++,K[2*Ce.Ie(t)]++),0==(8191&H)&&V>2){for(s=8*H,i=_-k,o=0;30>o;o++)s+=K[2*o]*(5+Ce.Ae[o]);if(s>>>=3,L<n.floor(H/2)&&s<n.floor(i/2))return!0}return H==W-1}function te(t,n){let r,s,i,o,c=0;if(0!==H)do{r=e.Le[c],s=e.je[c],c++,0===r?Y(s,t):(i=Ce.ze[s],Y(i+256+1,t),o=Ce.xe[i],0!==o&&(s-=Ce._e[i],X(s,o)),r--,i=Ce.Ie(r),Y(i,n),o=Ce.Ae[i],0!==o&&(r-=Ce.Ce[i],X(r,o)))}while(H>c);Y(256,t),j=t[513]}function ne(){O>8?Q(F):O>0&&J(255&F),F=0,O=0}function re(t,n,r){X(0+(r?1:0),3),((t,n)=>{ne(),j=8,Q(n),Q(~n),e.He.set(u.subarray(t,t+n),e.pending),e.pending+=n})(t,n)}function se(n){((t,n,r)=>{let s,i,o=0;V>0?(P.oe(e),U.oe(e),o=(()=>{let t;for(G(M,P.me),G(K,U.me),T.oe(e),t=18;t>=3&&0===N[2*Ce.Ve[t]+1];t--);return e.pe+=14+3*(t+1),t})(),s=e.pe+3+7>>>3,i=e.ye+3+7>>>3,i>s||(s=i)):s=i=n+5,n+4>s||-1==t?i==s?(X(2+(r?1:0),3),te(Ie.Re,Ie.Pe)):(X(4+(r?1:0),3),((e,t,n)=>{let r;for(X(e-257,5),X(t-1,5),X(n-4,4),r=0;n>r;r++)X(N[2*Ce.Ve[r]+1],3);Z(M,e-1),Z(K,t-1)})(P.me+1,U.me+1,o+1),te(M,K)):re(t,n,r),q(),r&&ne()})(0>k?-1:k,_-k,n),k=_,t.Fe()}function ie(){let e,n,r,s;do{if(s=w-I-_,0===s&&0===_&&0===I)s=f;else if(-1==s)s--;else if(_>=f+f-262){u.set(u.subarray(f,f+f),0),C-=f,_-=f,k-=f,e=y,r=e;do{n=65535&d[--r],d[r]=f>n?0:n-f}while(0!=--e);e=f,r=e;do{n=65535&h[--r],h[r]=f>n?0:n-f}while(0!=--e);s+=f}if(0===t.Oe)return;e=t.qe(u,_+I,s),I+=e,3>I||(p=255&u[_],p=(p<<g^255&u[_+1])&b)}while(262>I&&0!==t.Oe)}function oe(e){let t,n,r=A,s=_,i=x;const o=_>f-262?_-(f-262):0;let c=E;const a=l,w=_+258;let d=u[s+i-1],p=u[s+i];B>x||(r>>=2),c>I&&(c=I);do{if(t=e,u[t+i]==p&&u[t+i-1]==d&&u[t]==u[s]&&u[++t]==u[s+1]){s+=2,t++;do{}while(u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&w>s);if(n=258-(w-s),s=w-258,n>i){if(C=e,i=n,n>=c)break;d=u[s+i-1],p=u[s+i]}}}while((e=65535&h[e&a])>o&&0!=--r);return i>I?I:i}e.de=[],e.Se=[],e.he=[],M=[],K=[],N=[],e.be=(t,n)=>{const r=e.he,s=r[n];let i=n<<1;for(;i<=e.ue&&(i<e.ue&&Be(t,r[i+1],r[i],e.de)&&i++,!Be(t,s,r[i],e.de));)r[n]=r[i],n=i,i<<=1;r[n]=s},e.Ge=(t,S,C,H,L,G)=>(H||(H=8),L||(L=8),G||(G=0),t.Je=null,-1==S&&(S=6),1>L||L>9||8!=H||9>C||C>15||0>S||S>9||0>G||G>2?-2:(t.Qe=e,a=C,f=1<<a,l=f-1,m=L+7,y=1<<m,b=y-1,g=n.floor((m+3-1)/3),u=new s(2*f),h=[],d=[],W=1<<L+6,e.He=new s(4*W),o=4*W,e.Le=new i(W),e.je=new s(W),V=S,R=G,(t=>(t.Xe=t.Ye=0,t.Je=null,e.pending=0,e.Ze=0,r=113,c=0,P.ce=M,P.ae=Ie.Ue,U.ce=K,U.ae=Ie.Te,T.ce=N,T.ae=Ie.We,F=0,O=0,j=8,q(),(()=>{w=2*f,d[y-1]=0;for(let e=0;y-1>e;e++)d[e]=0;D=Ve[V].Ee,B=Ve[V].Be,E=Ve[V].Me,A=Ve[V].Ke,_=0,k=0,I=0,v=x=2,z=0,p=0})(),0))(t))),e.$e=()=>42!=r&&113!=r&&666!=r?-2:(e.je=null,e.Le=null,e.He=null,d=null,h=null,u=null,e.Qe=null,113==r?-3:0),e.et=(e,t,n)=>{let r=0;return-1==t&&(t=6),0>t||t>9||0>n||n>2?-2:(Ve[V].Ne!=Ve[t].Ne&&0!==e.Xe&&(r=e.tt(1)),V!=t&&(V=t,D=Ve[V].Ee,B=Ve[V].Be,E=Ve[V].Me,A=Ve[V].Ke),R=n,r)},e.nt=(e,t,n)=>{let s,i=n,o=0;if(!t||42!=r)return-2;if(3>i)return 0;for(i>f-262&&(i=f-262,o=n-i),u.set(t.subarray(o,o+i),0),_=i,k=i,p=255&u[0],p=(p<<g^255&u[1])&b,s=0;i-3>=s;s++)p=(p<<g^255&u[s+2])&b,h[s&l]=d[p],d[p]=s;return 0},e.tt=(n,s)=>{let i,w,m,A,B;if(s>4||0>s)return-2;if(!n.rt||!n.st&&0!==n.Oe||666==r&&4!=s)return n.Je=Re[4],-2;if(0===n.it)return n.Je=Re[7],-5;var E;if(t=n,A=c,c=s,42==r&&(w=8+(a-8<<4)<<8,m=(V-1&255)>>1,m>3&&(m=3),w|=m<<6,0!==_&&(w|=32),w+=31-w%31,r=113,J((E=w)>>8&255),J(255&E)),0!==e.pending){if(t.Fe(),0===t.it)return c=-1,0}else if(0===t.Oe&&A>=s&&4!=s)return t.Je=Re[7],-5;if(666==r&&0!==t.Oe)return n.Je=Re[7],-5;if(0!==t.Oe||0!==I||0!=s&&666!=r){switch(B=-1,Ve[V].Ne){case 0:B=(e=>{let n,r=65535;for(r>o-5&&(r=o-5);;){if(1>=I){if(ie(),0===I&&0==e)return 0;if(0===I)break}if(_+=I,I=0,n=k+r,(0===_||_>=n)&&(I=_-n,_=n,se(!1),0===t.it))return 0;if(_-k>=f-262&&(se(!1),0===t.it))return 0}return se(4==e),0===t.it?4==e?2:0:4==e?3:1})(s);break;case 1:B=(e=>{let n,r=0;for(;;){if(262>I){if(ie(),262>I&&0==e)return 0;if(0===I)break}if(3>I||(p=(p<<g^255&u[_+2])&b,r=65535&d[p],h[_&l]=d[p],d[p]=_),0===r||(_-r&65535)>f-262||2!=R&&(v=oe(r)),3>v)n=ee(0,255&u[_]),I--,_++;else if(n=ee(_-C,v-3),I-=v,v>D||3>I)_+=v,v=0,p=255&u[_],p=(p<<g^255&u[_+1])&b;else{v--;do{_++,p=(p<<g^255&u[_+2])&b,r=65535&d[p],h[_&l]=d[p],d[p]=_}while(0!=--v);_++}if(n&&(se(!1),0===t.it))return 0}return se(4==e),0===t.it?4==e?2:0:4==e?3:1})(s);break;case 2:B=(e=>{let n,r,s=0;for(;;){if(262>I){if(ie(),262>I&&0==e)return 0;if(0===I)break}if(3>I||(p=(p<<g^255&u[_+2])&b,s=65535&d[p],h[_&l]=d[p],d[p]=_),x=v,S=C,v=2,0!==s&&D>x&&f-262>=(_-s&65535)&&(2!=R&&(v=oe(s)),5>=v&&(1==R||3==v&&_-C>4096)&&(v=2)),3>x||v>x)if(0!==z){if(n=ee(0,255&u[_-1]),n&&se(!1),_++,I--,0===t.it)return 0}else z=1,_++,I--;else{r=_+I-3,n=ee(_-1-S,x-3),I-=x-1,x-=2;do{++_>r||(p=(p<<g^255&u[_+2])&b,s=65535&d[p],h[_&l]=d[p],d[p]=_)}while(0!=--x);if(z=0,v=2,_++,n&&(se(!1),0===t.it))return 0}}return 0!==z&&(n=ee(0,255&u[_-1]),z=0),se(4==e),0===t.it?4==e?2:0:4==e?3:1})(s)}if(2!=B&&3!=B||(r=666),0==B||2==B)return 0===t.it&&(c=-1),0;if(1==B){if(1==s)X(2,3),Y(256,Ie.Re),$(),9>1+j+10-O&&(X(2,3),Y(256,Ie.Re),$()),j=7;else if(re(0,0,!1),3==s)for(i=0;y>i;i++)d[i]=0;if(t.Fe(),0===t.it)return c=-1,0}}return 4!=s?0:1}}function Me(){const e=this;e.ot=0,e.ct=0,e.Oe=0,e.Xe=0,e.it=0,e.Ye=0}function Ke(e){const t=new Me,i=(o=e&&e.chunkSize?e.chunkSize:65536)+5*(n.floor(o/16383)+1);var o;const c=new s(i);let f=e?e.level:-1;void 0===f&&(f=-1),t.Ge(f),t.rt=c,this.append=(e,n)=>{let o,f,a=0,l=0,u=0;const w=[];if(e.length){t.ot=0,t.st=e,t.Oe=e.length;do{if(t.ct=0,t.it=i,o=t.tt(0),0!=o)throw new r("deflating: "+t.Je);t.ct&&(t.ct==i?w.push(new s(c)):w.push(c.slice(0,t.ct))),u+=t.ct,n&&t.ot>0&&t.ot!=a&&(n(t.ot),a=t.ot)}while(t.Oe>0||0===t.it);return w.length>1?(f=new s(u),w.forEach((e=>{f.set(e,l),l+=e.length}))):f=w[0]||new s,f}},this.flush=()=>{let e,n,o=0,f=0;const a=[];do{if(t.ct=0,t.it=i,e=t.tt(4),1!=e&&0!=e)throw new r("deflating: "+t.Je);i-t.it>0&&a.push(c.slice(0,t.ct)),f+=t.ct}while(t.Oe>0||0===t.it);return t.$e(),n=new s(f),a.forEach((e=>{n.set(e,o),o+=e.length})),n}}Me.prototype={Ge(e,t){const n=this;return n.Qe=new Ee,t||(t=15),n.Qe.Ge(n,e,t)},tt(e){const t=this;return t.Qe?t.Qe.tt(t,e):-2},$e(){const e=this;if(!e.Qe)return-2;const t=e.Qe.$e();return e.Qe=null,t},et(e,t){const n=this;return n.Qe?n.Qe.et(n,e,t):-2},nt(e,t){const n=this;return n.Qe?n.Qe.nt(n,e,t):-2},qe(e,t,n){const r=this;let s=r.Oe;return s>n&&(s=n),0===s?0:(r.Oe-=s,e.set(r.st.subarray(r.ot,r.ot+s),t),r.ot+=s,r.Xe+=s,s)},Fe(){const e=this;let t=e.Qe.pending;t>e.it&&(t=e.it),0!==t&&(e.rt.set(e.Qe.He.subarray(e.Qe.Ze,e.Qe.Ze+t),e.ct),e.ct+=t,e.Qe.Ze+=t,e.Ye+=t,e.it-=t,e.Qe.pending-=t,0===e.Qe.pending&&(e.Qe.Ze=0))}};const Ne=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Pe=[96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,192,80,7,10,0,8,96,0,8,32,0,9,160,0,8,0,0,8,128,0,8,64,0,9,224,80,7,6,0,8,88,0,8,24,0,9,144,83,7,59,0,8,120,0,8,56,0,9,208,81,7,17,0,8,104,0,8,40,0,9,176,0,8,8,0,8,136,0,8,72,0,9,240,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,200,81,7,13,0,8,100,0,8,36,0,9,168,0,8,4,0,8,132,0,8,68,0,9,232,80,7,8,0,8,92,0,8,28,0,9,152,84,7,83,0,8,124,0,8,60,0,9,216,82,7,23,0,8,108,0,8,44,0,9,184,0,8,12,0,8,140,0,8,76,0,9,248,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,196,81,7,11,0,8,98,0,8,34,0,9,164,0,8,2,0,8,130,0,8,66,0,9,228,80,7,7,0,8,90,0,8,26,0,9,148,84,7,67,0,8,122,0,8,58,0,9,212,82,7,19,0,8,106,0,8,42,0,9,180,0,8,10,0,8,138,0,8,74,0,9,244,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,204,81,7,15,0,8,102,0,8,38,0,9,172,0,8,6,0,8,134,0,8,70,0,9,236,80,7,9,0,8,94,0,8,30,0,9,156,84,7,99,0,8,126,0,8,62,0,9,220,82,7,27,0,8,110,0,8,46,0,9,188,0,8,14,0,8,142,0,8,78,0,9,252,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,194,80,7,10,0,8,97,0,8,33,0,9,162,0,8,1,0,8,129,0,8,65,0,9,226,80,7,6,0,8,89,0,8,25,0,9,146,83,7,59,0,8,121,0,8,57,0,9,210,81,7,17,0,8,105,0,8,41,0,9,178,0,8,9,0,8,137,0,8,73,0,9,242,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,202,81,7,13,0,8,101,0,8,37,0,9,170,0,8,5,0,8,133,0,8,69,0,9,234,80,7,8,0,8,93,0,8,29,0,9,154,84,7,83,0,8,125,0,8,61,0,9,218,82,7,23,0,8,109,0,8,45,0,9,186,0,8,13,0,8,141,0,8,77,0,9,250,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,198,81,7,11,0,8,99,0,8,35,0,9,166,0,8,3,0,8,131,0,8,67,0,9,230,80,7,7,0,8,91,0,8,27,0,9,150,84,7,67,0,8,123,0,8,59,0,9,214,82,7,19,0,8,107,0,8,43,0,9,182,0,8,11,0,8,139,0,8,75,0,9,246,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,206,81,7,15,0,8,103,0,8,39,0,9,174,0,8,7,0,8,135,0,8,71,0,9,238,80,7,9,0,8,95,0,8,31,0,9,158,84,7,99,0,8,127,0,8,63,0,9,222,82,7,27,0,8,111,0,8,47,0,9,190,0,8,15,0,8,143,0,8,79,0,9,254,96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,193,80,7,10,0,8,96,0,8,32,0,9,161,0,8,0,0,8,128,0,8,64,0,9,225,80,7,6,0,8,88,0,8,24,0,9,145,83,7,59,0,8,120,0,8,56,0,9,209,81,7,17,0,8,104,0,8,40,0,9,177,0,8,8,0,8,136,0,8,72,0,9,241,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,201,81,7,13,0,8,100,0,8,36,0,9,169,0,8,4,0,8,132,0,8,68,0,9,233,80,7,8,0,8,92,0,8,28,0,9,153,84,7,83,0,8,124,0,8,60,0,9,217,82,7,23,0,8,108,0,8,44,0,9,185,0,8,12,0,8,140,0,8,76,0,9,249,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,197,81,7,11,0,8,98,0,8,34,0,9,165,0,8,2,0,8,130,0,8,66,0,9,229,80,7,7,0,8,90,0,8,26,0,9,149,84,7,67,0,8,122,0,8,58,0,9,213,82,7,19,0,8,106,0,8,42,0,9,181,0,8,10,0,8,138,0,8,74,0,9,245,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,205,81,7,15,0,8,102,0,8,38,0,9,173,0,8,6,0,8,134,0,8,70,0,9,237,80,7,9,0,8,94,0,8,30,0,9,157,84,7,99,0,8,126,0,8,62,0,9,221,82,7,27,0,8,110,0,8,46,0,9,189,0,8,14,0,8,142,0,8,78,0,9,253,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,195,80,7,10,0,8,97,0,8,33,0,9,163,0,8,1,0,8,129,0,8,65,0,9,227,80,7,6,0,8,89,0,8,25,0,9,147,83,7,59,0,8,121,0,8,57,0,9,211,81,7,17,0,8,105,0,8,41,0,9,179,0,8,9,0,8,137,0,8,73,0,9,243,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,203,81,7,13,0,8,101,0,8,37,0,9,171,0,8,5,0,8,133,0,8,69,0,9,235,80,7,8,0,8,93,0,8,29,0,9,155,84,7,83,0,8,125,0,8,61,0,9,219,82,7,23,0,8,109,0,8,45,0,9,187,0,8,13,0,8,141,0,8,77,0,9,251,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,199,81,7,11,0,8,99,0,8,35,0,9,167,0,8,3,0,8,131,0,8,67,0,9,231,80,7,7,0,8,91,0,8,27,0,9,151,84,7,67,0,8,123,0,8,59,0,9,215,82,7,19,0,8,107,0,8,43,0,9,183,0,8,11,0,8,139,0,8,75,0,9,247,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,207,81,7,15,0,8,103,0,8,39,0,9,175,0,8,7,0,8,135,0,8,71,0,9,239,80,7,9,0,8,95,0,8,31,0,9,159,84,7,99,0,8,127,0,8,63,0,9,223,82,7,27,0,8,111,0,8,47,0,9,191,0,8,15,0,8,143,0,8,79,0,9,255],Ue=[80,5,1,87,5,257,83,5,17,91,5,4097,81,5,5,89,5,1025,85,5,65,93,5,16385,80,5,3,88,5,513,84,5,33,92,5,8193,82,5,9,90,5,2049,86,5,129,192,5,24577,80,5,2,87,5,385,83,5,25,91,5,6145,81,5,7,89,5,1537,85,5,97,93,5,24577,80,5,4,88,5,769,84,5,49,92,5,12289,82,5,13,90,5,3073,86,5,193,192,5,24577],Te=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],We=[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,112,112],He=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],Le=[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];function je(){let e,t,n,r,s,i;function o(e,t,o,c,f,a,l,u,w,h,d){let p,y,m,b,g,k,v,S,z,_,C,I,x,A,D;_=0,g=o;do{n[e[t+_]]++,_++,g--}while(0!==g);if(n[0]==o)return l[0]=-1,u[0]=0,0;for(S=u[0],k=1;15>=k&&0===n[k];k++);for(v=k,k>S&&(S=k),g=15;0!==g&&0===n[g];g--);for(m=g,S>g&&(S=g),u[0]=S,A=1<<k;g>k;k++,A<<=1)if(0>(A-=n[k]))return-3;if(0>(A-=n[g]))return-3;for(n[g]+=A,i[1]=k=0,_=1,x=2;0!=--g;)i[x]=k+=n[_],x++,_++;g=0,_=0;do{0!==(k=e[t+_])&&(d[i[k]++]=g),_++}while(++g<o);for(o=i[m],i[0]=g=0,_=0,b=-1,I=-S,s[0]=0,C=0,D=0;m>=v;v++)for(p=n[v];0!=p--;){for(;v>I+S;){if(b++,I+=S,D=m-I,D=D>S?S:D,(y=1<<(k=v-I))>p+1&&(y-=p+1,x=v,D>k))for(;++k<D&&(y<<=1)>n[++x];)y-=n[x];if(D=1<<k,h[0]+D>1440)return-3;s[b]=C=h[0],h[0]+=D,0!==b?(i[b]=g,r[0]=k,r[1]=S,k=g>>>I-S,r[2]=C-s[b-1]-k,w.set(r,3*(s[b-1]+k))):l[0]=C}for(r[1]=v-I,o>_?d[_]<c?(r[0]=256>d[_]?0:96,r[2]=d[_++]):(r[0]=a[d[_]-c]+16+64,r[2]=f[d[_++]-c]):r[0]=192,y=1<<v-I,k=g>>>I;D>k;k+=y)w.set(r,3*(C+k));for(k=1<<v-1;0!=(g&k);k>>>=1)g^=k;for(g^=k,z=(1<<I)-1;(g&z)!=i[b];)b--,I-=S,z=(1<<I)-1}return 0!==A&&1!=m?-5:0}function f(o){let f;for(e||(e=[],t=[],n=new c(16),r=[],s=new c(15),i=new c(16)),t.length<o&&(t=[]),f=0;o>f;f++)t[f]=0;for(f=0;16>f;f++)n[f]=0;for(f=0;3>f;f++)r[f]=0;s.set(n.subarray(0,15),0),i.set(n.subarray(0,16),0)}this.ft=(n,r,s,i,c)=>{let a;return f(19),e[0]=0,a=o(n,0,19,19,null,null,s,r,i,e,t),-3==a?c.Je="oversubscribed dynamic bit lengths tree":-5!=a&&0!==r[0]||(c.Je="incomplete dynamic bit lengths tree",a=-3),a},this.lt=(n,r,s,i,c,a,l,u,w)=>{let h;return f(288),e[0]=0,h=o(s,0,n,257,Te,We,a,i,u,e,t),0!=h||0===i[0]?(-3==h?w.Je="oversubscribed literal/length tree":-4!=h&&(w.Je="incomplete literal/length tree",h=-3),h):(f(288),h=o(s,n,r,0,He,Le,l,c,u,e,t),0!=h||0===c[0]&&n>257?(-3==h?w.Je="oversubscribed distance tree":-5==h?(w.Je="incomplete distance tree",h=-3):-4!=h&&(w.Je="empty distance tree with lengths",h=-3),h):0)}}function Fe(){const e=this;let t,n,r,s,i=0,o=0,c=0,f=0,a=0,l=0,u=0,w=0,h=0,d=0;function p(e,t,n,r,s,i,o,c){let f,a,l,u,w,h,d,p,y,m,b,g,k,v,S,z;d=c.ot,p=c.Oe,w=o.ut,h=o.wt,y=o.write,m=y<o.read?o.read-y-1:o.end-y,b=Ne[e],g=Ne[t];do{for(;20>h;)p--,w|=(255&c.ht(d++))<<h,h+=8;if(f=w&b,a=n,l=r,z=3*(l+f),0!==(u=a[z]))for(;;){if(w>>=a[z+1],h-=a[z+1],0!=(16&u)){for(u&=15,k=a[z+2]+(w&Ne[u]),w>>=u,h-=u;15>h;)p--,w|=(255&c.ht(d++))<<h,h+=8;for(f=w&g,a=s,l=i,z=3*(l+f),u=a[z];;){if(w>>=a[z+1],h-=a[z+1],0!=(16&u)){for(u&=15;u>h;)p--,w|=(255&c.ht(d++))<<h,h+=8;if(v=a[z+2]+(w&Ne[u]),w>>=u,h-=u,m-=k,v>y){S=y-v;do{S+=o.end}while(0>S);if(u=o.end-S,k>u){if(k-=u,y-S>0&&u>y-S)do{o.dt[y++]=o.dt[S++]}while(0!=--u);else o.dt.set(o.dt.subarray(S,S+u),y),y+=u,S+=u,u=0;S=0}}else S=y-v,y-S>0&&2>y-S?(o.dt[y++]=o.dt[S++],o.dt[y++]=o.dt[S++],k-=2):(o.dt.set(o.dt.subarray(S,S+2),y),y+=2,S+=2,k-=2);if(y-S>0&&k>y-S)do{o.dt[y++]=o.dt[S++]}while(0!=--k);else o.dt.set(o.dt.subarray(S,S+k),y),y+=k,S+=k,k=0;break}if(0!=(64&u))return c.Je="invalid distance code",k=c.Oe-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.ut=w,o.wt=h,c.Oe=p,c.Xe+=d-c.ot,c.ot=d,o.write=y,-3;f+=a[z+2],f+=w&Ne[u],z=3*(l+f),u=a[z]}break}if(0!=(64&u))return 0!=(32&u)?(k=c.Oe-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.ut=w,o.wt=h,c.Oe=p,c.Xe+=d-c.ot,c.ot=d,o.write=y,1):(c.Je="invalid literal/length code",k=c.Oe-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.ut=w,o.wt=h,c.Oe=p,c.Xe+=d-c.ot,c.ot=d,o.write=y,-3);if(f+=a[z+2],f+=w&Ne[u],z=3*(l+f),0===(u=a[z])){w>>=a[z+1],h-=a[z+1],o.dt[y++]=a[z+2],m--;break}}else w>>=a[z+1],h-=a[z+1],o.dt[y++]=a[z+2],m--}while(m>=258&&p>=10);return k=c.Oe-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.ut=w,o.wt=h,c.Oe=p,c.Xe+=d-c.ot,c.ot=d,o.write=y,0}e.init=(e,i,o,c,f,a)=>{t=0,u=e,w=i,r=o,h=c,s=f,d=a,n=null},e.yt=(e,y,m)=>{let b,g,k,v,S,z,_,C=0,I=0,x=0;for(x=y.ot,v=y.Oe,C=e.ut,I=e.wt,S=e.write,z=S<e.read?e.read-S-1:e.end-S;;)switch(t){case 0:if(z>=258&&v>=10&&(e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,m=p(u,w,r,h,s,d,e,y),x=y.ot,v=y.Oe,C=e.ut,I=e.wt,S=e.write,z=S<e.read?e.read-S-1:e.end-S,0!=m)){t=1==m?7:9;break}c=u,n=r,o=h,t=1;case 1:for(b=c;b>I;){if(0===v)return e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);m=0,v--,C|=(255&y.ht(x++))<<I,I+=8}if(g=3*(o+(C&Ne[b])),C>>>=n[g+1],I-=n[g+1],k=n[g],0===k){f=n[g+2],t=6;break}if(0!=(16&k)){a=15&k,i=n[g+2],t=2;break}if(0==(64&k)){c=k,o=g/3+n[g+2];break}if(0!=(32&k)){t=7;break}return t=9,y.Je="invalid literal/length code",m=-3,e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);case 2:for(b=a;b>I;){if(0===v)return e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);m=0,v--,C|=(255&y.ht(x++))<<I,I+=8}i+=C&Ne[b],C>>=b,I-=b,c=w,n=s,o=d,t=3;case 3:for(b=c;b>I;){if(0===v)return e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);m=0,v--,C|=(255&y.ht(x++))<<I,I+=8}if(g=3*(o+(C&Ne[b])),C>>=n[g+1],I-=n[g+1],k=n[g],0!=(16&k)){a=15&k,l=n[g+2],t=4;break}if(0==(64&k)){c=k,o=g/3+n[g+2];break}return t=9,y.Je="invalid distance code",m=-3,e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);case 4:for(b=a;b>I;){if(0===v)return e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);m=0,v--,C|=(255&y.ht(x++))<<I,I+=8}l+=C&Ne[b],C>>=b,I-=b,t=5;case 5:for(_=S-l;0>_;)_+=e.end;for(;0!==i;){if(0===z&&(S==e.end&&0!==e.read&&(S=0,z=S<e.read?e.read-S-1:e.end-S),0===z&&(e.write=S,m=e.bt(y,m),S=e.write,z=S<e.read?e.read-S-1:e.end-S,S==e.end&&0!==e.read&&(S=0,z=S<e.read?e.read-S-1:e.end-S),0===z)))return e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);e.dt[S++]=e.dt[_++],z--,_==e.end&&(_=0),i--}t=0;break;case 6:if(0===z&&(S==e.end&&0!==e.read&&(S=0,z=S<e.read?e.read-S-1:e.end-S),0===z&&(e.write=S,m=e.bt(y,m),S=e.write,z=S<e.read?e.read-S-1:e.end-S,S==e.end&&0!==e.read&&(S=0,z=S<e.read?e.read-S-1:e.end-S),0===z)))return e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);m=0,e.dt[S++]=f,z--,t=0;break;case 7:if(I>7&&(I-=8,v++,x--),e.write=S,m=e.bt(y,m),S=e.write,z=S<e.read?e.read-S-1:e.end-S,e.read!=e.write)return e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);t=8;case 8:return m=1,e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);case 9:return m=-3,e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m);default:return m=-2,e.ut=C,e.wt=I,y.Oe=v,y.Xe+=x-y.ot,y.ot=x,e.write=S,e.bt(y,m)}},e.gt=()=>{}}je.kt=(e,t,n,r)=>(e[0]=9,t[0]=5,n[0]=Pe,r[0]=Ue,0);const Oe=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function qe(e,t){const n=this;let r,i=0,o=0,f=0,a=0;const l=[0],u=[0],w=new Fe;let h=0,d=new c(4320);const p=new je;n.wt=0,n.ut=0,n.dt=new s(t),n.end=t,n.read=0,n.write=0,n.reset=(e,t)=>{t&&(t[0]=0),6==i&&w.gt(e),i=0,n.wt=0,n.ut=0,n.read=n.write=0},n.reset(e,null),n.bt=(e,t)=>{let r,s,i;return s=e.ct,i=n.read,r=(i>n.write?n.end:n.write)-i,r>e.it&&(r=e.it),0!==r&&-5==t&&(t=0),e.it-=r,e.Ye+=r,e.rt.set(n.dt.subarray(i,i+r),s),s+=r,i+=r,i==n.end&&(i=0,n.write==n.end&&(n.write=0),r=n.write-i,r>e.it&&(r=e.it),0!==r&&-5==t&&(t=0),e.it-=r,e.Ye+=r,e.rt.set(n.dt.subarray(i,i+r),s),s+=r,i+=r),e.ct=s,n.read=i,t},n.yt=(e,t)=>{let s,c,y,m,b,g,k,v;for(m=e.ot,b=e.Oe,c=n.ut,y=n.wt,g=n.write,k=g<n.read?n.read-g-1:n.end-g;;){let S,z,_,C,I,x,A,D;switch(i){case 0:for(;3>y;){if(0===b)return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);t=0,b--,c|=(255&e.ht(m++))<<y,y+=8}switch(s=7&c,h=1&s,s>>>1){case 0:c>>>=3,y-=3,s=7&y,c>>>=s,y-=s,i=1;break;case 1:S=[],z=[],_=[[]],C=[[]],je.kt(S,z,_,C),w.init(S[0],z[0],_[0],0,C[0],0),c>>>=3,y-=3,i=6;break;case 2:c>>>=3,y-=3,i=3;break;case 3:return c>>>=3,y-=3,i=9,e.Je="invalid block type",t=-3,n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t)}break;case 1:for(;32>y;){if(0===b)return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);t=0,b--,c|=(255&e.ht(m++))<<y,y+=8}if((~c>>>16&65535)!=(65535&c))return i=9,e.Je="invalid stored block lengths",t=-3,n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);o=65535&c,c=y=0,i=0!==o?2:0!==h?7:0;break;case 2:if(0===b)return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);if(0===k&&(g==n.end&&0!==n.read&&(g=0,k=g<n.read?n.read-g-1:n.end-g),0===k&&(n.write=g,t=n.bt(e,t),g=n.write,k=g<n.read?n.read-g-1:n.end-g,g==n.end&&0!==n.read&&(g=0,k=g<n.read?n.read-g-1:n.end-g),0===k)))return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);if(t=0,s=o,s>b&&(s=b),s>k&&(s=k),n.dt.set(e.qe(m,s),g),m+=s,b-=s,g+=s,k-=s,0!=(o-=s))break;i=0!==h?7:0;break;case 3:for(;14>y;){if(0===b)return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);t=0,b--,c|=(255&e.ht(m++))<<y,y+=8}if(f=s=16383&c,(31&s)>29||(s>>5&31)>29)return i=9,e.Je="too many length or distance symbols",t=-3,n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);if(s=258+(31&s)+(s>>5&31),!r||r.length<s)r=[];else for(v=0;s>v;v++)r[v]=0;c>>>=14,y-=14,a=0,i=4;case 4:for(;4+(f>>>10)>a;){for(;3>y;){if(0===b)return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);t=0,b--,c|=(255&e.ht(m++))<<y,y+=8}r[Oe[a++]]=7&c,c>>>=3,y-=3}for(;19>a;)r[Oe[a++]]=0;if(l[0]=7,s=p.ft(r,l,u,d,e),0!=s)return-3==(t=s)&&(r=null,i=9),n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);a=0,i=5;case 5:for(;s=f,258+(31&s)+(s>>5&31)>a;){let o,w;for(s=l[0];s>y;){if(0===b)return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);t=0,b--,c|=(255&e.ht(m++))<<y,y+=8}if(s=d[3*(u[0]+(c&Ne[s]))+1],w=d[3*(u[0]+(c&Ne[s]))+2],16>w)c>>>=s,y-=s,r[a++]=w;else{for(v=18==w?7:w-14,o=18==w?11:3;s+v>y;){if(0===b)return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);t=0,b--,c|=(255&e.ht(m++))<<y,y+=8}if(c>>>=s,y-=s,o+=c&Ne[v],c>>>=v,y-=v,v=a,s=f,v+o>258+(31&s)+(s>>5&31)||16==w&&1>v)return r=null,i=9,e.Je="invalid bit length repeat",t=-3,n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);w=16==w?r[v-1]:0;do{r[v++]=w}while(0!=--o);a=v}}if(u[0]=-1,I=[],x=[],A=[],D=[],I[0]=9,x[0]=6,s=f,s=p.lt(257+(31&s),1+(s>>5&31),r,I,x,A,D,d,e),0!=s)return-3==s&&(r=null,i=9),t=s,n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);w.init(I[0],x[0],d,A[0],d,D[0]),i=6;case 6:if(n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,1!=(t=w.yt(n,e,t)))return n.bt(e,t);if(t=0,w.gt(e),m=e.ot,b=e.Oe,c=n.ut,y=n.wt,g=n.write,k=g<n.read?n.read-g-1:n.end-g,0===h){i=0;break}i=7;case 7:if(n.write=g,t=n.bt(e,t),g=n.write,k=g<n.read?n.read-g-1:n.end-g,n.read!=n.write)return n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);i=8;case 8:return t=1,n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);case 9:return t=-3,n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t);default:return t=-2,n.ut=c,n.wt=y,e.Oe=b,e.Xe+=m-e.ot,e.ot=m,n.write=g,n.bt(e,t)}}},n.gt=e=>{n.reset(e,null),n.dt=null,d=null},n.vt=(e,t,r)=>{n.dt.set(e.subarray(t,t+r),0),n.read=n.write=r},n.St=()=>1==i?1:0}const Ge=[0,0,255,255];function Je(){const e=this;function t(e){return e&&e.zt?(e.Xe=e.Ye=0,e.Je=null,e.zt.mode=7,e.zt._t.reset(e,null),0):-2}e.mode=0,e.method=0,e.Ct=[0],e.It=0,e.marker=0,e.xt=0,e.At=t=>(e._t&&e._t.gt(t),e._t=null,0),e.Dt=(n,r)=>(n.Je=null,e._t=null,8>r||r>15?(e.At(n),-2):(e.xt=r,n.zt._t=new qe(n,1<<r),t(n),0)),e.Vt=(e,t)=>{let n,r;if(!e||!e.zt||!e.st)return-2;const s=e.zt;for(t=4==t?-5:0,n=-5;;)switch(s.mode){case 0:if(0===e.Oe)return n;if(n=t,e.Oe--,e.Xe++,8!=(15&(s.method=e.ht(e.ot++)))){s.mode=13,e.Je="unknown compression method",s.marker=5;break}if(8+(s.method>>4)>s.xt){s.mode=13,e.Je="invalid win size",s.marker=5;break}s.mode=1;case 1:if(0===e.Oe)return n;if(n=t,e.Oe--,e.Xe++,r=255&e.ht(e.ot++),((s.method<<8)+r)%31!=0){s.mode=13,e.Je="incorrect header check",s.marker=5;break}if(0==(32&r)){s.mode=7;break}s.mode=2;case 2:if(0===e.Oe)return n;n=t,e.Oe--,e.Xe++,s.It=(255&e.ht(e.ot++))<<24&4278190080,s.mode=3;case 3:if(0===e.Oe)return n;n=t,e.Oe--,e.Xe++,s.It+=(255&e.ht(e.ot++))<<16&16711680,s.mode=4;case 4:if(0===e.Oe)return n;n=t,e.Oe--,e.Xe++,s.It+=(255&e.ht(e.ot++))<<8&65280,s.mode=5;case 5:return 0===e.Oe?n:(n=t,e.Oe--,e.Xe++,s.It+=255&e.ht(e.ot++),s.mode=6,2);case 6:return s.mode=13,e.Je="need dictionary",s.marker=0,-2;case 7:if(n=s._t.yt(e,n),-3==n){s.mode=13,s.marker=0;break}if(0==n&&(n=t),1!=n)return n;n=t,s._t.reset(e,s.Ct),s.mode=12;case 12:return e.Oe=0,1;case 13:return-3;default:return-2}},e.Rt=(e,t,n)=>{let r=0,s=n;if(!e||!e.zt||6!=e.zt.mode)return-2;const i=e.zt;return s<1<<i.xt||(s=(1<<i.xt)-1,r=n-s),i._t.vt(t,r,s),i.mode=7,0},e.Bt=e=>{let n,r,s,i,o;if(!e||!e.zt)return-2;const c=e.zt;if(13!=c.mode&&(c.mode=13,c.marker=0),0===(n=e.Oe))return-5;for(r=e.ot,s=c.marker;0!==n&&4>s;)e.ht(r)==Ge[s]?s++:s=0!==e.ht(r)?0:4-s,r++,n--;return e.Xe+=r-e.ot,e.ot=r,e.Oe=n,c.marker=s,4!=s?-3:(i=e.Xe,o=e.Ye,t(e),e.Xe=i,e.Ye=o,c.mode=7,0)},e.Et=e=>e&&e.zt&&e.zt._t?e.zt._t.St():-2}function Qe(){}function Xe(e){const t=new Qe,i=e&&e.chunkSize?n.floor(2*e.chunkSize):131072,o=new s(i);let c=!1;t.Dt(),t.rt=o,this.append=(e,n)=>{const f=[];let a,l,u=0,w=0,h=0;if(0!==e.length){t.ot=0,t.st=e,t.Oe=e.length;do{if(t.ct=0,t.it=i,0!==t.Oe||c||(t.ot=0,c=!0),a=t.Vt(0),c&&-5===a){if(0!==t.Oe)throw new r("inflating: bad input")}else if(0!==a&&1!==a)throw new r("inflating: "+t.Je);if((c||1===a)&&t.Oe===e.length)throw new r("inflating: bad input");t.ct&&(t.ct===i?f.push(new s(o)):f.push(o.slice(0,t.ct))),h+=t.ct,n&&t.ot>0&&t.ot!=u&&(n(t.ot),u=t.ot)}while(t.Oe>0||0===t.it);return f.length>1?(l=new s(h),f.forEach((e=>{l.set(e,w),w+=e.length}))):l=f[0]||new s,l}},this.flush=()=>{t.At()}}Qe.prototype={Dt(e){const t=this;return t.zt=new Je,e||(e=15),t.zt.Dt(t,e)},Vt(e){const t=this;return t.zt?t.zt.Vt(t,e):-2},At(){const e=this;if(!e.zt)return-2;const t=e.zt.At(e);return e.zt=null,t},Bt(){const e=this;return e.zt?e.zt.Bt(e):-2},Rt(e,t){const n=this;return n.zt?n.zt.Rt(n,e,t):-2},ht(e){return this.st[e]},qe(e,t){return this.st.subarray(e,e+t)}},self.initCodec=()=>{self.Deflate=Ke,self.Inflate=Xe};\n'],{type:"text/javascript"}));e({workerScripts:{inflate:[t],deflate:[t]}});}
|
|
159
247
|
|
|
160
248
|
/*
|
|
161
|
-
|
|
162
|
-
* license or under the GNU GPL, version 2.0.
|
|
163
|
-
*/
|
|
249
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
164
250
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* Crush to remove comments, shorten variable names and
|
|
168
|
-
* generally reduce transmission size.
|
|
169
|
-
*
|
|
170
|
-
* @author Emily Stark
|
|
171
|
-
* @author Mike Hamburg
|
|
172
|
-
* @author Dan Boneh
|
|
173
|
-
*/
|
|
251
|
+
Redistribution and use in source and binary forms, with or without
|
|
252
|
+
modification, are permitted provided that the following conditions are met:
|
|
174
253
|
|
|
175
|
-
|
|
254
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
255
|
+
this list of conditions and the following disclaimer.
|
|
176
256
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
* @author Mike Hamburg
|
|
181
|
-
* @author Dan Boneh
|
|
182
|
-
*/
|
|
257
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
258
|
+
notice, this list of conditions and the following disclaimer in
|
|
259
|
+
the documentation and/or other materials provided with the distribution.
|
|
183
260
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
* array of words, 32 bits at a time. Since the words are double-precision
|
|
198
|
-
* floating point numbers, they fit some extra data. We use this (in a private,
|
|
199
|
-
* possibly-changing manner) to encode the number of bits actually present
|
|
200
|
-
* in the last word of the array.
|
|
201
|
-
* </p>
|
|
202
|
-
*
|
|
203
|
-
* <p>
|
|
204
|
-
* Because bitwise ops clear this out-of-band data, these arrays can be passed
|
|
205
|
-
* to ciphers like AES which want arrays of words.
|
|
206
|
-
* </p>
|
|
261
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
262
|
+
derived from this software without specific prior written permission.
|
|
263
|
+
|
|
264
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
265
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
266
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
267
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
268
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
269
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
270
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
271
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
272
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
273
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
207
274
|
*/
|
|
208
|
-
const bitArray = {
|
|
209
|
-
/**
|
|
210
|
-
* Concatenate two bit arrays.
|
|
211
|
-
* @param {bitArray} a1 The first array.
|
|
212
|
-
* @param {bitArray} a2 The second array.
|
|
213
|
-
* @return {bitArray} The concatenation of a1 and a2.
|
|
214
|
-
*/
|
|
215
|
-
concat(a1, a2) {
|
|
216
|
-
if (a1.length === 0 || a2.length === 0) {
|
|
217
|
-
return a1.concat(a2);
|
|
218
|
-
}
|
|
219
275
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
} else {
|
|
224
|
-
return bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
|
|
225
|
-
}
|
|
226
|
-
},
|
|
276
|
+
function getMimeType() {
|
|
277
|
+
return "application/octet-stream";
|
|
278
|
+
}
|
|
227
279
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
280
|
+
function initShimAsyncCodec(library, options = {}, registerDataHandler) {
|
|
281
|
+
return {
|
|
282
|
+
Deflate: createCodecClass(library.Deflate, options.deflate, registerDataHandler),
|
|
283
|
+
Inflate: createCodecClass(library.Inflate, options.inflate, registerDataHandler)
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function createCodecClass(constructor, constructorOptions, registerDataHandler) {
|
|
288
|
+
return class {
|
|
289
|
+
|
|
290
|
+
constructor(options) {
|
|
291
|
+
const codecAdapter = this;
|
|
292
|
+
const onData = data => {
|
|
293
|
+
if (codecAdapter.pendingData) {
|
|
294
|
+
const { pendingData } = codecAdapter;
|
|
295
|
+
codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
|
|
296
|
+
pendingData.set(pendingData, 0);
|
|
297
|
+
pendingData.set(data, pendingData.length);
|
|
298
|
+
} else {
|
|
299
|
+
codecAdapter.pendingData = new Uint8Array(data);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
if (Object.hasOwn(options, "level") && options.level === undefined) {
|
|
303
|
+
delete options.level;
|
|
304
|
+
}
|
|
305
|
+
codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
|
|
306
|
+
registerDataHandler(codecAdapter.codec, onData);
|
|
307
|
+
}
|
|
308
|
+
append(data) {
|
|
309
|
+
this.codec.push(data);
|
|
310
|
+
return getResponse(this);
|
|
311
|
+
}
|
|
312
|
+
flush() {
|
|
313
|
+
this.codec.push(new Uint8Array(), true);
|
|
314
|
+
return getResponse(this);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
function getResponse(codec) {
|
|
319
|
+
if (codec.pendingData) {
|
|
320
|
+
const output = codec.pendingData;
|
|
321
|
+
codec.pendingData = null;
|
|
322
|
+
return output;
|
|
323
|
+
} else {
|
|
324
|
+
return new Uint8Array();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/*
|
|
330
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
331
|
+
|
|
332
|
+
Redistribution and use in source and binary forms, with or without
|
|
333
|
+
modification, are permitted provided that the following conditions are met:
|
|
334
|
+
|
|
335
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
336
|
+
this list of conditions and the following disclaimer.
|
|
337
|
+
|
|
338
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
339
|
+
notice, this list of conditions and the following disclaimer in
|
|
340
|
+
the documentation and/or other materials provided with the distribution.
|
|
341
|
+
|
|
342
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
343
|
+
derived from this software without specific prior written permission.
|
|
344
|
+
|
|
345
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
346
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
347
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
348
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
349
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
350
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
351
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
352
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
353
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
354
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
355
|
+
*/
|
|
356
|
+
|
|
357
|
+
const table = [];
|
|
358
|
+
for (let i = 0; i < 256; i++) {
|
|
359
|
+
let t = i;
|
|
360
|
+
for (let j = 0; j < 8; j++) {
|
|
361
|
+
if (t & 1) {
|
|
362
|
+
t = (t >>> 1) ^ 0xEDB88320;
|
|
363
|
+
} else {
|
|
364
|
+
t = t >>> 1;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
table[i] = t;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
class Crc32 {
|
|
371
|
+
|
|
372
|
+
constructor(crc) {
|
|
373
|
+
this.crc = crc || -1;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
append(data) {
|
|
377
|
+
let crc = this.crc | 0;
|
|
378
|
+
for (let offset = 0, length = data.length | 0; offset < length; offset++) {
|
|
379
|
+
crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
|
|
380
|
+
}
|
|
381
|
+
this.crc = crc;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
get() {
|
|
385
|
+
return ~this.crc;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/*
|
|
390
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
391
|
+
|
|
392
|
+
Redistribution and use in source and binary forms, with or without
|
|
393
|
+
modification, are permitted provided that the following conditions are met:
|
|
394
|
+
|
|
395
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
396
|
+
this list of conditions and the following disclaimer.
|
|
397
|
+
|
|
398
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
399
|
+
notice, this list of conditions and the following disclaimer in
|
|
400
|
+
the documentation and/or other materials provided with the distribution.
|
|
401
|
+
|
|
402
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
403
|
+
derived from this software without specific prior written permission.
|
|
404
|
+
|
|
405
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
406
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
407
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
408
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
409
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
410
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
411
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
412
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
413
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
414
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
415
|
+
*/
|
|
416
|
+
|
|
417
|
+
class Crc32Stream extends TransformStream {
|
|
418
|
+
|
|
419
|
+
constructor() {
|
|
420
|
+
const crc32 = new Crc32();
|
|
421
|
+
super({
|
|
422
|
+
transform(chunk) {
|
|
423
|
+
crc32.append(chunk);
|
|
424
|
+
},
|
|
425
|
+
flush(controller) {
|
|
426
|
+
const value = new Uint8Array(4);
|
|
427
|
+
const dataView = new DataView(value.buffer);
|
|
428
|
+
dataView.setUint32(0, crc32.get());
|
|
429
|
+
controller.enqueue(value);
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/*
|
|
436
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
437
|
+
|
|
438
|
+
Redistribution and use in source and binary forms, with or without
|
|
439
|
+
modification, are permitted provided that the following conditions are met:
|
|
440
|
+
|
|
441
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
442
|
+
this list of conditions and the following disclaimer.
|
|
443
|
+
|
|
444
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
445
|
+
notice, this list of conditions and the following disclaimer in
|
|
446
|
+
the documentation and/or other materials provided with the distribution.
|
|
447
|
+
|
|
448
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
449
|
+
derived from this software without specific prior written permission.
|
|
450
|
+
|
|
451
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
452
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
453
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
454
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
455
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
456
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
457
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
458
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
459
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
460
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
461
|
+
*/
|
|
462
|
+
|
|
463
|
+
function encodeText(value) {
|
|
464
|
+
if (typeof TextEncoder == "undefined") {
|
|
465
|
+
value = unescape(encodeURIComponent(value));
|
|
466
|
+
const result = new Uint8Array(value.length);
|
|
467
|
+
for (let i = 0; i < result.length; i++) {
|
|
468
|
+
result[i] = value.charCodeAt(i);
|
|
469
|
+
}
|
|
470
|
+
return result;
|
|
471
|
+
} else {
|
|
472
|
+
return new TextEncoder().encode(value);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl
|
|
477
|
+
|
|
478
|
+
// deno-lint-ignore-file no-this-alias
|
|
479
|
+
|
|
480
|
+
/*
|
|
481
|
+
* SJCL is open. You can use, modify and redistribute it under a BSD
|
|
482
|
+
* license or under the GNU GPL, version 2.0.
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
/** @fileOverview Javascript cryptography implementation.
|
|
486
|
+
*
|
|
487
|
+
* Crush to remove comments, shorten variable names and
|
|
488
|
+
* generally reduce transmission size.
|
|
489
|
+
*
|
|
490
|
+
* @author Emily Stark
|
|
491
|
+
* @author Mike Hamburg
|
|
492
|
+
* @author Dan Boneh
|
|
493
|
+
*/
|
|
494
|
+
|
|
495
|
+
/*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
|
|
496
|
+
|
|
497
|
+
/** @fileOverview Arrays of bits, encoded as arrays of Numbers.
|
|
498
|
+
*
|
|
499
|
+
* @author Emily Stark
|
|
500
|
+
* @author Mike Hamburg
|
|
501
|
+
* @author Dan Boneh
|
|
502
|
+
*/
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Arrays of bits, encoded as arrays of Numbers.
|
|
506
|
+
* @namespace
|
|
507
|
+
* @description
|
|
508
|
+
* <p>
|
|
509
|
+
* These objects are the currency accepted by SJCL's crypto functions.
|
|
510
|
+
* </p>
|
|
511
|
+
*
|
|
512
|
+
* <p>
|
|
513
|
+
* Most of our crypto primitives operate on arrays of 4-byte words internally,
|
|
514
|
+
* but many of them can take arguments that are not a multiple of 4 bytes.
|
|
515
|
+
* This library encodes arrays of bits (whose size need not be a multiple of 8
|
|
516
|
+
* bits) as arrays of 32-bit words. The bits are packed, big-endian, into an
|
|
517
|
+
* array of words, 32 bits at a time. Since the words are double-precision
|
|
518
|
+
* floating point numbers, they fit some extra data. We use this (in a private,
|
|
519
|
+
* possibly-changing manner) to encode the number of bits actually present
|
|
520
|
+
* in the last word of the array.
|
|
521
|
+
* </p>
|
|
522
|
+
*
|
|
523
|
+
* <p>
|
|
524
|
+
* Because bitwise ops clear this out-of-band data, these arrays can be passed
|
|
525
|
+
* to ciphers like AES which want arrays of words.
|
|
526
|
+
* </p>
|
|
527
|
+
*/
|
|
528
|
+
const bitArray = {
|
|
529
|
+
/**
|
|
530
|
+
* Concatenate two bit arrays.
|
|
531
|
+
* @param {bitArray} a1 The first array.
|
|
532
|
+
* @param {bitArray} a2 The second array.
|
|
533
|
+
* @return {bitArray} The concatenation of a1 and a2.
|
|
534
|
+
*/
|
|
535
|
+
concat(a1, a2) {
|
|
536
|
+
if (a1.length === 0 || a2.length === 0) {
|
|
537
|
+
return a1.concat(a2);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const last = a1[a1.length - 1], shift = bitArray.getPartial(last);
|
|
541
|
+
if (shift === 32) {
|
|
542
|
+
return a1.concat(a2);
|
|
543
|
+
} else {
|
|
544
|
+
return bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Find the length of an array of bits.
|
|
550
|
+
* @param {bitArray} a The array.
|
|
231
551
|
* @return {Number} The length of a, in bits.
|
|
232
552
|
*/
|
|
233
553
|
bitLength(a) {
|
|
@@ -962,61 +1282,18 @@
|
|
|
962
1282
|
|
|
963
1283
|
hmac.reset();
|
|
964
1284
|
|
|
965
|
-
return result;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
encrypt(data) {
|
|
969
|
-
if (!this._updated) {
|
|
970
|
-
this.update(data);
|
|
971
|
-
return this.digest(data);
|
|
972
|
-
} else {
|
|
973
|
-
throw new Error("encrypt on already updated hmac called!");
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
};
|
|
977
|
-
|
|
978
|
-
/*
|
|
979
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
980
|
-
|
|
981
|
-
Redistribution and use in source and binary forms, with or without
|
|
982
|
-
modification, are permitted provided that the following conditions are met:
|
|
983
|
-
|
|
984
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
985
|
-
this list of conditions and the following disclaimer.
|
|
986
|
-
|
|
987
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
988
|
-
notice, this list of conditions and the following disclaimer in
|
|
989
|
-
the documentation and/or other materials provided with the distribution.
|
|
990
|
-
|
|
991
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
992
|
-
derived from this software without specific prior written permission.
|
|
993
|
-
|
|
994
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
995
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
996
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
997
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
998
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
999
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1000
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1001
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1002
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1003
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1004
|
-
*/
|
|
1005
|
-
|
|
1006
|
-
/* global crypto */
|
|
1007
|
-
|
|
1008
|
-
const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != "undefined" && typeof crypto.getRandomValues == "function";
|
|
1009
|
-
|
|
1010
|
-
const ERR_INVALID_PASSWORD = "Invalid password";
|
|
1011
|
-
const ERR_INVALID_SIGNATURE = "Invalid signature";
|
|
1285
|
+
return result;
|
|
1286
|
+
}
|
|
1012
1287
|
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1288
|
+
encrypt(data) {
|
|
1289
|
+
if (!this._updated) {
|
|
1290
|
+
this.update(data);
|
|
1291
|
+
return this.digest(data);
|
|
1292
|
+
} else {
|
|
1293
|
+
throw new Error("encrypt on already updated hmac called!");
|
|
1294
|
+
}
|
|
1018
1295
|
}
|
|
1019
|
-
}
|
|
1296
|
+
};
|
|
1020
1297
|
|
|
1021
1298
|
/*
|
|
1022
1299
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -1046,253 +1323,19 @@
|
|
|
1046
1323
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1047
1324
|
*/
|
|
1048
1325
|
|
|
1049
|
-
|
|
1050
|
-
const RAW_FORMAT = "raw";
|
|
1051
|
-
const PBKDF2_ALGORITHM = { name: "PBKDF2" };
|
|
1052
|
-
const HASH_ALGORITHM = { name: "HMAC" };
|
|
1053
|
-
const HASH_FUNCTION = "SHA-1";
|
|
1054
|
-
const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
|
|
1055
|
-
const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
|
|
1056
|
-
const DERIVED_BITS_USAGE = ["deriveBits"];
|
|
1057
|
-
const SALT_LENGTH = [8, 12, 16];
|
|
1058
|
-
const KEY_LENGTH = [16, 24, 32];
|
|
1059
|
-
const SIGNATURE_LENGTH = 10;
|
|
1060
|
-
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
1061
|
-
const UNDEFINED_TYPE$1 = "undefined";
|
|
1062
|
-
const FUNCTION_TYPE = "function";
|
|
1063
|
-
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE$1;
|
|
1064
|
-
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
1065
|
-
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE$1;
|
|
1066
|
-
const IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
|
|
1067
|
-
const DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
|
|
1068
|
-
const codecBytes = codec.bytes;
|
|
1069
|
-
const Aes = cipher.aes;
|
|
1070
|
-
const CtrGladman = mode.ctrGladman;
|
|
1071
|
-
const HmacSha1 = misc.hmacSha1;
|
|
1072
|
-
|
|
1073
|
-
class AESDecryptionStream extends TransformStream {
|
|
1074
|
-
|
|
1075
|
-
constructor(password, signed, strength) {
|
|
1076
|
-
super({
|
|
1077
|
-
start() {
|
|
1078
|
-
Object.assign(this, {
|
|
1079
|
-
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
1080
|
-
password,
|
|
1081
|
-
signed,
|
|
1082
|
-
strength: strength - 1,
|
|
1083
|
-
pending: new Uint8Array()
|
|
1084
|
-
});
|
|
1085
|
-
},
|
|
1086
|
-
async transform(chunk, controller) {
|
|
1087
|
-
const aesCrypto = this;
|
|
1088
|
-
const {
|
|
1089
|
-
password,
|
|
1090
|
-
strength,
|
|
1091
|
-
resolveReady,
|
|
1092
|
-
ready
|
|
1093
|
-
} = aesCrypto;
|
|
1094
|
-
if (password) {
|
|
1095
|
-
await createDecryptionKeys(aesCrypto, strength, password, subarray(chunk, 0, SALT_LENGTH[strength] + 2));
|
|
1096
|
-
chunk = subarray(chunk, SALT_LENGTH[strength] + 2);
|
|
1097
|
-
resolveReady();
|
|
1098
|
-
} else {
|
|
1099
|
-
await ready;
|
|
1100
|
-
}
|
|
1101
|
-
const output = new Uint8Array(chunk.length - SIGNATURE_LENGTH - ((chunk.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
|
|
1102
|
-
controller.enqueue(append(aesCrypto, chunk, output, 0, SIGNATURE_LENGTH, true));
|
|
1103
|
-
},
|
|
1104
|
-
async flush(controller) {
|
|
1105
|
-
const {
|
|
1106
|
-
signed,
|
|
1107
|
-
ctr,
|
|
1108
|
-
hmac,
|
|
1109
|
-
pending,
|
|
1110
|
-
ready
|
|
1111
|
-
} = this;
|
|
1112
|
-
await ready;
|
|
1113
|
-
const chunkToDecrypt = subarray(pending, 0, pending.length - SIGNATURE_LENGTH);
|
|
1114
|
-
const originalSignature = subarray(pending, pending.length - SIGNATURE_LENGTH);
|
|
1115
|
-
let decryptedChunkArray = new Uint8Array();
|
|
1116
|
-
if (chunkToDecrypt.length) {
|
|
1117
|
-
const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
|
|
1118
|
-
hmac.update(encryptedChunk);
|
|
1119
|
-
const decryptedChunk = ctr.update(encryptedChunk);
|
|
1120
|
-
decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
|
|
1121
|
-
}
|
|
1122
|
-
if (signed) {
|
|
1123
|
-
const signature = subarray(fromBits(codecBytes, hmac.digest()), 0, SIGNATURE_LENGTH);
|
|
1124
|
-
for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
|
|
1125
|
-
if (signature[indexSignature] != originalSignature[indexSignature]) {
|
|
1126
|
-
throw new Error(ERR_INVALID_SIGNATURE);
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
controller.enqueue(decryptedChunkArray);
|
|
1131
|
-
}
|
|
1132
|
-
});
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
class AESEncryptionStream extends TransformStream {
|
|
1137
|
-
|
|
1138
|
-
constructor(password, strength) {
|
|
1139
|
-
let stream;
|
|
1140
|
-
super({
|
|
1141
|
-
start() {
|
|
1142
|
-
Object.assign(this, {
|
|
1143
|
-
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
1144
|
-
password,
|
|
1145
|
-
strength: strength - 1,
|
|
1146
|
-
pending: new Uint8Array()
|
|
1147
|
-
});
|
|
1148
|
-
},
|
|
1149
|
-
async transform(chunk, controller) {
|
|
1150
|
-
const aesCrypto = this;
|
|
1151
|
-
const {
|
|
1152
|
-
password,
|
|
1153
|
-
strength,
|
|
1154
|
-
resolveReady,
|
|
1155
|
-
ready
|
|
1156
|
-
} = aesCrypto;
|
|
1157
|
-
let preamble = new Uint8Array();
|
|
1158
|
-
if (password) {
|
|
1159
|
-
preamble = await createEncryptionKeys(aesCrypto, strength, password);
|
|
1160
|
-
resolveReady();
|
|
1161
|
-
} else {
|
|
1162
|
-
await ready;
|
|
1163
|
-
}
|
|
1164
|
-
const output = new Uint8Array(preamble.length + chunk.length - (chunk.length % BLOCK_LENGTH));
|
|
1165
|
-
output.set(preamble, 0);
|
|
1166
|
-
controller.enqueue(append(aesCrypto, chunk, output, preamble.length, 0));
|
|
1167
|
-
},
|
|
1168
|
-
async flush(controller) {
|
|
1169
|
-
const {
|
|
1170
|
-
ctr,
|
|
1171
|
-
hmac,
|
|
1172
|
-
pending,
|
|
1173
|
-
ready
|
|
1174
|
-
} = this;
|
|
1175
|
-
await ready;
|
|
1176
|
-
let encryptedChunkArray = new Uint8Array();
|
|
1177
|
-
if (pending.length) {
|
|
1178
|
-
const encryptedChunk = ctr.update(toBits(codecBytes, pending));
|
|
1179
|
-
hmac.update(encryptedChunk);
|
|
1180
|
-
encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
|
|
1181
|
-
}
|
|
1182
|
-
stream.signature = fromBits(codecBytes, hmac.digest()).slice(0, SIGNATURE_LENGTH);
|
|
1183
|
-
controller.enqueue(concat(encryptedChunkArray, stream.signature));
|
|
1184
|
-
}
|
|
1185
|
-
});
|
|
1186
|
-
stream = this;
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
function append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {
|
|
1191
|
-
const {
|
|
1192
|
-
ctr,
|
|
1193
|
-
hmac,
|
|
1194
|
-
pending
|
|
1195
|
-
} = aesCrypto;
|
|
1196
|
-
const inputLength = input.length - paddingEnd;
|
|
1197
|
-
if (pending.length) {
|
|
1198
|
-
input = concat(pending, input);
|
|
1199
|
-
output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
|
|
1200
|
-
}
|
|
1201
|
-
let offset;
|
|
1202
|
-
for (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {
|
|
1203
|
-
const inputChunk = toBits(codecBytes, subarray(input, offset, offset + BLOCK_LENGTH));
|
|
1204
|
-
if (verifySignature) {
|
|
1205
|
-
hmac.update(inputChunk);
|
|
1206
|
-
}
|
|
1207
|
-
const outputChunk = ctr.update(inputChunk);
|
|
1208
|
-
if (!verifySignature) {
|
|
1209
|
-
hmac.update(outputChunk);
|
|
1210
|
-
}
|
|
1211
|
-
output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
|
|
1212
|
-
}
|
|
1213
|
-
aesCrypto.pending = subarray(input, offset);
|
|
1214
|
-
return output;
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
async function createDecryptionKeys(decrypt, strength, password, preamble) {
|
|
1218
|
-
const passwordVerificationKey = await createKeys$1(decrypt, strength, password, subarray(preamble, 0, SALT_LENGTH[strength]));
|
|
1219
|
-
const passwordVerification = subarray(preamble, SALT_LENGTH[strength]);
|
|
1220
|
-
if (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {
|
|
1221
|
-
throw new Error(ERR_INVALID_PASSWORD);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
async function createEncryptionKeys(encrypt, strength, password) {
|
|
1226
|
-
const salt = getRandomValues(new Uint8Array(SALT_LENGTH[strength]));
|
|
1227
|
-
const passwordVerification = await createKeys$1(encrypt, strength, password, salt);
|
|
1228
|
-
return concat(salt, passwordVerification);
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
async function createKeys$1(aesCrypto, strength, password, salt) {
|
|
1232
|
-
aesCrypto.password = null;
|
|
1233
|
-
const encodedPassword = encodeText(password);
|
|
1234
|
-
const baseKey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
|
|
1235
|
-
const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), baseKey, 8 * ((KEY_LENGTH[strength] * 2) + 2));
|
|
1236
|
-
const compositeKey = new Uint8Array(derivedBits);
|
|
1237
|
-
const key = toBits(codecBytes, subarray(compositeKey, 0, KEY_LENGTH[strength]));
|
|
1238
|
-
const authentication = toBits(codecBytes, subarray(compositeKey, KEY_LENGTH[strength], KEY_LENGTH[strength] * 2));
|
|
1239
|
-
const passwordVerification = subarray(compositeKey, KEY_LENGTH[strength] * 2);
|
|
1240
|
-
Object.assign(aesCrypto, {
|
|
1241
|
-
keys: {
|
|
1242
|
-
key,
|
|
1243
|
-
authentication,
|
|
1244
|
-
passwordVerification
|
|
1245
|
-
},
|
|
1246
|
-
ctr: new CtrGladman(new Aes(key), Array.from(COUNTER_DEFAULT_VALUE)),
|
|
1247
|
-
hmac: new HmacSha1(authentication)
|
|
1248
|
-
});
|
|
1249
|
-
return passwordVerification;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
function importKey(format, password, algorithm, extractable, keyUsages) {
|
|
1253
|
-
if (IMPORT_KEY_SUPPORTED) {
|
|
1254
|
-
return subtle.importKey(format, password, algorithm, extractable, keyUsages);
|
|
1255
|
-
} else {
|
|
1256
|
-
return misc.importKey(password);
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
async function deriveBits(algorithm, baseKey, length) {
|
|
1261
|
-
if (DERIVE_BITS_SUPPORTED) {
|
|
1262
|
-
return await subtle.deriveBits(algorithm, baseKey, length);
|
|
1263
|
-
} else {
|
|
1264
|
-
return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
function concat(leftArray, rightArray) {
|
|
1269
|
-
let array = leftArray;
|
|
1270
|
-
if (leftArray.length + rightArray.length) {
|
|
1271
|
-
array = new Uint8Array(leftArray.length + rightArray.length);
|
|
1272
|
-
array.set(leftArray, 0);
|
|
1273
|
-
array.set(rightArray, leftArray.length);
|
|
1274
|
-
}
|
|
1275
|
-
return array;
|
|
1276
|
-
}
|
|
1326
|
+
/* global crypto */
|
|
1277
1327
|
|
|
1278
|
-
|
|
1279
|
-
if (length && length > inputArray.length) {
|
|
1280
|
-
const array = inputArray;
|
|
1281
|
-
inputArray = new Uint8Array(length);
|
|
1282
|
-
inputArray.set(array, 0);
|
|
1283
|
-
}
|
|
1284
|
-
return inputArray;
|
|
1285
|
-
}
|
|
1328
|
+
const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != "undefined" && typeof crypto.getRandomValues == "function";
|
|
1286
1329
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
}
|
|
1330
|
+
const ERR_INVALID_PASSWORD = "Invalid password";
|
|
1331
|
+
const ERR_INVALID_SIGNATURE = "Invalid signature";
|
|
1290
1332
|
|
|
1291
|
-
function
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1333
|
+
function getRandomValues(array) {
|
|
1334
|
+
if (GET_RANDOM_VALUES_SUPPORTED) {
|
|
1335
|
+
return crypto.getRandomValues(array);
|
|
1336
|
+
} else {
|
|
1337
|
+
return random.getRandomValues(array);
|
|
1338
|
+
}
|
|
1296
1339
|
}
|
|
1297
1340
|
|
|
1298
1341
|
/*
|
|
@@ -1323,257 +1366,255 @@
|
|
|
1323
1366
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1324
1367
|
*/
|
|
1325
1368
|
|
|
1326
|
-
const
|
|
1369
|
+
const BLOCK_LENGTH = 16;
|
|
1370
|
+
const RAW_FORMAT = "raw";
|
|
1371
|
+
const PBKDF2_ALGORITHM = { name: "PBKDF2" };
|
|
1372
|
+
const HASH_ALGORITHM = { name: "HMAC" };
|
|
1373
|
+
const HASH_FUNCTION = "SHA-1";
|
|
1374
|
+
const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
|
|
1375
|
+
const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
|
|
1376
|
+
const DERIVED_BITS_USAGE = ["deriveBits"];
|
|
1377
|
+
const SALT_LENGTH = [8, 12, 16];
|
|
1378
|
+
const KEY_LENGTH = [16, 24, 32];
|
|
1379
|
+
const SIGNATURE_LENGTH = 10;
|
|
1380
|
+
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
1381
|
+
const UNDEFINED_TYPE = "undefined";
|
|
1382
|
+
const FUNCTION_TYPE = "function";
|
|
1383
|
+
// deno-lint-ignore valid-typeof
|
|
1384
|
+
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
|
|
1385
|
+
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
1386
|
+
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE;
|
|
1387
|
+
const IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
|
|
1388
|
+
const DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
|
|
1389
|
+
const codecBytes = codec.bytes;
|
|
1390
|
+
const Aes = cipher.aes;
|
|
1391
|
+
const CtrGladman = mode.ctrGladman;
|
|
1392
|
+
const HmacSha1 = misc.hmacSha1;
|
|
1327
1393
|
|
|
1328
|
-
class
|
|
1394
|
+
class AESDecryptionStream extends TransformStream {
|
|
1329
1395
|
|
|
1330
|
-
constructor(password,
|
|
1396
|
+
constructor(password, signed, strength) {
|
|
1331
1397
|
super({
|
|
1332
1398
|
start() {
|
|
1333
1399
|
Object.assign(this, {
|
|
1400
|
+
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
1334
1401
|
password,
|
|
1335
|
-
|
|
1402
|
+
signed,
|
|
1403
|
+
strength: strength - 1,
|
|
1404
|
+
pending: new Uint8Array()
|
|
1336
1405
|
});
|
|
1337
|
-
createKeys(this, password);
|
|
1338
1406
|
},
|
|
1339
|
-
transform(chunk, controller) {
|
|
1340
|
-
const
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1407
|
+
async transform(chunk, controller) {
|
|
1408
|
+
const aesCrypto = this;
|
|
1409
|
+
const {
|
|
1410
|
+
password,
|
|
1411
|
+
strength,
|
|
1412
|
+
resolveReady,
|
|
1413
|
+
ready
|
|
1414
|
+
} = aesCrypto;
|
|
1415
|
+
if (password) {
|
|
1416
|
+
await createDecryptionKeys(aesCrypto, strength, password, subarray(chunk, 0, SALT_LENGTH[strength] + 2));
|
|
1417
|
+
chunk = subarray(chunk, SALT_LENGTH[strength] + 2);
|
|
1418
|
+
resolveReady();
|
|
1419
|
+
} else {
|
|
1420
|
+
await ready;
|
|
1421
|
+
}
|
|
1422
|
+
const output = new Uint8Array(chunk.length - SIGNATURE_LENGTH - ((chunk.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
|
|
1423
|
+
controller.enqueue(append(aesCrypto, chunk, output, 0, SIGNATURE_LENGTH, true));
|
|
1424
|
+
},
|
|
1425
|
+
async flush(controller) {
|
|
1426
|
+
const {
|
|
1427
|
+
signed,
|
|
1428
|
+
ctr,
|
|
1429
|
+
hmac,
|
|
1430
|
+
pending,
|
|
1431
|
+
ready
|
|
1432
|
+
} = this;
|
|
1433
|
+
await ready;
|
|
1434
|
+
const chunkToDecrypt = subarray(pending, 0, pending.length - SIGNATURE_LENGTH);
|
|
1435
|
+
const originalSignature = subarray(pending, pending.length - SIGNATURE_LENGTH);
|
|
1436
|
+
let decryptedChunkArray = new Uint8Array();
|
|
1437
|
+
if (chunkToDecrypt.length) {
|
|
1438
|
+
const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
|
|
1439
|
+
hmac.update(encryptedChunk);
|
|
1440
|
+
const decryptedChunk = ctr.update(encryptedChunk);
|
|
1441
|
+
decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
|
|
1442
|
+
}
|
|
1443
|
+
if (signed) {
|
|
1444
|
+
const signature = subarray(fromBits(codecBytes, hmac.digest()), 0, SIGNATURE_LENGTH);
|
|
1445
|
+
for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
|
|
1446
|
+
if (signature[indexSignature] != originalSignature[indexSignature]) {
|
|
1447
|
+
throw new Error(ERR_INVALID_SIGNATURE);
|
|
1448
|
+
}
|
|
1346
1449
|
}
|
|
1347
|
-
chunk = chunk.subarray(HEADER_LENGTH);
|
|
1348
1450
|
}
|
|
1349
|
-
controller.enqueue(
|
|
1451
|
+
controller.enqueue(decryptedChunkArray);
|
|
1350
1452
|
}
|
|
1351
1453
|
});
|
|
1352
1454
|
}
|
|
1353
1455
|
}
|
|
1354
1456
|
|
|
1355
|
-
class
|
|
1457
|
+
class AESEncryptionStream extends TransformStream {
|
|
1356
1458
|
|
|
1357
|
-
constructor(password,
|
|
1459
|
+
constructor(password, strength) {
|
|
1460
|
+
// deno-lint-ignore prefer-const
|
|
1461
|
+
let stream;
|
|
1358
1462
|
super({
|
|
1359
1463
|
start() {
|
|
1360
1464
|
Object.assign(this, {
|
|
1465
|
+
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
1361
1466
|
password,
|
|
1362
|
-
|
|
1467
|
+
strength: strength - 1,
|
|
1468
|
+
pending: new Uint8Array()
|
|
1363
1469
|
});
|
|
1364
|
-
createKeys(this, password);
|
|
1365
1470
|
},
|
|
1366
|
-
transform(chunk, controller) {
|
|
1367
|
-
const
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1471
|
+
async transform(chunk, controller) {
|
|
1472
|
+
const aesCrypto = this;
|
|
1473
|
+
const {
|
|
1474
|
+
password,
|
|
1475
|
+
strength,
|
|
1476
|
+
resolveReady,
|
|
1477
|
+
ready
|
|
1478
|
+
} = aesCrypto;
|
|
1479
|
+
let preamble = new Uint8Array();
|
|
1480
|
+
if (password) {
|
|
1481
|
+
preamble = await createEncryptionKeys(aesCrypto, strength, password);
|
|
1482
|
+
resolveReady();
|
|
1377
1483
|
} else {
|
|
1378
|
-
|
|
1379
|
-
offset = 0;
|
|
1484
|
+
await ready;
|
|
1380
1485
|
}
|
|
1381
|
-
output.
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
updateKeys(target, input[index]);
|
|
1402
|
-
}
|
|
1403
|
-
return output;
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
function createKeys(target, password) {
|
|
1407
|
-
const keys = [0x12345678, 0x23456789, 0x34567890];
|
|
1408
|
-
Object.assign(target, {
|
|
1409
|
-
keys,
|
|
1410
|
-
crcKey0: new Crc32(keys[0]),
|
|
1411
|
-
crcKey2: new Crc32(keys[2]),
|
|
1412
|
-
});
|
|
1413
|
-
for (let index = 0; index < password.length; index++) {
|
|
1414
|
-
updateKeys(target, password.charCodeAt(index));
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
|
-
function updateKeys(target, byte) {
|
|
1419
|
-
let [key0, key1, key2] = target.keys;
|
|
1420
|
-
target.crcKey0.append([byte]);
|
|
1421
|
-
key0 = ~target.crcKey0.get();
|
|
1422
|
-
key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
|
|
1423
|
-
target.crcKey2.append([key1 >>> 24]);
|
|
1424
|
-
key2 = ~target.crcKey2.get();
|
|
1425
|
-
target.keys = [key0, key1, key2];
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
function getByte(target) {
|
|
1429
|
-
const temp = target.keys[2] | 2;
|
|
1430
|
-
return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
function getInt8(number) {
|
|
1434
|
-
return number & 0xFF;
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
function getInt32(number) {
|
|
1438
|
-
return number & 0xFFFFFFFF;
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
/*
|
|
1442
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1443
|
-
|
|
1444
|
-
Redistribution and use in source and binary forms, with or without
|
|
1445
|
-
modification, are permitted provided that the following conditions are met:
|
|
1446
|
-
|
|
1447
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
1448
|
-
this list of conditions and the following disclaimer.
|
|
1449
|
-
|
|
1450
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
1451
|
-
notice, this list of conditions and the following disclaimer in
|
|
1452
|
-
the documentation and/or other materials provided with the distribution.
|
|
1453
|
-
|
|
1454
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
1455
|
-
derived from this software without specific prior written permission.
|
|
1456
|
-
|
|
1457
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1458
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1459
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1460
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1461
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1462
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1463
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1464
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1465
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1466
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1467
|
-
*/
|
|
1468
|
-
|
|
1469
|
-
const COMPRESSION_FORMAT = "deflate-raw";
|
|
1470
|
-
|
|
1471
|
-
class DeflateStream extends TransformStream {
|
|
1472
|
-
|
|
1473
|
-
constructor(options, { chunkSize, CompressionStream, CompressionStreamNative }) {
|
|
1474
|
-
super({});
|
|
1475
|
-
const { compressed, encrypted, useCompressionStream, password, passwordVerification, encryptionStrength, zipCrypto, signed, level } = options;
|
|
1476
|
-
const stream = this;
|
|
1477
|
-
let crc32Stream, encryptionStream;
|
|
1478
|
-
let readable = filterEmptyChunks(super.readable);
|
|
1479
|
-
if ((!encrypted || zipCrypto) && signed) {
|
|
1480
|
-
[readable, crc32Stream] = readable.tee();
|
|
1481
|
-
crc32Stream = pipeThrough(crc32Stream, new Crc32Stream());
|
|
1482
|
-
}
|
|
1483
|
-
if (compressed) {
|
|
1484
|
-
readable = pipeThroughCommpressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStreamNative, CompressionStream);
|
|
1485
|
-
}
|
|
1486
|
-
if (encrypted) {
|
|
1487
|
-
if (zipCrypto) {
|
|
1488
|
-
readable = pipeThrough(readable, new ZipCryptoEncryptionStream(password, passwordVerification));
|
|
1489
|
-
} else {
|
|
1490
|
-
encryptionStream = new AESEncryptionStream(password, encryptionStrength);
|
|
1491
|
-
readable = pipeThrough(readable, encryptionStream);
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
setReadable(stream, readable, async () => {
|
|
1495
|
-
let signature;
|
|
1496
|
-
if (encrypted && !zipCrypto) {
|
|
1497
|
-
signature = encryptionStream.signature;
|
|
1498
|
-
}
|
|
1499
|
-
if ((!encrypted || zipCrypto) && signed) {
|
|
1500
|
-
signature = await crc32Stream.getReader().read();
|
|
1501
|
-
signature = new DataView(signature.value.buffer).getUint32(0);
|
|
1486
|
+
const output = new Uint8Array(preamble.length + chunk.length - (chunk.length % BLOCK_LENGTH));
|
|
1487
|
+
output.set(preamble, 0);
|
|
1488
|
+
controller.enqueue(append(aesCrypto, chunk, output, preamble.length, 0));
|
|
1489
|
+
},
|
|
1490
|
+
async flush(controller) {
|
|
1491
|
+
const {
|
|
1492
|
+
ctr,
|
|
1493
|
+
hmac,
|
|
1494
|
+
pending,
|
|
1495
|
+
ready
|
|
1496
|
+
} = this;
|
|
1497
|
+
await ready;
|
|
1498
|
+
let encryptedChunkArray = new Uint8Array();
|
|
1499
|
+
if (pending.length) {
|
|
1500
|
+
const encryptedChunk = ctr.update(toBits(codecBytes, pending));
|
|
1501
|
+
hmac.update(encryptedChunk);
|
|
1502
|
+
encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
|
|
1503
|
+
}
|
|
1504
|
+
stream.signature = fromBits(codecBytes, hmac.digest()).slice(0, SIGNATURE_LENGTH);
|
|
1505
|
+
controller.enqueue(concat(encryptedChunkArray, stream.signature));
|
|
1502
1506
|
}
|
|
1503
|
-
stream.signature = signature;
|
|
1504
1507
|
});
|
|
1508
|
+
stream = this;
|
|
1505
1509
|
}
|
|
1506
1510
|
}
|
|
1507
1511
|
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
readable = pipeThroughCommpressionStream(readable, useCompressionStream, { chunkSize }, DecompressionStreamNative, DecompressionStream);
|
|
1512
|
+
function append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {
|
|
1513
|
+
const {
|
|
1514
|
+
ctr,
|
|
1515
|
+
hmac,
|
|
1516
|
+
pending
|
|
1517
|
+
} = aesCrypto;
|
|
1518
|
+
const inputLength = input.length - paddingEnd;
|
|
1519
|
+
if (pending.length) {
|
|
1520
|
+
input = concat(pending, input);
|
|
1521
|
+
output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
|
|
1522
|
+
}
|
|
1523
|
+
let offset;
|
|
1524
|
+
for (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {
|
|
1525
|
+
const inputChunk = toBits(codecBytes, subarray(input, offset, offset + BLOCK_LENGTH));
|
|
1526
|
+
if (verifySignature) {
|
|
1527
|
+
hmac.update(inputChunk);
|
|
1525
1528
|
}
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
+
const outputChunk = ctr.update(inputChunk);
|
|
1530
|
+
if (!verifySignature) {
|
|
1531
|
+
hmac.update(outputChunk);
|
|
1529
1532
|
}
|
|
1530
|
-
|
|
1531
|
-
if ((!encrypted || zipCrypto) && signed) {
|
|
1532
|
-
const streamSignature = await crc32Stream.getReader().read();
|
|
1533
|
-
const dataViewSignature = new DataView(streamSignature.value.buffer);
|
|
1534
|
-
if (signature != dataViewSignature.getUint32(0, false)) {
|
|
1535
|
-
throw new Error(ERR_INVALID_SIGNATURE);
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
});
|
|
1533
|
+
output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
|
|
1539
1534
|
}
|
|
1535
|
+
aesCrypto.pending = subarray(input, offset);
|
|
1536
|
+
return output;
|
|
1540
1537
|
}
|
|
1541
1538
|
|
|
1542
|
-
function
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
}
|
|
1549
|
-
}));
|
|
1539
|
+
async function createDecryptionKeys(decrypt, strength, password, preamble) {
|
|
1540
|
+
const passwordVerificationKey = await createKeys$1(decrypt, strength, password, subarray(preamble, 0, SALT_LENGTH[strength]));
|
|
1541
|
+
const passwordVerification = subarray(preamble, SALT_LENGTH[strength]);
|
|
1542
|
+
if (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {
|
|
1543
|
+
throw new Error(ERR_INVALID_PASSWORD);
|
|
1544
|
+
}
|
|
1550
1545
|
}
|
|
1551
1546
|
|
|
1552
|
-
function
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1547
|
+
async function createEncryptionKeys(encrypt, strength, password) {
|
|
1548
|
+
const salt = getRandomValues(new Uint8Array(SALT_LENGTH[strength]));
|
|
1549
|
+
const passwordVerification = await createKeys$1(encrypt, strength, password, salt);
|
|
1550
|
+
return concat(salt, passwordVerification);
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
async function createKeys$1(aesCrypto, strength, password, salt) {
|
|
1554
|
+
aesCrypto.password = null;
|
|
1555
|
+
const encodedPassword = encodeText(password);
|
|
1556
|
+
const baseKey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
|
|
1557
|
+
const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), baseKey, 8 * ((KEY_LENGTH[strength] * 2) + 2));
|
|
1558
|
+
const compositeKey = new Uint8Array(derivedBits);
|
|
1559
|
+
const key = toBits(codecBytes, subarray(compositeKey, 0, KEY_LENGTH[strength]));
|
|
1560
|
+
const authentication = toBits(codecBytes, subarray(compositeKey, KEY_LENGTH[strength], KEY_LENGTH[strength] * 2));
|
|
1561
|
+
const passwordVerification = subarray(compositeKey, KEY_LENGTH[strength] * 2);
|
|
1562
|
+
Object.assign(aesCrypto, {
|
|
1563
|
+
keys: {
|
|
1564
|
+
key,
|
|
1565
|
+
authentication,
|
|
1566
|
+
passwordVerification
|
|
1567
|
+
},
|
|
1568
|
+
ctr: new CtrGladman(new Aes(key), Array.from(COUNTER_DEFAULT_VALUE)),
|
|
1569
|
+
hmac: new HmacSha1(authentication)
|
|
1558
1570
|
});
|
|
1571
|
+
return passwordVerification;
|
|
1559
1572
|
}
|
|
1560
1573
|
|
|
1561
|
-
function
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
if (useCompressionStream) {
|
|
1567
|
-
readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
|
|
1568
|
-
} else {
|
|
1569
|
-
throw error;
|
|
1570
|
-
}
|
|
1574
|
+
function importKey(format, password, algorithm, extractable, keyUsages) {
|
|
1575
|
+
if (IMPORT_KEY_SUPPORTED) {
|
|
1576
|
+
return subtle.importKey(format, password, algorithm, extractable, keyUsages);
|
|
1577
|
+
} else {
|
|
1578
|
+
return misc.importKey(password);
|
|
1571
1579
|
}
|
|
1572
|
-
return readable;
|
|
1573
1580
|
}
|
|
1574
1581
|
|
|
1575
|
-
function
|
|
1576
|
-
|
|
1582
|
+
async function deriveBits(algorithm, baseKey, length) {
|
|
1583
|
+
if (DERIVE_BITS_SUPPORTED) {
|
|
1584
|
+
return await subtle.deriveBits(algorithm, baseKey, length);
|
|
1585
|
+
} else {
|
|
1586
|
+
return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
function concat(leftArray, rightArray) {
|
|
1591
|
+
let array = leftArray;
|
|
1592
|
+
if (leftArray.length + rightArray.length) {
|
|
1593
|
+
array = new Uint8Array(leftArray.length + rightArray.length);
|
|
1594
|
+
array.set(leftArray, 0);
|
|
1595
|
+
array.set(rightArray, leftArray.length);
|
|
1596
|
+
}
|
|
1597
|
+
return array;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
function expand(inputArray, length) {
|
|
1601
|
+
if (length && length > inputArray.length) {
|
|
1602
|
+
const array = inputArray;
|
|
1603
|
+
inputArray = new Uint8Array(length);
|
|
1604
|
+
inputArray.set(array, 0);
|
|
1605
|
+
}
|
|
1606
|
+
return inputArray;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
function subarray(array, begin, end) {
|
|
1610
|
+
return array.subarray(begin, end);
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
function fromBits(codecBytes, chunk) {
|
|
1614
|
+
return codecBytes.fromBits(chunk);
|
|
1615
|
+
}
|
|
1616
|
+
function toBits(codecBytes, chunk) {
|
|
1617
|
+
return codecBytes.toBits(chunk);
|
|
1577
1618
|
}
|
|
1578
1619
|
|
|
1579
1620
|
/*
|
|
@@ -1604,195 +1645,120 @@
|
|
|
1604
1645
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1605
1646
|
*/
|
|
1606
1647
|
|
|
1607
|
-
|
|
1608
|
-
* This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.
|
|
1609
|
-
* JZlib is based on zlib-1.1.3, so all credit should go authors
|
|
1610
|
-
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
|
1611
|
-
* and contributors of zlib.
|
|
1612
|
-
*/
|
|
1613
|
-
|
|
1614
|
-
/* global TransformStream */
|
|
1648
|
+
const HEADER_LENGTH = 12;
|
|
1615
1649
|
|
|
1616
|
-
class
|
|
1650
|
+
class ZipCryptoDecryptionStream extends TransformStream {
|
|
1617
1651
|
|
|
1618
|
-
constructor(
|
|
1619
|
-
const codec = new Codec(options);
|
|
1652
|
+
constructor(password, passwordVerification) {
|
|
1620
1653
|
super({
|
|
1621
|
-
|
|
1622
|
-
|
|
1654
|
+
start() {
|
|
1655
|
+
Object.assign(this, {
|
|
1656
|
+
password,
|
|
1657
|
+
passwordVerification
|
|
1658
|
+
});
|
|
1659
|
+
createKeys(this, password);
|
|
1623
1660
|
},
|
|
1624
|
-
|
|
1625
|
-
const
|
|
1626
|
-
if (
|
|
1627
|
-
|
|
1661
|
+
transform(chunk, controller) {
|
|
1662
|
+
const zipCrypto = this;
|
|
1663
|
+
if (zipCrypto.password) {
|
|
1664
|
+
const decryptedHeader = decrypt(zipCrypto, chunk.subarray(0, HEADER_LENGTH));
|
|
1665
|
+
zipCrypto.password = null;
|
|
1666
|
+
if (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {
|
|
1667
|
+
throw new Error(ERR_INVALID_PASSWORD);
|
|
1668
|
+
}
|
|
1669
|
+
chunk = chunk.subarray(HEADER_LENGTH);
|
|
1628
1670
|
}
|
|
1671
|
+
controller.enqueue(decrypt(zipCrypto, chunk));
|
|
1629
1672
|
}
|
|
1630
1673
|
});
|
|
1631
1674
|
}
|
|
1632
1675
|
}
|
|
1633
1676
|
|
|
1634
|
-
|
|
1635
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
1636
|
-
|
|
1637
|
-
Redistribution and use in source and binary forms, with or without
|
|
1638
|
-
modification, are permitted provided that the following conditions are met:
|
|
1639
|
-
|
|
1640
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
1641
|
-
this list of conditions and the following disclaimer.
|
|
1642
|
-
|
|
1643
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
1644
|
-
notice, this list of conditions and the following disclaimer in
|
|
1645
|
-
the documentation and/or other materials provided with the distribution.
|
|
1646
|
-
|
|
1647
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
1648
|
-
derived from this software without specific prior written permission.
|
|
1649
|
-
|
|
1650
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1651
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1652
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1653
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1654
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1655
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1656
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1657
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1658
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1659
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1660
|
-
*/
|
|
1661
|
-
|
|
1662
|
-
const CODEC_DEFLATE = "deflate";
|
|
1663
|
-
const CODEC_INFLATE = "inflate";
|
|
1664
|
-
const MESSAGE_EVENT_TYPE = "message";
|
|
1665
|
-
const MESSAGE_START = "start";
|
|
1666
|
-
const MESSAGE_PULL = "pull";
|
|
1667
|
-
const MESSAGE_DATA = "data";
|
|
1668
|
-
const MESSAGE_ACK_DATA = "ack";
|
|
1669
|
-
const MESSAGE_CLOSE = "close";
|
|
1670
|
-
|
|
1671
|
-
class Codec {
|
|
1677
|
+
class ZipCryptoEncryptionStream extends TransformStream {
|
|
1672
1678
|
|
|
1673
|
-
constructor(
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1679
|
+
constructor(password, passwordVerification) {
|
|
1680
|
+
super({
|
|
1681
|
+
start() {
|
|
1682
|
+
Object.assign(this, {
|
|
1683
|
+
password,
|
|
1684
|
+
passwordVerification
|
|
1685
|
+
});
|
|
1686
|
+
createKeys(this, password);
|
|
1687
|
+
},
|
|
1688
|
+
transform(chunk, controller) {
|
|
1689
|
+
const zipCrypto = this;
|
|
1690
|
+
let output;
|
|
1691
|
+
let offset;
|
|
1692
|
+
if (zipCrypto.password) {
|
|
1693
|
+
zipCrypto.password = null;
|
|
1694
|
+
const header = getRandomValues(new Uint8Array(HEADER_LENGTH));
|
|
1695
|
+
header[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;
|
|
1696
|
+
output = new Uint8Array(chunk.length + header.length);
|
|
1697
|
+
output.set(encrypt(zipCrypto, header), 0);
|
|
1698
|
+
offset = HEADER_LENGTH;
|
|
1699
|
+
} else {
|
|
1700
|
+
output = new Uint8Array(chunk.length);
|
|
1701
|
+
offset = 0;
|
|
1702
|
+
}
|
|
1703
|
+
output.set(encrypt(zipCrypto, chunk), offset);
|
|
1704
|
+
controller.enqueue(output);
|
|
1705
|
+
}
|
|
1687
1706
|
});
|
|
1688
1707
|
}
|
|
1708
|
+
}
|
|
1689
1709
|
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
options,
|
|
1696
|
-
config
|
|
1697
|
-
} = this;
|
|
1698
|
-
const stream = new CodecStream(options, config);
|
|
1699
|
-
let size = 0;
|
|
1700
|
-
await readable
|
|
1701
|
-
.pipeThrough(stream)
|
|
1702
|
-
.pipeThrough(new TransformStream({
|
|
1703
|
-
transform(chunk, controller) {
|
|
1704
|
-
if (chunk && chunk.length) {
|
|
1705
|
-
size += chunk.length;
|
|
1706
|
-
controller.enqueue(chunk);
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
}))
|
|
1710
|
-
.pipeTo(writable, { preventClose: true, preventAbort: true });
|
|
1711
|
-
const { signature } = stream;
|
|
1712
|
-
return { size, signature };
|
|
1710
|
+
function decrypt(target, input) {
|
|
1711
|
+
const output = new Uint8Array(input.length);
|
|
1712
|
+
for (let index = 0; index < input.length; index++) {
|
|
1713
|
+
output[index] = getByte(target) ^ input[index];
|
|
1714
|
+
updateKeys(target, output[index]);
|
|
1713
1715
|
}
|
|
1716
|
+
return output;
|
|
1714
1717
|
}
|
|
1715
1718
|
|
|
1716
|
-
function
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
}
|
|
1719
|
+
function encrypt(target, input) {
|
|
1720
|
+
const output = new Uint8Array(input.length);
|
|
1721
|
+
for (let index = 0; index < input.length; index++) {
|
|
1722
|
+
output[index] = getByte(target) ^ input[index];
|
|
1723
|
+
updateKeys(target, input[index]);
|
|
1724
|
+
}
|
|
1725
|
+
return output;
|
|
1722
1726
|
}
|
|
1723
1727
|
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
the documentation and/or other materials provided with the distribution.
|
|
1736
|
-
|
|
1737
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
1738
|
-
derived from this software without specific prior written permission.
|
|
1739
|
-
|
|
1740
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1741
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1742
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1743
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1744
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1745
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1746
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1747
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1748
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1749
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1750
|
-
*/
|
|
1751
|
-
|
|
1752
|
-
const MAX_32_BITS = 0xffffffff;
|
|
1753
|
-
const MAX_16_BITS = 0xffff;
|
|
1754
|
-
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
1755
|
-
const COMPRESSION_METHOD_STORE = 0x00;
|
|
1756
|
-
const COMPRESSION_METHOD_AES = 0x63;
|
|
1757
|
-
|
|
1758
|
-
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
1759
|
-
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
1760
|
-
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
1761
|
-
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
1762
|
-
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
1763
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
1764
|
-
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
1765
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
1766
|
-
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
1767
|
-
const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
1768
|
-
|
|
1769
|
-
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
1770
|
-
|
|
1771
|
-
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
1772
|
-
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
1773
|
-
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
1774
|
-
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
1775
|
-
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
1776
|
-
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
1777
|
-
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
1778
|
-
|
|
1779
|
-
const BITFLAG_ENCRYPTED = 0x01;
|
|
1780
|
-
const BITFLAG_LEVEL = 0x06;
|
|
1781
|
-
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
1782
|
-
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
1783
|
-
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
1728
|
+
function createKeys(target, password) {
|
|
1729
|
+
const keys = [0x12345678, 0x23456789, 0x34567890];
|
|
1730
|
+
Object.assign(target, {
|
|
1731
|
+
keys,
|
|
1732
|
+
crcKey0: new Crc32(keys[0]),
|
|
1733
|
+
crcKey2: new Crc32(keys[2]),
|
|
1734
|
+
});
|
|
1735
|
+
for (let index = 0; index < password.length; index++) {
|
|
1736
|
+
updateKeys(target, password.charCodeAt(index));
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1784
1739
|
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1740
|
+
function updateKeys(target, byte) {
|
|
1741
|
+
let [key0, key1, key2] = target.keys;
|
|
1742
|
+
target.crcKey0.append([byte]);
|
|
1743
|
+
key0 = ~target.crcKey0.get();
|
|
1744
|
+
key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
|
|
1745
|
+
target.crcKey2.append([key1 >>> 24]);
|
|
1746
|
+
key2 = ~target.crcKey2.get();
|
|
1747
|
+
target.keys = [key0, key1, key2];
|
|
1748
|
+
}
|
|
1788
1749
|
|
|
1789
|
-
|
|
1750
|
+
function getByte(target) {
|
|
1751
|
+
const temp = target.keys[2] | 2;
|
|
1752
|
+
return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
|
|
1753
|
+
}
|
|
1790
1754
|
|
|
1791
|
-
|
|
1792
|
-
|
|
1755
|
+
function getInt8(number) {
|
|
1756
|
+
return number & 0xFF;
|
|
1757
|
+
}
|
|
1793
1758
|
|
|
1794
|
-
|
|
1795
|
-
|
|
1759
|
+
function getInt32(number) {
|
|
1760
|
+
return number & 0xFFFFFFFF;
|
|
1761
|
+
}
|
|
1796
1762
|
|
|
1797
1763
|
/*
|
|
1798
1764
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -1822,93 +1788,115 @@
|
|
|
1822
1788
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1823
1789
|
*/
|
|
1824
1790
|
|
|
1825
|
-
const
|
|
1826
|
-
let maxWorkers = 2;
|
|
1827
|
-
try {
|
|
1828
|
-
if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
|
|
1829
|
-
maxWorkers = navigator.hardwareConcurrency;
|
|
1830
|
-
}
|
|
1831
|
-
} catch (_error) {
|
|
1832
|
-
// ignored
|
|
1833
|
-
}
|
|
1834
|
-
const DEFAULT_CONFIGURATION = {
|
|
1835
|
-
chunkSize: 512 * 1024,
|
|
1836
|
-
maxWorkers,
|
|
1837
|
-
terminateWorkerTimeout: 5000,
|
|
1838
|
-
useWebWorkers: true,
|
|
1839
|
-
useCompressionStream: true,
|
|
1840
|
-
workerScripts: UNDEFINED_VALUE,
|
|
1841
|
-
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
|
|
1842
|
-
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
|
|
1843
|
-
};
|
|
1791
|
+
const COMPRESSION_FORMAT = "deflate-raw";
|
|
1844
1792
|
|
|
1845
|
-
|
|
1793
|
+
class DeflateStream extends TransformStream {
|
|
1846
1794
|
|
|
1847
|
-
|
|
1848
|
-
|
|
1795
|
+
constructor(options, { chunkSize, CompressionStream, CompressionStreamNative }) {
|
|
1796
|
+
super({});
|
|
1797
|
+
const { compressed, encrypted, useCompressionStream, password, passwordVerification, encryptionStrength, zipCrypto, signed, level } = options;
|
|
1798
|
+
const stream = this;
|
|
1799
|
+
let crc32Stream, encryptionStream;
|
|
1800
|
+
let readable = filterEmptyChunks(super.readable);
|
|
1801
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
1802
|
+
[readable, crc32Stream] = readable.tee();
|
|
1803
|
+
crc32Stream = pipeThrough(crc32Stream, new Crc32Stream());
|
|
1804
|
+
}
|
|
1805
|
+
if (compressed) {
|
|
1806
|
+
readable = pipeThroughCommpressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStreamNative, CompressionStream);
|
|
1807
|
+
}
|
|
1808
|
+
if (encrypted) {
|
|
1809
|
+
if (zipCrypto) {
|
|
1810
|
+
readable = pipeThrough(readable, new ZipCryptoEncryptionStream(password, passwordVerification));
|
|
1811
|
+
} else {
|
|
1812
|
+
encryptionStream = new AESEncryptionStream(password, encryptionStrength);
|
|
1813
|
+
readable = pipeThrough(readable, encryptionStream);
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
setReadable(stream, readable, async () => {
|
|
1817
|
+
let signature;
|
|
1818
|
+
if (encrypted && !zipCrypto) {
|
|
1819
|
+
signature = encryptionStream.signature;
|
|
1820
|
+
}
|
|
1821
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
1822
|
+
signature = await crc32Stream.getReader().read();
|
|
1823
|
+
signature = new DataView(signature.value.buffer).getUint32(0);
|
|
1824
|
+
}
|
|
1825
|
+
stream.signature = signature;
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1849
1828
|
}
|
|
1850
1829
|
|
|
1851
|
-
|
|
1852
|
-
return Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
|
|
1853
|
-
}
|
|
1830
|
+
class InflateStream extends TransformStream {
|
|
1854
1831
|
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
DecompressionStream,
|
|
1867
|
-
workerScripts
|
|
1868
|
-
} = configuration;
|
|
1869
|
-
setIfDefined("baseURL", baseURL);
|
|
1870
|
-
setIfDefined("chunkSize", chunkSize);
|
|
1871
|
-
setIfDefined("maxWorkers", maxWorkers);
|
|
1872
|
-
setIfDefined("terminateWorkerTimeout", terminateWorkerTimeout);
|
|
1873
|
-
setIfDefined("useCompressionStream", useCompressionStream);
|
|
1874
|
-
setIfDefined("useWebWorkers", useWebWorkers);
|
|
1875
|
-
if (Deflate) {
|
|
1876
|
-
config.CompressionStream = getCodecStreamClass(Deflate);
|
|
1877
|
-
}
|
|
1878
|
-
if (Inflate) {
|
|
1879
|
-
config.DecompressionStream = getCodecStreamClass(Inflate);
|
|
1880
|
-
}
|
|
1881
|
-
setIfDefined("CompressionStream", CompressionStream);
|
|
1882
|
-
setIfDefined("DecompressionStream", DecompressionStream);
|
|
1883
|
-
if (workerScripts !== UNDEFINED_VALUE) {
|
|
1884
|
-
const { deflate, inflate } = workerScripts;
|
|
1885
|
-
if (deflate || inflate) {
|
|
1886
|
-
if (!config.workerScripts) {
|
|
1887
|
-
config.workerScripts = {};
|
|
1832
|
+
constructor(options, { chunkSize, DecompressionStream, DecompressionStreamNative }) {
|
|
1833
|
+
super({});
|
|
1834
|
+
const { zipCrypto, encrypted, password, passwordVerification, signed, signature, encryptionStrength, compressed, useCompressionStream } = options;
|
|
1835
|
+
let crc32Stream, decryptionStream;
|
|
1836
|
+
let readable = filterEmptyChunks(super.readable);
|
|
1837
|
+
if (encrypted) {
|
|
1838
|
+
if (zipCrypto) {
|
|
1839
|
+
readable = pipeThrough(readable, new ZipCryptoDecryptionStream(password, passwordVerification));
|
|
1840
|
+
} else {
|
|
1841
|
+
decryptionStream = new AESDecryptionStream(password, signed, encryptionStrength);
|
|
1842
|
+
readable = pipeThrough(readable, decryptionStream);
|
|
1888
1843
|
}
|
|
1889
1844
|
}
|
|
1890
|
-
if (
|
|
1891
|
-
|
|
1892
|
-
|
|
1845
|
+
if (compressed) {
|
|
1846
|
+
readable = pipeThroughCommpressionStream(readable, useCompressionStream, { chunkSize }, DecompressionStreamNative, DecompressionStream);
|
|
1847
|
+
}
|
|
1848
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
1849
|
+
[readable, crc32Stream] = readable.tee();
|
|
1850
|
+
crc32Stream = pipeThrough(crc32Stream, new Crc32Stream());
|
|
1851
|
+
}
|
|
1852
|
+
setReadable(this, readable, async () => {
|
|
1853
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
1854
|
+
const streamSignature = await crc32Stream.getReader().read();
|
|
1855
|
+
const dataViewSignature = new DataView(streamSignature.value.buffer);
|
|
1856
|
+
if (signature != dataViewSignature.getUint32(0, false)) {
|
|
1857
|
+
throw new Error(ERR_INVALID_SIGNATURE);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function filterEmptyChunks(readable) {
|
|
1865
|
+
return pipeThrough(readable, new TransformStream({
|
|
1866
|
+
transform(chunk, controller) {
|
|
1867
|
+
if (chunk && chunk.length) {
|
|
1868
|
+
controller.enqueue(chunk);
|
|
1893
1869
|
}
|
|
1894
|
-
config.workerScripts.deflate = deflate;
|
|
1895
1870
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1871
|
+
}));
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
function setReadable(stream, readable, flush) {
|
|
1875
|
+
readable = pipeThrough(readable, new TransformStream({ flush }));
|
|
1876
|
+
Object.defineProperty(stream, "readable", {
|
|
1877
|
+
get() {
|
|
1878
|
+
return readable;
|
|
1901
1879
|
}
|
|
1902
|
-
}
|
|
1880
|
+
});
|
|
1903
1881
|
}
|
|
1904
1882
|
|
|
1905
|
-
function
|
|
1906
|
-
|
|
1907
|
-
|
|
1883
|
+
function pipeThroughCommpressionStream(readable, useCompressionStream, options, CodecStreamNative, CodecStream) {
|
|
1884
|
+
try {
|
|
1885
|
+
const CompressionStream = useCompressionStream && CodecStreamNative ? CodecStreamNative : CodecStream;
|
|
1886
|
+
readable = pipeThrough(readable, new CompressionStream(COMPRESSION_FORMAT, options));
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
if (useCompressionStream) {
|
|
1889
|
+
readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
|
|
1890
|
+
} else {
|
|
1891
|
+
throw error;
|
|
1892
|
+
}
|
|
1908
1893
|
}
|
|
1894
|
+
return readable;
|
|
1909
1895
|
}
|
|
1910
1896
|
|
|
1911
|
-
function e(e){const t=()=>URL.createObjectURL(new Blob(['const{Array:e,Object:t,Math:n,Error:r,Uint8Array:s,Uint16Array:i,Uint32Array:o,Int32Array:c,Map:f,DataView:a,Promise:l,TextEncoder:u,crypto:w,postMessage:h,TransformStream:d,ReadableStream:p,WritableStream:y,CompressionStream:m,DecompressionStream:b}=self,g=[];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;g[e]=t}class k{constructor(e){this.t=e||-1}append(e){let t=0|this.t;for(let n=0,r=0|e.length;r>n;n++)t=t>>>8^g[255&(t^e[n])];this.t=t}get(){return~this.t}}class v extends d{constructor(){const e=new k;super({transform(t){e.append(t)},flush(t){const n=new s(4);new a(n.buffer).setUint32(0,e.get()),t.enqueue(n)}})}}const S={concat(e,t){if(0===e.length||0===t.length)return e.concat(t);const n=e[e.length-1],r=S.i(n);return 32===r?e.concat(t):S.o(t,r,0|n,e.slice(0,e.length-1))},l(e){const t=e.length;if(0===t)return 0;const n=e[t-1];return 32*(t-1)+S.i(n)},u(e,t){if(32*e.length<t)return e;const r=(e=e.slice(0,n.ceil(t/32))).length;return t&=31,r>0&&t&&(e[r-1]=S.h(t,e[r-1]&2147483648>>t-1,1)),e},h:(e,t,n)=>32===e?t:(n?0|t:t<<32-e)+1099511627776*e,i:e=>n.round(e/1099511627776)||32,o(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,i=S.i(s);return r.push(S.h(t+i&31,t+i>32?n:r.pop(),1)),r}},C={p:{m(e){const t=S.l(e)/8,n=new s(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},g(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(S.h(8*(3&n),r)),t}}},z={k:function(e){e?(this.v=e.v.slice(0),this.S=e.S.slice(0),this.C=e.C):this.reset()}};z.k.prototype={blockSize:512,reset(){const e=this;return e.v=this._.slice(0),e.S=[],e.C=0,e},update(e){const t=this;"string"==typeof e&&(e=C.I.g(e));const n=t.S=S.concat(t.S,e),s=t.C,i=t.C=s+S.l(e);if(i>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new o(n);let f=0;for(let e=t.blockSize+s-(t.blockSize+s&t.blockSize-1);i>=e;e+=t.blockSize)t.A(c.subarray(16*f,16*(f+1))),f+=1;return n.splice(0,16*f),t},D(){const e=this;let t=e.S;const r=e.v;t=S.concat(t,[S.h(1,1)]);for(let e=t.length+2;15&e;e++)t.push(0);for(t.push(n.floor(e.C/4294967296)),t.push(0|e.C);t.length;)e.A(t.splice(0,16));return e.reset(),r},_:[1732584193,4023233417,2562383102,271733878,3285377520],V:[1518500249,1859775393,2400959708,3395469782],R:(e,t,n,r)=>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,B:(e,t)=>t<<e|t>>>32-e,A(t){const r=this,s=r.v,i=e(80);for(let e=0;16>e;e++)i[e]=t[e];let o=s[0],c=s[1],f=s[2],a=s[3],l=s[4];for(let e=0;79>=e;e++){16>e||(i[e]=r.B(1,i[e-3]^i[e-8]^i[e-14]^i[e-16]));const t=r.B(5,o)+r.R(e,c,f,a)+l+i[e]+r.V[n.floor(e/20)]|0;l=a,a=f,f=r.B(30,c),c=o,o=t}s[0]=s[0]+o|0,s[1]=s[1]+c|0,s[2]=s[2]+f|0,s[3]=s[3]+a|0,s[4]=s[4]+l|0}};const _={getRandomValues(e){const t=new o(e.buffer),r=e=>{let t=987654321;const r=4294967295;return()=>(t=36969*(65535&t)+(t>>16)&r,(((t<<16)+(e=18e3*(65535&e)+(e>>16)&r)&r)/4294967296+.5)*(n.random()>.5?1:-1))};for(let s,i=0;i<e.length;i+=4){const e=r(4294967296*(s||n.random()));s=987654071*e(),t[i/4]=4294967296*e()|0}return e}},I={importKey:e=>new I.M(C.p.g(e)),K(e,t,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const i=1+(s>>5)<<2;let o,c,f,l,u;const w=new ArrayBuffer(i),h=new a(w);let d=0;const p=S;for(t=C.p.g(t),u=1;(i||1)>d;u++){for(o=c=e.encrypt(p.concat(t,[u])),f=1;n>f;f++)for(c=e.encrypt(c),l=0;l<c.length;l++)o[l]^=c[l];for(f=0;(i||1)>d&&f<o.length;f++)h.setInt32(d,o[f]),d+=4}return w.slice(0,s/8)},M:class{constructor(e){const t=this,n=t.N=z.k,r=[[],[]],s=n.prototype.blockSize/32;t.P=[new n,new n],e.length>s&&(e=n.hash(e));for(let t=0;s>t;t++)r[0][t]=909522486^e[t],r[1][t]=1549556828^e[t];t.P[0].update(r[0]),t.P[1].update(r[1]),t.U=new n(t.P[0])}reset(){const e=this;e.U=new e.N(e.P[0]),e.T=!1}update(e){this.T=!0,this.U.update(e)}digest(){const e=this,t=e.U.D(),n=new e.N(e.P[1]).update(t).D();return e.reset(),n}encrypt(e){if(this.T)throw new r("encrypt on already updated hmac called!");return this.update(e),this.digest(e)}}},x=void 0!==w&&"function"==typeof w.getRandomValues;function A(e){return x?w.getRandomValues(e):_.getRandomValues(e)}const D={name:"PBKDF2"},V=t.assign({hash:{name:"HMAC"}},D),R=t.assign({iterations:1e3,hash:{name:"SHA-1"}},D),B=["deriveBits"],E=[8,12,16],M=[16,24,32],K=[0,0,0,0],N=void 0!==w,P=N&&w.subtle,U=N&&void 0!==P,T=N&&U&&"function"==typeof P.importKey,W=N&&U&&"function"==typeof P.deriveBits,H=C.p,L=class{constructor(e){const t=this;t.W=[[[],[],[],[],[]],[[],[],[],[],[]]],t.W[0][0][0]||t.H();const n=t.W[0][4],s=t.W[1],i=e.length;let o,c,f,a=1;if(4!==i&&6!==i&&8!==i)throw new r("invalid aes key size");for(t.V=[c=e.slice(0),f=[]],o=i;4*i+28>o;o++){let e=c[o-1];(o%i==0||8===i&&o%i==4)&&(e=n[e>>>24]<<24^n[e>>16&255]<<16^n[e>>8&255]<<8^n[255&e],o%i==0&&(e=e<<8^e>>>24^a<<24,a=a<<1^283*(a>>7))),c[o]=c[o-i]^e}for(let e=0;o;e++,o--){const t=c[3&e?o:o-4];f[e]=4>=o||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.L(e,0)}decrypt(e){return this.L(e,1)}H(){const e=this.W[0],t=this.W[1],n=e[4],r=t[4],s=[],i=[];let o,c,f,a;for(let e=0;256>e;e++)i[(s[e]=e<<1^283*(e>>7))^e]=e;for(let l=o=0;!n[l];l^=c||1,o=i[o]||1){let i=o^o<<1^o<<2^o<<3^o<<4;i=i>>8^255&i^99,n[l]=i,r[i]=l,a=s[f=s[c=s[l]]];let u=16843009*a^65537*f^257*c^16843008*l,w=257*s[i]^16843008*i;for(let n=0;4>n;n++)e[n][l]=w=w<<24^w>>>8,t[n][i]=u=u<<24^u>>>8}for(let n=0;5>n;n++)e[n]=e[n].slice(0),t[n]=t[n].slice(0)}L(e,t){if(4!==e.length)throw new r("invalid aes block size");const n=this.V[t],s=n.length/4-2,i=[0,0,0,0],o=this.W[t],c=o[0],f=o[1],a=o[2],l=o[3],u=o[4];let w,h,d,p=e[0]^n[0],y=e[t?3:1]^n[1],m=e[2]^n[2],b=e[t?1:3]^n[3],g=4;for(let e=0;s>e;e++)w=c[p>>>24]^f[y>>16&255]^a[m>>8&255]^l[255&b]^n[g],h=c[y>>>24]^f[m>>16&255]^a[b>>8&255]^l[255&p]^n[g+1],d=c[m>>>24]^f[b>>16&255]^a[p>>8&255]^l[255&y]^n[g+2],b=c[b>>>24]^f[p>>16&255]^a[y>>8&255]^l[255&m]^n[g+3],g+=4,p=w,y=h,m=d;for(let e=0;4>e;e++)i[t?3&-e:e]=u[p>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&b]^n[g++],w=p,p=y,y=m,m=b,b=w;return i}},j=class{constructor(e,t){this.j=e,this.F=t,this.O=t}reset(){this.O=this.F}update(e){return this.q(this.j,e,this.O)}G(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}J(e){0===(e[0]=this.G(e[0]))&&(e[1]=this.G(e[1]))}q(e,t,n){let r;if(!(r=t.length))return[];const s=S.l(t);for(let s=0;r>s;s+=4){this.J(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 S.u(t,s)}},F=I.M;class O extends d{constructor(e,n,i){super({start(){t.assign(this,{ready:new l((e=>this.X=e)),password:e,signed:n,Y:i-1,pending:new s})},async transform(e,t){const n=this,{password:i,Y:o,X:c,ready:f}=n;i?(await(async(e,t,n,s)=>{const i=await J(e,t,n,X(s,0,E[t])),o=X(s,E[t]);if(i[0]!=o[0]||i[1]!=o[1])throw new r("Invalid password")})(n,o,i,X(e,0,E[o]+2)),e=X(e,E[o]+2),c()):await f;const a=new s(e.length-10-(e.length-10)%16);t.enqueue(G(n,e,a,0,10,!0))},async flush(e){const{signed:t,Z:n,$:i,pending:o,ready:c}=this;await c;const f=X(o,0,o.length-10),a=X(o,o.length-10);let l=new s;if(f.length){const e=Z(H,f);i.update(e);const t=n.update(e);l=Y(H,t)}if(t){const e=X(Y(H,i.digest()),0,10);for(let t=0;10>t;t++)if(e[t]!=a[t])throw new r("Invalid signature")}e.enqueue(l)}})}}class q extends d{constructor(e,n){let r;super({start(){t.assign(this,{ready:new l((e=>this.X=e)),password:e,Y:n-1,pending:new s})},async transform(e,t){const n=this,{password:r,Y:i,X:o,ready:c}=n;let f=new s;r?(f=await(async(e,t,n)=>{const r=A(new s(E[t]));return Q(r,await J(e,t,n,r))})(n,i,r),o()):await c;const a=new s(f.length+e.length-e.length%16);a.set(f,0),t.enqueue(G(n,e,a,f.length,0))},async flush(e){const{Z:t,$:n,pending:i,ready:o}=this;await o;let c=new s;if(i.length){const e=t.update(Z(H,i));n.update(e),c=Y(H,e)}r.signature=Y(H,n.digest()).slice(0,10),e.enqueue(Q(c,r.signature))}}),r=this}}function G(e,t,n,r,i,o){const{Z:c,$:f,pending:a}=e,l=t.length-i;let u;for(a.length&&(t=Q(a,t),n=((e,t)=>{if(t&&t>e.length){const n=e;(e=new s(t)).set(n,0)}return e})(n,l-l%16)),u=0;l-16>=u;u+=16){const e=Z(H,X(t,u,u+16));o&&f.update(e);const s=c.update(e);o||f.update(s),n.set(Y(H,s),u+r)}return e.pending=X(t,u),n}async function J(n,r,i,o){n.password=null;const c=(e=>{if(void 0===u){const t=new s((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)})(i),f=await((e,t,n,r,s)=>T?P.importKey("raw",t,n,!1,s):I.importKey(t))(0,c,V,0,B),a=await(async(e,t,n)=>W?await P.deriveBits(e,t,n):I.K(t,e.salt,R.iterations,n))(t.assign({salt:o},R),f,8*(2*M[r]+2)),l=new s(a),w=Z(H,X(l,0,M[r])),h=Z(H,X(l,M[r],2*M[r])),d=X(l,2*M[r]);return t.assign(n,{keys:{key:w,ee:h,passwordVerification:d},Z:new j(new L(w),e.from(K)),$:new F(h)}),d}function Q(e,t){let n=e;return e.length+t.length&&(n=new s(e.length+t.length),n.set(e,0),n.set(t,e.length)),n}function X(e,t,n){return e.subarray(t,n)}function Y(e,t){return e.m(t)}function Z(e,t){return e.g(t)}class $ extends d{constructor(e,n){super({start(){t.assign(this,{password:e,passwordVerification:n}),re(this,e)},transform(e,t){const n=this;if(n.password){const t=te(n,e.subarray(0,12));if(n.password=null,t[11]!=n.passwordVerification)throw new r("Invalid password");e=e.subarray(12)}t.enqueue(te(n,e))}})}}class ee extends d{constructor(e,n){super({start(){t.assign(this,{password:e,passwordVerification:n}),re(this,e)},transform(e,t){const n=this;let r,i;if(n.password){n.password=null;const t=A(new s(12));t[11]=n.passwordVerification,r=new s(e.length+t.length),r.set(ne(n,t),0),i=12}else r=new s(e.length),i=0;r.set(ne(n,e),i),t.enqueue(r)}})}}function te(e,t){const n=new s(t.length);for(let r=0;r<t.length;r++)n[r]=ie(e)^t[r],se(e,n[r]);return n}function ne(e,t){const n=new s(t.length);for(let r=0;r<t.length;r++)n[r]=ie(e)^t[r],se(e,t[r]);return n}function re(e,n){const r=[305419896,591751049,878082192];t.assign(e,{keys:r,te:new k(r[0]),ne:new k(r[2])});for(let t=0;t<n.length;t++)se(e,n.charCodeAt(t))}function se(e,t){let[r,s,i]=e.keys;e.te.append([t]),r=~e.te.get(),s=ce(n.imul(ce(s+oe(r)),134775813)+1),e.ne.append([s>>>24]),i=~e.ne.get(),e.keys=[r,s,i]}function ie(e){const t=2|e.keys[2];return oe(n.imul(t,1^t)>>>8)}function oe(e){return 255&e}function ce(e){return 4294967295&e}class fe extends d{constructor(e,{chunkSize:t,CompressionStream:n,re:r}){super({});const{compressed:s,encrypted:i,useCompressionStream:o,password:c,passwordVerification:f,encryptionStrength:l,zipCrypto:u,signed:w,level:h}=e,d=this;let p,y,m=le(super.readable);i&&!u||!w||([m,p]=m.tee(),p=he(p,new v)),s&&(m=we(m,o,{level:h,chunkSize:t},r,n)),i&&(u?m=he(m,new ee(c,f)):(y=new q(c,l),m=he(m,y))),ue(d,m,(async()=>{let e;i&&!u&&(e=y.signature),i&&!u||!w||(e=await p.getReader().read(),e=new a(e.value.buffer).getUint32(0)),d.signature=e}))}}class ae extends d{constructor(e,{chunkSize:t,DecompressionStream:n,se:s}){super({});const{zipCrypto:i,encrypted:o,password:c,passwordVerification:f,signed:l,signature:u,encryptionStrength:w,compressed:h,useCompressionStream:d}=e;let p,y,m=le(super.readable);o&&(i?m=he(m,new $(c,f)):(y=new O(c,l,w),m=he(m,y))),h&&(m=we(m,d,{chunkSize:t},s,n)),o&&!i||!l||([m,p]=m.tee(),p=he(p,new v)),ue(this,m,(async()=>{if((!o||i)&&l){const e=await p.getReader().read(),t=new a(e.value.buffer);if(u!=t.getUint32(0,!1))throw new r("Invalid signature")}}))}}function le(e){return he(e,new d({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function ue(e,n,r){n=he(n,new d({flush:r})),t.defineProperty(e,"readable",{get:()=>n})}function we(e,t,n,r,s){try{e=he(e,new(t&&r?r:s)("deflate-raw",n))}catch(r){if(!t)throw r;e=he(e,new s("deflate-raw",n))}return e}function he(e,t){return e.pipeThrough(t)}class de extends d{constructor(e,t){const n=new e(t);super({transform(e,t){t.enqueue(n.append(e))},flush(e){const t=n.flush();t&&e.enqueue(t)}})}}class pe{constructor(e,n,r,s){const{codecType:i}=r;let o;i.startsWith("deflate")?o=fe:i.startsWith("inflate")&&(o=ae),t.assign(this,{ie:o,readable:e,writable:n,options:r,config:s})}async oe(){const{ie:e,readable:t,writable:n,options:r,config:s}=this,i=new e(r,s);let o=0;await t.pipeThrough(i).pipeThrough(new d({transform(e,t){e&&e.length&&(o+=e.length,t.enqueue(e))}})).pipeTo(n,{ce:!0,fe:!0});const{signature:c}=i;return{size:o,signature:c}}}function ye(e){return class extends de{constructor(t,n){super(e,n)}}}const me=new f,be=new f;let ge,ke=0;async function ve(e){try{const{options:t,scripts:n,config:r}=e;n&&n.length&&importScripts.apply(void 0,n),self.initCodec&&self.initCodec(),r.re=self.CompressionStream,r.se=self.DecompressionStream,self.Deflate&&(r.CompressionStream=ye(self.Deflate)),self.Inflate&&(r.DecompressionStream=ye(self.Inflate));const s={highWaterMark:1,size:()=>r.chunkSize},i=e.readable||new p({async pull(e){let t=new l((e=>me.set(ke,e)));Se({type:"pull",messageId:ke}),ke=(ke+1)%Number.MAX_SAFE_INTEGER;const{value:n,done:r}=await t;e.enqueue(n),r&&e.close()}},s),o=e.writable||new y({async write(e){let t;const n=new l((e=>t=e));be.set(ke,t),Se({type:"data",data:e,messageId:ke}),ke=(ke+1)%Number.MAX_SAFE_INTEGER,await n}},s);ge=new pe(i,o,t,r);const c=await ge.oe();try{await o.close()}catch(e){}Se({type:"close",result:c})}catch(e){Ce(e)}}function Se(e){if(e.data){let{data:t}=e;if(t&&t.length)try{t=new s(t),e.data=t.buffer,h(e,[e.data])}catch(t){h(e)}else h(e)}else h(e)}function Ce(e){const{message:t,stack:n,code:r,name:s}=e;h({error:{message:t,stack:n,code:r,name:s}})}function ze(t){return _e(t.map((([t,n])=>new e(t).fill(n,0,t))))}function _e(t){return t.reduce(((t,n)=>t.concat(e.isArray(n)?_e(n):n)),[])}addEventListener("message",(async e=>{const t=e.data,{type:n,messageId:r,data:i,done:o}=t;try{if("start"==n&&ve(t),"data"==n){const e=me.get(r);me.delete(r),e({value:new s(i),done:o})}if("ack"==n){const e=be.get(r);be.delete(r),e()}}catch(e){Ce(e)}}));const Ie=[0,1,2,3].concat(...ze([[2,4],[2,5],[4,6],[4,7],[8,8],[8,9],[16,10],[16,11],[32,12],[32,13],[64,14],[64,15],[2,0],[1,16],[1,17],[2,18],[2,19],[4,20],[4,21],[8,22],[8,23],[16,24],[16,25],[32,26],[32,27],[64,28],[64,29]]));function xe(){const e=this;function t(e,t){let n=0;do{n|=1&e,e>>>=1,n<<=1}while(--t>0);return n>>>1}e.ae=r=>{const s=e.le,i=e.we.ue,o=e.we.he;let c,f,a,l=-1;for(r.de=0,r.pe=573,c=0;o>c;c++)0!==s[2*c]?(r.ye[++r.de]=l=c,r.me[c]=0):s[2*c+1]=0;for(;2>r.de;)a=r.ye[++r.de]=2>l?++l:0,s[2*a]=1,r.me[a]=0,r.be--,i&&(r.ge-=i[2*a+1]);for(e.ke=l,c=n.floor(r.de/2);c>=1;c--)r.ve(s,c);a=o;do{c=r.ye[1],r.ye[1]=r.ye[r.de--],r.ve(s,1),f=r.ye[1],r.ye[--r.pe]=c,r.ye[--r.pe]=f,s[2*a]=s[2*c]+s[2*f],r.me[a]=n.max(r.me[c],r.me[f])+1,s[2*c+1]=s[2*f+1]=a,r.ye[1]=a++,r.ve(s,1)}while(r.de>=2);r.ye[--r.pe]=r.ye[1],(t=>{const n=e.le,r=e.we.ue,s=e.we.Se,i=e.we.Ce,o=e.we.ze;let c,f,a,l,u,w,h=0;for(l=0;15>=l;l++)t._e[l]=0;for(n[2*t.ye[t.pe]+1]=0,c=t.pe+1;573>c;c++)f=t.ye[c],l=n[2*n[2*f+1]+1]+1,l>o&&(l=o,h++),n[2*f+1]=l,f>e.ke||(t._e[l]++,u=0,i>f||(u=s[f-i]),w=n[2*f],t.be+=w*(l+u),r&&(t.ge+=w*(r[2*f+1]+u)));if(0!==h){do{for(l=o-1;0===t._e[l];)l--;t._e[l]--,t._e[l+1]+=2,t._e[o]--,h-=2}while(h>0);for(l=o;0!==l;l--)for(f=t._e[l];0!==f;)a=t.ye[--c],a>e.ke||(n[2*a+1]!=l&&(t.be+=(l-n[2*a+1])*n[2*a],n[2*a+1]=l),f--)}})(r),((e,n,r)=>{const s=[];let i,o,c,f=0;for(i=1;15>=i;i++)s[i]=f=f+r[i-1]<<1;for(o=0;n>=o;o++)c=e[2*o+1],0!==c&&(e[2*o]=t(s[c]++,c))})(s,e.ke,r._e)}}function Ae(e,t,n,r,s){const i=this;i.ue=e,i.Se=t,i.Ce=n,i.he=r,i.ze=s}xe.Ie=[0,1,2,3,4,5,6,7].concat(...ze([[2,8],[2,9],[2,10],[2,11],[4,12],[4,13],[4,14],[4,15],[8,16],[8,17],[8,18],[8,19],[16,20],[16,21],[16,22],[16,23],[32,24],[32,25],[32,26],[31,27],[1,28]])),xe.xe=[0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224,0],xe.Ae=[0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576],xe.De=e=>256>e?Ie[e]:Ie[256+(e>>>7)],xe.Ve=[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],xe.Re=[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],xe.Be=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],xe.Ee=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];const De=ze([[144,8],[112,9],[24,7],[8,8]]);Ae.Me=_e([12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,19,275,147,403,83,339,211,467,51,307,179,435,115,371,243,499,11,267,139,395,75,331,203,459,43,299,171,427,107,363,235,491,27,283,155,411,91,347,219,475,59,315,187,443,123,379,251,507,7,263,135,391,71,327,199,455,39,295,167,423,103,359,231,487,23,279,151,407,87,343,215,471,55,311,183,439,119,375,247,503,15,271,143,399,79,335,207,463,47,303,175,431,111,367,239,495,31,287,159,415,95,351,223,479,63,319,191,447,127,383,255,511,0,64,32,96,16,80,48,112,8,72,40,104,24,88,56,120,4,68,36,100,20,84,52,116,3,131,67,195,35,163,99,227].map(((e,t)=>[e,De[t]])));const Ve=ze([[30,5]]);function Re(e,t,n,r,s){const i=this;i.Ke=e,i.Ne=t,i.Pe=n,i.Ue=r,i.Te=s}Ae.We=_e([0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30,1,17,9,25,5,21,13,29,3,19,11,27,7,23].map(((e,t)=>[e,Ve[t]]))),Ae.He=new Ae(Ae.Me,xe.Ve,257,286,15),Ae.Le=new Ae(Ae.We,xe.Re,0,30,15),Ae.je=new Ae(null,xe.Be,0,19,7);const Be=[new Re(0,0,0,0,0),new Re(4,4,8,4,1),new Re(4,5,16,8,1),new Re(4,6,32,32,1),new Re(4,4,16,16,2),new Re(8,16,32,32,2),new Re(8,16,128,128,2),new Re(8,32,128,256,2),new Re(32,128,258,1024,2),new Re(32,258,258,4096,2)],Ee=["need dictionary","stream end","","","stream error","data error","","buffer error","",""];function Me(e,t,n,r){const s=e[2*t],i=e[2*n];return i>s||s==i&&r[t]<=r[n]}function Ke(){const e=this;let t,r,o,c,f,a,l,u,w,h,d,p,y,m,b,g,k,v,S,C,z,_,I,x,A,D,V,R,B,E,M,K,N;const P=new xe,U=new xe,T=new xe;let W,H,L,j,F,O;function q(){let t;for(t=0;286>t;t++)M[2*t]=0;for(t=0;30>t;t++)K[2*t]=0;for(t=0;19>t;t++)N[2*t]=0;M[512]=1,e.be=e.ge=0,H=L=0}function G(e,t){let n,r=-1,s=e[1],i=0,o=7,c=4;0===s&&(o=138,c=3),e[2*(t+1)+1]=65535;for(let f=0;t>=f;f++)n=s,s=e[2*(f+1)+1],++i<o&&n==s||(c>i?N[2*n]+=i:0!==n?(n!=r&&N[2*n]++,N[32]++):i>10?N[36]++:N[34]++,i=0,r=n,0===s?(o=138,c=3):n==s?(o=6,c=3):(o=7,c=4))}function J(t){e.Fe[e.pending++]=t}function Q(e){J(255&e),J(e>>>8&255)}function X(e,t){let n;const r=t;O>16-r?(n=e,F|=n<<O&65535,Q(F),F=n>>>16-O,O+=r-16):(F|=e<<O&65535,O+=r)}function Y(e,t){const n=2*e;X(65535&t[n],65535&t[n+1])}function Z(e,t){let n,r,s=-1,i=e[1],o=0,c=7,f=4;for(0===i&&(c=138,f=3),n=0;t>=n;n++)if(r=i,i=e[2*(n+1)+1],++o>=c||r!=i){if(f>o)do{Y(r,N)}while(0!=--o);else 0!==r?(r!=s&&(Y(r,N),o--),Y(16,N),X(o-3,2)):o>10?(Y(18,N),X(o-11,7)):(Y(17,N),X(o-3,3));o=0,s=r,0===i?(c=138,f=3):r==i?(c=6,f=3):(c=7,f=4)}}function $(){16==O?(Q(F),F=0,O=0):8>O||(J(255&F),F>>>=8,O-=8)}function ee(t,r){let s,i,o;if(e.Oe[H]=t,e.qe[H]=255&r,H++,0===t?M[2*r]++:(L++,t--,M[2*(xe.Ie[r]+256+1)]++,K[2*xe.De(t)]++),0==(8191&H)&&V>2){for(s=8*H,i=z-k,o=0;30>o;o++)s+=K[2*o]*(5+xe.Re[o]);if(s>>>=3,L<n.floor(H/2)&&s<n.floor(i/2))return!0}return H==W-1}function te(t,n){let r,s,i,o,c=0;if(0!==H)do{r=e.Oe[c],s=e.qe[c],c++,0===r?Y(s,t):(i=xe.Ie[s],Y(i+256+1,t),o=xe.Ve[i],0!==o&&(s-=xe.xe[i],X(s,o)),r--,i=xe.De(r),Y(i,n),o=xe.Re[i],0!==o&&(r-=xe.Ae[i],X(r,o)))}while(H>c);Y(256,t),j=t[513]}function ne(){O>8?Q(F):O>0&&J(255&F),F=0,O=0}function re(t,n,r){X(0+(r?1:0),3),((t,n)=>{ne(),j=8,Q(n),Q(~n),e.Fe.set(u.subarray(t,t+n),e.pending),e.pending+=n})(t,n)}function se(n){((t,n,r)=>{let s,i,o=0;V>0?(P.ae(e),U.ae(e),o=(()=>{let t;for(G(M,P.ke),G(K,U.ke),T.ae(e),t=18;t>=3&&0===N[2*xe.Ee[t]+1];t--);return e.be+=14+3*(t+1),t})(),s=e.be+3+7>>>3,i=e.ge+3+7>>>3,i>s||(s=i)):s=i=n+5,n+4>s||-1==t?i==s?(X(2+(r?1:0),3),te(Ae.Me,Ae.We)):(X(4+(r?1:0),3),((e,t,n)=>{let r;for(X(e-257,5),X(t-1,5),X(n-4,4),r=0;n>r;r++)X(N[2*xe.Ee[r]+1],3);Z(M,e-1),Z(K,t-1)})(P.ke+1,U.ke+1,o+1),te(M,K)):re(t,n,r),q(),r&&ne()})(0>k?-1:k,z-k,n),k=z,t.Ge()}function ie(){let e,n,r,s;do{if(s=w-I-z,0===s&&0===z&&0===I)s=f;else if(-1==s)s--;else if(z>=f+f-262){u.set(u.subarray(f,f+f),0),_-=f,z-=f,k-=f,e=y,r=e;do{n=65535&d[--r],d[r]=f>n?0:n-f}while(0!=--e);e=f,r=e;do{n=65535&h[--r],h[r]=f>n?0:n-f}while(0!=--e);s+=f}if(0===t.Je)return;e=t.Qe(u,z+I,s),I+=e,3>I||(p=255&u[z],p=(p<<g^255&u[z+1])&b)}while(262>I&&0!==t.Je)}function oe(e){let t,n,r=A,s=z,i=x;const o=z>f-262?z-(f-262):0;let c=E;const a=l,w=z+258;let d=u[s+i-1],p=u[s+i];B>x||(r>>=2),c>I&&(c=I);do{if(t=e,u[t+i]==p&&u[t+i-1]==d&&u[t]==u[s]&&u[++t]==u[s+1]){s+=2,t++;do{}while(u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&u[++s]==u[++t]&&w>s);if(n=258-(w-s),s=w-258,n>i){if(_=e,i=n,n>=c)break;d=u[s+i-1],p=u[s+i]}}}while((e=65535&h[e&a])>o&&0!=--r);return i>I?I:i}e.me=[],e._e=[],e.ye=[],M=[],K=[],N=[],e.ve=(t,n)=>{const r=e.ye,s=r[n];let i=n<<1;for(;i<=e.de&&(i<e.de&&Me(t,r[i+1],r[i],e.me)&&i++,!Me(t,s,r[i],e.me));)r[n]=r[i],n=i,i<<=1;r[n]=s},e.Xe=(t,S,_,H,L,G)=>(H||(H=8),L||(L=8),G||(G=0),t.Ye=null,-1==S&&(S=6),1>L||L>9||8!=H||9>_||_>15||0>S||S>9||0>G||G>2?-2:(t.Ze=e,a=_,f=1<<a,l=f-1,m=L+7,y=1<<m,b=y-1,g=n.floor((m+3-1)/3),u=new s(2*f),h=[],d=[],W=1<<L+6,e.Fe=new s(4*W),o=4*W,e.Oe=new i(W),e.qe=new s(W),V=S,R=G,(t=>(t.$e=t.et=0,t.Ye=null,e.pending=0,e.tt=0,r=113,c=0,P.le=M,P.we=Ae.He,U.le=K,U.we=Ae.Le,T.le=N,T.we=Ae.je,F=0,O=0,j=8,q(),(()=>{w=2*f,d[y-1]=0;for(let e=0;y-1>e;e++)d[e]=0;D=Be[V].Ne,B=Be[V].Ke,E=Be[V].Pe,A=Be[V].Ue,z=0,k=0,I=0,v=x=2,C=0,p=0})(),0))(t))),e.nt=()=>42!=r&&113!=r&&666!=r?-2:(e.qe=null,e.Oe=null,e.Fe=null,d=null,h=null,u=null,e.Ze=null,113==r?-3:0),e.rt=(e,t,n)=>{let r=0;return-1==t&&(t=6),0>t||t>9||0>n||n>2?-2:(Be[V].Te!=Be[t].Te&&0!==e.$e&&(r=e.st(1)),V!=t&&(V=t,D=Be[V].Ne,B=Be[V].Ke,E=Be[V].Pe,A=Be[V].Ue),R=n,r)},e.it=(e,t,n)=>{let s,i=n,o=0;if(!t||42!=r)return-2;if(3>i)return 0;for(i>f-262&&(i=f-262,o=n-i),u.set(t.subarray(o,o+i),0),z=i,k=i,p=255&u[0],p=(p<<g^255&u[1])&b,s=0;i-3>=s;s++)p=(p<<g^255&u[s+2])&b,h[s&l]=d[p],d[p]=s;return 0},e.st=(n,s)=>{let i,w,m,A,B;if(s>4||0>s)return-2;if(!n.ot||!n.ct&&0!==n.Je||666==r&&4!=s)return n.Ye=Ee[4],-2;if(0===n.ft)return n.Ye=Ee[7],-5;var E;if(t=n,A=c,c=s,42==r&&(w=8+(a-8<<4)<<8,m=(V-1&255)>>1,m>3&&(m=3),w|=m<<6,0!==z&&(w|=32),w+=31-w%31,r=113,J((E=w)>>8&255),J(255&E)),0!==e.pending){if(t.Ge(),0===t.ft)return c=-1,0}else if(0===t.Je&&A>=s&&4!=s)return t.Ye=Ee[7],-5;if(666==r&&0!==t.Je)return n.Ye=Ee[7],-5;if(0!==t.Je||0!==I||0!=s&&666!=r){switch(B=-1,Be[V].Te){case 0:B=(e=>{let n,r=65535;for(r>o-5&&(r=o-5);;){if(1>=I){if(ie(),0===I&&0==e)return 0;if(0===I)break}if(z+=I,I=0,n=k+r,(0===z||z>=n)&&(I=z-n,z=n,se(!1),0===t.ft))return 0;if(z-k>=f-262&&(se(!1),0===t.ft))return 0}return se(4==e),0===t.ft?4==e?2:0:4==e?3:1})(s);break;case 1:B=(e=>{let n,r=0;for(;;){if(262>I){if(ie(),262>I&&0==e)return 0;if(0===I)break}if(3>I||(p=(p<<g^255&u[z+2])&b,r=65535&d[p],h[z&l]=d[p],d[p]=z),0===r||(z-r&65535)>f-262||2!=R&&(v=oe(r)),3>v)n=ee(0,255&u[z]),I--,z++;else if(n=ee(z-_,v-3),I-=v,v>D||3>I)z+=v,v=0,p=255&u[z],p=(p<<g^255&u[z+1])&b;else{v--;do{z++,p=(p<<g^255&u[z+2])&b,r=65535&d[p],h[z&l]=d[p],d[p]=z}while(0!=--v);z++}if(n&&(se(!1),0===t.ft))return 0}return se(4==e),0===t.ft?4==e?2:0:4==e?3:1})(s);break;case 2:B=(e=>{let n,r,s=0;for(;;){if(262>I){if(ie(),262>I&&0==e)return 0;if(0===I)break}if(3>I||(p=(p<<g^255&u[z+2])&b,s=65535&d[p],h[z&l]=d[p],d[p]=z),x=v,S=_,v=2,0!==s&&D>x&&f-262>=(z-s&65535)&&(2!=R&&(v=oe(s)),5>=v&&(1==R||3==v&&z-_>4096)&&(v=2)),3>x||v>x)if(0!==C){if(n=ee(0,255&u[z-1]),n&&se(!1),z++,I--,0===t.ft)return 0}else C=1,z++,I--;else{r=z+I-3,n=ee(z-1-S,x-3),I-=x-1,x-=2;do{++z>r||(p=(p<<g^255&u[z+2])&b,s=65535&d[p],h[z&l]=d[p],d[p]=z)}while(0!=--x);if(C=0,v=2,z++,n&&(se(!1),0===t.ft))return 0}}return 0!==C&&(n=ee(0,255&u[z-1]),C=0),se(4==e),0===t.ft?4==e?2:0:4==e?3:1})(s)}if(2!=B&&3!=B||(r=666),0==B||2==B)return 0===t.ft&&(c=-1),0;if(1==B){if(1==s)X(2,3),Y(256,Ae.Me),$(),9>1+j+10-O&&(X(2,3),Y(256,Ae.Me),$()),j=7;else if(re(0,0,!1),3==s)for(i=0;y>i;i++)d[i]=0;if(t.Ge(),0===t.ft)return c=-1,0}}return 4!=s?0:1}}function Ne(){const e=this;e.lt=0,e.ut=0,e.Je=0,e.$e=0,e.ft=0,e.et=0}function Pe(e){const t=new Ne,i=(o=e&&e.chunkSize?e.chunkSize:65536)+5*(n.floor(o/16383)+1);var o;const c=new s(i);let f=e?e.level:-1;void 0===f&&(f=-1),t.Xe(f),t.ot=c,this.append=(e,n)=>{let o,f,a=0,l=0,u=0;const w=[];if(e.length){t.lt=0,t.ct=e,t.Je=e.length;do{if(t.ut=0,t.ft=i,o=t.st(0),0!=o)throw new r("deflating: "+t.Ye);t.ut&&(t.ut==i?w.push(new s(c)):w.push(c.slice(0,t.ut))),u+=t.ut,n&&t.lt>0&&t.lt!=a&&(n(t.lt),a=t.lt)}while(t.Je>0||0===t.ft);return w.length>1?(f=new s(u),w.forEach((e=>{f.set(e,l),l+=e.length}))):f=w[0]||new s,f}},this.flush=()=>{let e,n,o=0,f=0;const a=[];do{if(t.ut=0,t.ft=i,e=t.st(4),1!=e&&0!=e)throw new r("deflating: "+t.Ye);i-t.ft>0&&a.push(c.slice(0,t.ut)),f+=t.ut}while(t.Je>0||0===t.ft);return t.nt(),n=new s(f),a.forEach((e=>{n.set(e,o),o+=e.length})),n}}Ne.prototype={Xe(e,t){const n=this;return n.Ze=new Ke,t||(t=15),n.Ze.Xe(n,e,t)},st(e){const t=this;return t.Ze?t.Ze.st(t,e):-2},nt(){const e=this;if(!e.Ze)return-2;const t=e.Ze.nt();return e.Ze=null,t},rt(e,t){const n=this;return n.Ze?n.Ze.rt(n,e,t):-2},it(e,t){const n=this;return n.Ze?n.Ze.it(n,e,t):-2},Qe(e,t,n){const r=this;let s=r.Je;return s>n&&(s=n),0===s?0:(r.Je-=s,e.set(r.ct.subarray(r.lt,r.lt+s),t),r.lt+=s,r.$e+=s,s)},Ge(){const e=this;let t=e.Ze.pending;t>e.ft&&(t=e.ft),0!==t&&(e.ot.set(e.Ze.Fe.subarray(e.Ze.tt,e.Ze.tt+t),e.ut),e.ut+=t,e.Ze.tt+=t,e.et+=t,e.ft-=t,e.Ze.pending-=t,0===e.Ze.pending&&(e.Ze.tt=0))}};const Ue=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Te=[96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,192,80,7,10,0,8,96,0,8,32,0,9,160,0,8,0,0,8,128,0,8,64,0,9,224,80,7,6,0,8,88,0,8,24,0,9,144,83,7,59,0,8,120,0,8,56,0,9,208,81,7,17,0,8,104,0,8,40,0,9,176,0,8,8,0,8,136,0,8,72,0,9,240,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,200,81,7,13,0,8,100,0,8,36,0,9,168,0,8,4,0,8,132,0,8,68,0,9,232,80,7,8,0,8,92,0,8,28,0,9,152,84,7,83,0,8,124,0,8,60,0,9,216,82,7,23,0,8,108,0,8,44,0,9,184,0,8,12,0,8,140,0,8,76,0,9,248,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,196,81,7,11,0,8,98,0,8,34,0,9,164,0,8,2,0,8,130,0,8,66,0,9,228,80,7,7,0,8,90,0,8,26,0,9,148,84,7,67,0,8,122,0,8,58,0,9,212,82,7,19,0,8,106,0,8,42,0,9,180,0,8,10,0,8,138,0,8,74,0,9,244,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,204,81,7,15,0,8,102,0,8,38,0,9,172,0,8,6,0,8,134,0,8,70,0,9,236,80,7,9,0,8,94,0,8,30,0,9,156,84,7,99,0,8,126,0,8,62,0,9,220,82,7,27,0,8,110,0,8,46,0,9,188,0,8,14,0,8,142,0,8,78,0,9,252,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,194,80,7,10,0,8,97,0,8,33,0,9,162,0,8,1,0,8,129,0,8,65,0,9,226,80,7,6,0,8,89,0,8,25,0,9,146,83,7,59,0,8,121,0,8,57,0,9,210,81,7,17,0,8,105,0,8,41,0,9,178,0,8,9,0,8,137,0,8,73,0,9,242,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,202,81,7,13,0,8,101,0,8,37,0,9,170,0,8,5,0,8,133,0,8,69,0,9,234,80,7,8,0,8,93,0,8,29,0,9,154,84,7,83,0,8,125,0,8,61,0,9,218,82,7,23,0,8,109,0,8,45,0,9,186,0,8,13,0,8,141,0,8,77,0,9,250,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,198,81,7,11,0,8,99,0,8,35,0,9,166,0,8,3,0,8,131,0,8,67,0,9,230,80,7,7,0,8,91,0,8,27,0,9,150,84,7,67,0,8,123,0,8,59,0,9,214,82,7,19,0,8,107,0,8,43,0,9,182,0,8,11,0,8,139,0,8,75,0,9,246,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,206,81,7,15,0,8,103,0,8,39,0,9,174,0,8,7,0,8,135,0,8,71,0,9,238,80,7,9,0,8,95,0,8,31,0,9,158,84,7,99,0,8,127,0,8,63,0,9,222,82,7,27,0,8,111,0,8,47,0,9,190,0,8,15,0,8,143,0,8,79,0,9,254,96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,193,80,7,10,0,8,96,0,8,32,0,9,161,0,8,0,0,8,128,0,8,64,0,9,225,80,7,6,0,8,88,0,8,24,0,9,145,83,7,59,0,8,120,0,8,56,0,9,209,81,7,17,0,8,104,0,8,40,0,9,177,0,8,8,0,8,136,0,8,72,0,9,241,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,201,81,7,13,0,8,100,0,8,36,0,9,169,0,8,4,0,8,132,0,8,68,0,9,233,80,7,8,0,8,92,0,8,28,0,9,153,84,7,83,0,8,124,0,8,60,0,9,217,82,7,23,0,8,108,0,8,44,0,9,185,0,8,12,0,8,140,0,8,76,0,9,249,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,197,81,7,11,0,8,98,0,8,34,0,9,165,0,8,2,0,8,130,0,8,66,0,9,229,80,7,7,0,8,90,0,8,26,0,9,149,84,7,67,0,8,122,0,8,58,0,9,213,82,7,19,0,8,106,0,8,42,0,9,181,0,8,10,0,8,138,0,8,74,0,9,245,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,205,81,7,15,0,8,102,0,8,38,0,9,173,0,8,6,0,8,134,0,8,70,0,9,237,80,7,9,0,8,94,0,8,30,0,9,157,84,7,99,0,8,126,0,8,62,0,9,221,82,7,27,0,8,110,0,8,46,0,9,189,0,8,14,0,8,142,0,8,78,0,9,253,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,195,80,7,10,0,8,97,0,8,33,0,9,163,0,8,1,0,8,129,0,8,65,0,9,227,80,7,6,0,8,89,0,8,25,0,9,147,83,7,59,0,8,121,0,8,57,0,9,211,81,7,17,0,8,105,0,8,41,0,9,179,0,8,9,0,8,137,0,8,73,0,9,243,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,203,81,7,13,0,8,101,0,8,37,0,9,171,0,8,5,0,8,133,0,8,69,0,9,235,80,7,8,0,8,93,0,8,29,0,9,155,84,7,83,0,8,125,0,8,61,0,9,219,82,7,23,0,8,109,0,8,45,0,9,187,0,8,13,0,8,141,0,8,77,0,9,251,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,199,81,7,11,0,8,99,0,8,35,0,9,167,0,8,3,0,8,131,0,8,67,0,9,231,80,7,7,0,8,91,0,8,27,0,9,151,84,7,67,0,8,123,0,8,59,0,9,215,82,7,19,0,8,107,0,8,43,0,9,183,0,8,11,0,8,139,0,8,75,0,9,247,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,207,81,7,15,0,8,103,0,8,39,0,9,175,0,8,7,0,8,135,0,8,71,0,9,239,80,7,9,0,8,95,0,8,31,0,9,159,84,7,99,0,8,127,0,8,63,0,9,223,82,7,27,0,8,111,0,8,47,0,9,191,0,8,15,0,8,143,0,8,79,0,9,255],We=[80,5,1,87,5,257,83,5,17,91,5,4097,81,5,5,89,5,1025,85,5,65,93,5,16385,80,5,3,88,5,513,84,5,33,92,5,8193,82,5,9,90,5,2049,86,5,129,192,5,24577,80,5,2,87,5,385,83,5,25,91,5,6145,81,5,7,89,5,1537,85,5,97,93,5,24577,80,5,4,88,5,769,84,5,49,92,5,12289,82,5,13,90,5,3073,86,5,193,192,5,24577],He=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],Le=[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,112,112],je=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],Fe=[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];function Oe(){let e,t,n,r,s,i;function o(e,t,o,c,f,a,l,u,w,h,d){let p,y,m,b,g,k,v,S,C,z,_,I,x,A,D;z=0,g=o;do{n[e[t+z]]++,z++,g--}while(0!==g);if(n[0]==o)return l[0]=-1,u[0]=0,0;for(S=u[0],k=1;15>=k&&0===n[k];k++);for(v=k,k>S&&(S=k),g=15;0!==g&&0===n[g];g--);for(m=g,S>g&&(S=g),u[0]=S,A=1<<k;g>k;k++,A<<=1)if(0>(A-=n[k]))return-3;if(0>(A-=n[g]))return-3;for(n[g]+=A,i[1]=k=0,z=1,x=2;0!=--g;)i[x]=k+=n[z],x++,z++;g=0,z=0;do{0!==(k=e[t+z])&&(d[i[k]++]=g),z++}while(++g<o);for(o=i[m],i[0]=g=0,z=0,b=-1,I=-S,s[0]=0,_=0,D=0;m>=v;v++)for(p=n[v];0!=p--;){for(;v>I+S;){if(b++,I+=S,D=m-I,D=D>S?S:D,(y=1<<(k=v-I))>p+1&&(y-=p+1,x=v,D>k))for(;++k<D&&(y<<=1)>n[++x];)y-=n[x];if(D=1<<k,h[0]+D>1440)return-3;s[b]=_=h[0],h[0]+=D,0!==b?(i[b]=g,r[0]=k,r[1]=S,k=g>>>I-S,r[2]=_-s[b-1]-k,w.set(r,3*(s[b-1]+k))):l[0]=_}for(r[1]=v-I,o>z?d[z]<c?(r[0]=256>d[z]?0:96,r[2]=d[z++]):(r[0]=a[d[z]-c]+16+64,r[2]=f[d[z++]-c]):r[0]=192,y=1<<v-I,k=g>>>I;D>k;k+=y)w.set(r,3*(_+k));for(k=1<<v-1;0!=(g&k);k>>>=1)g^=k;for(g^=k,C=(1<<I)-1;(g&C)!=i[b];)b--,I-=S,C=(1<<I)-1}return 0!==A&&1!=m?-5:0}function f(o){let f;for(e||(e=[],t=[],n=new c(16),r=[],s=new c(15),i=new c(16)),t.length<o&&(t=[]),f=0;o>f;f++)t[f]=0;for(f=0;16>f;f++)n[f]=0;for(f=0;3>f;f++)r[f]=0;s.set(n.subarray(0,15),0),i.set(n.subarray(0,16),0)}this.wt=(n,r,s,i,c)=>{let a;return f(19),e[0]=0,a=o(n,0,19,19,null,null,s,r,i,e,t),-3==a?c.Ye="oversubscribed dynamic bit lengths tree":-5!=a&&0!==r[0]||(c.Ye="incomplete dynamic bit lengths tree",a=-3),a},this.ht=(n,r,s,i,c,a,l,u,w)=>{let h;return f(288),e[0]=0,h=o(s,0,n,257,He,Le,a,i,u,e,t),0!=h||0===i[0]?(-3==h?w.Ye="oversubscribed literal/length tree":-4!=h&&(w.Ye="incomplete literal/length tree",h=-3),h):(f(288),h=o(s,n,r,0,je,Fe,l,c,u,e,t),0!=h||0===c[0]&&n>257?(-3==h?w.Ye="oversubscribed distance tree":-5==h?(w.Ye="incomplete distance tree",h=-3):-4!=h&&(w.Ye="empty distance tree with lengths",h=-3),h):0)}}function qe(){const e=this;let t,n,r,s,i=0,o=0,c=0,f=0,a=0,l=0,u=0,w=0,h=0,d=0;function p(e,t,n,r,s,i,o,c){let f,a,l,u,w,h,d,p,y,m,b,g,k,v,S,C;d=c.lt,p=c.Je,w=o.dt,h=o.yt,y=o.write,m=y<o.read?o.read-y-1:o.end-y,b=Ue[e],g=Ue[t];do{for(;20>h;)p--,w|=(255&c.bt(d++))<<h,h+=8;if(f=w&b,a=n,l=r,C=3*(l+f),0!==(u=a[C]))for(;;){if(w>>=a[C+1],h-=a[C+1],0!=(16&u)){for(u&=15,k=a[C+2]+(w&Ue[u]),w>>=u,h-=u;15>h;)p--,w|=(255&c.bt(d++))<<h,h+=8;for(f=w&g,a=s,l=i,C=3*(l+f),u=a[C];;){if(w>>=a[C+1],h-=a[C+1],0!=(16&u)){for(u&=15;u>h;)p--,w|=(255&c.bt(d++))<<h,h+=8;if(v=a[C+2]+(w&Ue[u]),w>>=u,h-=u,m-=k,v>y){S=y-v;do{S+=o.end}while(0>S);if(u=o.end-S,k>u){if(k-=u,y-S>0&&u>y-S)do{o.gt[y++]=o.gt[S++]}while(0!=--u);else o.gt.set(o.gt.subarray(S,S+u),y),y+=u,S+=u,u=0;S=0}}else S=y-v,y-S>0&&2>y-S?(o.gt[y++]=o.gt[S++],o.gt[y++]=o.gt[S++],k-=2):(o.gt.set(o.gt.subarray(S,S+2),y),y+=2,S+=2,k-=2);if(y-S>0&&k>y-S)do{o.gt[y++]=o.gt[S++]}while(0!=--k);else o.gt.set(o.gt.subarray(S,S+k),y),y+=k,S+=k,k=0;break}if(0!=(64&u))return c.Ye="invalid distance code",k=c.Je-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.dt=w,o.yt=h,c.Je=p,c.$e+=d-c.lt,c.lt=d,o.write=y,-3;f+=a[C+2],f+=w&Ue[u],C=3*(l+f),u=a[C]}break}if(0!=(64&u))return 0!=(32&u)?(k=c.Je-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.dt=w,o.yt=h,c.Je=p,c.$e+=d-c.lt,c.lt=d,o.write=y,1):(c.Ye="invalid literal/length code",k=c.Je-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.dt=w,o.yt=h,c.Je=p,c.$e+=d-c.lt,c.lt=d,o.write=y,-3);if(f+=a[C+2],f+=w&Ue[u],C=3*(l+f),0===(u=a[C])){w>>=a[C+1],h-=a[C+1],o.gt[y++]=a[C+2],m--;break}}else w>>=a[C+1],h-=a[C+1],o.gt[y++]=a[C+2],m--}while(m>=258&&p>=10);return k=c.Je-p,k=k>h>>3?h>>3:k,p+=k,d-=k,h-=k<<3,o.dt=w,o.yt=h,c.Je=p,c.$e+=d-c.lt,c.lt=d,o.write=y,0}e.init=(e,i,o,c,f,a)=>{t=0,u=e,w=i,r=o,h=c,s=f,d=a,n=null},e.kt=(e,y,m)=>{let b,g,k,v,S,C,z,_=0,I=0,x=0;for(x=y.lt,v=y.Je,_=e.dt,I=e.yt,S=e.write,C=S<e.read?e.read-S-1:e.end-S;;)switch(t){case 0:if(C>=258&&v>=10&&(e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,m=p(u,w,r,h,s,d,e,y),x=y.lt,v=y.Je,_=e.dt,I=e.yt,S=e.write,C=S<e.read?e.read-S-1:e.end-S,0!=m)){t=1==m?7:9;break}c=u,n=r,o=h,t=1;case 1:for(b=c;b>I;){if(0===v)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,v--,_|=(255&y.bt(x++))<<I,I+=8}if(g=3*(o+(_&Ue[b])),_>>>=n[g+1],I-=n[g+1],k=n[g],0===k){f=n[g+2],t=6;break}if(0!=(16&k)){a=15&k,i=n[g+2],t=2;break}if(0==(64&k)){c=k,o=g/3+n[g+2];break}if(0!=(32&k)){t=7;break}return t=9,y.Ye="invalid literal/length code",m=-3,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);case 2:for(b=a;b>I;){if(0===v)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,v--,_|=(255&y.bt(x++))<<I,I+=8}i+=_&Ue[b],_>>=b,I-=b,c=w,n=s,o=d,t=3;case 3:for(b=c;b>I;){if(0===v)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,v--,_|=(255&y.bt(x++))<<I,I+=8}if(g=3*(o+(_&Ue[b])),_>>=n[g+1],I-=n[g+1],k=n[g],0!=(16&k)){a=15&k,l=n[g+2],t=4;break}if(0==(64&k)){c=k,o=g/3+n[g+2];break}return t=9,y.Ye="invalid distance code",m=-3,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);case 4:for(b=a;b>I;){if(0===v)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,v--,_|=(255&y.bt(x++))<<I,I+=8}l+=_&Ue[b],_>>=b,I-=b,t=5;case 5:for(z=S-l;0>z;)z+=e.end;for(;0!==i;){if(0===C&&(S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C&&(e.write=S,m=e.vt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C)))return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);e.gt[S++]=e.gt[z++],C--,z==e.end&&(z=0),i--}t=0;break;case 6:if(0===C&&(S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C&&(e.write=S,m=e.vt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,S==e.end&&0!==e.read&&(S=0,C=S<e.read?e.read-S-1:e.end-S),0===C)))return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);m=0,e.gt[S++]=f,C--,t=0;break;case 7:if(I>7&&(I-=8,v++,x--),e.write=S,m=e.vt(y,m),S=e.write,C=S<e.read?e.read-S-1:e.end-S,e.read!=e.write)return e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);t=8;case 8:return m=1,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);case 9:return m=-3,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m);default:return m=-2,e.dt=_,e.yt=I,y.Je=v,y.$e+=x-y.lt,y.lt=x,e.write=S,e.vt(y,m)}},e.St=()=>{}}Oe.Ct=(e,t,n,r)=>(e[0]=9,t[0]=5,n[0]=Te,r[0]=We,0);const Ge=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function Je(e,t){const n=this;let r,i=0,o=0,f=0,a=0;const l=[0],u=[0],w=new qe;let h=0,d=new c(4320);const p=new Oe;n.yt=0,n.dt=0,n.gt=new s(t),n.end=t,n.read=0,n.write=0,n.reset=(e,t)=>{t&&(t[0]=0),6==i&&w.St(e),i=0,n.yt=0,n.dt=0,n.read=n.write=0},n.reset(e,null),n.vt=(e,t)=>{let r,s,i;return s=e.ut,i=n.read,r=(i>n.write?n.end:n.write)-i,r>e.ft&&(r=e.ft),0!==r&&-5==t&&(t=0),e.ft-=r,e.et+=r,e.ot.set(n.gt.subarray(i,i+r),s),s+=r,i+=r,i==n.end&&(i=0,n.write==n.end&&(n.write=0),r=n.write-i,r>e.ft&&(r=e.ft),0!==r&&-5==t&&(t=0),e.ft-=r,e.et+=r,e.ot.set(n.gt.subarray(i,i+r),s),s+=r,i+=r),e.ut=s,n.read=i,t},n.kt=(e,t)=>{let s,c,y,m,b,g,k,v;for(m=e.lt,b=e.Je,c=n.dt,y=n.yt,g=n.write,k=g<n.read?n.read-g-1:n.end-g;;){let S,C,z,_,I,x,A,D;switch(i){case 0:for(;3>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}switch(s=7&c,h=1&s,s>>>1){case 0:c>>>=3,y-=3,s=7&y,c>>>=s,y-=s,i=1;break;case 1:S=[],C=[],z=[[]],_=[[]],Oe.Ct(S,C,z,_),w.init(S[0],C[0],z[0],0,_[0],0),c>>>=3,y-=3,i=6;break;case 2:c>>>=3,y-=3,i=3;break;case 3:return c>>>=3,y-=3,i=9,e.Ye="invalid block type",t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t)}break;case 1:for(;32>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}if((~c>>>16&65535)!=(65535&c))return i=9,e.Ye="invalid stored block lengths",t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);o=65535&c,c=y=0,i=0!==o?2:0!==h?7:0;break;case 2:if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);if(0===k&&(g==n.end&&0!==n.read&&(g=0,k=g<n.read?n.read-g-1:n.end-g),0===k&&(n.write=g,t=n.vt(e,t),g=n.write,k=g<n.read?n.read-g-1:n.end-g,g==n.end&&0!==n.read&&(g=0,k=g<n.read?n.read-g-1:n.end-g),0===k)))return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);if(t=0,s=o,s>b&&(s=b),s>k&&(s=k),n.gt.set(e.Qe(m,s),g),m+=s,b-=s,g+=s,k-=s,0!=(o-=s))break;i=0!==h?7:0;break;case 3:for(;14>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}if(f=s=16383&c,(31&s)>29||(s>>5&31)>29)return i=9,e.Ye="too many length or distance symbols",t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);if(s=258+(31&s)+(s>>5&31),!r||r.length<s)r=[];else for(v=0;s>v;v++)r[v]=0;c>>>=14,y-=14,a=0,i=4;case 4:for(;4+(f>>>10)>a;){for(;3>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}r[Ge[a++]]=7&c,c>>>=3,y-=3}for(;19>a;)r[Ge[a++]]=0;if(l[0]=7,s=p.wt(r,l,u,d,e),0!=s)return-3==(t=s)&&(r=null,i=9),n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);a=0,i=5;case 5:for(;s=f,258+(31&s)+(s>>5&31)>a;){let o,w;for(s=l[0];s>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}if(s=d[3*(u[0]+(c&Ue[s]))+1],w=d[3*(u[0]+(c&Ue[s]))+2],16>w)c>>>=s,y-=s,r[a++]=w;else{for(v=18==w?7:w-14,o=18==w?11:3;s+v>y;){if(0===b)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);t=0,b--,c|=(255&e.bt(m++))<<y,y+=8}if(c>>>=s,y-=s,o+=c&Ue[v],c>>>=v,y-=v,v=a,s=f,v+o>258+(31&s)+(s>>5&31)||16==w&&1>v)return r=null,i=9,e.Ye="invalid bit length repeat",t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);w=16==w?r[v-1]:0;do{r[v++]=w}while(0!=--o);a=v}}if(u[0]=-1,I=[],x=[],A=[],D=[],I[0]=9,x[0]=6,s=f,s=p.ht(257+(31&s),1+(s>>5&31),r,I,x,A,D,d,e),0!=s)return-3==s&&(r=null,i=9),t=s,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);w.init(I[0],x[0],d,A[0],d,D[0]),i=6;case 6:if(n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,1!=(t=w.kt(n,e,t)))return n.vt(e,t);if(t=0,w.St(e),m=e.lt,b=e.Je,c=n.dt,y=n.yt,g=n.write,k=g<n.read?n.read-g-1:n.end-g,0===h){i=0;break}i=7;case 7:if(n.write=g,t=n.vt(e,t),g=n.write,k=g<n.read?n.read-g-1:n.end-g,n.read!=n.write)return n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);i=8;case 8:return t=1,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);case 9:return t=-3,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t);default:return t=-2,n.dt=c,n.yt=y,e.Je=b,e.$e+=m-e.lt,e.lt=m,n.write=g,n.vt(e,t)}}},n.St=e=>{n.reset(e,null),n.gt=null,d=null},n.zt=(e,t,r)=>{n.gt.set(e.subarray(t,t+r),0),n.read=n.write=r},n._t=()=>1==i?1:0}const Qe=[0,0,255,255];function Xe(){const e=this;function t(e){return e&&e.It?(e.$e=e.et=0,e.Ye=null,e.It.mode=7,e.It.xt.reset(e,null),0):-2}e.mode=0,e.method=0,e.At=[0],e.Dt=0,e.marker=0,e.Vt=0,e.Rt=t=>(e.xt&&e.xt.St(t),e.xt=null,0),e.Bt=(n,r)=>(n.Ye=null,e.xt=null,8>r||r>15?(e.Rt(n),-2):(e.Vt=r,n.It.xt=new Je(n,1<<r),t(n),0)),e.Et=(e,t)=>{let n,r;if(!e||!e.It||!e.ct)return-2;const s=e.It;for(t=4==t?-5:0,n=-5;;)switch(s.mode){case 0:if(0===e.Je)return n;if(n=t,e.Je--,e.$e++,8!=(15&(s.method=e.bt(e.lt++)))){s.mode=13,e.Ye="unknown compression method",s.marker=5;break}if(8+(s.method>>4)>s.Vt){s.mode=13,e.Ye="invalid win size",s.marker=5;break}s.mode=1;case 1:if(0===e.Je)return n;if(n=t,e.Je--,e.$e++,r=255&e.bt(e.lt++),((s.method<<8)+r)%31!=0){s.mode=13,e.Ye="incorrect header check",s.marker=5;break}if(0==(32&r)){s.mode=7;break}s.mode=2;case 2:if(0===e.Je)return n;n=t,e.Je--,e.$e++,s.Dt=(255&e.bt(e.lt++))<<24&4278190080,s.mode=3;case 3:if(0===e.Je)return n;n=t,e.Je--,e.$e++,s.Dt+=(255&e.bt(e.lt++))<<16&16711680,s.mode=4;case 4:if(0===e.Je)return n;n=t,e.Je--,e.$e++,s.Dt+=(255&e.bt(e.lt++))<<8&65280,s.mode=5;case 5:return 0===e.Je?n:(n=t,e.Je--,e.$e++,s.Dt+=255&e.bt(e.lt++),s.mode=6,2);case 6:return s.mode=13,e.Ye="need dictionary",s.marker=0,-2;case 7:if(n=s.xt.kt(e,n),-3==n){s.mode=13,s.marker=0;break}if(0==n&&(n=t),1!=n)return n;n=t,s.xt.reset(e,s.At),s.mode=12;case 12:return e.Je=0,1;case 13:return-3;default:return-2}},e.Mt=(e,t,n)=>{let r=0,s=n;if(!e||!e.It||6!=e.It.mode)return-2;const i=e.It;return s<1<<i.Vt||(s=(1<<i.Vt)-1,r=n-s),i.xt.zt(t,r,s),i.mode=7,0},e.Kt=e=>{let n,r,s,i,o;if(!e||!e.It)return-2;const c=e.It;if(13!=c.mode&&(c.mode=13,c.marker=0),0===(n=e.Je))return-5;for(r=e.lt,s=c.marker;0!==n&&4>s;)e.bt(r)==Qe[s]?s++:s=0!==e.bt(r)?0:4-s,r++,n--;return e.$e+=r-e.lt,e.lt=r,e.Je=n,c.marker=s,4!=s?-3:(i=e.$e,o=e.et,t(e),e.$e=i,e.et=o,c.mode=7,0)},e.Nt=e=>e&&e.It&&e.It.xt?e.It.xt._t():-2}function Ye(){}function Ze(e){const t=new Ye,i=e&&e.chunkSize?n.floor(2*e.chunkSize):131072,o=new s(i);let c=!1;t.Bt(),t.ot=o,this.append=(e,n)=>{const f=[];let a,l,u=0,w=0,h=0;if(0!==e.length){t.lt=0,t.ct=e,t.Je=e.length;do{if(t.ut=0,t.ft=i,0!==t.Je||c||(t.lt=0,c=!0),a=t.Et(0),c&&-5===a){if(0!==t.Je)throw new r("inflating: bad input")}else if(0!==a&&1!==a)throw new r("inflating: "+t.Ye);if((c||1===a)&&t.Je===e.length)throw new r("inflating: bad input");t.ut&&(t.ut===i?f.push(new s(o)):f.push(o.slice(0,t.ut))),h+=t.ut,n&&t.lt>0&&t.lt!=u&&(n(t.lt),u=t.lt)}while(t.Je>0||0===t.ft);return f.length>1?(l=new s(h),f.forEach((e=>{l.set(e,w),w+=e.length}))):l=f[0]||new s,l}},this.flush=()=>{t.Rt()}}Ye.prototype={Bt(e){const t=this;return t.It=new Xe,e||(e=15),t.It.Bt(t,e)},Et(e){const t=this;return t.It?t.It.Et(t,e):-2},Rt(){const e=this;if(!e.It)return-2;const t=e.It.Rt(e);return e.It=null,t},Kt(){const e=this;return e.It?e.It.Kt(e):-2},Mt(e,t){const n=this;return n.It?n.It.Mt(n,e,t):-2},bt(e){return this.ct[e]},Qe(e,t){return this.ct.subarray(e,e+t)}},self.initCodec=()=>{self.Deflate=Pe,self.Inflate=Ze};\n'],{type:"text/javascript"}));e({workerScripts:{inflate:[t],deflate:[t]}});}
|
|
1897
|
+
function pipeThrough(readable, transformStream) {
|
|
1898
|
+
return readable.pipeThrough(transformStream);
|
|
1899
|
+
}
|
|
1912
1900
|
|
|
1913
1901
|
/*
|
|
1914
1902
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -1938,56 +1926,50 @@
|
|
|
1938
1926
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1939
1927
|
*/
|
|
1940
1928
|
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
};
|
|
1950
|
-
}
|
|
1929
|
+
const MESSAGE_EVENT_TYPE = "message";
|
|
1930
|
+
const MESSAGE_START = "start";
|
|
1931
|
+
const MESSAGE_PULL = "pull";
|
|
1932
|
+
const MESSAGE_DATA = "data";
|
|
1933
|
+
const MESSAGE_ACK_DATA = "ack";
|
|
1934
|
+
const MESSAGE_CLOSE = "close";
|
|
1935
|
+
const CODEC_DEFLATE = "deflate";
|
|
1936
|
+
const CODEC_INFLATE = "inflate";
|
|
1951
1937
|
|
|
1952
|
-
|
|
1953
|
-
return class {
|
|
1938
|
+
class CodecStream extends TransformStream {
|
|
1954
1939
|
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1940
|
+
constructor(options, config) {
|
|
1941
|
+
super({});
|
|
1942
|
+
const codec = this;
|
|
1943
|
+
const { codecType } = options;
|
|
1944
|
+
let Stream;
|
|
1945
|
+
if (codecType.startsWith(CODEC_DEFLATE)) {
|
|
1946
|
+
Stream = DeflateStream;
|
|
1947
|
+
} else if (codecType.startsWith(CODEC_INFLATE)) {
|
|
1948
|
+
Stream = InflateStream;
|
|
1949
|
+
}
|
|
1950
|
+
let size = 0;
|
|
1951
|
+
const stream = new Stream(options, config);
|
|
1952
|
+
const readable = super.readable;
|
|
1953
|
+
const transformStream = new TransformStream({
|
|
1954
|
+
transform(chunk, controller) {
|
|
1955
|
+
if (chunk && chunk.length) {
|
|
1956
|
+
size += chunk.length;
|
|
1957
|
+
controller.enqueue(chunk);
|
|
1965
1958
|
}
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
|
|
1959
|
+
},
|
|
1960
|
+
flush() {
|
|
1961
|
+
const { signature } = stream;
|
|
1962
|
+
Object.assign(codec, {
|
|
1963
|
+
signature,
|
|
1964
|
+
size
|
|
1965
|
+
});
|
|
1969
1966
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
}
|
|
1977
|
-
flush() {
|
|
1978
|
-
this.codec.push(new Uint8Array(), true);
|
|
1979
|
-
return getResponse(this);
|
|
1980
|
-
}
|
|
1981
|
-
};
|
|
1982
|
-
|
|
1983
|
-
function getResponse(codec) {
|
|
1984
|
-
if (codec.pendingData) {
|
|
1985
|
-
const output = codec.pendingData;
|
|
1986
|
-
codec.pendingData = null;
|
|
1987
|
-
return output;
|
|
1988
|
-
} else {
|
|
1989
|
-
return new Uint8Array();
|
|
1990
|
-
}
|
|
1967
|
+
});
|
|
1968
|
+
Object.defineProperty(codec, "readable", {
|
|
1969
|
+
get() {
|
|
1970
|
+
return readable.pipeThrough(stream).pipeThrough(transformStream);
|
|
1971
|
+
}
|
|
1972
|
+
});
|
|
1991
1973
|
}
|
|
1992
1974
|
}
|
|
1993
1975
|
|
|
@@ -2019,25 +2001,26 @@
|
|
|
2019
2001
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2020
2002
|
*/
|
|
2021
2003
|
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
let transferStreamsSupported = true;
|
|
2004
|
+
// deno-lint-ignore valid-typeof
|
|
2005
|
+
const WEB_WORKERS_SUPPORTED = typeof Worker != UNDEFINED_TYPE$1;
|
|
2025
2006
|
|
|
2026
2007
|
class CodecWorker {
|
|
2027
2008
|
|
|
2028
2009
|
constructor(workerData, stream, workerOptions, onTaskFinished) {
|
|
2029
2010
|
const { readable, writable } = stream;
|
|
2030
2011
|
const { options, config, streamOptions, useWebWorkers, transferStreams, scripts } = workerOptions;
|
|
2012
|
+
const { signal } = streamOptions;
|
|
2031
2013
|
Object.assign(workerData, {
|
|
2032
2014
|
busy: true,
|
|
2033
|
-
readable,
|
|
2015
|
+
readable: readable.pipeThrough(new ReadableStreamHooks(readable, streamOptions, config), { signal }),
|
|
2034
2016
|
writable,
|
|
2035
2017
|
options: Object.assign({}, options),
|
|
2036
2018
|
scripts,
|
|
2037
2019
|
transferStreams,
|
|
2038
2020
|
terminate() {
|
|
2039
|
-
|
|
2040
|
-
|
|
2021
|
+
const { worker, busy } = workerData;
|
|
2022
|
+
if (worker && !busy) {
|
|
2023
|
+
worker.terminate();
|
|
2041
2024
|
workerData.interface = null;
|
|
2042
2025
|
}
|
|
2043
2026
|
},
|
|
@@ -2046,30 +2029,34 @@
|
|
|
2046
2029
|
onTaskFinished(workerData);
|
|
2047
2030
|
}
|
|
2048
2031
|
});
|
|
2049
|
-
|
|
2032
|
+
return (useWebWorkers && WEB_WORKERS_SUPPORTED ? createWebWorkerInterface : createWorkerInterface)(workerData, config);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
class ReadableStreamHooks extends TransformStream {
|
|
2037
|
+
|
|
2038
|
+
constructor(readableSource, { onstart, onprogress, size, onend }, { chunkSize }) {
|
|
2050
2039
|
let chunkOffset = 0;
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2040
|
+
super({
|
|
2041
|
+
start() {
|
|
2042
|
+
if (onstart) {
|
|
2043
|
+
callHandler(onstart, size);
|
|
2044
|
+
}
|
|
2045
|
+
},
|
|
2046
|
+
async transform(chunk, controller) {
|
|
2047
|
+
chunkOffset += chunk.length;
|
|
2048
|
+
if (onprogress) {
|
|
2049
|
+
await callHandler(onprogress, chunkOffset, size);
|
|
2050
|
+
}
|
|
2051
|
+
controller.enqueue(chunk);
|
|
2052
|
+
},
|
|
2053
|
+
flush() {
|
|
2054
|
+
readableSource.size = chunkOffset;
|
|
2055
|
+
if (onend) {
|
|
2056
|
+
callHandler(onend, chunkOffset);
|
|
2057
|
+
}
|
|
2066
2058
|
}
|
|
2067
|
-
};
|
|
2068
|
-
workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
|
|
2069
|
-
if (workersSupported === UNDEFINED_VALUE) {
|
|
2070
|
-
workersSupported = typeof Worker != UNDEFINED_TYPE;
|
|
2071
|
-
}
|
|
2072
|
-
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
2059
|
+
}, { highWaterMark: 1, size: () => chunkSize });
|
|
2073
2060
|
}
|
|
2074
2061
|
}
|
|
2075
2062
|
|
|
@@ -2082,186 +2069,209 @@
|
|
|
2082
2069
|
}
|
|
2083
2070
|
|
|
2084
2071
|
function createWorkerInterface(workerData, config) {
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
const codec = {
|
|
2088
|
-
async run() {
|
|
2089
|
-
try {
|
|
2090
|
-
return await interfaceCodec.run();
|
|
2091
|
-
} finally {
|
|
2092
|
-
onTaskFinished();
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2072
|
+
return {
|
|
2073
|
+
run: () => runWorker$1(workerData, config)
|
|
2095
2074
|
};
|
|
2096
|
-
return codec;
|
|
2097
2075
|
}
|
|
2098
2076
|
|
|
2099
2077
|
function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
2100
|
-
const workerOptions = { type: "module" };
|
|
2101
|
-
Object.assign(workerData, {
|
|
2102
|
-
streams: {},
|
|
2103
|
-
result: new Promise((resolve, reject) => {
|
|
2104
|
-
workerData.resolveResult = resolve;
|
|
2105
|
-
workerData.rejectResult = reject;
|
|
2106
|
-
})
|
|
2107
|
-
});
|
|
2108
2078
|
if (!workerData.interface) {
|
|
2109
|
-
|
|
2110
|
-
workerData.
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
workerData.worker = getWorker({});
|
|
2114
|
-
} catch (_error) {
|
|
2115
|
-
classicWorkersSupported = false;
|
|
2116
|
-
workerData.worker = getWorker(workerOptions);
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
|
-
workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
|
|
2120
|
-
workerData.interface = {
|
|
2121
|
-
async run() {
|
|
2122
|
-
const { readable, options } = workerData;
|
|
2123
|
-
const writer = workerData.writable.getWriter();
|
|
2124
|
-
let resolveStreamClosed, streamClosed;
|
|
2125
|
-
streamClosed = new Promise(resolve => resolveStreamClosed = resolve);
|
|
2126
|
-
const writable = new WritableStream({
|
|
2127
|
-
async write(chunk) {
|
|
2128
|
-
await writer.ready;
|
|
2129
|
-
await writer.write(chunk);
|
|
2130
|
-
},
|
|
2131
|
-
async close() {
|
|
2132
|
-
writer.releaseLock();
|
|
2133
|
-
resolveStreamClosed();
|
|
2134
|
-
},
|
|
2135
|
-
abort(reason) {
|
|
2136
|
-
writer.abort(reason);
|
|
2137
|
-
}
|
|
2138
|
-
});
|
|
2139
|
-
const scripts = workerData.scripts.slice(1);
|
|
2140
|
-
const message = { type: MESSAGE_START, scripts, options, config: { chunkSize } };
|
|
2141
|
-
if (workerData.transferStreams && transferStreamsSupported) {
|
|
2142
|
-
const streamsTransferred = sendMessage({ ...message, readable, writable });
|
|
2143
|
-
if (!streamsTransferred) {
|
|
2144
|
-
transferStreamsSupported = false;
|
|
2145
|
-
initStreams(readable, writable);
|
|
2146
|
-
}
|
|
2147
|
-
} else {
|
|
2148
|
-
sendMessage(message);
|
|
2149
|
-
initStreams(readable, writable);
|
|
2150
|
-
}
|
|
2151
|
-
const result = await workerData.result;
|
|
2152
|
-
try {
|
|
2153
|
-
await writable.close();
|
|
2154
|
-
} catch (_error) {
|
|
2155
|
-
// ignored
|
|
2156
|
-
}
|
|
2157
|
-
await streamClosed;
|
|
2158
|
-
return result;
|
|
2079
|
+
Object.assign(workerData, {
|
|
2080
|
+
worker: getWebWorker(workerData.scripts[0], baseURL, workerData),
|
|
2081
|
+
interface: {
|
|
2082
|
+
run: () => runWebWorker(workerData, { chunkSize })
|
|
2159
2083
|
}
|
|
2160
|
-
};
|
|
2084
|
+
});
|
|
2161
2085
|
}
|
|
2162
2086
|
return workerData.interface;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
|
|
2090
|
+
const codecStream = new CodecStream(options, config);
|
|
2091
|
+
try {
|
|
2092
|
+
await readable.pipeThrough(codecStream).pipeTo(writable, { preventClose: true, preventAbort: true });
|
|
2093
|
+
const {
|
|
2094
|
+
signature,
|
|
2095
|
+
size
|
|
2096
|
+
} = codecStream;
|
|
2097
|
+
return {
|
|
2098
|
+
signature,
|
|
2099
|
+
size
|
|
2100
|
+
};
|
|
2101
|
+
} finally {
|
|
2102
|
+
onTaskFinished();
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2163
2105
|
|
|
2164
|
-
|
|
2165
|
-
|
|
2106
|
+
async function runWebWorker(workerData, config) {
|
|
2107
|
+
let resolveResult, rejectResult;
|
|
2108
|
+
const result = new Promise((resolve, reject) => {
|
|
2109
|
+
resolveResult = resolve;
|
|
2110
|
+
rejectResult = reject;
|
|
2111
|
+
});
|
|
2112
|
+
Object.assign(workerData, {
|
|
2113
|
+
reader: null,
|
|
2114
|
+
writer: null,
|
|
2115
|
+
resolveResult,
|
|
2116
|
+
rejectResult,
|
|
2117
|
+
result
|
|
2118
|
+
});
|
|
2119
|
+
const { readable, options } = workerData;
|
|
2120
|
+
const { writable, closed } = detectClosedStream(workerData.writable);
|
|
2121
|
+
const streamsTransferred = sendMessage({
|
|
2122
|
+
type: MESSAGE_START,
|
|
2123
|
+
scripts: workerData.scripts.slice(1),
|
|
2124
|
+
options,
|
|
2125
|
+
config,
|
|
2126
|
+
readable,
|
|
2127
|
+
writable
|
|
2128
|
+
}, workerData);
|
|
2129
|
+
if (!streamsTransferred) {
|
|
2130
|
+
Object.assign(workerData, {
|
|
2166
2131
|
reader: readable.getReader(),
|
|
2167
2132
|
writer: writable.getWriter()
|
|
2168
2133
|
});
|
|
2169
2134
|
}
|
|
2135
|
+
const resultValue = await result;
|
|
2136
|
+
try {
|
|
2137
|
+
await writable.close();
|
|
2138
|
+
} catch (_error) {
|
|
2139
|
+
// ignored
|
|
2140
|
+
}
|
|
2141
|
+
await closed;
|
|
2142
|
+
return resultValue;
|
|
2143
|
+
}
|
|
2170
2144
|
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2145
|
+
function detectClosedStream(writableSource) {
|
|
2146
|
+
const writer = writableSource.getWriter();
|
|
2147
|
+
let resolveStreamClosed;
|
|
2148
|
+
const closed = new Promise(resolve => resolveStreamClosed = resolve);
|
|
2149
|
+
const writable = new WritableStream({
|
|
2150
|
+
async write(chunk) {
|
|
2151
|
+
await writer.ready;
|
|
2152
|
+
await writer.write(chunk);
|
|
2153
|
+
},
|
|
2154
|
+
close() {
|
|
2155
|
+
writer.releaseLock();
|
|
2156
|
+
resolveStreamClosed();
|
|
2157
|
+
},
|
|
2158
|
+
abort(reason) {
|
|
2159
|
+
writer.abort(reason);
|
|
2176
2160
|
}
|
|
2161
|
+
});
|
|
2162
|
+
return { writable, closed };
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
let classicWorkersSupported = true;
|
|
2166
|
+
let transferStreamsSupported = true;
|
|
2167
|
+
|
|
2168
|
+
function getWebWorker(url, baseURL, workerData) {
|
|
2169
|
+
const workerOptions = { type: "module" };
|
|
2170
|
+
let scriptUrl, worker;
|
|
2171
|
+
if (typeof url == FUNCTION_TYPE$1) {
|
|
2172
|
+
url = url();
|
|
2173
|
+
}
|
|
2174
|
+
try {
|
|
2175
|
+
scriptUrl = new URL(url, baseURL);
|
|
2176
|
+
} catch (_error) {
|
|
2177
|
+
scriptUrl = url;
|
|
2178
|
+
}
|
|
2179
|
+
if (classicWorkersSupported) {
|
|
2177
2180
|
try {
|
|
2178
|
-
|
|
2181
|
+
worker = new Worker(scriptUrl);
|
|
2179
2182
|
} catch (_error) {
|
|
2180
|
-
|
|
2183
|
+
classicWorkersSupported = false;
|
|
2184
|
+
worker = new Worker(scriptUrl, workerOptions);
|
|
2181
2185
|
}
|
|
2182
|
-
|
|
2186
|
+
} else {
|
|
2187
|
+
worker = new Worker(scriptUrl, workerOptions);
|
|
2183
2188
|
}
|
|
2189
|
+
worker.addEventListener(MESSAGE_EVENT_TYPE, event => onMessage(event, workerData));
|
|
2190
|
+
return worker;
|
|
2191
|
+
}
|
|
2184
2192
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
data = new Uint8Array(data);
|
|
2194
|
-
}
|
|
2195
|
-
message.data = data.buffer;
|
|
2196
|
-
transferrables.push(message.data);
|
|
2193
|
+
function sendMessage(message, { worker, writer, onTaskFinished, transferStreams }) {
|
|
2194
|
+
try {
|
|
2195
|
+
let { data, readable, writable } = message;
|
|
2196
|
+
const transferrables = [];
|
|
2197
|
+
if (data) {
|
|
2198
|
+
const { buffer, length } = data;
|
|
2199
|
+
if (length != buffer.byteLength) {
|
|
2200
|
+
data = new Uint8Array(data);
|
|
2197
2201
|
}
|
|
2202
|
+
message.data = data.buffer;
|
|
2203
|
+
transferrables.push(message.data);
|
|
2204
|
+
}
|
|
2205
|
+
if (transferStreams && transferStreamsSupported) {
|
|
2198
2206
|
if (readable) {
|
|
2199
2207
|
transferrables.push(readable);
|
|
2200
2208
|
}
|
|
2201
2209
|
if (writable) {
|
|
2202
2210
|
transferrables.push(writable);
|
|
2203
2211
|
}
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2212
|
+
} else {
|
|
2213
|
+
message.readable = message.writable = null;
|
|
2214
|
+
}
|
|
2215
|
+
if (transferrables.length) {
|
|
2216
|
+
try {
|
|
2217
|
+
worker.postMessage(message, transferrables);
|
|
2218
|
+
return true;
|
|
2219
|
+
} catch (_error) {
|
|
2220
|
+
transferStreamsSupported = false;
|
|
2221
|
+
message.readable = message.writable = null;
|
|
2213
2222
|
worker.postMessage(message);
|
|
2214
2223
|
}
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2224
|
+
} else {
|
|
2225
|
+
worker.postMessage(message);
|
|
2226
|
+
}
|
|
2227
|
+
} catch (error) {
|
|
2228
|
+
if (writer) {
|
|
2229
|
+
writer.releaseLock();
|
|
2221
2230
|
}
|
|
2231
|
+
onTaskFinished();
|
|
2232
|
+
throw error;
|
|
2222
2233
|
}
|
|
2234
|
+
}
|
|
2223
2235
|
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
Object.assign(error, { stack, code, name });
|
|
2235
|
-
close(error);
|
|
2236
|
-
} else {
|
|
2237
|
-
if (type == MESSAGE_PULL) {
|
|
2238
|
-
const { value, done } = await reader.read();
|
|
2239
|
-
sendMessage({ type: MESSAGE_DATA, data: value, done, messageId });
|
|
2240
|
-
}
|
|
2241
|
-
if (type == MESSAGE_DATA) {
|
|
2242
|
-
await writer.ready;
|
|
2243
|
-
await writer.write(new Uint8Array(data));
|
|
2244
|
-
sendMessage({ type: MESSAGE_ACK_DATA, messageId });
|
|
2245
|
-
}
|
|
2246
|
-
if (type == MESSAGE_CLOSE) {
|
|
2247
|
-
close(null, result);
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
2250
|
-
} catch (error) {
|
|
2236
|
+
async function onMessage(event, workerData) {
|
|
2237
|
+
const message = event.data;
|
|
2238
|
+
const { reader, writer, resolveResult, rejectResult, onTaskFinished } = workerData;
|
|
2239
|
+
const { type, data, messageId, result } = message;
|
|
2240
|
+
const reponseError = message.error;
|
|
2241
|
+
try {
|
|
2242
|
+
if (reponseError) {
|
|
2243
|
+
const { message, stack, code, name } = reponseError;
|
|
2244
|
+
const error = new Error(message);
|
|
2245
|
+
Object.assign(error, { stack, code, name });
|
|
2251
2246
|
close(error);
|
|
2252
|
-
}
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
rejectResult(error);
|
|
2257
|
-
} else {
|
|
2258
|
-
resolveResult(result);
|
|
2247
|
+
} else {
|
|
2248
|
+
if (type == MESSAGE_PULL) {
|
|
2249
|
+
const { value, done } = await reader.read();
|
|
2250
|
+
sendMessage({ type: MESSAGE_DATA, data: value, done, messageId }, workerData);
|
|
2259
2251
|
}
|
|
2260
|
-
if (
|
|
2261
|
-
writer.
|
|
2252
|
+
if (type == MESSAGE_DATA) {
|
|
2253
|
+
await writer.ready;
|
|
2254
|
+
await writer.write(new Uint8Array(data));
|
|
2255
|
+
sendMessage({ type: MESSAGE_ACK_DATA, messageId }, workerData);
|
|
2262
2256
|
}
|
|
2263
|
-
|
|
2257
|
+
if (type == MESSAGE_CLOSE) {
|
|
2258
|
+
close(null, result);
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
} catch (error) {
|
|
2262
|
+
close(error);
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
function close(error, result) {
|
|
2266
|
+
if (error) {
|
|
2267
|
+
rejectResult(error);
|
|
2268
|
+
} else {
|
|
2269
|
+
resolveResult(result);
|
|
2264
2270
|
}
|
|
2271
|
+
if (writer) {
|
|
2272
|
+
writer.releaseLock();
|
|
2273
|
+
}
|
|
2274
|
+
onTaskFinished();
|
|
2265
2275
|
}
|
|
2266
2276
|
}
|
|
2267
2277
|
|
|
@@ -2387,9 +2397,11 @@
|
|
|
2387
2397
|
*/
|
|
2388
2398
|
|
|
2389
2399
|
/* global Blob, atob, btoa, XMLHttpRequest, URL, fetch, ReadableStream, WritableStream, FileReader, TransformStream, Response */
|
|
2400
|
+
// deno-lint-ignore-file no-this-alias
|
|
2390
2401
|
|
|
2391
2402
|
const ERR_HTTP_STATUS = "HTTP error ";
|
|
2392
2403
|
const ERR_HTTP_RANGE = "HTTP Range not supported";
|
|
2404
|
+
const ERR_ITERATOR_COMPLETED_TOO_SOON = "Writer iterator completed too soon";
|
|
2393
2405
|
|
|
2394
2406
|
const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
|
|
2395
2407
|
const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
|
|
@@ -2922,6 +2934,65 @@
|
|
|
2922
2934
|
}
|
|
2923
2935
|
}
|
|
2924
2936
|
|
|
2937
|
+
class SplitZipWriter extends Stream {
|
|
2938
|
+
|
|
2939
|
+
constructor(writerGenerator, maxSize = 4294967296) {
|
|
2940
|
+
super();
|
|
2941
|
+
const writer = this;
|
|
2942
|
+
Object.assign(writer, {
|
|
2943
|
+
diskNumber: 0,
|
|
2944
|
+
diskOffset: 0,
|
|
2945
|
+
size: 0,
|
|
2946
|
+
availableSize: maxSize
|
|
2947
|
+
});
|
|
2948
|
+
let currentWriter, diskWritable, diskWriter;
|
|
2949
|
+
const writable = new WritableStream({
|
|
2950
|
+
async write(chunk) {
|
|
2951
|
+
if (!diskWriter) {
|
|
2952
|
+
const { value, done } = await writerGenerator.next();
|
|
2953
|
+
if (done && !value) {
|
|
2954
|
+
throw new Error(ERR_ITERATOR_COMPLETED_TOO_SOON);
|
|
2955
|
+
} else {
|
|
2956
|
+
currentWriter = value;
|
|
2957
|
+
currentWriter.size = 0;
|
|
2958
|
+
diskWritable = value.writable;
|
|
2959
|
+
diskWriter = diskWritable.getWriter();
|
|
2960
|
+
}
|
|
2961
|
+
await this.write(chunk);
|
|
2962
|
+
} else if (diskWriter && currentWriter.size + chunk.length > maxSize) {
|
|
2963
|
+
await diskWriter.ready;
|
|
2964
|
+
const chunkLength = maxSize - currentWriter.size;
|
|
2965
|
+
await diskWriter.write(chunk.slice(0, chunkLength));
|
|
2966
|
+
chunk = chunk.slice(chunkLength);
|
|
2967
|
+
currentWriter.size += chunkLength;
|
|
2968
|
+
writer.size += chunkLength;
|
|
2969
|
+
writer.diskOffset += diskWritable.size = currentWriter.size;
|
|
2970
|
+
writer.diskNumber++;
|
|
2971
|
+
await diskWriter.close();
|
|
2972
|
+
diskWriter = null;
|
|
2973
|
+
await this.write(chunk);
|
|
2974
|
+
} else {
|
|
2975
|
+
await diskWriter.ready;
|
|
2976
|
+
await diskWriter.write(chunk);
|
|
2977
|
+
currentWriter.size += chunk.length;
|
|
2978
|
+
writer.size += chunk.length;
|
|
2979
|
+
}
|
|
2980
|
+
writer.availableSize = maxSize - currentWriter.size;
|
|
2981
|
+
},
|
|
2982
|
+
async close() {
|
|
2983
|
+
await diskWriter.ready;
|
|
2984
|
+
diskWritable.size = currentWriter.size;
|
|
2985
|
+
await diskWriter.close();
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2988
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
2989
|
+
get() {
|
|
2990
|
+
return writable;
|
|
2991
|
+
}
|
|
2992
|
+
});
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2925
2996
|
function isHttpFamily(url) {
|
|
2926
2997
|
const { baseURL } = getConfiguration();
|
|
2927
2998
|
const { protocol } = new URL(url, baseURL);
|
|
@@ -3053,7 +3124,8 @@
|
|
|
3053
3124
|
"rawExtraField", "bitFlag", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
|
|
3054
3125
|
"extraFieldAES", "filenameUTF8", "commentUTF8", "offset", "zip64", "compressionMethod",
|
|
3055
3126
|
"extraFieldNTFS", "lastAccessDate", "creationDate", "extraFieldExtendedTimestamp",
|
|
3056
|
-
"version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute"
|
|
3127
|
+
"version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute",
|
|
3128
|
+
"diskNumberStart"];
|
|
3057
3129
|
|
|
3058
3130
|
class Entry {
|
|
3059
3131
|
|
|
@@ -3091,7 +3163,6 @@
|
|
|
3091
3163
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3092
3164
|
*/
|
|
3093
3165
|
|
|
3094
|
-
const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
|
|
3095
3166
|
const ERR_BAD_FORMAT = "File format is not recognized";
|
|
3096
3167
|
const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
|
|
3097
3168
|
const ERR_EOCDR_ZIP64_NOT_FOUND = "End of Zip64 central directory not found";
|
|
@@ -3164,15 +3235,16 @@
|
|
|
3164
3235
|
throw new Error(ERR_EOCDR_NOT_FOUND);
|
|
3165
3236
|
}
|
|
3166
3237
|
}
|
|
3167
|
-
const { lastDiskNumber } = reader;
|
|
3168
3238
|
const endOfDirectoryView = getDataView$1(endOfDirectoryInfo);
|
|
3169
3239
|
let directoryDataLength = getUint32(endOfDirectoryView, 12);
|
|
3170
3240
|
let directoryDataOffset = getUint32(endOfDirectoryView, 16);
|
|
3171
3241
|
const commentOffset = endOfDirectoryInfo.offset;
|
|
3172
3242
|
const commentLength = getUint16(endOfDirectoryView, 20);
|
|
3173
3243
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
3174
|
-
|
|
3175
|
-
|
|
3244
|
+
const lastDiskNumber = getUint16(endOfDirectoryView, 4);
|
|
3245
|
+
const expectedLastDiskNumber = reader.lastDiskNumber || 0;
|
|
3246
|
+
let diskNumber = getUint16(endOfDirectoryView, 6);
|
|
3247
|
+
if (expectedLastDiskNumber != lastDiskNumber) {
|
|
3176
3248
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
3177
3249
|
}
|
|
3178
3250
|
let filesLength = getUint16(endOfDirectoryView, 8);
|
|
@@ -3341,7 +3413,7 @@
|
|
|
3341
3413
|
compressedSize
|
|
3342
3414
|
} = zipEntry;
|
|
3343
3415
|
const localDirectory = zipEntry.localDirectory = {};
|
|
3344
|
-
|
|
3416
|
+
const dataArray = await readUint8Array(reader, offset, 30, diskNumberStart);
|
|
3345
3417
|
const dataView = getDataView$1(dataArray);
|
|
3346
3418
|
let password = getOptionValue$1(zipEntry, options, "password");
|
|
3347
3419
|
password = password && password.length && password;
|
|
@@ -3712,7 +3784,7 @@
|
|
|
3712
3784
|
const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
|
|
3713
3785
|
|
|
3714
3786
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
3715
|
-
const EXTRAFIELD_LENGTH_ZIP64 =
|
|
3787
|
+
const EXTRAFIELD_LENGTH_ZIP64 = 28;
|
|
3716
3788
|
|
|
3717
3789
|
let workers = 0;
|
|
3718
3790
|
const pendingEntries = [];
|
|
@@ -3720,14 +3792,26 @@
|
|
|
3720
3792
|
class ZipWriter {
|
|
3721
3793
|
|
|
3722
3794
|
constructor(writer, options = {}) {
|
|
3795
|
+
if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
|
|
3796
|
+
writer = new SplitZipWriter(writer);
|
|
3797
|
+
}
|
|
3723
3798
|
if (writer instanceof WritableStream) {
|
|
3724
3799
|
writer = { writable: writer };
|
|
3725
3800
|
}
|
|
3726
3801
|
if (writer.writable.size === UNDEFINED_VALUE) {
|
|
3727
3802
|
writer.writable.size = 0;
|
|
3728
3803
|
}
|
|
3804
|
+
const splitZipFile = writer instanceof SplitZipWriter;
|
|
3805
|
+
if (!splitZipFile) {
|
|
3806
|
+
Object.assign(writer, {
|
|
3807
|
+
diskNumber: 0,
|
|
3808
|
+
diskOffset: 0,
|
|
3809
|
+
availableSize: Infinity
|
|
3810
|
+
});
|
|
3811
|
+
}
|
|
3729
3812
|
Object.assign(this, {
|
|
3730
3813
|
writer,
|
|
3814
|
+
addSplitZipSignature: splitZipFile,
|
|
3731
3815
|
options,
|
|
3732
3816
|
config: getConfiguration(),
|
|
3733
3817
|
files: new Map(),
|
|
@@ -3979,10 +4063,21 @@
|
|
|
3979
4063
|
releaseLockWriter = () => delete zipWriter.lockWriter;
|
|
3980
4064
|
}
|
|
3981
4065
|
await initStream(fileWriter);
|
|
4066
|
+
const { writable, diskNumber } = writer;
|
|
4067
|
+
let { diskOffset } = writer;
|
|
4068
|
+
if (zipWriter.addSplitZipSignature) {
|
|
4069
|
+
delete zipWriter.addSplitZipSignature;
|
|
4070
|
+
const signatureArray = new Uint8Array(4);
|
|
4071
|
+
const signatureArrayView = new DataView(signatureArray.buffer);
|
|
4072
|
+
setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
|
|
4073
|
+
await writeData(writable, signatureArray);
|
|
4074
|
+
zipWriter.offset += 4;
|
|
4075
|
+
}
|
|
3982
4076
|
if (!bufferedWrite) {
|
|
3983
4077
|
await lockPreviousFileEntry;
|
|
3984
4078
|
}
|
|
3985
4079
|
writingEntryData = true;
|
|
4080
|
+
fileEntry.diskNumberStart = diskNumber;
|
|
3986
4081
|
fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
|
|
3987
4082
|
writingEntryData = false;
|
|
3988
4083
|
files.set(name, fileEntry);
|
|
@@ -3993,7 +4088,6 @@
|
|
|
3993
4088
|
await lockPreviousFileEntry;
|
|
3994
4089
|
await requestLockWriter();
|
|
3995
4090
|
writingBufferedEntryData = true;
|
|
3996
|
-
const { writable } = writer;
|
|
3997
4091
|
if (!dataDescriptor) {
|
|
3998
4092
|
const arrayBuffer = await sliceAsArrayBuffer(blob, 0, 26);
|
|
3999
4093
|
const arrayBufferView = new DataView(arrayBuffer);
|
|
@@ -4010,13 +4104,18 @@
|
|
|
4010
4104
|
await writeData(writable, new Uint8Array(arrayBuffer));
|
|
4011
4105
|
blob = blob.slice(arrayBuffer.byteLength);
|
|
4012
4106
|
}
|
|
4107
|
+
fileEntry.diskNumberStart = writer.diskNumber;
|
|
4108
|
+
diskOffset = writer.diskOffset;
|
|
4013
4109
|
await blob.stream().pipeTo(writable, { preventClose: true, signal });
|
|
4110
|
+
writable.size += blob.size;
|
|
4014
4111
|
writingBufferedEntryData = false;
|
|
4015
4112
|
}
|
|
4016
|
-
fileEntry.offset = zipWriter.offset;
|
|
4113
|
+
fileEntry.offset = zipWriter.offset - diskOffset;
|
|
4017
4114
|
if (fileEntry.zip64) {
|
|
4018
|
-
const
|
|
4019
|
-
|
|
4115
|
+
const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
|
|
4116
|
+
const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
|
|
4117
|
+
setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
|
|
4118
|
+
setUint32(rawExtraFieldZip64View, 28, diskNumberStart);
|
|
4020
4119
|
} else if (fileEntry.offset >= MAX_32_BITS) {
|
|
4021
4120
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
4022
4121
|
}
|
|
@@ -4060,7 +4159,7 @@
|
|
|
4060
4159
|
}
|
|
4061
4160
|
}
|
|
4062
4161
|
|
|
4063
|
-
async function createFileEntry(reader, writer,
|
|
4162
|
+
async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryInfo, config, options) {
|
|
4064
4163
|
const {
|
|
4065
4164
|
headerInfo,
|
|
4066
4165
|
dataDescriptorInfo
|
|
@@ -4105,7 +4204,7 @@
|
|
|
4105
4204
|
useCompressionStream
|
|
4106
4205
|
} = options;
|
|
4107
4206
|
const fileEntry = {
|
|
4108
|
-
lock
|
|
4207
|
+
lock,
|
|
4109
4208
|
versionMadeBy,
|
|
4110
4209
|
zip64,
|
|
4111
4210
|
directory: Boolean(directory),
|
|
@@ -4120,7 +4219,8 @@
|
|
|
4120
4219
|
extendedTimestamp,
|
|
4121
4220
|
msDosCompatible,
|
|
4122
4221
|
internalFileAttribute,
|
|
4123
|
-
externalFileAttribute
|
|
4222
|
+
externalFileAttribute,
|
|
4223
|
+
diskNumberStart
|
|
4124
4224
|
};
|
|
4125
4225
|
let uncompressedSize = 0;
|
|
4126
4226
|
let signature;
|
|
@@ -4392,10 +4492,12 @@
|
|
|
4392
4492
|
}
|
|
4393
4493
|
|
|
4394
4494
|
async function closeFile(zipWriter, comment, options) {
|
|
4395
|
-
const { files } = zipWriter;
|
|
4495
|
+
const { files, writer } = zipWriter;
|
|
4396
4496
|
let offset = 0;
|
|
4397
4497
|
let directoryDataLength = 0;
|
|
4398
|
-
|
|
4498
|
+
const { diskOffset, writable } = writer;
|
|
4499
|
+
let { diskNumber } = writer;
|
|
4500
|
+
let directoryOffset = zipWriter.offset - diskOffset;
|
|
4399
4501
|
let filesLength = files.size;
|
|
4400
4502
|
for (const [, {
|
|
4401
4503
|
rawFilename,
|
|
@@ -4424,7 +4526,7 @@
|
|
|
4424
4526
|
zip64 = true;
|
|
4425
4527
|
}
|
|
4426
4528
|
}
|
|
4427
|
-
const directoryArray = new Uint8Array(directoryDataLength
|
|
4529
|
+
const directoryArray = new Uint8Array(directoryDataLength);
|
|
4428
4530
|
const directoryView = getDataView(directoryArray);
|
|
4429
4531
|
for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
|
|
4430
4532
|
const {
|
|
@@ -4443,7 +4545,8 @@
|
|
|
4443
4545
|
internalFileAttribute,
|
|
4444
4546
|
externalFileAttribute,
|
|
4445
4547
|
extendedTimestamp,
|
|
4446
|
-
lastModDate
|
|
4548
|
+
lastModDate,
|
|
4549
|
+
diskNumberStart
|
|
4447
4550
|
} = fileEntry;
|
|
4448
4551
|
let rawExtraFieldExtendedTimestamp;
|
|
4449
4552
|
if (extendedTimestamp) {
|
|
@@ -4462,17 +4565,14 @@
|
|
|
4462
4565
|
arraySet(directoryArray, headerArray, offset + 6);
|
|
4463
4566
|
setUint16(directoryView, offset + 30, extraFieldLength);
|
|
4464
4567
|
setUint16(directoryView, offset + 32, getLength(rawComment));
|
|
4568
|
+
setUint16(directoryView, offset + 34, zip64 ? MAX_16_BITS : diskNumberStart);
|
|
4465
4569
|
setUint16(directoryView, offset + 36, internalFileAttribute);
|
|
4466
4570
|
if (externalFileAttribute) {
|
|
4467
4571
|
setUint32(directoryView, offset + 38, externalFileAttribute);
|
|
4468
4572
|
} else if (directory && msDosCompatible) {
|
|
4469
4573
|
setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
|
|
4470
4574
|
}
|
|
4471
|
-
|
|
4472
|
-
setUint32(directoryView, offset + 42, MAX_32_BITS);
|
|
4473
|
-
} else {
|
|
4474
|
-
setUint32(directoryView, offset + 42, fileEntryOffset);
|
|
4475
|
-
}
|
|
4575
|
+
setUint32(directoryView, offset + 42, zip64 ? MAX_32_BITS : fileEntryOffset);
|
|
4476
4576
|
arraySet(directoryArray, rawFilename, offset + 46);
|
|
4477
4577
|
arraySet(directoryArray, rawExtraFieldZip64, offset + 46 + getLength(rawFilename));
|
|
4478
4578
|
arraySet(directoryArray, rawExtraFieldAES, offset + 46 + getLength(rawFilename, rawExtraFieldZip64));
|
|
@@ -4489,39 +4589,52 @@
|
|
|
4489
4589
|
}
|
|
4490
4590
|
}
|
|
4491
4591
|
}
|
|
4592
|
+
await initStream(writer);
|
|
4593
|
+
await writeData(writable, directoryArray);
|
|
4594
|
+
const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
|
|
4595
|
+
const endOfdirectoryView = getDataView(endOfdirectoryArray);
|
|
4596
|
+
let lastDiskNumber = writer.diskNumber;
|
|
4597
|
+
const { availableSize } = writer;
|
|
4598
|
+
if (availableSize < endOfdirectoryArray.length) {
|
|
4599
|
+
lastDiskNumber++;
|
|
4600
|
+
}
|
|
4601
|
+
offset = 0;
|
|
4492
4602
|
if (zip64) {
|
|
4493
|
-
setUint32(
|
|
4494
|
-
setBigUint64(
|
|
4495
|
-
setUint16(
|
|
4496
|
-
setUint16(
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
setBigUint64(
|
|
4500
|
-
setBigUint64(
|
|
4501
|
-
|
|
4502
|
-
setBigUint64(
|
|
4503
|
-
setUint32(
|
|
4603
|
+
setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
|
|
4604
|
+
setBigUint64(endOfdirectoryView, 4, BigInt(44));
|
|
4605
|
+
setUint16(endOfdirectoryView, 12, 45);
|
|
4606
|
+
setUint16(endOfdirectoryView, 14, 45);
|
|
4607
|
+
setUint32(endOfdirectoryView, 16, lastDiskNumber);
|
|
4608
|
+
setUint32(endOfdirectoryView, 20, diskNumber);
|
|
4609
|
+
setBigUint64(endOfdirectoryView, 24, BigInt(filesLength));
|
|
4610
|
+
setBigUint64(endOfdirectoryView, 32, BigInt(filesLength));
|
|
4611
|
+
setBigUint64(endOfdirectoryView, 40, BigInt(directoryDataLength));
|
|
4612
|
+
setBigUint64(endOfdirectoryView, 48, BigInt(directoryOffset));
|
|
4613
|
+
setUint32(endOfdirectoryView, 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
|
|
4614
|
+
setBigUint64(endOfdirectoryView, 64, BigInt(directoryOffset) + BigInt(directoryDataLength));
|
|
4615
|
+
setUint32(endOfdirectoryView, 72, lastDiskNumber + 1);
|
|
4616
|
+
diskNumber = MAX_16_BITS;
|
|
4504
4617
|
filesLength = MAX_16_BITS;
|
|
4505
4618
|
directoryOffset = MAX_32_BITS;
|
|
4506
4619
|
directoryDataLength = MAX_32_BITS;
|
|
4507
|
-
offset +=
|
|
4508
|
-
}
|
|
4509
|
-
setUint32(
|
|
4510
|
-
setUint16(
|
|
4511
|
-
setUint16(
|
|
4512
|
-
|
|
4513
|
-
|
|
4620
|
+
offset += ZIP64_END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH;
|
|
4621
|
+
}
|
|
4622
|
+
setUint32(endOfdirectoryView, offset, END_OF_CENTRAL_DIR_SIGNATURE);
|
|
4623
|
+
setUint16(endOfdirectoryView, offset + 4, lastDiskNumber);
|
|
4624
|
+
setUint16(endOfdirectoryView, offset + 6, diskNumber);
|
|
4625
|
+
setUint16(endOfdirectoryView, offset + 8, filesLength);
|
|
4626
|
+
setUint16(endOfdirectoryView, offset + 10, filesLength);
|
|
4627
|
+
setUint32(endOfdirectoryView, offset + 12, directoryDataLength);
|
|
4628
|
+
setUint32(endOfdirectoryView, offset + 16, directoryOffset);
|
|
4514
4629
|
const commentLength = getLength(comment);
|
|
4515
4630
|
if (commentLength) {
|
|
4516
4631
|
if (commentLength <= MAX_16_BITS) {
|
|
4517
|
-
setUint16(
|
|
4632
|
+
setUint16(endOfdirectoryView, offset + 20, commentLength);
|
|
4518
4633
|
} else {
|
|
4519
4634
|
throw new Error(ERR_INVALID_COMMENT);
|
|
4520
4635
|
}
|
|
4521
4636
|
}
|
|
4522
|
-
|
|
4523
|
-
await initStream(zipWriter.writer);
|
|
4524
|
-
await writeData(writable, directoryArray);
|
|
4637
|
+
await writeData(writable, endOfdirectoryArray);
|
|
4525
4638
|
if (commentLength) {
|
|
4526
4639
|
await writeData(writable, comment);
|
|
4527
4640
|
}
|
|
@@ -5258,6 +5371,7 @@
|
|
|
5258
5371
|
exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
|
|
5259
5372
|
exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
|
|
5260
5373
|
exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
|
|
5374
|
+
exports.ERR_ITERATOR_COMPLETED_TOO_SOON = ERR_ITERATOR_COMPLETED_TOO_SOON;
|
|
5261
5375
|
exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
|
|
5262
5376
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
5263
5377
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
|
|
@@ -5267,6 +5381,7 @@
|
|
|
5267
5381
|
exports.HttpReader = HttpReader;
|
|
5268
5382
|
exports.Reader = Reader;
|
|
5269
5383
|
exports.SplitZipReader = SplitZipReader;
|
|
5384
|
+
exports.SplitZipWriter = SplitZipWriter;
|
|
5270
5385
|
exports.TextReader = TextReader;
|
|
5271
5386
|
exports.TextWriter = TextWriter;
|
|
5272
5387
|
exports.Uint8ArrayReader = Uint8ArrayReader;
|