@zip.js/zip.js 2.8.36 → 2.8.38
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 +4 -2
- package/dist/zip-core.js +356 -63
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core.js +301 -63
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-native.js +359 -66
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +357 -64
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +358 -65
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +359 -66
- 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 +357 -64
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +359 -66
- package/index-native.min.js +1 -1
- package/index.cjs +357 -64
- package/index.d.cts +126 -4
- package/index.d.ts +126 -4
- package/index.min.js +1 -1
- package/lib/core/codec-pool.js +21 -4
- package/lib/core/codec-registry.js +116 -0
- package/lib/core/codec-worker.js +94 -18
- package/lib/core/configuration.js +2 -0
- package/lib/core/constants.js +5 -1
- package/lib/core/options.js +2 -0
- package/lib/core/streams/codec-stream.js +6 -2
- package/lib/core/streams/zip-entry-stream.js +50 -16
- package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
- package/lib/core/web-worker-base.js +30 -8
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-reader.js +29 -3
- package/lib/core/zip-writer.js +68 -25
- package/lib/zip-core-base.js +7 -0
- package/lib/zip-core-reader.js +2 -1
- package/lib/zip-core-writer.js +1 -0
- package/package.json +1 -1
- package/worker-message-property-names.js +1 -1
package/dist/zip-core.js
CHANGED
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
47
47
|
const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
|
|
48
48
|
const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
|
|
49
|
+
const ARCHIVE_EXTRA_DATA_SIGNATURE = 0x08064b50;
|
|
49
50
|
const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
|
|
50
51
|
const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
|
|
51
52
|
const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
|
|
@@ -77,6 +78,7 @@
|
|
|
77
78
|
const BITFLAG_LEVEL_FAST_MASK = 0b100;
|
|
78
79
|
const BITFLAG_LEVEL_SUPER_FAST_MASK = 0b110;
|
|
79
80
|
const BITFLAG_DATA_DESCRIPTOR = 0b1000;
|
|
81
|
+
const BITFLAG_STRONG_ENCRYPTION = 0b1000000;
|
|
80
82
|
const BITFLAG_LANG_ENCODING_FLAG = 0b100000000000;
|
|
81
83
|
const FILE_ATTR_MSDOS_DIR_MASK = 0b10000;
|
|
82
84
|
const FILE_ATTR_MSDOS_READONLY_MASK = 0x01;
|
|
@@ -104,7 +106,7 @@
|
|
|
104
106
|
const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
|
|
105
107
|
const LOCAL_HEADER_COMMON_OFFSET = 4;
|
|
106
108
|
|
|
107
|
-
const MAX_DATE = new Date(2107, 11, 31);
|
|
109
|
+
const MAX_DATE = new Date(2107, 11, 31, 23, 59, 58);
|
|
108
110
|
const MIN_DATE = new Date(1980, 0, 1);
|
|
109
111
|
|
|
110
112
|
const UNDEFINED_VALUE = undefined;
|
|
@@ -160,6 +162,7 @@
|
|
|
160
162
|
maxWorkers,
|
|
161
163
|
terminateWorkerTimeout: 5000,
|
|
162
164
|
workerStarvationTimeout: 5000,
|
|
165
|
+
workerStartupTimeout: 5000,
|
|
163
166
|
useWebWorkers: true,
|
|
164
167
|
useCompressionStream: true,
|
|
165
168
|
transferStreams: true,
|
|
@@ -175,6 +178,7 @@
|
|
|
175
178
|
"maxWorkers",
|
|
176
179
|
"terminateWorkerTimeout",
|
|
177
180
|
"workerStarvationTimeout",
|
|
181
|
+
"workerStartupTimeout",
|
|
178
182
|
"useCompressionStream",
|
|
179
183
|
"useWebWorkers",
|
|
180
184
|
"transferStreams",
|
|
@@ -220,6 +224,103 @@
|
|
|
220
224
|
Object.assign(config, DEFAULT_CONFIGURATION);
|
|
221
225
|
}
|
|
222
226
|
|
|
227
|
+
/*
|
|
228
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
229
|
+
|
|
230
|
+
Redistribution and use in source and binary forms, with or without
|
|
231
|
+
modification, are permitted provided that the following conditions are met:
|
|
232
|
+
|
|
233
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
234
|
+
this list of conditions and the following disclaimer.
|
|
235
|
+
|
|
236
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
237
|
+
notice, this list of conditions and the following disclaimer in
|
|
238
|
+
the documentation and/or other materials provided with the distribution.
|
|
239
|
+
|
|
240
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
241
|
+
derived from this software without specific prior written permission.
|
|
242
|
+
|
|
243
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
244
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
245
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
246
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
247
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
248
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
249
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
250
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
251
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
252
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
const ERR_INVALID_CODEC_DEFINITION = "Invalid codec definition";
|
|
257
|
+
const ERR_RESERVED_COMPRESSION_METHOD = "Reserved compression method";
|
|
258
|
+
const ERR_INVALID_CODEC_MODULE = "Invalid codec module";
|
|
259
|
+
|
|
260
|
+
const STRING_TYPE = "string";
|
|
261
|
+
const RESERVED_COMPRESSION_METHODS = [
|
|
262
|
+
COMPRESSION_METHOD_STORE,
|
|
263
|
+
COMPRESSION_METHOD_DEFLATE,
|
|
264
|
+
COMPRESSION_METHOD_DEFLATE_64,
|
|
265
|
+
COMPRESSION_METHOD_AES
|
|
266
|
+
];
|
|
267
|
+
|
|
268
|
+
const registeredCodecs = new Map();
|
|
269
|
+
const codecStreams = new Map();
|
|
270
|
+
|
|
271
|
+
function registerCodec(codec = {}) {
|
|
272
|
+
const { compressionMethod, format, codecURI, CompressionStream, DecompressionStream, versionNeeded } = codec;
|
|
273
|
+
if (!Number.isInteger(compressionMethod) || compressionMethod < 0 || compressionMethod > MAX_16_BITS ||
|
|
274
|
+
typeof format != STRING_TYPE || !format.length) {
|
|
275
|
+
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
276
|
+
}
|
|
277
|
+
if (RESERVED_COMPRESSION_METHODS.includes(compressionMethod)) {
|
|
278
|
+
throw new Error(ERR_RESERVED_COMPRESSION_METHOD);
|
|
279
|
+
}
|
|
280
|
+
const hasStreams = typeof CompressionStream == FUNCTION_TYPE || typeof DecompressionStream == FUNCTION_TYPE;
|
|
281
|
+
if (!hasStreams && (typeof codecURI != STRING_TYPE || !codecURI.length)) {
|
|
282
|
+
throw new Error(ERR_INVALID_CODEC_DEFINITION);
|
|
283
|
+
}
|
|
284
|
+
registeredCodecs.set(compressionMethod, { compressionMethod, format, codecURI, versionNeeded });
|
|
285
|
+
if (hasStreams) {
|
|
286
|
+
setCodecStreams(format, { CompressionStream, DecompressionStream });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function unregisterCodec(compressionMethod) {
|
|
291
|
+
const codec = registeredCodecs.get(compressionMethod);
|
|
292
|
+
if (codec) {
|
|
293
|
+
registeredCodecs.delete(compressionMethod);
|
|
294
|
+
let formatUsed;
|
|
295
|
+
registeredCodecs.forEach(otherCodec => formatUsed = formatUsed || otherCodec.format == codec.format);
|
|
296
|
+
if (!formatUsed) {
|
|
297
|
+
codecStreams.delete(codec.format);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function getRegisteredCodec(compressionMethod) {
|
|
303
|
+
return registeredCodecs.get(compressionMethod);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function getCodecStreams(format) {
|
|
307
|
+
return codecStreams.get(format);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function setCodecStreams(format, streams) {
|
|
311
|
+
const { CompressionStream, DecompressionStream } = streams;
|
|
312
|
+
if (typeof CompressionStream != FUNCTION_TYPE && typeof DecompressionStream != FUNCTION_TYPE) {
|
|
313
|
+
throw new Error(ERR_INVALID_CODEC_MODULE);
|
|
314
|
+
}
|
|
315
|
+
codecStreams.set(format, { CompressionStream, DecompressionStream });
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function ensureCodecStreams(format, codecURI) {
|
|
319
|
+
if (!codecStreams.has(format) && codecURI) {
|
|
320
|
+
setCodecStreams(format, await import(codecURI));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
223
324
|
/*
|
|
224
325
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
225
326
|
|
|
@@ -1756,6 +1857,7 @@
|
|
|
1756
1857
|
|
|
1757
1858
|
const ERR_INVALID_UNCOMPRESSED_SIZE = "Invalid uncompressed size";
|
|
1758
1859
|
const ERR_INVALID_COMPRESSED_DATA = "Invalid compressed data";
|
|
1860
|
+
const ERR_UNSUPPORTED_COMPRESSION$2 = "Compression method not supported";
|
|
1759
1861
|
const FORMAT_DEFLATE_RAW = "deflate-raw";
|
|
1760
1862
|
const FORMAT_DEFLATE64_RAW = "deflate64-raw";
|
|
1761
1863
|
const FORMAT_GZIP = "gzip";
|
|
@@ -1766,23 +1868,26 @@
|
|
|
1766
1868
|
|
|
1767
1869
|
constructor(options, { chunkSize, CompressionStreamZlib, CompressionStream }) {
|
|
1768
1870
|
super({});
|
|
1769
|
-
const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64 } = options;
|
|
1871
|
+
const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64, format } = options;
|
|
1770
1872
|
const stream = this;
|
|
1771
1873
|
let crc32Stream, encryptionStream, gzipCrc32Stream;
|
|
1772
1874
|
let readable = super.readable;
|
|
1773
|
-
const
|
|
1875
|
+
const codecStreams = format && getCodecStreams(format);
|
|
1876
|
+
const useGzipCrc32 = signed && compressed && !deflate64 && !codecStreams && (!encrypted || zipCrypto) &&
|
|
1774
1877
|
Boolean(useCompressionStream && CompressionStream);
|
|
1775
1878
|
if ((!encrypted || zipCrypto) && signed && !useGzipCrc32) {
|
|
1776
1879
|
crc32Stream = new Crc32Stream();
|
|
1777
1880
|
readable = pipeThrough(readable, crc32Stream);
|
|
1778
1881
|
}
|
|
1779
1882
|
if (compressed) {
|
|
1780
|
-
if (
|
|
1883
|
+
if (codecStreams) {
|
|
1884
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.CompressionStream, format, { level, chunkSize }));
|
|
1885
|
+
} else if (useGzipCrc32) {
|
|
1781
1886
|
gzipCrc32Stream = new GzipToRawDeflateStream();
|
|
1782
1887
|
readable = pipeThroughBackpressured(readable, new CompressionStream(FORMAT_GZIP));
|
|
1783
1888
|
readable = pipeThrough(readable, gzipCrc32Stream);
|
|
1784
1889
|
} else {
|
|
1785
|
-
readable =
|
|
1890
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStream, CompressionStreamZlib);
|
|
1786
1891
|
}
|
|
1787
1892
|
}
|
|
1788
1893
|
if (encrypted) {
|
|
@@ -1851,7 +1956,7 @@
|
|
|
1851
1956
|
|
|
1852
1957
|
constructor(options, { chunkSize, DecompressionStreamZlib, DecompressionStream }) {
|
|
1853
1958
|
super({});
|
|
1854
|
-
const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64 } = options;
|
|
1959
|
+
const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64, format } = options;
|
|
1855
1960
|
let crc32Stream, decryptionStream;
|
|
1856
1961
|
let readable = super.readable;
|
|
1857
1962
|
if (encrypted) {
|
|
@@ -1863,7 +1968,12 @@
|
|
|
1863
1968
|
}
|
|
1864
1969
|
}
|
|
1865
1970
|
if (compressed) {
|
|
1866
|
-
|
|
1971
|
+
const codecStreams = format && getCodecStreams(format);
|
|
1972
|
+
if (codecStreams) {
|
|
1973
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize }));
|
|
1974
|
+
} else {
|
|
1975
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamZlib);
|
|
1976
|
+
}
|
|
1867
1977
|
readable = mapInflateStreamError(readable);
|
|
1868
1978
|
}
|
|
1869
1979
|
if ((!encrypted || zipCrypto) && signed) {
|
|
@@ -1881,6 +1991,25 @@
|
|
|
1881
1991
|
}
|
|
1882
1992
|
}
|
|
1883
1993
|
|
|
1994
|
+
const deflateRawSupportByStream = new Map();
|
|
1995
|
+
|
|
1996
|
+
function supportsDeflateRaw(StreamClass) {
|
|
1997
|
+
if (!StreamClass) {
|
|
1998
|
+
return false;
|
|
1999
|
+
}
|
|
2000
|
+
let supported = deflateRawSupportByStream.get(StreamClass);
|
|
2001
|
+
if (supported === UNDEFINED_VALUE) {
|
|
2002
|
+
try {
|
|
2003
|
+
new StreamClass(FORMAT_DEFLATE_RAW);
|
|
2004
|
+
supported = true;
|
|
2005
|
+
} catch {
|
|
2006
|
+
supported = false;
|
|
2007
|
+
}
|
|
2008
|
+
deflateRawSupportByStream.set(StreamClass, supported);
|
|
2009
|
+
}
|
|
2010
|
+
return supported;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
1884
2013
|
function setReadable(stream, readable, flush) {
|
|
1885
2014
|
readable = pipeThrough(readable, new TransformStream({ flush }));
|
|
1886
2015
|
Object.defineProperty(stream, "readable", {
|
|
@@ -1890,21 +2019,24 @@
|
|
|
1890
2019
|
});
|
|
1891
2020
|
}
|
|
1892
2021
|
|
|
1893
|
-
function
|
|
1894
|
-
|
|
2022
|
+
function createCodecStream(CodecStreamClass, format, options) {
|
|
2023
|
+
if (!CodecStreamClass) {
|
|
2024
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION$2);
|
|
2025
|
+
}
|
|
2026
|
+
return new CodecStreamClass(format, options);
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
function pipeThroughCompressionStream(readable, useCompressionStream, options, CompressionStreamNative, CompressionStreamZlib) {
|
|
2030
|
+
const Stream = useCompressionStream && CompressionStreamNative ?
|
|
2031
|
+
CompressionStreamNative :
|
|
2032
|
+
CompressionStreamZlib || CompressionStreamNative;
|
|
1895
2033
|
const format = options.deflate64 ? FORMAT_DEFLATE64_RAW : FORMAT_DEFLATE_RAW;
|
|
1896
2034
|
let codecStream;
|
|
1897
2035
|
try {
|
|
1898
2036
|
codecStream = new Stream(format, options);
|
|
1899
2037
|
} catch (error) {
|
|
1900
|
-
if (useCompressionStream) {
|
|
1901
|
-
|
|
1902
|
-
codecStream = new CompressionStreamZlib(format, options);
|
|
1903
|
-
} else if (CompressionStream) {
|
|
1904
|
-
codecStream = new CompressionStream(format, options);
|
|
1905
|
-
} else {
|
|
1906
|
-
throw error;
|
|
1907
|
-
}
|
|
2038
|
+
if (useCompressionStream && CompressionStreamZlib && Stream != CompressionStreamZlib) {
|
|
2039
|
+
codecStream = new CompressionStreamZlib(format, options);
|
|
1908
2040
|
} else {
|
|
1909
2041
|
throw error;
|
|
1910
2042
|
}
|
|
@@ -2165,6 +2297,7 @@
|
|
|
2165
2297
|
const MODULE_WORKER_OPTIONS = { type: "module" };
|
|
2166
2298
|
const ERROR_EVENT_TYPE = "error";
|
|
2167
2299
|
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2300
|
+
const ERR_WORKER_STARTUP_TIMEOUT = "Worker startup timeout";
|
|
2168
2301
|
|
|
2169
2302
|
let webWorkerSupported, webWorkerSource, webWorkerURI, webWorkerOptions;
|
|
2170
2303
|
let transferStreamsSupported = true;
|
|
@@ -2175,6 +2308,10 @@
|
|
|
2175
2308
|
}
|
|
2176
2309
|
let initModule = () => { };
|
|
2177
2310
|
|
|
2311
|
+
function resetWebWorkerSupport() {
|
|
2312
|
+
webWorkerSupported = UNDEFINED_VALUE;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2178
2315
|
class CodecWorker {
|
|
2179
2316
|
|
|
2180
2317
|
constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI }, onTaskFinished) {
|
|
@@ -2268,7 +2405,7 @@
|
|
|
2268
2405
|
}
|
|
2269
2406
|
|
|
2270
2407
|
function createWebWorkerInterface(workerData, config) {
|
|
2271
|
-
const { baseURI, chunkSize } = config;
|
|
2408
|
+
const { baseURI, chunkSize, workerStartupTimeout } = config;
|
|
2272
2409
|
let { wasmURI } = config;
|
|
2273
2410
|
|
|
2274
2411
|
if (!workerData.interface) {
|
|
@@ -2285,9 +2422,26 @@
|
|
|
2285
2422
|
}
|
|
2286
2423
|
Object.assign(workerData, {
|
|
2287
2424
|
worker,
|
|
2425
|
+
workerAlive: false,
|
|
2288
2426
|
terminated: false,
|
|
2289
2427
|
interface: {
|
|
2290
|
-
run: () =>
|
|
2428
|
+
run: async () => {
|
|
2429
|
+
try {
|
|
2430
|
+
return await runWebWorker(workerData, { chunkSize, wasmURI, baseURI, workerStartupTimeout });
|
|
2431
|
+
} catch (error) {
|
|
2432
|
+
if (error && error.workerStartupFailed) {
|
|
2433
|
+
webWorkerSupported = false;
|
|
2434
|
+
const { reader } = workerData;
|
|
2435
|
+
if (reader) {
|
|
2436
|
+
reader.releaseLock();
|
|
2437
|
+
}
|
|
2438
|
+
workerData.reader = null;
|
|
2439
|
+
workerData.writer = null;
|
|
2440
|
+
return runWorker$1(workerData, config);
|
|
2441
|
+
}
|
|
2442
|
+
throw error;
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2291
2445
|
}
|
|
2292
2446
|
});
|
|
2293
2447
|
}
|
|
@@ -2297,15 +2451,23 @@
|
|
|
2297
2451
|
async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
|
|
2298
2452
|
let codecStream;
|
|
2299
2453
|
try {
|
|
2300
|
-
if (!options.
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
config
|
|
2307
|
-
|
|
2308
|
-
|
|
2454
|
+
if (options.compressed && !options.format) {
|
|
2455
|
+
const deflate = options.codecType.startsWith(CODEC_DEFLATE);
|
|
2456
|
+
const ZlibStream = deflate ? config.CompressionStreamZlib : config.DecompressionStreamZlib;
|
|
2457
|
+
const NativeStream = deflate ? config.CompressionStream : config.DecompressionStream;
|
|
2458
|
+
if (!options.useCompressionStream) {
|
|
2459
|
+
try {
|
|
2460
|
+
await initModule(config);
|
|
2461
|
+
} catch {
|
|
2462
|
+
if (!ZlibStream || ZlibStream.requiresModule) {
|
|
2463
|
+
options.useCompressionStream = true;
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
} else if (ZlibStream && ZlibStream.requiresModule && !supportsDeflateRaw(NativeStream)) {
|
|
2467
|
+
try {
|
|
2468
|
+
await initModule(config);
|
|
2469
|
+
} catch {
|
|
2470
|
+
// ignored
|
|
2309
2471
|
}
|
|
2310
2472
|
}
|
|
2311
2473
|
}
|
|
@@ -2374,6 +2536,10 @@
|
|
|
2374
2536
|
writer: writable.getWriter()
|
|
2375
2537
|
});
|
|
2376
2538
|
}
|
|
2539
|
+
const { workerStartupTimeout } = config;
|
|
2540
|
+
if (!workerData.workerAlive && Number.isFinite(workerStartupTimeout) && workerStartupTimeout >= 0) {
|
|
2541
|
+
workerData.startupTimeout = setTimeout(() => onStartupTimeout(workerData), workerStartupTimeout);
|
|
2542
|
+
}
|
|
2377
2543
|
try {
|
|
2378
2544
|
const resultValue = await result;
|
|
2379
2545
|
await closeWritable();
|
|
@@ -2486,28 +2652,68 @@
|
|
|
2486
2652
|
} else {
|
|
2487
2653
|
worker = new Worker(webWorkerURI, webWorkerOptions);
|
|
2488
2654
|
}
|
|
2489
|
-
worker.addEventListener(MESSAGE_EVENT_TYPE, event =>
|
|
2655
|
+
worker.addEventListener(MESSAGE_EVENT_TYPE, event => {
|
|
2656
|
+
workerData.workerAlive = true;
|
|
2657
|
+
clearStartupTimeout(workerData);
|
|
2658
|
+
onMessage(event, workerData);
|
|
2659
|
+
});
|
|
2490
2660
|
worker.addEventListener(ERROR_EVENT_TYPE, event => onWorkerError(event, workerData));
|
|
2491
2661
|
worker.addEventListener(MESSAGE_ERROR_EVENT_TYPE, event => onWorkerError(event, workerData));
|
|
2492
2662
|
return worker;
|
|
2493
2663
|
}
|
|
2494
2664
|
|
|
2665
|
+
function onStartupTimeout(workerData) {
|
|
2666
|
+
workerData.startupTimeout = null;
|
|
2667
|
+
if (workerData.workerAlive) {
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
const { rejectResult, writer } = workerData;
|
|
2671
|
+
terminateWorker$1(workerData);
|
|
2672
|
+
workerData.worker = null;
|
|
2673
|
+
if (rejectResult) {
|
|
2674
|
+
const error = new Error(ERR_WORKER_STARTUP_TIMEOUT);
|
|
2675
|
+
error.workerStartupFailed = true;
|
|
2676
|
+
rejectResult(error);
|
|
2677
|
+
if (writer) {
|
|
2678
|
+
writer.releaseLock();
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
function clearStartupTimeout(workerData) {
|
|
2684
|
+
const { startupTimeout } = workerData;
|
|
2685
|
+
if (startupTimeout) {
|
|
2686
|
+
clearTimeout(startupTimeout);
|
|
2687
|
+
workerData.startupTimeout = null;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2495
2691
|
function onWorkerError(event, workerData) {
|
|
2496
2692
|
if (event.preventDefault) {
|
|
2497
2693
|
event.preventDefault();
|
|
2498
2694
|
}
|
|
2499
|
-
|
|
2695
|
+
clearStartupTimeout(workerData);
|
|
2696
|
+
const { workerAlive, rejectResult, writer, onTaskFinished } = workerData;
|
|
2500
2697
|
terminateWorker$1(workerData);
|
|
2698
|
+
if (!workerAlive) {
|
|
2699
|
+
workerData.worker = null;
|
|
2700
|
+
}
|
|
2501
2701
|
if (rejectResult) {
|
|
2502
|
-
|
|
2702
|
+
let error = event.error || new Error(event.message || ERROR_EVENT_TYPE);
|
|
2703
|
+
if (!workerAlive) {
|
|
2704
|
+
error = Object.assign(new Error(error.message || ERROR_EVENT_TYPE), { workerStartupFailed: true });
|
|
2705
|
+
}
|
|
2706
|
+
rejectResult(error);
|
|
2503
2707
|
if (writer) {
|
|
2504
2708
|
writer.releaseLock();
|
|
2505
2709
|
}
|
|
2506
|
-
|
|
2710
|
+
if (workerAlive) {
|
|
2711
|
+
onTaskFinished();
|
|
2712
|
+
}
|
|
2507
2713
|
}
|
|
2508
2714
|
}
|
|
2509
2715
|
|
|
2510
|
-
function sendMessage(message, { worker, writer, transferStreams }) {
|
|
2716
|
+
function sendMessage(message, { worker, writer, transferStreams, workerAlive }) {
|
|
2511
2717
|
try {
|
|
2512
2718
|
const { value, readable, writable } = message;
|
|
2513
2719
|
const transferables = [];
|
|
@@ -2515,7 +2721,7 @@
|
|
|
2515
2721
|
message.value = toExactUint8Array(value);
|
|
2516
2722
|
transferables.push(message.value.buffer);
|
|
2517
2723
|
}
|
|
2518
|
-
if (transferStreams && transferStreamsSupported) {
|
|
2724
|
+
if (transferStreams && transferStreamsSupported && workerAlive) {
|
|
2519
2725
|
if (readable) {
|
|
2520
2726
|
transferables.push(readable);
|
|
2521
2727
|
}
|
|
@@ -2634,11 +2840,18 @@
|
|
|
2634
2840
|
|
|
2635
2841
|
async function runWorker(stream, workerOptions) {
|
|
2636
2842
|
const { options, config } = workerOptions;
|
|
2637
|
-
const { transferStreams, useWebWorkers, useCompressionStream, compressed, signed, encrypted } = options;
|
|
2843
|
+
const { transferStreams, useWebWorkers, useCompressionStream, compressed, signed, encrypted, format, codecURI } = options;
|
|
2638
2844
|
const { workerURI, maxWorkers } = config;
|
|
2845
|
+
if (format) {
|
|
2846
|
+
if (codecURI) {
|
|
2847
|
+
options.codecURI = resolveCodecURI(codecURI, config.baseURI);
|
|
2848
|
+
}
|
|
2849
|
+
await ensureCodecStreams(format, options.codecURI);
|
|
2850
|
+
}
|
|
2639
2851
|
workerOptions.transferStreams = transferStreams || (transferStreams === UNDEFINED_VALUE && config.transferStreams);
|
|
2640
2852
|
const streamCopy = !compressed && !signed && !encrypted;
|
|
2641
|
-
|
|
2853
|
+
const workerSupported = format === UNDEFINED_VALUE || Boolean(options.codecURI);
|
|
2854
|
+
workerOptions.useWebWorkers = !streamCopy && workerSupported && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
2642
2855
|
workerOptions.workerURI = workerOptions.useWebWorkers && workerURI ? workerURI : UNDEFINED_VALUE;
|
|
2643
2856
|
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
2644
2857
|
return (await getWorker()).run();
|
|
@@ -2678,6 +2891,14 @@
|
|
|
2678
2891
|
}
|
|
2679
2892
|
}
|
|
2680
2893
|
|
|
2894
|
+
function resolveCodecURI(codecURI, baseURI) {
|
|
2895
|
+
try {
|
|
2896
|
+
return new URL(codecURI, baseURI).toString();
|
|
2897
|
+
} catch {
|
|
2898
|
+
return codecURI;
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2681
2902
|
function armStarvationTimeout() {
|
|
2682
2903
|
if (!starvationTimeout && pendingRequests.length && Number.isFinite(starvationDelay) && starvationDelay >= 0) {
|
|
2683
2904
|
starvationTimeout = setTimeout(onWorkerStarvation, starvationDelay);
|
|
@@ -2738,6 +2959,7 @@
|
|
|
2738
2959
|
clearTerminateTimeout(workerData);
|
|
2739
2960
|
return workerData.terminate();
|
|
2740
2961
|
}));
|
|
2962
|
+
resetWebWorkerSupport();
|
|
2741
2963
|
}
|
|
2742
2964
|
|
|
2743
2965
|
/*
|
|
@@ -3961,6 +4183,7 @@
|
|
|
3961
4183
|
const OPTION_PREVENT_CLOSE = "preventClose";
|
|
3962
4184
|
const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
|
|
3963
4185
|
const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
|
|
4186
|
+
const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
|
|
3964
4187
|
const OPTION_KEEP_ORDER = "keepOrder";
|
|
3965
4188
|
const OPTION_LEVEL = "level";
|
|
3966
4189
|
const OPTION_BUFFERED_WRITE = "bufferedWrite";
|
|
@@ -4020,6 +4243,7 @@
|
|
|
4020
4243
|
const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
4021
4244
|
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
4022
4245
|
const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
|
|
4246
|
+
const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
|
|
4023
4247
|
const CHARSET_UTF8 = "utf-8";
|
|
4024
4248
|
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
|
|
4025
4249
|
const CHARSET_CP437 = "cp437";
|
|
@@ -4097,6 +4321,7 @@
|
|
|
4097
4321
|
let prependedDataLength = 0;
|
|
4098
4322
|
let startOffset;
|
|
4099
4323
|
let zip64EndOfDirectory;
|
|
4324
|
+
let zip64EndOfDirectoryVersion2;
|
|
4100
4325
|
const requiresZip64 = directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS;
|
|
4101
4326
|
if (directoryDataOffset != MAX_32_BITS && diskNumber != MAX_16_BITS) {
|
|
4102
4327
|
directoryDataOffset += getDiskOffset$1(reader, diskNumber);
|
|
@@ -4126,6 +4351,7 @@
|
|
|
4126
4351
|
throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
|
|
4127
4352
|
}
|
|
4128
4353
|
zip64EndOfDirectory = true;
|
|
4354
|
+
zip64EndOfDirectoryVersion2 = getBigUint64(endOfDirectoryView, 4) > ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12;
|
|
4129
4355
|
if (lastDiskNumber == MAX_16_BITS) {
|
|
4130
4356
|
lastDiskNumber = getUint32(endOfDirectoryView, 16);
|
|
4131
4357
|
} else if (checkAmbiguity && lastDiskNumber != getUint32(endOfDirectoryView, 16)) {
|
|
@@ -4205,6 +4431,9 @@
|
|
|
4205
4431
|
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
4206
4432
|
const fileEntry = new ZipEntry(reader, config, zipReader.options);
|
|
4207
4433
|
if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
4434
|
+
if (indexFile == 0 && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
|
|
4435
|
+
throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
|
|
4436
|
+
}
|
|
4208
4437
|
throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);
|
|
4209
4438
|
}
|
|
4210
4439
|
readCommonHeader(fileEntry, directoryView, offset + 6);
|
|
@@ -4432,7 +4661,8 @@
|
|
|
4432
4661
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4433
4662
|
}
|
|
4434
4663
|
}
|
|
4435
|
-
|
|
4664
|
+
const registeredCodec = passThrough ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
4665
|
+
if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64 && !registeredCodec) && !passThrough) {
|
|
4436
4666
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
4437
4667
|
}
|
|
4438
4668
|
if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
@@ -4471,7 +4701,10 @@
|
|
|
4471
4701
|
fileEntry.zipCrypto = zipCrypto;
|
|
4472
4702
|
}
|
|
4473
4703
|
if (encrypted) {
|
|
4474
|
-
if (
|
|
4704
|
+
if ((localDirectory.rawBitFlag & BITFLAG_STRONG_ENCRYPTION) == BITFLAG_STRONG_ENCRYPTION) {
|
|
4705
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4706
|
+
}
|
|
4707
|
+
if (!zipCrypto && (extraFieldAES.strength < 1 || extraFieldAES.strength > 3)) {
|
|
4475
4708
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
4476
4709
|
} else if (!password && !rawPassword) {
|
|
4477
4710
|
throw new Error(ERR_ENCRYPTED);
|
|
@@ -4510,6 +4743,8 @@
|
|
|
4510
4743
|
useCompressionStream,
|
|
4511
4744
|
transferStreams: getOptionValue$1(zipEntry, options, OPTION_TRANSFER_STREAMS),
|
|
4512
4745
|
deflate64,
|
|
4746
|
+
format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
|
|
4747
|
+
codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
|
|
4513
4748
|
checkPasswordOnly
|
|
4514
4749
|
},
|
|
4515
4750
|
config,
|
|
@@ -4562,6 +4797,16 @@
|
|
|
4562
4797
|
}
|
|
4563
4798
|
}
|
|
4564
4799
|
|
|
4800
|
+
function detectEncryptedCentralDirectory(directoryView) {
|
|
4801
|
+
const maxOffset = Math.min(directoryView.byteLength, 1024) - 3;
|
|
4802
|
+
for (let offset = 0; offset < maxOffset; offset++) {
|
|
4803
|
+
if (getUint32(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
|
|
4804
|
+
return true;
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
4807
|
+
return false;
|
|
4808
|
+
}
|
|
4809
|
+
|
|
4565
4810
|
function readCommonHeader(directory, dataView, offset) {
|
|
4566
4811
|
const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
|
|
4567
4812
|
const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
|
|
@@ -5076,6 +5321,7 @@
|
|
|
5076
5321
|
ERR_BAD_FORMAT: ERR_BAD_FORMAT,
|
|
5077
5322
|
ERR_CENTRAL_DIRECTORY_NOT_FOUND: ERR_CENTRAL_DIRECTORY_NOT_FOUND,
|
|
5078
5323
|
ERR_ENCRYPTED: ERR_ENCRYPTED,
|
|
5324
|
+
ERR_ENCRYPTED_CENTRAL_DIRECTORY: ERR_ENCRYPTED_CENTRAL_DIRECTORY,
|
|
5079
5325
|
ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
|
|
5080
5326
|
ERR_EOCDR_NOT_FOUND: ERR_EOCDR_NOT_FOUND,
|
|
5081
5327
|
ERR_EXTRAFIELD_ZIP64_NOT_FOUND: ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
|
|
@@ -5127,6 +5373,7 @@
|
|
|
5127
5373
|
const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
|
|
5128
5374
|
const ERR_INVALID_VERSION = "Version exceeds 65535";
|
|
5129
5375
|
const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
|
|
5376
|
+
const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
|
|
5130
5377
|
const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
|
|
5131
5378
|
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
5132
5379
|
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
@@ -5487,7 +5734,11 @@
|
|
|
5487
5734
|
if (versionMadeBy > MAX_16_BITS) {
|
|
5488
5735
|
throw new Error(ERR_INVALID_VERSION);
|
|
5489
5736
|
}
|
|
5490
|
-
let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES
|
|
5737
|
+
let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES);
|
|
5738
|
+
const externalFileAttributesProvided = externalFileAttributes !== UNDEFINED_VALUE;
|
|
5739
|
+
if (!externalFileAttributesProvided) {
|
|
5740
|
+
externalFileAttributes = 0;
|
|
5741
|
+
}
|
|
5491
5742
|
if (!options[PROPERTY_NAME_DIRECTORY] && name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
5492
5743
|
options[PROPERTY_NAME_DIRECTORY] = true;
|
|
5493
5744
|
}
|
|
@@ -5496,13 +5747,13 @@
|
|
|
5496
5747
|
if (!name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
5497
5748
|
name += DIRECTORY_SIGNATURE;
|
|
5498
5749
|
}
|
|
5499
|
-
if (
|
|
5750
|
+
if (!externalFileAttributesProvided) {
|
|
5500
5751
|
externalFileAttributes = FILE_ATTR_MSDOS_DIR_MASK;
|
|
5501
5752
|
if (!msDosCompatible) {
|
|
5502
5753
|
externalFileAttributes |= (FILE_ATTR_UNIX_TYPE_DIR | FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_DEFAULT_MASK) << 16;
|
|
5503
5754
|
}
|
|
5504
5755
|
}
|
|
5505
|
-
} else if (!msDosCompatible &&
|
|
5756
|
+
} else if (!msDosCompatible && !externalFileAttributesProvided) {
|
|
5506
5757
|
if (executable) {
|
|
5507
5758
|
externalFileAttributes = (FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_DEFAULT_MASK) << 16;
|
|
5508
5759
|
} else {
|
|
@@ -5511,6 +5762,7 @@
|
|
|
5511
5762
|
}
|
|
5512
5763
|
let unixExternalUpper;
|
|
5513
5764
|
if (!msDosCompatible) {
|
|
5765
|
+
const unixModeProvided = unixMode !== UNDEFINED_VALUE || Boolean(setuid || setgid || sticky);
|
|
5514
5766
|
unixExternalUpper = (externalFileAttributes >> 16) & MAX_16_BITS;
|
|
5515
5767
|
unixMode = unixMode === UNDEFINED_VALUE ? unixExternalUpper : (unixMode & MAX_16_BITS);
|
|
5516
5768
|
if (setuid) {
|
|
@@ -5528,10 +5780,12 @@
|
|
|
5528
5780
|
} else {
|
|
5529
5781
|
sticky = Boolean(unixMode & FILE_ATTR_UNIX_STICKY_MASK);
|
|
5530
5782
|
}
|
|
5531
|
-
if (
|
|
5532
|
-
|
|
5783
|
+
if (!externalFileAttributesProvided || unixModeProvided) {
|
|
5784
|
+
if (directory) {
|
|
5785
|
+
unixMode |= FILE_ATTR_UNIX_TYPE_DIR;
|
|
5786
|
+
}
|
|
5787
|
+
externalFileAttributes = ((unixMode & MAX_16_BITS) << 16) | (externalFileAttributes & MAX_16_BITS);
|
|
5533
5788
|
}
|
|
5534
|
-
externalFileAttributes = ((unixMode & MAX_16_BITS) << 16) | (externalFileAttributes & MAX_8_BITS);
|
|
5535
5789
|
}
|
|
5536
5790
|
({ msdosAttributesRaw, msdosAttributes } = normalizeMsdosAttributes(msdosAttributesRaw, msdosAttributes));
|
|
5537
5791
|
if (hasMsDosProvided) {
|
|
@@ -5591,6 +5845,7 @@
|
|
|
5591
5845
|
const encryptionStrength = getOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
5592
5846
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
5593
5847
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
5848
|
+
const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
|
|
5594
5849
|
const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
|
|
5595
5850
|
const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
|
|
5596
5851
|
const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
|
|
@@ -5600,11 +5855,20 @@
|
|
|
5600
5855
|
const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
|
|
5601
5856
|
const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
|
|
5602
5857
|
const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
|
|
5858
|
+
const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
5603
5859
|
if (!passThrough && compressionMethod !== UNDEFINED_VALUE &&
|
|
5604
|
-
compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE) {
|
|
5860
|
+
compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE && !registeredCodec) {
|
|
5605
5861
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
5606
5862
|
}
|
|
5607
5863
|
let level = getOptionValue(zipWriter, options, OPTION_LEVEL);
|
|
5864
|
+
if (zipWriter.options[OPTION_USDZ]) {
|
|
5865
|
+
if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
|
|
5866
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
|
|
5867
|
+
}
|
|
5868
|
+
if (level === UNDEFINED_VALUE && compressionMethod === UNDEFINED_VALUE) {
|
|
5869
|
+
level = 0;
|
|
5870
|
+
}
|
|
5871
|
+
}
|
|
5608
5872
|
let useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
|
|
5609
5873
|
let dataDescriptor = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR);
|
|
5610
5874
|
if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
|
|
@@ -5616,7 +5880,7 @@
|
|
|
5616
5880
|
if (level !== UNDEFINED_VALUE && level != 6) {
|
|
5617
5881
|
useCompressionStream = false;
|
|
5618
5882
|
}
|
|
5619
|
-
if (!useCompressionStream && (zipWriter.config.CompressionStream === UNDEFINED_VALUE && zipWriter.config.CompressionStreamZlib === UNDEFINED_VALUE)) {
|
|
5883
|
+
if (!useCompressionStream && !registeredCodec && (zipWriter.config.CompressionStream === UNDEFINED_VALUE && zipWriter.config.CompressionStreamZlib === UNDEFINED_VALUE)) {
|
|
5620
5884
|
level = 0;
|
|
5621
5885
|
}
|
|
5622
5886
|
const zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
@@ -5660,6 +5924,7 @@
|
|
|
5660
5924
|
encryptionStrength,
|
|
5661
5925
|
zipCrypto,
|
|
5662
5926
|
extendedTimestamp,
|
|
5927
|
+
ntfsTimestamp,
|
|
5663
5928
|
keepOrder,
|
|
5664
5929
|
useWebWorkers,
|
|
5665
5930
|
transferStreams,
|
|
@@ -5669,6 +5934,9 @@
|
|
|
5669
5934
|
signal,
|
|
5670
5935
|
useUnicodeFileNames,
|
|
5671
5936
|
compressionMethod,
|
|
5937
|
+
format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
|
|
5938
|
+
codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
|
|
5939
|
+
codecVersionNeeded: registeredCodec ? registeredCodec.versionNeeded : UNDEFINED_VALUE,
|
|
5672
5940
|
level,
|
|
5673
5941
|
useCompressionStream,
|
|
5674
5942
|
dataDescriptor,
|
|
@@ -5965,7 +6233,9 @@
|
|
|
5965
6233
|
msdosAttributesRaw,
|
|
5966
6234
|
msdosAttributes,
|
|
5967
6235
|
useCompressionStream,
|
|
5968
|
-
passThrough
|
|
6236
|
+
passThrough,
|
|
6237
|
+
format,
|
|
6238
|
+
codecURI
|
|
5969
6239
|
} = options;
|
|
5970
6240
|
const fileEntry = {
|
|
5971
6241
|
lock,
|
|
@@ -6025,7 +6295,9 @@
|
|
|
6025
6295
|
encrypted: encrypted && !passThrough,
|
|
6026
6296
|
useWebWorkers,
|
|
6027
6297
|
useCompressionStream,
|
|
6028
|
-
transferStreams
|
|
6298
|
+
transferStreams,
|
|
6299
|
+
format,
|
|
6300
|
+
codecURI
|
|
6029
6301
|
},
|
|
6030
6302
|
config,
|
|
6031
6303
|
streamOptions: { signal, size, onstart, onprogress, onend }
|
|
@@ -6097,6 +6369,7 @@
|
|
|
6097
6369
|
rawExtraField,
|
|
6098
6370
|
encryptionStrength,
|
|
6099
6371
|
extendedTimestamp,
|
|
6372
|
+
ntfsTimestamp,
|
|
6100
6373
|
passThrough,
|
|
6101
6374
|
encrypted,
|
|
6102
6375
|
zip64UncompressedSize,
|
|
@@ -6142,7 +6415,8 @@
|
|
|
6142
6415
|
let extraFieldExtendedTimestampFlag;
|
|
6143
6416
|
if (extendedTimestamp) {
|
|
6144
6417
|
const lastModTimeUnix = getTimeUnix(lastModDate);
|
|
6145
|
-
|
|
6418
|
+
const lastModTimeUnixInRange = inUnixTimeRange(lastModTimeUnix);
|
|
6419
|
+
if (lastModTimeUnixInRange) {
|
|
6146
6420
|
const extraFieldTimestampLength = 9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0);
|
|
6147
6421
|
const extraFieldTimestamp = createRecordWriter(extraFieldTimestampLength);
|
|
6148
6422
|
extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
|
|
@@ -6160,19 +6434,26 @@
|
|
|
6160
6434
|
} else {
|
|
6161
6435
|
rawExtraFieldExtendedTimestamp = EMPTY_UINT8_ARRAY;
|
|
6162
6436
|
}
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6437
|
+
const writeExtraFieldNTFS = ntfsTimestamp === UNDEFINED_VALUE ?
|
|
6438
|
+
!lastModTimeUnixInRange || Boolean(lastAccessDate || creationDate) :
|
|
6439
|
+
ntfsTimestamp;
|
|
6440
|
+
if (writeExtraFieldNTFS) {
|
|
6441
|
+
try {
|
|
6442
|
+
const lastModTimeNTFS = getTimeNTFS(lastModDate);
|
|
6443
|
+
const extraFieldNTFS = createRecordWriter(36);
|
|
6444
|
+
extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS);
|
|
6445
|
+
extraFieldNTFS.uint16(32);
|
|
6446
|
+
extraFieldNTFS.skip(4);
|
|
6447
|
+
extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
|
|
6448
|
+
extraFieldNTFS.uint16(24);
|
|
6449
|
+
extraFieldNTFS.uint64(lastModTimeNTFS);
|
|
6450
|
+
extraFieldNTFS.uint64(getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
|
|
6451
|
+
extraFieldNTFS.uint64(getTimeNTFS(creationDate) || lastModTimeNTFS);
|
|
6452
|
+
rawExtraFieldNTFS = extraFieldNTFS.array;
|
|
6453
|
+
} catch {
|
|
6454
|
+
rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
|
|
6455
|
+
}
|
|
6456
|
+
} else {
|
|
6176
6457
|
rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
|
|
6177
6458
|
}
|
|
6178
6459
|
} else {
|
|
@@ -6210,6 +6491,10 @@
|
|
|
6210
6491
|
if (compressionMethod === UNDEFINED_VALUE) {
|
|
6211
6492
|
compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
|
|
6212
6493
|
}
|
|
6494
|
+
const { codecVersionNeeded } = options;
|
|
6495
|
+
if (compressed && codecVersionNeeded !== UNDEFINED_VALUE) {
|
|
6496
|
+
version = version > codecVersionNeeded ? version : codecVersionNeeded;
|
|
6497
|
+
}
|
|
6213
6498
|
if (zip64) {
|
|
6214
6499
|
version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
|
|
6215
6500
|
}
|
|
@@ -6223,6 +6508,7 @@
|
|
|
6223
6508
|
if (extraFieldLength > MAX_16_BITS) {
|
|
6224
6509
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
6225
6510
|
}
|
|
6511
|
+
const dosLastModDate = new Date(Math.ceil(lastModDate.getTime() / 2000) * 2000);
|
|
6226
6512
|
const {
|
|
6227
6513
|
headerArray,
|
|
6228
6514
|
headerView,
|
|
@@ -6232,7 +6518,7 @@
|
|
|
6232
6518
|
bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
|
|
6233
6519
|
compressionMethod,
|
|
6234
6520
|
uncompressedSize,
|
|
6235
|
-
lastModDate:
|
|
6521
|
+
lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
|
|
6236
6522
|
rawFilename,
|
|
6237
6523
|
zip64CompressedSize,
|
|
6238
6524
|
zip64UncompressedSize,
|
|
@@ -7330,11 +7616,14 @@
|
|
|
7330
7616
|
exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
|
|
7331
7617
|
exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
|
|
7332
7618
|
exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
|
|
7619
|
+
exports.ERR_ENCRYPTED_CENTRAL_DIRECTORY = ERR_ENCRYPTED_CENTRAL_DIRECTORY;
|
|
7333
7620
|
exports.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND;
|
|
7334
7621
|
exports.ERR_EOCDR_NOT_FOUND = ERR_EOCDR_NOT_FOUND;
|
|
7335
7622
|
exports.ERR_EXTRAFIELD_ZIP64_NOT_FOUND = ERR_EXTRAFIELD_ZIP64_NOT_FOUND;
|
|
7336
7623
|
exports.ERR_HTTP_RANGE = ERR_HTTP_RANGE;
|
|
7337
7624
|
exports.ERR_HTTP_RESOURCE_CHANGED = ERR_HTTP_RESOURCE_CHANGED;
|
|
7625
|
+
exports.ERR_INVALID_CODEC_DEFINITION = ERR_INVALID_CODEC_DEFINITION;
|
|
7626
|
+
exports.ERR_INVALID_CODEC_MODULE = ERR_INVALID_CODEC_MODULE;
|
|
7338
7627
|
exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
|
|
7339
7628
|
exports.ERR_INVALID_COMPRESSED_DATA = ERR_INVALID_COMPRESSED_DATA;
|
|
7340
7629
|
exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
|
|
@@ -7349,11 +7638,13 @@
|
|
|
7349
7638
|
exports.ERR_ITERATOR_COMPLETED_TOO_SOON = ERR_ITERATOR_COMPLETED_TOO_SOON;
|
|
7350
7639
|
exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
|
|
7351
7640
|
exports.ERR_OVERLAPPING_ENTRY = ERR_OVERLAPPING_ENTRY;
|
|
7641
|
+
exports.ERR_RESERVED_COMPRESSION_METHOD = ERR_RESERVED_COMPRESSION_METHOD;
|
|
7352
7642
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
7353
7643
|
exports.ERR_UNDEFINED_READER = ERR_UNDEFINED_READER;
|
|
7354
7644
|
exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
|
|
7355
7645
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION$1;
|
|
7356
7646
|
exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
|
|
7647
|
+
exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
|
|
7357
7648
|
exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
|
|
7358
7649
|
exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;
|
|
7359
7650
|
exports.ERR_ZIP_NOT_EMPTY = ERR_ZIP_NOT_EMPTY;
|
|
@@ -7376,7 +7667,9 @@
|
|
|
7376
7667
|
exports.createOPFSTempStream = createOPFSTempStream;
|
|
7377
7668
|
exports.createSyncAccessHandleTempStream = createSyncAccessHandleTempStream;
|
|
7378
7669
|
exports.getMimeType = getMimeType;
|
|
7670
|
+
exports.registerCodec = registerCodec;
|
|
7379
7671
|
exports.resetConfiguration = resetConfiguration;
|
|
7380
7672
|
exports.terminateWorkers = terminateWorkers;
|
|
7673
|
+
exports.unregisterCodec = unregisterCodec;
|
|
7381
7674
|
|
|
7382
7675
|
}));
|