@zip.js/zip.js 2.8.45 → 2.8.46
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/README.md +28 -2
- package/deno.json +13 -3
- package/dist/zip-core-external.js +61 -26
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +59 -24
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +61 -26
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +38 -22
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +61 -26
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +63 -28
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +63 -28
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +61 -26
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +63 -28
- 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 +63 -28
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +63 -28
- package/index-native.min.js +1 -1
- package/index.cjs +63 -28
- package/index.d.cts +91 -1
- package/index.d.ts +91 -1
- package/index.min.js +1 -1
- package/lib/core/codec-pool.js +3 -2
- package/lib/core/codec-worker.js +28 -12
- package/lib/core/configuration.js +20 -2
- package/lib/core/streams/zip-entry-stream.js +8 -8
- package/lib/core/web-worker-base.js +27 -0
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/web-worker-native.js +7 -9
- package/lib/core/web-worker-wasm.js +9 -12
- package/lib/{core/web-worker-inline-template.js → zip-core-custom.js} +13 -20
- package/lib/zip-module-native.js +3 -3
- package/lib/zip-module-wasm-base.js +3 -3
- package/package.json +20 -2
- package/lib/core/web-worker-inline-template-native.js +0 -48
- package/lib/core/zlib-streams-inline-template.js +0 -45
package/dist/zip-core.js
CHANGED
|
@@ -176,6 +176,7 @@
|
|
|
176
176
|
"baseURI",
|
|
177
177
|
"wasmURI",
|
|
178
178
|
"workerURI",
|
|
179
|
+
"createWorker",
|
|
179
180
|
"chunkSize",
|
|
180
181
|
"maxWorkers",
|
|
181
182
|
"terminateWorkerTimeout",
|
|
@@ -186,8 +187,8 @@
|
|
|
186
187
|
"transferStreams",
|
|
187
188
|
"CompressionStream",
|
|
188
189
|
"DecompressionStream",
|
|
189
|
-
"
|
|
190
|
-
"
|
|
190
|
+
"CompressionStreamFallback",
|
|
191
|
+
"DecompressionStreamFallback"
|
|
191
192
|
];
|
|
192
193
|
|
|
193
194
|
const config = { ...DEFAULT_CONFIGURATION };
|
|
@@ -201,6 +202,7 @@
|
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
function configure(configuration) {
|
|
205
|
+
configuration = normalizeConfiguration(configuration);
|
|
204
206
|
for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
|
|
205
207
|
const propertyValue = configuration[propertyName];
|
|
206
208
|
if (propertyValue !== UNDEFINED_VALUE) {
|
|
@@ -209,7 +211,23 @@
|
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
|
|
214
|
+
function normalizeConfiguration(configuration) {
|
|
215
|
+
const { CompressionStreamZlib, DecompressionStreamZlib } = configuration;
|
|
216
|
+
if (CompressionStreamZlib === UNDEFINED_VALUE && DecompressionStreamZlib === UNDEFINED_VALUE) {
|
|
217
|
+
return configuration;
|
|
218
|
+
}
|
|
219
|
+
const normalizedConfiguration = Object.assign({}, configuration);
|
|
220
|
+
if (normalizedConfiguration.CompressionStreamFallback === UNDEFINED_VALUE) {
|
|
221
|
+
normalizedConfiguration.CompressionStreamFallback = CompressionStreamZlib;
|
|
222
|
+
}
|
|
223
|
+
if (normalizedConfiguration.DecompressionStreamFallback === UNDEFINED_VALUE) {
|
|
224
|
+
normalizedConfiguration.DecompressionStreamFallback = DecompressionStreamZlib;
|
|
225
|
+
}
|
|
226
|
+
return normalizedConfiguration;
|
|
227
|
+
}
|
|
228
|
+
|
|
212
229
|
function setDefaultConfiguration(configuration) {
|
|
230
|
+
configuration = normalizeConfiguration(configuration);
|
|
213
231
|
for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
|
|
214
232
|
const propertyValue = configuration[propertyName];
|
|
215
233
|
if (propertyValue !== UNDEFINED_VALUE) {
|
|
@@ -1936,7 +1954,7 @@
|
|
|
1936
1954
|
|
|
1937
1955
|
class DeflateStream extends TransformStream {
|
|
1938
1956
|
|
|
1939
|
-
constructor(options, { chunkSize,
|
|
1957
|
+
constructor(options, { chunkSize, CompressionStreamFallback, CompressionStream }) {
|
|
1940
1958
|
super({});
|
|
1941
1959
|
const { compressed, encrypted, useCompressionStream, zipCrypto, computeCrc32, level, deflate64, format, compressionMethod } = options;
|
|
1942
1960
|
const stream = this;
|
|
@@ -1958,7 +1976,7 @@
|
|
|
1958
1976
|
readable = pipeThrough(readable, gzipCrc32Stream);
|
|
1959
1977
|
} else {
|
|
1960
1978
|
try {
|
|
1961
|
-
readable = pipeThroughCompressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStream,
|
|
1979
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStream, CompressionStreamFallback);
|
|
1962
1980
|
} catch (error) {
|
|
1963
1981
|
let gzipStream;
|
|
1964
1982
|
try {
|
|
@@ -2100,7 +2118,7 @@
|
|
|
2100
2118
|
|
|
2101
2119
|
class InflateStream extends TransformStream {
|
|
2102
2120
|
|
|
2103
|
-
constructor(options, { chunkSize,
|
|
2121
|
+
constructor(options, { chunkSize, DecompressionStreamFallback, DecompressionStream }) {
|
|
2104
2122
|
super({});
|
|
2105
2123
|
const { zipCrypto, encrypted, checkCrc32, crc32, compressed, useCompressionStream, deflate64, format, compressionMethod, rawBitFlag, outputSize } = options;
|
|
2106
2124
|
let crc32Stream, decryptionStream;
|
|
@@ -2119,7 +2137,7 @@
|
|
|
2119
2137
|
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize, compressionMethod, rawBitFlag, uncompressedSize: outputSize }));
|
|
2120
2138
|
} else {
|
|
2121
2139
|
try {
|
|
2122
|
-
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream,
|
|
2140
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamFallback);
|
|
2123
2141
|
} catch (error) {
|
|
2124
2142
|
if (deflate64 || outputSize === UNDEFINED_VALUE) {
|
|
2125
2143
|
throw error;
|
|
@@ -2198,17 +2216,17 @@
|
|
|
2198
2216
|
return new CodecStreamClass(format, options);
|
|
2199
2217
|
}
|
|
2200
2218
|
|
|
2201
|
-
function pipeThroughCompressionStream(readable, useCompressionStream, options, CompressionStreamNative,
|
|
2219
|
+
function pipeThroughCompressionStream(readable, useCompressionStream, options, CompressionStreamNative, CompressionStreamFallback) {
|
|
2202
2220
|
const Stream = useCompressionStream && CompressionStreamNative ?
|
|
2203
2221
|
CompressionStreamNative :
|
|
2204
|
-
|
|
2222
|
+
CompressionStreamFallback || CompressionStreamNative;
|
|
2205
2223
|
const format = options.deflate64 ? FORMAT_DEFLATE64_RAW : FORMAT_DEFLATE_RAW;
|
|
2206
2224
|
let codecStream;
|
|
2207
2225
|
try {
|
|
2208
2226
|
codecStream = new Stream(format, options);
|
|
2209
2227
|
} catch (error) {
|
|
2210
|
-
if (useCompressionStream &&
|
|
2211
|
-
codecStream = new
|
|
2228
|
+
if (useCompressionStream && CompressionStreamFallback && Stream != CompressionStreamFallback) {
|
|
2229
|
+
codecStream = new CompressionStreamFallback(format, options);
|
|
2212
2230
|
} else {
|
|
2213
2231
|
throw error;
|
|
2214
2232
|
}
|
|
@@ -2471,7 +2489,7 @@
|
|
|
2471
2489
|
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2472
2490
|
const ERR_WORKER_STARTUP_TIMEOUT = "Worker startup timeout";
|
|
2473
2491
|
|
|
2474
|
-
let webWorkerSupported, webWorkerSource, webWorkerURI, webWorkerOptions;
|
|
2492
|
+
let webWorkerSupported, webWorkerSource, webWorkerURI, webWorkerOptions, createWorkerFailed;
|
|
2475
2493
|
let transferStreamsSupported = true;
|
|
2476
2494
|
try {
|
|
2477
2495
|
transferStreamsSupported = typeof structuredClone == FUNCTION_TYPE && structuredClone(new DOMException("", "AbortError")).code !== UNDEFINED_VALUE;
|
|
@@ -2481,14 +2499,14 @@
|
|
|
2481
2499
|
let initModule = () => { };
|
|
2482
2500
|
|
|
2483
2501
|
async function supportsDeflate(config) {
|
|
2484
|
-
const { CompressionStream: NativeStream,
|
|
2485
|
-
if (
|
|
2502
|
+
const { CompressionStream: NativeStream, CompressionStreamFallback: FallbackStream } = config;
|
|
2503
|
+
if (FallbackStream && !FallbackStream.requiresModule) {
|
|
2486
2504
|
return true;
|
|
2487
2505
|
}
|
|
2488
2506
|
if (supportsDeflateRaw(NativeStream) || supportsGzip(NativeStream)) {
|
|
2489
2507
|
return true;
|
|
2490
2508
|
}
|
|
2491
|
-
if (
|
|
2509
|
+
if (FallbackStream) {
|
|
2492
2510
|
try {
|
|
2493
2511
|
await initModule(config);
|
|
2494
2512
|
return true;
|
|
@@ -2501,12 +2519,16 @@
|
|
|
2501
2519
|
|
|
2502
2520
|
function resetWebWorkerSupport() {
|
|
2503
2521
|
webWorkerSupported = UNDEFINED_VALUE;
|
|
2522
|
+
createWorkerFailed = false;
|
|
2504
2523
|
}
|
|
2505
2524
|
|
|
2506
2525
|
class CodecWorker {
|
|
2507
2526
|
|
|
2508
|
-
constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI }, onTaskFinished) {
|
|
2527
|
+
constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI, createWorker }, onTaskFinished) {
|
|
2509
2528
|
const { signal } = streamOptions;
|
|
2529
|
+
if (createWorkerFailed) {
|
|
2530
|
+
createWorker = UNDEFINED_VALUE;
|
|
2531
|
+
}
|
|
2510
2532
|
Object.assign(workerData, {
|
|
2511
2533
|
busy: true,
|
|
2512
2534
|
generation: (workerData.generation || 0) + 1,
|
|
@@ -2516,6 +2538,7 @@
|
|
|
2516
2538
|
writable,
|
|
2517
2539
|
options: Object.assign({}, options),
|
|
2518
2540
|
workerURI,
|
|
2541
|
+
createWorker,
|
|
2519
2542
|
transferStreams,
|
|
2520
2543
|
terminate() {
|
|
2521
2544
|
return new Promise(resolve => {
|
|
@@ -2551,7 +2574,7 @@
|
|
|
2551
2574
|
// deno-lint-ignore valid-typeof
|
|
2552
2575
|
webWorkerSupported = typeof Worker != UNDEFINED_TYPE;
|
|
2553
2576
|
}
|
|
2554
|
-
return (useWebWorkers && webWorkerSupported ? createWebWorkerInterface : createWorkerInterface)(workerData, config);
|
|
2577
|
+
return (useWebWorkers && ((webWorkerSupported && workerURI) || createWorker) ? createWebWorkerInterface : createWorkerInterface)(workerData, config);
|
|
2555
2578
|
}
|
|
2556
2579
|
}
|
|
2557
2580
|
|
|
@@ -2608,7 +2631,11 @@
|
|
|
2608
2631
|
try {
|
|
2609
2632
|
worker = getWebWorker(workerData.workerURI, baseURI, workerData);
|
|
2610
2633
|
} catch {
|
|
2611
|
-
|
|
2634
|
+
if (workerData.createWorker) {
|
|
2635
|
+
createWorkerFailed = true;
|
|
2636
|
+
} else {
|
|
2637
|
+
webWorkerSupported = false;
|
|
2638
|
+
}
|
|
2612
2639
|
return createWorkerInterface(workerData, config);
|
|
2613
2640
|
}
|
|
2614
2641
|
Object.assign(workerData, {
|
|
@@ -2621,7 +2648,11 @@
|
|
|
2621
2648
|
return await runWebWorker(workerData, { chunkSize, wasmURI, baseURI, workerStartupTimeout });
|
|
2622
2649
|
} catch (error) {
|
|
2623
2650
|
if (error && error.workerStartupFailed) {
|
|
2624
|
-
|
|
2651
|
+
if (workerData.createWorker) {
|
|
2652
|
+
createWorkerFailed = true;
|
|
2653
|
+
} else {
|
|
2654
|
+
webWorkerSupported = false;
|
|
2655
|
+
}
|
|
2625
2656
|
const { reader } = workerData;
|
|
2626
2657
|
if (reader) {
|
|
2627
2658
|
reader.releaseLock();
|
|
@@ -2644,17 +2675,17 @@
|
|
|
2644
2675
|
try {
|
|
2645
2676
|
if (options.compressed && !options.format) {
|
|
2646
2677
|
const deflate = options.codecType.startsWith(CODEC_DEFLATE);
|
|
2647
|
-
const
|
|
2678
|
+
const FallbackStream = deflate ? config.CompressionStreamFallback : config.DecompressionStreamFallback;
|
|
2648
2679
|
const NativeStream = deflate ? config.CompressionStream : config.DecompressionStream;
|
|
2649
2680
|
if (!options.useCompressionStream) {
|
|
2650
2681
|
try {
|
|
2651
2682
|
await initModule(config);
|
|
2652
2683
|
} catch {
|
|
2653
|
-
if (!
|
|
2684
|
+
if (!FallbackStream || FallbackStream.requiresModule) {
|
|
2654
2685
|
options.useCompressionStream = true;
|
|
2655
2686
|
}
|
|
2656
2687
|
}
|
|
2657
|
-
} else if (
|
|
2688
|
+
} else if (FallbackStream && FallbackStream.requiresModule && !supportsDeflateRaw(NativeStream)) {
|
|
2658
2689
|
try {
|
|
2659
2690
|
await initModule(config);
|
|
2660
2691
|
} catch {
|
|
@@ -2779,8 +2810,11 @@
|
|
|
2779
2810
|
}
|
|
2780
2811
|
|
|
2781
2812
|
function getWebWorker(url, baseURI, workerData, isModuleType, useBlobURI = true) {
|
|
2813
|
+
const { createWorker } = workerData;
|
|
2782
2814
|
let worker, resolvedURI, resolvedOptions;
|
|
2783
|
-
if (
|
|
2815
|
+
if (createWorker) {
|
|
2816
|
+
worker = createWorker();
|
|
2817
|
+
} else if (webWorkerURI === UNDEFINED_VALUE || webWorkerSource !== url) {
|
|
2784
2818
|
// deno-lint-ignore valid-typeof
|
|
2785
2819
|
const isFunctionURI = typeof url == FUNCTION_TYPE;
|
|
2786
2820
|
if (isFunctionURI) {
|
|
@@ -3035,7 +3069,7 @@
|
|
|
3035
3069
|
async function runWorker(stream, workerOptions) {
|
|
3036
3070
|
const { options, config } = workerOptions;
|
|
3037
3071
|
const { transferStreams, useWebWorkers, useCompressionStream, compressed, checkCrc32, computeCrc32, encrypted, format, codecURI } = options;
|
|
3038
|
-
const { workerURI, maxWorkers } = config;
|
|
3072
|
+
const { workerURI, createWorker, maxWorkers } = config;
|
|
3039
3073
|
if (format) {
|
|
3040
3074
|
if (codecURI) {
|
|
3041
3075
|
options.codecURI = resolveCodecURI(codecURI, config.baseURI);
|
|
@@ -3047,6 +3081,7 @@
|
|
|
3047
3081
|
const workerSupported = format === UNDEFINED_VALUE || Boolean(options.codecURI);
|
|
3048
3082
|
workerOptions.useWebWorkers = !streamCopy && workerSupported && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
3049
3083
|
workerOptions.workerURI = workerOptions.useWebWorkers && workerURI ? workerURI : UNDEFINED_VALUE;
|
|
3084
|
+
workerOptions.createWorker = workerOptions.useWebWorkers && createWorker ? createWorker : UNDEFINED_VALUE;
|
|
3050
3085
|
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
3051
3086
|
return (await getWorker()).run();
|
|
3052
3087
|
|
|
@@ -3110,7 +3145,7 @@
|
|
|
3110
3145
|
starvationTimeout = null;
|
|
3111
3146
|
if (pendingRequests.length) {
|
|
3112
3147
|
const [{ resolve, stream, workerOptions }] = pendingRequests.splice(0, 1);
|
|
3113
|
-
const inlineWorkerOptions = Object.assign({}, workerOptions, { useWebWorkers: false, workerURI: UNDEFINED_VALUE });
|
|
3148
|
+
const inlineWorkerOptions = Object.assign({}, workerOptions, { useWebWorkers: false, workerURI: UNDEFINED_VALUE, createWorker: UNDEFINED_VALUE });
|
|
3114
3149
|
resolve(new CodecWorker({}, stream, inlineWorkerOptions, onInlineTaskFinished));
|
|
3115
3150
|
armStarvationTimeout();
|
|
3116
3151
|
}
|