@zip.js/zip.js 2.16.0 → 2.17.0
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 +429 -274
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +230 -151
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +580 -283
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +383 -160
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +580 -283
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +386 -163
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +583 -283
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +232 -153
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +233 -154
- 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 +430 -274
- package/dist/zip.min.js +1 -1
- package/eslint.config.mjs +1 -1
- package/index-native.cjs +386 -163
- package/index-native.min.js +1 -1
- package/index.cjs +583 -283
- package/index.d.cts +168 -29
- package/index.d.ts +168 -29
- package/index.min.js +1 -1
- package/lib/core/codec-pool.js +2 -0
- package/lib/core/codec-worker-web.js +11 -3
- package/lib/core/codec-worker.js +2 -1
- package/lib/core/streams/aes-crypto-stream.js +60 -17
- package/lib/core/streams/codec-stream.js +2 -0
- package/lib/core/streams/zip-crypto-stream.js +7 -7
- package/lib/core/streams/zip-entry-stream.js +130 -113
- package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
- package/lib/core/streams/zlib-wasm/zlib-streams.js +199 -122
- package/lib/core/util/compatible-streams.js +10 -5
- package/lib/core/version.js +1 -1
- package/lib/core/web-worker-base.js +1 -1
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-fs.js +157 -10
- package/lib/core/zip-reader.js +8 -5
- package/lib/core/zip-writer.js +5 -2
- package/lib/zip-core-reader.js +1 -0
- package/package.json +3 -2
package/dist/zip-fs-external.js
CHANGED
|
@@ -214,7 +214,7 @@ const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
|
|
|
214
214
|
const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
|
|
215
215
|
const ERR_INVALID_PASS_THROUGH_VALUE = "Invalid passThrough option (must be a boolean or 'compressed')";
|
|
216
216
|
const ERR_ABORTED = "The operation was aborted";
|
|
217
|
-
const ABORT_ERROR_NAME = "AbortError";
|
|
217
|
+
const ABORT_ERROR_NAME$1 = "AbortError";
|
|
218
218
|
|
|
219
219
|
function checkFunctionOption(value) {
|
|
220
220
|
if (value && typeof value != FUNCTION_TYPE) {
|
|
@@ -232,7 +232,7 @@ function checkSignalOption(signal) {
|
|
|
232
232
|
|
|
233
233
|
function throwIfAborted(signal) {
|
|
234
234
|
if (signal && signal.aborted) {
|
|
235
|
-
throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
|
|
235
|
+
throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME$1) : signal.reason;
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
|
|
@@ -1310,12 +1310,12 @@ let createEngine$1 = createEngine$2;
|
|
|
1310
1310
|
class AESDecryptionStream extends TransformStream {
|
|
1311
1311
|
|
|
1312
1312
|
constructor({ password, rawPassword, encryptionStrength, checkPasswordOnly, checkAuthenticationCode = true }) {
|
|
1313
|
+
const aesCrypto = {};
|
|
1313
1314
|
super({
|
|
1314
1315
|
start() {
|
|
1315
|
-
initAesCrypto(
|
|
1316
|
+
initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength);
|
|
1316
1317
|
},
|
|
1317
1318
|
async transform(chunk, controller) {
|
|
1318
|
-
const aesCrypto = this;
|
|
1319
1319
|
const {
|
|
1320
1320
|
password,
|
|
1321
1321
|
strength,
|
|
@@ -1334,6 +1334,9 @@ class AESDecryptionStream extends TransformStream {
|
|
|
1334
1334
|
} else {
|
|
1335
1335
|
await ready;
|
|
1336
1336
|
}
|
|
1337
|
+
if (aesCrypto.discarded) {
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1337
1340
|
const output = new Uint8Array(chunk.length - AUTHENTICATION_CODE_LENGTH - ((chunk.length - AUTHENTICATION_CODE_LENGTH) % BLOCK_LENGTH));
|
|
1338
1341
|
controller.enqueue(append(aesCrypto, chunk, output, 0, AUTHENTICATION_CODE_LENGTH, true));
|
|
1339
1342
|
},
|
|
@@ -1342,9 +1345,12 @@ class AESDecryptionStream extends TransformStream {
|
|
|
1342
1345
|
engine,
|
|
1343
1346
|
pendingInput,
|
|
1344
1347
|
ready
|
|
1345
|
-
} =
|
|
1348
|
+
} = aesCrypto;
|
|
1346
1349
|
if (engine) {
|
|
1347
1350
|
await ready;
|
|
1351
|
+
if (aesCrypto.discarded) {
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1348
1354
|
const originalAuthenticationCode = subarray(pendingInput, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
|
|
1349
1355
|
const decryptedChunkArray = new Uint8Array(subarray(pendingInput, 0, pendingInput.length - AUTHENTICATION_CODE_LENGTH));
|
|
1350
1356
|
engine.process(decryptedChunkArray, true);
|
|
@@ -1354,27 +1360,26 @@ class AESDecryptionStream extends TransformStream {
|
|
|
1354
1360
|
invalidAuthenticationCode |= authenticationCode[indexByte] ^ originalAuthenticationCode[indexByte];
|
|
1355
1361
|
}
|
|
1356
1362
|
if (invalidAuthenticationCode && checkAuthenticationCode) {
|
|
1357
|
-
|
|
1363
|
+
controller.error(new Error(ERR_INVALID_AUTHENTICATION_CODE));
|
|
1364
|
+
return;
|
|
1358
1365
|
}
|
|
1359
1366
|
controller.enqueue(decryptedChunkArray);
|
|
1360
1367
|
}
|
|
1361
|
-
},
|
|
1362
|
-
cancel() {
|
|
1363
|
-
disposeEngine(this);
|
|
1364
1368
|
}
|
|
1365
1369
|
});
|
|
1370
|
+
setDisposingReadable(this, aesCrypto);
|
|
1366
1371
|
}
|
|
1367
1372
|
}
|
|
1368
1373
|
|
|
1369
1374
|
class AESEncryptionStream extends TransformStream {
|
|
1370
1375
|
|
|
1371
1376
|
constructor({ password, rawPassword, encryptionStrength }) {
|
|
1377
|
+
const aesCrypto = {};
|
|
1372
1378
|
super({
|
|
1373
1379
|
start() {
|
|
1374
|
-
initAesCrypto(
|
|
1380
|
+
initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength);
|
|
1375
1381
|
},
|
|
1376
1382
|
async transform(chunk, controller) {
|
|
1377
|
-
const aesCrypto = this;
|
|
1378
1383
|
const {
|
|
1379
1384
|
password,
|
|
1380
1385
|
strength,
|
|
@@ -1388,6 +1393,9 @@ class AESEncryptionStream extends TransformStream {
|
|
|
1388
1393
|
} else {
|
|
1389
1394
|
await ready;
|
|
1390
1395
|
}
|
|
1396
|
+
if (aesCrypto.discarded) {
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1391
1399
|
const output = new Uint8Array(preamble.length + chunk.length - (chunk.length % BLOCK_LENGTH));
|
|
1392
1400
|
output.set(preamble, 0);
|
|
1393
1401
|
controller.enqueue(append(aesCrypto, chunk, output, preamble.length, 0, false));
|
|
@@ -1397,19 +1405,20 @@ class AESEncryptionStream extends TransformStream {
|
|
|
1397
1405
|
engine,
|
|
1398
1406
|
pendingInput,
|
|
1399
1407
|
ready
|
|
1400
|
-
} =
|
|
1408
|
+
} = aesCrypto;
|
|
1401
1409
|
if (engine) {
|
|
1402
1410
|
await ready;
|
|
1411
|
+
if (aesCrypto.discarded) {
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1403
1414
|
const encryptedChunkArray = new Uint8Array(pendingInput);
|
|
1404
1415
|
engine.process(encryptedChunkArray, false);
|
|
1405
1416
|
const authenticationCode = subarray(engine.digest(), 0, AUTHENTICATION_CODE_LENGTH);
|
|
1406
1417
|
controller.enqueue(concat(encryptedChunkArray, authenticationCode));
|
|
1407
1418
|
}
|
|
1408
|
-
},
|
|
1409
|
-
cancel() {
|
|
1410
|
-
disposeEngine(this);
|
|
1411
1419
|
}
|
|
1412
1420
|
});
|
|
1421
|
+
setDisposingReadable(this, aesCrypto);
|
|
1413
1422
|
}
|
|
1414
1423
|
}
|
|
1415
1424
|
|
|
@@ -1422,7 +1431,37 @@ function initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength) {
|
|
|
1422
1431
|
ready: new Promise(resolve => aesCrypto.resolveReady = resolve),
|
|
1423
1432
|
password: encodePassword(password, rawPassword),
|
|
1424
1433
|
strength: encryptionStrength - 1,
|
|
1425
|
-
pendingInput: EMPTY_UINT8_ARRAY
|
|
1434
|
+
pendingInput: EMPTY_UINT8_ARRAY,
|
|
1435
|
+
discarded: false
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
function setDisposingReadable(stream, aesCrypto) {
|
|
1440
|
+
const reader = stream.readable.getReader();
|
|
1441
|
+
const readable = new ReadableStream({
|
|
1442
|
+
async pull(controller) {
|
|
1443
|
+
try {
|
|
1444
|
+
const { value, done } = await reader.read();
|
|
1445
|
+
if (done) {
|
|
1446
|
+
controller.close();
|
|
1447
|
+
} else {
|
|
1448
|
+
controller.enqueue(value);
|
|
1449
|
+
}
|
|
1450
|
+
} catch (error) {
|
|
1451
|
+
disposeEngine(aesCrypto);
|
|
1452
|
+
reader.cancel(error).catch(() => { });
|
|
1453
|
+
throw error;
|
|
1454
|
+
}
|
|
1455
|
+
},
|
|
1456
|
+
cancel(reason) {
|
|
1457
|
+
disposeEngine(aesCrypto);
|
|
1458
|
+
return reader.cancel(reason);
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
Object.defineProperty(stream, "readable", {
|
|
1462
|
+
get() {
|
|
1463
|
+
return readable;
|
|
1464
|
+
}
|
|
1426
1465
|
});
|
|
1427
1466
|
}
|
|
1428
1467
|
|
|
@@ -1455,7 +1494,9 @@ async function createDecryptionKeys(decrypt, strength, password, preamble) {
|
|
|
1455
1494
|
}
|
|
1456
1495
|
}
|
|
1457
1496
|
|
|
1458
|
-
function disposeEngine(
|
|
1497
|
+
function disposeEngine(aesCrypto) {
|
|
1498
|
+
const { engine } = aesCrypto;
|
|
1499
|
+
aesCrypto.discarded = true;
|
|
1459
1500
|
if (engine && engine.dispose) {
|
|
1460
1501
|
engine.dispose();
|
|
1461
1502
|
}
|
|
@@ -1472,6 +1513,9 @@ async function createKeys$1(aesCrypto, strength, password, salt) {
|
|
|
1472
1513
|
const keyLength = KEY_LENGTH[strength];
|
|
1473
1514
|
const compositeKey = await deriveKey(password, salt, keyLength * 2 + PASSWORD_VERIFICATION_LENGTH);
|
|
1474
1515
|
aesCrypto.engine = createEngine$1(subarray(compositeKey, 0, keyLength), subarray(compositeKey, keyLength, keyLength * 2));
|
|
1516
|
+
if (aesCrypto.discarded) {
|
|
1517
|
+
disposeEngine(aesCrypto);
|
|
1518
|
+
}
|
|
1475
1519
|
return subarray(compositeKey, keyLength * 2);
|
|
1476
1520
|
}
|
|
1477
1521
|
|
|
@@ -1623,11 +1667,11 @@ function encrypt(target, input) {
|
|
|
1623
1667
|
}
|
|
1624
1668
|
|
|
1625
1669
|
function createKeys(target, password, rawPassword) {
|
|
1626
|
-
const
|
|
1670
|
+
const cryptoKeys = [0x12345678, 0x23456789, 0x34567890];
|
|
1627
1671
|
Object.assign(target, {
|
|
1628
|
-
|
|
1629
|
-
crcKey0: new Crc32(
|
|
1630
|
-
crcKey2: new Crc32(
|
|
1672
|
+
cryptoKeys,
|
|
1673
|
+
crcKey0: new Crc32(cryptoKeys[0]),
|
|
1674
|
+
crcKey2: new Crc32(cryptoKeys[2])
|
|
1631
1675
|
});
|
|
1632
1676
|
if (rawPassword) {
|
|
1633
1677
|
for (let index = 0; index < rawPassword.length; index++) {
|
|
@@ -1641,17 +1685,17 @@ function createKeys(target, password, rawPassword) {
|
|
|
1641
1685
|
}
|
|
1642
1686
|
|
|
1643
1687
|
function updateKeys(target, byte) {
|
|
1644
|
-
let [, key1] = target.
|
|
1688
|
+
let [, key1] = target.cryptoKeys;
|
|
1645
1689
|
target.crcKey0.append([byte]);
|
|
1646
1690
|
const key0 = ~target.crcKey0.get();
|
|
1647
1691
|
key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
|
|
1648
1692
|
target.crcKey2.append([key1 >>> 24]);
|
|
1649
1693
|
const key2 = ~target.crcKey2.get();
|
|
1650
|
-
target.
|
|
1694
|
+
target.cryptoKeys = [key0, key1, key2];
|
|
1651
1695
|
}
|
|
1652
1696
|
|
|
1653
1697
|
function getByte(target) {
|
|
1654
|
-
const temp = target.
|
|
1698
|
+
const temp = target.cryptoKeys[2] | 2;
|
|
1655
1699
|
return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
|
|
1656
1700
|
}
|
|
1657
1701
|
|
|
@@ -1699,11 +1743,16 @@ function toCompatibleReadable(readable) {
|
|
|
1699
1743
|
const reader = readable.getReader();
|
|
1700
1744
|
return new ReadableStream({
|
|
1701
1745
|
async pull(controller) {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1746
|
+
try {
|
|
1747
|
+
const { value, done } = await reader.read();
|
|
1748
|
+
if (done) {
|
|
1749
|
+
controller.close();
|
|
1750
|
+
} else {
|
|
1751
|
+
controller.enqueue(value);
|
|
1752
|
+
}
|
|
1753
|
+
} catch (error) {
|
|
1754
|
+
reader.cancel(error).catch(() => { });
|
|
1755
|
+
throw error;
|
|
1707
1756
|
}
|
|
1708
1757
|
},
|
|
1709
1758
|
cancel(reason) {
|
|
@@ -1882,7 +1931,9 @@ async function ensureCodecStreams(format, codecURI) {
|
|
|
1882
1931
|
|
|
1883
1932
|
const ERR_INVALID_UNCOMPRESSED_SIZE = "Invalid uncompressed size";
|
|
1884
1933
|
const ERR_INVALID_COMPRESSED_DATA = "Invalid compressed data";
|
|
1934
|
+
const ERR_CODEC_OUT_OF_MEMORY = "Codec out of memory";
|
|
1885
1935
|
const ERR_INVALID_CRC32 = "Invalid CRC32";
|
|
1936
|
+
const Z_MEM_ERROR_CODE$1 = "Z_MEM_ERROR";
|
|
1886
1937
|
const FORMAT_DEFLATE_RAW$1 = "deflate-raw";
|
|
1887
1938
|
const FORMAT_DEFLATE64_RAW$1 = "deflate64-raw";
|
|
1888
1939
|
const FORMAT_GZIP$1 = "gzip";
|
|
@@ -1917,13 +1968,13 @@ class DeflateStream extends TransformStream {
|
|
|
1917
1968
|
readable = pipeThroughCompressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStream, CompressionStreamFallback);
|
|
1918
1969
|
} catch (error) {
|
|
1919
1970
|
if (!useCompressionStream && CompressionStreamFallback) {
|
|
1920
|
-
throw error;
|
|
1971
|
+
throw mapMemoryError(error);
|
|
1921
1972
|
}
|
|
1922
1973
|
let gzipStream;
|
|
1923
1974
|
try {
|
|
1924
1975
|
gzipStream = new CompressionStream(FORMAT_GZIP$1);
|
|
1925
1976
|
} catch {
|
|
1926
|
-
throw error;
|
|
1977
|
+
throw mapMemoryError(error);
|
|
1927
1978
|
}
|
|
1928
1979
|
readable = pipeThroughBackpressured(readable, gzipStream);
|
|
1929
1980
|
readable = pipeThrough(readable, new GzipToRawDeflateStream());
|
|
@@ -1987,53 +2038,30 @@ class GzipToRawDeflateStream extends TransformStream {
|
|
|
1987
2038
|
}
|
|
1988
2039
|
}
|
|
1989
2040
|
|
|
1990
|
-
function pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, crc32) {
|
|
2041
|
+
function pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, crc32, sourceErrors) {
|
|
1991
2042
|
const writer = gzipStream.writable.getWriter();
|
|
1992
2043
|
const reader = gzipStream.readable.getReader();
|
|
1993
2044
|
const outputCrc32 = crc32 === UNDEFINED_VALUE ? new Crc32() : UNDEFINED_VALUE;
|
|
1994
2045
|
let outputLength = 0;
|
|
1995
|
-
let inputDone = false;
|
|
1996
2046
|
let trailerWritten = false;
|
|
1997
|
-
let
|
|
1998
|
-
let
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
trailerReady.catch(() => { });
|
|
2006
|
-
pump();
|
|
2007
|
-
return new ReadableStream({
|
|
2008
|
-
async pull(controller) {
|
|
2009
|
-
let result;
|
|
2010
|
-
try {
|
|
2011
|
-
result = await read();
|
|
2012
|
-
} catch (error) {
|
|
2013
|
-
throw trailerWritten ? getTrailerError(error) : error;
|
|
2014
|
-
}
|
|
2015
|
-
const { value, done } = result;
|
|
2016
|
-
if (done) {
|
|
2017
|
-
controller.close();
|
|
2018
|
-
} else {
|
|
2019
|
-
outputLength += value.length;
|
|
2020
|
-
if (outputLength > outputSize) {
|
|
2021
|
-
const error = new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
|
|
2022
|
-
rejectTrailerReady(error);
|
|
2023
|
-
await cancel(reader, error);
|
|
2024
|
-
throw error;
|
|
2025
|
-
}
|
|
2026
|
-
if (outputCrc32) {
|
|
2027
|
-
outputCrc32.append(value);
|
|
2028
|
-
}
|
|
2029
|
-
controller.enqueue(value);
|
|
2030
|
-
}
|
|
2047
|
+
let settled = false;
|
|
2048
|
+
let resolvePull, controller;
|
|
2049
|
+
const output = new ReadableStream({
|
|
2050
|
+
start(streamController) {
|
|
2051
|
+
controller = streamController;
|
|
2052
|
+
},
|
|
2053
|
+
pull() {
|
|
2054
|
+
resumePump();
|
|
2031
2055
|
},
|
|
2032
2056
|
cancel(reason) {
|
|
2033
|
-
|
|
2057
|
+
settled = true;
|
|
2058
|
+
resumePump();
|
|
2034
2059
|
return reader.cancel(reason);
|
|
2035
2060
|
}
|
|
2036
2061
|
});
|
|
2062
|
+
pump();
|
|
2063
|
+
drain();
|
|
2064
|
+
return output;
|
|
2037
2065
|
|
|
2038
2066
|
async function pump() {
|
|
2039
2067
|
const inputReader = readable.getReader();
|
|
@@ -2042,19 +2070,16 @@ function pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, cr
|
|
|
2042
2070
|
header.set(GZIP_HEADER_BYTES);
|
|
2043
2071
|
await writer.write(header);
|
|
2044
2072
|
for (; ;) {
|
|
2073
|
+
await outputCapacity();
|
|
2045
2074
|
await writer.ready;
|
|
2046
|
-
const { value, done } = await inputReader
|
|
2075
|
+
const { value, done } = await readSource(inputReader, sourceErrors);
|
|
2047
2076
|
if (done) {
|
|
2048
2077
|
break;
|
|
2049
2078
|
}
|
|
2050
2079
|
await writer.write(value);
|
|
2051
2080
|
}
|
|
2052
|
-
inputDone = true;
|
|
2053
2081
|
if (outputCrc32) {
|
|
2054
|
-
|
|
2055
|
-
armIdleCheck();
|
|
2056
|
-
}
|
|
2057
|
-
await trailerReady;
|
|
2082
|
+
await writer.write(new Uint8Array(0));
|
|
2058
2083
|
}
|
|
2059
2084
|
const trailer = new Uint8Array(GZIP_TRAILER_LENGTH);
|
|
2060
2085
|
const dataView = getDataView(trailer);
|
|
@@ -2069,54 +2094,68 @@ function pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, cr
|
|
|
2069
2094
|
}
|
|
2070
2095
|
}
|
|
2071
2096
|
|
|
2072
|
-
function
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2097
|
+
async function drain() {
|
|
2098
|
+
try {
|
|
2099
|
+
for (; ;) {
|
|
2100
|
+
const { value, done } = await read();
|
|
2101
|
+
if (done) {
|
|
2102
|
+
break;
|
|
2103
|
+
}
|
|
2104
|
+
outputLength += value.length;
|
|
2105
|
+
if (outputLength > outputSize) {
|
|
2106
|
+
throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
|
|
2107
|
+
}
|
|
2108
|
+
if (outputCrc32) {
|
|
2109
|
+
outputCrc32.append(value);
|
|
2110
|
+
}
|
|
2111
|
+
controller.enqueue(value);
|
|
2112
|
+
}
|
|
2113
|
+
if (!settled) {
|
|
2114
|
+
settled = true;
|
|
2115
|
+
controller.close();
|
|
2116
|
+
}
|
|
2117
|
+
} catch (error) {
|
|
2118
|
+
fail(error);
|
|
2119
|
+
await cancel(reader, error);
|
|
2079
2120
|
}
|
|
2080
|
-
return result;
|
|
2081
2121
|
}
|
|
2082
2122
|
|
|
2083
|
-
function
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
if (!idleCheckArmed) {
|
|
2089
|
-
idleCheckArmed = true;
|
|
2090
|
-
const count = readCount;
|
|
2091
|
-
await nextTask();
|
|
2092
|
-
idleCheckArmed = false;
|
|
2093
|
-
if (readPending) {
|
|
2094
|
-
if (readCount == count) {
|
|
2095
|
-
resolveTrailerReady();
|
|
2096
|
-
} else {
|
|
2097
|
-
armIdleCheck();
|
|
2123
|
+
function read() {
|
|
2124
|
+
return reader.read().catch(error => {
|
|
2125
|
+
if (trailerWritten) {
|
|
2126
|
+
if (!outputCrc32) {
|
|
2127
|
+
throw mapError(error, ERR_INVALID_CRC32);
|
|
2098
2128
|
}
|
|
2129
|
+
if (outputLength != outputSize) {
|
|
2130
|
+
throw mapError(error, ERR_INVALID_UNCOMPRESSED_SIZE);
|
|
2131
|
+
}
|
|
2132
|
+
return { done: true };
|
|
2099
2133
|
}
|
|
2100
|
-
|
|
2134
|
+
throw mapCodecError(error, sourceErrors);
|
|
2135
|
+
});
|
|
2101
2136
|
}
|
|
2102
2137
|
|
|
2103
|
-
function
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2138
|
+
function outputCapacity() {
|
|
2139
|
+
if (!settled && controller.desiredSize <= 0) {
|
|
2140
|
+
return new Promise(resolve => resolvePull = resolve);
|
|
2141
|
+
}
|
|
2107
2142
|
}
|
|
2108
|
-
}
|
|
2109
2143
|
|
|
2110
|
-
function
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
port1.close();
|
|
2115
|
-
port2.close();
|
|
2144
|
+
function resumePump() {
|
|
2145
|
+
if (resolvePull) {
|
|
2146
|
+
const resolve = resolvePull;
|
|
2147
|
+
resolvePull = UNDEFINED_VALUE;
|
|
2116
2148
|
resolve();
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
function fail(error) {
|
|
2153
|
+
if (!settled) {
|
|
2154
|
+
settled = true;
|
|
2155
|
+
controller.error(error);
|
|
2156
|
+
resumePump();
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2120
2159
|
}
|
|
2121
2160
|
|
|
2122
2161
|
class InflateStream extends TransformStream {
|
|
@@ -2135,11 +2174,12 @@ class InflateStream extends TransformStream {
|
|
|
2135
2174
|
}
|
|
2136
2175
|
}
|
|
2137
2176
|
if (compressed) {
|
|
2177
|
+
const sourceErrors = new Set();
|
|
2138
2178
|
const codecStreams = format && getCodecStreams(format);
|
|
2179
|
+
let gzipStream;
|
|
2139
2180
|
if (codecStreams) {
|
|
2140
|
-
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize, compressionMethod, rawBitFlag, uncompressedSize: outputSize }));
|
|
2181
|
+
readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize, compressionMethod, rawBitFlag, uncompressedSize: outputSize }), sourceErrors);
|
|
2141
2182
|
} else {
|
|
2142
|
-
let gzipStream;
|
|
2143
2183
|
const GzipDecompressionStream = getGzipCodecStream(useCompressionStream, DecompressionStream, DecompressionStreamFallback);
|
|
2144
2184
|
if (checkCrc32 && !deflate64 && crc32 !== UNDEFINED_VALUE && outputSize !== UNDEFINED_VALUE && GzipDecompressionStream) {
|
|
2145
2185
|
try {
|
|
@@ -2150,24 +2190,25 @@ class InflateStream extends TransformStream {
|
|
|
2150
2190
|
}
|
|
2151
2191
|
if (!gzipStream) {
|
|
2152
2192
|
try {
|
|
2153
|
-
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamFallback);
|
|
2193
|
+
readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamFallback, sourceErrors);
|
|
2154
2194
|
} catch (error) {
|
|
2155
2195
|
if (deflate64 || outputSize === UNDEFINED_VALUE || (!useCompressionStream && DecompressionStreamFallback)) {
|
|
2156
|
-
throw error;
|
|
2196
|
+
throw mapMemoryError(error);
|
|
2157
2197
|
}
|
|
2158
2198
|
try {
|
|
2159
2199
|
gzipStream = new DecompressionStream(FORMAT_GZIP$1);
|
|
2160
2200
|
} catch {
|
|
2161
|
-
throw error;
|
|
2201
|
+
throw mapMemoryError(error);
|
|
2162
2202
|
}
|
|
2163
2203
|
}
|
|
2164
2204
|
}
|
|
2165
|
-
if (gzipStream) {
|
|
2166
|
-
gzipCrc32 = true;
|
|
2167
|
-
readable = pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, crc32);
|
|
2168
|
-
}
|
|
2169
2205
|
}
|
|
2170
|
-
|
|
2206
|
+
if (gzipStream) {
|
|
2207
|
+
gzipCrc32 = true;
|
|
2208
|
+
readable = pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize, crc32, sourceErrors);
|
|
2209
|
+
} else {
|
|
2210
|
+
readable = mapInflateStreamError(readable, sourceErrors);
|
|
2211
|
+
}
|
|
2171
2212
|
}
|
|
2172
2213
|
if (checkCrc32 && !gzipCrc32) {
|
|
2173
2214
|
crc32Stream = new Crc32Stream();
|
|
@@ -2240,7 +2281,7 @@ function getGzipCodecStream(useCompressionStream, CodecStreamNative, CodecStream
|
|
|
2240
2281
|
}
|
|
2241
2282
|
}
|
|
2242
2283
|
|
|
2243
|
-
function pipeThroughCompressionStream(readable, useCompressionStream, options, CompressionStreamNative, CompressionStreamFallback) {
|
|
2284
|
+
function pipeThroughCompressionStream(readable, useCompressionStream, options, CompressionStreamNative, CompressionStreamFallback, sourceErrors) {
|
|
2244
2285
|
const Stream = useCompressionStream && CompressionStreamNative ?
|
|
2245
2286
|
CompressionStreamNative :
|
|
2246
2287
|
CompressionStreamFallback || CompressionStreamNative;
|
|
@@ -2255,14 +2296,14 @@ function pipeThroughCompressionStream(readable, useCompressionStream, options, C
|
|
|
2255
2296
|
throw error;
|
|
2256
2297
|
}
|
|
2257
2298
|
}
|
|
2258
|
-
return pipeThroughBackpressured(readable, codecStream);
|
|
2299
|
+
return pipeThroughBackpressured(readable, codecStream, sourceErrors);
|
|
2259
2300
|
}
|
|
2260
2301
|
|
|
2261
2302
|
function pipeThrough(readable, transformStream) {
|
|
2262
2303
|
return toCompatibleReadable(readable).pipeThrough(transformStream);
|
|
2263
2304
|
}
|
|
2264
2305
|
|
|
2265
|
-
function pipeThroughBackpressured(readable, transformStream) {
|
|
2306
|
+
function pipeThroughBackpressured(readable, transformStream, sourceErrors) {
|
|
2266
2307
|
const writer = transformStream.writable.getWriter();
|
|
2267
2308
|
const reader = readable.getReader();
|
|
2268
2309
|
pump();
|
|
@@ -2272,7 +2313,7 @@ function pipeThroughBackpressured(readable, transformStream) {
|
|
|
2272
2313
|
try {
|
|
2273
2314
|
for (; ;) {
|
|
2274
2315
|
await writer.ready;
|
|
2275
|
-
const result = await reader
|
|
2316
|
+
const result = await readSource(reader, sourceErrors);
|
|
2276
2317
|
if (result.done) {
|
|
2277
2318
|
await writer.close();
|
|
2278
2319
|
break;
|
|
@@ -2302,26 +2343,49 @@ async function cancel(reader, error) {
|
|
|
2302
2343
|
}
|
|
2303
2344
|
}
|
|
2304
2345
|
|
|
2305
|
-
function
|
|
2346
|
+
function readSource(reader, sourceErrors) {
|
|
2347
|
+
const result = reader.read();
|
|
2348
|
+
return sourceErrors ? result.catch(error => {
|
|
2349
|
+
sourceErrors.add(error);
|
|
2350
|
+
throw error;
|
|
2351
|
+
}) : result;
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
function mapCodecError(error, sourceErrors) {
|
|
2355
|
+
if (sourceErrors.has(error)) {
|
|
2356
|
+
return error;
|
|
2357
|
+
}
|
|
2358
|
+
return mapError(error, isMemoryError(error) ? ERR_CODEC_OUT_OF_MEMORY : ERR_INVALID_COMPRESSED_DATA);
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
function mapMemoryError(error) {
|
|
2362
|
+
return isMemoryError(error) ? mapError(error, ERR_CODEC_OUT_OF_MEMORY) : error;
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
function isMemoryError(error) {
|
|
2366
|
+
return isErrorObject(error) && error.code == Z_MEM_ERROR_CODE$1;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
function mapError(error, message) {
|
|
2370
|
+
const mappedError = new Error(message);
|
|
2371
|
+
mappedError.cause = error;
|
|
2372
|
+
return mappedError;
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
function mapInflateStreamError(readable, sourceErrors) {
|
|
2306
2376
|
const reader = readable.getReader();
|
|
2307
2377
|
return new ReadableStream({
|
|
2308
2378
|
async pull(controller) {
|
|
2309
|
-
let result;
|
|
2310
2379
|
try {
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2380
|
+
const { value, done } = await reader.read();
|
|
2381
|
+
if (done) {
|
|
2382
|
+
controller.close();
|
|
2383
|
+
} else {
|
|
2384
|
+
controller.enqueue(value);
|
|
2315
2385
|
}
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
throw
|
|
2319
|
-
}
|
|
2320
|
-
const { value, done } = result;
|
|
2321
|
-
if (done) {
|
|
2322
|
-
controller.close();
|
|
2323
|
-
} else {
|
|
2324
|
-
controller.enqueue(value);
|
|
2386
|
+
} catch (error) {
|
|
2387
|
+
await cancel(reader, error);
|
|
2388
|
+
throw mapCodecError(error, sourceErrors);
|
|
2325
2389
|
}
|
|
2326
2390
|
},
|
|
2327
2391
|
cancel(reason) {
|
|
@@ -2689,10 +2753,11 @@ async function runWorker$1({ options, readable, writable, onTaskFinished, worker
|
|
|
2689
2753
|
}
|
|
2690
2754
|
codecStream = new CodecStream(options, config);
|
|
2691
2755
|
chunkStream = new ChunkStream(getChunkSize(config));
|
|
2756
|
+
const { signal } = workerOptions.streamOptions;
|
|
2692
2757
|
await readable
|
|
2693
2758
|
.pipeThrough(codecStream)
|
|
2694
2759
|
.pipeThrough(chunkStream)
|
|
2695
|
-
.pipeTo(writable, { preventClose: true, preventAbort: true });
|
|
2760
|
+
.pipeTo(writable, { preventClose: true, preventAbort: true, signal });
|
|
2696
2761
|
const {
|
|
2697
2762
|
crc32,
|
|
2698
2763
|
inputSize,
|
|
@@ -2760,6 +2825,7 @@ async function runWorker$1({ options, readable, writable, onTaskFinished, worker
|
|
|
2760
2825
|
const MODULE_WORKER_OPTIONS = { type: "module" };
|
|
2761
2826
|
const ERROR_EVENT_TYPE = "error";
|
|
2762
2827
|
const MESSAGE_ERROR_EVENT_TYPE = "messageerror";
|
|
2828
|
+
const ABORT_EVENT_TYPE = "abort";
|
|
2763
2829
|
|
|
2764
2830
|
let webWorkerSource, webWorkerURI, webWorkerOptions;
|
|
2765
2831
|
let transferStreamsSupported = true;
|
|
@@ -2936,6 +3002,13 @@ function watchClosedStream(writableSource, workerData) {
|
|
|
2936
3002
|
Object.assign(workerData, { destinationFailed: true, destinationError: error });
|
|
2937
3003
|
}
|
|
2938
3004
|
});
|
|
3005
|
+
const { signal } = workerData.workerOptions.streamOptions;
|
|
3006
|
+
if (signal) {
|
|
3007
|
+
const onAbort = () => abortController.abort(signal.reason);
|
|
3008
|
+
const removeAbortListener = () => signal.removeEventListener(ABORT_EVENT_TYPE, onAbort);
|
|
3009
|
+
signal.addEventListener(ABORT_EVENT_TYPE, onAbort);
|
|
3010
|
+
closed.then(removeAbortListener, removeAbortListener);
|
|
3011
|
+
}
|
|
2939
3012
|
return {
|
|
2940
3013
|
writable, closed, abortPipe: () => {
|
|
2941
3014
|
aborting = true;
|
|
@@ -3198,9 +3271,6 @@ function getResponseError(errorData, errorValue) {
|
|
|
3198
3271
|
responseError = errorValue.value;
|
|
3199
3272
|
} else {
|
|
3200
3273
|
responseError = Object.assign(new Error(message), { stack, code, name });
|
|
3201
|
-
if (cause) {
|
|
3202
|
-
responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
|
|
3203
|
-
}
|
|
3204
3274
|
}
|
|
3205
3275
|
if (isErrorObject(responseError)) {
|
|
3206
3276
|
try {
|
|
@@ -3210,6 +3280,9 @@ function getResponseError(errorData, errorValue) {
|
|
|
3210
3280
|
if (codecImportFailed) {
|
|
3211
3281
|
responseError.codecImportFailed = true;
|
|
3212
3282
|
}
|
|
3283
|
+
if (cause && !isErrorObject(responseError.cause)) {
|
|
3284
|
+
responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
|
|
3285
|
+
}
|
|
3213
3286
|
if (errorValue) {
|
|
3214
3287
|
if (responseError.name !== name) {
|
|
3215
3288
|
responseError.name = name;
|
|
@@ -5401,8 +5474,8 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5401
5474
|
const passThroughCompression = Boolean(passThrough);
|
|
5402
5475
|
const passThroughEncryption = passThrough === true;
|
|
5403
5476
|
checkPasswordOption(password, rawPassword);
|
|
5404
|
-
password = password && password.length
|
|
5405
|
-
rawPassword = rawPassword && rawPassword.length
|
|
5477
|
+
password = password && password.length ? password : UNDEFINED_VALUE;
|
|
5478
|
+
rawPassword = rawPassword && rawPassword.length ? rawPassword : UNDEFINED_VALUE;
|
|
5406
5479
|
if (extraFieldAES) {
|
|
5407
5480
|
if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
|
|
5408
5481
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
@@ -5552,6 +5625,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5552
5625
|
({ writable } = writer);
|
|
5553
5626
|
const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
|
|
5554
5627
|
const { outputSize: writtenSize } = await runWorker({ readable, writable }, workerOptions);
|
|
5628
|
+
throwIfAborted(signal);
|
|
5555
5629
|
if (writtenSize != outputSize) {
|
|
5556
5630
|
throw Object.assign(new Error(ERR_INVALID_UNCOMPRESSED_SIZE), { outputSize: writtenSize });
|
|
5557
5631
|
}
|
|
@@ -6163,7 +6237,7 @@ function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
|
|
|
6163
6237
|
async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDataSize) {
|
|
6164
6238
|
const { size } = reader;
|
|
6165
6239
|
const anchoredLength = Math.min(size, END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS);
|
|
6166
|
-
const remoteProbeBudget = {
|
|
6240
|
+
const remoteProbeBudget = { remaining: MAX_END_OF_CENTRAL_DIR_PROBES };
|
|
6167
6241
|
let endOfDirectoryInfo;
|
|
6168
6242
|
let plausibleEndOfDirectoryInfo;
|
|
6169
6243
|
let endOfDirectoryReachingEndCount = 0;
|
|
@@ -6256,8 +6330,8 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
|
|
|
6256
6330
|
if (signatureOffset >= anchoredOffset) {
|
|
6257
6331
|
return getUint32$1(view, signatureOffset - anchoredOffset);
|
|
6258
6332
|
}
|
|
6259
|
-
if (remoteProbeBudget.
|
|
6260
|
-
remoteProbeBudget.
|
|
6333
|
+
if (remoteProbeBudget.remaining > 0) {
|
|
6334
|
+
remoteProbeBudget.remaining--;
|
|
6261
6335
|
const signatureArray = await readUint8Array(reader, signatureOffset, 4);
|
|
6262
6336
|
return getUint32$1(getDataView(signatureArray), 0);
|
|
6263
6337
|
}
|
|
@@ -6347,6 +6421,7 @@ var zipReader = /*#__PURE__*/Object.freeze({
|
|
|
6347
6421
|
ERR_AMBIGUOUS_ARCHIVE: ERR_AMBIGUOUS_ARCHIVE,
|
|
6348
6422
|
ERR_BAD_FORMAT: ERR_BAD_FORMAT,
|
|
6349
6423
|
ERR_CENTRAL_DIRECTORY_NOT_FOUND: ERR_CENTRAL_DIRECTORY_NOT_FOUND,
|
|
6424
|
+
ERR_CODEC_OUT_OF_MEMORY: ERR_CODEC_OUT_OF_MEMORY,
|
|
6350
6425
|
ERR_ENCRYPTED: ERR_ENCRYPTED,
|
|
6351
6426
|
ERR_ENCRYPTED_CENTRAL_DIRECTORY: ERR_ENCRYPTED_CENTRAL_DIRECTORY,
|
|
6352
6427
|
ERR_ENTRY_DATA_OUT_OF_BOUNDS: ERR_ENTRY_DATA_OUT_OF_BOUNDS,
|
|
@@ -7173,9 +7248,11 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
7173
7248
|
const passThrough = checkPassThroughOption(getOptionValue(zipWriter, options, OPTION_PASS_THROUGH));
|
|
7174
7249
|
const passThroughCompression = Boolean(passThrough);
|
|
7175
7250
|
const passThroughEncryption = passThrough === true;
|
|
7176
|
-
|
|
7177
|
-
|
|
7251
|
+
let password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
7252
|
+
let rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
7178
7253
|
checkPasswordOption(password, rawPassword);
|
|
7254
|
+
password = password && password.length ? password : UNDEFINED_VALUE;
|
|
7255
|
+
rawPassword = rawPassword && rawPassword.length ? rawPassword : UNDEFINED_VALUE;
|
|
7179
7256
|
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
7180
7257
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
7181
7258
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
@@ -7792,6 +7869,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
|
|
|
7792
7869
|
const result = await runWorker({ readable, writable }, workerOptions);
|
|
7793
7870
|
compressedSize = result.outputSize;
|
|
7794
7871
|
writer.size += compressedSize;
|
|
7872
|
+
throwIfAborted(signal);
|
|
7795
7873
|
if (!passThroughCompression) {
|
|
7796
7874
|
uncompressedSize = result.inputSize;
|
|
7797
7875
|
if (!encrypted || zipCrypto) {
|
|
@@ -8971,7 +9049,7 @@ function formatSupported(StreamClass, format) {
|
|
|
8971
9049
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
8972
9050
|
*/
|
|
8973
9051
|
|
|
8974
|
-
const VERSION = "2.
|
|
9052
|
+
const VERSION = "2.17.0";
|
|
8975
9053
|
|
|
8976
9054
|
/*
|
|
8977
9055
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
@@ -9448,12 +9526,16 @@ try {
|
|
|
9448
9526
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
9449
9527
|
*/
|
|
9450
9528
|
|
|
9451
|
-
/* global
|
|
9529
|
+
/* global ReadableStream, WritableStream */
|
|
9452
9530
|
|
|
9453
9531
|
const FORMAT_DEFLATE = "deflate";
|
|
9454
9532
|
const FORMAT_DEFLATE_RAW = "deflate-raw";
|
|
9455
9533
|
const FORMAT_DEFLATE64_RAW = "deflate64-raw";
|
|
9456
9534
|
const FORMAT_GZIP = "gzip";
|
|
9535
|
+
const Z_MEM_ERROR = -4;
|
|
9536
|
+
const Z_MEM_ERROR_CODE = "Z_MEM_ERROR";
|
|
9537
|
+
const COMPRESSION_FORMATS = [FORMAT_DEFLATE, FORMAT_DEFLATE_RAW, FORMAT_GZIP];
|
|
9538
|
+
const DECOMPRESSION_FORMATS = [FORMAT_DEFLATE, FORMAT_DEFLATE_RAW, FORMAT_GZIP, FORMAT_DEFLATE64_RAW];
|
|
9457
9539
|
|
|
9458
9540
|
let wasm$1, malloc, free, memory, initError;
|
|
9459
9541
|
|
|
@@ -9474,7 +9556,17 @@ function resetWasmExports$1() {
|
|
|
9474
9556
|
wasm$1 = malloc = free = memory = initError = null;
|
|
9475
9557
|
}
|
|
9476
9558
|
|
|
9559
|
+
function setZlibCode(error, result) {
|
|
9560
|
+
if (result === Z_MEM_ERROR) {
|
|
9561
|
+
error.code = Z_MEM_ERROR_CODE;
|
|
9562
|
+
}
|
|
9563
|
+
return error;
|
|
9564
|
+
}
|
|
9565
|
+
|
|
9477
9566
|
function _make(isCompress, type, options = {}) {
|
|
9567
|
+
if (!(isCompress ? COMPRESSION_FORMATS : DECOMPRESSION_FORMATS).includes(type)) {
|
|
9568
|
+
throw new TypeError("Unsupported format: " + type);
|
|
9569
|
+
}
|
|
9478
9570
|
if (!wasm$1) {
|
|
9479
9571
|
const error = new Error("WASM module not loaded");
|
|
9480
9572
|
error.cause = initError;
|
|
@@ -9483,137 +9575,200 @@ function _make(isCompress, type, options = {}) {
|
|
|
9483
9575
|
const level = (typeof options.level === "number") ? options.level : -1;
|
|
9484
9576
|
const outBufferSize = (typeof options.outBuffer === "number") ? options.outBuffer : 64 * 1024;
|
|
9485
9577
|
const inBufferSize = (typeof options.inBufferSize === "number") ? options.inBufferSize : 64 * 1024;
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9578
|
+
const state = { out: 0, in: 0, inBufferSize: 0, streamHandle: 0, streamEnded: false };
|
|
9579
|
+
let readableController, writableController, resolveWrite, cancelReason;
|
|
9580
|
+
let backpressure = true;
|
|
9581
|
+
let cancelled = false;
|
|
9582
|
+
initStream();
|
|
9583
|
+
const readable = new ReadableStream({
|
|
9584
|
+
start(controller) {
|
|
9585
|
+
readableController = controller;
|
|
9586
|
+
},
|
|
9587
|
+
pull() {
|
|
9588
|
+
backpressure = false;
|
|
9589
|
+
resumeWrite();
|
|
9590
|
+
},
|
|
9591
|
+
cancel(reason) {
|
|
9592
|
+
cancelled = true;
|
|
9593
|
+
cancelReason = reason;
|
|
9594
|
+
disposeStream(state);
|
|
9595
|
+
writableController.error(reason);
|
|
9596
|
+
resumeWrite();
|
|
9597
|
+
}
|
|
9598
|
+
}, { highWaterMark: 0 });
|
|
9599
|
+
const writable = new WritableStream({
|
|
9600
|
+
start(controller) {
|
|
9601
|
+
writableController = controller;
|
|
9602
|
+
},
|
|
9603
|
+
async write(chunk) {
|
|
9604
|
+
if (backpressure) {
|
|
9605
|
+
await new Promise(resolve => resolveWrite = resolve);
|
|
9606
|
+
}
|
|
9607
|
+
if (cancelled) {
|
|
9608
|
+
throw cancelReason;
|
|
9609
|
+
}
|
|
9489
9610
|
try {
|
|
9490
|
-
|
|
9491
|
-
this.out = malloc(outBufferSize);
|
|
9492
|
-
this.in = malloc(inBufferSize);
|
|
9493
|
-
this.inBufferSize = inBufferSize;
|
|
9494
|
-
if (!this.out || !this.in) {
|
|
9495
|
-
throw new Error("allocation failed");
|
|
9496
|
-
}
|
|
9497
|
-
if (isCompress) {
|
|
9498
|
-
this._process = wasm$1.deflate_process;
|
|
9499
|
-
this._last_consumed = wasm$1.deflate_last_consumed;
|
|
9500
|
-
this._end = wasm$1.deflate_end;
|
|
9501
|
-
this.streamHandle = wasm$1.deflate_new();
|
|
9502
|
-
if (type === FORMAT_GZIP) {
|
|
9503
|
-
result = wasm$1.deflate_init_gzip(this.streamHandle, level);
|
|
9504
|
-
} else if (type === FORMAT_DEFLATE_RAW) {
|
|
9505
|
-
result = wasm$1.deflate_init_raw(this.streamHandle, level);
|
|
9506
|
-
} else {
|
|
9507
|
-
result = wasm$1.deflate_init(this.streamHandle, level);
|
|
9508
|
-
}
|
|
9509
|
-
} else {
|
|
9510
|
-
if (type === FORMAT_DEFLATE64_RAW) {
|
|
9511
|
-
this._process = wasm$1.inflate9_process;
|
|
9512
|
-
this._last_consumed = wasm$1.inflate9_last_consumed;
|
|
9513
|
-
this._end = wasm$1.inflate9_end;
|
|
9514
|
-
this.streamHandle = wasm$1.inflate9_new();
|
|
9515
|
-
result = wasm$1.inflate9_init_raw(this.streamHandle);
|
|
9516
|
-
} else {
|
|
9517
|
-
this._process = wasm$1.inflate_process;
|
|
9518
|
-
this._last_consumed = wasm$1.inflate_last_consumed;
|
|
9519
|
-
this._end = wasm$1.inflate_end;
|
|
9520
|
-
this.streamHandle = wasm$1.inflate_new();
|
|
9521
|
-
if (type === FORMAT_DEFLATE_RAW) {
|
|
9522
|
-
result = wasm$1.inflate_init_raw(this.streamHandle);
|
|
9523
|
-
} else if (type === FORMAT_GZIP) {
|
|
9524
|
-
result = wasm$1.inflate_init_gzip(this.streamHandle);
|
|
9525
|
-
} else {
|
|
9526
|
-
result = wasm$1.inflate_init(this.streamHandle);
|
|
9527
|
-
}
|
|
9528
|
-
}
|
|
9529
|
-
}
|
|
9530
|
-
if (result !== 0) {
|
|
9531
|
-
throw new Error("init failed:" + result);
|
|
9532
|
-
}
|
|
9611
|
+
processChunk(chunk);
|
|
9533
9612
|
} catch (error) {
|
|
9534
|
-
disposeStream(
|
|
9613
|
+
disposeStream(state);
|
|
9614
|
+
readableController.error(error);
|
|
9535
9615
|
throw error;
|
|
9536
9616
|
}
|
|
9537
9617
|
},
|
|
9538
|
-
|
|
9618
|
+
close() {
|
|
9619
|
+
if (cancelled) {
|
|
9620
|
+
return;
|
|
9621
|
+
}
|
|
9539
9622
|
try {
|
|
9540
|
-
|
|
9541
|
-
const heap = new Uint8Array(memory.buffer);
|
|
9542
|
-
const process = this._process;
|
|
9543
|
-
const last_consumed = this._last_consumed;
|
|
9544
|
-
const out = this.out;
|
|
9545
|
-
let offset = 0;
|
|
9546
|
-
while (offset < buffer.length) {
|
|
9547
|
-
const toRead = Math.min(buffer.length - offset, 32 * 1024);
|
|
9548
|
-
if (!this.in || this.inBufferSize < toRead) {
|
|
9549
|
-
if (this.in && free) {
|
|
9550
|
-
free(this.in);
|
|
9551
|
-
this.in = 0;
|
|
9552
|
-
}
|
|
9553
|
-
this.in = malloc(toRead);
|
|
9554
|
-
this.inBufferSize = toRead;
|
|
9555
|
-
if (!this.in) {
|
|
9556
|
-
throw new Error("allocation failed");
|
|
9557
|
-
}
|
|
9558
|
-
}
|
|
9559
|
-
heap.set(buffer.subarray(offset, offset + toRead), this.in);
|
|
9560
|
-
const result = process(this.streamHandle, this.in, toRead, out, outBufferSize, 0);
|
|
9561
|
-
// checked before the byte count is used, so a status code can never be read as one
|
|
9562
|
-
const code = (result >> 24) & 0xff;
|
|
9563
|
-
const signedCode = (code & 0x80) ? code - 256 : code;
|
|
9564
|
-
if (signedCode < 0) {
|
|
9565
|
-
throw new Error("process error:" + signedCode);
|
|
9566
|
-
}
|
|
9567
|
-
const prod = result & 0x00ffffff;
|
|
9568
|
-
if (prod) {
|
|
9569
|
-
controller.enqueue(heap.slice(out, out + prod));
|
|
9570
|
-
}
|
|
9571
|
-
const consumed = last_consumed(this.streamHandle);
|
|
9572
|
-
if (consumed === 0 && prod === 0) {
|
|
9573
|
-
break;
|
|
9574
|
-
}
|
|
9575
|
-
offset += consumed;
|
|
9576
|
-
}
|
|
9623
|
+
flushStream();
|
|
9577
9624
|
} catch (error) {
|
|
9578
|
-
disposeStream(
|
|
9579
|
-
|
|
9625
|
+
disposeStream(state);
|
|
9626
|
+
readableController.error(error);
|
|
9627
|
+
throw error;
|
|
9580
9628
|
}
|
|
9629
|
+
const result = disposeStream(state);
|
|
9630
|
+
if (result !== 0) {
|
|
9631
|
+
const error = setZlibCode(new Error("end error:" + result), result);
|
|
9632
|
+
readableController.error(error);
|
|
9633
|
+
throw error;
|
|
9634
|
+
}
|
|
9635
|
+
readableController.close();
|
|
9581
9636
|
},
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9637
|
+
abort(reason) {
|
|
9638
|
+
disposeStream(state);
|
|
9639
|
+
readableController.error(reason);
|
|
9640
|
+
}
|
|
9641
|
+
}, { highWaterMark: 1 });
|
|
9642
|
+
return { readable, writable };
|
|
9643
|
+
|
|
9644
|
+
function initStream() {
|
|
9645
|
+
try {
|
|
9646
|
+
let result;
|
|
9647
|
+
state.out = malloc(outBufferSize);
|
|
9648
|
+
state.in = malloc(inBufferSize);
|
|
9649
|
+
state.inBufferSize = inBufferSize;
|
|
9650
|
+
if (!state.out || !state.in) {
|
|
9651
|
+
throw setZlibCode(new Error("allocation failed"), Z_MEM_ERROR);
|
|
9652
|
+
}
|
|
9653
|
+
if (isCompress) {
|
|
9654
|
+
state._process = wasm$1.deflate_process;
|
|
9655
|
+
state._last_consumed = wasm$1.deflate_last_consumed;
|
|
9656
|
+
state._end = wasm$1.deflate_end;
|
|
9657
|
+
state.streamHandle = wasm$1.deflate_new();
|
|
9658
|
+
if (type === FORMAT_GZIP) {
|
|
9659
|
+
result = wasm$1.deflate_init_gzip(state.streamHandle, level);
|
|
9660
|
+
} else if (type === FORMAT_DEFLATE_RAW) {
|
|
9661
|
+
result = wasm$1.deflate_init_raw(state.streamHandle, level);
|
|
9662
|
+
} else {
|
|
9663
|
+
result = wasm$1.deflate_init(state.streamHandle, level);
|
|
9664
|
+
}
|
|
9665
|
+
} else {
|
|
9666
|
+
if (type === FORMAT_DEFLATE64_RAW) {
|
|
9667
|
+
state._process = wasm$1.inflate9_process;
|
|
9668
|
+
state._last_consumed = wasm$1.inflate9_last_consumed;
|
|
9669
|
+
state._end = wasm$1.inflate9_end;
|
|
9670
|
+
state.streamHandle = wasm$1.inflate9_new();
|
|
9671
|
+
result = wasm$1.inflate9_init_raw(state.streamHandle);
|
|
9672
|
+
} else {
|
|
9673
|
+
state._process = wasm$1.inflate_process;
|
|
9674
|
+
state._last_consumed = wasm$1.inflate_last_consumed;
|
|
9675
|
+
state._end = wasm$1.inflate_end;
|
|
9676
|
+
state.streamHandle = wasm$1.inflate_new();
|
|
9677
|
+
if (type === FORMAT_DEFLATE_RAW) {
|
|
9678
|
+
result = wasm$1.inflate_init_raw(state.streamHandle);
|
|
9679
|
+
} else if (type === FORMAT_GZIP) {
|
|
9680
|
+
result = wasm$1.inflate_init_gzip(state.streamHandle);
|
|
9681
|
+
} else {
|
|
9682
|
+
result = wasm$1.inflate_init(state.streamHandle);
|
|
9600
9683
|
}
|
|
9601
9684
|
}
|
|
9602
|
-
}
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9685
|
+
}
|
|
9686
|
+
if (result !== 0) {
|
|
9687
|
+
throw setZlibCode(new Error("init failed:" + result), result);
|
|
9688
|
+
}
|
|
9689
|
+
} catch (error) {
|
|
9690
|
+
disposeStream(state);
|
|
9691
|
+
throw error;
|
|
9692
|
+
}
|
|
9693
|
+
}
|
|
9694
|
+
|
|
9695
|
+
function processChunk(chunk) {
|
|
9696
|
+
const heap = new Uint8Array(memory.buffer);
|
|
9697
|
+
const process = state._process;
|
|
9698
|
+
const last_consumed = state._last_consumed;
|
|
9699
|
+
const out = state.out;
|
|
9700
|
+
let offset = 0;
|
|
9701
|
+
while (offset < chunk.length) {
|
|
9702
|
+
if (state.streamEnded) {
|
|
9703
|
+
throw new Error("trailing data after the end of the stream");
|
|
9704
|
+
}
|
|
9705
|
+
const toRead = Math.min(chunk.length - offset, 32 * 1024);
|
|
9706
|
+
if (!state.in || state.inBufferSize < toRead) {
|
|
9707
|
+
if (state.in && free) {
|
|
9708
|
+
free(state.in);
|
|
9709
|
+
state.in = 0;
|
|
9710
|
+
}
|
|
9711
|
+
state.in = malloc(toRead);
|
|
9712
|
+
state.inBufferSize = toRead;
|
|
9713
|
+
if (!state.in) {
|
|
9714
|
+
throw setZlibCode(new Error("allocation failed"), Z_MEM_ERROR);
|
|
9608
9715
|
}
|
|
9609
9716
|
}
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
//
|
|
9613
|
-
|
|
9614
|
-
|
|
9717
|
+
heap.set(chunk.subarray(offset, offset + toRead), state.in);
|
|
9718
|
+
const result = process(state.streamHandle, state.in, toRead, out, outBufferSize, 0);
|
|
9719
|
+
// checked before the byte count is used, so a status code can never be read as one
|
|
9720
|
+
const code = (result >> 24) & 0xff;
|
|
9721
|
+
const signedCode = (code & 0x80) ? code - 256 : code;
|
|
9722
|
+
if (signedCode < 0) {
|
|
9723
|
+
throw setZlibCode(new Error("process error:" + signedCode), signedCode);
|
|
9724
|
+
}
|
|
9725
|
+
const prod = result & 0x00ffffff;
|
|
9726
|
+
if (prod) {
|
|
9727
|
+
enqueue(heap.slice(out, out + prod));
|
|
9728
|
+
}
|
|
9729
|
+
const consumed = last_consumed(state.streamHandle);
|
|
9730
|
+
if (code === 1) {
|
|
9731
|
+
state.streamEnded = true;
|
|
9732
|
+
} else if (consumed === 0 && prod === 0) {
|
|
9733
|
+
break;
|
|
9734
|
+
}
|
|
9735
|
+
offset += consumed;
|
|
9615
9736
|
}
|
|
9616
|
-
}
|
|
9737
|
+
}
|
|
9738
|
+
|
|
9739
|
+
function flushStream() {
|
|
9740
|
+
const heap = new Uint8Array(memory.buffer);
|
|
9741
|
+
const process = state._process;
|
|
9742
|
+
const out = state.out;
|
|
9743
|
+
while (true) {
|
|
9744
|
+
const result = process(state.streamHandle, 0, 0, out, outBufferSize, 4);
|
|
9745
|
+
const code = (result >> 24) & 0xff;
|
|
9746
|
+
const signedCode = (code & 0x80) ? code - 256 : code;
|
|
9747
|
+
if (signedCode < 0) {
|
|
9748
|
+
throw setZlibCode(new Error("process error:" + signedCode), signedCode);
|
|
9749
|
+
}
|
|
9750
|
+
const produced = result & 0x00ffffff;
|
|
9751
|
+
if (produced) {
|
|
9752
|
+
enqueue(heap.slice(out, out + produced));
|
|
9753
|
+
}
|
|
9754
|
+
if (code === 1 || produced === 0) {
|
|
9755
|
+
break;
|
|
9756
|
+
}
|
|
9757
|
+
}
|
|
9758
|
+
}
|
|
9759
|
+
|
|
9760
|
+
function enqueue(chunk) {
|
|
9761
|
+
backpressure = true;
|
|
9762
|
+
readableController.enqueue(chunk);
|
|
9763
|
+
}
|
|
9764
|
+
|
|
9765
|
+
function resumeWrite() {
|
|
9766
|
+
if (resolveWrite) {
|
|
9767
|
+
const resolve = resolveWrite;
|
|
9768
|
+
resolveWrite = null;
|
|
9769
|
+
resolve();
|
|
9770
|
+
}
|
|
9771
|
+
}
|
|
9617
9772
|
|
|
9618
9773
|
function disposeStream(state) {
|
|
9619
9774
|
let endResult = 0;
|
|
@@ -9649,10 +9804,10 @@ class DecompressionStreamZlib {
|
|
|
9649
9804
|
CompressionStreamZlib.requiresModule = true;
|
|
9650
9805
|
DecompressionStreamZlib.requiresModule = true;
|
|
9651
9806
|
// Constructing these classes before the module is loaded throws, so capability probes cannot rely
|
|
9652
|
-
// on trying the constructor; the formats are declared instead,
|
|
9653
|
-
//
|
|
9654
|
-
CompressionStreamZlib.supportedFormats =
|
|
9655
|
-
DecompressionStreamZlib.supportedFormats =
|
|
9807
|
+
// on trying the constructor; the formats are declared instead, the lists _make() checks a format
|
|
9808
|
+
// against before anything else.
|
|
9809
|
+
CompressionStreamZlib.supportedFormats = COMPRESSION_FORMATS;
|
|
9810
|
+
DecompressionStreamZlib.supportedFormats = DECOMPRESSION_FORMATS;
|
|
9656
9811
|
|
|
9657
9812
|
/*
|
|
9658
9813
|
Copyright (c) 2026 Gildas Lormeau. All rights reserved.
|
|
@@ -9943,7 +10098,12 @@ const DUPLICATES_VALUES = new Set([DUPLICATES_THROW, DUPLICATES_KEEP_FIRST, DUPL
|
|
|
9943
10098
|
const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
|
|
9944
10099
|
const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
|
|
9945
10100
|
const ERR_UNSUPPORTED_PASS_THROUGH_VALUE = "The 'compressed' passThrough option is only supported by Entry#getData() and ZipWriter#add()";
|
|
10101
|
+
const ERR_INVALID_PASSWORDS = "Invalid passwords option (must be an array of strings)";
|
|
10102
|
+
const ERR_INVALID_REQUEST_PASSWORD = "Invalid requestPassword option (must be a function returning a string or undefined)";
|
|
9946
10103
|
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
10104
|
+
const ABORT_ERROR_NAME = "AbortError";
|
|
10105
|
+
const EMPTY_RAW_PASSWORD = new Uint8Array(0);
|
|
10106
|
+
const FALSE_ACCEPT_ERRORS = new Set([ERR_INVALID_CRC32, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_COMPRESSED_DATA]);
|
|
9947
10107
|
|
|
9948
10108
|
class ZipEntry {
|
|
9949
10109
|
|
|
@@ -10316,8 +10476,10 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
10316
10476
|
zipReader = new ZipReader(reader, options);
|
|
10317
10477
|
}
|
|
10318
10478
|
checkPassThroughValue(options.passThrough);
|
|
10479
|
+
checkPasswordCandidatesOptions(options);
|
|
10319
10480
|
const duplicates = checkDuplicatesOption(options.duplicates);
|
|
10320
10481
|
const importedEntries = [];
|
|
10482
|
+
const passwordState = { known: [] };
|
|
10321
10483
|
const entries = await zipReader.getEntries(options);
|
|
10322
10484
|
for (const entry of entries) {
|
|
10323
10485
|
let parent = this;
|
|
@@ -10362,7 +10524,7 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
10362
10524
|
}
|
|
10363
10525
|
importedEntries.push(addChild(parent, name, {
|
|
10364
10526
|
data: entry,
|
|
10365
|
-
Reader: getZipBlobReader(Object.assign({}, options)),
|
|
10527
|
+
Reader: getZipBlobReader(Object.assign({}, options), passwordState),
|
|
10366
10528
|
uncompressedSize: options.passThrough ? entry.compressedSize : entry.uncompressedSize,
|
|
10367
10529
|
passThrough: options.passThrough
|
|
10368
10530
|
}));
|
|
@@ -10691,7 +10853,7 @@ function getReadableReader(readable) {
|
|
|
10691
10853
|
};
|
|
10692
10854
|
}
|
|
10693
10855
|
|
|
10694
|
-
function getZipBlobReader(options) {
|
|
10856
|
+
function getZipBlobReader(options, passwordState) {
|
|
10695
10857
|
return class extends Reader {
|
|
10696
10858
|
|
|
10697
10859
|
constructor(entry, options = {}) {
|
|
@@ -10704,12 +10866,12 @@ function getZipBlobReader(options) {
|
|
|
10704
10866
|
const zipBlobReader = this;
|
|
10705
10867
|
const readerOptions = Object.assign({}, options, zipBlobReader.options);
|
|
10706
10868
|
const { checkOverlappingEntry, checkOverlappingEntryOnly } = readerOptions;
|
|
10707
|
-
const data = await zipBlobReader.entry
|
|
10869
|
+
const data = await readEntryData(zipBlobReader.entry, Object.assign(readerOptions, {
|
|
10708
10870
|
checkPasswordOnly: false,
|
|
10709
10871
|
checkOverlappingEntry: checkOverlappingEntryOnly || checkOverlappingEntry,
|
|
10710
10872
|
checkOverlappingEntryOnly: false,
|
|
10711
10873
|
preventClose: false
|
|
10712
|
-
}));
|
|
10874
|
+
}), passwordState);
|
|
10713
10875
|
zipBlobReader.data = data;
|
|
10714
10876
|
zipBlobReader.blobReader = new BlobReader(data);
|
|
10715
10877
|
zipBlobReader.size = data.size;
|
|
@@ -10771,10 +10933,9 @@ async function initReaders(entry, options) {
|
|
|
10771
10933
|
await initStream(reader);
|
|
10772
10934
|
} catch (error) {
|
|
10773
10935
|
try {
|
|
10936
|
+
error.entry = child;
|
|
10774
10937
|
error.entryId = child.id;
|
|
10775
|
-
error.
|
|
10776
|
-
entry: child
|
|
10777
|
-
};
|
|
10938
|
+
error.entryName = child.getRelativeName(entry);
|
|
10778
10939
|
} catch {
|
|
10779
10940
|
// ignored
|
|
10780
10941
|
}
|
|
@@ -10866,10 +11027,145 @@ function checkReaderOptions(readerOptions) {
|
|
|
10866
11027
|
}
|
|
10867
11028
|
if (readerOptions) {
|
|
10868
11029
|
checkPassThroughValue(readerOptions.passThrough);
|
|
11030
|
+
checkPasswordCandidatesOptions(readerOptions);
|
|
10869
11031
|
}
|
|
10870
11032
|
return readerOptions;
|
|
10871
11033
|
}
|
|
10872
11034
|
|
|
11035
|
+
function checkPasswordCandidatesOptions(options) {
|
|
11036
|
+
const { passwords, requestPassword } = options;
|
|
11037
|
+
if (passwords && (!Array.isArray(passwords) || passwords.some(password => typeof password != STRING_TYPE))) {
|
|
11038
|
+
throw new Error(ERR_INVALID_PASSWORDS);
|
|
11039
|
+
}
|
|
11040
|
+
if (requestPassword && typeof requestPassword != FUNCTION_TYPE) {
|
|
11041
|
+
throw new Error(ERR_INVALID_REQUEST_PASSWORD);
|
|
11042
|
+
}
|
|
11043
|
+
}
|
|
11044
|
+
|
|
11045
|
+
async function readEntryData(entry, options, passwordState) {
|
|
11046
|
+
checkPasswordCandidatesOptions(options);
|
|
11047
|
+
const { passwords, requestPassword, signal } = options;
|
|
11048
|
+
options = Object.assign({}, options);
|
|
11049
|
+
delete options.passwords;
|
|
11050
|
+
delete options.requestPassword;
|
|
11051
|
+
if (!entry.encrypted || options.passThrough || (!passwords && !requestPassword)) {
|
|
11052
|
+
return entry.getData(new BlobWriter(), options);
|
|
11053
|
+
}
|
|
11054
|
+
const tried = new Set();
|
|
11055
|
+
let error;
|
|
11056
|
+
while (true) {
|
|
11057
|
+
for (const candidate of getPasswordCandidates(options, passwordState, passwords)) {
|
|
11058
|
+
if (!tried.has(candidate.key)) {
|
|
11059
|
+
const result = await tryPasswordCandidate(candidate);
|
|
11060
|
+
if (result.done) {
|
|
11061
|
+
return result.data;
|
|
11062
|
+
}
|
|
11063
|
+
error = result.error;
|
|
11064
|
+
}
|
|
11065
|
+
}
|
|
11066
|
+
if (!requestPassword) {
|
|
11067
|
+
break;
|
|
11068
|
+
}
|
|
11069
|
+
if (passwordState.pendingPrompt) {
|
|
11070
|
+
await passwordState.pendingPrompt;
|
|
11071
|
+
continue;
|
|
11072
|
+
}
|
|
11073
|
+
let release;
|
|
11074
|
+
passwordState.pendingPrompt = new Promise(resolve => release = resolve);
|
|
11075
|
+
try {
|
|
11076
|
+
const answer = await requestPassword(entry, error);
|
|
11077
|
+
if (answer === UNDEFINED_VALUE || answer === null) {
|
|
11078
|
+
break;
|
|
11079
|
+
}
|
|
11080
|
+
// deno-lint-ignore valid-typeof
|
|
11081
|
+
if (typeof answer != STRING_TYPE) {
|
|
11082
|
+
throw new Error(ERR_INVALID_REQUEST_PASSWORD);
|
|
11083
|
+
}
|
|
11084
|
+
const result = await tryPasswordCandidate(getPasswordCandidate(answer));
|
|
11085
|
+
if (result.done) {
|
|
11086
|
+
return result.data;
|
|
11087
|
+
}
|
|
11088
|
+
error = result.error;
|
|
11089
|
+
} finally {
|
|
11090
|
+
passwordState.pendingPrompt = UNDEFINED_VALUE;
|
|
11091
|
+
release();
|
|
11092
|
+
}
|
|
11093
|
+
}
|
|
11094
|
+
if (!tried.size) {
|
|
11095
|
+
throw new Error(ERR_ENCRYPTED);
|
|
11096
|
+
}
|
|
11097
|
+
const passwordError = new Error(ERR_INVALID_PASSWORD);
|
|
11098
|
+
passwordError.cause = error;
|
|
11099
|
+
throw passwordError;
|
|
11100
|
+
|
|
11101
|
+
async function tryPasswordCandidate(candidate) {
|
|
11102
|
+
tried.add(candidate.key);
|
|
11103
|
+
const candidateOptions = Object.assign({}, options, candidate.options);
|
|
11104
|
+
if (entry.zipCrypto) {
|
|
11105
|
+
candidateOptions.checkCrc32 = true;
|
|
11106
|
+
try {
|
|
11107
|
+
await entry.getData(null, Object.assign({}, candidateOptions, { checkPasswordOnly: true }));
|
|
11108
|
+
} catch (probeError) {
|
|
11109
|
+
if (isInvalidPasswordError(probeError)) {
|
|
11110
|
+
return { done: false, error: probeError };
|
|
11111
|
+
}
|
|
11112
|
+
throw probeError;
|
|
11113
|
+
}
|
|
11114
|
+
}
|
|
11115
|
+
try {
|
|
11116
|
+
const data = await entry.getData(new BlobWriter(), candidateOptions);
|
|
11117
|
+
rememberPassword(passwordState, candidate);
|
|
11118
|
+
return { done: true, data };
|
|
11119
|
+
} catch (readError) {
|
|
11120
|
+
if (isAbortError(readError, signal) || !isWrongPasswordError(readError, entry)) {
|
|
11121
|
+
throw readError;
|
|
11122
|
+
}
|
|
11123
|
+
return { done: false, error: readError };
|
|
11124
|
+
}
|
|
11125
|
+
}
|
|
11126
|
+
}
|
|
11127
|
+
|
|
11128
|
+
function isInvalidPasswordError(error) {
|
|
11129
|
+
return isErrorObject(error) && error.message == ERR_INVALID_PASSWORD;
|
|
11130
|
+
}
|
|
11131
|
+
|
|
11132
|
+
function isWrongPasswordError(error, entry) {
|
|
11133
|
+
return isInvalidPasswordError(error) || (entry.zipCrypto && isErrorObject(error) && FALSE_ACCEPT_ERRORS.has(error.message));
|
|
11134
|
+
}
|
|
11135
|
+
|
|
11136
|
+
function isAbortError(error, signal) {
|
|
11137
|
+
return Boolean(signal && signal.aborted) || (isErrorObject(error) && error.name == ABORT_ERROR_NAME);
|
|
11138
|
+
}
|
|
11139
|
+
|
|
11140
|
+
function getPasswordCandidates(options, passwordState, passwords) {
|
|
11141
|
+
const candidates = [];
|
|
11142
|
+
const { password, rawPassword } = options;
|
|
11143
|
+
if (rawPassword && rawPassword.length) {
|
|
11144
|
+
candidates.push({ key: rawPassword, options: { password: "", rawPassword } });
|
|
11145
|
+
}
|
|
11146
|
+
if (password) {
|
|
11147
|
+
candidates.push(getPasswordCandidate(password));
|
|
11148
|
+
}
|
|
11149
|
+
candidates.push(...passwordState.known);
|
|
11150
|
+
if (passwords) {
|
|
11151
|
+
candidates.push(...passwords.filter(password => password).map(getPasswordCandidate));
|
|
11152
|
+
}
|
|
11153
|
+
return candidates;
|
|
11154
|
+
}
|
|
11155
|
+
|
|
11156
|
+
function getPasswordCandidate(password) {
|
|
11157
|
+
return { key: password, options: { password, rawPassword: EMPTY_RAW_PASSWORD } };
|
|
11158
|
+
}
|
|
11159
|
+
|
|
11160
|
+
function rememberPassword(passwordState, candidate) {
|
|
11161
|
+
const { known } = passwordState;
|
|
11162
|
+
const index = known.findIndex(knownCandidate => knownCandidate.key === candidate.key);
|
|
11163
|
+
if (index != -1) {
|
|
11164
|
+
known.splice(index, 1);
|
|
11165
|
+
}
|
|
11166
|
+
known.unshift(candidate);
|
|
11167
|
+
}
|
|
11168
|
+
|
|
10873
11169
|
function checkPassThroughValue(passThrough) {
|
|
10874
11170
|
if (checkPassThroughOption(passThrough) === PASS_THROUGH_COMPRESSED) {
|
|
10875
11171
|
throw new Error(ERR_UNSUPPORTED_PASS_THROUGH_VALUE);
|
|
@@ -11007,6 +11303,7 @@ function addFileSystemHandle(zipEntry, handle, options) {
|
|
|
11007
11303
|
async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
|
|
11008
11304
|
const { onstart, onprogress, onend } = options;
|
|
11009
11305
|
checkPassThroughValue(options.passThrough);
|
|
11306
|
+
checkPasswordCandidatesOptions(options);
|
|
11010
11307
|
const readerOptions = checkReaderOptions(options.readerOptions);
|
|
11011
11308
|
const abortController = new AbortController();
|
|
11012
11309
|
const { signal } = abortController;
|
|
@@ -11320,4 +11617,4 @@ function decodeMimeTypes(data) {
|
|
|
11320
11617
|
return mimeTypes;
|
|
11321
11618
|
}
|
|
11322
11619
|
|
|
11323
|
-
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, ERR_AMBIGUOUS_ARCHIVE, ERR_ANCESTOR_ENTRY, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_DUPLICATE_IMPORTED_ENTRY, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_HTTP_STATUS, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_BASE_URI, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMMENT_TYPE, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_DATE, ERR_INVALID_DUPLICATES, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_COMMENT_TYPE, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_DATA_TYPE, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_FUNCTION_OPTION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MAX_WORKERS, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_PASS_THROUGH, ERR_INVALID_PASS_THROUGH_VALUE, ERR_INVALID_READER, ERR_INVALID_READER_OPTIONS, ERR_INVALID_SIGNAL, 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_URI, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_PARENT_NOT_DIRECTORY, ERR_READABLE_CONSUMED, ERR_RESERVED_COMPRESSION_METHOD, ERR_ROOT_DIRECTORY_NOT_MOVABLE, ERR_SPLIT_ZIP_FILE, ERR_TARGET_NOT_DIRECTORY, ERR_UNDEFINED_COMPRESSION_METHOD, ERR_UNDEFINED_CRC32, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_UNSUPPORTED_PASS_THROUGH_VALUE, ERR_UNSUPPORTED_SPLIT_USDZ, ERR_UNSUPPORTED_UINT64, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_WRITER_SIZE_NOT_WRITABLE, ERR_ZIP_CRYPTO_LAST_MOD_DATE, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, VERSION, WARNING_APPENDED_DATA, WARNING_CLAMPED_LAST_MODIFICATION_DATE, WARNING_COMPRESSED_PATCHED_DATA, WARNING_COMPRESSION_UNAVAILABLE, WARNING_DUPLICATE_FILENAME, WARNING_MALFORMED_EXTRA_FIELD, WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG, WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD, WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES, WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY, WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY, WARNING_PREPENDED_CENTRAL_DIRECTORY, WARNING_PREPENDED_DATA, WARNING_TRAILING_CENTRAL_DIRECTORY_DATA, WARNING_UNKNOWN_VERSION, WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA, WARNING_UNSORTED_CENTRAL_DIRECTORY, WARNING_WRAPPED_ENTRIES_COUNT, Writer, ZipDirectoryEntry, ZipEntry, ZipFS, ZipFileEntry, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, getRegisteredCodecs, getSupportedCompressionMethods, isZipFile, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|
|
11620
|
+
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, ERR_AMBIGUOUS_ARCHIVE, ERR_ANCESTOR_ENTRY, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_CODEC_OUT_OF_MEMORY, ERR_DUPLICATED_NAME, ERR_DUPLICATE_IMPORTED_ENTRY, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_HTTP_STATUS, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_BASE_URI, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMMENT_TYPE, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_DATE, ERR_INVALID_DUPLICATES, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_COMMENT_TYPE, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_DATA_TYPE, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_FUNCTION_OPTION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MAX_WORKERS, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORDS, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_PASS_THROUGH, ERR_INVALID_PASS_THROUGH_VALUE, ERR_INVALID_READER, ERR_INVALID_READER_OPTIONS, ERR_INVALID_REQUEST_PASSWORD, ERR_INVALID_SIGNAL, 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_URI, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_PARENT_NOT_DIRECTORY, ERR_READABLE_CONSUMED, ERR_RESERVED_COMPRESSION_METHOD, ERR_ROOT_DIRECTORY_NOT_MOVABLE, ERR_SPLIT_ZIP_FILE, ERR_TARGET_NOT_DIRECTORY, ERR_UNDEFINED_COMPRESSION_METHOD, ERR_UNDEFINED_CRC32, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_UNSUPPORTED_PASS_THROUGH_VALUE, ERR_UNSUPPORTED_SPLIT_USDZ, ERR_UNSUPPORTED_UINT64, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_WRITER_SIZE_NOT_WRITABLE, ERR_ZIP_CRYPTO_LAST_MOD_DATE, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, VERSION, WARNING_APPENDED_DATA, WARNING_CLAMPED_LAST_MODIFICATION_DATE, WARNING_COMPRESSED_PATCHED_DATA, WARNING_COMPRESSION_UNAVAILABLE, WARNING_DUPLICATE_FILENAME, WARNING_MALFORMED_EXTRA_FIELD, WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG, WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD, WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES, WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY, WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY, WARNING_PREPENDED_CENTRAL_DIRECTORY, WARNING_PREPENDED_DATA, WARNING_TRAILING_CENTRAL_DIRECTORY_DATA, WARNING_UNKNOWN_VERSION, WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA, WARNING_UNSORTED_CENTRAL_DIRECTORY, WARNING_WRAPPED_ENTRIES_COUNT, Writer, ZipDirectoryEntry, ZipEntry, ZipFS, ZipFileEntry, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, getRegisteredCodecs, getSupportedCompressionMethods, isZipFile, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|