@zip.js/zip.js 2.16.0 → 2.16.1
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 +284 -179
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +108 -61
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +426 -189
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +251 -70
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +426 -189
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +253 -72
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +428 -189
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +110 -63
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +110 -63
- 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 +285 -180
- package/dist/zip.min.js +1 -1
- package/eslint.config.mjs +1 -1
- package/index-native.cjs +253 -72
- package/index-native.min.js +1 -1
- package/index.cjs +428 -189
- package/index.d.cts +117 -16
- package/index.d.ts +117 -16
- package/index.min.js +1 -1
- package/lib/core/streams/aes-crypto-stream.js +60 -17
- package/lib/core/streams/zip-crypto-stream.js +7 -7
- package/lib/core/streams/zip-entry-stream.js +22 -26
- package/lib/core/streams/zlib-wasm/zlib-streams.js +176 -118
- package/lib/core/util/compatible-streams.js +10 -5
- package/lib/core/version.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 +144 -10
- package/lib/core/zip-reader.js +5 -5
- package/lib/core/zip-writer.js +4 -2
- package/package.json +3 -2
package/dist/zip-fs-core.js
CHANGED
|
@@ -223,7 +223,7 @@
|
|
|
223
223
|
const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
|
|
224
224
|
const ERR_INVALID_PASS_THROUGH_VALUE = "Invalid passThrough option (must be a boolean or 'compressed')";
|
|
225
225
|
const ERR_ABORTED = "The operation was aborted";
|
|
226
|
-
const ABORT_ERROR_NAME = "AbortError";
|
|
226
|
+
const ABORT_ERROR_NAME$1 = "AbortError";
|
|
227
227
|
|
|
228
228
|
function checkFunctionOption(value) {
|
|
229
229
|
if (value && typeof value != FUNCTION_TYPE) {
|
|
@@ -241,7 +241,7 @@
|
|
|
241
241
|
|
|
242
242
|
function throwIfAborted(signal) {
|
|
243
243
|
if (signal && signal.aborted) {
|
|
244
|
-
throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
|
|
244
|
+
throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME$1) : signal.reason;
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
|
|
@@ -1283,12 +1283,12 @@
|
|
|
1283
1283
|
class AESDecryptionStream extends TransformStream {
|
|
1284
1284
|
|
|
1285
1285
|
constructor({ password, rawPassword, encryptionStrength, checkPasswordOnly, checkAuthenticationCode = true }) {
|
|
1286
|
+
const aesCrypto = {};
|
|
1286
1287
|
super({
|
|
1287
1288
|
start() {
|
|
1288
|
-
initAesCrypto(
|
|
1289
|
+
initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength);
|
|
1289
1290
|
},
|
|
1290
1291
|
async transform(chunk, controller) {
|
|
1291
|
-
const aesCrypto = this;
|
|
1292
1292
|
const {
|
|
1293
1293
|
password,
|
|
1294
1294
|
strength,
|
|
@@ -1307,6 +1307,9 @@
|
|
|
1307
1307
|
} else {
|
|
1308
1308
|
await ready;
|
|
1309
1309
|
}
|
|
1310
|
+
if (aesCrypto.discarded) {
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1310
1313
|
const output = new Uint8Array(chunk.length - AUTHENTICATION_CODE_LENGTH - ((chunk.length - AUTHENTICATION_CODE_LENGTH) % BLOCK_LENGTH));
|
|
1311
1314
|
controller.enqueue(append(aesCrypto, chunk, output, 0, AUTHENTICATION_CODE_LENGTH, true));
|
|
1312
1315
|
},
|
|
@@ -1315,9 +1318,12 @@
|
|
|
1315
1318
|
engine,
|
|
1316
1319
|
pendingInput,
|
|
1317
1320
|
ready
|
|
1318
|
-
} =
|
|
1321
|
+
} = aesCrypto;
|
|
1319
1322
|
if (engine) {
|
|
1320
1323
|
await ready;
|
|
1324
|
+
if (aesCrypto.discarded) {
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1321
1327
|
const originalAuthenticationCode = subarray(pendingInput, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
|
|
1322
1328
|
const decryptedChunkArray = new Uint8Array(subarray(pendingInput, 0, pendingInput.length - AUTHENTICATION_CODE_LENGTH));
|
|
1323
1329
|
engine.process(decryptedChunkArray, true);
|
|
@@ -1327,27 +1333,26 @@
|
|
|
1327
1333
|
invalidAuthenticationCode |= authenticationCode[indexByte] ^ originalAuthenticationCode[indexByte];
|
|
1328
1334
|
}
|
|
1329
1335
|
if (invalidAuthenticationCode && checkAuthenticationCode) {
|
|
1330
|
-
|
|
1336
|
+
controller.error(new Error(ERR_INVALID_AUTHENTICATION_CODE));
|
|
1337
|
+
return;
|
|
1331
1338
|
}
|
|
1332
1339
|
controller.enqueue(decryptedChunkArray);
|
|
1333
1340
|
}
|
|
1334
|
-
},
|
|
1335
|
-
cancel() {
|
|
1336
|
-
disposeEngine(this);
|
|
1337
1341
|
}
|
|
1338
1342
|
});
|
|
1343
|
+
setDisposingReadable(this, aesCrypto);
|
|
1339
1344
|
}
|
|
1340
1345
|
}
|
|
1341
1346
|
|
|
1342
1347
|
class AESEncryptionStream extends TransformStream {
|
|
1343
1348
|
|
|
1344
1349
|
constructor({ password, rawPassword, encryptionStrength }) {
|
|
1350
|
+
const aesCrypto = {};
|
|
1345
1351
|
super({
|
|
1346
1352
|
start() {
|
|
1347
|
-
initAesCrypto(
|
|
1353
|
+
initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength);
|
|
1348
1354
|
},
|
|
1349
1355
|
async transform(chunk, controller) {
|
|
1350
|
-
const aesCrypto = this;
|
|
1351
1356
|
const {
|
|
1352
1357
|
password,
|
|
1353
1358
|
strength,
|
|
@@ -1361,6 +1366,9 @@
|
|
|
1361
1366
|
} else {
|
|
1362
1367
|
await ready;
|
|
1363
1368
|
}
|
|
1369
|
+
if (aesCrypto.discarded) {
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1364
1372
|
const output = new Uint8Array(preamble.length + chunk.length - (chunk.length % BLOCK_LENGTH));
|
|
1365
1373
|
output.set(preamble, 0);
|
|
1366
1374
|
controller.enqueue(append(aesCrypto, chunk, output, preamble.length, 0, false));
|
|
@@ -1370,19 +1378,20 @@
|
|
|
1370
1378
|
engine,
|
|
1371
1379
|
pendingInput,
|
|
1372
1380
|
ready
|
|
1373
|
-
} =
|
|
1381
|
+
} = aesCrypto;
|
|
1374
1382
|
if (engine) {
|
|
1375
1383
|
await ready;
|
|
1384
|
+
if (aesCrypto.discarded) {
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1376
1387
|
const encryptedChunkArray = new Uint8Array(pendingInput);
|
|
1377
1388
|
engine.process(encryptedChunkArray, false);
|
|
1378
1389
|
const authenticationCode = subarray(engine.digest(), 0, AUTHENTICATION_CODE_LENGTH);
|
|
1379
1390
|
controller.enqueue(concat(encryptedChunkArray, authenticationCode));
|
|
1380
1391
|
}
|
|
1381
|
-
},
|
|
1382
|
-
cancel() {
|
|
1383
|
-
disposeEngine(this);
|
|
1384
1392
|
}
|
|
1385
1393
|
});
|
|
1394
|
+
setDisposingReadable(this, aesCrypto);
|
|
1386
1395
|
}
|
|
1387
1396
|
}
|
|
1388
1397
|
|
|
@@ -1391,7 +1400,37 @@
|
|
|
1391
1400
|
ready: new Promise(resolve => aesCrypto.resolveReady = resolve),
|
|
1392
1401
|
password: encodePassword(password, rawPassword),
|
|
1393
1402
|
strength: encryptionStrength - 1,
|
|
1394
|
-
pendingInput: EMPTY_UINT8_ARRAY
|
|
1403
|
+
pendingInput: EMPTY_UINT8_ARRAY,
|
|
1404
|
+
discarded: false
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
function setDisposingReadable(stream, aesCrypto) {
|
|
1409
|
+
const reader = stream.readable.getReader();
|
|
1410
|
+
const readable = new ReadableStream({
|
|
1411
|
+
async pull(controller) {
|
|
1412
|
+
try {
|
|
1413
|
+
const { value, done } = await reader.read();
|
|
1414
|
+
if (done) {
|
|
1415
|
+
controller.close();
|
|
1416
|
+
} else {
|
|
1417
|
+
controller.enqueue(value);
|
|
1418
|
+
}
|
|
1419
|
+
} catch (error) {
|
|
1420
|
+
disposeEngine(aesCrypto);
|
|
1421
|
+
reader.cancel(error).catch(() => { });
|
|
1422
|
+
throw error;
|
|
1423
|
+
}
|
|
1424
|
+
},
|
|
1425
|
+
cancel(reason) {
|
|
1426
|
+
disposeEngine(aesCrypto);
|
|
1427
|
+
return reader.cancel(reason);
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
Object.defineProperty(stream, "readable", {
|
|
1431
|
+
get() {
|
|
1432
|
+
return readable;
|
|
1433
|
+
}
|
|
1395
1434
|
});
|
|
1396
1435
|
}
|
|
1397
1436
|
|
|
@@ -1424,7 +1463,9 @@
|
|
|
1424
1463
|
}
|
|
1425
1464
|
}
|
|
1426
1465
|
|
|
1427
|
-
function disposeEngine(
|
|
1466
|
+
function disposeEngine(aesCrypto) {
|
|
1467
|
+
const { engine } = aesCrypto;
|
|
1468
|
+
aesCrypto.discarded = true;
|
|
1428
1469
|
if (engine && engine.dispose) {
|
|
1429
1470
|
engine.dispose();
|
|
1430
1471
|
}
|
|
@@ -1441,6 +1482,9 @@
|
|
|
1441
1482
|
const keyLength = KEY_LENGTH[strength];
|
|
1442
1483
|
const compositeKey = await deriveKey(password, salt, keyLength * 2 + PASSWORD_VERIFICATION_LENGTH);
|
|
1443
1484
|
aesCrypto.engine = createEngine(subarray(compositeKey, 0, keyLength), subarray(compositeKey, keyLength, keyLength * 2));
|
|
1485
|
+
if (aesCrypto.discarded) {
|
|
1486
|
+
disposeEngine(aesCrypto);
|
|
1487
|
+
}
|
|
1444
1488
|
return subarray(compositeKey, keyLength * 2);
|
|
1445
1489
|
}
|
|
1446
1490
|
|
|
@@ -1592,11 +1636,11 @@
|
|
|
1592
1636
|
}
|
|
1593
1637
|
|
|
1594
1638
|
function createKeys(target, password, rawPassword) {
|
|
1595
|
-
const
|
|
1639
|
+
const cryptoKeys = [0x12345678, 0x23456789, 0x34567890];
|
|
1596
1640
|
Object.assign(target, {
|
|
1597
|
-
|
|
1598
|
-
crcKey0: new Crc32(
|
|
1599
|
-
crcKey2: new Crc32(
|
|
1641
|
+
cryptoKeys,
|
|
1642
|
+
crcKey0: new Crc32(cryptoKeys[0]),
|
|
1643
|
+
crcKey2: new Crc32(cryptoKeys[2])
|
|
1600
1644
|
});
|
|
1601
1645
|
if (rawPassword) {
|
|
1602
1646
|
for (let index = 0; index < rawPassword.length; index++) {
|
|
@@ -1610,17 +1654,17 @@
|
|
|
1610
1654
|
}
|
|
1611
1655
|
|
|
1612
1656
|
function updateKeys(target, byte) {
|
|
1613
|
-
let [, key1] = target.
|
|
1657
|
+
let [, key1] = target.cryptoKeys;
|
|
1614
1658
|
target.crcKey0.append([byte]);
|
|
1615
1659
|
const key0 = ~target.crcKey0.get();
|
|
1616
1660
|
key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
|
|
1617
1661
|
target.crcKey2.append([key1 >>> 24]);
|
|
1618
1662
|
const key2 = ~target.crcKey2.get();
|
|
1619
|
-
target.
|
|
1663
|
+
target.cryptoKeys = [key0, key1, key2];
|
|
1620
1664
|
}
|
|
1621
1665
|
|
|
1622
1666
|
function getByte(target) {
|
|
1623
|
-
const temp = target.
|
|
1667
|
+
const temp = target.cryptoKeys[2] | 2;
|
|
1624
1668
|
return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
|
|
1625
1669
|
}
|
|
1626
1670
|
|
|
@@ -1668,11 +1712,16 @@
|
|
|
1668
1712
|
const reader = readable.getReader();
|
|
1669
1713
|
return new ReadableStream({
|
|
1670
1714
|
async pull(controller) {
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1715
|
+
try {
|
|
1716
|
+
const { value, done } = await reader.read();
|
|
1717
|
+
if (done) {
|
|
1718
|
+
controller.close();
|
|
1719
|
+
} else {
|
|
1720
|
+
controller.enqueue(value);
|
|
1721
|
+
}
|
|
1722
|
+
} catch (error) {
|
|
1723
|
+
reader.cancel(error).catch(() => { });
|
|
1724
|
+
throw error;
|
|
1676
1725
|
}
|
|
1677
1726
|
},
|
|
1678
1727
|
cancel(reason) {
|
|
@@ -1975,28 +2024,25 @@
|
|
|
1975
2024
|
pump();
|
|
1976
2025
|
return new ReadableStream({
|
|
1977
2026
|
async pull(controller) {
|
|
1978
|
-
let result;
|
|
1979
2027
|
try {
|
|
1980
|
-
|
|
2028
|
+
const { value, done } = await read();
|
|
2029
|
+
if (done) {
|
|
2030
|
+
controller.close();
|
|
2031
|
+
} else {
|
|
2032
|
+
outputLength += value.length;
|
|
2033
|
+
if (outputLength > outputSize) {
|
|
2034
|
+
throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
|
|
2035
|
+
}
|
|
2036
|
+
if (outputCrc32) {
|
|
2037
|
+
outputCrc32.append(value);
|
|
2038
|
+
}
|
|
2039
|
+
controller.enqueue(value);
|
|
2040
|
+
}
|
|
1981
2041
|
} catch (error) {
|
|
2042
|
+
rejectTrailerReady(error);
|
|
2043
|
+
await cancel(reader, error);
|
|
1982
2044
|
throw trailerWritten ? getTrailerError(error) : error;
|
|
1983
2045
|
}
|
|
1984
|
-
const { value, done } = result;
|
|
1985
|
-
if (done) {
|
|
1986
|
-
controller.close();
|
|
1987
|
-
} else {
|
|
1988
|
-
outputLength += value.length;
|
|
1989
|
-
if (outputLength > outputSize) {
|
|
1990
|
-
const error = new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
|
|
1991
|
-
rejectTrailerReady(error);
|
|
1992
|
-
await cancel(reader, error);
|
|
1993
|
-
throw error;
|
|
1994
|
-
}
|
|
1995
|
-
if (outputCrc32) {
|
|
1996
|
-
outputCrc32.append(value);
|
|
1997
|
-
}
|
|
1998
|
-
controller.enqueue(value);
|
|
1999
|
-
}
|
|
2000
2046
|
},
|
|
2001
2047
|
cancel(reason) {
|
|
2002
2048
|
rejectTrailerReady(reason);
|
|
@@ -2275,10 +2321,15 @@
|
|
|
2275
2321
|
const reader = readable.getReader();
|
|
2276
2322
|
return new ReadableStream({
|
|
2277
2323
|
async pull(controller) {
|
|
2278
|
-
let result;
|
|
2279
2324
|
try {
|
|
2280
|
-
|
|
2325
|
+
const { value, done } = await reader.read();
|
|
2326
|
+
if (done) {
|
|
2327
|
+
controller.close();
|
|
2328
|
+
} else {
|
|
2329
|
+
controller.enqueue(value);
|
|
2330
|
+
}
|
|
2281
2331
|
} catch (error) {
|
|
2332
|
+
await cancel(reader, error);
|
|
2282
2333
|
if (error && error.message) {
|
|
2283
2334
|
throw error;
|
|
2284
2335
|
}
|
|
@@ -2286,12 +2337,6 @@
|
|
|
2286
2337
|
mappedError.cause = error;
|
|
2287
2338
|
throw mappedError;
|
|
2288
2339
|
}
|
|
2289
|
-
const { value, done } = result;
|
|
2290
|
-
if (done) {
|
|
2291
|
-
controller.close();
|
|
2292
|
-
} else {
|
|
2293
|
-
controller.enqueue(value);
|
|
2294
|
-
}
|
|
2295
2340
|
},
|
|
2296
2341
|
cancel(reason) {
|
|
2297
2342
|
return reader.cancel(reason);
|
|
@@ -5366,8 +5411,8 @@
|
|
|
5366
5411
|
const passThroughCompression = Boolean(passThrough);
|
|
5367
5412
|
const passThroughEncryption = passThrough === true;
|
|
5368
5413
|
checkPasswordOption(password, rawPassword);
|
|
5369
|
-
password = password && password.length
|
|
5370
|
-
rawPassword = rawPassword && rawPassword.length
|
|
5414
|
+
password = password && password.length ? password : UNDEFINED_VALUE;
|
|
5415
|
+
rawPassword = rawPassword && rawPassword.length ? rawPassword : UNDEFINED_VALUE;
|
|
5371
5416
|
if (extraFieldAES) {
|
|
5372
5417
|
if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
|
|
5373
5418
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
@@ -6128,7 +6173,7 @@
|
|
|
6128
6173
|
async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDataSize) {
|
|
6129
6174
|
const { size } = reader;
|
|
6130
6175
|
const anchoredLength = Math.min(size, END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS);
|
|
6131
|
-
const remoteProbeBudget = {
|
|
6176
|
+
const remoteProbeBudget = { remaining: MAX_END_OF_CENTRAL_DIR_PROBES };
|
|
6132
6177
|
let endOfDirectoryInfo;
|
|
6133
6178
|
let plausibleEndOfDirectoryInfo;
|
|
6134
6179
|
let endOfDirectoryReachingEndCount = 0;
|
|
@@ -6221,8 +6266,8 @@
|
|
|
6221
6266
|
if (signatureOffset >= anchoredOffset) {
|
|
6222
6267
|
return getUint32$1(view, signatureOffset - anchoredOffset);
|
|
6223
6268
|
}
|
|
6224
|
-
if (remoteProbeBudget.
|
|
6225
|
-
remoteProbeBudget.
|
|
6269
|
+
if (remoteProbeBudget.remaining > 0) {
|
|
6270
|
+
remoteProbeBudget.remaining--;
|
|
6226
6271
|
const signatureArray = await readUint8Array(reader, signatureOffset, 4);
|
|
6227
6272
|
return getUint32$1(getDataView(signatureArray), 0);
|
|
6228
6273
|
}
|
|
@@ -7138,9 +7183,11 @@
|
|
|
7138
7183
|
const passThrough = checkPassThroughOption(getOptionValue(zipWriter, options, OPTION_PASS_THROUGH));
|
|
7139
7184
|
const passThroughCompression = Boolean(passThrough);
|
|
7140
7185
|
const passThroughEncryption = passThrough === true;
|
|
7141
|
-
|
|
7142
|
-
|
|
7186
|
+
let password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
7187
|
+
let rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
7143
7188
|
checkPasswordOption(password, rawPassword);
|
|
7189
|
+
password = password && password.length ? password : UNDEFINED_VALUE;
|
|
7190
|
+
rawPassword = rawPassword && rawPassword.length ? rawPassword : UNDEFINED_VALUE;
|
|
7144
7191
|
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
7145
7192
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
7146
7193
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
@@ -8936,7 +8983,7 @@
|
|
|
8936
8983
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
8937
8984
|
*/
|
|
8938
8985
|
|
|
8939
|
-
const VERSION = "2.16.
|
|
8986
|
+
const VERSION = "2.16.1";
|
|
8940
8987
|
|
|
8941
8988
|
/*
|
|
8942
8989
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
@@ -9429,7 +9476,11 @@
|
|
|
9429
9476
|
const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
|
|
9430
9477
|
const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
|
|
9431
9478
|
const ERR_UNSUPPORTED_PASS_THROUGH_VALUE = "The 'compressed' passThrough option is only supported by Entry#getData() and ZipWriter#add()";
|
|
9479
|
+
const ERR_INVALID_PASSWORDS = "Invalid passwords option (must be an array of strings)";
|
|
9480
|
+
const ERR_INVALID_REQUEST_PASSWORD = "Invalid requestPassword option (must be a function returning a string or undefined)";
|
|
9432
9481
|
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
9482
|
+
const ABORT_ERROR_NAME = "AbortError";
|
|
9483
|
+
const EMPTY_RAW_PASSWORD = new Uint8Array(0);
|
|
9433
9484
|
|
|
9434
9485
|
class ZipEntry {
|
|
9435
9486
|
|
|
@@ -9802,8 +9853,10 @@
|
|
|
9802
9853
|
zipReader = new ZipReader(reader, options);
|
|
9803
9854
|
}
|
|
9804
9855
|
checkPassThroughValue(options.passThrough);
|
|
9856
|
+
checkPasswordCandidatesOptions(options);
|
|
9805
9857
|
const duplicates = checkDuplicatesOption(options.duplicates);
|
|
9806
9858
|
const importedEntries = [];
|
|
9859
|
+
const passwordState = { known: [] };
|
|
9807
9860
|
const entries = await zipReader.getEntries(options);
|
|
9808
9861
|
for (const entry of entries) {
|
|
9809
9862
|
let parent = this;
|
|
@@ -9848,7 +9901,7 @@
|
|
|
9848
9901
|
}
|
|
9849
9902
|
importedEntries.push(addChild(parent, name, {
|
|
9850
9903
|
data: entry,
|
|
9851
|
-
Reader: getZipBlobReader(Object.assign({}, options)),
|
|
9904
|
+
Reader: getZipBlobReader(Object.assign({}, options), passwordState),
|
|
9852
9905
|
uncompressedSize: options.passThrough ? entry.compressedSize : entry.uncompressedSize,
|
|
9853
9906
|
passThrough: options.passThrough
|
|
9854
9907
|
}));
|
|
@@ -10177,7 +10230,7 @@
|
|
|
10177
10230
|
};
|
|
10178
10231
|
}
|
|
10179
10232
|
|
|
10180
|
-
function getZipBlobReader(options) {
|
|
10233
|
+
function getZipBlobReader(options, passwordState) {
|
|
10181
10234
|
return class extends Reader {
|
|
10182
10235
|
|
|
10183
10236
|
constructor(entry, options = {}) {
|
|
@@ -10190,12 +10243,12 @@
|
|
|
10190
10243
|
const zipBlobReader = this;
|
|
10191
10244
|
const readerOptions = Object.assign({}, options, zipBlobReader.options);
|
|
10192
10245
|
const { checkOverlappingEntry, checkOverlappingEntryOnly } = readerOptions;
|
|
10193
|
-
const data = await zipBlobReader.entry
|
|
10246
|
+
const data = await readEntryData(zipBlobReader.entry, Object.assign(readerOptions, {
|
|
10194
10247
|
checkPasswordOnly: false,
|
|
10195
10248
|
checkOverlappingEntry: checkOverlappingEntryOnly || checkOverlappingEntry,
|
|
10196
10249
|
checkOverlappingEntryOnly: false,
|
|
10197
10250
|
preventClose: false
|
|
10198
|
-
}));
|
|
10251
|
+
}), passwordState);
|
|
10199
10252
|
zipBlobReader.data = data;
|
|
10200
10253
|
zipBlobReader.blobReader = new BlobReader(data);
|
|
10201
10254
|
zipBlobReader.size = data.size;
|
|
@@ -10257,10 +10310,9 @@
|
|
|
10257
10310
|
await initStream(reader);
|
|
10258
10311
|
} catch (error) {
|
|
10259
10312
|
try {
|
|
10313
|
+
error.entry = child;
|
|
10260
10314
|
error.entryId = child.id;
|
|
10261
|
-
error.
|
|
10262
|
-
entry: child
|
|
10263
|
-
};
|
|
10315
|
+
error.entryName = child.getRelativeName(entry);
|
|
10264
10316
|
} catch {
|
|
10265
10317
|
// ignored
|
|
10266
10318
|
}
|
|
@@ -10352,10 +10404,136 @@
|
|
|
10352
10404
|
}
|
|
10353
10405
|
if (readerOptions) {
|
|
10354
10406
|
checkPassThroughValue(readerOptions.passThrough);
|
|
10407
|
+
checkPasswordCandidatesOptions(readerOptions);
|
|
10355
10408
|
}
|
|
10356
10409
|
return readerOptions;
|
|
10357
10410
|
}
|
|
10358
10411
|
|
|
10412
|
+
function checkPasswordCandidatesOptions(options) {
|
|
10413
|
+
const { passwords, requestPassword } = options;
|
|
10414
|
+
if (passwords && (!Array.isArray(passwords) || passwords.some(password => typeof password != STRING_TYPE))) {
|
|
10415
|
+
throw new Error(ERR_INVALID_PASSWORDS);
|
|
10416
|
+
}
|
|
10417
|
+
if (requestPassword && typeof requestPassword != FUNCTION_TYPE) {
|
|
10418
|
+
throw new Error(ERR_INVALID_REQUEST_PASSWORD);
|
|
10419
|
+
}
|
|
10420
|
+
}
|
|
10421
|
+
|
|
10422
|
+
async function readEntryData(entry, options, passwordState) {
|
|
10423
|
+
checkPasswordCandidatesOptions(options);
|
|
10424
|
+
const { passwords, requestPassword, signal } = options;
|
|
10425
|
+
options = Object.assign({}, options);
|
|
10426
|
+
delete options.passwords;
|
|
10427
|
+
delete options.requestPassword;
|
|
10428
|
+
if (!entry.encrypted || options.passThrough || (!passwords && !requestPassword)) {
|
|
10429
|
+
return entry.getData(new BlobWriter(), options);
|
|
10430
|
+
}
|
|
10431
|
+
const tried = new Set();
|
|
10432
|
+
let error;
|
|
10433
|
+
while (true) {
|
|
10434
|
+
for (const candidate of getPasswordCandidates(options, passwordState, passwords)) {
|
|
10435
|
+
if (!tried.has(candidate.key)) {
|
|
10436
|
+
const result = await tryPasswordCandidate(candidate);
|
|
10437
|
+
if (result.done) {
|
|
10438
|
+
return result.data;
|
|
10439
|
+
}
|
|
10440
|
+
error = result.error;
|
|
10441
|
+
}
|
|
10442
|
+
}
|
|
10443
|
+
if (!requestPassword) {
|
|
10444
|
+
break;
|
|
10445
|
+
}
|
|
10446
|
+
if (passwordState.pendingPrompt) {
|
|
10447
|
+
await passwordState.pendingPrompt;
|
|
10448
|
+
continue;
|
|
10449
|
+
}
|
|
10450
|
+
let release;
|
|
10451
|
+
passwordState.pendingPrompt = new Promise(resolve => release = resolve);
|
|
10452
|
+
try {
|
|
10453
|
+
const answer = await requestPassword(entry, error);
|
|
10454
|
+
if (answer === UNDEFINED_VALUE || answer === null) {
|
|
10455
|
+
break;
|
|
10456
|
+
}
|
|
10457
|
+
// deno-lint-ignore valid-typeof
|
|
10458
|
+
if (typeof answer != STRING_TYPE) {
|
|
10459
|
+
throw new Error(ERR_INVALID_REQUEST_PASSWORD);
|
|
10460
|
+
}
|
|
10461
|
+
const result = await tryPasswordCandidate(getPasswordCandidate(answer));
|
|
10462
|
+
if (result.done) {
|
|
10463
|
+
return result.data;
|
|
10464
|
+
}
|
|
10465
|
+
error = result.error;
|
|
10466
|
+
} finally {
|
|
10467
|
+
passwordState.pendingPrompt = UNDEFINED_VALUE;
|
|
10468
|
+
release();
|
|
10469
|
+
}
|
|
10470
|
+
}
|
|
10471
|
+
throw new Error(tried.size ? ERR_INVALID_PASSWORD : ERR_ENCRYPTED);
|
|
10472
|
+
|
|
10473
|
+
async function tryPasswordCandidate(candidate) {
|
|
10474
|
+
tried.add(candidate.key);
|
|
10475
|
+
const candidateOptions = Object.assign({}, options, candidate.options);
|
|
10476
|
+
if (entry.zipCrypto) {
|
|
10477
|
+
candidateOptions.checkCrc32 = true;
|
|
10478
|
+
try {
|
|
10479
|
+
await entry.getData(null, Object.assign({}, candidateOptions, { checkPasswordOnly: true }));
|
|
10480
|
+
} catch (probeError) {
|
|
10481
|
+
if (isInvalidPasswordError(probeError)) {
|
|
10482
|
+
return { done: false, error: probeError };
|
|
10483
|
+
}
|
|
10484
|
+
throw probeError;
|
|
10485
|
+
}
|
|
10486
|
+
}
|
|
10487
|
+
try {
|
|
10488
|
+
const data = await entry.getData(new BlobWriter(), candidateOptions);
|
|
10489
|
+
rememberPassword(passwordState, candidate);
|
|
10490
|
+
return { done: true, data };
|
|
10491
|
+
} catch (readError) {
|
|
10492
|
+
if (isAbortError(readError, signal) || (!entry.zipCrypto && !isInvalidPasswordError(readError))) {
|
|
10493
|
+
throw readError;
|
|
10494
|
+
}
|
|
10495
|
+
return { done: false, error: readError };
|
|
10496
|
+
}
|
|
10497
|
+
}
|
|
10498
|
+
}
|
|
10499
|
+
|
|
10500
|
+
function isInvalidPasswordError(error) {
|
|
10501
|
+
return isErrorObject(error) && error.message == ERR_INVALID_PASSWORD;
|
|
10502
|
+
}
|
|
10503
|
+
|
|
10504
|
+
function isAbortError(error, signal) {
|
|
10505
|
+
return Boolean(signal && signal.aborted) || (isErrorObject(error) && error.name == ABORT_ERROR_NAME);
|
|
10506
|
+
}
|
|
10507
|
+
|
|
10508
|
+
function getPasswordCandidates(options, passwordState, passwords) {
|
|
10509
|
+
const candidates = [];
|
|
10510
|
+
const { password, rawPassword } = options;
|
|
10511
|
+
if (rawPassword && rawPassword.length) {
|
|
10512
|
+
candidates.push({ key: rawPassword, options: { password: "", rawPassword } });
|
|
10513
|
+
}
|
|
10514
|
+
if (password) {
|
|
10515
|
+
candidates.push(getPasswordCandidate(password));
|
|
10516
|
+
}
|
|
10517
|
+
candidates.push(...passwordState.known);
|
|
10518
|
+
if (passwords) {
|
|
10519
|
+
candidates.push(...passwords.filter(password => password).map(getPasswordCandidate));
|
|
10520
|
+
}
|
|
10521
|
+
return candidates;
|
|
10522
|
+
}
|
|
10523
|
+
|
|
10524
|
+
function getPasswordCandidate(password) {
|
|
10525
|
+
return { key: password, options: { password, rawPassword: EMPTY_RAW_PASSWORD } };
|
|
10526
|
+
}
|
|
10527
|
+
|
|
10528
|
+
function rememberPassword(passwordState, candidate) {
|
|
10529
|
+
const { known } = passwordState;
|
|
10530
|
+
const index = known.findIndex(knownCandidate => knownCandidate.key === candidate.key);
|
|
10531
|
+
if (index != -1) {
|
|
10532
|
+
known.splice(index, 1);
|
|
10533
|
+
}
|
|
10534
|
+
known.unshift(candidate);
|
|
10535
|
+
}
|
|
10536
|
+
|
|
10359
10537
|
function checkPassThroughValue(passThrough) {
|
|
10360
10538
|
if (checkPassThroughOption(passThrough) === PASS_THROUGH_COMPRESSED) {
|
|
10361
10539
|
throw new Error(ERR_UNSUPPORTED_PASS_THROUGH_VALUE);
|
|
@@ -10493,6 +10671,7 @@
|
|
|
10493
10671
|
async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
|
|
10494
10672
|
const { onstart, onprogress, onend } = options;
|
|
10495
10673
|
checkPassThroughValue(options.passThrough);
|
|
10674
|
+
checkPasswordCandidatesOptions(options);
|
|
10496
10675
|
const readerOptions = checkReaderOptions(options.readerOptions);
|
|
10497
10676
|
const abortController = new AbortController();
|
|
10498
10677
|
const { signal } = abortController;
|
|
@@ -10791,11 +10970,13 @@
|
|
|
10791
10970
|
exports.ERR_INVALID_MSDOS_ATTRIBUTES = ERR_INVALID_MSDOS_ATTRIBUTES;
|
|
10792
10971
|
exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
|
|
10793
10972
|
exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
|
|
10973
|
+
exports.ERR_INVALID_PASSWORDS = ERR_INVALID_PASSWORDS;
|
|
10794
10974
|
exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
|
|
10795
10975
|
exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
|
|
10796
10976
|
exports.ERR_INVALID_PASS_THROUGH_VALUE = ERR_INVALID_PASS_THROUGH_VALUE;
|
|
10797
10977
|
exports.ERR_INVALID_READER = ERR_INVALID_READER;
|
|
10798
10978
|
exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
|
|
10979
|
+
exports.ERR_INVALID_REQUEST_PASSWORD = ERR_INVALID_REQUEST_PASSWORD;
|
|
10799
10980
|
exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
|
|
10800
10981
|
exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
|
|
10801
10982
|
exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
|