@zip.js/zip.js 2.6.32 → 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 +2441 -2287
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +1970 -1816
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +1969 -1815
- 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 +1971 -1817
- package/dist/zip.min.js +1 -1
- package/index-fflate.js +3 -1
- package/index.cjs +2441 -2287
- package/index.d.ts +36 -7
- package/index.js +3 -1
- package/lib/core/codec-pool.js +6 -5
- package/lib/core/codec-worker.js +321 -0
- package/lib/core/configuration.js +11 -8
- package/lib/core/constants.js +11 -5
- package/lib/core/io.js +150 -51
- 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 +23 -12
- package/lib/core/zip-entry.js +2 -1
- package/lib/core/zip-fs-core.js +1 -0
- package/lib/core/zip-reader.js +16 -12
- package/lib/core/zip-writer.js +102 -54
- package/lib/z-worker-inline.js +1 -1
- package/lib/zip.js +1 -1
- package/package.json +5 -5
- package/rollup-es5.config.dev.js +199 -0
- package/rollup-es5.config.js +243 -0
- package/tests/all/test-http-split-zip.js +37 -0
- package/tests/all/test-readable-stream.js +1 -2
- package/tests/all/test-readable-zip-stream.js +1 -1
- 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 -289
package/dist/zip-full.js
CHANGED
|
@@ -4257,37 +4257,50 @@
|
|
|
4257
4257
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4258
4258
|
*/
|
|
4259
4259
|
|
|
4260
|
-
const
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
t = (t >>> 1) ^ 0xEDB88320;
|
|
4266
|
-
} else {
|
|
4267
|
-
t = t >>> 1;
|
|
4268
|
-
}
|
|
4269
|
-
}
|
|
4270
|
-
table[i] = t;
|
|
4271
|
-
}
|
|
4260
|
+
const MAX_32_BITS = 0xffffffff;
|
|
4261
|
+
const MAX_16_BITS = 0xffff;
|
|
4262
|
+
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
4263
|
+
const COMPRESSION_METHOD_STORE = 0x00;
|
|
4264
|
+
const COMPRESSION_METHOD_AES = 0x63;
|
|
4272
4265
|
|
|
4273
|
-
|
|
4266
|
+
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
4267
|
+
const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
|
|
4268
|
+
const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
|
|
4269
|
+
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
4270
|
+
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
4271
|
+
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
4272
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
4273
|
+
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
4274
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
4275
|
+
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
4276
|
+
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;
|
|
4274
4277
|
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
+
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
4279
|
+
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
4280
|
+
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
4281
|
+
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
4282
|
+
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
4283
|
+
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
4284
|
+
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
4278
4285
|
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
this.crc = crc;
|
|
4285
|
-
}
|
|
4286
|
+
const BITFLAG_ENCRYPTED = 0x01;
|
|
4287
|
+
const BITFLAG_LEVEL = 0x06;
|
|
4288
|
+
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
4289
|
+
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
4290
|
+
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
4286
4291
|
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4292
|
+
const VERSION_DEFLATE = 0x14;
|
|
4293
|
+
const VERSION_ZIP64 = 0x2D;
|
|
4294
|
+
const VERSION_AES = 0x33;
|
|
4295
|
+
|
|
4296
|
+
const DIRECTORY_SIGNATURE = "/";
|
|
4297
|
+
|
|
4298
|
+
const MAX_DATE = new Date(2107, 11, 31);
|
|
4299
|
+
const MIN_DATE = new Date(1980, 0, 1);
|
|
4300
|
+
|
|
4301
|
+
const UNDEFINED_VALUE = undefined;
|
|
4302
|
+
const UNDEFINED_TYPE$1 = "undefined";
|
|
4303
|
+
const FUNCTION_TYPE$1 = "function";
|
|
4291
4304
|
|
|
4292
4305
|
/*
|
|
4293
4306
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -4317,21 +4330,25 @@
|
|
|
4317
4330
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4318
4331
|
*/
|
|
4319
4332
|
|
|
4320
|
-
class
|
|
4333
|
+
class StreamAdapter {
|
|
4321
4334
|
|
|
4322
|
-
constructor() {
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4335
|
+
constructor(Codec) {
|
|
4336
|
+
return class extends TransformStream {
|
|
4337
|
+
constructor(options) {
|
|
4338
|
+
const codec = new Codec(options);
|
|
4339
|
+
super({
|
|
4340
|
+
transform(chunk, controller) {
|
|
4341
|
+
controller.enqueue(codec.append(chunk));
|
|
4342
|
+
},
|
|
4343
|
+
flush(controller) {
|
|
4344
|
+
const chunk = codec.flush();
|
|
4345
|
+
if (chunk) {
|
|
4346
|
+
controller.enqueue(chunk);
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4349
|
+
});
|
|
4333
4350
|
}
|
|
4334
|
-
}
|
|
4351
|
+
};
|
|
4335
4352
|
}
|
|
4336
4353
|
}
|
|
4337
4354
|
|
|
@@ -4363,1302 +4380,1185 @@
|
|
|
4363
4380
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4364
4381
|
*/
|
|
4365
4382
|
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4383
|
+
const MINIMUM_CHUNK_SIZE = 64;
|
|
4384
|
+
let maxWorkers = 2;
|
|
4385
|
+
try {
|
|
4386
|
+
if (typeof navigator != UNDEFINED_TYPE$1 && navigator.hardwareConcurrency) {
|
|
4387
|
+
maxWorkers = navigator.hardwareConcurrency;
|
|
4388
|
+
}
|
|
4389
|
+
} catch (_error) {
|
|
4390
|
+
// ignored
|
|
4391
|
+
}
|
|
4392
|
+
const DEFAULT_CONFIGURATION = {
|
|
4393
|
+
chunkSize: 512 * 1024,
|
|
4394
|
+
maxWorkers,
|
|
4395
|
+
terminateWorkerTimeout: 5000,
|
|
4396
|
+
useWebWorkers: true,
|
|
4397
|
+
useCompressionStream: true,
|
|
4398
|
+
workerScripts: UNDEFINED_VALUE,
|
|
4399
|
+
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE$1 && CompressionStream,
|
|
4400
|
+
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE$1 && DecompressionStream
|
|
4401
|
+
};
|
|
4402
|
+
|
|
4403
|
+
const config = Object.assign({}, DEFAULT_CONFIGURATION);
|
|
4404
|
+
|
|
4405
|
+
function getConfiguration() {
|
|
4406
|
+
return config;
|
|
4407
|
+
}
|
|
4408
|
+
|
|
4409
|
+
function getChunkSize(config) {
|
|
4410
|
+
return Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
|
|
4411
|
+
}
|
|
4412
|
+
|
|
4413
|
+
function configure(configuration) {
|
|
4414
|
+
const {
|
|
4415
|
+
baseURL,
|
|
4416
|
+
chunkSize,
|
|
4417
|
+
maxWorkers,
|
|
4418
|
+
terminateWorkerTimeout,
|
|
4419
|
+
useCompressionStream,
|
|
4420
|
+
useWebWorkers,
|
|
4421
|
+
Deflate,
|
|
4422
|
+
Inflate,
|
|
4423
|
+
CompressionStream,
|
|
4424
|
+
DecompressionStream,
|
|
4425
|
+
workerScripts
|
|
4426
|
+
} = configuration;
|
|
4427
|
+
setIfDefined("baseURL", baseURL);
|
|
4428
|
+
setIfDefined("chunkSize", chunkSize);
|
|
4429
|
+
setIfDefined("maxWorkers", maxWorkers);
|
|
4430
|
+
setIfDefined("terminateWorkerTimeout", terminateWorkerTimeout);
|
|
4431
|
+
setIfDefined("useCompressionStream", useCompressionStream);
|
|
4432
|
+
setIfDefined("useWebWorkers", useWebWorkers);
|
|
4433
|
+
if (Deflate) {
|
|
4434
|
+
config.CompressionStream = new StreamAdapter(Deflate);
|
|
4435
|
+
}
|
|
4436
|
+
if (Inflate) {
|
|
4437
|
+
config.DecompressionStream = new StreamAdapter(Inflate);
|
|
4438
|
+
}
|
|
4439
|
+
setIfDefined("CompressionStream", CompressionStream);
|
|
4440
|
+
setIfDefined("DecompressionStream", DecompressionStream);
|
|
4441
|
+
if (workerScripts !== UNDEFINED_VALUE) {
|
|
4442
|
+
const { deflate, inflate } = workerScripts;
|
|
4443
|
+
if (deflate || inflate) {
|
|
4444
|
+
if (!config.workerScripts) {
|
|
4445
|
+
config.workerScripts = {};
|
|
4446
|
+
}
|
|
4447
|
+
}
|
|
4448
|
+
if (deflate) {
|
|
4449
|
+
if (!Array.isArray(deflate)) {
|
|
4450
|
+
throw new Error("workerScripts.deflate must be an array");
|
|
4451
|
+
}
|
|
4452
|
+
config.workerScripts.deflate = deflate;
|
|
4453
|
+
}
|
|
4454
|
+
if (inflate) {
|
|
4455
|
+
if (!Array.isArray(inflate)) {
|
|
4456
|
+
throw new Error("workerScripts.inflate must be an array");
|
|
4457
|
+
}
|
|
4458
|
+
config.workerScripts.inflate = inflate;
|
|
4372
4459
|
}
|
|
4373
|
-
return result;
|
|
4374
|
-
} else {
|
|
4375
|
-
return new TextEncoder().encode(value);
|
|
4376
4460
|
}
|
|
4377
4461
|
}
|
|
4378
4462
|
|
|
4379
|
-
|
|
4463
|
+
function setIfDefined(propertyName, propertyValue) {
|
|
4464
|
+
if (propertyValue !== UNDEFINED_VALUE) {
|
|
4465
|
+
config[propertyName] = propertyValue;
|
|
4466
|
+
}
|
|
4467
|
+
}
|
|
4380
4468
|
|
|
4381
|
-
/*// deno-lint-ignore-file no-this-alias *
|
|
4469
|
+
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]}});}
|
|
4382
4470
|
|
|
4383
4471
|
/*
|
|
4384
|
-
|
|
4385
|
-
* license or under the GNU GPL, version 2.0.
|
|
4386
|
-
*/
|
|
4472
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
4387
4473
|
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
* Crush to remove comments, shorten variable names and
|
|
4391
|
-
* generally reduce transmission size.
|
|
4392
|
-
*
|
|
4393
|
-
* @author Emily Stark
|
|
4394
|
-
* @author Mike Hamburg
|
|
4395
|
-
* @author Dan Boneh
|
|
4396
|
-
*/
|
|
4474
|
+
Redistribution and use in source and binary forms, with or without
|
|
4475
|
+
modification, are permitted provided that the following conditions are met:
|
|
4397
4476
|
|
|
4398
|
-
|
|
4477
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
4478
|
+
this list of conditions and the following disclaimer.
|
|
4399
4479
|
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
* @author Mike Hamburg
|
|
4404
|
-
* @author Dan Boneh
|
|
4405
|
-
*/
|
|
4480
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
4481
|
+
notice, this list of conditions and the following disclaimer in
|
|
4482
|
+
the documentation and/or other materials provided with the distribution.
|
|
4406
4483
|
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
* array of words, 32 bits at a time. Since the words are double-precision
|
|
4421
|
-
* floating point numbers, they fit some extra data. We use this (in a private,
|
|
4422
|
-
* possibly-changing manner) to encode the number of bits actually present
|
|
4423
|
-
* in the last word of the array.
|
|
4424
|
-
* </p>
|
|
4425
|
-
*
|
|
4426
|
-
* <p>
|
|
4427
|
-
* Because bitwise ops clear this out-of-band data, these arrays can be passed
|
|
4428
|
-
* to ciphers like AES which want arrays of words.
|
|
4429
|
-
* </p>
|
|
4484
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
4485
|
+
derived from this software without specific prior written permission.
|
|
4486
|
+
|
|
4487
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4488
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4489
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4490
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4491
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
4492
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
4493
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
4494
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
4495
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
4496
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4430
4497
|
*/
|
|
4431
|
-
const bitArray = {
|
|
4432
|
-
/**
|
|
4433
|
-
* Concatenate two bit arrays.
|
|
4434
|
-
* @param {bitArray} a1 The first array.
|
|
4435
|
-
* @param {bitArray} a2 The second array.
|
|
4436
|
-
* @return {bitArray} The concatenation of a1 and a2.
|
|
4437
|
-
*/
|
|
4438
|
-
concat(a1, a2) {
|
|
4439
|
-
if (a1.length === 0 || a2.length === 0) {
|
|
4440
|
-
return a1.concat(a2);
|
|
4441
|
-
}
|
|
4442
4498
|
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
} else {
|
|
4447
|
-
return bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
|
|
4448
|
-
}
|
|
4449
|
-
},
|
|
4499
|
+
function getMimeType() {
|
|
4500
|
+
return "application/octet-stream";
|
|
4501
|
+
}
|
|
4450
4502
|
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
const l = a.length;
|
|
4458
|
-
if (l === 0) {
|
|
4459
|
-
return 0;
|
|
4460
|
-
}
|
|
4461
|
-
const x = a[l - 1];
|
|
4462
|
-
return (l - 1) * 32 + bitArray.getPartial(x);
|
|
4463
|
-
},
|
|
4503
|
+
function initShimAsyncCodec(library, options = {}, registerDataHandler) {
|
|
4504
|
+
return {
|
|
4505
|
+
Deflate: createCodecClass(library.Deflate, options.deflate, registerDataHandler),
|
|
4506
|
+
Inflate: createCodecClass(library.Inflate, options.inflate, registerDataHandler)
|
|
4507
|
+
};
|
|
4508
|
+
}
|
|
4464
4509
|
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4510
|
+
function createCodecClass(constructor, constructorOptions, registerDataHandler) {
|
|
4511
|
+
return class {
|
|
4512
|
+
|
|
4513
|
+
constructor(options) {
|
|
4514
|
+
const codecAdapter = this;
|
|
4515
|
+
const onData = data => {
|
|
4516
|
+
if (codecAdapter.pendingData) {
|
|
4517
|
+
const { pendingData } = codecAdapter;
|
|
4518
|
+
codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
|
|
4519
|
+
pendingData.set(pendingData, 0);
|
|
4520
|
+
pendingData.set(data, pendingData.length);
|
|
4521
|
+
} else {
|
|
4522
|
+
codecAdapter.pendingData = new Uint8Array(data);
|
|
4523
|
+
}
|
|
4524
|
+
};
|
|
4525
|
+
if (Object.hasOwn(options, "level") && options.level === undefined) {
|
|
4526
|
+
delete options.level;
|
|
4527
|
+
}
|
|
4528
|
+
codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
|
|
4529
|
+
registerDataHandler(codecAdapter.codec, onData);
|
|
4474
4530
|
}
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
if (l > 0 && len) {
|
|
4479
|
-
a[l - 1] = bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);
|
|
4531
|
+
append(data) {
|
|
4532
|
+
this.codec.push(data);
|
|
4533
|
+
return getResponse(this);
|
|
4480
4534
|
}
|
|
4481
|
-
|
|
4482
|
-
|
|
4535
|
+
flush() {
|
|
4536
|
+
this.codec.push(new Uint8Array(), true);
|
|
4537
|
+
return getResponse(this);
|
|
4538
|
+
}
|
|
4539
|
+
};
|
|
4483
4540
|
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
partial(len, x, _end) {
|
|
4492
|
-
if (len === 32) {
|
|
4493
|
-
return x;
|
|
4541
|
+
function getResponse(codec) {
|
|
4542
|
+
if (codec.pendingData) {
|
|
4543
|
+
const output = codec.pendingData;
|
|
4544
|
+
codec.pendingData = null;
|
|
4545
|
+
return output;
|
|
4546
|
+
} else {
|
|
4547
|
+
return new Uint8Array();
|
|
4494
4548
|
}
|
|
4495
|
-
|
|
4496
|
-
|
|
4549
|
+
}
|
|
4550
|
+
}
|
|
4497
4551
|
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
* @param {Number} x The partial word.
|
|
4501
|
-
* @return {Number} The number of bits used by the partial word.
|
|
4502
|
-
*/
|
|
4503
|
-
getPartial(x) {
|
|
4504
|
-
return Math.round(x / 0x10000000000) || 32;
|
|
4505
|
-
},
|
|
4552
|
+
/*
|
|
4553
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
4506
4554
|
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
* @param {Number} shift The number of bits to shift.
|
|
4510
|
-
* @param {Number} [carry=0] A byte to carry in
|
|
4511
|
-
* @param {bitArray} [out=[]] An array to prepend to the output.
|
|
4512
|
-
* @private
|
|
4513
|
-
*/
|
|
4514
|
-
_shiftRight(a, shift, carry, out) {
|
|
4515
|
-
if (out === undefined) {
|
|
4516
|
-
out = [];
|
|
4517
|
-
}
|
|
4555
|
+
Redistribution and use in source and binary forms, with or without
|
|
4556
|
+
modification, are permitted provided that the following conditions are met:
|
|
4518
4557
|
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
carry = 0;
|
|
4522
|
-
}
|
|
4523
|
-
if (shift === 0) {
|
|
4524
|
-
return out.concat(a);
|
|
4525
|
-
}
|
|
4558
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
4559
|
+
this list of conditions and the following disclaimer.
|
|
4526
4560
|
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
}
|
|
4531
|
-
const last2 = a.length ? a[a.length - 1] : 0;
|
|
4532
|
-
const shift2 = bitArray.getPartial(last2);
|
|
4533
|
-
out.push(bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));
|
|
4534
|
-
return out;
|
|
4535
|
-
}
|
|
4536
|
-
};
|
|
4561
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
4562
|
+
notice, this list of conditions and the following disclaimer in
|
|
4563
|
+
the documentation and/or other materials provided with the distribution.
|
|
4537
4564
|
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
* @author Emily Stark
|
|
4541
|
-
* @author Mike Hamburg
|
|
4542
|
-
* @author Dan Boneh
|
|
4543
|
-
*/
|
|
4565
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
4566
|
+
derived from this software without specific prior written permission.
|
|
4544
4567
|
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4568
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4569
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4570
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4571
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4572
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
4573
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
4574
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
4575
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
4576
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
4577
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4548
4578
|
*/
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
if ((i & 3) === 0) {
|
|
4559
|
-
tmp = arr[i / 4];
|
|
4560
|
-
}
|
|
4561
|
-
out[i] = tmp >>> 24;
|
|
4562
|
-
tmp <<= 8;
|
|
4563
|
-
}
|
|
4564
|
-
return out;
|
|
4565
|
-
},
|
|
4566
|
-
/** Convert from an array of bytes to a bitArray. */
|
|
4567
|
-
toBits(bytes) {
|
|
4568
|
-
const out = [];
|
|
4569
|
-
let i;
|
|
4570
|
-
let tmp = 0;
|
|
4571
|
-
for (i = 0; i < bytes.length; i++) {
|
|
4572
|
-
tmp = tmp << 8 | bytes[i];
|
|
4573
|
-
if ((i & 3) === 3) {
|
|
4574
|
-
out.push(tmp);
|
|
4575
|
-
tmp = 0;
|
|
4576
|
-
}
|
|
4577
|
-
}
|
|
4578
|
-
if (i & 3) {
|
|
4579
|
-
out.push(bitArray.partial(8 * (i & 3), tmp));
|
|
4580
|
-
}
|
|
4581
|
-
return out;
|
|
4579
|
+
|
|
4580
|
+
const table = [];
|
|
4581
|
+
for (let i = 0; i < 256; i++) {
|
|
4582
|
+
let t = i;
|
|
4583
|
+
for (let j = 0; j < 8; j++) {
|
|
4584
|
+
if (t & 1) {
|
|
4585
|
+
t = (t >>> 1) ^ 0xEDB88320;
|
|
4586
|
+
} else {
|
|
4587
|
+
t = t >>> 1;
|
|
4582
4588
|
}
|
|
4583
4589
|
}
|
|
4584
|
-
|
|
4590
|
+
table[i] = t;
|
|
4591
|
+
}
|
|
4585
4592
|
|
|
4586
|
-
|
|
4593
|
+
class Crc32 {
|
|
4587
4594
|
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
* @constructor
|
|
4591
|
-
*/
|
|
4592
|
-
hash.sha1 = function (hash) {
|
|
4593
|
-
if (hash) {
|
|
4594
|
-
this._h = hash._h.slice(0);
|
|
4595
|
-
this._buffer = hash._buffer.slice(0);
|
|
4596
|
-
this._length = hash._length;
|
|
4597
|
-
} else {
|
|
4598
|
-
this.reset();
|
|
4595
|
+
constructor(crc) {
|
|
4596
|
+
this.crc = crc || -1;
|
|
4599
4597
|
}
|
|
4600
|
-
};
|
|
4601
|
-
|
|
4602
|
-
hash.sha1.prototype = {
|
|
4603
|
-
/**
|
|
4604
|
-
* The hash's block size, in bits.
|
|
4605
|
-
* @constant
|
|
4606
|
-
*/
|
|
4607
|
-
blockSize: 512,
|
|
4608
|
-
|
|
4609
|
-
/**
|
|
4610
|
-
* Reset the hash state.
|
|
4611
|
-
* @return this
|
|
4612
|
-
*/
|
|
4613
|
-
reset() {
|
|
4614
|
-
const sha1 = this;
|
|
4615
|
-
sha1._h = this._init.slice(0);
|
|
4616
|
-
sha1._buffer = [];
|
|
4617
|
-
sha1._length = 0;
|
|
4618
|
-
return sha1;
|
|
4619
|
-
},
|
|
4620
4598
|
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
*/
|
|
4626
|
-
update(data) {
|
|
4627
|
-
const sha1 = this;
|
|
4628
|
-
if (typeof data === "string") {
|
|
4629
|
-
data = codec.utf8String.toBits(data);
|
|
4630
|
-
}
|
|
4631
|
-
const b = sha1._buffer = bitArray.concat(sha1._buffer, data);
|
|
4632
|
-
const ol = sha1._length;
|
|
4633
|
-
const nl = sha1._length = ol + bitArray.bitLength(data);
|
|
4634
|
-
if (nl > 9007199254740991) {
|
|
4635
|
-
throw new Error("Cannot hash more than 2^53 - 1 bits");
|
|
4636
|
-
}
|
|
4637
|
-
const c = new Uint32Array(b);
|
|
4638
|
-
let j = 0;
|
|
4639
|
-
for (let i = sha1.blockSize + ol - ((sha1.blockSize + ol) & (sha1.blockSize - 1)); i <= nl;
|
|
4640
|
-
i += sha1.blockSize) {
|
|
4641
|
-
sha1._block(c.subarray(16 * j, 16 * (j + 1)));
|
|
4642
|
-
j += 1;
|
|
4599
|
+
append(data) {
|
|
4600
|
+
let crc = this.crc | 0;
|
|
4601
|
+
for (let offset = 0, length = data.length | 0; offset < length; offset++) {
|
|
4602
|
+
crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
|
|
4643
4603
|
}
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
},
|
|
4604
|
+
this.crc = crc;
|
|
4605
|
+
}
|
|
4647
4606
|
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
finalize() {
|
|
4653
|
-
const sha1 = this;
|
|
4654
|
-
let b = sha1._buffer;
|
|
4655
|
-
const h = sha1._h;
|
|
4607
|
+
get() {
|
|
4608
|
+
return ~this.crc;
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4656
4611
|
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
// Round out the buffer to a multiple of 16 words, less the 2 length words.
|
|
4660
|
-
for (let i = b.length + 2; i & 15; i++) {
|
|
4661
|
-
b.push(0);
|
|
4662
|
-
}
|
|
4612
|
+
/*
|
|
4613
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
4663
4614
|
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
b.push(sha1._length | 0);
|
|
4615
|
+
Redistribution and use in source and binary forms, with or without
|
|
4616
|
+
modification, are permitted provided that the following conditions are met:
|
|
4667
4617
|
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
}
|
|
4618
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
4619
|
+
this list of conditions and the following disclaimer.
|
|
4671
4620
|
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4621
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
4622
|
+
notice, this list of conditions and the following disclaimer in
|
|
4623
|
+
the documentation and/or other materials provided with the distribution.
|
|
4675
4624
|
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
* @private
|
|
4679
|
-
*/
|
|
4680
|
-
_init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],
|
|
4625
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
4626
|
+
derived from this software without specific prior written permission.
|
|
4681
4627
|
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4628
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4629
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4630
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4631
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4632
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
4633
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
4634
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
4635
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
4636
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
4637
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4638
|
+
*/
|
|
4687
4639
|
|
|
4688
|
-
|
|
4689
|
-
* The SHA-1 logical functions f(0), f(1), ..., f(79).
|
|
4690
|
-
* @private
|
|
4691
|
-
*/
|
|
4692
|
-
_f(t, b, c, d) {
|
|
4693
|
-
if (t <= 19) {
|
|
4694
|
-
return (b & c) | (~b & d);
|
|
4695
|
-
} else if (t <= 39) {
|
|
4696
|
-
return b ^ c ^ d;
|
|
4697
|
-
} else if (t <= 59) {
|
|
4698
|
-
return (b & c) | (b & d) | (c & d);
|
|
4699
|
-
} else if (t <= 79) {
|
|
4700
|
-
return b ^ c ^ d;
|
|
4701
|
-
}
|
|
4702
|
-
},
|
|
4640
|
+
class Crc32Stream extends TransformStream {
|
|
4703
4641
|
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4642
|
+
constructor() {
|
|
4643
|
+
const crc32 = new Crc32();
|
|
4644
|
+
super({
|
|
4645
|
+
transform(chunk) {
|
|
4646
|
+
crc32.append(chunk);
|
|
4647
|
+
},
|
|
4648
|
+
flush(controller) {
|
|
4649
|
+
const value = new Uint8Array(4);
|
|
4650
|
+
const dataView = new DataView(value.buffer);
|
|
4651
|
+
dataView.setUint32(0, crc32.get());
|
|
4652
|
+
controller.enqueue(value);
|
|
4653
|
+
}
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4656
|
+
}
|
|
4711
4657
|
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
* @param {Uint32Array|bitArray} words one block of words.
|
|
4715
|
-
* @private
|
|
4716
|
-
*/
|
|
4717
|
-
_block(words) {
|
|
4718
|
-
const sha1 = this;
|
|
4719
|
-
const h = sha1._h;
|
|
4720
|
-
// When words is passed to _block, it has 16 elements. SHA1 _block
|
|
4721
|
-
// function extends words with new elements (at the end there are 80 elements).
|
|
4722
|
-
// The problem is that if we use Uint32Array instead of Array,
|
|
4723
|
-
// the length of Uint32Array cannot be changed. Thus, we replace words with a
|
|
4724
|
-
// normal Array here.
|
|
4725
|
-
const w = Array(80); // do not use Uint32Array here as the instantiation is slower
|
|
4726
|
-
for (let j = 0; j < 16; j++) {
|
|
4727
|
-
w[j] = words[j];
|
|
4728
|
-
}
|
|
4658
|
+
/*
|
|
4659
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
4729
4660
|
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
let c = h[2];
|
|
4733
|
-
let d = h[3];
|
|
4734
|
-
let e = h[4];
|
|
4661
|
+
Redistribution and use in source and binary forms, with or without
|
|
4662
|
+
modification, are permitted provided that the following conditions are met:
|
|
4735
4663
|
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
w[t] = sha1._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
|
|
4739
|
-
}
|
|
4740
|
-
const tmp = (sha1._S(5, a) + sha1._f(t, b, c, d) + e + w[t] +
|
|
4741
|
-
sha1._key[Math.floor(t / 20)]) | 0;
|
|
4742
|
-
e = d;
|
|
4743
|
-
d = c;
|
|
4744
|
-
c = sha1._S(30, b);
|
|
4745
|
-
b = a;
|
|
4746
|
-
a = tmp;
|
|
4747
|
-
}
|
|
4664
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
4665
|
+
this list of conditions and the following disclaimer.
|
|
4748
4666
|
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4667
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
4668
|
+
notice, this list of conditions and the following disclaimer in
|
|
4669
|
+
the documentation and/or other materials provided with the distribution.
|
|
4670
|
+
|
|
4671
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
4672
|
+
derived from this software without specific prior written permission.
|
|
4673
|
+
|
|
4674
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4675
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4676
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4677
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4678
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
4679
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
4680
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
4681
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
4682
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
4683
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4684
|
+
*/
|
|
4685
|
+
|
|
4686
|
+
function encodeText(value) {
|
|
4687
|
+
if (typeof TextEncoder == "undefined") {
|
|
4688
|
+
value = unescape(encodeURIComponent(value));
|
|
4689
|
+
const result = new Uint8Array(value.length);
|
|
4690
|
+
for (let i = 0; i < result.length; i++) {
|
|
4691
|
+
result[i] = value.charCodeAt(i);
|
|
4692
|
+
}
|
|
4693
|
+
return result;
|
|
4694
|
+
} else {
|
|
4695
|
+
return new TextEncoder().encode(value);
|
|
4754
4696
|
}
|
|
4755
|
-
}
|
|
4697
|
+
}
|
|
4756
4698
|
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
*
|
|
4699
|
+
// Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl
|
|
4700
|
+
|
|
4701
|
+
// deno-lint-ignore-file no-this-alias
|
|
4702
|
+
|
|
4703
|
+
/*
|
|
4704
|
+
* SJCL is open. You can use, modify and redistribute it under a BSD
|
|
4705
|
+
* license or under the GNU GPL, version 2.0.
|
|
4706
|
+
*/
|
|
4707
|
+
|
|
4708
|
+
/** @fileOverview Javascript cryptography implementation.
|
|
4763
4709
|
*
|
|
4764
|
-
*
|
|
4765
|
-
*
|
|
4766
|
-
* Stanford University 2008-2010 and BSD-licensed for liability
|
|
4767
|
-
* reasons.
|
|
4710
|
+
* Crush to remove comments, shorten variable names and
|
|
4711
|
+
* generally reduce transmission size.
|
|
4768
4712
|
*
|
|
4769
4713
|
* @author Emily Stark
|
|
4770
4714
|
* @author Mike Hamburg
|
|
4771
4715
|
* @author Dan Boneh
|
|
4772
4716
|
*/
|
|
4773
4717
|
|
|
4774
|
-
|
|
4718
|
+
/*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
|
|
4719
|
+
|
|
4720
|
+
/** @fileOverview Arrays of bits, encoded as arrays of Numbers.
|
|
4721
|
+
*
|
|
4722
|
+
* @author Emily Stark
|
|
4723
|
+
* @author Mike Hamburg
|
|
4724
|
+
* @author Dan Boneh
|
|
4725
|
+
*/
|
|
4775
4726
|
|
|
4776
4727
|
/**
|
|
4777
|
-
*
|
|
4778
|
-
*
|
|
4728
|
+
* Arrays of bits, encoded as arrays of Numbers.
|
|
4729
|
+
* @namespace
|
|
4730
|
+
* @description
|
|
4731
|
+
* <p>
|
|
4732
|
+
* These objects are the currency accepted by SJCL's crypto functions.
|
|
4733
|
+
* </p>
|
|
4779
4734
|
*
|
|
4780
|
-
*
|
|
4781
|
-
*
|
|
4735
|
+
* <p>
|
|
4736
|
+
* Most of our crypto primitives operate on arrays of 4-byte words internally,
|
|
4737
|
+
* but many of them can take arguments that are not a multiple of 4 bytes.
|
|
4738
|
+
* This library encodes arrays of bits (whose size need not be a multiple of 8
|
|
4739
|
+
* bits) as arrays of 32-bit words. The bits are packed, big-endian, into an
|
|
4740
|
+
* array of words, 32 bits at a time. Since the words are double-precision
|
|
4741
|
+
* floating point numbers, they fit some extra data. We use this (in a private,
|
|
4742
|
+
* possibly-changing manner) to encode the number of bits actually present
|
|
4743
|
+
* in the last word of the array.
|
|
4744
|
+
* </p>
|
|
4745
|
+
*
|
|
4746
|
+
* <p>
|
|
4747
|
+
* Because bitwise ops clear this out-of-band data, these arrays can be passed
|
|
4748
|
+
* to ciphers like AES which want arrays of words.
|
|
4749
|
+
* </p>
|
|
4782
4750
|
*/
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
*
|
|
4795
|
-
* @private
|
|
4796
|
-
*/
|
|
4797
|
-
const aes = this;
|
|
4798
|
-
aes._tables = [[[], [], [], [], []], [[], [], [], [], []]];
|
|
4751
|
+
const bitArray = {
|
|
4752
|
+
/**
|
|
4753
|
+
* Concatenate two bit arrays.
|
|
4754
|
+
* @param {bitArray} a1 The first array.
|
|
4755
|
+
* @param {bitArray} a2 The second array.
|
|
4756
|
+
* @return {bitArray} The concatenation of a1 and a2.
|
|
4757
|
+
*/
|
|
4758
|
+
concat(a1, a2) {
|
|
4759
|
+
if (a1.length === 0 || a2.length === 0) {
|
|
4760
|
+
return a1.concat(a2);
|
|
4761
|
+
}
|
|
4799
4762
|
|
|
4800
|
-
|
|
4801
|
-
|
|
4763
|
+
const last = a1[a1.length - 1], shift = bitArray.getPartial(last);
|
|
4764
|
+
if (shift === 32) {
|
|
4765
|
+
return a1.concat(a2);
|
|
4766
|
+
} else {
|
|
4767
|
+
return bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
|
|
4802
4768
|
}
|
|
4769
|
+
},
|
|
4803
4770
|
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4771
|
+
/**
|
|
4772
|
+
* Find the length of an array of bits.
|
|
4773
|
+
* @param {bitArray} a The array.
|
|
4774
|
+
* @return {Number} The length of a, in bits.
|
|
4775
|
+
*/
|
|
4776
|
+
bitLength(a) {
|
|
4777
|
+
const l = a.length;
|
|
4778
|
+
if (l === 0) {
|
|
4779
|
+
return 0;
|
|
4812
4780
|
}
|
|
4781
|
+
const x = a[l - 1];
|
|
4782
|
+
return (l - 1) * 32 + bitArray.getPartial(x);
|
|
4783
|
+
},
|
|
4813
4784
|
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
// shift rows and add rcon
|
|
4825
|
-
if (i % keyLen === 0) {
|
|
4826
|
-
tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
|
|
4827
|
-
rcon = rcon << 1 ^ (rcon >> 7) * 283;
|
|
4828
|
-
}
|
|
4829
|
-
}
|
|
4830
|
-
|
|
4831
|
-
encKey[i] = encKey[i - keyLen] ^ tmp;
|
|
4785
|
+
/**
|
|
4786
|
+
* Truncate an array.
|
|
4787
|
+
* @param {bitArray} a The array.
|
|
4788
|
+
* @param {Number} len The length to truncate to, in bits.
|
|
4789
|
+
* @return {bitArray} A new array, truncated to len bits.
|
|
4790
|
+
*/
|
|
4791
|
+
clamp(a, len) {
|
|
4792
|
+
if (a.length * 32 < len) {
|
|
4793
|
+
return a;
|
|
4832
4794
|
}
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
decKey[j] = tmp;
|
|
4839
|
-
} else {
|
|
4840
|
-
decKey[j] = decTable[0][sbox[tmp >>> 24]] ^
|
|
4841
|
-
decTable[1][sbox[tmp >> 16 & 255]] ^
|
|
4842
|
-
decTable[2][sbox[tmp >> 8 & 255]] ^
|
|
4843
|
-
decTable[3][sbox[tmp & 255]];
|
|
4844
|
-
}
|
|
4795
|
+
a = a.slice(0, Math.ceil(len / 32));
|
|
4796
|
+
const l = a.length;
|
|
4797
|
+
len = len & 31;
|
|
4798
|
+
if (l > 0 && len) {
|
|
4799
|
+
a[l - 1] = bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);
|
|
4845
4800
|
}
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
/* Something like this might appear here eventually
|
|
4849
|
-
name: "AES",
|
|
4850
|
-
blockSize: 4,
|
|
4851
|
-
keySizes: [4,6,8],
|
|
4852
|
-
*/
|
|
4801
|
+
return a;
|
|
4802
|
+
},
|
|
4853
4803
|
|
|
4854
4804
|
/**
|
|
4855
|
-
*
|
|
4856
|
-
* @param {
|
|
4857
|
-
* @
|
|
4805
|
+
* Make a partial word for a bit array.
|
|
4806
|
+
* @param {Number} len The number of bits in the word.
|
|
4807
|
+
* @param {Number} x The bits.
|
|
4808
|
+
* @param {Number} [_end=0] Pass 1 if x has already been shifted to the high side.
|
|
4809
|
+
* @return {Number} The partial word.
|
|
4858
4810
|
*/
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4811
|
+
partial(len, x, _end) {
|
|
4812
|
+
if (len === 32) {
|
|
4813
|
+
return x;
|
|
4814
|
+
}
|
|
4815
|
+
return (_end ? x | 0 : x << (32 - len)) + len * 0x10000000000;
|
|
4816
|
+
},
|
|
4862
4817
|
|
|
4863
4818
|
/**
|
|
4864
|
-
*
|
|
4865
|
-
* @param {
|
|
4866
|
-
* @return {
|
|
4819
|
+
* Get the number of bits used by a partial word.
|
|
4820
|
+
* @param {Number} x The partial word.
|
|
4821
|
+
* @return {Number} The number of bits used by the partial word.
|
|
4867
4822
|
*/
|
|
4868
|
-
|
|
4869
|
-
return
|
|
4870
|
-
}
|
|
4823
|
+
getPartial(x) {
|
|
4824
|
+
return Math.round(x / 0x10000000000) || 32;
|
|
4825
|
+
},
|
|
4871
4826
|
|
|
4872
|
-
/**
|
|
4873
|
-
*
|
|
4874
|
-
*
|
|
4827
|
+
/** Shift an array right.
|
|
4828
|
+
* @param {bitArray} a The array to shift.
|
|
4829
|
+
* @param {Number} shift The number of bits to shift.
|
|
4830
|
+
* @param {Number} [carry=0] A byte to carry in
|
|
4831
|
+
* @param {bitArray} [out=[]] An array to prepend to the output.
|
|
4875
4832
|
* @private
|
|
4876
4833
|
*/
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
const sbox = encTable[4];
|
|
4881
|
-
const sboxInv = decTable[4];
|
|
4882
|
-
const d = [];
|
|
4883
|
-
const th = [];
|
|
4884
|
-
let xInv, x2, x4, x8;
|
|
4885
|
-
|
|
4886
|
-
// Compute double and third tables
|
|
4887
|
-
for (let i = 0; i < 256; i++) {
|
|
4888
|
-
th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
|
|
4889
|
-
}
|
|
4890
|
-
|
|
4891
|
-
for (let x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
|
|
4892
|
-
// Compute sbox
|
|
4893
|
-
let s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
|
|
4894
|
-
s = s >> 8 ^ s & 255 ^ 99;
|
|
4895
|
-
sbox[x] = s;
|
|
4896
|
-
sboxInv[s] = x;
|
|
4897
|
-
|
|
4898
|
-
// Compute MixColumns
|
|
4899
|
-
x8 = d[x4 = d[x2 = d[x]]];
|
|
4900
|
-
let tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
|
|
4901
|
-
let tEnc = d[s] * 0x101 ^ s * 0x1010100;
|
|
4902
|
-
|
|
4903
|
-
for (let i = 0; i < 4; i++) {
|
|
4904
|
-
encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
|
|
4905
|
-
decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
|
|
4906
|
-
}
|
|
4907
|
-
}
|
|
4908
|
-
|
|
4909
|
-
// Compactify. Considerable speedup on Firefox.
|
|
4910
|
-
for (let i = 0; i < 5; i++) {
|
|
4911
|
-
encTable[i] = encTable[i].slice(0);
|
|
4912
|
-
decTable[i] = decTable[i].slice(0);
|
|
4834
|
+
_shiftRight(a, shift, carry, out) {
|
|
4835
|
+
if (out === undefined) {
|
|
4836
|
+
out = [];
|
|
4913
4837
|
}
|
|
4914
|
-
}
|
|
4915
4838
|
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
* @param dir The direction, 0 for encrypt and 1 for decrypt.
|
|
4920
|
-
* @return {Array} The four encrypted or decrypted words.
|
|
4921
|
-
* @private
|
|
4922
|
-
*/
|
|
4923
|
-
_crypt(input, dir) {
|
|
4924
|
-
if (input.length !== 4) {
|
|
4925
|
-
throw new Error("invalid aes block size");
|
|
4839
|
+
for (; shift >= 32; shift -= 32) {
|
|
4840
|
+
out.push(carry);
|
|
4841
|
+
carry = 0;
|
|
4926
4842
|
}
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
const nInnerRounds = key.length / 4 - 2;
|
|
4931
|
-
const out = [0, 0, 0, 0];
|
|
4932
|
-
const table = this._tables[dir];
|
|
4933
|
-
|
|
4934
|
-
// load up the tables
|
|
4935
|
-
const t0 = table[0];
|
|
4936
|
-
const t1 = table[1];
|
|
4937
|
-
const t2 = table[2];
|
|
4938
|
-
const t3 = table[3];
|
|
4939
|
-
const sbox = table[4];
|
|
4940
|
-
|
|
4941
|
-
// state variables a,b,c,d are loaded with pre-whitened data
|
|
4942
|
-
let a = input[0] ^ key[0];
|
|
4943
|
-
let b = input[dir ? 3 : 1] ^ key[1];
|
|
4944
|
-
let c = input[2] ^ key[2];
|
|
4945
|
-
let d = input[dir ? 1 : 3] ^ key[3];
|
|
4946
|
-
let kIndex = 4;
|
|
4947
|
-
let a2, b2, c2;
|
|
4948
|
-
|
|
4949
|
-
// Inner rounds. Cribbed from OpenSSL.
|
|
4950
|
-
for (let i = 0; i < nInnerRounds; i++) {
|
|
4951
|
-
a2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];
|
|
4952
|
-
b2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];
|
|
4953
|
-
c2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];
|
|
4954
|
-
d = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];
|
|
4955
|
-
kIndex += 4;
|
|
4956
|
-
a = a2; b = b2; c = c2;
|
|
4843
|
+
if (shift === 0) {
|
|
4844
|
+
return out.concat(a);
|
|
4957
4845
|
}
|
|
4958
4846
|
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
sbox[a >>> 24] << 24 ^
|
|
4963
|
-
sbox[b >> 16 & 255] << 16 ^
|
|
4964
|
-
sbox[c >> 8 & 255] << 8 ^
|
|
4965
|
-
sbox[d & 255] ^
|
|
4966
|
-
key[kIndex++];
|
|
4967
|
-
a2 = a; a = b; b = c; c = d; d = a2;
|
|
4847
|
+
for (let i = 0; i < a.length; i++) {
|
|
4848
|
+
out.push(carry | a[i] >>> shift);
|
|
4849
|
+
carry = a[i] << (32 - shift);
|
|
4968
4850
|
}
|
|
4969
|
-
|
|
4851
|
+
const last2 = a.length ? a[a.length - 1] : 0;
|
|
4852
|
+
const shift2 = bitArray.getPartial(last2);
|
|
4853
|
+
out.push(bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));
|
|
4970
4854
|
return out;
|
|
4971
4855
|
}
|
|
4972
4856
|
};
|
|
4973
4857
|
|
|
4974
|
-
/**
|
|
4975
|
-
* Random values
|
|
4976
|
-
* @namespace
|
|
4977
|
-
*/
|
|
4978
|
-
const random = {
|
|
4979
|
-
/**
|
|
4980
|
-
* Generate random words with pure js, cryptographically not as strong & safe as native implementation.
|
|
4981
|
-
* @param {TypedArray} typedArray The array to fill.
|
|
4982
|
-
* @return {TypedArray} The random values.
|
|
4983
|
-
*/
|
|
4984
|
-
getRandomValues(typedArray) {
|
|
4985
|
-
const words = new Uint32Array(typedArray.buffer);
|
|
4986
|
-
const r = (m_w) => {
|
|
4987
|
-
let m_z = 0x3ade68b1;
|
|
4988
|
-
const mask = 0xffffffff;
|
|
4989
|
-
return function () {
|
|
4990
|
-
m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
|
|
4991
|
-
m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
|
|
4992
|
-
const result = ((((m_z << 0x10) + m_w) & mask) / 0x100000000) + .5;
|
|
4993
|
-
return result * (Math.random() > .5 ? 1 : -1);
|
|
4994
|
-
};
|
|
4995
|
-
};
|
|
4996
|
-
for (let i = 0, rcache; i < typedArray.length; i += 4) {
|
|
4997
|
-
const _r = r((rcache || Math.random()) * 0x100000000);
|
|
4998
|
-
rcache = _r() * 0x3ade67b7;
|
|
4999
|
-
words[i / 4] = (_r() * 0x100000000) | 0;
|
|
5000
|
-
}
|
|
5001
|
-
return typedArray;
|
|
5002
|
-
}
|
|
5003
|
-
};
|
|
5004
|
-
|
|
5005
|
-
/** @fileOverview CTR mode implementation.
|
|
5006
|
-
*
|
|
5007
|
-
* Special thanks to Roy Nicholson for pointing out a bug in our
|
|
5008
|
-
* implementation.
|
|
4858
|
+
/** @fileOverview Bit array codec implementations.
|
|
5009
4859
|
*
|
|
5010
4860
|
* @author Emily Stark
|
|
5011
4861
|
* @author Mike Hamburg
|
|
5012
4862
|
* @author Dan Boneh
|
|
5013
4863
|
*/
|
|
5014
4864
|
|
|
5015
|
-
/** Brian Gladman's CTR Mode.
|
|
5016
|
-
* @constructor
|
|
5017
|
-
* @param {Object} _prf The aes instance to generate key.
|
|
5018
|
-
* @param {bitArray} _iv The iv for ctr mode, it must be 128 bits.
|
|
5019
|
-
*/
|
|
5020
|
-
|
|
5021
|
-
const mode = {};
|
|
5022
|
-
|
|
5023
4865
|
/**
|
|
5024
|
-
*
|
|
4866
|
+
* Arrays of bytes
|
|
5025
4867
|
* @namespace
|
|
5026
4868
|
*/
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
/** Input some data to calculate.
|
|
5039
|
-
* @param {bitArray} data the data to process, it must be intergral multiple of 128 bits unless it's the last.
|
|
5040
|
-
*/
|
|
5041
|
-
update(data) {
|
|
5042
|
-
return this.calculate(this._prf, data, this._iv);
|
|
5043
|
-
}
|
|
5044
|
-
|
|
5045
|
-
incWord(word) {
|
|
5046
|
-
if (((word >> 24) & 0xff) === 0xff) { //overflow
|
|
5047
|
-
let b1 = (word >> 16) & 0xff;
|
|
5048
|
-
let b2 = (word >> 8) & 0xff;
|
|
5049
|
-
let b3 = word & 0xff;
|
|
5050
|
-
|
|
5051
|
-
if (b1 === 0xff) { // overflow b1
|
|
5052
|
-
b1 = 0;
|
|
5053
|
-
if (b2 === 0xff) {
|
|
5054
|
-
b2 = 0;
|
|
5055
|
-
if (b3 === 0xff) {
|
|
5056
|
-
b3 = 0;
|
|
5057
|
-
} else {
|
|
5058
|
-
++b3;
|
|
5059
|
-
}
|
|
5060
|
-
} else {
|
|
5061
|
-
++b2;
|
|
4869
|
+
const codec = {
|
|
4870
|
+
bytes: {
|
|
4871
|
+
/** Convert from a bitArray to an array of bytes. */
|
|
4872
|
+
fromBits(arr) {
|
|
4873
|
+
const bl = bitArray.bitLength(arr);
|
|
4874
|
+
const byteLength = bl / 8;
|
|
4875
|
+
const out = new Uint8Array(byteLength);
|
|
4876
|
+
let tmp;
|
|
4877
|
+
for (let i = 0; i < byteLength; i++) {
|
|
4878
|
+
if ((i & 3) === 0) {
|
|
4879
|
+
tmp = arr[i / 4];
|
|
5062
4880
|
}
|
|
5063
|
-
|
|
5064
|
-
|
|
4881
|
+
out[i] = tmp >>> 24;
|
|
4882
|
+
tmp <<= 8;
|
|
5065
4883
|
}
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
if ((counter[0] = this.incWord(counter[0])) === 0) {
|
|
5079
|
-
// encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
|
|
5080
|
-
counter[1] = this.incWord(counter[1]);
|
|
5081
|
-
}
|
|
5082
|
-
}
|
|
5083
|
-
|
|
5084
|
-
calculate(prf, data, iv) {
|
|
5085
|
-
let l;
|
|
5086
|
-
if (!(l = data.length)) {
|
|
5087
|
-
return [];
|
|
5088
|
-
}
|
|
5089
|
-
const bl = bitArray.bitLength(data);
|
|
5090
|
-
for (let i = 0; i < l; i += 4) {
|
|
5091
|
-
this.incCounter(iv);
|
|
5092
|
-
const e = prf.encrypt(iv);
|
|
5093
|
-
data[i] ^= e[0];
|
|
5094
|
-
data[i + 1] ^= e[1];
|
|
5095
|
-
data[i + 2] ^= e[2];
|
|
5096
|
-
data[i + 3] ^= e[3];
|
|
5097
|
-
}
|
|
5098
|
-
return bitArray.clamp(data, bl);
|
|
5099
|
-
}
|
|
5100
|
-
};
|
|
5101
|
-
|
|
5102
|
-
const misc = {
|
|
5103
|
-
importKey(password) {
|
|
5104
|
-
return new misc.hmacSha1(codec.bytes.toBits(password));
|
|
5105
|
-
},
|
|
5106
|
-
pbkdf2(prf, salt, count, length) {
|
|
5107
|
-
count = count || 10000;
|
|
5108
|
-
if (length < 0 || count < 0) {
|
|
5109
|
-
throw new Error("invalid params to pbkdf2");
|
|
5110
|
-
}
|
|
5111
|
-
const byteLength = ((length >> 5) + 1) << 2;
|
|
5112
|
-
let u, ui, i, j, k;
|
|
5113
|
-
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
5114
|
-
const out = new DataView(arrayBuffer);
|
|
5115
|
-
let outLength = 0;
|
|
5116
|
-
const b = bitArray;
|
|
5117
|
-
salt = codec.bytes.toBits(salt);
|
|
5118
|
-
for (k = 1; outLength < (byteLength || 1); k++) {
|
|
5119
|
-
u = ui = prf.encrypt(b.concat(salt, [k]));
|
|
5120
|
-
for (i = 1; i < count; i++) {
|
|
5121
|
-
ui = prf.encrypt(ui);
|
|
5122
|
-
for (j = 0; j < ui.length; j++) {
|
|
5123
|
-
u[j] ^= ui[j];
|
|
4884
|
+
return out;
|
|
4885
|
+
},
|
|
4886
|
+
/** Convert from an array of bytes to a bitArray. */
|
|
4887
|
+
toBits(bytes) {
|
|
4888
|
+
const out = [];
|
|
4889
|
+
let i;
|
|
4890
|
+
let tmp = 0;
|
|
4891
|
+
for (i = 0; i < bytes.length; i++) {
|
|
4892
|
+
tmp = tmp << 8 | bytes[i];
|
|
4893
|
+
if ((i & 3) === 3) {
|
|
4894
|
+
out.push(tmp);
|
|
4895
|
+
tmp = 0;
|
|
5124
4896
|
}
|
|
5125
4897
|
}
|
|
5126
|
-
|
|
5127
|
-
out.
|
|
5128
|
-
outLength += 4;
|
|
4898
|
+
if (i & 3) {
|
|
4899
|
+
out.push(bitArray.partial(8 * (i & 3), tmp));
|
|
5129
4900
|
}
|
|
4901
|
+
return out;
|
|
5130
4902
|
}
|
|
5131
|
-
return arrayBuffer.slice(0, length / 8);
|
|
5132
4903
|
}
|
|
5133
4904
|
};
|
|
5134
4905
|
|
|
5135
|
-
|
|
5136
|
-
*
|
|
5137
|
-
* @author Emily Stark
|
|
5138
|
-
* @author Mike Hamburg
|
|
5139
|
-
* @author Dan Boneh
|
|
5140
|
-
*/
|
|
4906
|
+
const hash = {};
|
|
5141
4907
|
|
|
5142
|
-
/**
|
|
4908
|
+
/**
|
|
4909
|
+
* Context for a SHA-1 operation in progress.
|
|
5143
4910
|
* @constructor
|
|
5144
|
-
* @param {bitArray} key the key for HMAC.
|
|
5145
|
-
* @param {Object} [Hash=hash.sha1] The hash function to use.
|
|
5146
4911
|
*/
|
|
5147
|
-
|
|
4912
|
+
hash.sha1 = function (hash) {
|
|
4913
|
+
if (hash) {
|
|
4914
|
+
this._h = hash._h.slice(0);
|
|
4915
|
+
this._buffer = hash._buffer.slice(0);
|
|
4916
|
+
this._length = hash._length;
|
|
4917
|
+
} else {
|
|
4918
|
+
this.reset();
|
|
4919
|
+
}
|
|
4920
|
+
};
|
|
5148
4921
|
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
4922
|
+
hash.sha1.prototype = {
|
|
4923
|
+
/**
|
|
4924
|
+
* The hash's block size, in bits.
|
|
4925
|
+
* @constant
|
|
4926
|
+
*/
|
|
4927
|
+
blockSize: 512,
|
|
5155
4928
|
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
4929
|
+
/**
|
|
4930
|
+
* Reset the hash state.
|
|
4931
|
+
* @return this
|
|
4932
|
+
*/
|
|
4933
|
+
reset() {
|
|
4934
|
+
const sha1 = this;
|
|
4935
|
+
sha1._h = this._init.slice(0);
|
|
4936
|
+
sha1._buffer = [];
|
|
4937
|
+
sha1._length = 0;
|
|
4938
|
+
return sha1;
|
|
4939
|
+
},
|
|
5159
4940
|
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
4941
|
+
/**
|
|
4942
|
+
* Input several words to the hash.
|
|
4943
|
+
* @param {bitArray|String} data the data to hash.
|
|
4944
|
+
* @return this
|
|
4945
|
+
*/
|
|
4946
|
+
update(data) {
|
|
4947
|
+
const sha1 = this;
|
|
4948
|
+
if (typeof data === "string") {
|
|
4949
|
+
data = codec.utf8String.toBits(data);
|
|
4950
|
+
}
|
|
4951
|
+
const b = sha1._buffer = bitArray.concat(sha1._buffer, data);
|
|
4952
|
+
const ol = sha1._length;
|
|
4953
|
+
const nl = sha1._length = ol + bitArray.bitLength(data);
|
|
4954
|
+
if (nl > 9007199254740991) {
|
|
4955
|
+
throw new Error("Cannot hash more than 2^53 - 1 bits");
|
|
4956
|
+
}
|
|
4957
|
+
const c = new Uint32Array(b);
|
|
4958
|
+
let j = 0;
|
|
4959
|
+
for (let i = sha1.blockSize + ol - ((sha1.blockSize + ol) & (sha1.blockSize - 1)); i <= nl;
|
|
4960
|
+
i += sha1.blockSize) {
|
|
4961
|
+
sha1._block(c.subarray(16 * j, 16 * (j + 1)));
|
|
4962
|
+
j += 1;
|
|
5163
4963
|
}
|
|
4964
|
+
b.splice(0, 16 * j);
|
|
4965
|
+
return sha1;
|
|
4966
|
+
},
|
|
5164
4967
|
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
const
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
}
|
|
4968
|
+
/**
|
|
4969
|
+
* Complete hashing and output the hash value.
|
|
4970
|
+
* @return {bitArray} The hash value, an array of 5 big-endian words. TODO
|
|
4971
|
+
*/
|
|
4972
|
+
finalize() {
|
|
4973
|
+
const sha1 = this;
|
|
4974
|
+
let b = sha1._buffer;
|
|
4975
|
+
const h = sha1._h;
|
|
5174
4976
|
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
4977
|
+
// Round out and push the buffer
|
|
4978
|
+
b = bitArray.concat(b, [bitArray.partial(1, 1)]);
|
|
4979
|
+
// Round out the buffer to a multiple of 16 words, less the 2 length words.
|
|
4980
|
+
for (let i = b.length + 2; i & 15; i++) {
|
|
4981
|
+
b.push(0);
|
|
4982
|
+
}
|
|
5180
4983
|
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
const result = new (hmac._hash)(hmac._baseHash[1]).update(w).finalize();
|
|
4984
|
+
// append the length
|
|
4985
|
+
b.push(Math.floor(sha1._length / 0x100000000));
|
|
4986
|
+
b.push(sha1._length | 0);
|
|
5185
4987
|
|
|
5186
|
-
|
|
4988
|
+
while (b.length) {
|
|
4989
|
+
sha1._block(b.splice(0, 16));
|
|
4990
|
+
}
|
|
5187
4991
|
|
|
5188
|
-
|
|
5189
|
-
|
|
4992
|
+
sha1.reset();
|
|
4993
|
+
return h;
|
|
4994
|
+
},
|
|
5190
4995
|
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
4996
|
+
/**
|
|
4997
|
+
* The SHA-1 initialization vector.
|
|
4998
|
+
* @private
|
|
4999
|
+
*/
|
|
5000
|
+
_init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],
|
|
5001
|
+
|
|
5002
|
+
/**
|
|
5003
|
+
* The SHA-1 hash key.
|
|
5004
|
+
* @private
|
|
5005
|
+
*/
|
|
5006
|
+
_key: [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6],
|
|
5007
|
+
|
|
5008
|
+
/**
|
|
5009
|
+
* The SHA-1 logical functions f(0), f(1), ..., f(79).
|
|
5010
|
+
* @private
|
|
5011
|
+
*/
|
|
5012
|
+
_f(t, b, c, d) {
|
|
5013
|
+
if (t <= 19) {
|
|
5014
|
+
return (b & c) | (~b & d);
|
|
5015
|
+
} else if (t <= 39) {
|
|
5016
|
+
return b ^ c ^ d;
|
|
5017
|
+
} else if (t <= 59) {
|
|
5018
|
+
return (b & c) | (b & d) | (c & d);
|
|
5019
|
+
} else if (t <= 79) {
|
|
5020
|
+
return b ^ c ^ d;
|
|
5197
5021
|
}
|
|
5198
|
-
}
|
|
5199
|
-
};
|
|
5022
|
+
},
|
|
5200
5023
|
|
|
5201
|
-
|
|
5202
|
-
|
|
5024
|
+
/**
|
|
5025
|
+
* Circular left-shift operator.
|
|
5026
|
+
* @private
|
|
5027
|
+
*/
|
|
5028
|
+
_S(n, x) {
|
|
5029
|
+
return (x << n) | (x >>> 32 - n);
|
|
5030
|
+
},
|
|
5203
5031
|
|
|
5204
|
-
|
|
5205
|
-
|
|
5032
|
+
/**
|
|
5033
|
+
* Perform one cycle of SHA-1.
|
|
5034
|
+
* @param {Uint32Array|bitArray} words one block of words.
|
|
5035
|
+
* @private
|
|
5036
|
+
*/
|
|
5037
|
+
_block(words) {
|
|
5038
|
+
const sha1 = this;
|
|
5039
|
+
const h = sha1._h;
|
|
5040
|
+
// When words is passed to _block, it has 16 elements. SHA1 _block
|
|
5041
|
+
// function extends words with new elements (at the end there are 80 elements).
|
|
5042
|
+
// The problem is that if we use Uint32Array instead of Array,
|
|
5043
|
+
// the length of Uint32Array cannot be changed. Thus, we replace words with a
|
|
5044
|
+
// normal Array here.
|
|
5045
|
+
const w = Array(80); // do not use Uint32Array here as the instantiation is slower
|
|
5046
|
+
for (let j = 0; j < 16; j++) {
|
|
5047
|
+
w[j] = words[j];
|
|
5048
|
+
}
|
|
5206
5049
|
|
|
5207
|
-
|
|
5208
|
-
|
|
5050
|
+
let a = h[0];
|
|
5051
|
+
let b = h[1];
|
|
5052
|
+
let c = h[2];
|
|
5053
|
+
let d = h[3];
|
|
5054
|
+
let e = h[4];
|
|
5209
5055
|
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5056
|
+
for (let t = 0; t <= 79; t++) {
|
|
5057
|
+
if (t >= 16) {
|
|
5058
|
+
w[t] = sha1._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
|
|
5059
|
+
}
|
|
5060
|
+
const tmp = (sha1._S(5, a) + sha1._f(t, b, c, d) + e + w[t] +
|
|
5061
|
+
sha1._key[Math.floor(t / 20)]) | 0;
|
|
5062
|
+
e = d;
|
|
5063
|
+
d = c;
|
|
5064
|
+
c = sha1._S(30, b);
|
|
5065
|
+
b = a;
|
|
5066
|
+
a = tmp;
|
|
5067
|
+
}
|
|
5213
5068
|
|
|
5214
|
-
|
|
5215
|
-
|
|
5069
|
+
h[0] = (h[0] + a) | 0;
|
|
5070
|
+
h[1] = (h[1] + b) | 0;
|
|
5071
|
+
h[2] = (h[2] + c) | 0;
|
|
5072
|
+
h[3] = (h[3] + d) | 0;
|
|
5073
|
+
h[4] = (h[4] + e) | 0;
|
|
5074
|
+
}
|
|
5075
|
+
};
|
|
5216
5076
|
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5077
|
+
/** @fileOverview Low-level AES implementation.
|
|
5078
|
+
*
|
|
5079
|
+
* This file contains a low-level implementation of AES, optimized for
|
|
5080
|
+
* size and for efficiency on several browsers. It is based on
|
|
5081
|
+
* OpenSSL's aes_core.c, a public-domain implementation by Vincent
|
|
5082
|
+
* Rijmen, Antoon Bosselaers and Paulo Barreto.
|
|
5083
|
+
*
|
|
5084
|
+
* An older version of this implementation is available in the public
|
|
5085
|
+
* domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,
|
|
5086
|
+
* Stanford University 2008-2010 and BSD-licensed for liability
|
|
5087
|
+
* reasons.
|
|
5088
|
+
*
|
|
5089
|
+
* @author Emily Stark
|
|
5090
|
+
* @author Mike Hamburg
|
|
5091
|
+
* @author Dan Boneh
|
|
5227
5092
|
*/
|
|
5228
5093
|
|
|
5229
|
-
|
|
5094
|
+
const cipher = {};
|
|
5230
5095
|
|
|
5231
|
-
|
|
5096
|
+
/**
|
|
5097
|
+
* Schedule out an AES key for both encryption and decryption. This
|
|
5098
|
+
* is a low-level class. Use a cipher mode to do bulk encryption.
|
|
5099
|
+
*
|
|
5100
|
+
* @constructor
|
|
5101
|
+
* @param {Array} key The key as an array of 4, 6 or 8 words.
|
|
5102
|
+
*/
|
|
5103
|
+
cipher.aes = class {
|
|
5104
|
+
constructor(key) {
|
|
5105
|
+
/**
|
|
5106
|
+
* The expanded S-box and inverse S-box tables. These will be computed
|
|
5107
|
+
* on the client so that we don't have to send them down the wire.
|
|
5108
|
+
*
|
|
5109
|
+
* There are two tables, _tables[0] is for encryption and
|
|
5110
|
+
* _tables[1] is for decryption.
|
|
5111
|
+
*
|
|
5112
|
+
* The first 4 sub-tables are the expanded S-box with MixColumns. The
|
|
5113
|
+
* last (_tables[01][4]) is the S-box itself.
|
|
5114
|
+
*
|
|
5115
|
+
* @private
|
|
5116
|
+
*/
|
|
5117
|
+
const aes = this;
|
|
5118
|
+
aes._tables = [[[], [], [], [], []], [[], [], [], [], []]];
|
|
5232
5119
|
|
|
5233
|
-
|
|
5234
|
-
|
|
5120
|
+
if (!aes._tables[0][0][0]) {
|
|
5121
|
+
aes._precompute();
|
|
5122
|
+
}
|
|
5235
5123
|
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
} else {
|
|
5240
|
-
return random.getRandomValues(array);
|
|
5241
|
-
}
|
|
5242
|
-
}
|
|
5124
|
+
const sbox = aes._tables[0][4];
|
|
5125
|
+
const decTable = aes._tables[1];
|
|
5126
|
+
const keyLen = key.length;
|
|
5243
5127
|
|
|
5244
|
-
|
|
5245
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
5128
|
+
let i, encKey, decKey, rcon = 1;
|
|
5246
5129
|
|
|
5247
|
-
|
|
5248
|
-
|
|
5130
|
+
if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
|
|
5131
|
+
throw new Error("invalid aes key size");
|
|
5132
|
+
}
|
|
5249
5133
|
|
|
5250
|
-
|
|
5251
|
-
this list of conditions and the following disclaimer.
|
|
5134
|
+
aes._key = [encKey = key.slice(0), decKey = []];
|
|
5252
5135
|
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5136
|
+
// schedule encryption keys
|
|
5137
|
+
for (i = keyLen; i < 4 * keyLen + 28; i++) {
|
|
5138
|
+
let tmp = encKey[i - 1];
|
|
5256
5139
|
|
|
5257
|
-
|
|
5258
|
-
|
|
5140
|
+
// apply sbox
|
|
5141
|
+
if (i % keyLen === 0 || (keyLen === 8 && i % keyLen === 4)) {
|
|
5142
|
+
tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
|
|
5259
5143
|
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
5267
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
5268
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
5269
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
5270
|
-
*/
|
|
5144
|
+
// shift rows and add rcon
|
|
5145
|
+
if (i % keyLen === 0) {
|
|
5146
|
+
tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
|
|
5147
|
+
rcon = rcon << 1 ^ (rcon >> 7) * 283;
|
|
5148
|
+
}
|
|
5149
|
+
}
|
|
5271
5150
|
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
const PBKDF2_ALGORITHM = { name: "PBKDF2" };
|
|
5275
|
-
const HASH_ALGORITHM = { name: "HMAC" };
|
|
5276
|
-
const HASH_FUNCTION = "SHA-1";
|
|
5277
|
-
const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
|
|
5278
|
-
const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
|
|
5279
|
-
const DERIVED_BITS_USAGE = ["deriveBits"];
|
|
5280
|
-
const SALT_LENGTH = [8, 12, 16];
|
|
5281
|
-
const KEY_LENGTH = [16, 24, 32];
|
|
5282
|
-
const SIGNATURE_LENGTH = 10;
|
|
5283
|
-
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
5284
|
-
const UNDEFINED_TYPE = "undefined";
|
|
5285
|
-
const FUNCTION_TYPE = "function";
|
|
5286
|
-
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
|
|
5287
|
-
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
5288
|
-
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE;
|
|
5289
|
-
const IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
|
|
5290
|
-
const DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
|
|
5291
|
-
const codecBytes = codec.bytes;
|
|
5292
|
-
const Aes = cipher.aes;
|
|
5293
|
-
const CtrGladman = mode.ctrGladman;
|
|
5294
|
-
const HmacSha1 = misc.hmacSha1;
|
|
5151
|
+
encKey[i] = encKey[i - keyLen] ^ tmp;
|
|
5152
|
+
}
|
|
5295
5153
|
|
|
5296
|
-
|
|
5154
|
+
// schedule decryption keys
|
|
5155
|
+
for (let j = 0; i; j++, i--) {
|
|
5156
|
+
const tmp = encKey[j & 3 ? i : i - 4];
|
|
5157
|
+
if (i <= 4 || j < 4) {
|
|
5158
|
+
decKey[j] = tmp;
|
|
5159
|
+
} else {
|
|
5160
|
+
decKey[j] = decTable[0][sbox[tmp >>> 24]] ^
|
|
5161
|
+
decTable[1][sbox[tmp >> 16 & 255]] ^
|
|
5162
|
+
decTable[2][sbox[tmp >> 8 & 255]] ^
|
|
5163
|
+
decTable[3][sbox[tmp & 255]];
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
}
|
|
5167
|
+
// public
|
|
5168
|
+
/* Something like this might appear here eventually
|
|
5169
|
+
name: "AES",
|
|
5170
|
+
blockSize: 4,
|
|
5171
|
+
keySizes: [4,6,8],
|
|
5172
|
+
*/
|
|
5297
5173
|
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
strength: strength - 1,
|
|
5306
|
-
pending: new Uint8Array()
|
|
5307
|
-
});
|
|
5308
|
-
},
|
|
5309
|
-
async transform(chunk, controller) {
|
|
5310
|
-
const aesCrypto = this;
|
|
5311
|
-
const {
|
|
5312
|
-
password,
|
|
5313
|
-
strength,
|
|
5314
|
-
resolveReady,
|
|
5315
|
-
ready
|
|
5316
|
-
} = aesCrypto;
|
|
5317
|
-
if (password) {
|
|
5318
|
-
await createDecryptionKeys(aesCrypto, strength, password, subarray(chunk, 0, SALT_LENGTH[strength] + 2));
|
|
5319
|
-
chunk = subarray(chunk, SALT_LENGTH[strength] + 2);
|
|
5320
|
-
resolveReady();
|
|
5321
|
-
} else {
|
|
5322
|
-
await ready;
|
|
5323
|
-
}
|
|
5324
|
-
const output = new Uint8Array(chunk.length - SIGNATURE_LENGTH - ((chunk.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
|
|
5325
|
-
controller.enqueue(append(aesCrypto, chunk, output, 0, SIGNATURE_LENGTH, true));
|
|
5326
|
-
},
|
|
5327
|
-
async flush(controller) {
|
|
5328
|
-
const {
|
|
5329
|
-
signed,
|
|
5330
|
-
ctr,
|
|
5331
|
-
hmac,
|
|
5332
|
-
pending,
|
|
5333
|
-
ready
|
|
5334
|
-
} = this;
|
|
5335
|
-
await ready;
|
|
5336
|
-
const chunkToDecrypt = subarray(pending, 0, pending.length - SIGNATURE_LENGTH);
|
|
5337
|
-
const originalSignature = subarray(pending, pending.length - SIGNATURE_LENGTH);
|
|
5338
|
-
let decryptedChunkArray = new Uint8Array();
|
|
5339
|
-
if (chunkToDecrypt.length) {
|
|
5340
|
-
const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
|
|
5341
|
-
hmac.update(encryptedChunk);
|
|
5342
|
-
const decryptedChunk = ctr.update(encryptedChunk);
|
|
5343
|
-
decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
|
|
5344
|
-
}
|
|
5345
|
-
if (signed) {
|
|
5346
|
-
const signature = subarray(fromBits(codecBytes, hmac.digest()), 0, SIGNATURE_LENGTH);
|
|
5347
|
-
for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
|
|
5348
|
-
if (signature[indexSignature] != originalSignature[indexSignature]) {
|
|
5349
|
-
throw new Error(ERR_INVALID_SIGNATURE);
|
|
5350
|
-
}
|
|
5351
|
-
}
|
|
5352
|
-
}
|
|
5353
|
-
controller.enqueue(decryptedChunkArray);
|
|
5354
|
-
}
|
|
5355
|
-
});
|
|
5174
|
+
/**
|
|
5175
|
+
* Encrypt an array of 4 big-endian words.
|
|
5176
|
+
* @param {Array} data The plaintext.
|
|
5177
|
+
* @return {Array} The ciphertext.
|
|
5178
|
+
*/
|
|
5179
|
+
encrypt(data) {
|
|
5180
|
+
return this._crypt(data, 0);
|
|
5356
5181
|
}
|
|
5357
|
-
}
|
|
5358
5182
|
|
|
5359
|
-
|
|
5183
|
+
/**
|
|
5184
|
+
* Decrypt an array of 4 big-endian words.
|
|
5185
|
+
* @param {Array} data The ciphertext.
|
|
5186
|
+
* @return {Array} The plaintext.
|
|
5187
|
+
*/
|
|
5188
|
+
decrypt(data) {
|
|
5189
|
+
return this._crypt(data, 1);
|
|
5190
|
+
}
|
|
5360
5191
|
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
pending,
|
|
5396
|
-
ready
|
|
5397
|
-
} = this;
|
|
5398
|
-
await ready;
|
|
5399
|
-
let encryptedChunkArray = new Uint8Array();
|
|
5400
|
-
if (pending.length) {
|
|
5401
|
-
const encryptedChunk = ctr.update(toBits(codecBytes, pending));
|
|
5402
|
-
hmac.update(encryptedChunk);
|
|
5403
|
-
encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
|
|
5404
|
-
}
|
|
5405
|
-
stream.signature = fromBits(codecBytes, hmac.digest()).slice(0, SIGNATURE_LENGTH);
|
|
5406
|
-
controller.enqueue(concat(encryptedChunkArray, stream.signature));
|
|
5192
|
+
/**
|
|
5193
|
+
* Expand the S-box tables.
|
|
5194
|
+
*
|
|
5195
|
+
* @private
|
|
5196
|
+
*/
|
|
5197
|
+
_precompute() {
|
|
5198
|
+
const encTable = this._tables[0];
|
|
5199
|
+
const decTable = this._tables[1];
|
|
5200
|
+
const sbox = encTable[4];
|
|
5201
|
+
const sboxInv = decTable[4];
|
|
5202
|
+
const d = [];
|
|
5203
|
+
const th = [];
|
|
5204
|
+
let xInv, x2, x4, x8;
|
|
5205
|
+
|
|
5206
|
+
// Compute double and third tables
|
|
5207
|
+
for (let i = 0; i < 256; i++) {
|
|
5208
|
+
th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
|
|
5209
|
+
}
|
|
5210
|
+
|
|
5211
|
+
for (let x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
|
|
5212
|
+
// Compute sbox
|
|
5213
|
+
let s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
|
|
5214
|
+
s = s >> 8 ^ s & 255 ^ 99;
|
|
5215
|
+
sbox[x] = s;
|
|
5216
|
+
sboxInv[s] = x;
|
|
5217
|
+
|
|
5218
|
+
// Compute MixColumns
|
|
5219
|
+
x8 = d[x4 = d[x2 = d[x]]];
|
|
5220
|
+
let tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
|
|
5221
|
+
let tEnc = d[s] * 0x101 ^ s * 0x1010100;
|
|
5222
|
+
|
|
5223
|
+
for (let i = 0; i < 4; i++) {
|
|
5224
|
+
encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
|
|
5225
|
+
decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
|
|
5407
5226
|
}
|
|
5408
|
-
}
|
|
5409
|
-
stream = this;
|
|
5410
|
-
}
|
|
5411
|
-
}
|
|
5227
|
+
}
|
|
5412
5228
|
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
} = aesCrypto;
|
|
5419
|
-
const inputLength = input.length - paddingEnd;
|
|
5420
|
-
if (pending.length) {
|
|
5421
|
-
input = concat(pending, input);
|
|
5422
|
-
output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
|
|
5229
|
+
// Compactify. Considerable speedup on Firefox.
|
|
5230
|
+
for (let i = 0; i < 5; i++) {
|
|
5231
|
+
encTable[i] = encTable[i].slice(0);
|
|
5232
|
+
decTable[i] = decTable[i].slice(0);
|
|
5233
|
+
}
|
|
5423
5234
|
}
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5235
|
+
|
|
5236
|
+
/**
|
|
5237
|
+
* Encryption and decryption core.
|
|
5238
|
+
* @param {Array} input Four words to be encrypted or decrypted.
|
|
5239
|
+
* @param dir The direction, 0 for encrypt and 1 for decrypt.
|
|
5240
|
+
* @return {Array} The four encrypted or decrypted words.
|
|
5241
|
+
* @private
|
|
5242
|
+
*/
|
|
5243
|
+
_crypt(input, dir) {
|
|
5244
|
+
if (input.length !== 4) {
|
|
5245
|
+
throw new Error("invalid aes block size");
|
|
5429
5246
|
}
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5247
|
+
|
|
5248
|
+
const key = this._key[dir];
|
|
5249
|
+
|
|
5250
|
+
const nInnerRounds = key.length / 4 - 2;
|
|
5251
|
+
const out = [0, 0, 0, 0];
|
|
5252
|
+
const table = this._tables[dir];
|
|
5253
|
+
|
|
5254
|
+
// load up the tables
|
|
5255
|
+
const t0 = table[0];
|
|
5256
|
+
const t1 = table[1];
|
|
5257
|
+
const t2 = table[2];
|
|
5258
|
+
const t3 = table[3];
|
|
5259
|
+
const sbox = table[4];
|
|
5260
|
+
|
|
5261
|
+
// state variables a,b,c,d are loaded with pre-whitened data
|
|
5262
|
+
let a = input[0] ^ key[0];
|
|
5263
|
+
let b = input[dir ? 3 : 1] ^ key[1];
|
|
5264
|
+
let c = input[2] ^ key[2];
|
|
5265
|
+
let d = input[dir ? 1 : 3] ^ key[3];
|
|
5266
|
+
let kIndex = 4;
|
|
5267
|
+
let a2, b2, c2;
|
|
5268
|
+
|
|
5269
|
+
// Inner rounds. Cribbed from OpenSSL.
|
|
5270
|
+
for (let i = 0; i < nInnerRounds; i++) {
|
|
5271
|
+
a2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];
|
|
5272
|
+
b2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];
|
|
5273
|
+
c2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];
|
|
5274
|
+
d = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];
|
|
5275
|
+
kIndex += 4;
|
|
5276
|
+
a = a2; b = b2; c = c2;
|
|
5433
5277
|
}
|
|
5434
|
-
|
|
5278
|
+
|
|
5279
|
+
// Last round.
|
|
5280
|
+
for (let i = 0; i < 4; i++) {
|
|
5281
|
+
out[dir ? 3 & -i : i] =
|
|
5282
|
+
sbox[a >>> 24] << 24 ^
|
|
5283
|
+
sbox[b >> 16 & 255] << 16 ^
|
|
5284
|
+
sbox[c >> 8 & 255] << 8 ^
|
|
5285
|
+
sbox[d & 255] ^
|
|
5286
|
+
key[kIndex++];
|
|
5287
|
+
a2 = a; a = b; b = c; c = d; d = a2;
|
|
5288
|
+
}
|
|
5289
|
+
|
|
5290
|
+
return out;
|
|
5435
5291
|
}
|
|
5436
|
-
|
|
5437
|
-
return output;
|
|
5438
|
-
}
|
|
5292
|
+
};
|
|
5439
5293
|
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5294
|
+
/**
|
|
5295
|
+
* Random values
|
|
5296
|
+
* @namespace
|
|
5297
|
+
*/
|
|
5298
|
+
const random = {
|
|
5299
|
+
/**
|
|
5300
|
+
* Generate random words with pure js, cryptographically not as strong & safe as native implementation.
|
|
5301
|
+
* @param {TypedArray} typedArray The array to fill.
|
|
5302
|
+
* @return {TypedArray} The random values.
|
|
5303
|
+
*/
|
|
5304
|
+
getRandomValues(typedArray) {
|
|
5305
|
+
const words = new Uint32Array(typedArray.buffer);
|
|
5306
|
+
const r = (m_w) => {
|
|
5307
|
+
let m_z = 0x3ade68b1;
|
|
5308
|
+
const mask = 0xffffffff;
|
|
5309
|
+
return function () {
|
|
5310
|
+
m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
|
|
5311
|
+
m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
|
|
5312
|
+
const result = ((((m_z << 0x10) + m_w) & mask) / 0x100000000) + .5;
|
|
5313
|
+
return result * (Math.random() > .5 ? 1 : -1);
|
|
5314
|
+
};
|
|
5315
|
+
};
|
|
5316
|
+
for (let i = 0, rcache; i < typedArray.length; i += 4) {
|
|
5317
|
+
const _r = r((rcache || Math.random()) * 0x100000000);
|
|
5318
|
+
rcache = _r() * 0x3ade67b7;
|
|
5319
|
+
words[i / 4] = (_r() * 0x100000000) | 0;
|
|
5320
|
+
}
|
|
5321
|
+
return typedArray;
|
|
5445
5322
|
}
|
|
5446
|
-
}
|
|
5323
|
+
};
|
|
5447
5324
|
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5325
|
+
/** @fileOverview CTR mode implementation.
|
|
5326
|
+
*
|
|
5327
|
+
* Special thanks to Roy Nicholson for pointing out a bug in our
|
|
5328
|
+
* implementation.
|
|
5329
|
+
*
|
|
5330
|
+
* @author Emily Stark
|
|
5331
|
+
* @author Mike Hamburg
|
|
5332
|
+
* @author Dan Boneh
|
|
5333
|
+
*/
|
|
5453
5334
|
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
const compositeKey = new Uint8Array(derivedBits);
|
|
5460
|
-
const key = toBits(codecBytes, subarray(compositeKey, 0, KEY_LENGTH[strength]));
|
|
5461
|
-
const authentication = toBits(codecBytes, subarray(compositeKey, KEY_LENGTH[strength], KEY_LENGTH[strength] * 2));
|
|
5462
|
-
const passwordVerification = subarray(compositeKey, KEY_LENGTH[strength] * 2);
|
|
5463
|
-
Object.assign(aesCrypto, {
|
|
5464
|
-
keys: {
|
|
5465
|
-
key,
|
|
5466
|
-
authentication,
|
|
5467
|
-
passwordVerification
|
|
5468
|
-
},
|
|
5469
|
-
ctr: new CtrGladman(new Aes(key), Array.from(COUNTER_DEFAULT_VALUE)),
|
|
5470
|
-
hmac: new HmacSha1(authentication)
|
|
5471
|
-
});
|
|
5472
|
-
return passwordVerification;
|
|
5473
|
-
}
|
|
5335
|
+
/** Brian Gladman's CTR Mode.
|
|
5336
|
+
* @constructor
|
|
5337
|
+
* @param {Object} _prf The aes instance to generate key.
|
|
5338
|
+
* @param {bitArray} _iv The iv for ctr mode, it must be 128 bits.
|
|
5339
|
+
*/
|
|
5474
5340
|
|
|
5475
|
-
|
|
5476
|
-
if (IMPORT_KEY_SUPPORTED) {
|
|
5477
|
-
return subtle.importKey(format, password, algorithm, extractable, keyUsages);
|
|
5478
|
-
} else {
|
|
5479
|
-
return misc.importKey(password);
|
|
5480
|
-
}
|
|
5481
|
-
}
|
|
5341
|
+
const mode = {};
|
|
5482
5342
|
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5343
|
+
/**
|
|
5344
|
+
* Brian Gladman's CTR Mode.
|
|
5345
|
+
* @namespace
|
|
5346
|
+
*/
|
|
5347
|
+
mode.ctrGladman = class {
|
|
5348
|
+
constructor(prf, iv) {
|
|
5349
|
+
this._prf = prf;
|
|
5350
|
+
this._initIv = iv;
|
|
5351
|
+
this._iv = iv;
|
|
5488
5352
|
}
|
|
5489
|
-
}
|
|
5490
5353
|
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
if (leftArray.length + rightArray.length) {
|
|
5494
|
-
array = new Uint8Array(leftArray.length + rightArray.length);
|
|
5495
|
-
array.set(leftArray, 0);
|
|
5496
|
-
array.set(rightArray, leftArray.length);
|
|
5354
|
+
reset() {
|
|
5355
|
+
this._iv = this._initIv;
|
|
5497
5356
|
}
|
|
5498
|
-
return array;
|
|
5499
|
-
}
|
|
5500
5357
|
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5358
|
+
/** Input some data to calculate.
|
|
5359
|
+
* @param {bitArray} data the data to process, it must be intergral multiple of 128 bits unless it's the last.
|
|
5360
|
+
*/
|
|
5361
|
+
update(data) {
|
|
5362
|
+
return this.calculate(this._prf, data, this._iv);
|
|
5506
5363
|
}
|
|
5507
|
-
return inputArray;
|
|
5508
|
-
}
|
|
5509
|
-
|
|
5510
|
-
function subarray(array, begin, end) {
|
|
5511
|
-
return array.subarray(begin, end);
|
|
5512
|
-
}
|
|
5513
5364
|
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
}
|
|
5365
|
+
incWord(word) {
|
|
5366
|
+
if (((word >> 24) & 0xff) === 0xff) { //overflow
|
|
5367
|
+
let b1 = (word >> 16) & 0xff;
|
|
5368
|
+
let b2 = (word >> 8) & 0xff;
|
|
5369
|
+
let b3 = word & 0xff;
|
|
5520
5370
|
|
|
5521
|
-
|
|
5522
|
-
|
|
5371
|
+
if (b1 === 0xff) { // overflow b1
|
|
5372
|
+
b1 = 0;
|
|
5373
|
+
if (b2 === 0xff) {
|
|
5374
|
+
b2 = 0;
|
|
5375
|
+
if (b3 === 0xff) {
|
|
5376
|
+
b3 = 0;
|
|
5377
|
+
} else {
|
|
5378
|
+
++b3;
|
|
5379
|
+
}
|
|
5380
|
+
} else {
|
|
5381
|
+
++b2;
|
|
5382
|
+
}
|
|
5383
|
+
} else {
|
|
5384
|
+
++b1;
|
|
5385
|
+
}
|
|
5523
5386
|
|
|
5524
|
-
|
|
5525
|
-
|
|
5387
|
+
word = 0;
|
|
5388
|
+
word += (b1 << 16);
|
|
5389
|
+
word += (b2 << 8);
|
|
5390
|
+
word += b3;
|
|
5391
|
+
} else {
|
|
5392
|
+
word += (0x01 << 24);
|
|
5393
|
+
}
|
|
5394
|
+
return word;
|
|
5395
|
+
}
|
|
5526
5396
|
|
|
5527
|
-
|
|
5528
|
-
|
|
5397
|
+
incCounter(counter) {
|
|
5398
|
+
if ((counter[0] = this.incWord(counter[0])) === 0) {
|
|
5399
|
+
// encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
|
|
5400
|
+
counter[1] = this.incWord(counter[1]);
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5529
5403
|
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5404
|
+
calculate(prf, data, iv) {
|
|
5405
|
+
let l;
|
|
5406
|
+
if (!(l = data.length)) {
|
|
5407
|
+
return [];
|
|
5408
|
+
}
|
|
5409
|
+
const bl = bitArray.bitLength(data);
|
|
5410
|
+
for (let i = 0; i < l; i += 4) {
|
|
5411
|
+
this.incCounter(iv);
|
|
5412
|
+
const e = prf.encrypt(iv);
|
|
5413
|
+
data[i] ^= e[0];
|
|
5414
|
+
data[i + 1] ^= e[1];
|
|
5415
|
+
data[i + 2] ^= e[2];
|
|
5416
|
+
data[i + 3] ^= e[3];
|
|
5417
|
+
}
|
|
5418
|
+
return bitArray.clamp(data, bl);
|
|
5419
|
+
}
|
|
5420
|
+
};
|
|
5533
5421
|
|
|
5534
|
-
|
|
5535
|
-
|
|
5422
|
+
const misc = {
|
|
5423
|
+
importKey(password) {
|
|
5424
|
+
return new misc.hmacSha1(codec.bytes.toBits(password));
|
|
5425
|
+
},
|
|
5426
|
+
pbkdf2(prf, salt, count, length) {
|
|
5427
|
+
count = count || 10000;
|
|
5428
|
+
if (length < 0 || count < 0) {
|
|
5429
|
+
throw new Error("invalid params to pbkdf2");
|
|
5430
|
+
}
|
|
5431
|
+
const byteLength = ((length >> 5) + 1) << 2;
|
|
5432
|
+
let u, ui, i, j, k;
|
|
5433
|
+
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
5434
|
+
const out = new DataView(arrayBuffer);
|
|
5435
|
+
let outLength = 0;
|
|
5436
|
+
const b = bitArray;
|
|
5437
|
+
salt = codec.bytes.toBits(salt);
|
|
5438
|
+
for (k = 1; outLength < (byteLength || 1); k++) {
|
|
5439
|
+
u = ui = prf.encrypt(b.concat(salt, [k]));
|
|
5440
|
+
for (i = 1; i < count; i++) {
|
|
5441
|
+
ui = prf.encrypt(ui);
|
|
5442
|
+
for (j = 0; j < ui.length; j++) {
|
|
5443
|
+
u[j] ^= ui[j];
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
for (i = 0; outLength < (byteLength || 1) && i < u.length; i++) {
|
|
5447
|
+
out.setInt32(outLength, u[i]);
|
|
5448
|
+
outLength += 4;
|
|
5449
|
+
}
|
|
5450
|
+
}
|
|
5451
|
+
return arrayBuffer.slice(0, length / 8);
|
|
5452
|
+
}
|
|
5453
|
+
};
|
|
5536
5454
|
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
5543
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
5544
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
5545
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
5546
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
5455
|
+
/** @fileOverview HMAC implementation.
|
|
5456
|
+
*
|
|
5457
|
+
* @author Emily Stark
|
|
5458
|
+
* @author Mike Hamburg
|
|
5459
|
+
* @author Dan Boneh
|
|
5547
5460
|
*/
|
|
5548
5461
|
|
|
5549
|
-
|
|
5462
|
+
/** HMAC with the specified hash function.
|
|
5463
|
+
* @constructor
|
|
5464
|
+
* @param {bitArray} key the key for HMAC.
|
|
5465
|
+
* @param {Object} [Hash=hash.sha1] The hash function to use.
|
|
5466
|
+
*/
|
|
5467
|
+
misc.hmacSha1 = class {
|
|
5550
5468
|
|
|
5551
|
-
|
|
5469
|
+
constructor(key) {
|
|
5470
|
+
const hmac = this;
|
|
5471
|
+
const Hash = hmac._hash = hash.sha1;
|
|
5472
|
+
const exKey = [[], []];
|
|
5473
|
+
const bs = Hash.prototype.blockSize / 32;
|
|
5474
|
+
hmac._baseHash = [new Hash(), new Hash()];
|
|
5552
5475
|
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
Object.assign(this, {
|
|
5557
|
-
password,
|
|
5558
|
-
passwordVerification
|
|
5559
|
-
});
|
|
5560
|
-
createKeys(this, password);
|
|
5561
|
-
},
|
|
5562
|
-
transform(chunk, controller) {
|
|
5563
|
-
const zipCrypto = this;
|
|
5564
|
-
if (zipCrypto.password) {
|
|
5565
|
-
const decryptedHeader = decrypt(zipCrypto, chunk.subarray(0, HEADER_LENGTH));
|
|
5566
|
-
zipCrypto.password = null;
|
|
5567
|
-
if (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {
|
|
5568
|
-
throw new Error(ERR_INVALID_PASSWORD);
|
|
5569
|
-
}
|
|
5570
|
-
chunk = chunk.subarray(HEADER_LENGTH);
|
|
5571
|
-
}
|
|
5572
|
-
controller.enqueue(decrypt(zipCrypto, chunk));
|
|
5573
|
-
}
|
|
5574
|
-
});
|
|
5575
|
-
}
|
|
5576
|
-
}
|
|
5476
|
+
if (key.length > bs) {
|
|
5477
|
+
key = Hash.hash(key);
|
|
5478
|
+
}
|
|
5577
5479
|
|
|
5578
|
-
|
|
5480
|
+
for (let i = 0; i < bs; i++) {
|
|
5481
|
+
exKey[0][i] = key[i] ^ 0x36363636;
|
|
5482
|
+
exKey[1][i] = key[i] ^ 0x5C5C5C5C;
|
|
5483
|
+
}
|
|
5579
5484
|
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
},
|
|
5589
|
-
transform(chunk, controller) {
|
|
5590
|
-
const zipCrypto = this;
|
|
5591
|
-
let output;
|
|
5592
|
-
let offset;
|
|
5593
|
-
if (zipCrypto.password) {
|
|
5594
|
-
zipCrypto.password = null;
|
|
5595
|
-
const header = getRandomValues(new Uint8Array(HEADER_LENGTH));
|
|
5596
|
-
header[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;
|
|
5597
|
-
output = new Uint8Array(chunk.length + header.length);
|
|
5598
|
-
output.set(encrypt(zipCrypto, header), 0);
|
|
5599
|
-
offset = HEADER_LENGTH;
|
|
5600
|
-
} else {
|
|
5601
|
-
output = new Uint8Array(chunk.length);
|
|
5602
|
-
offset = 0;
|
|
5603
|
-
}
|
|
5604
|
-
output.set(encrypt(zipCrypto, chunk), offset);
|
|
5605
|
-
controller.enqueue(output);
|
|
5606
|
-
}
|
|
5607
|
-
});
|
|
5485
|
+
hmac._baseHash[0].update(exKey[0]);
|
|
5486
|
+
hmac._baseHash[1].update(exKey[1]);
|
|
5487
|
+
hmac._resultHash = new Hash(hmac._baseHash[0]);
|
|
5488
|
+
}
|
|
5489
|
+
reset() {
|
|
5490
|
+
const hmac = this;
|
|
5491
|
+
hmac._resultHash = new hmac._hash(hmac._baseHash[0]);
|
|
5492
|
+
hmac._updated = false;
|
|
5608
5493
|
}
|
|
5609
|
-
}
|
|
5610
5494
|
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
updateKeys(target, output[index]);
|
|
5495
|
+
update(data) {
|
|
5496
|
+
const hmac = this;
|
|
5497
|
+
hmac._updated = true;
|
|
5498
|
+
hmac._resultHash.update(data);
|
|
5616
5499
|
}
|
|
5617
|
-
return output;
|
|
5618
|
-
}
|
|
5619
5500
|
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5501
|
+
digest() {
|
|
5502
|
+
const hmac = this;
|
|
5503
|
+
const w = hmac._resultHash.finalize();
|
|
5504
|
+
const result = new (hmac._hash)(hmac._baseHash[1]).update(w).finalize();
|
|
5505
|
+
|
|
5506
|
+
hmac.reset();
|
|
5507
|
+
|
|
5508
|
+
return result;
|
|
5625
5509
|
}
|
|
5626
|
-
return output;
|
|
5627
|
-
}
|
|
5628
5510
|
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
for (let index = 0; index < password.length; index++) {
|
|
5637
|
-
updateKeys(target, password.charCodeAt(index));
|
|
5511
|
+
encrypt(data) {
|
|
5512
|
+
if (!this._updated) {
|
|
5513
|
+
this.update(data);
|
|
5514
|
+
return this.digest(data);
|
|
5515
|
+
} else {
|
|
5516
|
+
throw new Error("encrypt on already updated hmac called!");
|
|
5517
|
+
}
|
|
5638
5518
|
}
|
|
5639
|
-
}
|
|
5519
|
+
};
|
|
5640
5520
|
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
target.crcKey0.append([byte]);
|
|
5644
|
-
key0 = ~target.crcKey0.get();
|
|
5645
|
-
key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
|
|
5646
|
-
target.crcKey2.append([key1 >>> 24]);
|
|
5647
|
-
key2 = ~target.crcKey2.get();
|
|
5648
|
-
target.keys = [key0, key1, key2];
|
|
5649
|
-
}
|
|
5521
|
+
/*
|
|
5522
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
5650
5523
|
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
|
|
5654
|
-
}
|
|
5524
|
+
Redistribution and use in source and binary forms, with or without
|
|
5525
|
+
modification, are permitted provided that the following conditions are met:
|
|
5655
5526
|
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
}
|
|
5527
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
5528
|
+
this list of conditions and the following disclaimer.
|
|
5659
5529
|
|
|
5660
|
-
|
|
5661
|
-
|
|
5530
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
5531
|
+
notice, this list of conditions and the following disclaimer in
|
|
5532
|
+
the documentation and/or other materials provided with the distribution.
|
|
5533
|
+
|
|
5534
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
5535
|
+
derived from this software without specific prior written permission.
|
|
5536
|
+
|
|
5537
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
5538
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
5539
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
5540
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
5541
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
5542
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
5543
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
5544
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
5545
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
5546
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
5547
|
+
*/
|
|
5548
|
+
|
|
5549
|
+
/* global crypto */
|
|
5550
|
+
|
|
5551
|
+
const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != "undefined" && typeof crypto.getRandomValues == "function";
|
|
5552
|
+
|
|
5553
|
+
const ERR_INVALID_PASSWORD = "Invalid password";
|
|
5554
|
+
const ERR_INVALID_SIGNATURE = "Invalid signature";
|
|
5555
|
+
|
|
5556
|
+
function getRandomValues(array) {
|
|
5557
|
+
if (GET_RANDOM_VALUES_SUPPORTED) {
|
|
5558
|
+
return crypto.getRandomValues(array);
|
|
5559
|
+
} else {
|
|
5560
|
+
return random.getRandomValues(array);
|
|
5561
|
+
}
|
|
5662
5562
|
}
|
|
5663
5563
|
|
|
5664
5564
|
/*
|
|
@@ -5689,114 +5589,255 @@
|
|
|
5689
5589
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
5690
5590
|
*/
|
|
5691
5591
|
|
|
5692
|
-
const
|
|
5592
|
+
const BLOCK_LENGTH = 16;
|
|
5593
|
+
const RAW_FORMAT = "raw";
|
|
5594
|
+
const PBKDF2_ALGORITHM = { name: "PBKDF2" };
|
|
5595
|
+
const HASH_ALGORITHM = { name: "HMAC" };
|
|
5596
|
+
const HASH_FUNCTION = "SHA-1";
|
|
5597
|
+
const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
|
|
5598
|
+
const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
|
|
5599
|
+
const DERIVED_BITS_USAGE = ["deriveBits"];
|
|
5600
|
+
const SALT_LENGTH = [8, 12, 16];
|
|
5601
|
+
const KEY_LENGTH = [16, 24, 32];
|
|
5602
|
+
const SIGNATURE_LENGTH = 10;
|
|
5603
|
+
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
|
|
5604
|
+
const UNDEFINED_TYPE = "undefined";
|
|
5605
|
+
const FUNCTION_TYPE = "function";
|
|
5606
|
+
// deno-lint-ignore valid-typeof
|
|
5607
|
+
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
|
|
5608
|
+
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
|
|
5609
|
+
const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE;
|
|
5610
|
+
const IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
|
|
5611
|
+
const DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
|
|
5612
|
+
const codecBytes = codec.bytes;
|
|
5613
|
+
const Aes = cipher.aes;
|
|
5614
|
+
const CtrGladman = mode.ctrGladman;
|
|
5615
|
+
const HmacSha1 = misc.hmacSha1;
|
|
5693
5616
|
|
|
5694
|
-
class
|
|
5617
|
+
class AESDecryptionStream extends TransformStream {
|
|
5695
5618
|
|
|
5696
|
-
constructor(
|
|
5697
|
-
super({
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5619
|
+
constructor(password, signed, strength) {
|
|
5620
|
+
super({
|
|
5621
|
+
start() {
|
|
5622
|
+
Object.assign(this, {
|
|
5623
|
+
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
5624
|
+
password,
|
|
5625
|
+
signed,
|
|
5626
|
+
strength: strength - 1,
|
|
5627
|
+
pending: new Uint8Array()
|
|
5628
|
+
});
|
|
5629
|
+
},
|
|
5630
|
+
async transform(chunk, controller) {
|
|
5631
|
+
const aesCrypto = this;
|
|
5632
|
+
const {
|
|
5633
|
+
password,
|
|
5634
|
+
strength,
|
|
5635
|
+
resolveReady,
|
|
5636
|
+
ready
|
|
5637
|
+
} = aesCrypto;
|
|
5638
|
+
if (password) {
|
|
5639
|
+
await createDecryptionKeys(aesCrypto, strength, password, subarray(chunk, 0, SALT_LENGTH[strength] + 2));
|
|
5640
|
+
chunk = subarray(chunk, SALT_LENGTH[strength] + 2);
|
|
5641
|
+
resolveReady();
|
|
5642
|
+
} else {
|
|
5643
|
+
await ready;
|
|
5644
|
+
}
|
|
5645
|
+
const output = new Uint8Array(chunk.length - SIGNATURE_LENGTH - ((chunk.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
|
|
5646
|
+
controller.enqueue(append(aesCrypto, chunk, output, 0, SIGNATURE_LENGTH, true));
|
|
5647
|
+
},
|
|
5648
|
+
async flush(controller) {
|
|
5649
|
+
const {
|
|
5650
|
+
signed,
|
|
5651
|
+
ctr,
|
|
5652
|
+
hmac,
|
|
5653
|
+
pending,
|
|
5654
|
+
ready
|
|
5655
|
+
} = this;
|
|
5656
|
+
await ready;
|
|
5657
|
+
const chunkToDecrypt = subarray(pending, 0, pending.length - SIGNATURE_LENGTH);
|
|
5658
|
+
const originalSignature = subarray(pending, pending.length - SIGNATURE_LENGTH);
|
|
5659
|
+
let decryptedChunkArray = new Uint8Array();
|
|
5660
|
+
if (chunkToDecrypt.length) {
|
|
5661
|
+
const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
|
|
5662
|
+
hmac.update(encryptedChunk);
|
|
5663
|
+
const decryptedChunk = ctr.update(encryptedChunk);
|
|
5664
|
+
decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
|
|
5665
|
+
}
|
|
5666
|
+
if (signed) {
|
|
5667
|
+
const signature = subarray(fromBits(codecBytes, hmac.digest()), 0, SIGNATURE_LENGTH);
|
|
5668
|
+
for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
|
|
5669
|
+
if (signature[indexSignature] != originalSignature[indexSignature]) {
|
|
5670
|
+
throw new Error(ERR_INVALID_SIGNATURE);
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5673
|
+
}
|
|
5674
|
+
controller.enqueue(decryptedChunkArray);
|
|
5725
5675
|
}
|
|
5726
|
-
stream.signature = signature;
|
|
5727
5676
|
});
|
|
5728
5677
|
}
|
|
5729
5678
|
}
|
|
5730
5679
|
|
|
5731
|
-
class
|
|
5680
|
+
class AESEncryptionStream extends TransformStream {
|
|
5732
5681
|
|
|
5733
|
-
constructor(
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
}
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5682
|
+
constructor(password, strength) {
|
|
5683
|
+
// deno-lint-ignore prefer-const
|
|
5684
|
+
let stream;
|
|
5685
|
+
super({
|
|
5686
|
+
start() {
|
|
5687
|
+
Object.assign(this, {
|
|
5688
|
+
ready: new Promise(resolve => this.resolveReady = resolve),
|
|
5689
|
+
password,
|
|
5690
|
+
strength: strength - 1,
|
|
5691
|
+
pending: new Uint8Array()
|
|
5692
|
+
});
|
|
5693
|
+
},
|
|
5694
|
+
async transform(chunk, controller) {
|
|
5695
|
+
const aesCrypto = this;
|
|
5696
|
+
const {
|
|
5697
|
+
password,
|
|
5698
|
+
strength,
|
|
5699
|
+
resolveReady,
|
|
5700
|
+
ready
|
|
5701
|
+
} = aesCrypto;
|
|
5702
|
+
let preamble = new Uint8Array();
|
|
5703
|
+
if (password) {
|
|
5704
|
+
preamble = await createEncryptionKeys(aesCrypto, strength, password);
|
|
5705
|
+
resolveReady();
|
|
5706
|
+
} else {
|
|
5707
|
+
await ready;
|
|
5708
|
+
}
|
|
5709
|
+
const output = new Uint8Array(preamble.length + chunk.length - (chunk.length % BLOCK_LENGTH));
|
|
5710
|
+
output.set(preamble, 0);
|
|
5711
|
+
controller.enqueue(append(aesCrypto, chunk, output, preamble.length, 0));
|
|
5712
|
+
},
|
|
5713
|
+
async flush(controller) {
|
|
5714
|
+
const {
|
|
5715
|
+
ctr,
|
|
5716
|
+
hmac,
|
|
5717
|
+
pending,
|
|
5718
|
+
ready
|
|
5719
|
+
} = this;
|
|
5720
|
+
await ready;
|
|
5721
|
+
let encryptedChunkArray = new Uint8Array();
|
|
5722
|
+
if (pending.length) {
|
|
5723
|
+
const encryptedChunk = ctr.update(toBits(codecBytes, pending));
|
|
5724
|
+
hmac.update(encryptedChunk);
|
|
5725
|
+
encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
|
|
5759
5726
|
}
|
|
5727
|
+
stream.signature = fromBits(codecBytes, hmac.digest()).slice(0, SIGNATURE_LENGTH);
|
|
5728
|
+
controller.enqueue(concat(encryptedChunkArray, stream.signature));
|
|
5760
5729
|
}
|
|
5761
5730
|
});
|
|
5731
|
+
stream = this;
|
|
5762
5732
|
}
|
|
5763
5733
|
}
|
|
5764
5734
|
|
|
5765
|
-
function
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5735
|
+
function append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {
|
|
5736
|
+
const {
|
|
5737
|
+
ctr,
|
|
5738
|
+
hmac,
|
|
5739
|
+
pending
|
|
5740
|
+
} = aesCrypto;
|
|
5741
|
+
const inputLength = input.length - paddingEnd;
|
|
5742
|
+
if (pending.length) {
|
|
5743
|
+
input = concat(pending, input);
|
|
5744
|
+
output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
|
|
5745
|
+
}
|
|
5746
|
+
let offset;
|
|
5747
|
+
for (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {
|
|
5748
|
+
const inputChunk = toBits(codecBytes, subarray(input, offset, offset + BLOCK_LENGTH));
|
|
5749
|
+
if (verifySignature) {
|
|
5750
|
+
hmac.update(inputChunk);
|
|
5771
5751
|
}
|
|
5772
|
-
|
|
5752
|
+
const outputChunk = ctr.update(inputChunk);
|
|
5753
|
+
if (!verifySignature) {
|
|
5754
|
+
hmac.update(outputChunk);
|
|
5755
|
+
}
|
|
5756
|
+
output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
|
|
5757
|
+
}
|
|
5758
|
+
aesCrypto.pending = subarray(input, offset);
|
|
5759
|
+
return output;
|
|
5773
5760
|
}
|
|
5774
5761
|
|
|
5775
|
-
function
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5762
|
+
async function createDecryptionKeys(decrypt, strength, password, preamble) {
|
|
5763
|
+
const passwordVerificationKey = await createKeys$1(decrypt, strength, password, subarray(preamble, 0, SALT_LENGTH[strength]));
|
|
5764
|
+
const passwordVerification = subarray(preamble, SALT_LENGTH[strength]);
|
|
5765
|
+
if (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {
|
|
5766
|
+
throw new Error(ERR_INVALID_PASSWORD);
|
|
5767
|
+
}
|
|
5768
|
+
}
|
|
5769
|
+
|
|
5770
|
+
async function createEncryptionKeys(encrypt, strength, password) {
|
|
5771
|
+
const salt = getRandomValues(new Uint8Array(SALT_LENGTH[strength]));
|
|
5772
|
+
const passwordVerification = await createKeys$1(encrypt, strength, password, salt);
|
|
5773
|
+
return concat(salt, passwordVerification);
|
|
5774
|
+
}
|
|
5775
|
+
|
|
5776
|
+
async function createKeys$1(aesCrypto, strength, password, salt) {
|
|
5777
|
+
aesCrypto.password = null;
|
|
5778
|
+
const encodedPassword = encodeText(password);
|
|
5779
|
+
const baseKey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
|
|
5780
|
+
const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), baseKey, 8 * ((KEY_LENGTH[strength] * 2) + 2));
|
|
5781
|
+
const compositeKey = new Uint8Array(derivedBits);
|
|
5782
|
+
const key = toBits(codecBytes, subarray(compositeKey, 0, KEY_LENGTH[strength]));
|
|
5783
|
+
const authentication = toBits(codecBytes, subarray(compositeKey, KEY_LENGTH[strength], KEY_LENGTH[strength] * 2));
|
|
5784
|
+
const passwordVerification = subarray(compositeKey, KEY_LENGTH[strength] * 2);
|
|
5785
|
+
Object.assign(aesCrypto, {
|
|
5786
|
+
keys: {
|
|
5787
|
+
key,
|
|
5788
|
+
authentication,
|
|
5789
|
+
passwordVerification
|
|
5790
|
+
},
|
|
5791
|
+
ctr: new CtrGladman(new Aes(key), Array.from(COUNTER_DEFAULT_VALUE)),
|
|
5792
|
+
hmac: new HmacSha1(authentication)
|
|
5781
5793
|
});
|
|
5794
|
+
return passwordVerification;
|
|
5782
5795
|
}
|
|
5783
5796
|
|
|
5784
|
-
function
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
if (useCompressionStream) {
|
|
5790
|
-
readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
|
|
5791
|
-
} else {
|
|
5792
|
-
throw error;
|
|
5793
|
-
}
|
|
5797
|
+
function importKey(format, password, algorithm, extractable, keyUsages) {
|
|
5798
|
+
if (IMPORT_KEY_SUPPORTED) {
|
|
5799
|
+
return subtle.importKey(format, password, algorithm, extractable, keyUsages);
|
|
5800
|
+
} else {
|
|
5801
|
+
return misc.importKey(password);
|
|
5794
5802
|
}
|
|
5795
|
-
return readable;
|
|
5796
5803
|
}
|
|
5797
5804
|
|
|
5798
|
-
function
|
|
5799
|
-
|
|
5805
|
+
async function deriveBits(algorithm, baseKey, length) {
|
|
5806
|
+
if (DERIVE_BITS_SUPPORTED) {
|
|
5807
|
+
return await subtle.deriveBits(algorithm, baseKey, length);
|
|
5808
|
+
} else {
|
|
5809
|
+
return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
|
|
5810
|
+
}
|
|
5811
|
+
}
|
|
5812
|
+
|
|
5813
|
+
function concat(leftArray, rightArray) {
|
|
5814
|
+
let array = leftArray;
|
|
5815
|
+
if (leftArray.length + rightArray.length) {
|
|
5816
|
+
array = new Uint8Array(leftArray.length + rightArray.length);
|
|
5817
|
+
array.set(leftArray, 0);
|
|
5818
|
+
array.set(rightArray, leftArray.length);
|
|
5819
|
+
}
|
|
5820
|
+
return array;
|
|
5821
|
+
}
|
|
5822
|
+
|
|
5823
|
+
function expand(inputArray, length) {
|
|
5824
|
+
if (length && length > inputArray.length) {
|
|
5825
|
+
const array = inputArray;
|
|
5826
|
+
inputArray = new Uint8Array(length);
|
|
5827
|
+
inputArray.set(array, 0);
|
|
5828
|
+
}
|
|
5829
|
+
return inputArray;
|
|
5830
|
+
}
|
|
5831
|
+
|
|
5832
|
+
function subarray(array, begin, end) {
|
|
5833
|
+
return array.subarray(begin, end);
|
|
5834
|
+
}
|
|
5835
|
+
|
|
5836
|
+
function fromBits(codecBytes, chunk) {
|
|
5837
|
+
return codecBytes.fromBits(chunk);
|
|
5838
|
+
}
|
|
5839
|
+
function toBits(codecBytes, chunk) {
|
|
5840
|
+
return codecBytes.toBits(chunk);
|
|
5800
5841
|
}
|
|
5801
5842
|
|
|
5802
5843
|
/*
|
|
@@ -5827,121 +5868,119 @@
|
|
|
5827
5868
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
5828
5869
|
*/
|
|
5829
5870
|
|
|
5830
|
-
|
|
5831
|
-
* This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.
|
|
5832
|
-
* JZlib is based on zlib-1.1.3, so all credit should go authors
|
|
5833
|
-
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
|
5834
|
-
* and contributors of zlib.
|
|
5835
|
-
*/
|
|
5836
|
-
|
|
5837
|
-
/* global TransformStream */
|
|
5871
|
+
const HEADER_LENGTH = 12;
|
|
5838
5872
|
|
|
5839
|
-
class
|
|
5873
|
+
class ZipCryptoDecryptionStream extends TransformStream {
|
|
5840
5874
|
|
|
5841
|
-
constructor(
|
|
5842
|
-
const codec = new Codec(options);
|
|
5875
|
+
constructor(password, passwordVerification) {
|
|
5843
5876
|
super({
|
|
5844
|
-
|
|
5845
|
-
|
|
5877
|
+
start() {
|
|
5878
|
+
Object.assign(this, {
|
|
5879
|
+
password,
|
|
5880
|
+
passwordVerification
|
|
5881
|
+
});
|
|
5882
|
+
createKeys(this, password);
|
|
5846
5883
|
},
|
|
5847
|
-
|
|
5848
|
-
const
|
|
5849
|
-
if (
|
|
5850
|
-
|
|
5884
|
+
transform(chunk, controller) {
|
|
5885
|
+
const zipCrypto = this;
|
|
5886
|
+
if (zipCrypto.password) {
|
|
5887
|
+
const decryptedHeader = decrypt(zipCrypto, chunk.subarray(0, HEADER_LENGTH));
|
|
5888
|
+
zipCrypto.password = null;
|
|
5889
|
+
if (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {
|
|
5890
|
+
throw new Error(ERR_INVALID_PASSWORD);
|
|
5891
|
+
}
|
|
5892
|
+
chunk = chunk.subarray(HEADER_LENGTH);
|
|
5851
5893
|
}
|
|
5894
|
+
controller.enqueue(decrypt(zipCrypto, chunk));
|
|
5852
5895
|
}
|
|
5853
5896
|
});
|
|
5854
5897
|
}
|
|
5855
5898
|
}
|
|
5856
5899
|
|
|
5857
|
-
|
|
5858
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
5859
|
-
|
|
5860
|
-
Redistribution and use in source and binary forms, with or without
|
|
5861
|
-
modification, are permitted provided that the following conditions are met:
|
|
5862
|
-
|
|
5863
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
5864
|
-
this list of conditions and the following disclaimer.
|
|
5865
|
-
|
|
5866
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
5867
|
-
notice, this list of conditions and the following disclaimer in
|
|
5868
|
-
the documentation and/or other materials provided with the distribution.
|
|
5869
|
-
|
|
5870
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
5871
|
-
derived from this software without specific prior written permission.
|
|
5900
|
+
class ZipCryptoEncryptionStream extends TransformStream {
|
|
5872
5901
|
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5902
|
+
constructor(password, passwordVerification) {
|
|
5903
|
+
super({
|
|
5904
|
+
start() {
|
|
5905
|
+
Object.assign(this, {
|
|
5906
|
+
password,
|
|
5907
|
+
passwordVerification
|
|
5908
|
+
});
|
|
5909
|
+
createKeys(this, password);
|
|
5910
|
+
},
|
|
5911
|
+
transform(chunk, controller) {
|
|
5912
|
+
const zipCrypto = this;
|
|
5913
|
+
let output;
|
|
5914
|
+
let offset;
|
|
5915
|
+
if (zipCrypto.password) {
|
|
5916
|
+
zipCrypto.password = null;
|
|
5917
|
+
const header = getRandomValues(new Uint8Array(HEADER_LENGTH));
|
|
5918
|
+
header[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;
|
|
5919
|
+
output = new Uint8Array(chunk.length + header.length);
|
|
5920
|
+
output.set(encrypt(zipCrypto, header), 0);
|
|
5921
|
+
offset = HEADER_LENGTH;
|
|
5922
|
+
} else {
|
|
5923
|
+
output = new Uint8Array(chunk.length);
|
|
5924
|
+
offset = 0;
|
|
5925
|
+
}
|
|
5926
|
+
output.set(encrypt(zipCrypto, chunk), offset);
|
|
5927
|
+
controller.enqueue(output);
|
|
5928
|
+
}
|
|
5929
|
+
});
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5884
5932
|
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5933
|
+
function decrypt(target, input) {
|
|
5934
|
+
const output = new Uint8Array(input.length);
|
|
5935
|
+
for (let index = 0; index < input.length; index++) {
|
|
5936
|
+
output[index] = getByte(target) ^ input[index];
|
|
5937
|
+
updateKeys(target, output[index]);
|
|
5938
|
+
}
|
|
5939
|
+
return output;
|
|
5940
|
+
}
|
|
5893
5941
|
|
|
5894
|
-
|
|
5942
|
+
function encrypt(target, input) {
|
|
5943
|
+
const output = new Uint8Array(input.length);
|
|
5944
|
+
for (let index = 0; index < input.length; index++) {
|
|
5945
|
+
output[index] = getByte(target) ^ input[index];
|
|
5946
|
+
updateKeys(target, input[index]);
|
|
5947
|
+
}
|
|
5948
|
+
return output;
|
|
5949
|
+
}
|
|
5895
5950
|
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
CodecStream,
|
|
5906
|
-
readable,
|
|
5907
|
-
writable,
|
|
5908
|
-
options,
|
|
5909
|
-
config
|
|
5910
|
-
});
|
|
5951
|
+
function createKeys(target, password) {
|
|
5952
|
+
const keys = [0x12345678, 0x23456789, 0x34567890];
|
|
5953
|
+
Object.assign(target, {
|
|
5954
|
+
keys,
|
|
5955
|
+
crcKey0: new Crc32(keys[0]),
|
|
5956
|
+
crcKey2: new Crc32(keys[2]),
|
|
5957
|
+
});
|
|
5958
|
+
for (let index = 0; index < password.length; index++) {
|
|
5959
|
+
updateKeys(target, password.charCodeAt(index));
|
|
5911
5960
|
}
|
|
5961
|
+
}
|
|
5912
5962
|
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
const stream = new CodecStream(options, config);
|
|
5922
|
-
let size = 0;
|
|
5923
|
-
await readable
|
|
5924
|
-
.pipeThrough(stream)
|
|
5925
|
-
.pipeThrough(new TransformStream({
|
|
5926
|
-
transform(chunk, controller) {
|
|
5927
|
-
if (chunk && chunk.length) {
|
|
5928
|
-
size += chunk.length;
|
|
5929
|
-
controller.enqueue(chunk);
|
|
5930
|
-
}
|
|
5931
|
-
}
|
|
5932
|
-
}))
|
|
5933
|
-
.pipeTo(writable, { preventClose: true, preventAbort: true });
|
|
5934
|
-
const { signature } = stream;
|
|
5935
|
-
return { size, signature };
|
|
5936
|
-
}
|
|
5963
|
+
function updateKeys(target, byte) {
|
|
5964
|
+
let [key0, key1, key2] = target.keys;
|
|
5965
|
+
target.crcKey0.append([byte]);
|
|
5966
|
+
key0 = ~target.crcKey0.get();
|
|
5967
|
+
key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
|
|
5968
|
+
target.crcKey2.append([key1 >>> 24]);
|
|
5969
|
+
key2 = ~target.crcKey2.get();
|
|
5970
|
+
target.keys = [key0, key1, key2];
|
|
5937
5971
|
}
|
|
5938
5972
|
|
|
5939
|
-
function
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5973
|
+
function getByte(target) {
|
|
5974
|
+
const temp = target.keys[2] | 2;
|
|
5975
|
+
return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
|
|
5976
|
+
}
|
|
5977
|
+
|
|
5978
|
+
function getInt8(number) {
|
|
5979
|
+
return number & 0xFF;
|
|
5980
|
+
}
|
|
5981
|
+
|
|
5982
|
+
function getInt32(number) {
|
|
5983
|
+
return number & 0xFFFFFFFF;
|
|
5945
5984
|
}
|
|
5946
5985
|
|
|
5947
5986
|
/*
|
|
@@ -5972,94 +6011,115 @@
|
|
|
5972
6011
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
5973
6012
|
*/
|
|
5974
6013
|
|
|
5975
|
-
const
|
|
5976
|
-
const UNDEFINED_VALUE = undefined;
|
|
5977
|
-
let maxWorkers = 2;
|
|
5978
|
-
try {
|
|
5979
|
-
if (typeof navigator != "undefined" && navigator.hardwareConcurrency) {
|
|
5980
|
-
maxWorkers = navigator.hardwareConcurrency;
|
|
5981
|
-
}
|
|
5982
|
-
} catch (_error) {
|
|
5983
|
-
// ignored
|
|
5984
|
-
}
|
|
5985
|
-
const DEFAULT_CONFIGURATION = {
|
|
5986
|
-
chunkSize: 512 * 1024,
|
|
5987
|
-
maxWorkers,
|
|
5988
|
-
terminateWorkerTimeout: 5000,
|
|
5989
|
-
useWebWorkers: true,
|
|
5990
|
-
useCompressionStream: true,
|
|
5991
|
-
workerScripts: undefined,
|
|
5992
|
-
CompressionStreamNative: typeof CompressionStream != "undefined" && CompressionStream,
|
|
5993
|
-
DecompressionStreamNative: typeof DecompressionStream != "undefined" && DecompressionStream
|
|
5994
|
-
};
|
|
6014
|
+
const COMPRESSION_FORMAT = "deflate-raw";
|
|
5995
6015
|
|
|
5996
|
-
|
|
6016
|
+
class DeflateStream extends TransformStream {
|
|
5997
6017
|
|
|
5998
|
-
|
|
5999
|
-
|
|
6018
|
+
constructor(options, { chunkSize, CompressionStream, CompressionStreamNative }) {
|
|
6019
|
+
super({});
|
|
6020
|
+
const { compressed, encrypted, useCompressionStream, password, passwordVerification, encryptionStrength, zipCrypto, signed, level } = options;
|
|
6021
|
+
const stream = this;
|
|
6022
|
+
let crc32Stream, encryptionStream;
|
|
6023
|
+
let readable = filterEmptyChunks(super.readable);
|
|
6024
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
6025
|
+
[readable, crc32Stream] = readable.tee();
|
|
6026
|
+
crc32Stream = pipeThrough(crc32Stream, new Crc32Stream());
|
|
6027
|
+
}
|
|
6028
|
+
if (compressed) {
|
|
6029
|
+
readable = pipeThroughCommpressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStreamNative, CompressionStream);
|
|
6030
|
+
}
|
|
6031
|
+
if (encrypted) {
|
|
6032
|
+
if (zipCrypto) {
|
|
6033
|
+
readable = pipeThrough(readable, new ZipCryptoEncryptionStream(password, passwordVerification));
|
|
6034
|
+
} else {
|
|
6035
|
+
encryptionStream = new AESEncryptionStream(password, encryptionStrength);
|
|
6036
|
+
readable = pipeThrough(readable, encryptionStream);
|
|
6037
|
+
}
|
|
6038
|
+
}
|
|
6039
|
+
setReadable(stream, readable, async () => {
|
|
6040
|
+
let signature;
|
|
6041
|
+
if (encrypted && !zipCrypto) {
|
|
6042
|
+
signature = encryptionStream.signature;
|
|
6043
|
+
}
|
|
6044
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
6045
|
+
signature = await crc32Stream.getReader().read();
|
|
6046
|
+
signature = new DataView(signature.value.buffer).getUint32(0);
|
|
6047
|
+
}
|
|
6048
|
+
stream.signature = signature;
|
|
6049
|
+
});
|
|
6050
|
+
}
|
|
6000
6051
|
}
|
|
6001
6052
|
|
|
6002
|
-
|
|
6003
|
-
return Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
|
|
6004
|
-
}
|
|
6053
|
+
class InflateStream extends TransformStream {
|
|
6005
6054
|
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
DecompressionStream,
|
|
6018
|
-
workerScripts
|
|
6019
|
-
} = configuration;
|
|
6020
|
-
setIfDefined("baseURL", baseURL);
|
|
6021
|
-
setIfDefined("chunkSize", chunkSize);
|
|
6022
|
-
setIfDefined("maxWorkers", maxWorkers);
|
|
6023
|
-
setIfDefined("terminateWorkerTimeout", terminateWorkerTimeout);
|
|
6024
|
-
setIfDefined("useCompressionStream", useCompressionStream);
|
|
6025
|
-
setIfDefined("useWebWorkers", useWebWorkers);
|
|
6026
|
-
if (Deflate) {
|
|
6027
|
-
config.CompressionStream = getCodecStreamClass(Deflate);
|
|
6028
|
-
}
|
|
6029
|
-
if (Inflate) {
|
|
6030
|
-
config.DecompressionStream = getCodecStreamClass(Inflate);
|
|
6031
|
-
}
|
|
6032
|
-
setIfDefined("CompressionStream", CompressionStream);
|
|
6033
|
-
setIfDefined("DecompressionStream", DecompressionStream);
|
|
6034
|
-
if (workerScripts !== UNDEFINED_VALUE) {
|
|
6035
|
-
const { deflate, inflate } = workerScripts;
|
|
6036
|
-
if (deflate || inflate) {
|
|
6037
|
-
if (!config.workerScripts) {
|
|
6038
|
-
config.workerScripts = {};
|
|
6055
|
+
constructor(options, { chunkSize, DecompressionStream, DecompressionStreamNative }) {
|
|
6056
|
+
super({});
|
|
6057
|
+
const { zipCrypto, encrypted, password, passwordVerification, signed, signature, encryptionStrength, compressed, useCompressionStream } = options;
|
|
6058
|
+
let crc32Stream, decryptionStream;
|
|
6059
|
+
let readable = filterEmptyChunks(super.readable);
|
|
6060
|
+
if (encrypted) {
|
|
6061
|
+
if (zipCrypto) {
|
|
6062
|
+
readable = pipeThrough(readable, new ZipCryptoDecryptionStream(password, passwordVerification));
|
|
6063
|
+
} else {
|
|
6064
|
+
decryptionStream = new AESDecryptionStream(password, signed, encryptionStrength);
|
|
6065
|
+
readable = pipeThrough(readable, decryptionStream);
|
|
6039
6066
|
}
|
|
6040
6067
|
}
|
|
6041
|
-
if (
|
|
6042
|
-
|
|
6043
|
-
throw new Error("workerScripts.deflate must be an array");
|
|
6044
|
-
}
|
|
6045
|
-
config.workerScripts.deflate = deflate;
|
|
6068
|
+
if (compressed) {
|
|
6069
|
+
readable = pipeThroughCommpressionStream(readable, useCompressionStream, { chunkSize }, DecompressionStreamNative, DecompressionStream);
|
|
6046
6070
|
}
|
|
6047
|
-
if (
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
}
|
|
6051
|
-
config.workerScripts.inflate = inflate;
|
|
6071
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
6072
|
+
[readable, crc32Stream] = readable.tee();
|
|
6073
|
+
crc32Stream = pipeThrough(crc32Stream, new Crc32Stream());
|
|
6052
6074
|
}
|
|
6075
|
+
setReadable(this, readable, async () => {
|
|
6076
|
+
if ((!encrypted || zipCrypto) && signed) {
|
|
6077
|
+
const streamSignature = await crc32Stream.getReader().read();
|
|
6078
|
+
const dataViewSignature = new DataView(streamSignature.value.buffer);
|
|
6079
|
+
if (signature != dataViewSignature.getUint32(0, false)) {
|
|
6080
|
+
throw new Error(ERR_INVALID_SIGNATURE);
|
|
6081
|
+
}
|
|
6082
|
+
}
|
|
6083
|
+
});
|
|
6053
6084
|
}
|
|
6054
6085
|
}
|
|
6055
6086
|
|
|
6056
|
-
function
|
|
6057
|
-
|
|
6058
|
-
|
|
6087
|
+
function filterEmptyChunks(readable) {
|
|
6088
|
+
return pipeThrough(readable, new TransformStream({
|
|
6089
|
+
transform(chunk, controller) {
|
|
6090
|
+
if (chunk && chunk.length) {
|
|
6091
|
+
controller.enqueue(chunk);
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
}));
|
|
6095
|
+
}
|
|
6096
|
+
|
|
6097
|
+
function setReadable(stream, readable, flush) {
|
|
6098
|
+
readable = pipeThrough(readable, new TransformStream({ flush }));
|
|
6099
|
+
Object.defineProperty(stream, "readable", {
|
|
6100
|
+
get() {
|
|
6101
|
+
return readable;
|
|
6102
|
+
}
|
|
6103
|
+
});
|
|
6104
|
+
}
|
|
6105
|
+
|
|
6106
|
+
function pipeThroughCommpressionStream(readable, useCompressionStream, options, CodecStreamNative, CodecStream) {
|
|
6107
|
+
try {
|
|
6108
|
+
const CompressionStream = useCompressionStream && CodecStreamNative ? CodecStreamNative : CodecStream;
|
|
6109
|
+
readable = pipeThrough(readable, new CompressionStream(COMPRESSION_FORMAT, options));
|
|
6110
|
+
} catch (error) {
|
|
6111
|
+
if (useCompressionStream) {
|
|
6112
|
+
readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
|
|
6113
|
+
} else {
|
|
6114
|
+
throw error;
|
|
6115
|
+
}
|
|
6059
6116
|
}
|
|
6117
|
+
return readable;
|
|
6060
6118
|
}
|
|
6061
6119
|
|
|
6062
|
-
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]}});}
|
|
6120
|
+
function pipeThrough(readable, transformStream) {
|
|
6121
|
+
return readable.pipeThrough(transformStream);
|
|
6122
|
+
}
|
|
6063
6123
|
|
|
6064
6124
|
/*
|
|
6065
6125
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
@@ -6089,56 +6149,50 @@
|
|
|
6089
6149
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
6090
6150
|
*/
|
|
6091
6151
|
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
};
|
|
6101
|
-
}
|
|
6102
|
-
|
|
6103
|
-
function createCodecClass(constructor, constructorOptions, registerDataHandler) {
|
|
6104
|
-
return class {
|
|
6152
|
+
const MESSAGE_EVENT_TYPE = "message";
|
|
6153
|
+
const MESSAGE_START = "start";
|
|
6154
|
+
const MESSAGE_PULL = "pull";
|
|
6155
|
+
const MESSAGE_DATA = "data";
|
|
6156
|
+
const MESSAGE_ACK_DATA = "ack";
|
|
6157
|
+
const MESSAGE_CLOSE = "close";
|
|
6158
|
+
const CODEC_DEFLATE = "deflate";
|
|
6159
|
+
const CODEC_INFLATE = "inflate";
|
|
6105
6160
|
|
|
6106
|
-
|
|
6107
|
-
const codecAdapter = this;
|
|
6108
|
-
const onData = data => {
|
|
6109
|
-
if (codecAdapter.pendingData) {
|
|
6110
|
-
const { pendingData } = codecAdapter;
|
|
6111
|
-
codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
|
|
6112
|
-
pendingData.set(pendingData, 0);
|
|
6113
|
-
pendingData.set(data, pendingData.length);
|
|
6114
|
-
} else {
|
|
6115
|
-
codecAdapter.pendingData = new Uint8Array(data);
|
|
6116
|
-
}
|
|
6117
|
-
};
|
|
6118
|
-
if (Object.hasOwn(options, "level") && options.level === undefined) {
|
|
6119
|
-
delete options.level;
|
|
6120
|
-
}
|
|
6121
|
-
codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
|
|
6122
|
-
registerDataHandler(codecAdapter.codec, onData);
|
|
6123
|
-
}
|
|
6124
|
-
append(data) {
|
|
6125
|
-
this.codec.push(data);
|
|
6126
|
-
return getResponse(this);
|
|
6127
|
-
}
|
|
6128
|
-
flush() {
|
|
6129
|
-
this.codec.push(new Uint8Array(), true);
|
|
6130
|
-
return getResponse(this);
|
|
6131
|
-
}
|
|
6132
|
-
};
|
|
6161
|
+
class CodecStream extends TransformStream {
|
|
6133
6162
|
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6163
|
+
constructor(options, config) {
|
|
6164
|
+
super({});
|
|
6165
|
+
const codec = this;
|
|
6166
|
+
const { codecType } = options;
|
|
6167
|
+
let Stream;
|
|
6168
|
+
if (codecType.startsWith(CODEC_DEFLATE)) {
|
|
6169
|
+
Stream = DeflateStream;
|
|
6170
|
+
} else if (codecType.startsWith(CODEC_INFLATE)) {
|
|
6171
|
+
Stream = InflateStream;
|
|
6141
6172
|
}
|
|
6173
|
+
let size = 0;
|
|
6174
|
+
const stream = new Stream(options, config);
|
|
6175
|
+
const readable = super.readable;
|
|
6176
|
+
const transformStream = new TransformStream({
|
|
6177
|
+
transform(chunk, controller) {
|
|
6178
|
+
if (chunk && chunk.length) {
|
|
6179
|
+
size += chunk.length;
|
|
6180
|
+
controller.enqueue(chunk);
|
|
6181
|
+
}
|
|
6182
|
+
},
|
|
6183
|
+
flush() {
|
|
6184
|
+
const { signature } = stream;
|
|
6185
|
+
Object.assign(codec, {
|
|
6186
|
+
signature,
|
|
6187
|
+
size
|
|
6188
|
+
});
|
|
6189
|
+
}
|
|
6190
|
+
});
|
|
6191
|
+
Object.defineProperty(codec, "readable", {
|
|
6192
|
+
get() {
|
|
6193
|
+
return readable.pipeThrough(stream).pipeThrough(transformStream);
|
|
6194
|
+
}
|
|
6195
|
+
});
|
|
6142
6196
|
}
|
|
6143
6197
|
}
|
|
6144
6198
|
|
|
@@ -6170,25 +6224,26 @@
|
|
|
6170
6224
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
6171
6225
|
*/
|
|
6172
6226
|
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
let transferStreamsSupported = true;
|
|
6227
|
+
// deno-lint-ignore valid-typeof
|
|
6228
|
+
const WEB_WORKERS_SUPPORTED = typeof Worker != UNDEFINED_TYPE$1;
|
|
6176
6229
|
|
|
6177
6230
|
class CodecWorker {
|
|
6178
6231
|
|
|
6179
6232
|
constructor(workerData, stream, workerOptions, onTaskFinished) {
|
|
6180
6233
|
const { readable, writable } = stream;
|
|
6181
6234
|
const { options, config, streamOptions, useWebWorkers, transferStreams, scripts } = workerOptions;
|
|
6235
|
+
const { signal } = streamOptions;
|
|
6182
6236
|
Object.assign(workerData, {
|
|
6183
6237
|
busy: true,
|
|
6184
|
-
readable,
|
|
6238
|
+
readable: readable.pipeThrough(new ReadableStreamHooks(readable, streamOptions, config), { signal }),
|
|
6185
6239
|
writable,
|
|
6186
6240
|
options: Object.assign({}, options),
|
|
6187
6241
|
scripts,
|
|
6188
6242
|
transferStreams,
|
|
6189
6243
|
terminate() {
|
|
6190
|
-
|
|
6191
|
-
|
|
6244
|
+
const { worker, busy } = workerData;
|
|
6245
|
+
if (worker && !busy) {
|
|
6246
|
+
worker.terminate();
|
|
6192
6247
|
workerData.interface = null;
|
|
6193
6248
|
}
|
|
6194
6249
|
},
|
|
@@ -6197,30 +6252,34 @@
|
|
|
6197
6252
|
onTaskFinished(workerData);
|
|
6198
6253
|
}
|
|
6199
6254
|
});
|
|
6200
|
-
|
|
6255
|
+
return (useWebWorkers && WEB_WORKERS_SUPPORTED ? createWebWorkerInterface : createWorkerInterface)(workerData, config);
|
|
6256
|
+
}
|
|
6257
|
+
}
|
|
6258
|
+
|
|
6259
|
+
class ReadableStreamHooks extends TransformStream {
|
|
6260
|
+
|
|
6261
|
+
constructor(readableSource, { onstart, onprogress, size, onend }, { chunkSize }) {
|
|
6201
6262
|
let chunkOffset = 0;
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6263
|
+
super({
|
|
6264
|
+
start() {
|
|
6265
|
+
if (onstart) {
|
|
6266
|
+
callHandler(onstart, size);
|
|
6267
|
+
}
|
|
6268
|
+
},
|
|
6269
|
+
async transform(chunk, controller) {
|
|
6270
|
+
chunkOffset += chunk.length;
|
|
6271
|
+
if (onprogress) {
|
|
6272
|
+
await callHandler(onprogress, chunkOffset, size);
|
|
6273
|
+
}
|
|
6274
|
+
controller.enqueue(chunk);
|
|
6275
|
+
},
|
|
6276
|
+
flush() {
|
|
6277
|
+
readableSource.size = chunkOffset;
|
|
6278
|
+
if (onend) {
|
|
6279
|
+
callHandler(onend, chunkOffset);
|
|
6280
|
+
}
|
|
6217
6281
|
}
|
|
6218
|
-
};
|
|
6219
|
-
workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
|
|
6220
|
-
if (workersSupported === undefined) {
|
|
6221
|
-
workersSupported = typeof Worker != "undefined";
|
|
6222
|
-
}
|
|
6223
|
-
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
6282
|
+
}, { highWaterMark: 1, size: () => chunkSize });
|
|
6224
6283
|
}
|
|
6225
6284
|
}
|
|
6226
6285
|
|
|
@@ -6233,186 +6292,209 @@
|
|
|
6233
6292
|
}
|
|
6234
6293
|
|
|
6235
6294
|
function createWorkerInterface(workerData, config) {
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
const codec = {
|
|
6239
|
-
async run() {
|
|
6240
|
-
try {
|
|
6241
|
-
return await interfaceCodec.run();
|
|
6242
|
-
} finally {
|
|
6243
|
-
onTaskFinished();
|
|
6244
|
-
}
|
|
6245
|
-
}
|
|
6295
|
+
return {
|
|
6296
|
+
run: () => runWorker$1(workerData, config)
|
|
6246
6297
|
};
|
|
6247
|
-
return codec;
|
|
6248
6298
|
}
|
|
6249
6299
|
|
|
6250
6300
|
function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
6251
|
-
const workerOptions = { type: "module" };
|
|
6252
|
-
Object.assign(workerData, {
|
|
6253
|
-
streams: {},
|
|
6254
|
-
result: new Promise((resolve, reject) => {
|
|
6255
|
-
workerData.resolveResult = resolve;
|
|
6256
|
-
workerData.rejectResult = reject;
|
|
6257
|
-
})
|
|
6258
|
-
});
|
|
6259
6301
|
if (!workerData.interface) {
|
|
6260
|
-
|
|
6261
|
-
workerData.
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
workerData.worker = getWorker({});
|
|
6265
|
-
} catch (_error) {
|
|
6266
|
-
classicWorkersSupported = false;
|
|
6267
|
-
workerData.worker = getWorker(workerOptions);
|
|
6268
|
-
}
|
|
6269
|
-
}
|
|
6270
|
-
workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
|
|
6271
|
-
workerData.interface = {
|
|
6272
|
-
async run() {
|
|
6273
|
-
const { readable, options } = workerData;
|
|
6274
|
-
const writer = workerData.writable.getWriter();
|
|
6275
|
-
let resolveStreamClosed, streamClosed;
|
|
6276
|
-
streamClosed = new Promise(resolve => resolveStreamClosed = resolve);
|
|
6277
|
-
const writable = new WritableStream({
|
|
6278
|
-
async write(chunk) {
|
|
6279
|
-
await writer.ready;
|
|
6280
|
-
await writer.write(chunk);
|
|
6281
|
-
},
|
|
6282
|
-
async close() {
|
|
6283
|
-
writer.releaseLock();
|
|
6284
|
-
resolveStreamClosed();
|
|
6285
|
-
},
|
|
6286
|
-
abort(reason) {
|
|
6287
|
-
writer.abort(reason);
|
|
6288
|
-
}
|
|
6289
|
-
});
|
|
6290
|
-
const scripts = workerData.scripts.slice(1);
|
|
6291
|
-
const message = { type: MESSAGE_START, scripts, options, config: { chunkSize } };
|
|
6292
|
-
if (workerData.transferStreams && transferStreamsSupported) {
|
|
6293
|
-
const streamsTransferred = sendMessage({ ...message, readable, writable });
|
|
6294
|
-
if (!streamsTransferred) {
|
|
6295
|
-
transferStreamsSupported = false;
|
|
6296
|
-
initStreams(readable, writable);
|
|
6297
|
-
}
|
|
6298
|
-
} else {
|
|
6299
|
-
sendMessage(message);
|
|
6300
|
-
initStreams(readable, writable);
|
|
6301
|
-
}
|
|
6302
|
-
const result = await workerData.result;
|
|
6303
|
-
try {
|
|
6304
|
-
await writable.close();
|
|
6305
|
-
} catch (_error) {
|
|
6306
|
-
// ignored
|
|
6307
|
-
}
|
|
6308
|
-
await streamClosed;
|
|
6309
|
-
return result;
|
|
6302
|
+
Object.assign(workerData, {
|
|
6303
|
+
worker: getWebWorker(workerData.scripts[0], baseURL, workerData),
|
|
6304
|
+
interface: {
|
|
6305
|
+
run: () => runWebWorker(workerData, { chunkSize })
|
|
6310
6306
|
}
|
|
6311
|
-
};
|
|
6307
|
+
});
|
|
6312
6308
|
}
|
|
6313
6309
|
return workerData.interface;
|
|
6310
|
+
}
|
|
6311
|
+
|
|
6312
|
+
async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
|
|
6313
|
+
const codecStream = new CodecStream(options, config);
|
|
6314
|
+
try {
|
|
6315
|
+
await readable.pipeThrough(codecStream).pipeTo(writable, { preventClose: true, preventAbort: true });
|
|
6316
|
+
const {
|
|
6317
|
+
signature,
|
|
6318
|
+
size
|
|
6319
|
+
} = codecStream;
|
|
6320
|
+
return {
|
|
6321
|
+
signature,
|
|
6322
|
+
size
|
|
6323
|
+
};
|
|
6324
|
+
} finally {
|
|
6325
|
+
onTaskFinished();
|
|
6326
|
+
}
|
|
6327
|
+
}
|
|
6314
6328
|
|
|
6315
|
-
|
|
6316
|
-
|
|
6329
|
+
async function runWebWorker(workerData, config) {
|
|
6330
|
+
let resolveResult, rejectResult;
|
|
6331
|
+
const result = new Promise((resolve, reject) => {
|
|
6332
|
+
resolveResult = resolve;
|
|
6333
|
+
rejectResult = reject;
|
|
6334
|
+
});
|
|
6335
|
+
Object.assign(workerData, {
|
|
6336
|
+
reader: null,
|
|
6337
|
+
writer: null,
|
|
6338
|
+
resolveResult,
|
|
6339
|
+
rejectResult,
|
|
6340
|
+
result
|
|
6341
|
+
});
|
|
6342
|
+
const { readable, options } = workerData;
|
|
6343
|
+
const { writable, closed } = detectClosedStream(workerData.writable);
|
|
6344
|
+
const streamsTransferred = sendMessage({
|
|
6345
|
+
type: MESSAGE_START,
|
|
6346
|
+
scripts: workerData.scripts.slice(1),
|
|
6347
|
+
options,
|
|
6348
|
+
config,
|
|
6349
|
+
readable,
|
|
6350
|
+
writable
|
|
6351
|
+
}, workerData);
|
|
6352
|
+
if (!streamsTransferred) {
|
|
6353
|
+
Object.assign(workerData, {
|
|
6317
6354
|
reader: readable.getReader(),
|
|
6318
6355
|
writer: writable.getWriter()
|
|
6319
6356
|
});
|
|
6320
6357
|
}
|
|
6358
|
+
const resultValue = await result;
|
|
6359
|
+
try {
|
|
6360
|
+
await writable.close();
|
|
6361
|
+
} catch (_error) {
|
|
6362
|
+
// ignored
|
|
6363
|
+
}
|
|
6364
|
+
await closed;
|
|
6365
|
+
return resultValue;
|
|
6366
|
+
}
|
|
6321
6367
|
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6368
|
+
function detectClosedStream(writableSource) {
|
|
6369
|
+
const writer = writableSource.getWriter();
|
|
6370
|
+
let resolveStreamClosed;
|
|
6371
|
+
const closed = new Promise(resolve => resolveStreamClosed = resolve);
|
|
6372
|
+
const writable = new WritableStream({
|
|
6373
|
+
async write(chunk) {
|
|
6374
|
+
await writer.ready;
|
|
6375
|
+
await writer.write(chunk);
|
|
6376
|
+
},
|
|
6377
|
+
close() {
|
|
6378
|
+
writer.releaseLock();
|
|
6379
|
+
resolveStreamClosed();
|
|
6380
|
+
},
|
|
6381
|
+
abort(reason) {
|
|
6382
|
+
writer.abort(reason);
|
|
6327
6383
|
}
|
|
6384
|
+
});
|
|
6385
|
+
return { writable, closed };
|
|
6386
|
+
}
|
|
6387
|
+
|
|
6388
|
+
let classicWorkersSupported = true;
|
|
6389
|
+
let transferStreamsSupported = true;
|
|
6390
|
+
|
|
6391
|
+
function getWebWorker(url, baseURL, workerData) {
|
|
6392
|
+
const workerOptions = { type: "module" };
|
|
6393
|
+
let scriptUrl, worker;
|
|
6394
|
+
if (typeof url == FUNCTION_TYPE$1) {
|
|
6395
|
+
url = url();
|
|
6396
|
+
}
|
|
6397
|
+
try {
|
|
6398
|
+
scriptUrl = new URL(url, baseURL);
|
|
6399
|
+
} catch (_error) {
|
|
6400
|
+
scriptUrl = url;
|
|
6401
|
+
}
|
|
6402
|
+
if (classicWorkersSupported) {
|
|
6328
6403
|
try {
|
|
6329
|
-
|
|
6404
|
+
worker = new Worker(scriptUrl);
|
|
6330
6405
|
} catch (_error) {
|
|
6331
|
-
|
|
6406
|
+
classicWorkersSupported = false;
|
|
6407
|
+
worker = new Worker(scriptUrl, workerOptions);
|
|
6332
6408
|
}
|
|
6333
|
-
|
|
6409
|
+
} else {
|
|
6410
|
+
worker = new Worker(scriptUrl, workerOptions);
|
|
6334
6411
|
}
|
|
6412
|
+
worker.addEventListener(MESSAGE_EVENT_TYPE, event => onMessage(event, workerData));
|
|
6413
|
+
return worker;
|
|
6414
|
+
}
|
|
6335
6415
|
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
data = new Uint8Array(data);
|
|
6345
|
-
}
|
|
6346
|
-
message.data = data.buffer;
|
|
6347
|
-
transferrables.push(message.data);
|
|
6416
|
+
function sendMessage(message, { worker, writer, onTaskFinished, transferStreams }) {
|
|
6417
|
+
try {
|
|
6418
|
+
let { data, readable, writable } = message;
|
|
6419
|
+
const transferrables = [];
|
|
6420
|
+
if (data) {
|
|
6421
|
+
const { buffer, length } = data;
|
|
6422
|
+
if (length != buffer.byteLength) {
|
|
6423
|
+
data = new Uint8Array(data);
|
|
6348
6424
|
}
|
|
6425
|
+
message.data = data.buffer;
|
|
6426
|
+
transferrables.push(message.data);
|
|
6427
|
+
}
|
|
6428
|
+
if (transferStreams && transferStreamsSupported) {
|
|
6349
6429
|
if (readable) {
|
|
6350
6430
|
transferrables.push(readable);
|
|
6351
6431
|
}
|
|
6352
6432
|
if (writable) {
|
|
6353
6433
|
transferrables.push(writable);
|
|
6354
6434
|
}
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6435
|
+
} else {
|
|
6436
|
+
message.readable = message.writable = null;
|
|
6437
|
+
}
|
|
6438
|
+
if (transferrables.length) {
|
|
6439
|
+
try {
|
|
6440
|
+
worker.postMessage(message, transferrables);
|
|
6441
|
+
return true;
|
|
6442
|
+
} catch (_error) {
|
|
6443
|
+
transferStreamsSupported = false;
|
|
6444
|
+
message.readable = message.writable = null;
|
|
6364
6445
|
worker.postMessage(message);
|
|
6365
6446
|
}
|
|
6366
|
-
}
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6447
|
+
} else {
|
|
6448
|
+
worker.postMessage(message);
|
|
6449
|
+
}
|
|
6450
|
+
} catch (error) {
|
|
6451
|
+
if (writer) {
|
|
6452
|
+
writer.releaseLock();
|
|
6372
6453
|
}
|
|
6454
|
+
onTaskFinished();
|
|
6455
|
+
throw error;
|
|
6373
6456
|
}
|
|
6457
|
+
}
|
|
6374
6458
|
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
Object.assign(error, { stack, code, name });
|
|
6386
|
-
close(error);
|
|
6387
|
-
} else {
|
|
6388
|
-
if (type == MESSAGE_PULL) {
|
|
6389
|
-
const { value, done } = await reader.read();
|
|
6390
|
-
sendMessage({ type: MESSAGE_DATA, data: value, done, messageId });
|
|
6391
|
-
}
|
|
6392
|
-
if (type == MESSAGE_DATA) {
|
|
6393
|
-
await writer.ready;
|
|
6394
|
-
await writer.write(new Uint8Array(data));
|
|
6395
|
-
sendMessage({ type: MESSAGE_ACK_DATA, messageId });
|
|
6396
|
-
}
|
|
6397
|
-
if (type == MESSAGE_CLOSE) {
|
|
6398
|
-
close(null, result);
|
|
6399
|
-
}
|
|
6400
|
-
}
|
|
6401
|
-
} catch (error) {
|
|
6459
|
+
async function onMessage(event, workerData) {
|
|
6460
|
+
const message = event.data;
|
|
6461
|
+
const { reader, writer, resolveResult, rejectResult, onTaskFinished } = workerData;
|
|
6462
|
+
const { type, data, messageId, result } = message;
|
|
6463
|
+
const reponseError = message.error;
|
|
6464
|
+
try {
|
|
6465
|
+
if (reponseError) {
|
|
6466
|
+
const { message, stack, code, name } = reponseError;
|
|
6467
|
+
const error = new Error(message);
|
|
6468
|
+
Object.assign(error, { stack, code, name });
|
|
6402
6469
|
close(error);
|
|
6403
|
-
}
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
rejectResult(error);
|
|
6408
|
-
} else {
|
|
6409
|
-
resolveResult(result);
|
|
6470
|
+
} else {
|
|
6471
|
+
if (type == MESSAGE_PULL) {
|
|
6472
|
+
const { value, done } = await reader.read();
|
|
6473
|
+
sendMessage({ type: MESSAGE_DATA, data: value, done, messageId }, workerData);
|
|
6410
6474
|
}
|
|
6411
|
-
if (
|
|
6412
|
-
writer.
|
|
6475
|
+
if (type == MESSAGE_DATA) {
|
|
6476
|
+
await writer.ready;
|
|
6477
|
+
await writer.write(new Uint8Array(data));
|
|
6478
|
+
sendMessage({ type: MESSAGE_ACK_DATA, messageId }, workerData);
|
|
6413
6479
|
}
|
|
6414
|
-
|
|
6480
|
+
if (type == MESSAGE_CLOSE) {
|
|
6481
|
+
close(null, result);
|
|
6482
|
+
}
|
|
6483
|
+
}
|
|
6484
|
+
} catch (error) {
|
|
6485
|
+
close(error);
|
|
6486
|
+
}
|
|
6487
|
+
|
|
6488
|
+
function close(error, result) {
|
|
6489
|
+
if (error) {
|
|
6490
|
+
rejectResult(error);
|
|
6491
|
+
} else {
|
|
6492
|
+
resolveResult(result);
|
|
6415
6493
|
}
|
|
6494
|
+
if (writer) {
|
|
6495
|
+
writer.releaseLock();
|
|
6496
|
+
}
|
|
6497
|
+
onTaskFinished();
|
|
6416
6498
|
}
|
|
6417
6499
|
}
|
|
6418
6500
|
|
|
@@ -6453,11 +6535,11 @@
|
|
|
6453
6535
|
const { options, config } = workerOptions;
|
|
6454
6536
|
const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
|
|
6455
6537
|
const { workerScripts } = config;
|
|
6456
|
-
workerOptions.transferStreams = transferStreams || transferStreams ===
|
|
6538
|
+
workerOptions.transferStreams = transferStreams || transferStreams === UNDEFINED_VALUE;
|
|
6457
6539
|
const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
|
|
6458
|
-
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers ===
|
|
6540
|
+
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
6459
6541
|
workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
|
|
6460
|
-
options.useCompressionStream = useCompressionStream || (useCompressionStream ===
|
|
6542
|
+
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
6461
6543
|
let worker;
|
|
6462
6544
|
if (pool.length < config.maxWorkers) {
|
|
6463
6545
|
const workerData = { indexWorker };
|
|
@@ -6538,20 +6620,25 @@
|
|
|
6538
6620
|
*/
|
|
6539
6621
|
|
|
6540
6622
|
/* global Blob, atob, btoa, XMLHttpRequest, URL, fetch, ReadableStream, WritableStream, FileReader, TransformStream, Response */
|
|
6623
|
+
// deno-lint-ignore-file no-this-alias
|
|
6541
6624
|
|
|
6542
6625
|
const ERR_HTTP_STATUS = "HTTP error ";
|
|
6543
6626
|
const ERR_HTTP_RANGE = "HTTP Range not supported";
|
|
6627
|
+
const ERR_ITERATOR_COMPLETED_TOO_SOON = "Writer iterator completed too soon";
|
|
6544
6628
|
|
|
6545
6629
|
const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
|
|
6546
6630
|
const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
|
|
6547
6631
|
const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
|
|
6548
6632
|
const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
|
|
6549
6633
|
const HTTP_HEADER_RANGE = "Range";
|
|
6634
|
+
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
6550
6635
|
const HTTP_METHOD_HEAD = "HEAD";
|
|
6551
6636
|
const HTTP_METHOD_GET = "GET";
|
|
6552
6637
|
const HTTP_RANGE_UNIT = "bytes";
|
|
6553
6638
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
6554
6639
|
|
|
6640
|
+
const PROPERTY_NAME_WRITABLE = "writable";
|
|
6641
|
+
|
|
6555
6642
|
class Stream {
|
|
6556
6643
|
|
|
6557
6644
|
constructor() {
|
|
@@ -6597,7 +6684,7 @@
|
|
|
6597
6684
|
return writer.writeUint8Array(chunk);
|
|
6598
6685
|
}
|
|
6599
6686
|
});
|
|
6600
|
-
Object.defineProperty(writer,
|
|
6687
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
6601
6688
|
get() {
|
|
6602
6689
|
return writable;
|
|
6603
6690
|
}
|
|
@@ -6613,21 +6700,26 @@
|
|
|
6613
6700
|
|
|
6614
6701
|
constructor(dataURI) {
|
|
6615
6702
|
super();
|
|
6616
|
-
const reader = this;
|
|
6617
|
-
reader.dataURI = dataURI;
|
|
6618
6703
|
let dataEnd = dataURI.length;
|
|
6619
6704
|
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
6620
6705
|
dataEnd--;
|
|
6621
6706
|
}
|
|
6622
|
-
|
|
6623
|
-
|
|
6707
|
+
const dataStart = dataURI.indexOf(",") + 1;
|
|
6708
|
+
Object.assign(this, {
|
|
6709
|
+
dataURI,
|
|
6710
|
+
dataStart,
|
|
6711
|
+
size: Math.floor((dataEnd - dataStart) * 0.75)
|
|
6712
|
+
});
|
|
6624
6713
|
}
|
|
6625
6714
|
|
|
6626
6715
|
readUint8Array(offset, length) {
|
|
6716
|
+
const {
|
|
6717
|
+
dataStart,
|
|
6718
|
+
dataURI
|
|
6719
|
+
} = this;
|
|
6627
6720
|
const dataArray = new Uint8Array(length);
|
|
6628
6721
|
const start = Math.floor(offset / 3) * 4;
|
|
6629
|
-
const
|
|
6630
|
-
const bytes = atob(this.dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
6722
|
+
const bytes = atob(dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
6631
6723
|
const delta = offset - Math.floor(start / 4) * 3;
|
|
6632
6724
|
for (let indexByte = delta; indexByte < delta + length; indexByte++) {
|
|
6633
6725
|
dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
|
|
@@ -6640,8 +6732,10 @@
|
|
|
6640
6732
|
|
|
6641
6733
|
constructor(contentType) {
|
|
6642
6734
|
super();
|
|
6643
|
-
|
|
6644
|
-
|
|
6735
|
+
Object.assign(this, {
|
|
6736
|
+
data: "data:" + (contentType || "") + ";base64,",
|
|
6737
|
+
pending: []
|
|
6738
|
+
});
|
|
6645
6739
|
}
|
|
6646
6740
|
|
|
6647
6741
|
writeUint8Array(array) {
|
|
@@ -6672,8 +6766,10 @@
|
|
|
6672
6766
|
|
|
6673
6767
|
constructor(blob) {
|
|
6674
6768
|
super();
|
|
6675
|
-
this
|
|
6676
|
-
|
|
6769
|
+
Object.assign(this, {
|
|
6770
|
+
blob,
|
|
6771
|
+
size: blob.size
|
|
6772
|
+
});
|
|
6677
6773
|
}
|
|
6678
6774
|
|
|
6679
6775
|
async readUint8Array(offset, length) {
|
|
@@ -6690,9 +6786,9 @@
|
|
|
6690
6786
|
const transformStream = new TransformStream();
|
|
6691
6787
|
const headers = [];
|
|
6692
6788
|
if (contentType) {
|
|
6693
|
-
headers.push([
|
|
6789
|
+
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
6694
6790
|
}
|
|
6695
|
-
Object.defineProperty(writer,
|
|
6791
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
6696
6792
|
get() {
|
|
6697
6793
|
return transformStream.writable;
|
|
6698
6794
|
}
|
|
@@ -6733,8 +6829,10 @@
|
|
|
6733
6829
|
} else {
|
|
6734
6830
|
const reader = new FileReader();
|
|
6735
6831
|
return new Promise((resolve, reject) => {
|
|
6736
|
-
reader
|
|
6737
|
-
|
|
6832
|
+
Object.assign(reader, {
|
|
6833
|
+
onload: ({ target }) => resolve(target.result),
|
|
6834
|
+
onerror: () => reject(reader.error)
|
|
6835
|
+
});
|
|
6738
6836
|
reader.readAsText(blob, encoding);
|
|
6739
6837
|
});
|
|
6740
6838
|
}
|
|
@@ -6745,16 +6843,7 @@
|
|
|
6745
6843
|
|
|
6746
6844
|
constructor(url, options) {
|
|
6747
6845
|
super();
|
|
6748
|
-
|
|
6749
|
-
reader.url = url;
|
|
6750
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
6751
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
6752
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
6753
|
-
reader.options = options = Object.assign({}, options);
|
|
6754
|
-
delete options.preventHeadRequest;
|
|
6755
|
-
delete options.useRangeHeader;
|
|
6756
|
-
delete options.forceRangeRequests;
|
|
6757
|
-
delete options.useXHR;
|
|
6846
|
+
createHtpReader(this, url, options);
|
|
6758
6847
|
}
|
|
6759
6848
|
|
|
6760
6849
|
async init() {
|
|
@@ -6771,12 +6860,7 @@
|
|
|
6771
6860
|
|
|
6772
6861
|
constructor(url, options) {
|
|
6773
6862
|
super();
|
|
6774
|
-
|
|
6775
|
-
reader.url = url;
|
|
6776
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
6777
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
6778
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
6779
|
-
reader.options = options;
|
|
6863
|
+
createHtpReader(this, url, options);
|
|
6780
6864
|
}
|
|
6781
6865
|
|
|
6782
6866
|
async init() {
|
|
@@ -6789,14 +6873,39 @@
|
|
|
6789
6873
|
}
|
|
6790
6874
|
}
|
|
6791
6875
|
|
|
6876
|
+
function createHtpReader(httpReader, url, options) {
|
|
6877
|
+
const {
|
|
6878
|
+
preventHeadRequest,
|
|
6879
|
+
useRangeHeader,
|
|
6880
|
+
forceRangeRequests
|
|
6881
|
+
} = options;
|
|
6882
|
+
options = Object.assign({}, options);
|
|
6883
|
+
delete options.preventHeadRequest;
|
|
6884
|
+
delete options.useRangeHeader;
|
|
6885
|
+
delete options.forceRangeRequests;
|
|
6886
|
+
delete options.useXHR;
|
|
6887
|
+
Object.assign(httpReader, {
|
|
6888
|
+
url,
|
|
6889
|
+
options,
|
|
6890
|
+
preventHeadRequest,
|
|
6891
|
+
useRangeHeader,
|
|
6892
|
+
forceRangeRequests
|
|
6893
|
+
});
|
|
6894
|
+
}
|
|
6895
|
+
|
|
6792
6896
|
async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6897
|
+
const {
|
|
6898
|
+
url,
|
|
6899
|
+
useRangeHeader,
|
|
6900
|
+
forceRangeRequests
|
|
6901
|
+
} = httpReader;
|
|
6902
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
|
|
6903
|
+
const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
|
|
6904
|
+
if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
6796
6905
|
throw new Error(ERR_HTTP_RANGE);
|
|
6797
6906
|
} else {
|
|
6798
6907
|
let contentSize;
|
|
6799
|
-
const contentRangeHeader =
|
|
6908
|
+
const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
6800
6909
|
if (contentRangeHeader) {
|
|
6801
6910
|
const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
|
|
6802
6911
|
if (splitHeader.length) {
|
|
@@ -6806,7 +6915,7 @@
|
|
|
6806
6915
|
}
|
|
6807
6916
|
}
|
|
6808
6917
|
}
|
|
6809
|
-
if (contentSize ===
|
|
6918
|
+
if (contentSize === UNDEFINED_VALUE) {
|
|
6810
6919
|
await getContentLength(httpReader, sendRequest, getRequestData);
|
|
6811
6920
|
} else {
|
|
6812
6921
|
httpReader.size = contentSize;
|
|
@@ -6818,17 +6927,23 @@
|
|
|
6818
6927
|
}
|
|
6819
6928
|
|
|
6820
6929
|
async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
|
|
6821
|
-
|
|
6930
|
+
const {
|
|
6931
|
+
data,
|
|
6932
|
+
useRangeHeader,
|
|
6933
|
+
forceRangeRequests,
|
|
6934
|
+
options
|
|
6935
|
+
} = httpReader;
|
|
6936
|
+
if (useRangeHeader || forceRangeRequests) {
|
|
6822
6937
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
|
|
6823
6938
|
if (response.status != 206) {
|
|
6824
6939
|
throw new Error(ERR_HTTP_RANGE);
|
|
6825
6940
|
}
|
|
6826
6941
|
return new Uint8Array(await response.arrayBuffer());
|
|
6827
6942
|
} else {
|
|
6828
|
-
if (!
|
|
6829
|
-
await getRequestData(httpReader,
|
|
6943
|
+
if (!data) {
|
|
6944
|
+
await getRequestData(httpReader, options);
|
|
6830
6945
|
}
|
|
6831
|
-
return new Uint8Array(
|
|
6946
|
+
return new Uint8Array(data.subarray(index, index + length));
|
|
6832
6947
|
}
|
|
6833
6948
|
}
|
|
6834
6949
|
|
|
@@ -6836,8 +6951,8 @@
|
|
|
6836
6951
|
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
|
|
6837
6952
|
}
|
|
6838
6953
|
|
|
6839
|
-
function getHeaders(
|
|
6840
|
-
const headers =
|
|
6954
|
+
function getHeaders({ options }) {
|
|
6955
|
+
const { headers } = options;
|
|
6841
6956
|
if (headers) {
|
|
6842
6957
|
if (Symbol.iterator in headers) {
|
|
6843
6958
|
return Object.fromEntries(headers);
|
|
@@ -6922,9 +7037,10 @@
|
|
|
6922
7037
|
|
|
6923
7038
|
constructor(url, options = {}) {
|
|
6924
7039
|
super();
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
7040
|
+
Object.assign(this, {
|
|
7041
|
+
url,
|
|
7042
|
+
reader: options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options)
|
|
7043
|
+
});
|
|
6928
7044
|
}
|
|
6929
7045
|
|
|
6930
7046
|
set size(value) {
|
|
@@ -6958,8 +7074,10 @@
|
|
|
6958
7074
|
|
|
6959
7075
|
constructor(array) {
|
|
6960
7076
|
super();
|
|
6961
|
-
this
|
|
6962
|
-
|
|
7077
|
+
Object.assign(this, {
|
|
7078
|
+
array,
|
|
7079
|
+
size: array.length
|
|
7080
|
+
});
|
|
6963
7081
|
}
|
|
6964
7082
|
|
|
6965
7083
|
readUint8Array(index, length) {
|
|
@@ -6971,9 +7089,10 @@
|
|
|
6971
7089
|
|
|
6972
7090
|
init(initSize = 0) {
|
|
6973
7091
|
super.init();
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
7092
|
+
Object.assign(this, {
|
|
7093
|
+
offset: 0,
|
|
7094
|
+
array: new Uint8Array(initSize)
|
|
7095
|
+
});
|
|
6977
7096
|
}
|
|
6978
7097
|
|
|
6979
7098
|
writeUint8Array(array) {
|
|
@@ -7038,6 +7157,65 @@
|
|
|
7038
7157
|
}
|
|
7039
7158
|
}
|
|
7040
7159
|
|
|
7160
|
+
class SplitZipWriter extends Stream {
|
|
7161
|
+
|
|
7162
|
+
constructor(writerGenerator, maxSize = 4294967296) {
|
|
7163
|
+
super();
|
|
7164
|
+
const writer = this;
|
|
7165
|
+
Object.assign(writer, {
|
|
7166
|
+
diskNumber: 0,
|
|
7167
|
+
diskOffset: 0,
|
|
7168
|
+
size: 0,
|
|
7169
|
+
availableSize: maxSize
|
|
7170
|
+
});
|
|
7171
|
+
let currentWriter, diskWritable, diskWriter;
|
|
7172
|
+
const writable = new WritableStream({
|
|
7173
|
+
async write(chunk) {
|
|
7174
|
+
if (!diskWriter) {
|
|
7175
|
+
const { value, done } = await writerGenerator.next();
|
|
7176
|
+
if (done && !value) {
|
|
7177
|
+
throw new Error(ERR_ITERATOR_COMPLETED_TOO_SOON);
|
|
7178
|
+
} else {
|
|
7179
|
+
currentWriter = value;
|
|
7180
|
+
currentWriter.size = 0;
|
|
7181
|
+
diskWritable = value.writable;
|
|
7182
|
+
diskWriter = diskWritable.getWriter();
|
|
7183
|
+
}
|
|
7184
|
+
await this.write(chunk);
|
|
7185
|
+
} else if (diskWriter && currentWriter.size + chunk.length > maxSize) {
|
|
7186
|
+
await diskWriter.ready;
|
|
7187
|
+
const chunkLength = maxSize - currentWriter.size;
|
|
7188
|
+
await diskWriter.write(chunk.slice(0, chunkLength));
|
|
7189
|
+
chunk = chunk.slice(chunkLength);
|
|
7190
|
+
currentWriter.size += chunkLength;
|
|
7191
|
+
writer.size += chunkLength;
|
|
7192
|
+
writer.diskOffset += diskWritable.size = currentWriter.size;
|
|
7193
|
+
writer.diskNumber++;
|
|
7194
|
+
await diskWriter.close();
|
|
7195
|
+
diskWriter = null;
|
|
7196
|
+
await this.write(chunk);
|
|
7197
|
+
} else {
|
|
7198
|
+
await diskWriter.ready;
|
|
7199
|
+
await diskWriter.write(chunk);
|
|
7200
|
+
currentWriter.size += chunk.length;
|
|
7201
|
+
writer.size += chunk.length;
|
|
7202
|
+
}
|
|
7203
|
+
writer.availableSize = maxSize - currentWriter.size;
|
|
7204
|
+
},
|
|
7205
|
+
async close() {
|
|
7206
|
+
await diskWriter.ready;
|
|
7207
|
+
diskWritable.size = currentWriter.size;
|
|
7208
|
+
await diskWriter.close();
|
|
7209
|
+
}
|
|
7210
|
+
});
|
|
7211
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
7212
|
+
get() {
|
|
7213
|
+
return writable;
|
|
7214
|
+
}
|
|
7215
|
+
});
|
|
7216
|
+
}
|
|
7217
|
+
}
|
|
7218
|
+
|
|
7041
7219
|
function isHttpFamily(url) {
|
|
7042
7220
|
const { baseURL } = getConfiguration();
|
|
7043
7221
|
const { protocol } = new URL(url, baseURL);
|
|
@@ -7054,76 +7232,6 @@
|
|
|
7054
7232
|
return reader.readUint8Array(offset, size, diskNumber);
|
|
7055
7233
|
}
|
|
7056
7234
|
|
|
7057
|
-
/*
|
|
7058
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
7059
|
-
|
|
7060
|
-
Redistribution and use in source and binary forms, with or without
|
|
7061
|
-
modification, are permitted provided that the following conditions are met:
|
|
7062
|
-
|
|
7063
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
7064
|
-
this list of conditions and the following disclaimer.
|
|
7065
|
-
|
|
7066
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
7067
|
-
notice, this list of conditions and the following disclaimer in
|
|
7068
|
-
the documentation and/or other materials provided with the distribution.
|
|
7069
|
-
|
|
7070
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
7071
|
-
derived from this software without specific prior written permission.
|
|
7072
|
-
|
|
7073
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
7074
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
7075
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
7076
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
7077
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
7078
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
7079
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
7080
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
7081
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
7082
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7083
|
-
*/
|
|
7084
|
-
|
|
7085
|
-
const MAX_32_BITS = 0xffffffff;
|
|
7086
|
-
const MAX_16_BITS = 0xffff;
|
|
7087
|
-
const COMPRESSION_METHOD_DEFLATE = 0x08;
|
|
7088
|
-
const COMPRESSION_METHOD_STORE = 0x00;
|
|
7089
|
-
const COMPRESSION_METHOD_AES = 0x63;
|
|
7090
|
-
|
|
7091
|
-
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
7092
|
-
const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
|
|
7093
|
-
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
7094
|
-
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
7095
|
-
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
7096
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
|
|
7097
|
-
const END_OF_CENTRAL_DIR_LENGTH = 22;
|
|
7098
|
-
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
|
|
7099
|
-
const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
|
|
7100
|
-
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;
|
|
7101
|
-
|
|
7102
|
-
const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
|
|
7103
|
-
|
|
7104
|
-
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
7105
|
-
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
7106
|
-
const EXTRAFIELD_TYPE_NTFS = 0x000a;
|
|
7107
|
-
const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
|
|
7108
|
-
const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
|
|
7109
|
-
const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
|
|
7110
|
-
const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
|
|
7111
|
-
|
|
7112
|
-
const BITFLAG_ENCRYPTED = 0x01;
|
|
7113
|
-
const BITFLAG_LEVEL = 0x06;
|
|
7114
|
-
const BITFLAG_DATA_DESCRIPTOR = 0x0008;
|
|
7115
|
-
const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
|
|
7116
|
-
const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
|
|
7117
|
-
|
|
7118
|
-
const VERSION_DEFLATE = 0x14;
|
|
7119
|
-
const VERSION_ZIP64 = 0x2D;
|
|
7120
|
-
const VERSION_AES = 0x33;
|
|
7121
|
-
|
|
7122
|
-
const DIRECTORY_SIGNATURE = "/";
|
|
7123
|
-
|
|
7124
|
-
const MAX_DATE = new Date(2107, 11, 31);
|
|
7125
|
-
const MIN_DATE = new Date(1980, 0, 1);
|
|
7126
|
-
|
|
7127
7235
|
/*
|
|
7128
7236
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
7129
7237
|
|
|
@@ -7239,7 +7347,8 @@
|
|
|
7239
7347
|
"rawExtraField", "bitFlag", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
|
|
7240
7348
|
"extraFieldAES", "filenameUTF8", "commentUTF8", "offset", "zip64", "compressionMethod",
|
|
7241
7349
|
"extraFieldNTFS", "lastAccessDate", "creationDate", "extraFieldExtendedTimestamp",
|
|
7242
|
-
"version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute"
|
|
7350
|
+
"version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute",
|
|
7351
|
+
"diskNumberStart"];
|
|
7243
7352
|
|
|
7244
7353
|
class Entry {
|
|
7245
7354
|
|
|
@@ -7277,7 +7386,6 @@
|
|
|
7277
7386
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7278
7387
|
*/
|
|
7279
7388
|
|
|
7280
|
-
const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
|
|
7281
7389
|
const ERR_BAD_FORMAT = "File format is not recognized";
|
|
7282
7390
|
const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
|
|
7283
7391
|
const ERR_EOCDR_ZIP64_NOT_FOUND = "End of Zip64 central directory not found";
|
|
@@ -7328,7 +7436,7 @@
|
|
|
7328
7436
|
let { reader } = zipReader;
|
|
7329
7437
|
const { config } = zipReader;
|
|
7330
7438
|
await initStream(reader);
|
|
7331
|
-
if (reader.size ===
|
|
7439
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
7332
7440
|
if (Array.isArray(reader)) {
|
|
7333
7441
|
reader = new SplitZipReader(reader);
|
|
7334
7442
|
} else {
|
|
@@ -7350,15 +7458,16 @@
|
|
|
7350
7458
|
throw new Error(ERR_EOCDR_NOT_FOUND);
|
|
7351
7459
|
}
|
|
7352
7460
|
}
|
|
7353
|
-
const { lastDiskNumber } = reader;
|
|
7354
7461
|
const endOfDirectoryView = getDataView$1(endOfDirectoryInfo);
|
|
7355
7462
|
let directoryDataLength = getUint32(endOfDirectoryView, 12);
|
|
7356
7463
|
let directoryDataOffset = getUint32(endOfDirectoryView, 16);
|
|
7357
7464
|
const commentOffset = endOfDirectoryInfo.offset;
|
|
7358
7465
|
const commentLength = getUint16(endOfDirectoryView, 20);
|
|
7359
7466
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
7360
|
-
|
|
7361
|
-
|
|
7467
|
+
const lastDiskNumber = getUint16(endOfDirectoryView, 4);
|
|
7468
|
+
const expectedLastDiskNumber = reader.lastDiskNumber || 0;
|
|
7469
|
+
let diskNumber = getUint16(endOfDirectoryView, 6);
|
|
7470
|
+
if (expectedLastDiskNumber != lastDiskNumber) {
|
|
7362
7471
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
7363
7472
|
}
|
|
7364
7473
|
let filesLength = getUint16(endOfDirectoryView, 8);
|
|
@@ -7527,7 +7636,7 @@
|
|
|
7527
7636
|
compressedSize
|
|
7528
7637
|
} = zipEntry;
|
|
7529
7638
|
const localDirectory = zipEntry.localDirectory = {};
|
|
7530
|
-
|
|
7639
|
+
const dataArray = await readUint8Array(reader, offset, 30, diskNumberStart);
|
|
7531
7640
|
const dataView = getDataView$1(dataArray);
|
|
7532
7641
|
let password = getOptionValue$1(zipEntry, options, "password");
|
|
7533
7642
|
password = password && password.length && password;
|
|
@@ -7543,8 +7652,9 @@
|
|
|
7543
7652
|
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
7544
7653
|
}
|
|
7545
7654
|
readCommonHeader(localDirectory, dataView, 4);
|
|
7546
|
-
|
|
7547
|
-
|
|
7655
|
+
localDirectory.rawExtraField = localDirectory.extraFieldLength ?
|
|
7656
|
+
await readUint8Array(reader, offset + 30 + localDirectory.filenameLength, localDirectory.extraFieldLength, diskNumberStart) :
|
|
7657
|
+
new Uint8Array();
|
|
7548
7658
|
await readCommonFooter(zipEntry, localDirectory, dataView, 4);
|
|
7549
7659
|
Object.assign(fileEntry, {
|
|
7550
7660
|
lastAccessDate: localDirectory.lastAccessDate,
|
|
@@ -7553,7 +7663,7 @@
|
|
|
7553
7663
|
const encrypted = zipEntry.encrypted && localDirectory.encrypted;
|
|
7554
7664
|
const zipCrypto = encrypted && !extraFieldAES;
|
|
7555
7665
|
if (encrypted) {
|
|
7556
|
-
if (!zipCrypto && extraFieldAES.strength ===
|
|
7666
|
+
if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
|
|
7557
7667
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
7558
7668
|
} else if (!password) {
|
|
7559
7669
|
throw new Error(ERR_ENCRYPTED);
|
|
@@ -7570,7 +7680,7 @@
|
|
|
7570
7680
|
};
|
|
7571
7681
|
}
|
|
7572
7682
|
const { writable } = writer;
|
|
7573
|
-
if (writable.size ===
|
|
7683
|
+
if (writable.size === UNDEFINED_VALUE) {
|
|
7574
7684
|
writable.size = 0;
|
|
7575
7685
|
}
|
|
7576
7686
|
const signal = getOptionValue$1(zipEntry, options, "signal");
|
|
@@ -7818,7 +7928,7 @@
|
|
|
7818
7928
|
}
|
|
7819
7929
|
|
|
7820
7930
|
function getOptionValue$1(zipReader, options, name) {
|
|
7821
|
-
return options[name] ===
|
|
7931
|
+
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
7822
7932
|
}
|
|
7823
7933
|
|
|
7824
7934
|
function getDate(timeRaw) {
|
|
@@ -7897,7 +8007,7 @@
|
|
|
7897
8007
|
const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
|
|
7898
8008
|
|
|
7899
8009
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
7900
|
-
const EXTRAFIELD_LENGTH_ZIP64 =
|
|
8010
|
+
const EXTRAFIELD_LENGTH_ZIP64 = 28;
|
|
7901
8011
|
|
|
7902
8012
|
let workers = 0;
|
|
7903
8013
|
const pendingEntries = [];
|
|
@@ -7905,14 +8015,26 @@
|
|
|
7905
8015
|
class ZipWriter {
|
|
7906
8016
|
|
|
7907
8017
|
constructor(writer, options = {}) {
|
|
8018
|
+
if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
|
|
8019
|
+
writer = new SplitZipWriter(writer);
|
|
8020
|
+
}
|
|
7908
8021
|
if (writer instanceof WritableStream) {
|
|
7909
8022
|
writer = { writable: writer };
|
|
7910
8023
|
}
|
|
7911
|
-
if (writer.writable.size ===
|
|
8024
|
+
if (writer.writable.size === UNDEFINED_VALUE) {
|
|
7912
8025
|
writer.writable.size = 0;
|
|
7913
8026
|
}
|
|
8027
|
+
const splitZipFile = writer instanceof SplitZipWriter;
|
|
8028
|
+
if (!splitZipFile) {
|
|
8029
|
+
Object.assign(writer, {
|
|
8030
|
+
diskNumber: 0,
|
|
8031
|
+
diskOffset: 0,
|
|
8032
|
+
availableSize: Infinity
|
|
8033
|
+
});
|
|
8034
|
+
}
|
|
7914
8035
|
Object.assign(this, {
|
|
7915
8036
|
writer,
|
|
8037
|
+
addSplitZipSignature: splitZipFile,
|
|
7916
8038
|
options,
|
|
7917
8039
|
config: getConfiguration(),
|
|
7918
8040
|
files: new Map(),
|
|
@@ -8002,7 +8124,7 @@
|
|
|
8002
8124
|
const password = getOptionValue(zipWriter, options, "password");
|
|
8003
8125
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
8004
8126
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
8005
|
-
if (password !==
|
|
8127
|
+
if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
8006
8128
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
8007
8129
|
}
|
|
8008
8130
|
let rawExtraField = new Uint8Array();
|
|
@@ -8026,18 +8148,18 @@
|
|
|
8026
8148
|
});
|
|
8027
8149
|
}
|
|
8028
8150
|
let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
|
|
8029
|
-
if (extendedTimestamp ===
|
|
8151
|
+
if (extendedTimestamp === UNDEFINED_VALUE) {
|
|
8030
8152
|
extendedTimestamp = true;
|
|
8031
8153
|
}
|
|
8032
8154
|
let maximumCompressedSize = 0;
|
|
8033
8155
|
let maximumEntrySize = 0;
|
|
8034
8156
|
let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
|
|
8035
|
-
if (keepOrder ===
|
|
8157
|
+
if (keepOrder === UNDEFINED_VALUE) {
|
|
8036
8158
|
keepOrder = true;
|
|
8037
8159
|
}
|
|
8038
8160
|
let uncompressedSize = 0;
|
|
8039
8161
|
let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
|
|
8040
|
-
if (msDosCompatible ===
|
|
8162
|
+
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
8041
8163
|
msDosCompatible = true;
|
|
8042
8164
|
}
|
|
8043
8165
|
const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
|
|
@@ -8050,15 +8172,16 @@
|
|
|
8050
8172
|
};
|
|
8051
8173
|
}
|
|
8052
8174
|
await initStream(reader);
|
|
8053
|
-
if (reader.size ===
|
|
8175
|
+
if (reader.size === UNDEFINED_VALUE) {
|
|
8054
8176
|
options.dataDescriptor = true;
|
|
8055
|
-
if (zip64 ===
|
|
8177
|
+
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
8056
8178
|
zip64 = true;
|
|
8179
|
+
maximumCompressedSize = MAX_32_BITS;
|
|
8057
8180
|
}
|
|
8058
8181
|
} else {
|
|
8059
8182
|
uncompressedSize = reader.size;
|
|
8183
|
+
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
8060
8184
|
}
|
|
8061
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
8062
8185
|
}
|
|
8063
8186
|
if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
|
|
8064
8187
|
uncompressedSize >= MAX_32_BITS ||
|
|
@@ -8077,10 +8200,10 @@
|
|
|
8077
8200
|
let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
|
|
8078
8201
|
const signal = getOptionValue(zipWriter, options, "signal");
|
|
8079
8202
|
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
8080
|
-
if (dataDescriptor ===
|
|
8203
|
+
if (dataDescriptor === UNDEFINED_VALUE) {
|
|
8081
8204
|
dataDescriptor = true;
|
|
8082
8205
|
}
|
|
8083
|
-
if (dataDescriptor && dataDescriptorSignature ===
|
|
8206
|
+
if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
|
|
8084
8207
|
dataDescriptorSignature = false;
|
|
8085
8208
|
}
|
|
8086
8209
|
options = Object.assign({}, options, {
|
|
@@ -8163,10 +8286,21 @@
|
|
|
8163
8286
|
releaseLockWriter = () => delete zipWriter.lockWriter;
|
|
8164
8287
|
}
|
|
8165
8288
|
await initStream(fileWriter);
|
|
8289
|
+
const { writable, diskNumber } = writer;
|
|
8290
|
+
let { diskOffset } = writer;
|
|
8291
|
+
if (zipWriter.addSplitZipSignature) {
|
|
8292
|
+
delete zipWriter.addSplitZipSignature;
|
|
8293
|
+
const signatureArray = new Uint8Array(4);
|
|
8294
|
+
const signatureArrayView = new DataView(signatureArray.buffer);
|
|
8295
|
+
setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
|
|
8296
|
+
await writeData(writable, signatureArray);
|
|
8297
|
+
zipWriter.offset += 4;
|
|
8298
|
+
}
|
|
8166
8299
|
if (!bufferedWrite) {
|
|
8167
8300
|
await lockPreviousFileEntry;
|
|
8168
8301
|
}
|
|
8169
8302
|
writingEntryData = true;
|
|
8303
|
+
fileEntry.diskNumberStart = diskNumber;
|
|
8170
8304
|
fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
|
|
8171
8305
|
writingEntryData = false;
|
|
8172
8306
|
files.set(name, fileEntry);
|
|
@@ -8177,7 +8311,6 @@
|
|
|
8177
8311
|
await lockPreviousFileEntry;
|
|
8178
8312
|
await requestLockWriter();
|
|
8179
8313
|
writingBufferedEntryData = true;
|
|
8180
|
-
const { writable } = writer;
|
|
8181
8314
|
if (!dataDescriptor) {
|
|
8182
8315
|
const arrayBuffer = await sliceAsArrayBuffer(blob, 0, 26);
|
|
8183
8316
|
const arrayBufferView = new DataView(arrayBuffer);
|
|
@@ -8194,13 +8327,18 @@
|
|
|
8194
8327
|
await writeData(writable, new Uint8Array(arrayBuffer));
|
|
8195
8328
|
blob = blob.slice(arrayBuffer.byteLength);
|
|
8196
8329
|
}
|
|
8330
|
+
fileEntry.diskNumberStart = writer.diskNumber;
|
|
8331
|
+
diskOffset = writer.diskOffset;
|
|
8197
8332
|
await blob.stream().pipeTo(writable, { preventClose: true, signal });
|
|
8333
|
+
writable.size += blob.size;
|
|
8198
8334
|
writingBufferedEntryData = false;
|
|
8199
8335
|
}
|
|
8200
|
-
fileEntry.offset = zipWriter.offset;
|
|
8336
|
+
fileEntry.offset = zipWriter.offset - diskOffset;
|
|
8201
8337
|
if (fileEntry.zip64) {
|
|
8202
|
-
const
|
|
8203
|
-
|
|
8338
|
+
const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
|
|
8339
|
+
const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
|
|
8340
|
+
setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
|
|
8341
|
+
setUint32(rawExtraFieldZip64View, 28, diskNumberStart);
|
|
8204
8342
|
} else if (fileEntry.offset >= MAX_32_BITS) {
|
|
8205
8343
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
8206
8344
|
}
|
|
@@ -8244,7 +8382,7 @@
|
|
|
8244
8382
|
}
|
|
8245
8383
|
}
|
|
8246
8384
|
|
|
8247
|
-
async function createFileEntry(reader, writer,
|
|
8385
|
+
async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryInfo, config, options) {
|
|
8248
8386
|
const {
|
|
8249
8387
|
headerInfo,
|
|
8250
8388
|
dataDescriptorInfo
|
|
@@ -8289,7 +8427,7 @@
|
|
|
8289
8427
|
useCompressionStream
|
|
8290
8428
|
} = options;
|
|
8291
8429
|
const fileEntry = {
|
|
8292
|
-
lock
|
|
8430
|
+
lock,
|
|
8293
8431
|
versionMadeBy,
|
|
8294
8432
|
zip64,
|
|
8295
8433
|
directory: Boolean(directory),
|
|
@@ -8304,7 +8442,8 @@
|
|
|
8304
8442
|
extendedTimestamp,
|
|
8305
8443
|
msDosCompatible,
|
|
8306
8444
|
internalFileAttribute,
|
|
8307
|
-
externalFileAttribute
|
|
8445
|
+
externalFileAttribute,
|
|
8446
|
+
diskNumberStart
|
|
8308
8447
|
};
|
|
8309
8448
|
let uncompressedSize = 0;
|
|
8310
8449
|
let signature;
|
|
@@ -8547,7 +8686,7 @@
|
|
|
8547
8686
|
zipCrypto,
|
|
8548
8687
|
dataDescriptor
|
|
8549
8688
|
} = options;
|
|
8550
|
-
if ((!encrypted || zipCrypto) && signature !==
|
|
8689
|
+
if ((!encrypted || zipCrypto) && signature !== UNDEFINED_VALUE) {
|
|
8551
8690
|
setUint32(headerView, 10, signature);
|
|
8552
8691
|
if (dataDescriptor) {
|
|
8553
8692
|
setUint32(dataDescriptorView, dataDescriptorOffset, signature);
|
|
@@ -8576,10 +8715,12 @@
|
|
|
8576
8715
|
}
|
|
8577
8716
|
|
|
8578
8717
|
async function closeFile(zipWriter, comment, options) {
|
|
8579
|
-
const { files } = zipWriter;
|
|
8718
|
+
const { files, writer } = zipWriter;
|
|
8580
8719
|
let offset = 0;
|
|
8581
8720
|
let directoryDataLength = 0;
|
|
8582
|
-
|
|
8721
|
+
const { diskOffset, writable } = writer;
|
|
8722
|
+
let { diskNumber } = writer;
|
|
8723
|
+
let directoryOffset = zipWriter.offset - diskOffset;
|
|
8583
8724
|
let filesLength = files.size;
|
|
8584
8725
|
for (const [, {
|
|
8585
8726
|
rawFilename,
|
|
@@ -8608,7 +8749,7 @@
|
|
|
8608
8749
|
zip64 = true;
|
|
8609
8750
|
}
|
|
8610
8751
|
}
|
|
8611
|
-
const directoryArray = new Uint8Array(directoryDataLength
|
|
8752
|
+
const directoryArray = new Uint8Array(directoryDataLength);
|
|
8612
8753
|
const directoryView = getDataView(directoryArray);
|
|
8613
8754
|
for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
|
|
8614
8755
|
const {
|
|
@@ -8627,7 +8768,8 @@
|
|
|
8627
8768
|
internalFileAttribute,
|
|
8628
8769
|
externalFileAttribute,
|
|
8629
8770
|
extendedTimestamp,
|
|
8630
|
-
lastModDate
|
|
8771
|
+
lastModDate,
|
|
8772
|
+
diskNumberStart
|
|
8631
8773
|
} = fileEntry;
|
|
8632
8774
|
let rawExtraFieldExtendedTimestamp;
|
|
8633
8775
|
if (extendedTimestamp) {
|
|
@@ -8646,17 +8788,14 @@
|
|
|
8646
8788
|
arraySet(directoryArray, headerArray, offset + 6);
|
|
8647
8789
|
setUint16(directoryView, offset + 30, extraFieldLength);
|
|
8648
8790
|
setUint16(directoryView, offset + 32, getLength(rawComment));
|
|
8791
|
+
setUint16(directoryView, offset + 34, zip64 ? MAX_16_BITS : diskNumberStart);
|
|
8649
8792
|
setUint16(directoryView, offset + 36, internalFileAttribute);
|
|
8650
8793
|
if (externalFileAttribute) {
|
|
8651
8794
|
setUint32(directoryView, offset + 38, externalFileAttribute);
|
|
8652
8795
|
} else if (directory && msDosCompatible) {
|
|
8653
8796
|
setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
|
|
8654
8797
|
}
|
|
8655
|
-
|
|
8656
|
-
setUint32(directoryView, offset + 42, MAX_32_BITS);
|
|
8657
|
-
} else {
|
|
8658
|
-
setUint32(directoryView, offset + 42, fileEntryOffset);
|
|
8659
|
-
}
|
|
8798
|
+
setUint32(directoryView, offset + 42, zip64 ? MAX_32_BITS : fileEntryOffset);
|
|
8660
8799
|
arraySet(directoryArray, rawFilename, offset + 46);
|
|
8661
8800
|
arraySet(directoryArray, rawExtraFieldZip64, offset + 46 + getLength(rawFilename));
|
|
8662
8801
|
arraySet(directoryArray, rawExtraFieldAES, offset + 46 + getLength(rawFilename, rawExtraFieldZip64));
|
|
@@ -8673,39 +8812,52 @@
|
|
|
8673
8812
|
}
|
|
8674
8813
|
}
|
|
8675
8814
|
}
|
|
8815
|
+
await initStream(writer);
|
|
8816
|
+
await writeData(writable, directoryArray);
|
|
8817
|
+
const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
|
|
8818
|
+
const endOfdirectoryView = getDataView(endOfdirectoryArray);
|
|
8819
|
+
let lastDiskNumber = writer.diskNumber;
|
|
8820
|
+
const { availableSize } = writer;
|
|
8821
|
+
if (availableSize < endOfdirectoryArray.length) {
|
|
8822
|
+
lastDiskNumber++;
|
|
8823
|
+
}
|
|
8824
|
+
offset = 0;
|
|
8676
8825
|
if (zip64) {
|
|
8677
|
-
setUint32(
|
|
8678
|
-
setBigUint64(
|
|
8679
|
-
setUint16(
|
|
8680
|
-
setUint16(
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
setBigUint64(
|
|
8684
|
-
setBigUint64(
|
|
8685
|
-
|
|
8686
|
-
setBigUint64(
|
|
8687
|
-
setUint32(
|
|
8826
|
+
setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
|
|
8827
|
+
setBigUint64(endOfdirectoryView, 4, BigInt(44));
|
|
8828
|
+
setUint16(endOfdirectoryView, 12, 45);
|
|
8829
|
+
setUint16(endOfdirectoryView, 14, 45);
|
|
8830
|
+
setUint32(endOfdirectoryView, 16, lastDiskNumber);
|
|
8831
|
+
setUint32(endOfdirectoryView, 20, diskNumber);
|
|
8832
|
+
setBigUint64(endOfdirectoryView, 24, BigInt(filesLength));
|
|
8833
|
+
setBigUint64(endOfdirectoryView, 32, BigInt(filesLength));
|
|
8834
|
+
setBigUint64(endOfdirectoryView, 40, BigInt(directoryDataLength));
|
|
8835
|
+
setBigUint64(endOfdirectoryView, 48, BigInt(directoryOffset));
|
|
8836
|
+
setUint32(endOfdirectoryView, 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
|
|
8837
|
+
setBigUint64(endOfdirectoryView, 64, BigInt(directoryOffset) + BigInt(directoryDataLength));
|
|
8838
|
+
setUint32(endOfdirectoryView, 72, lastDiskNumber + 1);
|
|
8839
|
+
diskNumber = MAX_16_BITS;
|
|
8688
8840
|
filesLength = MAX_16_BITS;
|
|
8689
8841
|
directoryOffset = MAX_32_BITS;
|
|
8690
8842
|
directoryDataLength = MAX_32_BITS;
|
|
8691
|
-
offset +=
|
|
8692
|
-
}
|
|
8693
|
-
setUint32(
|
|
8694
|
-
setUint16(
|
|
8695
|
-
setUint16(
|
|
8696
|
-
|
|
8697
|
-
|
|
8843
|
+
offset += ZIP64_END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH;
|
|
8844
|
+
}
|
|
8845
|
+
setUint32(endOfdirectoryView, offset, END_OF_CENTRAL_DIR_SIGNATURE);
|
|
8846
|
+
setUint16(endOfdirectoryView, offset + 4, lastDiskNumber);
|
|
8847
|
+
setUint16(endOfdirectoryView, offset + 6, diskNumber);
|
|
8848
|
+
setUint16(endOfdirectoryView, offset + 8, filesLength);
|
|
8849
|
+
setUint16(endOfdirectoryView, offset + 10, filesLength);
|
|
8850
|
+
setUint32(endOfdirectoryView, offset + 12, directoryDataLength);
|
|
8851
|
+
setUint32(endOfdirectoryView, offset + 16, directoryOffset);
|
|
8698
8852
|
const commentLength = getLength(comment);
|
|
8699
8853
|
if (commentLength) {
|
|
8700
8854
|
if (commentLength <= MAX_16_BITS) {
|
|
8701
|
-
setUint16(
|
|
8855
|
+
setUint16(endOfdirectoryView, offset + 20, commentLength);
|
|
8702
8856
|
} else {
|
|
8703
8857
|
throw new Error(ERR_INVALID_COMMENT);
|
|
8704
8858
|
}
|
|
8705
8859
|
}
|
|
8706
|
-
|
|
8707
|
-
await initStream(zipWriter.writer);
|
|
8708
|
-
await writeData(writable, directoryArray);
|
|
8860
|
+
await writeData(writable, endOfdirectoryArray);
|
|
8709
8861
|
if (commentLength) {
|
|
8710
8862
|
await writeData(writable, comment);
|
|
8711
8863
|
}
|
|
@@ -8734,7 +8886,7 @@
|
|
|
8734
8886
|
}
|
|
8735
8887
|
|
|
8736
8888
|
function getOptionValue(zipWriter, options, name) {
|
|
8737
|
-
return options[name] ===
|
|
8889
|
+
return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
|
|
8738
8890
|
}
|
|
8739
8891
|
|
|
8740
8892
|
function getMaximumCompressedSize(uncompressedSize) {
|
|
@@ -8830,6 +8982,7 @@
|
|
|
8830
8982
|
exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
|
|
8831
8983
|
exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
|
|
8832
8984
|
exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
|
|
8985
|
+
exports.ERR_ITERATOR_COMPLETED_TOO_SOON = ERR_ITERATOR_COMPLETED_TOO_SOON;
|
|
8833
8986
|
exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
|
|
8834
8987
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
8835
8988
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
|
|
@@ -8839,6 +8992,7 @@
|
|
|
8839
8992
|
exports.HttpReader = HttpReader;
|
|
8840
8993
|
exports.Reader = Reader;
|
|
8841
8994
|
exports.SplitZipReader = SplitZipReader;
|
|
8995
|
+
exports.SplitZipWriter = SplitZipWriter;
|
|
8842
8996
|
exports.TextReader = TextReader;
|
|
8843
8997
|
exports.TextWriter = TextWriter;
|
|
8844
8998
|
exports.Uint8ArrayReader = Uint8ArrayReader;
|