@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
|
@@ -167,6 +167,7 @@ const CONFIGURABLE_PROPERTY_NAMES = [
|
|
|
167
167
|
"baseURI",
|
|
168
168
|
"wasmURI",
|
|
169
169
|
"workerURI",
|
|
170
|
+
"createWorker",
|
|
170
171
|
"chunkSize",
|
|
171
172
|
"maxWorkers",
|
|
172
173
|
"terminateWorkerTimeout",
|
|
@@ -177,8 +178,8 @@ const CONFIGURABLE_PROPERTY_NAMES = [
|
|
|
177
178
|
"transferStreams",
|
|
178
179
|
"CompressionStream",
|
|
179
180
|
"DecompressionStream",
|
|
180
|
-
"
|
|
181
|
-
"
|
|
181
|
+
"CompressionStreamFallback",
|
|
182
|
+
"DecompressionStreamFallback"
|
|
182
183
|
];
|
|
183
184
|
|
|
184
185
|
const config = { ...DEFAULT_CONFIGURATION };
|
|
@@ -192,6 +193,7 @@ function getChunkSize(config) {
|
|
|
192
193
|
}
|
|
193
194
|
|
|
194
195
|
function configure(configuration) {
|
|
196
|
+
configuration = normalizeConfiguration(configuration);
|
|
195
197
|
for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
|
|
196
198
|
const propertyValue = configuration[propertyName];
|
|
197
199
|
if (propertyValue !== UNDEFINED_VALUE) {
|
|
@@ -200,7 +202,23 @@ function configure(configuration) {
|
|
|
200
202
|
}
|
|
201
203
|
}
|
|
202
204
|
|
|
205
|
+
function normalizeConfiguration(configuration) {
|
|
206
|
+
const { CompressionStreamZlib, DecompressionStreamZlib } = configuration;
|
|
207
|
+
if (CompressionStreamZlib === UNDEFINED_VALUE && DecompressionStreamZlib === UNDEFINED_VALUE) {
|
|
208
|
+
return configuration;
|
|
209
|
+
}
|
|
210
|
+
const normalizedConfiguration = Object.assign({}, configuration);
|
|
211
|
+
if (normalizedConfiguration.CompressionStreamFallback === UNDEFINED_VALUE) {
|
|
212
|
+
normalizedConfiguration.CompressionStreamFallback = CompressionStreamZlib;
|
|
213
|
+
}
|
|
214
|
+
if (normalizedConfiguration.DecompressionStreamFallback === UNDEFINED_VALUE) {
|
|
215
|
+
normalizedConfiguration.DecompressionStreamFallback = DecompressionStreamZlib;
|
|
216
|
+
}
|
|
217
|
+
return normalizedConfiguration;
|
|
218
|
+
}
|
|
219
|
+
|
|
203
220
|
function setDefaultConfiguration(configuration) {
|
|
221
|
+
configuration = normalizeConfiguration(configuration);
|
|
204
222
|
for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
|
|
205
223
|
const propertyValue = configuration[propertyName];
|
|
206
224
|
if (propertyValue !== UNDEFINED_VALUE) {
|
|
@@ -1963,7 +1981,7 @@ const GZIP_OUTPUT_STALL_TIMEOUT = 5000;
|
|
|
1963
1981
|
|
|
1964
1982
|
class DeflateStream extends TransformStream {
|
|
1965
1983
|
|
|
1966
|
-
constructor(options, { chunkSize,
|
|
1984
|
+
constructor(options, { chunkSize, CompressionStreamFallback, CompressionStream }) {
|
|
1967
1985
|
super({});
|
|
1968
1986
|
const { compressed, encrypted, useCompressionStream, zipCrypto, computeCrc32, level, deflate64, format, compressionMethod } = options;
|
|
1969
1987
|
const stream = this;
|
|
@@ -1985,7 +2003,7 @@ class DeflateStream extends TransformStream {
|
|
|
1985
2003
|
readable = pipeThrough(readable, gzipCrc32Stream);
|
|
1986
2004
|
} else {
|
|
1987
2005
|
try {
|
|
1988
|
-
readable = pipeThroughCompressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStream,
|
|
2006
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStream, CompressionStreamFallback);
|
|
1989
2007
|
} catch (error) {
|
|
1990
2008
|
let gzipStream;
|
|
1991
2009
|
try {
|
|
@@ -2127,7 +2145,7 @@ function pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize) {
|
|
|
2127
2145
|
|
|
2128
2146
|
class InflateStream extends TransformStream {
|
|
2129
2147
|
|
|
2130
|
-
constructor(options, { chunkSize,
|
|
2148
|
+
constructor(options, { chunkSize, DecompressionStreamFallback, DecompressionStream }) {
|
|
2131
2149
|
super({});
|
|
2132
2150
|
const { zipCrypto, encrypted, checkCrc32, crc32, compressed, useCompressionStream, deflate64, format, compressionMethod, rawBitFlag, outputSize } = options;
|
|
2133
2151
|
let crc32Stream, decryptionStream;
|
|
@@ -2146,7 +2164,7 @@ class InflateStream extends TransformStream {
|
|
|
2146
2164
|
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize, compressionMethod, rawBitFlag, uncompressedSize: outputSize }));
|
|
2147
2165
|
} else {
|
|
2148
2166
|
try {
|
|
2149
|
-
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream,
|
|
2167
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamFallback);
|
|
2150
2168
|
} catch (error) {
|
|
2151
2169
|
if (deflate64 || outputSize === UNDEFINED_VALUE) {
|
|
2152
2170
|
throw error;
|
|
@@ -2225,17 +2243,17 @@ function createCodecStream(CodecStreamClass, format, options) {
|
|
|
2225
2243
|
return new CodecStreamClass(format, options);
|
|
2226
2244
|
}
|
|
2227
2245
|
|
|
2228
|
-
function pipeThroughCompressionStream(readable, useCompressionStream, options, CompressionStreamNative,
|
|
2246
|
+
function pipeThroughCompressionStream(readable, useCompressionStream, options, CompressionStreamNative, CompressionStreamFallback) {
|
|
2229
2247
|
const Stream = useCompressionStream && CompressionStreamNative ?
|
|
2230
2248
|
CompressionStreamNative :
|
|
2231
|
-
|
|
2249
|
+
CompressionStreamFallback || CompressionStreamNative;
|
|
2232
2250
|
const format = options.deflate64 ? FORMAT_DEFLATE64_RAW : FORMAT_DEFLATE_RAW;
|
|
2233
2251
|
let codecStream;
|
|
2234
2252
|
try {
|
|
2235
2253
|
codecStream = new Stream(format, options);
|
|
2236
2254
|
} catch (error) {
|
|
2237
|
-
if (useCompressionStream &&
|
|
2238
|
-
codecStream = new
|
|
2255
|
+
if (useCompressionStream && CompressionStreamFallback && Stream != CompressionStreamFallback) {
|
|
2256
|
+
codecStream = new CompressionStreamFallback(format, options);
|
|
2239
2257
|
} else {
|
|
2240
2258
|
throw error;
|
|
2241
2259
|
}
|
|
@@ -2498,7 +2516,7 @@ const ERROR_EVENT_TYPE = "error";
|
|
|
2498
2516
|
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2499
2517
|
const ERR_WORKER_STARTUP_TIMEOUT = "Worker startup timeout";
|
|
2500
2518
|
|
|
2501
|
-
let webWorkerSupported, webWorkerSource, webWorkerURI, webWorkerOptions;
|
|
2519
|
+
let webWorkerSupported, webWorkerSource, webWorkerURI, webWorkerOptions, createWorkerFailed;
|
|
2502
2520
|
let transferStreamsSupported = true;
|
|
2503
2521
|
try {
|
|
2504
2522
|
transferStreamsSupported = typeof structuredClone == FUNCTION_TYPE && structuredClone(new DOMException("", "AbortError")).code !== UNDEFINED_VALUE;
|
|
@@ -2512,14 +2530,14 @@ function configureWorker({ initModule: initModuleFunction }) {
|
|
|
2512
2530
|
}
|
|
2513
2531
|
|
|
2514
2532
|
async function supportsDeflate(config) {
|
|
2515
|
-
const { CompressionStream: NativeStream,
|
|
2516
|
-
if (
|
|
2533
|
+
const { CompressionStream: NativeStream, CompressionStreamFallback: FallbackStream } = config;
|
|
2534
|
+
if (FallbackStream && !FallbackStream.requiresModule) {
|
|
2517
2535
|
return true;
|
|
2518
2536
|
}
|
|
2519
2537
|
if (supportsDeflateRaw(NativeStream) || supportsGzip(NativeStream)) {
|
|
2520
2538
|
return true;
|
|
2521
2539
|
}
|
|
2522
|
-
if (
|
|
2540
|
+
if (FallbackStream) {
|
|
2523
2541
|
try {
|
|
2524
2542
|
await initModule$1(config);
|
|
2525
2543
|
return true;
|
|
@@ -2532,12 +2550,16 @@ async function supportsDeflate(config) {
|
|
|
2532
2550
|
|
|
2533
2551
|
function resetWebWorkerSupport() {
|
|
2534
2552
|
webWorkerSupported = UNDEFINED_VALUE;
|
|
2553
|
+
createWorkerFailed = false;
|
|
2535
2554
|
}
|
|
2536
2555
|
|
|
2537
2556
|
class CodecWorker {
|
|
2538
2557
|
|
|
2539
|
-
constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI }, onTaskFinished) {
|
|
2558
|
+
constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI, createWorker }, onTaskFinished) {
|
|
2540
2559
|
const { signal } = streamOptions;
|
|
2560
|
+
if (createWorkerFailed) {
|
|
2561
|
+
createWorker = UNDEFINED_VALUE;
|
|
2562
|
+
}
|
|
2541
2563
|
Object.assign(workerData, {
|
|
2542
2564
|
busy: true,
|
|
2543
2565
|
generation: (workerData.generation || 0) + 1,
|
|
@@ -2547,6 +2569,7 @@ class CodecWorker {
|
|
|
2547
2569
|
writable,
|
|
2548
2570
|
options: Object.assign({}, options),
|
|
2549
2571
|
workerURI,
|
|
2572
|
+
createWorker,
|
|
2550
2573
|
transferStreams,
|
|
2551
2574
|
terminate() {
|
|
2552
2575
|
return new Promise(resolve => {
|
|
@@ -2582,7 +2605,7 @@ class CodecWorker {
|
|
|
2582
2605
|
// deno-lint-ignore valid-typeof
|
|
2583
2606
|
webWorkerSupported = typeof Worker != UNDEFINED_TYPE;
|
|
2584
2607
|
}
|
|
2585
|
-
return (useWebWorkers && webWorkerSupported ? createWebWorkerInterface : createWorkerInterface)(workerData, config);
|
|
2608
|
+
return (useWebWorkers && ((webWorkerSupported && workerURI) || createWorker) ? createWebWorkerInterface : createWorkerInterface)(workerData, config);
|
|
2586
2609
|
}
|
|
2587
2610
|
}
|
|
2588
2611
|
|
|
@@ -2639,7 +2662,11 @@ function createWebWorkerInterface(workerData, config) {
|
|
|
2639
2662
|
try {
|
|
2640
2663
|
worker = getWebWorker(workerData.workerURI, baseURI, workerData);
|
|
2641
2664
|
} catch {
|
|
2642
|
-
|
|
2665
|
+
if (workerData.createWorker) {
|
|
2666
|
+
createWorkerFailed = true;
|
|
2667
|
+
} else {
|
|
2668
|
+
webWorkerSupported = false;
|
|
2669
|
+
}
|
|
2643
2670
|
return createWorkerInterface(workerData, config);
|
|
2644
2671
|
}
|
|
2645
2672
|
Object.assign(workerData, {
|
|
@@ -2652,7 +2679,11 @@ function createWebWorkerInterface(workerData, config) {
|
|
|
2652
2679
|
return await runWebWorker(workerData, { chunkSize, wasmURI, baseURI, workerStartupTimeout });
|
|
2653
2680
|
} catch (error) {
|
|
2654
2681
|
if (error && error.workerStartupFailed) {
|
|
2655
|
-
|
|
2682
|
+
if (workerData.createWorker) {
|
|
2683
|
+
createWorkerFailed = true;
|
|
2684
|
+
} else {
|
|
2685
|
+
webWorkerSupported = false;
|
|
2686
|
+
}
|
|
2656
2687
|
const { reader } = workerData;
|
|
2657
2688
|
if (reader) {
|
|
2658
2689
|
reader.releaseLock();
|
|
@@ -2675,17 +2706,17 @@ async function runWorker$1({ options, readable, writable, onTaskFinished }, conf
|
|
|
2675
2706
|
try {
|
|
2676
2707
|
if (options.compressed && !options.format) {
|
|
2677
2708
|
const deflate = options.codecType.startsWith(CODEC_DEFLATE);
|
|
2678
|
-
const
|
|
2709
|
+
const FallbackStream = deflate ? config.CompressionStreamFallback : config.DecompressionStreamFallback;
|
|
2679
2710
|
const NativeStream = deflate ? config.CompressionStream : config.DecompressionStream;
|
|
2680
2711
|
if (!options.useCompressionStream) {
|
|
2681
2712
|
try {
|
|
2682
2713
|
await initModule$1(config);
|
|
2683
2714
|
} catch {
|
|
2684
|
-
if (!
|
|
2715
|
+
if (!FallbackStream || FallbackStream.requiresModule) {
|
|
2685
2716
|
options.useCompressionStream = true;
|
|
2686
2717
|
}
|
|
2687
2718
|
}
|
|
2688
|
-
} else if (
|
|
2719
|
+
} else if (FallbackStream && FallbackStream.requiresModule && !supportsDeflateRaw(NativeStream)) {
|
|
2689
2720
|
try {
|
|
2690
2721
|
await initModule$1(config);
|
|
2691
2722
|
} catch {
|
|
@@ -2810,8 +2841,11 @@ function terminateWorker$1(workerData) {
|
|
|
2810
2841
|
}
|
|
2811
2842
|
|
|
2812
2843
|
function getWebWorker(url, baseURI, workerData, isModuleType, useBlobURI = true) {
|
|
2844
|
+
const { createWorker } = workerData;
|
|
2813
2845
|
let worker, resolvedURI, resolvedOptions;
|
|
2814
|
-
if (
|
|
2846
|
+
if (createWorker) {
|
|
2847
|
+
worker = createWorker();
|
|
2848
|
+
} else if (webWorkerURI === UNDEFINED_VALUE || webWorkerSource !== url) {
|
|
2815
2849
|
// deno-lint-ignore valid-typeof
|
|
2816
2850
|
const isFunctionURI = typeof url == FUNCTION_TYPE;
|
|
2817
2851
|
if (isFunctionURI) {
|
|
@@ -3066,7 +3100,7 @@ let indexWorker = 0;
|
|
|
3066
3100
|
async function runWorker(stream, workerOptions) {
|
|
3067
3101
|
const { options, config } = workerOptions;
|
|
3068
3102
|
const { transferStreams, useWebWorkers, useCompressionStream, compressed, checkCrc32, computeCrc32, encrypted, format, codecURI } = options;
|
|
3069
|
-
const { workerURI, maxWorkers } = config;
|
|
3103
|
+
const { workerURI, createWorker, maxWorkers } = config;
|
|
3070
3104
|
if (format) {
|
|
3071
3105
|
if (codecURI) {
|
|
3072
3106
|
options.codecURI = resolveCodecURI(codecURI, config.baseURI);
|
|
@@ -3078,6 +3112,7 @@ async function runWorker(stream, workerOptions) {
|
|
|
3078
3112
|
const workerSupported = format === UNDEFINED_VALUE || Boolean(options.codecURI);
|
|
3079
3113
|
workerOptions.useWebWorkers = !streamCopy && workerSupported && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
3080
3114
|
workerOptions.workerURI = workerOptions.useWebWorkers && workerURI ? workerURI : UNDEFINED_VALUE;
|
|
3115
|
+
workerOptions.createWorker = workerOptions.useWebWorkers && createWorker ? createWorker : UNDEFINED_VALUE;
|
|
3081
3116
|
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
3082
3117
|
return (await getWorker()).run();
|
|
3083
3118
|
|
|
@@ -3141,7 +3176,7 @@ function onWorkerStarvation() {
|
|
|
3141
3176
|
starvationTimeout = null;
|
|
3142
3177
|
if (pendingRequests.length) {
|
|
3143
3178
|
const [{ resolve, stream, workerOptions }] = pendingRequests.splice(0, 1);
|
|
3144
|
-
const inlineWorkerOptions = Object.assign({}, workerOptions, { useWebWorkers: false, workerURI: UNDEFINED_VALUE });
|
|
3179
|
+
const inlineWorkerOptions = Object.assign({}, workerOptions, { useWebWorkers: false, workerURI: UNDEFINED_VALUE, createWorker: UNDEFINED_VALUE });
|
|
3145
3180
|
resolve(new CodecWorker({}, stream, inlineWorkerOptions, onInlineTaskFinished));
|
|
3146
3181
|
armStarvationTimeout();
|
|
3147
3182
|
}
|
|
@@ -8278,8 +8313,8 @@ configureWorker({
|
|
|
8278
8313
|
}
|
|
8279
8314
|
});
|
|
8280
8315
|
setDefaultConfiguration({
|
|
8281
|
-
CompressionStreamZlib,
|
|
8282
|
-
DecompressionStreamZlib
|
|
8316
|
+
CompressionStreamFallback: CompressionStreamZlib,
|
|
8317
|
+
DecompressionStreamFallback: DecompressionStreamZlib
|
|
8283
8318
|
});
|
|
8284
8319
|
|
|
8285
8320
|
function terminateWorkersAndModule() {
|