@zip.js/zip.js 2.9.0 → 2.11.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/README.md +40 -0
- package/deno.json +1 -1
- package/dist/zip-core-external.js +17 -46
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +16 -46
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +170 -88
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +171 -88
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +170 -88
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +174 -91
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +175 -92
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +18 -48
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-module.wasm +0 -0
- package/dist/zip-native.js +19 -49
- 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 +20 -50
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +174 -91
- package/index-native.min.js +1 -1
- package/index.cjs +175 -92
- package/index.d.cts +92 -44
- package/index.d.ts +92 -44
- package/index.min.js +1 -1
- package/lib/core/codec-pool.js +0 -2
- package/lib/core/codec-registry.js +2 -0
- package/lib/core/streams/codec-stream.js +0 -2
- package/lib/core/streams/common-crypto.js +1 -3
- package/lib/core/streams/zip-entry-stream.js +2 -5
- package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
- package/lib/core/streams/zlib-wasm/zlib-streams.js +1 -1
- package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
- package/lib/core/util/decode-cp437.js +4 -11
- 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-entry.js +0 -6
- package/lib/core/zip-fs.js +155 -44
- package/lib/core/zip-reader.js +1 -6
- package/lib/core/zip-writer.js +4 -19
- package/lib/core/zlib-streams-inline.js +1 -1
- package/lib/zip-core-reader.js +0 -1
- package/package.json +1 -1
|
@@ -1488,8 +1488,7 @@ misc.hmacSha1 = class {
|
|
|
1488
1488
|
const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != UNDEFINED_TYPE && typeof crypto.getRandomValues == FUNCTION_TYPE;
|
|
1489
1489
|
|
|
1490
1490
|
const ERR_INVALID_PASSWORD = "Invalid password";
|
|
1491
|
-
const
|
|
1492
|
-
const ERR_INVALID_AUTHENTICATION_CODE = ERR_INVALID_SIGNATURE;
|
|
1491
|
+
const ERR_INVALID_AUTHENTICATION_CODE = "Invalid authentication code";
|
|
1493
1492
|
const ERR_ABORT_CHECK_PASSWORD = "zipjs-abort-check-password";
|
|
1494
1493
|
const ERR_UNSUPPORTED_CRYPTO_API = "Crypto API not supported";
|
|
1495
1494
|
|
|
@@ -2063,6 +2062,7 @@ function toCompatibleWritable(writable) {
|
|
|
2063
2062
|
const ERR_INVALID_CODEC_DEFINITION = "Invalid codec definition";
|
|
2064
2063
|
const ERR_RESERVED_COMPRESSION_METHOD = "Reserved compression method";
|
|
2065
2064
|
const ERR_INVALID_CODEC_MODULE = "Invalid codec module";
|
|
2065
|
+
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
2066
2066
|
|
|
2067
2067
|
const RESERVED_COMPRESSION_METHODS = [
|
|
2068
2068
|
COMPRESSION_METHOD_STORE,
|
|
@@ -2162,8 +2162,7 @@ async function ensureCodecStreams(format, codecURI) {
|
|
|
2162
2162
|
|
|
2163
2163
|
const ERR_INVALID_UNCOMPRESSED_SIZE = "Invalid uncompressed size";
|
|
2164
2164
|
const ERR_INVALID_COMPRESSED_DATA = "Invalid compressed data";
|
|
2165
|
-
const ERR_INVALID_CRC32 =
|
|
2166
|
-
const ERR_UNSUPPORTED_COMPRESSION$2 = "Compression method not supported";
|
|
2165
|
+
const ERR_INVALID_CRC32 = "Invalid CRC32";
|
|
2167
2166
|
const FORMAT_DEFLATE_RAW$1 = "deflate-raw";
|
|
2168
2167
|
const FORMAT_DEFLATE64_RAW$1 = "deflate64-raw";
|
|
2169
2168
|
const FORMAT_GZIP$1 = "gzip";
|
|
@@ -2431,7 +2430,7 @@ function setReadable(stream, readable, flush) {
|
|
|
2431
2430
|
|
|
2432
2431
|
function createCodecStream(CodecStreamClass, format, options) {
|
|
2433
2432
|
if (!CodecStreamClass) {
|
|
2434
|
-
throw new Error(ERR_UNSUPPORTED_COMPRESSION
|
|
2433
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
2435
2434
|
}
|
|
2436
2435
|
return new CodecStreamClass(format, options);
|
|
2437
2436
|
}
|
|
@@ -3506,21 +3505,14 @@ async function terminateWorkers() {
|
|
|
3506
3505
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3507
3506
|
*/
|
|
3508
3507
|
|
|
3509
|
-
/* global TextDecoder */
|
|
3510
|
-
|
|
3511
3508
|
const CP437 = "\0\u263A\u263B\u2665\u2666\u2663\u2660\u2022\u25D8\u25CB\u25D9\u2642\u2640\u266A\u266B\u263C\u25BA\u25C4\u2195\u203C\u00B6\u00A7\u25AC\u21A8\u2191\u2193\u2192\u2190\u221F\u2194\u25B2\u25BC !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\u00C7\u00FC\u00E9\u00E2\u00E4\u00E0\u00E5\u00E7\u00EA\u00EB\u00E8\u00EF\u00EE\u00EC\u00C4\u00C5\u00C9\u00E6\u00C6\u00F4\u00F6\u00F2\u00FB\u00F9\u00FF\u00D6\u00DC\u00A2\u00A3\u00A5\u20A7\u0192\u00E1\u00ED\u00F3\u00FA\u00F1\u00D1\u00AA\u00BA\u00BF\u2310\u00AC\u00BD\u00BC\u00A1\u00AB\u00BB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\u00DF\u0393\u03C0\u03A3\u03C3\u00B5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\u00B1\u2265\u2264\u2320\u2321\u00F7\u2248\u00B0\u2219\u00B7\u221A\u207F\u00B2\u25A0\u00A0".split("");
|
|
3512
|
-
const VALID_CP437 = CP437.length == 256;
|
|
3513
3509
|
|
|
3514
3510
|
function decodeCP437(stringValue) {
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
result += CP437[stringValue[indexCharacter]];
|
|
3519
|
-
}
|
|
3520
|
-
return result;
|
|
3521
|
-
} else {
|
|
3522
|
-
return new TextDecoder().decode(stringValue);
|
|
3511
|
+
let result = "";
|
|
3512
|
+
for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
|
|
3513
|
+
result += CP437[stringValue[indexCharacter]];
|
|
3523
3514
|
}
|
|
3515
|
+
return result;
|
|
3524
3516
|
}
|
|
3525
3517
|
|
|
3526
3518
|
/*
|
|
@@ -4606,8 +4598,6 @@ const PROPERTY_NAME_CREATION_DATE = "creationDate";
|
|
|
4606
4598
|
const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
|
|
4607
4599
|
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES = "internalFileAttributes";
|
|
4608
4600
|
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttributes";
|
|
4609
|
-
const PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES = "internalFileAttribute";
|
|
4610
|
-
const PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttribute";
|
|
4611
4601
|
const PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW = "msdosAttributesRaw";
|
|
4612
4602
|
const PROPERTY_NAME_MSDOS_ATTRIBUTES = "msdosAttributes";
|
|
4613
4603
|
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
@@ -4666,8 +4656,6 @@ const PROPERTY_NAMES = [
|
|
|
4666
4656
|
PROPERTY_NAME_DISK_NUMBER_START,
|
|
4667
4657
|
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
|
|
4668
4658
|
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
|
|
4669
|
-
PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES,
|
|
4670
|
-
PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES,
|
|
4671
4659
|
PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW,
|
|
4672
4660
|
PROPERTY_NAME_MSDOS_ATTRIBUTES,
|
|
4673
4661
|
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
@@ -4755,7 +4743,6 @@ const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
|
|
|
4755
4743
|
const ERR_EXTRAFIELD_ZIP64_NOT_FOUND = "Zip64 extra field not found";
|
|
4756
4744
|
const ERR_ENCRYPTED = "File contains encrypted entry";
|
|
4757
4745
|
const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
|
|
4758
|
-
const ERR_UNSUPPORTED_COMPRESSION$1 = "Compression method not supported";
|
|
4759
4746
|
const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
4760
4747
|
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
4761
4748
|
const ERR_ENTRY_DATA_OUT_OF_BOUNDS = "Entry data out of bounds";
|
|
@@ -5136,8 +5123,6 @@ class ZipReader {
|
|
|
5136
5123
|
sticky,
|
|
5137
5124
|
symlink,
|
|
5138
5125
|
unixExternalUpper,
|
|
5139
|
-
internalFileAttribute: fileEntry.internalFileAttributes,
|
|
5140
|
-
externalFileAttribute: fileEntry.externalFileAttributes,
|
|
5141
5126
|
executable,
|
|
5142
5127
|
directory: modeIsDir || upperIsDir || (msDosCompatible && msdosAttributes.directory) || fileEntry.filename.endsWith(DIRECTORY_SIGNATURE),
|
|
5143
5128
|
zipCrypto: fileEntry.encrypted && !fileEntry.extraFieldAES
|
|
@@ -5336,7 +5321,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5336
5321
|
rawPassword = rawPassword && rawPassword.length && rawPassword;
|
|
5337
5322
|
if (extraFieldAES) {
|
|
5338
5323
|
if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
|
|
5339
|
-
throw new Error(ERR_UNSUPPORTED_COMPRESSION
|
|
5324
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
5340
5325
|
}
|
|
5341
5326
|
}
|
|
5342
5327
|
if (dataArray.length < HEADER_SIZE || getUint32$1(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
@@ -5392,7 +5377,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5392
5377
|
}
|
|
5393
5378
|
const registeredCodec = passThrough ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
5394
5379
|
if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64 && !registeredCodec && !passThrough) {
|
|
5395
|
-
throw new Error(ERR_UNSUPPORTED_COMPRESSION
|
|
5380
|
+
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
5396
5381
|
}
|
|
5397
5382
|
if (encrypted) {
|
|
5398
5383
|
if (!zipCrypto && (extraFieldAES.strength < 1 || extraFieldAES.strength > 3)) {
|
|
@@ -6244,14 +6229,13 @@ var zipReader = /*#__PURE__*/Object.freeze({
|
|
|
6244
6229
|
ERR_INVALID_FILENAME_VALIDATION: ERR_INVALID_FILENAME_VALIDATION,
|
|
6245
6230
|
ERR_INVALID_MAX_APPENDED_DATA_SIZE: ERR_INVALID_MAX_APPENDED_DATA_SIZE,
|
|
6246
6231
|
ERR_INVALID_PASSWORD: ERR_INVALID_PASSWORD,
|
|
6247
|
-
ERR_INVALID_SIGNATURE: ERR_INVALID_SIGNATURE,
|
|
6248
6232
|
ERR_INVALID_STRICTNESS: ERR_INVALID_STRICTNESS,
|
|
6249
6233
|
ERR_INVALID_UNCOMPRESSED_SIZE: ERR_INVALID_UNCOMPRESSED_SIZE,
|
|
6250
6234
|
ERR_LOCAL_FILE_HEADER_NOT_FOUND: ERR_LOCAL_FILE_HEADER_NOT_FOUND,
|
|
6251
6235
|
ERR_OVERLAPPING_ENTRY: ERR_OVERLAPPING_ENTRY,
|
|
6252
6236
|
ERR_SPLIT_ZIP_FILE: ERR_SPLIT_ZIP_FILE,
|
|
6253
6237
|
ERR_UNSAFE_FILENAME: ERR_UNSAFE_FILENAME,
|
|
6254
|
-
ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION
|
|
6238
|
+
ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION,
|
|
6255
6239
|
ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
|
|
6256
6240
|
ERR_UNSUPPORTED_UINT64: ERR_UNSUPPORTED_UINT64,
|
|
6257
6241
|
ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
|
|
@@ -6319,7 +6303,6 @@ const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
|
|
|
6319
6303
|
const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
|
|
6320
6304
|
const ERR_INVALID_EXTRAFIELD_DATA_TYPE = "Invalid extra field data (must be a Uint8Array)";
|
|
6321
6305
|
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
6322
|
-
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
6323
6306
|
const MIN_UNIX_TIME = -2147483648;
|
|
6324
6307
|
const MAX_UNIX_TIME = 2147483647;
|
|
6325
6308
|
const MIN_NTFS_TIME = BigInt(0);
|
|
@@ -6759,9 +6742,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
6759
6742
|
Object.assign(fileEntry, {
|
|
6760
6743
|
name,
|
|
6761
6744
|
comment,
|
|
6762
|
-
extraField
|
|
6763
|
-
[PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES]: fileEntry.internalFileAttributes,
|
|
6764
|
-
[PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES]: fileEntry.externalFileAttributes
|
|
6745
|
+
extraField
|
|
6765
6746
|
});
|
|
6766
6747
|
return new Entry(fileEntry);
|
|
6767
6748
|
}
|
|
@@ -6808,7 +6789,7 @@ function resolveAttributes(zipWriter, name, options) {
|
|
|
6808
6789
|
if (versionMadeBy > MAX_16_BITS) {
|
|
6809
6790
|
throw new Error(ERR_INVALID_VERSION);
|
|
6810
6791
|
}
|
|
6811
|
-
let externalFileAttributes =
|
|
6792
|
+
let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES);
|
|
6812
6793
|
const externalFileAttributesProvided = externalFileAttributes !== UNDEFINED_VALUE;
|
|
6813
6794
|
if (!externalFileAttributesProvided) {
|
|
6814
6795
|
externalFileAttributes = 0;
|
|
@@ -6918,7 +6899,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6918
6899
|
const rawLastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE);
|
|
6919
6900
|
const lastAccessDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
6920
6901
|
const creationDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
6921
|
-
const internalFileAttributes =
|
|
6902
|
+
const internalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, 0);
|
|
6922
6903
|
const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
|
|
6923
6904
|
const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
6924
6905
|
const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
@@ -8387,16 +8368,6 @@ function getFunctionOptionValue(zipWriter, options, name) {
|
|
|
8387
8368
|
return checkFunctionOption(getOptionValue(zipWriter, options, name));
|
|
8388
8369
|
}
|
|
8389
8370
|
|
|
8390
|
-
function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
|
|
8391
|
-
const value = getAliasedValue(options, name, deprecatedName);
|
|
8392
|
-
const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
|
|
8393
|
-
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
8394
|
-
}
|
|
8395
|
-
|
|
8396
|
-
function getAliasedValue(options, name, deprecatedName) {
|
|
8397
|
-
return options[name] === UNDEFINED_VALUE ? options[deprecatedName] : options[name];
|
|
8398
|
-
}
|
|
8399
|
-
|
|
8400
8371
|
function getNumberOptionValue(zipWriter, options, name, defaultValue) {
|
|
8401
8372
|
return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
|
|
8402
8373
|
}
|
|
@@ -8655,7 +8626,7 @@ function formatSupported(StreamClass, format) {
|
|
|
8655
8626
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
8656
8627
|
*/
|
|
8657
8628
|
|
|
8658
|
-
const VERSION = "2.
|
|
8629
|
+
const VERSION = "2.11.0";
|
|
8659
8630
|
|
|
8660
8631
|
/*
|
|
8661
8632
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
@@ -9257,7 +9228,7 @@ function _make(isCompress, type, options = {}) {
|
|
|
9257
9228
|
}
|
|
9258
9229
|
}
|
|
9259
9230
|
const consumed = last_consumed(this.streamHandle);
|
|
9260
|
-
if (consumed === 0) {
|
|
9231
|
+
if (consumed === 0 && prod === 0) {
|
|
9261
9232
|
break;
|
|
9262
9233
|
}
|
|
9263
9234
|
offset += consumed;
|
|
@@ -9519,7 +9490,14 @@ configureExternalAssets();
|
|
|
9519
9490
|
|
|
9520
9491
|
|
|
9521
9492
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
9493
|
+
const ERR_DUPLICATE_IMPORTED_ENTRY = "Duplicate entry filename in the imported zip file";
|
|
9494
|
+
const ERR_INVALID_DUPLICATES = "Invalid duplicates option (must be \"throw\", \"keep-first\" or \"keep-last\")";
|
|
9495
|
+
const ERR_ANCESTOR_ENTRY = "Entry is a ancestor of target entry";
|
|
9522
9496
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
9497
|
+
const DUPLICATES_THROW = "throw";
|
|
9498
|
+
const DUPLICATES_KEEP_FIRST = "keep-first";
|
|
9499
|
+
const DUPLICATES_KEEP_LAST = "keep-last";
|
|
9500
|
+
const DUPLICATES_VALUES = new Set([DUPLICATES_THROW, DUPLICATES_KEEP_FIRST, DUPLICATES_KEEP_LAST]);
|
|
9523
9501
|
const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
|
|
9524
9502
|
const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
|
|
9525
9503
|
const ERR_ZIP_CRYPTO_LAST_MOD_DATE = "The last modification date of an entry encrypted with ZipCrypto cannot be changed when passThrough is set";
|
|
@@ -9596,12 +9574,26 @@ class ZipEntry {
|
|
|
9596
9574
|
}
|
|
9597
9575
|
|
|
9598
9576
|
rename(name) {
|
|
9599
|
-
const
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9577
|
+
const zipEntry = this;
|
|
9578
|
+
let parent = zipEntry.parent;
|
|
9579
|
+
if (parent) {
|
|
9580
|
+
const path = splitPath(name);
|
|
9581
|
+
if (path) {
|
|
9582
|
+
name = path.pop();
|
|
9583
|
+
parent = getPathParent(parent, path, zipEntry);
|
|
9584
|
+
}
|
|
9585
|
+
const existingChild = parent.getChildByName(name);
|
|
9586
|
+
if (existingChild && existingChild != zipEntry) {
|
|
9587
|
+
throw new Error(ERR_ENTRY_EXISTS);
|
|
9588
|
+
}
|
|
9589
|
+
if (parent != zipEntry.parent) {
|
|
9590
|
+
detach(zipEntry);
|
|
9591
|
+
zipEntry.parent = parent;
|
|
9592
|
+
parent.children.push(zipEntry);
|
|
9593
|
+
registerEntries(zipEntry.fs, zipEntry);
|
|
9594
|
+
}
|
|
9604
9595
|
}
|
|
9596
|
+
zipEntry.name = name;
|
|
9605
9597
|
}
|
|
9606
9598
|
|
|
9607
9599
|
setOptions(options) {
|
|
@@ -9694,47 +9686,47 @@ class ZipFileEntry extends ZipEntry {
|
|
|
9694
9686
|
}
|
|
9695
9687
|
|
|
9696
9688
|
replaceBlob(blob) {
|
|
9697
|
-
|
|
9689
|
+
replaceContent(this, {
|
|
9698
9690
|
data: blob,
|
|
9699
9691
|
Reader: BlobReader,
|
|
9700
9692
|
Writer: BlobWriter,
|
|
9701
|
-
|
|
9693
|
+
uncompressedSize: blob.size
|
|
9702
9694
|
});
|
|
9703
9695
|
}
|
|
9704
9696
|
|
|
9705
9697
|
replaceText(text) {
|
|
9706
|
-
|
|
9698
|
+
replaceContent(this, {
|
|
9707
9699
|
data: text,
|
|
9708
9700
|
Reader: TextReader,
|
|
9709
9701
|
Writer: TextWriter,
|
|
9710
|
-
|
|
9702
|
+
uncompressedSize: getTextSize(text)
|
|
9711
9703
|
});
|
|
9712
9704
|
}
|
|
9713
9705
|
|
|
9714
9706
|
replaceData64URI(dataURI) {
|
|
9715
|
-
|
|
9707
|
+
replaceContent(this, {
|
|
9716
9708
|
data: dataURI,
|
|
9717
9709
|
Reader: Data64URIReader,
|
|
9718
9710
|
Writer: Data64URIWriter,
|
|
9719
|
-
|
|
9711
|
+
uncompressedSize: getData64URISize(dataURI)
|
|
9720
9712
|
});
|
|
9721
9713
|
}
|
|
9722
9714
|
|
|
9723
9715
|
replaceUint8Array(array) {
|
|
9724
|
-
|
|
9716
|
+
replaceContent(this, {
|
|
9725
9717
|
data: array,
|
|
9726
9718
|
Reader: Uint8ArrayReader,
|
|
9727
9719
|
Writer: Uint8ArrayWriter,
|
|
9728
|
-
|
|
9720
|
+
uncompressedSize: array.length
|
|
9729
9721
|
});
|
|
9730
9722
|
}
|
|
9731
9723
|
|
|
9732
9724
|
replaceReadable(readable) {
|
|
9733
|
-
|
|
9725
|
+
replaceContent(this, {
|
|
9734
9726
|
data: null,
|
|
9735
9727
|
Reader: getReadableReader(readable),
|
|
9736
9728
|
Writer: null,
|
|
9737
|
-
|
|
9729
|
+
uncompressedSize: UNDEFINED_VALUE
|
|
9738
9730
|
});
|
|
9739
9731
|
}
|
|
9740
9732
|
}
|
|
@@ -9784,17 +9776,12 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
9784
9776
|
}
|
|
9785
9777
|
|
|
9786
9778
|
addData64URI(name, dataURI, options = {}) {
|
|
9787
|
-
let dataEnd = dataURI.length;
|
|
9788
|
-
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
9789
|
-
dataEnd--;
|
|
9790
|
-
}
|
|
9791
|
-
const dataStart = dataURI.indexOf(",") + 1;
|
|
9792
9779
|
return addChild(this, name, {
|
|
9793
9780
|
data: dataURI,
|
|
9794
9781
|
Reader: Data64URIReader,
|
|
9795
9782
|
Writer: Data64URIWriter,
|
|
9796
9783
|
options,
|
|
9797
|
-
uncompressedSize:
|
|
9784
|
+
uncompressedSize: getData64URISize(dataURI)
|
|
9798
9785
|
});
|
|
9799
9786
|
}
|
|
9800
9787
|
|
|
@@ -9902,6 +9889,7 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
9902
9889
|
await initStream(reader);
|
|
9903
9890
|
zipReader = new ZipReader(reader, options);
|
|
9904
9891
|
}
|
|
9892
|
+
const duplicates = checkDuplicatesOption(options.duplicates);
|
|
9905
9893
|
const importedEntries = [];
|
|
9906
9894
|
const entries = await zipReader.getEntries(options);
|
|
9907
9895
|
for (const entry of entries) {
|
|
@@ -9909,19 +9897,42 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
9909
9897
|
try {
|
|
9910
9898
|
const path = entry.filename.split("/").filter(pathPart => pathPart != "" && pathPart != ".");
|
|
9911
9899
|
const name = path.pop();
|
|
9912
|
-
|
|
9900
|
+
let skippedEntry = false;
|
|
9901
|
+
for (const pathPart of path) {
|
|
9913
9902
|
const previousParent = parent;
|
|
9914
9903
|
parent = parent.getChildByName(pathPart);
|
|
9915
9904
|
if (parent) {
|
|
9916
9905
|
if (!parent.directory) {
|
|
9917
|
-
|
|
9906
|
+
if (duplicates == DUPLICATES_KEEP_FIRST) {
|
|
9907
|
+
skippedEntry = true;
|
|
9908
|
+
break;
|
|
9909
|
+
} else if (duplicates == DUPLICATES_KEEP_LAST) {
|
|
9910
|
+
this.fs.remove(parent);
|
|
9911
|
+
parent = new ZipDirectoryEntry(this.fs, pathPart, { data: null }, previousParent);
|
|
9912
|
+
importedEntries.push(parent);
|
|
9913
|
+
} else {
|
|
9914
|
+
throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
|
|
9915
|
+
}
|
|
9918
9916
|
}
|
|
9919
9917
|
} else {
|
|
9920
9918
|
parent = new ZipDirectoryEntry(this.fs, pathPart, { data: null }, previousParent);
|
|
9921
9919
|
importedEntries.push(parent);
|
|
9922
9920
|
}
|
|
9923
|
-
}
|
|
9921
|
+
}
|
|
9922
|
+
if (skippedEntry) {
|
|
9923
|
+
continue;
|
|
9924
|
+
}
|
|
9924
9925
|
if (!entry.directory) {
|
|
9926
|
+
const existingChild = parent.getChildByName(name);
|
|
9927
|
+
if (existingChild) {
|
|
9928
|
+
if (duplicates == DUPLICATES_KEEP_FIRST) {
|
|
9929
|
+
continue;
|
|
9930
|
+
} else if (duplicates == DUPLICATES_KEEP_LAST) {
|
|
9931
|
+
this.fs.remove(existingChild);
|
|
9932
|
+
} else {
|
|
9933
|
+
throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
|
|
9934
|
+
}
|
|
9935
|
+
}
|
|
9925
9936
|
importedEntries.push(addChild(parent, name, {
|
|
9926
9937
|
data: entry,
|
|
9927
9938
|
Reader: getZipBlobReader(Object.assign({}, options)),
|
|
@@ -9932,11 +9943,17 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
9932
9943
|
let directoryEntry = parent;
|
|
9933
9944
|
if (name) {
|
|
9934
9945
|
directoryEntry = parent.getChildByName(name);
|
|
9935
|
-
if (directoryEntry) {
|
|
9936
|
-
if (
|
|
9937
|
-
|
|
9946
|
+
if (directoryEntry && !directoryEntry.directory) {
|
|
9947
|
+
if (duplicates == DUPLICATES_KEEP_FIRST) {
|
|
9948
|
+
continue;
|
|
9949
|
+
} else if (duplicates == DUPLICATES_KEEP_LAST) {
|
|
9950
|
+
this.fs.remove(directoryEntry);
|
|
9951
|
+
directoryEntry = UNDEFINED_VALUE;
|
|
9952
|
+
} else {
|
|
9953
|
+
throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
|
|
9938
9954
|
}
|
|
9939
|
-
}
|
|
9955
|
+
}
|
|
9956
|
+
if (!directoryEntry) {
|
|
9940
9957
|
directoryEntry = new ZipDirectoryEntry(this.fs, name, { data: null }, parent);
|
|
9941
9958
|
importedEntries.push(directoryEntry);
|
|
9942
9959
|
}
|
|
@@ -9946,6 +9963,7 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
9946
9963
|
}
|
|
9947
9964
|
}
|
|
9948
9965
|
} catch (error) {
|
|
9966
|
+
importedEntries.reverse().forEach(importedEntry => this.fs.remove(importedEntry));
|
|
9949
9967
|
try {
|
|
9950
9968
|
error.cause = {
|
|
9951
9969
|
entry
|
|
@@ -10064,7 +10082,7 @@ class ZipFS {
|
|
|
10064
10082
|
}
|
|
10065
10083
|
}
|
|
10066
10084
|
} else {
|
|
10067
|
-
throw new Error(
|
|
10085
|
+
throw new Error(ERR_ANCESTOR_ENTRY);
|
|
10068
10086
|
}
|
|
10069
10087
|
} else {
|
|
10070
10088
|
throw new Error("Target entry is not a directory");
|
|
@@ -10076,7 +10094,7 @@ class ZipFS {
|
|
|
10076
10094
|
const path = fullname.split("/");
|
|
10077
10095
|
let node = this.root;
|
|
10078
10096
|
for (let index = 0; node && index < path.length; index++) {
|
|
10079
|
-
node = node.getChildByName(path[index]);
|
|
10097
|
+
node = node.directory ? node.getChildByName(path[index]) : UNDEFINED_VALUE;
|
|
10080
10098
|
}
|
|
10081
10099
|
if (!node) {
|
|
10082
10100
|
node = this.entries.find(entry => entry && (entry == this.root || entry.isDescendantOf(this.root)) &&
|
|
@@ -10138,33 +10156,27 @@ class ZipFS {
|
|
|
10138
10156
|
}
|
|
10139
10157
|
|
|
10140
10158
|
importBlob(blob, options) {
|
|
10141
|
-
|
|
10142
|
-
return this.root.importBlob(blob, options);
|
|
10159
|
+
return resetAndImport(this, root => root.importBlob(blob, options));
|
|
10143
10160
|
}
|
|
10144
10161
|
|
|
10145
10162
|
importData64URI(dataURI, options) {
|
|
10146
|
-
|
|
10147
|
-
return this.root.importData64URI(dataURI, options);
|
|
10163
|
+
return resetAndImport(this, root => root.importData64URI(dataURI, options));
|
|
10148
10164
|
}
|
|
10149
10165
|
|
|
10150
10166
|
importUint8Array(array, options) {
|
|
10151
|
-
|
|
10152
|
-
return this.root.importUint8Array(array, options);
|
|
10167
|
+
return resetAndImport(this, root => root.importUint8Array(array, options));
|
|
10153
10168
|
}
|
|
10154
10169
|
|
|
10155
10170
|
importHttpContent(url, options) {
|
|
10156
|
-
|
|
10157
|
-
return this.root.importHttpContent(url, options);
|
|
10171
|
+
return resetAndImport(this, root => root.importHttpContent(url, options));
|
|
10158
10172
|
}
|
|
10159
10173
|
|
|
10160
10174
|
importReadable(readable, options) {
|
|
10161
|
-
|
|
10162
|
-
return this.root.importReadable(readable, options);
|
|
10175
|
+
return resetAndImport(this, root => root.importReadable(readable, options));
|
|
10163
10176
|
}
|
|
10164
10177
|
|
|
10165
10178
|
importZip(reader, options) {
|
|
10166
|
-
|
|
10167
|
-
return this.root.importZip(reader, options);
|
|
10179
|
+
return resetAndImport(this, root => root.importZip(reader, options));
|
|
10168
10180
|
}
|
|
10169
10181
|
|
|
10170
10182
|
exportBlob(options) {
|
|
@@ -10484,6 +10496,25 @@ function checkReaderOptions(readerOptions) {
|
|
|
10484
10496
|
return readerOptions;
|
|
10485
10497
|
}
|
|
10486
10498
|
|
|
10499
|
+
function replaceContent(zipEntry, params) {
|
|
10500
|
+
const { uncompressedSize } = params;
|
|
10501
|
+
Object.assign(zipEntry, params, {
|
|
10502
|
+
reader: null,
|
|
10503
|
+
passThrough: UNDEFINED_VALUE,
|
|
10504
|
+
uncompressedSize: uncompressedSize === UNDEFINED_VALUE ? 0 : uncompressedSize,
|
|
10505
|
+
undeterminedSize: uncompressedSize === UNDEFINED_VALUE
|
|
10506
|
+
});
|
|
10507
|
+
}
|
|
10508
|
+
|
|
10509
|
+
function getData64URISize(dataURI) {
|
|
10510
|
+
let dataEnd = dataURI.length;
|
|
10511
|
+
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
10512
|
+
dataEnd--;
|
|
10513
|
+
}
|
|
10514
|
+
const dataStart = dataURI.indexOf(",") + 1;
|
|
10515
|
+
return Math.floor((dataEnd - dataStart) * 0.75);
|
|
10516
|
+
}
|
|
10517
|
+
|
|
10487
10518
|
function isPassThrough(child, options) {
|
|
10488
10519
|
const { readerOptions } = options;
|
|
10489
10520
|
return Boolean(!child.directory && (child.passThrough || (readerOptions && readerOptions.passThrough)));
|
|
@@ -10773,6 +10804,15 @@ function resetFS(fs) {
|
|
|
10773
10804
|
fs.root = new ZipDirectoryEntry(fs);
|
|
10774
10805
|
}
|
|
10775
10806
|
|
|
10807
|
+
function resetAndImport(fs, importFunction) {
|
|
10808
|
+
const { entries, entryIdCounter, root } = fs;
|
|
10809
|
+
resetFS(fs);
|
|
10810
|
+
return importFunction(fs.root).catch(error => {
|
|
10811
|
+
Object.assign(fs, { entries, entryIdCounter, root });
|
|
10812
|
+
throw error;
|
|
10813
|
+
});
|
|
10814
|
+
}
|
|
10815
|
+
|
|
10776
10816
|
function collectChildren(directory, recursive) {
|
|
10777
10817
|
const children = [];
|
|
10778
10818
|
const pendingDirectories = [directory];
|
|
@@ -10801,10 +10841,52 @@ function registerEntries(fs, entry) {
|
|
|
10801
10841
|
|
|
10802
10842
|
function addChild(parent, name, params, directory) {
|
|
10803
10843
|
if (parent.directory) {
|
|
10844
|
+
const path = splitPath(name);
|
|
10845
|
+
if (path) {
|
|
10846
|
+
name = path.pop();
|
|
10847
|
+
parent = getPathParent(parent, path);
|
|
10848
|
+
}
|
|
10804
10849
|
return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new ZipFileEntry(parent.fs, name, params, parent);
|
|
10805
10850
|
} else {
|
|
10806
10851
|
throw new Error("Parent entry is not a directory");
|
|
10807
10852
|
}
|
|
10808
10853
|
}
|
|
10809
10854
|
|
|
10810
|
-
|
|
10855
|
+
function checkDuplicatesOption(duplicates) {
|
|
10856
|
+
if (duplicates === UNDEFINED_VALUE) {
|
|
10857
|
+
return DUPLICATES_THROW;
|
|
10858
|
+
} else if (DUPLICATES_VALUES.has(duplicates)) {
|
|
10859
|
+
return duplicates;
|
|
10860
|
+
} else {
|
|
10861
|
+
throw new Error(ERR_INVALID_DUPLICATES);
|
|
10862
|
+
}
|
|
10863
|
+
}
|
|
10864
|
+
|
|
10865
|
+
function splitPath(name) {
|
|
10866
|
+
if (name.includes("/")) {
|
|
10867
|
+
const path = name.split("/").filter(pathPart => pathPart != "" && pathPart != ".");
|
|
10868
|
+
if (path.length) {
|
|
10869
|
+
return path;
|
|
10870
|
+
}
|
|
10871
|
+
}
|
|
10872
|
+
}
|
|
10873
|
+
|
|
10874
|
+
function getPathParent(parent, path, movedEntry) {
|
|
10875
|
+
path.forEach(pathPart => {
|
|
10876
|
+
const previousParent = parent;
|
|
10877
|
+
parent = parent.getChildByName(pathPart);
|
|
10878
|
+
if (parent) {
|
|
10879
|
+
if (!parent.directory) {
|
|
10880
|
+
throw new Error(ERR_ENTRY_EXISTS);
|
|
10881
|
+
}
|
|
10882
|
+
if (movedEntry && (parent == movedEntry || parent.isDescendantOf(movedEntry))) {
|
|
10883
|
+
throw new Error(ERR_ANCESTOR_ENTRY);
|
|
10884
|
+
}
|
|
10885
|
+
} else {
|
|
10886
|
+
parent = new ZipDirectoryEntry(previousParent.fs, pathPart, { data: null }, previousParent);
|
|
10887
|
+
}
|
|
10888
|
+
});
|
|
10889
|
+
return parent;
|
|
10890
|
+
}
|
|
10891
|
+
|
|
10892
|
+
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, ERR_AMBIGUOUS_ARCHIVE, 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_INVALID_AUTHENTICATION_CODE, 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_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_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_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_READABLE_CONSUMED, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_COMPRESSION_METHOD, 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_UINT64, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_CRYPTO_LAST_MOD_DATE, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, VERSION, WARNING_APPENDED_DATA, WARNING_COMPRESSED_PATCHED_DATA, 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_ZIP64_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 };
|