@zip.js/zip.js 2.8.61 → 2.10.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 +15 -15
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +15 -14
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +168 -57
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +170 -56
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +168 -57
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +170 -56
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +170 -56
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +15 -14
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +15 -14
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +15 -14
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +170 -56
- package/index-native.min.js +1 -1
- package/index.cjs +170 -56
- package/index.d.cts +104 -9
- package/index.d.ts +104 -9
- package/index.min.js +1 -1
- package/lib/core/streams/codecs/crc32.js +1 -1
- package/lib/core/util/decode-cp437.js +5 -12
- package/lib/core/version.js +1 -1
- package/lib/core/zip-fs.js +155 -44
- package/lib/core/zip-reader.js +7 -0
- package/lib/zip-core-reader.js +1 -0
- package/package.json +1 -1
package/dist/zip-fs-core.js
CHANGED
|
@@ -493,7 +493,7 @@
|
|
|
493
493
|
// Every table MUST stay a PACKED_SMI array: build with array literals (not `new Array(n)`,
|
|
494
494
|
// which is HOLEY) and store the signed int32 XOR result (no `>>> 0`). An unsigned or holey
|
|
495
495
|
// table becomes a V8 FixedDoubleArray whose every hot-loop lookup unboxes a double (~1.6x
|
|
496
|
-
// slower). Signedness is irrelevant to the result
|
|
496
|
+
// slower). Signedness is irrelevant to the result: the reads mask/shift it and the final
|
|
497
497
|
// `~crc` normalizes it. Do NOT reintroduce `>>> 0` here or switch to `new Array(256)`.
|
|
498
498
|
const T = [[], [], [], [], [], [], [], []];
|
|
499
499
|
for (let n = 0; n < 256; n++) {
|
|
@@ -3475,21 +3475,14 @@
|
|
|
3475
3475
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3476
3476
|
*/
|
|
3477
3477
|
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
|
|
3481
|
-
const VALID_CP437 = CP437.length == 256;
|
|
3478
|
+
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("");
|
|
3482
3479
|
|
|
3483
3480
|
function decodeCP437(stringValue) {
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
result += CP437[stringValue[indexCharacter]];
|
|
3488
|
-
}
|
|
3489
|
-
return result;
|
|
3490
|
-
} else {
|
|
3491
|
-
return new TextDecoder().decode(stringValue);
|
|
3481
|
+
let result = "";
|
|
3482
|
+
for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
|
|
3483
|
+
result += CP437[stringValue[indexCharacter]];
|
|
3492
3484
|
}
|
|
3485
|
+
return result;
|
|
3493
3486
|
}
|
|
3494
3487
|
|
|
3495
3488
|
/*
|
|
@@ -4743,6 +4736,7 @@
|
|
|
4743
4736
|
const WARNING_WRAPPED_ENTRIES_COUNT = "wrapped entries count";
|
|
4744
4737
|
const WARNING_APPENDED_DATA = "appended data";
|
|
4745
4738
|
const WARNING_PREPENDED_DATA = "prepended data";
|
|
4739
|
+
const WARNING_PREPENDED_CENTRAL_DIRECTORY = "prepended central directory";
|
|
4746
4740
|
const WARNING_TRAILING_CENTRAL_DIRECTORY_DATA = "trailing central directory data";
|
|
4747
4741
|
const WARNING_DUPLICATE_FILENAME = "duplicate filename";
|
|
4748
4742
|
const WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY = "mismatched zip64 end of central directory record";
|
|
@@ -4836,6 +4830,7 @@
|
|
|
4836
4830
|
let diskNumber = getUint16$1(endOfDirectoryView, 6);
|
|
4837
4831
|
let filesLength = getUint16$1(endOfDirectoryView, 10);
|
|
4838
4832
|
let prependedDataLength = 0;
|
|
4833
|
+
let prependedCentralDirectory;
|
|
4839
4834
|
let startOffset;
|
|
4840
4835
|
let zip64EndOfDirectory;
|
|
4841
4836
|
let zip64EndOfDirectoryVersion2;
|
|
@@ -4939,6 +4934,7 @@
|
|
|
4939
4934
|
directoryDataOffset = expectedDirectoryDataOffset;
|
|
4940
4935
|
if (directoryDataOffset > originalDirectoryDataOffset) {
|
|
4941
4936
|
prependedDataLength += directoryDataOffset - originalDirectoryDataOffset;
|
|
4937
|
+
prependedCentralDirectory = storedPointsAtDirectory;
|
|
4942
4938
|
}
|
|
4943
4939
|
directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);
|
|
4944
4940
|
directoryView = getDataView(directoryArray);
|
|
@@ -5166,6 +5162,9 @@
|
|
|
5166
5162
|
if (prependedDataLength || (filesLength && startOffset > SPLIT_ZIP_FILE_SIGNATURE_LENGTH)) {
|
|
5167
5163
|
addWarning(warnings, WARNING_PREPENDED_DATA);
|
|
5168
5164
|
}
|
|
5165
|
+
if (prependedCentralDirectory) {
|
|
5166
|
+
addWarning(warnings, WARNING_PREPENDED_CENTRAL_DIRECTORY);
|
|
5167
|
+
}
|
|
5169
5168
|
if (extractPrependedData) {
|
|
5170
5169
|
zipReader.prependedData = startOffset > splitZipSignatureLength ?
|
|
5171
5170
|
await readUint8Array(reader, splitZipSignatureLength, startOffset - splitZipSignatureLength) :
|
|
@@ -6226,6 +6225,7 @@
|
|
|
6226
6225
|
WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD: WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD,
|
|
6227
6226
|
WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES: WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES,
|
|
6228
6227
|
WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY: WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY,
|
|
6228
|
+
WARNING_PREPENDED_CENTRAL_DIRECTORY: WARNING_PREPENDED_CENTRAL_DIRECTORY,
|
|
6229
6229
|
WARNING_PREPENDED_DATA: WARNING_PREPENDED_DATA,
|
|
6230
6230
|
WARNING_TRAILING_CENTRAL_DIRECTORY_DATA: WARNING_TRAILING_CENTRAL_DIRECTORY_DATA,
|
|
6231
6231
|
WARNING_UNKNOWN_VERSION: WARNING_UNKNOWN_VERSION,
|
|
@@ -8617,7 +8617,7 @@
|
|
|
8617
8617
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
8618
8618
|
*/
|
|
8619
8619
|
|
|
8620
|
-
const VERSION = "2.
|
|
8620
|
+
const VERSION = "2.10.0";
|
|
8621
8621
|
|
|
8622
8622
|
/*
|
|
8623
8623
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
@@ -9096,7 +9096,14 @@
|
|
|
9096
9096
|
|
|
9097
9097
|
|
|
9098
9098
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
9099
|
+
const ERR_DUPLICATE_IMPORTED_ENTRY = "Duplicate entry filename in the imported zip file";
|
|
9100
|
+
const ERR_INVALID_DUPLICATES = "Invalid duplicates option (must be \"throw\", \"keep-first\" or \"keep-last\")";
|
|
9101
|
+
const ERR_ANCESTOR_ENTRY = "Entry is a ancestor of target entry";
|
|
9099
9102
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
9103
|
+
const DUPLICATES_THROW = "throw";
|
|
9104
|
+
const DUPLICATES_KEEP_FIRST = "keep-first";
|
|
9105
|
+
const DUPLICATES_KEEP_LAST = "keep-last";
|
|
9106
|
+
const DUPLICATES_VALUES = new Set([DUPLICATES_THROW, DUPLICATES_KEEP_FIRST, DUPLICATES_KEEP_LAST]);
|
|
9100
9107
|
const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
|
|
9101
9108
|
const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
|
|
9102
9109
|
const ERR_ZIP_CRYPTO_LAST_MOD_DATE = "The last modification date of an entry encrypted with ZipCrypto cannot be changed when passThrough is set";
|
|
@@ -9173,12 +9180,26 @@
|
|
|
9173
9180
|
}
|
|
9174
9181
|
|
|
9175
9182
|
rename(name) {
|
|
9176
|
-
const
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9183
|
+
const zipEntry = this;
|
|
9184
|
+
let parent = zipEntry.parent;
|
|
9185
|
+
if (parent) {
|
|
9186
|
+
const path = splitPath(name);
|
|
9187
|
+
if (path) {
|
|
9188
|
+
name = path.pop();
|
|
9189
|
+
parent = getPathParent(parent, path, zipEntry);
|
|
9190
|
+
}
|
|
9191
|
+
const existingChild = parent.getChildByName(name);
|
|
9192
|
+
if (existingChild && existingChild != zipEntry) {
|
|
9193
|
+
throw new Error(ERR_ENTRY_EXISTS);
|
|
9194
|
+
}
|
|
9195
|
+
if (parent != zipEntry.parent) {
|
|
9196
|
+
detach(zipEntry);
|
|
9197
|
+
zipEntry.parent = parent;
|
|
9198
|
+
parent.children.push(zipEntry);
|
|
9199
|
+
registerEntries(zipEntry.fs, zipEntry);
|
|
9200
|
+
}
|
|
9181
9201
|
}
|
|
9202
|
+
zipEntry.name = name;
|
|
9182
9203
|
}
|
|
9183
9204
|
|
|
9184
9205
|
setOptions(options) {
|
|
@@ -9271,47 +9292,47 @@
|
|
|
9271
9292
|
}
|
|
9272
9293
|
|
|
9273
9294
|
replaceBlob(blob) {
|
|
9274
|
-
|
|
9295
|
+
replaceContent(this, {
|
|
9275
9296
|
data: blob,
|
|
9276
9297
|
Reader: BlobReader,
|
|
9277
9298
|
Writer: BlobWriter,
|
|
9278
|
-
|
|
9299
|
+
uncompressedSize: blob.size
|
|
9279
9300
|
});
|
|
9280
9301
|
}
|
|
9281
9302
|
|
|
9282
9303
|
replaceText(text) {
|
|
9283
|
-
|
|
9304
|
+
replaceContent(this, {
|
|
9284
9305
|
data: text,
|
|
9285
9306
|
Reader: TextReader,
|
|
9286
9307
|
Writer: TextWriter,
|
|
9287
|
-
|
|
9308
|
+
uncompressedSize: getTextSize(text)
|
|
9288
9309
|
});
|
|
9289
9310
|
}
|
|
9290
9311
|
|
|
9291
9312
|
replaceData64URI(dataURI) {
|
|
9292
|
-
|
|
9313
|
+
replaceContent(this, {
|
|
9293
9314
|
data: dataURI,
|
|
9294
9315
|
Reader: Data64URIReader,
|
|
9295
9316
|
Writer: Data64URIWriter,
|
|
9296
|
-
|
|
9317
|
+
uncompressedSize: getData64URISize(dataURI)
|
|
9297
9318
|
});
|
|
9298
9319
|
}
|
|
9299
9320
|
|
|
9300
9321
|
replaceUint8Array(array) {
|
|
9301
|
-
|
|
9322
|
+
replaceContent(this, {
|
|
9302
9323
|
data: array,
|
|
9303
9324
|
Reader: Uint8ArrayReader,
|
|
9304
9325
|
Writer: Uint8ArrayWriter,
|
|
9305
|
-
|
|
9326
|
+
uncompressedSize: array.length
|
|
9306
9327
|
});
|
|
9307
9328
|
}
|
|
9308
9329
|
|
|
9309
9330
|
replaceReadable(readable) {
|
|
9310
|
-
|
|
9331
|
+
replaceContent(this, {
|
|
9311
9332
|
data: null,
|
|
9312
9333
|
Reader: getReadableReader(readable),
|
|
9313
9334
|
Writer: null,
|
|
9314
|
-
|
|
9335
|
+
uncompressedSize: UNDEFINED_VALUE
|
|
9315
9336
|
});
|
|
9316
9337
|
}
|
|
9317
9338
|
}
|
|
@@ -9361,17 +9382,12 @@
|
|
|
9361
9382
|
}
|
|
9362
9383
|
|
|
9363
9384
|
addData64URI(name, dataURI, options = {}) {
|
|
9364
|
-
let dataEnd = dataURI.length;
|
|
9365
|
-
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
9366
|
-
dataEnd--;
|
|
9367
|
-
}
|
|
9368
|
-
const dataStart = dataURI.indexOf(",") + 1;
|
|
9369
9385
|
return addChild(this, name, {
|
|
9370
9386
|
data: dataURI,
|
|
9371
9387
|
Reader: Data64URIReader,
|
|
9372
9388
|
Writer: Data64URIWriter,
|
|
9373
9389
|
options,
|
|
9374
|
-
uncompressedSize:
|
|
9390
|
+
uncompressedSize: getData64URISize(dataURI)
|
|
9375
9391
|
});
|
|
9376
9392
|
}
|
|
9377
9393
|
|
|
@@ -9479,6 +9495,7 @@
|
|
|
9479
9495
|
await initStream(reader);
|
|
9480
9496
|
zipReader = new ZipReader(reader, options);
|
|
9481
9497
|
}
|
|
9498
|
+
const duplicates = checkDuplicatesOption(options.duplicates);
|
|
9482
9499
|
const importedEntries = [];
|
|
9483
9500
|
const entries = await zipReader.getEntries(options);
|
|
9484
9501
|
for (const entry of entries) {
|
|
@@ -9486,19 +9503,42 @@
|
|
|
9486
9503
|
try {
|
|
9487
9504
|
const path = entry.filename.split("/").filter(pathPart => pathPart != "" && pathPart != ".");
|
|
9488
9505
|
const name = path.pop();
|
|
9489
|
-
|
|
9506
|
+
let skippedEntry = false;
|
|
9507
|
+
for (const pathPart of path) {
|
|
9490
9508
|
const previousParent = parent;
|
|
9491
9509
|
parent = parent.getChildByName(pathPart);
|
|
9492
9510
|
if (parent) {
|
|
9493
9511
|
if (!parent.directory) {
|
|
9494
|
-
|
|
9512
|
+
if (duplicates == DUPLICATES_KEEP_FIRST) {
|
|
9513
|
+
skippedEntry = true;
|
|
9514
|
+
break;
|
|
9515
|
+
} else if (duplicates == DUPLICATES_KEEP_LAST) {
|
|
9516
|
+
this.fs.remove(parent);
|
|
9517
|
+
parent = new ZipDirectoryEntry(this.fs, pathPart, { data: null }, previousParent);
|
|
9518
|
+
importedEntries.push(parent);
|
|
9519
|
+
} else {
|
|
9520
|
+
throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
|
|
9521
|
+
}
|
|
9495
9522
|
}
|
|
9496
9523
|
} else {
|
|
9497
9524
|
parent = new ZipDirectoryEntry(this.fs, pathPart, { data: null }, previousParent);
|
|
9498
9525
|
importedEntries.push(parent);
|
|
9499
9526
|
}
|
|
9500
|
-
}
|
|
9527
|
+
}
|
|
9528
|
+
if (skippedEntry) {
|
|
9529
|
+
continue;
|
|
9530
|
+
}
|
|
9501
9531
|
if (!entry.directory) {
|
|
9532
|
+
const existingChild = parent.getChildByName(name);
|
|
9533
|
+
if (existingChild) {
|
|
9534
|
+
if (duplicates == DUPLICATES_KEEP_FIRST) {
|
|
9535
|
+
continue;
|
|
9536
|
+
} else if (duplicates == DUPLICATES_KEEP_LAST) {
|
|
9537
|
+
this.fs.remove(existingChild);
|
|
9538
|
+
} else {
|
|
9539
|
+
throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
|
|
9540
|
+
}
|
|
9541
|
+
}
|
|
9502
9542
|
importedEntries.push(addChild(parent, name, {
|
|
9503
9543
|
data: entry,
|
|
9504
9544
|
Reader: getZipBlobReader(Object.assign({}, options)),
|
|
@@ -9509,11 +9549,17 @@
|
|
|
9509
9549
|
let directoryEntry = parent;
|
|
9510
9550
|
if (name) {
|
|
9511
9551
|
directoryEntry = parent.getChildByName(name);
|
|
9512
|
-
if (directoryEntry) {
|
|
9513
|
-
if (
|
|
9514
|
-
|
|
9552
|
+
if (directoryEntry && !directoryEntry.directory) {
|
|
9553
|
+
if (duplicates == DUPLICATES_KEEP_FIRST) {
|
|
9554
|
+
continue;
|
|
9555
|
+
} else if (duplicates == DUPLICATES_KEEP_LAST) {
|
|
9556
|
+
this.fs.remove(directoryEntry);
|
|
9557
|
+
directoryEntry = UNDEFINED_VALUE;
|
|
9558
|
+
} else {
|
|
9559
|
+
throw new Error(ERR_DUPLICATE_IMPORTED_ENTRY);
|
|
9515
9560
|
}
|
|
9516
|
-
}
|
|
9561
|
+
}
|
|
9562
|
+
if (!directoryEntry) {
|
|
9517
9563
|
directoryEntry = new ZipDirectoryEntry(this.fs, name, { data: null }, parent);
|
|
9518
9564
|
importedEntries.push(directoryEntry);
|
|
9519
9565
|
}
|
|
@@ -9523,6 +9569,7 @@
|
|
|
9523
9569
|
}
|
|
9524
9570
|
}
|
|
9525
9571
|
} catch (error) {
|
|
9572
|
+
importedEntries.reverse().forEach(importedEntry => this.fs.remove(importedEntry));
|
|
9526
9573
|
try {
|
|
9527
9574
|
error.cause = {
|
|
9528
9575
|
entry
|
|
@@ -9641,7 +9688,7 @@
|
|
|
9641
9688
|
}
|
|
9642
9689
|
}
|
|
9643
9690
|
} else {
|
|
9644
|
-
throw new Error(
|
|
9691
|
+
throw new Error(ERR_ANCESTOR_ENTRY);
|
|
9645
9692
|
}
|
|
9646
9693
|
} else {
|
|
9647
9694
|
throw new Error("Target entry is not a directory");
|
|
@@ -9653,7 +9700,7 @@
|
|
|
9653
9700
|
const path = fullname.split("/");
|
|
9654
9701
|
let node = this.root;
|
|
9655
9702
|
for (let index = 0; node && index < path.length; index++) {
|
|
9656
|
-
node = node.getChildByName(path[index]);
|
|
9703
|
+
node = node.directory ? node.getChildByName(path[index]) : UNDEFINED_VALUE;
|
|
9657
9704
|
}
|
|
9658
9705
|
if (!node) {
|
|
9659
9706
|
node = this.entries.find(entry => entry && (entry == this.root || entry.isDescendantOf(this.root)) &&
|
|
@@ -9715,33 +9762,27 @@
|
|
|
9715
9762
|
}
|
|
9716
9763
|
|
|
9717
9764
|
importBlob(blob, options) {
|
|
9718
|
-
|
|
9719
|
-
return this.root.importBlob(blob, options);
|
|
9765
|
+
return resetAndImport(this, root => root.importBlob(blob, options));
|
|
9720
9766
|
}
|
|
9721
9767
|
|
|
9722
9768
|
importData64URI(dataURI, options) {
|
|
9723
|
-
|
|
9724
|
-
return this.root.importData64URI(dataURI, options);
|
|
9769
|
+
return resetAndImport(this, root => root.importData64URI(dataURI, options));
|
|
9725
9770
|
}
|
|
9726
9771
|
|
|
9727
9772
|
importUint8Array(array, options) {
|
|
9728
|
-
|
|
9729
|
-
return this.root.importUint8Array(array, options);
|
|
9773
|
+
return resetAndImport(this, root => root.importUint8Array(array, options));
|
|
9730
9774
|
}
|
|
9731
9775
|
|
|
9732
9776
|
importHttpContent(url, options) {
|
|
9733
|
-
|
|
9734
|
-
return this.root.importHttpContent(url, options);
|
|
9777
|
+
return resetAndImport(this, root => root.importHttpContent(url, options));
|
|
9735
9778
|
}
|
|
9736
9779
|
|
|
9737
9780
|
importReadable(readable, options) {
|
|
9738
|
-
|
|
9739
|
-
return this.root.importReadable(readable, options);
|
|
9781
|
+
return resetAndImport(this, root => root.importReadable(readable, options));
|
|
9740
9782
|
}
|
|
9741
9783
|
|
|
9742
9784
|
importZip(reader, options) {
|
|
9743
|
-
|
|
9744
|
-
return this.root.importZip(reader, options);
|
|
9785
|
+
return resetAndImport(this, root => root.importZip(reader, options));
|
|
9745
9786
|
}
|
|
9746
9787
|
|
|
9747
9788
|
exportBlob(options) {
|
|
@@ -10061,6 +10102,25 @@
|
|
|
10061
10102
|
return readerOptions;
|
|
10062
10103
|
}
|
|
10063
10104
|
|
|
10105
|
+
function replaceContent(zipEntry, params) {
|
|
10106
|
+
const { uncompressedSize } = params;
|
|
10107
|
+
Object.assign(zipEntry, params, {
|
|
10108
|
+
reader: null,
|
|
10109
|
+
passThrough: UNDEFINED_VALUE,
|
|
10110
|
+
uncompressedSize: uncompressedSize === UNDEFINED_VALUE ? 0 : uncompressedSize,
|
|
10111
|
+
undeterminedSize: uncompressedSize === UNDEFINED_VALUE
|
|
10112
|
+
});
|
|
10113
|
+
}
|
|
10114
|
+
|
|
10115
|
+
function getData64URISize(dataURI) {
|
|
10116
|
+
let dataEnd = dataURI.length;
|
|
10117
|
+
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
10118
|
+
dataEnd--;
|
|
10119
|
+
}
|
|
10120
|
+
const dataStart = dataURI.indexOf(",") + 1;
|
|
10121
|
+
return Math.floor((dataEnd - dataStart) * 0.75);
|
|
10122
|
+
}
|
|
10123
|
+
|
|
10064
10124
|
function isPassThrough(child, options) {
|
|
10065
10125
|
const { readerOptions } = options;
|
|
10066
10126
|
return Boolean(!child.directory && (child.passThrough || (readerOptions && readerOptions.passThrough)));
|
|
@@ -10350,6 +10410,15 @@
|
|
|
10350
10410
|
fs.root = new ZipDirectoryEntry(fs);
|
|
10351
10411
|
}
|
|
10352
10412
|
|
|
10413
|
+
function resetAndImport(fs, importFunction) {
|
|
10414
|
+
const { entries, entryIdCounter, root } = fs;
|
|
10415
|
+
resetFS(fs);
|
|
10416
|
+
return importFunction(fs.root).catch(error => {
|
|
10417
|
+
Object.assign(fs, { entries, entryIdCounter, root });
|
|
10418
|
+
throw error;
|
|
10419
|
+
});
|
|
10420
|
+
}
|
|
10421
|
+
|
|
10353
10422
|
function collectChildren(directory, recursive) {
|
|
10354
10423
|
const children = [];
|
|
10355
10424
|
const pendingDirectories = [directory];
|
|
@@ -10378,12 +10447,54 @@
|
|
|
10378
10447
|
|
|
10379
10448
|
function addChild(parent, name, params, directory) {
|
|
10380
10449
|
if (parent.directory) {
|
|
10450
|
+
const path = splitPath(name);
|
|
10451
|
+
if (path) {
|
|
10452
|
+
name = path.pop();
|
|
10453
|
+
parent = getPathParent(parent, path);
|
|
10454
|
+
}
|
|
10381
10455
|
return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new ZipFileEntry(parent.fs, name, params, parent);
|
|
10382
10456
|
} else {
|
|
10383
10457
|
throw new Error("Parent entry is not a directory");
|
|
10384
10458
|
}
|
|
10385
10459
|
}
|
|
10386
10460
|
|
|
10461
|
+
function checkDuplicatesOption(duplicates) {
|
|
10462
|
+
if (duplicates === UNDEFINED_VALUE) {
|
|
10463
|
+
return DUPLICATES_THROW;
|
|
10464
|
+
} else if (DUPLICATES_VALUES.has(duplicates)) {
|
|
10465
|
+
return duplicates;
|
|
10466
|
+
} else {
|
|
10467
|
+
throw new Error(ERR_INVALID_DUPLICATES);
|
|
10468
|
+
}
|
|
10469
|
+
}
|
|
10470
|
+
|
|
10471
|
+
function splitPath(name) {
|
|
10472
|
+
if (name.includes("/")) {
|
|
10473
|
+
const path = name.split("/").filter(pathPart => pathPart != "" && pathPart != ".");
|
|
10474
|
+
if (path.length) {
|
|
10475
|
+
return path;
|
|
10476
|
+
}
|
|
10477
|
+
}
|
|
10478
|
+
}
|
|
10479
|
+
|
|
10480
|
+
function getPathParent(parent, path, movedEntry) {
|
|
10481
|
+
path.forEach(pathPart => {
|
|
10482
|
+
const previousParent = parent;
|
|
10483
|
+
parent = parent.getChildByName(pathPart);
|
|
10484
|
+
if (parent) {
|
|
10485
|
+
if (!parent.directory) {
|
|
10486
|
+
throw new Error(ERR_ENTRY_EXISTS);
|
|
10487
|
+
}
|
|
10488
|
+
if (movedEntry && (parent == movedEntry || parent.isDescendantOf(movedEntry))) {
|
|
10489
|
+
throw new Error(ERR_ANCESTOR_ENTRY);
|
|
10490
|
+
}
|
|
10491
|
+
} else {
|
|
10492
|
+
parent = new ZipDirectoryEntry(previousParent.fs, pathPart, { data: null }, previousParent);
|
|
10493
|
+
}
|
|
10494
|
+
});
|
|
10495
|
+
return parent;
|
|
10496
|
+
}
|
|
10497
|
+
|
|
10387
10498
|
exports.BlobReader = BlobReader;
|
|
10388
10499
|
exports.BlobWriter = BlobWriter;
|
|
10389
10500
|
exports.Data64URIReader = Data64URIReader;
|
|
@@ -10393,6 +10504,7 @@
|
|
|
10393
10504
|
exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
|
|
10394
10505
|
exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
|
|
10395
10506
|
exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
|
|
10507
|
+
exports.ERR_DUPLICATE_IMPORTED_ENTRY = ERR_DUPLICATE_IMPORTED_ENTRY;
|
|
10396
10508
|
exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
|
|
10397
10509
|
exports.ERR_ENCRYPTED_CENTRAL_DIRECTORY = ERR_ENCRYPTED_CENTRAL_DIRECTORY;
|
|
10398
10510
|
exports.ERR_ENTRY_DATA_OUT_OF_BOUNDS = ERR_ENTRY_DATA_OUT_OF_BOUNDS;
|
|
@@ -10410,6 +10522,7 @@
|
|
|
10410
10522
|
exports.ERR_INVALID_COMPRESSED_DATA = ERR_INVALID_COMPRESSED_DATA;
|
|
10411
10523
|
exports.ERR_INVALID_CRC32 = ERR_INVALID_CRC32;
|
|
10412
10524
|
exports.ERR_INVALID_DATE = ERR_INVALID_DATE;
|
|
10525
|
+
exports.ERR_INVALID_DUPLICATES = ERR_INVALID_DUPLICATES;
|
|
10413
10526
|
exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
|
|
10414
10527
|
exports.ERR_INVALID_ENTRY_COMMENT = ERR_INVALID_ENTRY_COMMENT;
|
|
10415
10528
|
exports.ERR_INVALID_ENTRY_COMMENT_TYPE = ERR_INVALID_ENTRY_COMMENT_TYPE;
|
|
@@ -10481,6 +10594,7 @@
|
|
|
10481
10594
|
exports.WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD = WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD;
|
|
10482
10595
|
exports.WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES = WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES;
|
|
10483
10596
|
exports.WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY = WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY;
|
|
10597
|
+
exports.WARNING_PREPENDED_CENTRAL_DIRECTORY = WARNING_PREPENDED_CENTRAL_DIRECTORY;
|
|
10484
10598
|
exports.WARNING_PREPENDED_DATA = WARNING_PREPENDED_DATA;
|
|
10485
10599
|
exports.WARNING_TRAILING_CENTRAL_DIRECTORY_DATA = WARNING_TRAILING_CENTRAL_DIRECTORY_DATA;
|
|
10486
10600
|
exports.WARNING_UNKNOWN_VERSION = WARNING_UNKNOWN_VERSION;
|