@zip.js/zip.js 2.8.48 → 2.8.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist/zip-core-external.js +351 -205
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +357 -205
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +438 -216
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +213 -435
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +438 -216
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +447 -219
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +445 -217
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +359 -207
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +360 -208
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +358 -206
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +446 -218
- package/index-native.min.js +1 -1
- package/index.cjs +444 -216
- package/index.d.cts +124 -2
- package/index.d.ts +124 -2
- package/index.min.js +1 -1
- package/lib/core/codec-pool.js +1 -1
- package/lib/core/codec-registry.js +2 -2
- package/lib/core/codec-worker-web.js +436 -0
- package/lib/core/codec-worker.js +23 -388
- package/lib/core/constants.js +5 -1
- package/lib/core/io.js +2 -1
- package/lib/core/options.js +8 -0
- package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
- package/lib/core/web-worker-base.js +10 -2
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-fs.js +88 -12
- package/lib/core/zip-reader.js +90 -16
- package/lib/core/zip-writer.js +36 -13
- package/lib/zip-core-reader.js +6 -0
- package/lib/zip-core-writer.js +4 -0
- package/package.json +1 -1
- package/worker-message-property-names.js +1 -1
|
@@ -108,6 +108,8 @@ const INFINITY_VALUE = Infinity;
|
|
|
108
108
|
const UNDEFINED_TYPE = "undefined";
|
|
109
109
|
const FUNCTION_TYPE = "function";
|
|
110
110
|
const OBJECT_TYPE = "object";
|
|
111
|
+
const STRING_TYPE = "string";
|
|
112
|
+
const NUMBER_TYPE = "number";
|
|
111
113
|
|
|
112
114
|
const EMPTY_UINT8_ARRAY = new Uint8Array();
|
|
113
115
|
|
|
@@ -273,7 +275,7 @@ function configureExternalAssets() {
|
|
|
273
275
|
}
|
|
274
276
|
|
|
275
277
|
/*
|
|
276
|
-
Copyright (c)
|
|
278
|
+
Copyright (c) 2026 Gildas Lormeau. All rights reserved.
|
|
277
279
|
|
|
278
280
|
Redistribution and use in source and binary forms, with or without
|
|
279
281
|
modification, are permitted provided that the following conditions are met:
|
|
@@ -301,72 +303,19 @@ function configureExternalAssets() {
|
|
|
301
303
|
*/
|
|
302
304
|
|
|
303
305
|
|
|
304
|
-
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const RESERVED_COMPRESSION_METHODS = [
|
|
310
|
-
COMPRESSION_METHOD_STORE,
|
|
311
|
-
COMPRESSION_METHOD_DEFLATE,
|
|
312
|
-
COMPRESSION_METHOD_DEFLATE_64,
|
|
313
|
-
COMPRESSION_METHOD_AES
|
|
314
|
-
];
|
|
315
|
-
|
|
316
|
-
const registeredCodecs = new Map();
|
|
317
|
-
const codecStreams = new Map();
|
|
318
|
-
|
|
319
|
-
function registerCodec(codec = {}) {
|
|
320
|
-
const { compressionMethod, format, codecURI, CompressionStream, DecompressionStream, versionNeeded } = codec;
|
|
321
|
-
if (!Number.isInteger(compressionMethod) || compressionMethod < 0 || compressionMethod > MAX_16_BITS ||
|
|
322
|
-
typeof format != STRING_TYPE || !format.length) {
|
|
323
|
-
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
324
|
-
}
|
|
325
|
-
if (RESERVED_COMPRESSION_METHODS.includes(compressionMethod)) {
|
|
326
|
-
throw new Error(ERR_RESERVED_COMPRESSION_METHOD);
|
|
327
|
-
}
|
|
328
|
-
const hasStreams = typeof CompressionStream == FUNCTION_TYPE || typeof DecompressionStream == FUNCTION_TYPE;
|
|
329
|
-
if (!hasStreams && (typeof codecURI != STRING_TYPE || !codecURI.length)) {
|
|
330
|
-
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
331
|
-
}
|
|
332
|
-
registeredCodecs.set(compressionMethod, { compressionMethod, format, codecURI, versionNeeded });
|
|
333
|
-
if (hasStreams) {
|
|
334
|
-
setCodecStreams(format, { CompressionStream, DecompressionStream });
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function unregisterCodec(compressionMethod) {
|
|
339
|
-
const codec = registeredCodecs.get(compressionMethod);
|
|
340
|
-
if (codec) {
|
|
341
|
-
registeredCodecs.delete(compressionMethod);
|
|
342
|
-
let formatUsed;
|
|
343
|
-
registeredCodecs.forEach(otherCodec => formatUsed = formatUsed || otherCodec.format == codec.format);
|
|
344
|
-
if (!formatUsed) {
|
|
345
|
-
codecStreams.delete(codec.format);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function getRegisteredCodec(compressionMethod) {
|
|
351
|
-
return registeredCodecs.get(compressionMethod);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function getCodecStreams(format) {
|
|
355
|
-
return codecStreams.get(format);
|
|
306
|
+
function concat(first, second) {
|
|
307
|
+
const result = new Uint8Array(first.length + second.length);
|
|
308
|
+
result.set(first);
|
|
309
|
+
result.set(second, first.length);
|
|
310
|
+
return result;
|
|
356
311
|
}
|
|
357
312
|
|
|
358
|
-
function
|
|
359
|
-
|
|
360
|
-
if (typeof CompressionStream != FUNCTION_TYPE && typeof DecompressionStream != FUNCTION_TYPE) {
|
|
361
|
-
throw new Error(ERR_INVALID_CODEC_MODULE);
|
|
362
|
-
}
|
|
363
|
-
codecStreams.set(format, { CompressionStream, DecompressionStream });
|
|
313
|
+
function toExactUint8Array(array) {
|
|
314
|
+
return array.byteOffset || array.byteLength != array.buffer.byteLength ? new Uint8Array(array) : array;
|
|
364
315
|
}
|
|
365
316
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
setCodecStreams(format, await import(/* webpackIgnore: true */ /* @vite-ignore */ codecURI));
|
|
369
|
-
}
|
|
317
|
+
function getDataView(array) {
|
|
318
|
+
return new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
370
319
|
}
|
|
371
320
|
|
|
372
321
|
/*
|
|
@@ -551,50 +500,6 @@ function encodeText(value) {
|
|
|
551
500
|
}
|
|
552
501
|
}
|
|
553
502
|
|
|
554
|
-
/*
|
|
555
|
-
Copyright (c) 2026 Gildas Lormeau. All rights reserved.
|
|
556
|
-
|
|
557
|
-
Redistribution and use in source and binary forms, with or without
|
|
558
|
-
modification, are permitted provided that the following conditions are met:
|
|
559
|
-
|
|
560
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
561
|
-
this list of conditions and the following disclaimer.
|
|
562
|
-
|
|
563
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
564
|
-
notice, this list of conditions and the following disclaimer in
|
|
565
|
-
the documentation and/or other materials provided with the distribution.
|
|
566
|
-
|
|
567
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
568
|
-
derived from this software without specific prior written permission.
|
|
569
|
-
|
|
570
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
571
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
572
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
573
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
574
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
575
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
576
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
577
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
578
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
579
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
580
|
-
*/
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
function concat(first, second) {
|
|
584
|
-
const result = new Uint8Array(first.length + second.length);
|
|
585
|
-
result.set(first);
|
|
586
|
-
result.set(second, first.length);
|
|
587
|
-
return result;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
function toExactUint8Array(array) {
|
|
591
|
-
return array.byteOffset || array.byteLength != array.buffer.byteLength ? new Uint8Array(array) : array;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
function getDataView(array) {
|
|
595
|
-
return new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
596
|
-
}
|
|
597
|
-
|
|
598
503
|
// Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl
|
|
599
504
|
|
|
600
505
|
// deno-lint-ignore-file no-this-alias
|
|
@@ -1964,6 +1869,102 @@ function toCompatibleWritable(writable) {
|
|
|
1964
1869
|
});
|
|
1965
1870
|
}
|
|
1966
1871
|
|
|
1872
|
+
/*
|
|
1873
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
1874
|
+
|
|
1875
|
+
Redistribution and use in source and binary forms, with or without
|
|
1876
|
+
modification, are permitted provided that the following conditions are met:
|
|
1877
|
+
|
|
1878
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
1879
|
+
this list of conditions and the following disclaimer.
|
|
1880
|
+
|
|
1881
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
1882
|
+
notice, this list of conditions and the following disclaimer in
|
|
1883
|
+
the documentation and/or other materials provided with the distribution.
|
|
1884
|
+
|
|
1885
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
1886
|
+
derived from this software without specific prior written permission.
|
|
1887
|
+
|
|
1888
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
1889
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
1890
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
1891
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
1892
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
1893
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
1894
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
1895
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
1896
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
1897
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1898
|
+
*/
|
|
1899
|
+
|
|
1900
|
+
|
|
1901
|
+
const ERR_INVALID_CODEC_DEFINITION = "Invalid codec definition";
|
|
1902
|
+
const ERR_RESERVED_COMPRESSION_METHOD = "Reserved compression method";
|
|
1903
|
+
const ERR_INVALID_CODEC_MODULE = "Invalid codec module";
|
|
1904
|
+
|
|
1905
|
+
const RESERVED_COMPRESSION_METHODS = [
|
|
1906
|
+
COMPRESSION_METHOD_STORE,
|
|
1907
|
+
COMPRESSION_METHOD_DEFLATE,
|
|
1908
|
+
COMPRESSION_METHOD_DEFLATE_64,
|
|
1909
|
+
COMPRESSION_METHOD_AES
|
|
1910
|
+
];
|
|
1911
|
+
|
|
1912
|
+
const registeredCodecs = new Map();
|
|
1913
|
+
const codecStreams = new Map();
|
|
1914
|
+
|
|
1915
|
+
function registerCodec(codec = {}) {
|
|
1916
|
+
const { compressionMethod, format, codecURI, CompressionStream, DecompressionStream, versionNeeded } = codec;
|
|
1917
|
+
if (!Number.isInteger(compressionMethod) || compressionMethod < 0 || compressionMethod > MAX_16_BITS ||
|
|
1918
|
+
typeof format != STRING_TYPE || !format.length) {
|
|
1919
|
+
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
1920
|
+
}
|
|
1921
|
+
if (RESERVED_COMPRESSION_METHODS.includes(compressionMethod)) {
|
|
1922
|
+
throw new Error(ERR_RESERVED_COMPRESSION_METHOD);
|
|
1923
|
+
}
|
|
1924
|
+
const hasStreams = typeof CompressionStream == FUNCTION_TYPE || typeof DecompressionStream == FUNCTION_TYPE;
|
|
1925
|
+
if (!hasStreams && (typeof codecURI != STRING_TYPE || !codecURI.length)) {
|
|
1926
|
+
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
1927
|
+
}
|
|
1928
|
+
registeredCodecs.set(compressionMethod, { compressionMethod, format, codecURI, versionNeeded });
|
|
1929
|
+
if (hasStreams) {
|
|
1930
|
+
setCodecStreams(format, { CompressionStream, DecompressionStream });
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
function unregisterCodec(compressionMethod) {
|
|
1935
|
+
const codec = registeredCodecs.get(compressionMethod);
|
|
1936
|
+
if (codec) {
|
|
1937
|
+
registeredCodecs.delete(compressionMethod);
|
|
1938
|
+
let formatUsed;
|
|
1939
|
+
registeredCodecs.forEach(otherCodec => formatUsed = formatUsed || otherCodec.format == codec.format);
|
|
1940
|
+
if (!formatUsed) {
|
|
1941
|
+
codecStreams.delete(codec.format);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
function getRegisteredCodec(compressionMethod) {
|
|
1947
|
+
return registeredCodecs.get(compressionMethod);
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
function getCodecStreams(format) {
|
|
1951
|
+
return codecStreams.get(format);
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
function setCodecStreams(format, streams) {
|
|
1955
|
+
const { CompressionStream, DecompressionStream } = streams;
|
|
1956
|
+
if (typeof CompressionStream != FUNCTION_TYPE && typeof DecompressionStream != FUNCTION_TYPE) {
|
|
1957
|
+
throw new Error(ERR_INVALID_CODEC_MODULE);
|
|
1958
|
+
}
|
|
1959
|
+
codecStreams.set(format, { CompressionStream, DecompressionStream });
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
async function ensureCodecStreams(format, codecURI) {
|
|
1963
|
+
if (!codecStreams.has(format) && codecURI) {
|
|
1964
|
+
setCodecStreams(format, await import(/* webpackIgnore: true */ /* @vite-ignore */ codecURI));
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1967
1968
|
/*
|
|
1968
1969
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
1969
1970
|
|
|
@@ -2517,8 +2518,8 @@ class ChunkStream extends TransformStream {
|
|
|
2517
2518
|
1. Redistributions of source code must retain the above copyright notice,
|
|
2518
2519
|
this list of conditions and the following disclaimer.
|
|
2519
2520
|
|
|
2520
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
2521
|
-
notice, this list of conditions and the following disclaimer in
|
|
2521
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2522
|
+
notice, this list of conditions and the following disclaimer in
|
|
2522
2523
|
the documentation and/or other materials provided with the distribution.
|
|
2523
2524
|
|
|
2524
2525
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -2537,24 +2538,19 @@ class ChunkStream extends TransformStream {
|
|
|
2537
2538
|
*/
|
|
2538
2539
|
|
|
2539
2540
|
|
|
2540
|
-
const MODULE_WORKER_OPTIONS = { type: "module" };
|
|
2541
|
-
const ERROR_EVENT_TYPE = "error";
|
|
2542
|
-
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2543
2541
|
const ERR_WORKER_STARTUP_TIMEOUT = "Worker startup timeout";
|
|
2544
2542
|
|
|
2545
|
-
let webWorkerSupported,
|
|
2546
|
-
let transferStreamsSupported = true;
|
|
2547
|
-
try {
|
|
2548
|
-
transferStreamsSupported = typeof structuredClone == FUNCTION_TYPE && structuredClone(new DOMException("", "AbortError")).code !== UNDEFINED_VALUE;
|
|
2549
|
-
} catch {
|
|
2550
|
-
// ignored
|
|
2551
|
-
}
|
|
2543
|
+
let webWorkerSupported, createWorkerFailed, webWorkerBackend;
|
|
2552
2544
|
let initModule$1 = () => { };
|
|
2553
2545
|
|
|
2554
2546
|
function configureWorker({ initModule: initModuleFunction }) {
|
|
2555
2547
|
initModule$1 = initModuleFunction;
|
|
2556
2548
|
}
|
|
2557
2549
|
|
|
2550
|
+
function setWebWorkerBackend(backend) {
|
|
2551
|
+
webWorkerBackend = backend;
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2558
2554
|
async function supportsDeflate(config) {
|
|
2559
2555
|
const { CompressionStream: NativeStream, CompressionStreamFallback: FallbackStream } = config;
|
|
2560
2556
|
if (FallbackStream && !FallbackStream.requiresModule) {
|
|
@@ -2579,6 +2575,14 @@ function resetWebWorkerSupport() {
|
|
|
2579
2575
|
createWorkerFailed = false;
|
|
2580
2576
|
}
|
|
2581
2577
|
|
|
2578
|
+
function disableWebWorker(workerData) {
|
|
2579
|
+
if (workerData.createWorker) {
|
|
2580
|
+
createWorkerFailed = true;
|
|
2581
|
+
} else {
|
|
2582
|
+
webWorkerSupported = false;
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2582
2586
|
class CodecWorker {
|
|
2583
2587
|
|
|
2584
2588
|
constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI, createWorker }, onTaskFinished) {
|
|
@@ -2631,7 +2635,7 @@ class CodecWorker {
|
|
|
2631
2635
|
// deno-lint-ignore valid-typeof
|
|
2632
2636
|
webWorkerSupported = typeof Worker != UNDEFINED_TYPE;
|
|
2633
2637
|
}
|
|
2634
|
-
return (useWebWorkers && ((webWorkerSupported && workerURI) || createWorker) ?
|
|
2638
|
+
return (useWebWorkers && webWorkerBackend && ((webWorkerSupported && workerURI) || createWorker) ? webWorkerBackend : createWorkerInterface)(workerData, config);
|
|
2635
2639
|
}
|
|
2636
2640
|
}
|
|
2637
2641
|
|
|
@@ -2675,58 +2679,6 @@ function createWorkerInterface(workerData, config) {
|
|
|
2675
2679
|
};
|
|
2676
2680
|
}
|
|
2677
2681
|
|
|
2678
|
-
function createWebWorkerInterface(workerData, config) {
|
|
2679
|
-
const { baseURI, chunkSize, workerStartupTimeout } = config;
|
|
2680
|
-
let { wasmURI } = config;
|
|
2681
|
-
|
|
2682
|
-
if (!workerData.interface) {
|
|
2683
|
-
// deno-lint-ignore valid-typeof
|
|
2684
|
-
if (typeof wasmURI == FUNCTION_TYPE) {
|
|
2685
|
-
wasmURI = wasmURI();
|
|
2686
|
-
}
|
|
2687
|
-
let worker;
|
|
2688
|
-
try {
|
|
2689
|
-
worker = getWebWorker(workerData.workerURI, baseURI, workerData);
|
|
2690
|
-
} catch {
|
|
2691
|
-
if (workerData.createWorker) {
|
|
2692
|
-
createWorkerFailed = true;
|
|
2693
|
-
} else {
|
|
2694
|
-
webWorkerSupported = false;
|
|
2695
|
-
}
|
|
2696
|
-
return createWorkerInterface(workerData, config);
|
|
2697
|
-
}
|
|
2698
|
-
Object.assign(workerData, {
|
|
2699
|
-
worker,
|
|
2700
|
-
workerAlive: false,
|
|
2701
|
-
terminated: false,
|
|
2702
|
-
interface: {
|
|
2703
|
-
run: async () => {
|
|
2704
|
-
try {
|
|
2705
|
-
return await runWebWorker(workerData, { chunkSize, wasmURI, baseURI, workerStartupTimeout });
|
|
2706
|
-
} catch (error) {
|
|
2707
|
-
if (error && error.workerStartupFailed) {
|
|
2708
|
-
if (workerData.createWorker) {
|
|
2709
|
-
createWorkerFailed = true;
|
|
2710
|
-
} else {
|
|
2711
|
-
webWorkerSupported = false;
|
|
2712
|
-
}
|
|
2713
|
-
const { reader } = workerData;
|
|
2714
|
-
if (reader) {
|
|
2715
|
-
reader.releaseLock();
|
|
2716
|
-
}
|
|
2717
|
-
workerData.reader = null;
|
|
2718
|
-
workerData.writer = null;
|
|
2719
|
-
return runWorker$1(workerData, config);
|
|
2720
|
-
}
|
|
2721
|
-
throw error;
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
}
|
|
2725
|
-
});
|
|
2726
|
-
}
|
|
2727
|
-
return workerData.interface;
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
2682
|
async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
|
|
2731
2683
|
let codecStream;
|
|
2732
2684
|
try {
|
|
@@ -2775,6 +2727,95 @@ async function runWorker$1({ options, readable, writable, onTaskFinished }, conf
|
|
|
2775
2727
|
}
|
|
2776
2728
|
}
|
|
2777
2729
|
|
|
2730
|
+
/*
|
|
2731
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
2732
|
+
|
|
2733
|
+
Redistribution and use in source and binary forms, with or without
|
|
2734
|
+
modification, are permitted provided that the following conditions are met:
|
|
2735
|
+
|
|
2736
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
2737
|
+
this list of conditions and the following disclaimer.
|
|
2738
|
+
|
|
2739
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
2740
|
+
notice, this list of conditions and the following disclaimer in
|
|
2741
|
+
the documentation and/or other materials provided with the distribution.
|
|
2742
|
+
|
|
2743
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
2744
|
+
derived from this software without specific prior written permission.
|
|
2745
|
+
|
|
2746
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
2747
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
2748
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
2749
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
2750
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
2751
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
2752
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
2753
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
2754
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
2755
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2756
|
+
*/
|
|
2757
|
+
|
|
2758
|
+
|
|
2759
|
+
const MODULE_WORKER_OPTIONS = { type: "module" };
|
|
2760
|
+
const ERROR_EVENT_TYPE = "error";
|
|
2761
|
+
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2762
|
+
|
|
2763
|
+
let webWorkerSource, webWorkerURI, webWorkerOptions;
|
|
2764
|
+
let transferStreamsSupported = true;
|
|
2765
|
+
try {
|
|
2766
|
+
transferStreamsSupported = typeof structuredClone == FUNCTION_TYPE && structuredClone(new DOMException("", "AbortError")).code !== UNDEFINED_VALUE;
|
|
2767
|
+
} catch {
|
|
2768
|
+
// ignored
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
setWebWorkerBackend(createWebWorkerInterface);
|
|
2772
|
+
|
|
2773
|
+
function createWebWorkerInterface(workerData, config) {
|
|
2774
|
+
const { baseURI, chunkSize, workerStartupTimeout } = config;
|
|
2775
|
+
let { wasmURI } = config;
|
|
2776
|
+
|
|
2777
|
+
if (!workerData.interface) {
|
|
2778
|
+
// deno-lint-ignore valid-typeof
|
|
2779
|
+
if (typeof wasmURI == FUNCTION_TYPE) {
|
|
2780
|
+
wasmURI = wasmURI();
|
|
2781
|
+
}
|
|
2782
|
+
let worker;
|
|
2783
|
+
try {
|
|
2784
|
+
worker = getWebWorker(workerData.workerURI, baseURI, workerData);
|
|
2785
|
+
} catch {
|
|
2786
|
+
disableWebWorker(workerData);
|
|
2787
|
+
return createWorkerInterface(workerData, config);
|
|
2788
|
+
}
|
|
2789
|
+
Object.assign(workerData, {
|
|
2790
|
+
worker,
|
|
2791
|
+
workerAlive: false,
|
|
2792
|
+
terminated: false,
|
|
2793
|
+
interface: {
|
|
2794
|
+
run: async () => {
|
|
2795
|
+
try {
|
|
2796
|
+
return await runWebWorker(workerData, { chunkSize, wasmURI, baseURI, workerStartupTimeout });
|
|
2797
|
+
} catch (error) {
|
|
2798
|
+
if (error && error.workerStartupFailed) {
|
|
2799
|
+
disableWebWorker(workerData);
|
|
2800
|
+
releaseWorkerStreams(workerData);
|
|
2801
|
+
return runWorker$1(workerData, config);
|
|
2802
|
+
}
|
|
2803
|
+
if (error && error.codecImportFailed) {
|
|
2804
|
+
if (workerData.reader) {
|
|
2805
|
+
releaseWorkerStreams(workerData);
|
|
2806
|
+
return runWorker$1(workerData, config);
|
|
2807
|
+
}
|
|
2808
|
+
workerData.onTaskFinished();
|
|
2809
|
+
}
|
|
2810
|
+
throw error;
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
});
|
|
2815
|
+
}
|
|
2816
|
+
return workerData.interface;
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2778
2819
|
async function runWebWorker(workerData, config) {
|
|
2779
2820
|
let resolveResult, rejectResult;
|
|
2780
2821
|
const result = new Promise((resolve, reject) => {
|
|
@@ -2854,6 +2895,15 @@ function watchClosedStream(writableSource) {
|
|
|
2854
2895
|
return { writable, closed, abortPipe: () => abortController.abort() };
|
|
2855
2896
|
}
|
|
2856
2897
|
|
|
2898
|
+
function releaseWorkerStreams(workerData) {
|
|
2899
|
+
const { reader } = workerData;
|
|
2900
|
+
if (reader) {
|
|
2901
|
+
reader.releaseLock();
|
|
2902
|
+
}
|
|
2903
|
+
workerData.reader = null;
|
|
2904
|
+
workerData.writer = null;
|
|
2905
|
+
}
|
|
2906
|
+
|
|
2857
2907
|
function terminateWorker$1(workerData) {
|
|
2858
2908
|
const { worker } = workerData;
|
|
2859
2909
|
if (worker) {
|
|
@@ -2921,7 +2971,7 @@ function getWebWorker(url, baseURI, workerData, isModuleType, useBlobURI = true)
|
|
|
2921
2971
|
try {
|
|
2922
2972
|
worker = new Worker(resolvedURI, resolvedOptions);
|
|
2923
2973
|
} catch (error) {
|
|
2924
|
-
if (
|
|
2974
|
+
if (isModuleType) {
|
|
2925
2975
|
return getWebWorker(url, baseURI, workerData, false, useBlobURI);
|
|
2926
2976
|
} else {
|
|
2927
2977
|
throw error;
|
|
@@ -3039,12 +3089,15 @@ async function onMessage({ data }, workerData) {
|
|
|
3039
3089
|
const stale = () => workerData.generation != generation;
|
|
3040
3090
|
try {
|
|
3041
3091
|
if (error) {
|
|
3042
|
-
const { message, stack, code, name, outputSize, cause } = error;
|
|
3092
|
+
const { message, stack, code, name, outputSize, cause, codecImportFailed } = error;
|
|
3043
3093
|
const responseError = new Error(message);
|
|
3044
3094
|
Object.assign(responseError, { stack, code, name, outputSize });
|
|
3045
3095
|
if (cause) {
|
|
3046
3096
|
responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
|
|
3047
3097
|
}
|
|
3098
|
+
if (codecImportFailed) {
|
|
3099
|
+
responseError.codecImportFailed = true;
|
|
3100
|
+
}
|
|
3048
3101
|
close(responseError);
|
|
3049
3102
|
} else {
|
|
3050
3103
|
if (type == MESSAGE_PULL) {
|
|
@@ -3083,7 +3136,9 @@ async function onMessage({ data }, workerData) {
|
|
|
3083
3136
|
if (writer) {
|
|
3084
3137
|
writer.releaseLock();
|
|
3085
3138
|
}
|
|
3086
|
-
|
|
3139
|
+
if (!(error && error.codecImportFailed)) {
|
|
3140
|
+
onTaskFinished();
|
|
3141
|
+
}
|
|
3087
3142
|
}
|
|
3088
3143
|
}
|
|
3089
3144
|
|
|
@@ -3133,7 +3188,7 @@ async function runWorker(stream, workerOptions) {
|
|
|
3133
3188
|
}
|
|
3134
3189
|
await ensureCodecStreams(format, options.codecURI);
|
|
3135
3190
|
}
|
|
3136
|
-
workerOptions.transferStreams = transferStreams || (transferStreams === UNDEFINED_VALUE && config.transferStreams);
|
|
3191
|
+
workerOptions.transferStreams = !format && (transferStreams || (transferStreams === UNDEFINED_VALUE && config.transferStreams));
|
|
3137
3192
|
const streamCopy = !compressed && !checkCrc32 && !computeCrc32 && !encrypted;
|
|
3138
3193
|
const workerSupported = format === UNDEFINED_VALUE || Boolean(options.codecURI);
|
|
3139
3194
|
workerOptions.useWebWorkers = !streamCopy && workerSupported && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
@@ -3637,7 +3692,7 @@ async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
|
3637
3692
|
forceRangeRequests,
|
|
3638
3693
|
combineSizeEocd
|
|
3639
3694
|
} = httpReader;
|
|
3640
|
-
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest ==
|
|
3695
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == UNDEFINED_TYPE || preventHeadRequest)) {
|
|
3641
3696
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
|
|
3642
3697
|
const acceptRanges = response.headers.get(HTTP_HEADER_ACCEPT_RANGES);
|
|
3643
3698
|
if (!forceRangeRequests && (!acceptRanges || acceptRanges.toLowerCase() != HTTP_RANGE_UNIT)) {
|
|
@@ -4490,9 +4545,13 @@ const OPTION_USDZ = "usdz";
|
|
|
4490
4545
|
const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
|
|
4491
4546
|
const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
|
|
4492
4547
|
const OPTION_STRICTNESS = "strictness";
|
|
4548
|
+
const OPTION_FILENAME_VALIDATION = "filenameValidation";
|
|
4549
|
+
const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
|
|
4493
4550
|
const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
|
|
4494
4551
|
const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
|
|
4495
4552
|
const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
|
|
4553
|
+
const TEXT_TYPE_FILENAME = "filename";
|
|
4554
|
+
const TEXT_TYPE_COMMENT = "comment";
|
|
4496
4555
|
const STRICTNESS_STRICT = "strict";
|
|
4497
4556
|
const STRICTNESS_BALANCED = "balanced";
|
|
4498
4557
|
const STRICTNESS_TOLERANT = "tolerant";
|
|
@@ -4539,6 +4598,11 @@ const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
|
4539
4598
|
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
4540
4599
|
const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
|
|
4541
4600
|
const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
|
|
4601
|
+
const ERR_UNSAFE_FILENAME = "Unsafe filename";
|
|
4602
|
+
const ERR_INVALID_STRICTNESS = "Invalid strictness (must be 'strict', 'balanced' or 'tolerant')";
|
|
4603
|
+
const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
|
|
4604
|
+
const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
|
|
4605
|
+
const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
|
|
4542
4606
|
const CHARSET_UTF8 = "utf-8";
|
|
4543
4607
|
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
|
|
4544
4608
|
const CHARSET_CP437 = "cp437";
|
|
@@ -4560,6 +4624,10 @@ const ZIP64_EXTRACTION = {
|
|
|
4560
4624
|
bytes: 8
|
|
4561
4625
|
}
|
|
4562
4626
|
};
|
|
4627
|
+
const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
|
|
4628
|
+
const CENTRAL_DIRECTORY_UNREACHABLE = 0;
|
|
4629
|
+
const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
|
|
4630
|
+
const CENTRAL_DIRECTORY_REACHABLE = 2;
|
|
4563
4631
|
|
|
4564
4632
|
class ZipReader {
|
|
4565
4633
|
|
|
@@ -4588,6 +4656,8 @@ class ZipReader {
|
|
|
4588
4656
|
const checkAmbiguity = strictness == STRICTNESS_STRICT;
|
|
4589
4657
|
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
4590
4658
|
const maxAppendedDataSize = getMaxAppendedDataSize(getOptionValue$1(zipReader, options, OPTION_MAX_APPENDED_DATA_SIZE), strictness);
|
|
4659
|
+
const filenameValidation = getFilenameValidation(getOptionValue$1(zipReader, options, OPTION_FILENAME_VALIDATION), strictness);
|
|
4660
|
+
const normalizeFilename = getOptionValue$1(zipReader, options, OPTION_NORMALIZE_FILENAME);
|
|
4591
4661
|
const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
|
|
4592
4662
|
if (!endOfDirectoryInfo) {
|
|
4593
4663
|
const signatureArray = await readUint8Array(reader, 0, 4);
|
|
@@ -4781,11 +4851,22 @@ class ZipReader {
|
|
|
4781
4851
|
const decode = getOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
|
|
4782
4852
|
const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
|
|
4783
4853
|
const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
|
|
4784
|
-
let filename = decode(rawFilename, rawFilenameEncoding);
|
|
4854
|
+
let filename = decode(rawFilename, rawFilenameEncoding, TEXT_TYPE_FILENAME);
|
|
4785
4855
|
if (filename === UNDEFINED_VALUE) {
|
|
4786
4856
|
filename = decodeText(rawFilename, rawFilenameEncoding);
|
|
4787
4857
|
}
|
|
4788
|
-
|
|
4858
|
+
if (normalizeFilename) {
|
|
4859
|
+
const normalizedFilename = normalizeFilename(filename);
|
|
4860
|
+
if (normalizedFilename !== UNDEFINED_VALUE) {
|
|
4861
|
+
filename = normalizedFilename;
|
|
4862
|
+
}
|
|
4863
|
+
}
|
|
4864
|
+
if (isUnsafeFilename(filename, filenameValidation)) {
|
|
4865
|
+
const error = new Error(ERR_UNSAFE_FILENAME);
|
|
4866
|
+
error.filename = filename;
|
|
4867
|
+
throw error;
|
|
4868
|
+
}
|
|
4869
|
+
let comment = decode(rawComment, rawCommentEncoding, TEXT_TYPE_COMMENT);
|
|
4789
4870
|
if (comment === UNDEFINED_VALUE) {
|
|
4790
4871
|
comment = decodeText(rawComment, rawCommentEncoding);
|
|
4791
4872
|
}
|
|
@@ -4846,10 +4927,10 @@ class ZipReader {
|
|
|
4846
4927
|
entry.getData = (writer, options) => fileEntry.getData(writer, entry, zipReader.readRanges, options);
|
|
4847
4928
|
entry.arrayBuffer = async options => {
|
|
4848
4929
|
const writer = new TransformStream();
|
|
4849
|
-
const
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
return
|
|
4930
|
+
const arrayBufferPromise = streamToBlob(writer.readable).then(blob => blob.arrayBuffer());
|
|
4931
|
+
arrayBufferPromise.catch(() => { });
|
|
4932
|
+
await fileEntry.getData(writer, entry, zipReader.readRanges, options);
|
|
4933
|
+
return arrayBufferPromise;
|
|
4853
4934
|
};
|
|
4854
4935
|
offset = endOffset;
|
|
4855
4936
|
const { onprogress } = options;
|
|
@@ -5100,7 +5181,7 @@ class ZipEntry {
|
|
|
5100
5181
|
readRanges
|
|
5101
5182
|
});
|
|
5102
5183
|
}
|
|
5103
|
-
let writable;
|
|
5184
|
+
let writable, abortError;
|
|
5104
5185
|
try {
|
|
5105
5186
|
if (!checkOverlappingEntryOnly) {
|
|
5106
5187
|
if (checkPasswordOnly) {
|
|
@@ -5120,12 +5201,22 @@ class ZipEntry {
|
|
|
5120
5201
|
writer.size += error.outputSize;
|
|
5121
5202
|
}
|
|
5122
5203
|
if (!checkPasswordOnly || error.message != ERR_ABORT_CHECK_PASSWORD) {
|
|
5204
|
+
abortError = error;
|
|
5123
5205
|
throw error;
|
|
5124
5206
|
}
|
|
5125
5207
|
} finally {
|
|
5126
5208
|
const preventClose = getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5127
5209
|
if (!preventClose && writable && !writable.locked) {
|
|
5128
|
-
|
|
5210
|
+
const writableWriter = writable.getWriter();
|
|
5211
|
+
if (abortError) {
|
|
5212
|
+
try {
|
|
5213
|
+
await writableWriter.abort(abortError);
|
|
5214
|
+
} catch {
|
|
5215
|
+
// the error being propagated is more relevant; ignored
|
|
5216
|
+
}
|
|
5217
|
+
} else {
|
|
5218
|
+
await writableWriter.close();
|
|
5219
|
+
}
|
|
5129
5220
|
}
|
|
5130
5221
|
}
|
|
5131
5222
|
return checkPasswordOnly || checkOverlappingEntryOnly ? UNDEFINED_VALUE : writer.getData ? writer.getData() : writable;
|
|
@@ -5505,16 +5596,51 @@ function getDiskOffset$1(reader, diskNumber) {
|
|
|
5505
5596
|
return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
|
|
5506
5597
|
}
|
|
5507
5598
|
|
|
5599
|
+
function isStrictnessValue(value) {
|
|
5600
|
+
return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
|
|
5601
|
+
}
|
|
5602
|
+
|
|
5508
5603
|
function getStrictness(strictness, checkAmbiguity) {
|
|
5509
5604
|
if (strictness === UNDEFINED_VALUE) {
|
|
5510
5605
|
return checkAmbiguity ? STRICTNESS_STRICT : STRICTNESS_BALANCED;
|
|
5511
5606
|
}
|
|
5607
|
+
if (!isStrictnessValue(strictness)) {
|
|
5608
|
+
throw new Error(ERR_INVALID_STRICTNESS);
|
|
5609
|
+
}
|
|
5512
5610
|
return strictness;
|
|
5513
5611
|
}
|
|
5514
5612
|
|
|
5613
|
+
function getFilenameValidation(filenameValidation, strictness) {
|
|
5614
|
+
if (filenameValidation === UNDEFINED_VALUE) {
|
|
5615
|
+
return strictness;
|
|
5616
|
+
}
|
|
5617
|
+
if (!isStrictnessValue(filenameValidation)) {
|
|
5618
|
+
throw new Error(ERR_INVALID_FILENAME_VALIDATION);
|
|
5619
|
+
}
|
|
5620
|
+
return filenameValidation;
|
|
5621
|
+
}
|
|
5622
|
+
|
|
5623
|
+
function isUnsafeFilename(filename, filenameValidation) {
|
|
5624
|
+
if (filenameValidation == STRICTNESS_TOLERANT) {
|
|
5625
|
+
return false;
|
|
5626
|
+
}
|
|
5627
|
+
const pathParts = filename.split("/");
|
|
5628
|
+
if (pathParts.length > 1 && pathParts[pathParts.length - 1] === "") {
|
|
5629
|
+
pathParts.pop();
|
|
5630
|
+
}
|
|
5631
|
+
if (pathParts.includes("..") || filename.startsWith("/") || filename.startsWith("\\\\") || DRIVE_LETTER_REGEXP.test(filename)) {
|
|
5632
|
+
return true;
|
|
5633
|
+
}
|
|
5634
|
+
return filenameValidation == STRICTNESS_STRICT && (pathParts.includes(".") || pathParts.includes(""));
|
|
5635
|
+
}
|
|
5636
|
+
|
|
5515
5637
|
function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
|
|
5516
5638
|
if (maxAppendedDataSize !== UNDEFINED_VALUE) {
|
|
5517
|
-
|
|
5639
|
+
const size = toNumber$1(maxAppendedDataSize);
|
|
5640
|
+
if (typeof size != NUMBER_TYPE || Number.isNaN(size) || size < 0) {
|
|
5641
|
+
throw new Error(ERR_INVALID_MAX_APPENDED_DATA_SIZE);
|
|
5642
|
+
}
|
|
5643
|
+
return size;
|
|
5518
5644
|
}
|
|
5519
5645
|
if (strictness == STRICTNESS_STRICT) {
|
|
5520
5646
|
return 0;
|
|
@@ -5525,12 +5651,6 @@ function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
|
|
|
5525
5651
|
return MAX_16_BITS;
|
|
5526
5652
|
}
|
|
5527
5653
|
|
|
5528
|
-
const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
|
|
5529
|
-
|
|
5530
|
-
const CENTRAL_DIRECTORY_UNREACHABLE = 0;
|
|
5531
|
-
const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
|
|
5532
|
-
const CENTRAL_DIRECTORY_REACHABLE = 2;
|
|
5533
|
-
|
|
5534
5654
|
async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDataSize) {
|
|
5535
5655
|
const { size } = reader;
|
|
5536
5656
|
const anchoredLength = Math.min(size, END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS);
|
|
@@ -5666,6 +5786,10 @@ function getOptionValue$1(zipReader, options, name) {
|
|
|
5666
5786
|
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
5667
5787
|
}
|
|
5668
5788
|
|
|
5789
|
+
function toNumber$1(value) {
|
|
5790
|
+
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
5791
|
+
}
|
|
5792
|
+
|
|
5669
5793
|
function getDate(timeRaw) {
|
|
5670
5794
|
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
|
|
5671
5795
|
return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
|
|
@@ -5704,12 +5828,16 @@ var zipReader = /*#__PURE__*/Object.freeze({
|
|
|
5704
5828
|
ERR_INVALID_AUTHENTICATION_CODE: ERR_INVALID_AUTHENTICATION_CODE,
|
|
5705
5829
|
ERR_INVALID_COMPRESSED_DATA: ERR_INVALID_COMPRESSED_DATA,
|
|
5706
5830
|
ERR_INVALID_CRC32: ERR_INVALID_CRC32,
|
|
5831
|
+
ERR_INVALID_FILENAME_VALIDATION: ERR_INVALID_FILENAME_VALIDATION,
|
|
5832
|
+
ERR_INVALID_MAX_APPENDED_DATA_SIZE: ERR_INVALID_MAX_APPENDED_DATA_SIZE,
|
|
5707
5833
|
ERR_INVALID_PASSWORD: ERR_INVALID_PASSWORD,
|
|
5708
5834
|
ERR_INVALID_SIGNATURE: ERR_INVALID_SIGNATURE,
|
|
5835
|
+
ERR_INVALID_STRICTNESS: ERR_INVALID_STRICTNESS,
|
|
5709
5836
|
ERR_INVALID_UNCOMPRESSED_SIZE: ERR_INVALID_UNCOMPRESSED_SIZE,
|
|
5710
5837
|
ERR_LOCAL_FILE_HEADER_NOT_FOUND: ERR_LOCAL_FILE_HEADER_NOT_FOUND,
|
|
5711
5838
|
ERR_OVERLAPPING_ENTRY: ERR_OVERLAPPING_ENTRY,
|
|
5712
5839
|
ERR_SPLIT_ZIP_FILE: ERR_SPLIT_ZIP_FILE,
|
|
5840
|
+
ERR_UNSAFE_FILENAME: ERR_UNSAFE_FILENAME,
|
|
5713
5841
|
ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION$1,
|
|
5714
5842
|
ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
|
|
5715
5843
|
ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
|
|
@@ -5771,6 +5899,8 @@ const ERR_INVALID_UNIX_EXTRA_FIELD_TYPE = "Invalid unixExtraFieldType (must be '
|
|
|
5771
5899
|
const ERR_INVALID_UNIX_ID_SIZE = "uid/gid must be 0..65535 for unixExtraFieldType 'unix' (use 'infozip' for larger ids)";
|
|
5772
5900
|
const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
|
|
5773
5901
|
const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
|
|
5902
|
+
const ERR_INVALID_LEVEL = "Invalid level (must be integer 0..9)";
|
|
5903
|
+
const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
|
|
5774
5904
|
const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
|
|
5775
5905
|
|
|
5776
5906
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
@@ -5778,6 +5908,7 @@ const EXTRAFIELD_OFFSET_AES_VENDOR_VERSION = 4;
|
|
|
5778
5908
|
const VENDOR_VERSION_AE_1 = 1;
|
|
5779
5909
|
const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
|
|
5780
5910
|
const UNIX_EXTRA_FIELD_TYPE = "unix";
|
|
5911
|
+
const MAX_LEVEL = 9;
|
|
5781
5912
|
|
|
5782
5913
|
let workers = 0;
|
|
5783
5914
|
const pendingEntries = [];
|
|
@@ -5940,7 +6071,8 @@ class ZipWriter {
|
|
|
5940
6071
|
|
|
5941
6072
|
remove(entry) {
|
|
5942
6073
|
const { filenames, files } = this;
|
|
5943
|
-
|
|
6074
|
+
// deno-lint-ignore valid-typeof
|
|
6075
|
+
if (typeof entry == STRING_TYPE) {
|
|
5944
6076
|
entry = files.get(entry);
|
|
5945
6077
|
}
|
|
5946
6078
|
if (entry && entry.filename !== UNDEFINED_VALUE) {
|
|
@@ -6078,20 +6210,20 @@ function resolveAttributes(zipWriter, name, options) {
|
|
|
6078
6210
|
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
6079
6211
|
let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? 20 : 768);
|
|
6080
6212
|
const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
|
|
6081
|
-
const uid =
|
|
6082
|
-
const gid =
|
|
6083
|
-
let unixMode =
|
|
6213
|
+
const uid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UID);
|
|
6214
|
+
const gid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_GID);
|
|
6215
|
+
let unixMode = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UNIX_MODE);
|
|
6084
6216
|
let unixExtraFieldType = getOptionValue(zipWriter, options, OPTION_UNIX_EXTRA_FIELD_TYPE);
|
|
6085
6217
|
let setuid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETUID);
|
|
6086
6218
|
let setgid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETGID);
|
|
6087
6219
|
let sticky = getOptionValue(zipWriter, options, PROPERTY_NAME_STICKY);
|
|
6088
|
-
if (uid !== UNDEFINED_VALUE && (uid < 0 || uid > MAX_32_BITS)) {
|
|
6220
|
+
if (uid !== UNDEFINED_VALUE && (!Number.isInteger(uid) || uid < 0 || uid > MAX_32_BITS)) {
|
|
6089
6221
|
throw new Error(ERR_INVALID_UID);
|
|
6090
6222
|
}
|
|
6091
|
-
if (gid !== UNDEFINED_VALUE && (gid < 0 || gid > MAX_32_BITS)) {
|
|
6223
|
+
if (gid !== UNDEFINED_VALUE && (!Number.isInteger(gid) || gid < 0 || gid > MAX_32_BITS)) {
|
|
6092
6224
|
throw new Error(ERR_INVALID_GID);
|
|
6093
6225
|
}
|
|
6094
|
-
if (unixMode !== UNDEFINED_VALUE && (unixMode < 0 || unixMode > MAX_16_BITS)) {
|
|
6226
|
+
if (unixMode !== UNDEFINED_VALUE && (!Number.isInteger(unixMode) || unixMode < 0 || unixMode > MAX_16_BITS)) {
|
|
6095
6227
|
throw new Error(ERR_INVALID_UNIX_MODE);
|
|
6096
6228
|
}
|
|
6097
6229
|
if (unixExtraFieldType !== UNDEFINED_VALUE && unixExtraFieldType !== INFOZIP_EXTRA_FIELD_TYPE && unixExtraFieldType !== UNIX_EXTRA_FIELD_TYPE) {
|
|
@@ -6203,7 +6335,7 @@ function resolveAttributes(zipWriter, name, options) {
|
|
|
6203
6335
|
|
|
6204
6336
|
function resolveMetadata(zipWriter, name, options) {
|
|
6205
6337
|
const encode = getOptionValue(zipWriter, options, OPTION_ENCODE_TEXT, encodeText);
|
|
6206
|
-
let rawFilename = encode(name);
|
|
6338
|
+
let rawFilename = encode(name, TEXT_TYPE_FILENAME);
|
|
6207
6339
|
if (rawFilename === UNDEFINED_VALUE) {
|
|
6208
6340
|
rawFilename = encodeText(name);
|
|
6209
6341
|
}
|
|
@@ -6211,7 +6343,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6211
6343
|
throw new Error(ERR_INVALID_ENTRY_NAME);
|
|
6212
6344
|
}
|
|
6213
6345
|
const comment = options[PROPERTY_NAME_COMMENT] || "";
|
|
6214
|
-
let rawComment = encode(comment);
|
|
6346
|
+
let rawComment = encode(comment, TEXT_TYPE_COMMENT);
|
|
6215
6347
|
if (rawComment === UNDEFINED_VALUE) {
|
|
6216
6348
|
rawComment = encodeText(comment);
|
|
6217
6349
|
}
|
|
@@ -6231,8 +6363,11 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6231
6363
|
if (!passThrough) {
|
|
6232
6364
|
password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
6233
6365
|
rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
6366
|
+
if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
|
|
6367
|
+
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
6368
|
+
}
|
|
6234
6369
|
}
|
|
6235
|
-
const encryptionStrength =
|
|
6370
|
+
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
6236
6371
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
6237
6372
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
6238
6373
|
const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
|
|
@@ -6250,7 +6385,10 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6250
6385
|
compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE && !registeredCodec) {
|
|
6251
6386
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
6252
6387
|
}
|
|
6253
|
-
let level =
|
|
6388
|
+
let level = getNumberOptionValue(zipWriter, options, OPTION_LEVEL);
|
|
6389
|
+
if (level !== UNDEFINED_VALUE && (!Number.isInteger(level) || level < 0 || level > MAX_LEVEL)) {
|
|
6390
|
+
throw new Error(ERR_INVALID_LEVEL);
|
|
6391
|
+
}
|
|
6254
6392
|
if (zipWriter.options[OPTION_USDZ]) {
|
|
6255
6393
|
if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
|
|
6256
6394
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
|
|
@@ -6271,7 +6409,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6271
6409
|
useCompressionStream = false;
|
|
6272
6410
|
}
|
|
6273
6411
|
const zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
6274
|
-
if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
|
|
6412
|
+
if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(Number.isInteger(encryptionStrength) && encryptionStrength >= 1 && encryptionStrength <= 3)) {
|
|
6275
6413
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
6276
6414
|
}
|
|
6277
6415
|
const rawExtraField = serializeExtraField(options[PROPERTY_NAME_EXTRA_FIELD]);
|
|
@@ -7465,6 +7603,14 @@ function getOptionValue(zipWriter, options, name, defaultValue) {
|
|
|
7465
7603
|
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7466
7604
|
}
|
|
7467
7605
|
|
|
7606
|
+
function getNumberOptionValue(zipWriter, options, name, defaultValue) {
|
|
7607
|
+
return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
|
|
7608
|
+
}
|
|
7609
|
+
|
|
7610
|
+
function toNumber(value) {
|
|
7611
|
+
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
7612
|
+
}
|
|
7613
|
+
|
|
7468
7614
|
function getMaximumCompressedSize(uncompressedSize) {
|
|
7469
7615
|
return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
|
|
7470
7616
|
}
|
|
@@ -8423,4 +8569,4 @@ function terminateWorkersAndModule() {
|
|
|
8423
8569
|
|
|
8424
8570
|
configureExternalAssets();
|
|
8425
8571
|
|
|
8426
|
-
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_GID, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_SIGNATURE, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|
|
8572
|
+
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_SIGNATURE, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_STRICTNESS, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|