@zip.js/zip.js 2.8.49 → 2.8.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist/zip-core-external.js +333 -203
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +339 -203
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +420 -214
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +212 -450
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +420 -214
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +426 -214
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +426 -214
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +339 -203
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +339 -203
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +339 -203
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +425 -213
- package/index-native.min.js +1 -1
- package/index.cjs +425 -213
- package/index.d.cts +124 -2
- package/index.d.ts +124 -2
- package/index.min.js +1 -1
- package/lib/core/codec-registry.js +2 -2
- package/lib/core/codec-worker-web.js +436 -0
- package/lib/core/codec-worker.js +23 -404
- package/lib/core/constants.js +5 -1
- package/lib/core/io.js +2 -1
- package/lib/core/options.js +8 -0
- package/lib/core/zip-fs.js +88 -12
- package/lib/core/zip-reader.js +90 -16
- package/lib/core/zip-writer.js +36 -13
- package/lib/zip-core-reader.js +6 -0
- package/lib/zip-core-writer.js +4 -0
- package/package.json +1 -1
|
@@ -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,60 +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
|
-
releaseWorkerStreams(workerData);
|
|
2714
|
-
return runWorker$1(workerData, config);
|
|
2715
|
-
}
|
|
2716
|
-
if (error && error.codecImportFailed) {
|
|
2717
|
-
if (workerData.reader) {
|
|
2718
|
-
releaseWorkerStreams(workerData);
|
|
2719
|
-
return runWorker$1(workerData, config);
|
|
2720
|
-
}
|
|
2721
|
-
workerData.onTaskFinished();
|
|
2722
|
-
}
|
|
2723
|
-
throw error;
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
});
|
|
2728
|
-
}
|
|
2729
|
-
return workerData.interface;
|
|
2730
|
-
}
|
|
2731
|
-
|
|
2732
2682
|
async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
|
|
2733
2683
|
let codecStream;
|
|
2734
2684
|
try {
|
|
@@ -2777,6 +2727,95 @@ async function runWorker$1({ options, readable, writable, onTaskFinished }, conf
|
|
|
2777
2727
|
}
|
|
2778
2728
|
}
|
|
2779
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
|
+
|
|
2780
2819
|
async function runWebWorker(workerData, config) {
|
|
2781
2820
|
let resolveResult, rejectResult;
|
|
2782
2821
|
const result = new Promise((resolve, reject) => {
|
|
@@ -3653,7 +3692,7 @@ async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
|
3653
3692
|
forceRangeRequests,
|
|
3654
3693
|
combineSizeEocd
|
|
3655
3694
|
} = httpReader;
|
|
3656
|
-
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest ==
|
|
3695
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == UNDEFINED_TYPE || preventHeadRequest)) {
|
|
3657
3696
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
|
|
3658
3697
|
const acceptRanges = response.headers.get(HTTP_HEADER_ACCEPT_RANGES);
|
|
3659
3698
|
if (!forceRangeRequests && (!acceptRanges || acceptRanges.toLowerCase() != HTTP_RANGE_UNIT)) {
|
|
@@ -4506,9 +4545,13 @@ const OPTION_USDZ = "usdz";
|
|
|
4506
4545
|
const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
|
|
4507
4546
|
const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
|
|
4508
4547
|
const OPTION_STRICTNESS = "strictness";
|
|
4548
|
+
const OPTION_FILENAME_VALIDATION = "filenameValidation";
|
|
4549
|
+
const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
|
|
4509
4550
|
const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
|
|
4510
4551
|
const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
|
|
4511
4552
|
const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
|
|
4553
|
+
const TEXT_TYPE_FILENAME = "filename";
|
|
4554
|
+
const TEXT_TYPE_COMMENT = "comment";
|
|
4512
4555
|
const STRICTNESS_STRICT = "strict";
|
|
4513
4556
|
const STRICTNESS_BALANCED = "balanced";
|
|
4514
4557
|
const STRICTNESS_TOLERANT = "tolerant";
|
|
@@ -4555,6 +4598,11 @@ const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
|
4555
4598
|
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
4556
4599
|
const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
|
|
4557
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]:/;
|
|
4558
4606
|
const CHARSET_UTF8 = "utf-8";
|
|
4559
4607
|
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
|
|
4560
4608
|
const CHARSET_CP437 = "cp437";
|
|
@@ -4576,6 +4624,10 @@ const ZIP64_EXTRACTION = {
|
|
|
4576
4624
|
bytes: 8
|
|
4577
4625
|
}
|
|
4578
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;
|
|
4579
4631
|
|
|
4580
4632
|
class ZipReader {
|
|
4581
4633
|
|
|
@@ -4604,6 +4656,8 @@ class ZipReader {
|
|
|
4604
4656
|
const checkAmbiguity = strictness == STRICTNESS_STRICT;
|
|
4605
4657
|
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
4606
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);
|
|
4607
4661
|
const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
|
|
4608
4662
|
if (!endOfDirectoryInfo) {
|
|
4609
4663
|
const signatureArray = await readUint8Array(reader, 0, 4);
|
|
@@ -4797,11 +4851,22 @@ class ZipReader {
|
|
|
4797
4851
|
const decode = getOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
|
|
4798
4852
|
const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
|
|
4799
4853
|
const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
|
|
4800
|
-
let filename = decode(rawFilename, rawFilenameEncoding);
|
|
4854
|
+
let filename = decode(rawFilename, rawFilenameEncoding, TEXT_TYPE_FILENAME);
|
|
4801
4855
|
if (filename === UNDEFINED_VALUE) {
|
|
4802
4856
|
filename = decodeText(rawFilename, rawFilenameEncoding);
|
|
4803
4857
|
}
|
|
4804
|
-
|
|
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);
|
|
4805
4870
|
if (comment === UNDEFINED_VALUE) {
|
|
4806
4871
|
comment = decodeText(rawComment, rawCommentEncoding);
|
|
4807
4872
|
}
|
|
@@ -4862,10 +4927,10 @@ class ZipReader {
|
|
|
4862
4927
|
entry.getData = (writer, options) => fileEntry.getData(writer, entry, zipReader.readRanges, options);
|
|
4863
4928
|
entry.arrayBuffer = async options => {
|
|
4864
4929
|
const writer = new TransformStream();
|
|
4865
|
-
const
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
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;
|
|
4869
4934
|
};
|
|
4870
4935
|
offset = endOffset;
|
|
4871
4936
|
const { onprogress } = options;
|
|
@@ -5116,7 +5181,7 @@ class ZipEntry {
|
|
|
5116
5181
|
readRanges
|
|
5117
5182
|
});
|
|
5118
5183
|
}
|
|
5119
|
-
let writable;
|
|
5184
|
+
let writable, abortError;
|
|
5120
5185
|
try {
|
|
5121
5186
|
if (!checkOverlappingEntryOnly) {
|
|
5122
5187
|
if (checkPasswordOnly) {
|
|
@@ -5136,12 +5201,22 @@ class ZipEntry {
|
|
|
5136
5201
|
writer.size += error.outputSize;
|
|
5137
5202
|
}
|
|
5138
5203
|
if (!checkPasswordOnly || error.message != ERR_ABORT_CHECK_PASSWORD) {
|
|
5204
|
+
abortError = error;
|
|
5139
5205
|
throw error;
|
|
5140
5206
|
}
|
|
5141
5207
|
} finally {
|
|
5142
5208
|
const preventClose = getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5143
5209
|
if (!preventClose && writable && !writable.locked) {
|
|
5144
|
-
|
|
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
|
+
}
|
|
5145
5220
|
}
|
|
5146
5221
|
}
|
|
5147
5222
|
return checkPasswordOnly || checkOverlappingEntryOnly ? UNDEFINED_VALUE : writer.getData ? writer.getData() : writable;
|
|
@@ -5521,16 +5596,51 @@ function getDiskOffset$1(reader, diskNumber) {
|
|
|
5521
5596
|
return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
|
|
5522
5597
|
}
|
|
5523
5598
|
|
|
5599
|
+
function isStrictnessValue(value) {
|
|
5600
|
+
return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
|
|
5601
|
+
}
|
|
5602
|
+
|
|
5524
5603
|
function getStrictness(strictness, checkAmbiguity) {
|
|
5525
5604
|
if (strictness === UNDEFINED_VALUE) {
|
|
5526
5605
|
return checkAmbiguity ? STRICTNESS_STRICT : STRICTNESS_BALANCED;
|
|
5527
5606
|
}
|
|
5607
|
+
if (!isStrictnessValue(strictness)) {
|
|
5608
|
+
throw new Error(ERR_INVALID_STRICTNESS);
|
|
5609
|
+
}
|
|
5528
5610
|
return strictness;
|
|
5529
5611
|
}
|
|
5530
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
|
+
|
|
5531
5637
|
function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
|
|
5532
5638
|
if (maxAppendedDataSize !== UNDEFINED_VALUE) {
|
|
5533
|
-
|
|
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;
|
|
5534
5644
|
}
|
|
5535
5645
|
if (strictness == STRICTNESS_STRICT) {
|
|
5536
5646
|
return 0;
|
|
@@ -5541,12 +5651,6 @@ function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
|
|
|
5541
5651
|
return MAX_16_BITS;
|
|
5542
5652
|
}
|
|
5543
5653
|
|
|
5544
|
-
const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
|
|
5545
|
-
|
|
5546
|
-
const CENTRAL_DIRECTORY_UNREACHABLE = 0;
|
|
5547
|
-
const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
|
|
5548
|
-
const CENTRAL_DIRECTORY_REACHABLE = 2;
|
|
5549
|
-
|
|
5550
5654
|
async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDataSize) {
|
|
5551
5655
|
const { size } = reader;
|
|
5552
5656
|
const anchoredLength = Math.min(size, END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS);
|
|
@@ -5682,6 +5786,10 @@ function getOptionValue$1(zipReader, options, name) {
|
|
|
5682
5786
|
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
5683
5787
|
}
|
|
5684
5788
|
|
|
5789
|
+
function toNumber$1(value) {
|
|
5790
|
+
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
5791
|
+
}
|
|
5792
|
+
|
|
5685
5793
|
function getDate(timeRaw) {
|
|
5686
5794
|
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
|
|
5687
5795
|
return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
|
|
@@ -5720,12 +5828,16 @@ var zipReader = /*#__PURE__*/Object.freeze({
|
|
|
5720
5828
|
ERR_INVALID_AUTHENTICATION_CODE: ERR_INVALID_AUTHENTICATION_CODE,
|
|
5721
5829
|
ERR_INVALID_COMPRESSED_DATA: ERR_INVALID_COMPRESSED_DATA,
|
|
5722
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,
|
|
5723
5833
|
ERR_INVALID_PASSWORD: ERR_INVALID_PASSWORD,
|
|
5724
5834
|
ERR_INVALID_SIGNATURE: ERR_INVALID_SIGNATURE,
|
|
5835
|
+
ERR_INVALID_STRICTNESS: ERR_INVALID_STRICTNESS,
|
|
5725
5836
|
ERR_INVALID_UNCOMPRESSED_SIZE: ERR_INVALID_UNCOMPRESSED_SIZE,
|
|
5726
5837
|
ERR_LOCAL_FILE_HEADER_NOT_FOUND: ERR_LOCAL_FILE_HEADER_NOT_FOUND,
|
|
5727
5838
|
ERR_OVERLAPPING_ENTRY: ERR_OVERLAPPING_ENTRY,
|
|
5728
5839
|
ERR_SPLIT_ZIP_FILE: ERR_SPLIT_ZIP_FILE,
|
|
5840
|
+
ERR_UNSAFE_FILENAME: ERR_UNSAFE_FILENAME,
|
|
5729
5841
|
ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION$1,
|
|
5730
5842
|
ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
|
|
5731
5843
|
ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
|
|
@@ -5787,6 +5899,8 @@ const ERR_INVALID_UNIX_EXTRA_FIELD_TYPE = "Invalid unixExtraFieldType (must be '
|
|
|
5787
5899
|
const ERR_INVALID_UNIX_ID_SIZE = "uid/gid must be 0..65535 for unixExtraFieldType 'unix' (use 'infozip' for larger ids)";
|
|
5788
5900
|
const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
|
|
5789
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)";
|
|
5790
5904
|
const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
|
|
5791
5905
|
|
|
5792
5906
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
@@ -5794,6 +5908,7 @@ const EXTRAFIELD_OFFSET_AES_VENDOR_VERSION = 4;
|
|
|
5794
5908
|
const VENDOR_VERSION_AE_1 = 1;
|
|
5795
5909
|
const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
|
|
5796
5910
|
const UNIX_EXTRA_FIELD_TYPE = "unix";
|
|
5911
|
+
const MAX_LEVEL = 9;
|
|
5797
5912
|
|
|
5798
5913
|
let workers = 0;
|
|
5799
5914
|
const pendingEntries = [];
|
|
@@ -5956,7 +6071,8 @@ class ZipWriter {
|
|
|
5956
6071
|
|
|
5957
6072
|
remove(entry) {
|
|
5958
6073
|
const { filenames, files } = this;
|
|
5959
|
-
|
|
6074
|
+
// deno-lint-ignore valid-typeof
|
|
6075
|
+
if (typeof entry == STRING_TYPE) {
|
|
5960
6076
|
entry = files.get(entry);
|
|
5961
6077
|
}
|
|
5962
6078
|
if (entry && entry.filename !== UNDEFINED_VALUE) {
|
|
@@ -6094,20 +6210,20 @@ function resolveAttributes(zipWriter, name, options) {
|
|
|
6094
6210
|
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
6095
6211
|
let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? 20 : 768);
|
|
6096
6212
|
const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
|
|
6097
|
-
const uid =
|
|
6098
|
-
const gid =
|
|
6099
|
-
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);
|
|
6100
6216
|
let unixExtraFieldType = getOptionValue(zipWriter, options, OPTION_UNIX_EXTRA_FIELD_TYPE);
|
|
6101
6217
|
let setuid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETUID);
|
|
6102
6218
|
let setgid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETGID);
|
|
6103
6219
|
let sticky = getOptionValue(zipWriter, options, PROPERTY_NAME_STICKY);
|
|
6104
|
-
if (uid !== UNDEFINED_VALUE && (uid < 0 || uid > MAX_32_BITS)) {
|
|
6220
|
+
if (uid !== UNDEFINED_VALUE && (!Number.isInteger(uid) || uid < 0 || uid > MAX_32_BITS)) {
|
|
6105
6221
|
throw new Error(ERR_INVALID_UID);
|
|
6106
6222
|
}
|
|
6107
|
-
if (gid !== UNDEFINED_VALUE && (gid < 0 || gid > MAX_32_BITS)) {
|
|
6223
|
+
if (gid !== UNDEFINED_VALUE && (!Number.isInteger(gid) || gid < 0 || gid > MAX_32_BITS)) {
|
|
6108
6224
|
throw new Error(ERR_INVALID_GID);
|
|
6109
6225
|
}
|
|
6110
|
-
if (unixMode !== UNDEFINED_VALUE && (unixMode < 0 || unixMode > MAX_16_BITS)) {
|
|
6226
|
+
if (unixMode !== UNDEFINED_VALUE && (!Number.isInteger(unixMode) || unixMode < 0 || unixMode > MAX_16_BITS)) {
|
|
6111
6227
|
throw new Error(ERR_INVALID_UNIX_MODE);
|
|
6112
6228
|
}
|
|
6113
6229
|
if (unixExtraFieldType !== UNDEFINED_VALUE && unixExtraFieldType !== INFOZIP_EXTRA_FIELD_TYPE && unixExtraFieldType !== UNIX_EXTRA_FIELD_TYPE) {
|
|
@@ -6219,7 +6335,7 @@ function resolveAttributes(zipWriter, name, options) {
|
|
|
6219
6335
|
|
|
6220
6336
|
function resolveMetadata(zipWriter, name, options) {
|
|
6221
6337
|
const encode = getOptionValue(zipWriter, options, OPTION_ENCODE_TEXT, encodeText);
|
|
6222
|
-
let rawFilename = encode(name);
|
|
6338
|
+
let rawFilename = encode(name, TEXT_TYPE_FILENAME);
|
|
6223
6339
|
if (rawFilename === UNDEFINED_VALUE) {
|
|
6224
6340
|
rawFilename = encodeText(name);
|
|
6225
6341
|
}
|
|
@@ -6227,7 +6343,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6227
6343
|
throw new Error(ERR_INVALID_ENTRY_NAME);
|
|
6228
6344
|
}
|
|
6229
6345
|
const comment = options[PROPERTY_NAME_COMMENT] || "";
|
|
6230
|
-
let rawComment = encode(comment);
|
|
6346
|
+
let rawComment = encode(comment, TEXT_TYPE_COMMENT);
|
|
6231
6347
|
if (rawComment === UNDEFINED_VALUE) {
|
|
6232
6348
|
rawComment = encodeText(comment);
|
|
6233
6349
|
}
|
|
@@ -6247,8 +6363,11 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6247
6363
|
if (!passThrough) {
|
|
6248
6364
|
password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
6249
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
|
+
}
|
|
6250
6369
|
}
|
|
6251
|
-
const encryptionStrength =
|
|
6370
|
+
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
6252
6371
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
6253
6372
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
6254
6373
|
const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
|
|
@@ -6266,7 +6385,10 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6266
6385
|
compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE && !registeredCodec) {
|
|
6267
6386
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
6268
6387
|
}
|
|
6269
|
-
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
|
+
}
|
|
6270
6392
|
if (zipWriter.options[OPTION_USDZ]) {
|
|
6271
6393
|
if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
|
|
6272
6394
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
|
|
@@ -6287,7 +6409,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6287
6409
|
useCompressionStream = false;
|
|
6288
6410
|
}
|
|
6289
6411
|
const zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
6290
|
-
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)) {
|
|
6291
6413
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
6292
6414
|
}
|
|
6293
6415
|
const rawExtraField = serializeExtraField(options[PROPERTY_NAME_EXTRA_FIELD]);
|
|
@@ -7481,6 +7603,14 @@ function getOptionValue(zipWriter, options, name, defaultValue) {
|
|
|
7481
7603
|
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7482
7604
|
}
|
|
7483
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
|
+
|
|
7484
7614
|
function getMaximumCompressedSize(uncompressedSize) {
|
|
7485
7615
|
return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
|
|
7486
7616
|
}
|
|
@@ -8439,4 +8569,4 @@ function terminateWorkersAndModule() {
|
|
|
8439
8569
|
|
|
8440
8570
|
configureExternalAssets();
|
|
8441
8571
|
|
|
8442
|
-
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 };
|