@zip.js/zip.js 2.8.50 → 2.8.51
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-fs-core-external.js +130 -101
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +130 -100
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +130 -101
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +130 -100
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +130 -100
- package/dist/zip-fs.min.js +1 -1
- package/index-native.cjs +130 -100
- package/index-native.min.js +1 -1
- package/index.cjs +130 -100
- package/index.d.cts +43 -0
- package/index.d.ts +43 -0
- package/index.min.js +1 -1
- package/lib/core/zip-fs.js +131 -102
- package/package.json +1 -1
package/dist/zip-fs.js
CHANGED
|
@@ -8604,6 +8604,8 @@
|
|
|
8604
8604
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
8605
8605
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
8606
8606
|
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
8607
|
+
const ERR_ABORTED = "The operation was aborted";
|
|
8608
|
+
const ABORT_ERROR_NAME = "AbortError";
|
|
8607
8609
|
const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
|
|
8608
8610
|
const INTERPRETED_EXTRA_FIELD_TYPES = new Set([
|
|
8609
8611
|
EXTRAFIELD_TYPE_ZIP64,
|
|
@@ -9056,6 +9058,10 @@
|
|
|
9056
9058
|
}
|
|
9057
9059
|
}
|
|
9058
9060
|
|
|
9061
|
+
getChildren(options = {}) {
|
|
9062
|
+
return collectChildren(this, options.recursive);
|
|
9063
|
+
}
|
|
9064
|
+
|
|
9059
9065
|
isPasswordProtected() {
|
|
9060
9066
|
const children = this.children;
|
|
9061
9067
|
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
@@ -9147,6 +9153,10 @@
|
|
|
9147
9153
|
return this.root.getChildByName(name);
|
|
9148
9154
|
}
|
|
9149
9155
|
|
|
9156
|
+
getChildren(options) {
|
|
9157
|
+
return this.root.getChildren(options);
|
|
9158
|
+
}
|
|
9159
|
+
|
|
9150
9160
|
addDirectory(name, options) {
|
|
9151
9161
|
return this.root.addDirectory(name, options);
|
|
9152
9162
|
}
|
|
@@ -9406,103 +9416,101 @@
|
|
|
9406
9416
|
async function exportZip(zipWriter, entry, totalSize, options, readers) {
|
|
9407
9417
|
const selectedEntry = entry;
|
|
9408
9418
|
const entryOffsets = new Map();
|
|
9409
|
-
|
|
9419
|
+
if (options.bufferedWrite) {
|
|
9420
|
+
await processChildren(entry);
|
|
9421
|
+
} else {
|
|
9422
|
+
for (const child of entry.getChildren({ recursive: true })) {
|
|
9423
|
+
await addChild(child);
|
|
9424
|
+
}
|
|
9425
|
+
}
|
|
9410
9426
|
|
|
9411
|
-
async function
|
|
9412
|
-
await
|
|
9427
|
+
async function processChildren(entry) {
|
|
9428
|
+
const results = await Promise.allSettled(entry.children.map(async child => {
|
|
9429
|
+
await addChild(child);
|
|
9430
|
+
await processChildren(child);
|
|
9431
|
+
}));
|
|
9432
|
+
const errorResult = results.find(result => result.status == "rejected");
|
|
9433
|
+
if (errorResult) {
|
|
9434
|
+
throw errorResult.reason;
|
|
9435
|
+
}
|
|
9436
|
+
}
|
|
9413
9437
|
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9438
|
+
async function addChild(child) {
|
|
9439
|
+
const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
|
|
9440
|
+
const childOptions = child.options || {};
|
|
9441
|
+
let zipEntryOptions = {};
|
|
9442
|
+
if (child.data instanceof Entry) {
|
|
9443
|
+
const {
|
|
9444
|
+
externalFileAttributes,
|
|
9445
|
+
versionMadeBy,
|
|
9446
|
+
comment,
|
|
9447
|
+
lastModDate,
|
|
9448
|
+
creationDate,
|
|
9449
|
+
lastAccessDate,
|
|
9450
|
+
uncompressedSize,
|
|
9451
|
+
encrypted,
|
|
9452
|
+
zipCrypto,
|
|
9453
|
+
crc32,
|
|
9454
|
+
compressionMethod,
|
|
9455
|
+
extraFieldAES,
|
|
9456
|
+
internalFileAttributes,
|
|
9457
|
+
extraField,
|
|
9458
|
+
uid,
|
|
9459
|
+
gid
|
|
9460
|
+
} = child.data;
|
|
9461
|
+
zipEntryOptions = {
|
|
9462
|
+
externalFileAttributes,
|
|
9463
|
+
versionMadeBy,
|
|
9464
|
+
comment,
|
|
9465
|
+
lastModDate,
|
|
9466
|
+
creationDate,
|
|
9467
|
+
lastAccessDate,
|
|
9468
|
+
internalFileAttributes
|
|
9469
|
+
};
|
|
9470
|
+
const userExtraField = getUserExtraField(extraField);
|
|
9471
|
+
if (userExtraField) {
|
|
9472
|
+
zipEntryOptions.extraField = userExtraField;
|
|
9473
|
+
}
|
|
9474
|
+
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
9475
|
+
Object.assign(zipEntryOptions, {
|
|
9476
|
+
uid,
|
|
9477
|
+
gid,
|
|
9478
|
+
unixExtraFieldType: options.unixExtraFieldType || INFOZIP_EXTRA_FIELD_TYPE
|
|
9479
|
+
});
|
|
9480
|
+
}
|
|
9481
|
+
if (child.passThrough) {
|
|
9482
|
+
let level, encryptionStrength;
|
|
9483
|
+
if (compressionMethod === 0) {
|
|
9484
|
+
level = 0;
|
|
9420
9485
|
}
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
await processChild(child);
|
|
9486
|
+
if (extraFieldAES) {
|
|
9487
|
+
encryptionStrength = extraFieldAES.strength;
|
|
9424
9488
|
}
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
async function processChild(child) {
|
|
9429
|
-
const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
|
|
9430
|
-
const childOptions = child.options || {};
|
|
9431
|
-
let zipEntryOptions = {};
|
|
9432
|
-
if (child.data instanceof Entry) {
|
|
9433
|
-
const {
|
|
9434
|
-
externalFileAttributes,
|
|
9435
|
-
versionMadeBy,
|
|
9436
|
-
comment,
|
|
9437
|
-
lastModDate,
|
|
9438
|
-
creationDate,
|
|
9439
|
-
lastAccessDate,
|
|
9440
|
-
uncompressedSize,
|
|
9489
|
+
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
9490
|
+
passThrough: true,
|
|
9441
9491
|
encrypted,
|
|
9442
9492
|
zipCrypto,
|
|
9443
9493
|
crc32,
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
gid
|
|
9450
|
-
} = child.data;
|
|
9451
|
-
zipEntryOptions = {
|
|
9452
|
-
externalFileAttributes,
|
|
9453
|
-
versionMadeBy,
|
|
9454
|
-
comment,
|
|
9455
|
-
lastModDate,
|
|
9456
|
-
creationDate,
|
|
9457
|
-
lastAccessDate,
|
|
9458
|
-
internalFileAttributes
|
|
9459
|
-
};
|
|
9460
|
-
const userExtraField = getUserExtraField(extraField);
|
|
9461
|
-
if (userExtraField) {
|
|
9462
|
-
zipEntryOptions.extraField = userExtraField;
|
|
9463
|
-
}
|
|
9464
|
-
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
9465
|
-
Object.assign(zipEntryOptions, {
|
|
9466
|
-
uid,
|
|
9467
|
-
gid,
|
|
9468
|
-
unixExtraFieldType: options.unixExtraFieldType || INFOZIP_EXTRA_FIELD_TYPE
|
|
9469
|
-
});
|
|
9470
|
-
}
|
|
9471
|
-
if (child.passThrough) {
|
|
9472
|
-
let level, encryptionStrength;
|
|
9473
|
-
if (compressionMethod === 0) {
|
|
9474
|
-
level = 0;
|
|
9475
|
-
}
|
|
9476
|
-
if (extraFieldAES) {
|
|
9477
|
-
encryptionStrength = extraFieldAES.strength;
|
|
9478
|
-
}
|
|
9479
|
-
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
9480
|
-
passThrough: true,
|
|
9481
|
-
encrypted,
|
|
9482
|
-
zipCrypto,
|
|
9483
|
-
crc32,
|
|
9484
|
-
uncompressedSize,
|
|
9485
|
-
level,
|
|
9486
|
-
encryptionStrength,
|
|
9487
|
-
compressionMethod
|
|
9488
|
-
});
|
|
9489
|
-
}
|
|
9494
|
+
uncompressedSize,
|
|
9495
|
+
level,
|
|
9496
|
+
encryptionStrength,
|
|
9497
|
+
compressionMethod
|
|
9498
|
+
});
|
|
9490
9499
|
}
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9500
|
+
}
|
|
9501
|
+
await zipWriter.add(name, readers.get(child), Object.assign({}, options, zipEntryOptions, childOptions, {
|
|
9502
|
+
directory: child.directory,
|
|
9503
|
+
onprogress: async indexProgress => {
|
|
9504
|
+
if (options.onprogress) {
|
|
9505
|
+
entryOffsets.set(name, indexProgress);
|
|
9506
|
+
try {
|
|
9507
|
+
await options.onprogress(Array.from(entryOffsets.values()).reduce((previousValue, currentValue) => previousValue + currentValue), totalSize);
|
|
9508
|
+
} catch {
|
|
9509
|
+
// ignored
|
|
9501
9510
|
}
|
|
9502
9511
|
}
|
|
9503
|
-
}
|
|
9504
|
-
|
|
9505
|
-
}
|
|
9512
|
+
}
|
|
9513
|
+
}));
|
|
9506
9514
|
}
|
|
9507
9515
|
}
|
|
9508
9516
|
|
|
@@ -9558,6 +9566,7 @@
|
|
|
9558
9566
|
const { signal } = abortController;
|
|
9559
9567
|
const releaseSignal = forwardAbort(options.signal, abortController);
|
|
9560
9568
|
const exportedEntryNames = [];
|
|
9569
|
+
let exportAborted = false;
|
|
9561
9570
|
try {
|
|
9562
9571
|
await exportChildren(zipEntry, directoryHandle);
|
|
9563
9572
|
} catch (error) {
|
|
@@ -9590,10 +9599,10 @@
|
|
|
9590
9599
|
|
|
9591
9600
|
async function exportChild(child, parentHandle) {
|
|
9592
9601
|
if (signal.aborted) {
|
|
9593
|
-
if (isExportAborted(signal.reason)) {
|
|
9602
|
+
if (exportAborted || isExportAborted(signal.reason)) {
|
|
9594
9603
|
return;
|
|
9595
9604
|
}
|
|
9596
|
-
throw signal.reason;
|
|
9605
|
+
throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
|
|
9597
9606
|
}
|
|
9598
9607
|
try {
|
|
9599
9608
|
if (child.directory) {
|
|
@@ -9602,22 +9611,27 @@
|
|
|
9602
9611
|
} else {
|
|
9603
9612
|
const fileHandle = await parentHandle.getFileHandle(child.name, { create: true });
|
|
9604
9613
|
const writable = await fileHandle.createWritable();
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
+
try {
|
|
9615
|
+
await child.getData({ writable }, Object.assign({}, options, {
|
|
9616
|
+
signal,
|
|
9617
|
+
onprogress: async progress => {
|
|
9618
|
+
if (options.onprogress) {
|
|
9619
|
+
writtenSizes.set(child.id, progress);
|
|
9620
|
+
try {
|
|
9621
|
+
await options.onprogress(Array.from(writtenSizes.values()).reduce((previousValue, currentValue) => previousValue + currentValue, 0), totalSize);
|
|
9622
|
+
} catch {
|
|
9623
|
+
// ignored
|
|
9624
|
+
}
|
|
9614
9625
|
}
|
|
9615
9626
|
}
|
|
9616
|
-
}
|
|
9617
|
-
})
|
|
9627
|
+
}));
|
|
9628
|
+
} catch (error) {
|
|
9629
|
+
throw exportAborted ? new Error(ERR_ABORT_EXPORT) : error;
|
|
9630
|
+
}
|
|
9618
9631
|
exportedEntryNames.push(child.getRelativeName(zipEntry));
|
|
9619
9632
|
}
|
|
9620
9633
|
} catch (error) {
|
|
9634
|
+
exportAborted = true;
|
|
9621
9635
|
abortController.abort(new Error(ERR_ABORT_EXPORT));
|
|
9622
9636
|
try {
|
|
9623
9637
|
if (error.entryName === UNDEFINED_VALUE) {
|
|
@@ -9689,6 +9703,21 @@
|
|
|
9689
9703
|
fs.root = new ZipDirectoryEntry(fs);
|
|
9690
9704
|
}
|
|
9691
9705
|
|
|
9706
|
+
function collectChildren(directory, recursive) {
|
|
9707
|
+
const children = [];
|
|
9708
|
+
const pendingDirectories = [directory];
|
|
9709
|
+
let directoryIndex = 0;
|
|
9710
|
+
while (directoryIndex < pendingDirectories.length) {
|
|
9711
|
+
for (const child of pendingDirectories[directoryIndex++].children) {
|
|
9712
|
+
children.push(child);
|
|
9713
|
+
if (recursive) {
|
|
9714
|
+
pendingDirectories.push(child);
|
|
9715
|
+
}
|
|
9716
|
+
}
|
|
9717
|
+
}
|
|
9718
|
+
return children;
|
|
9719
|
+
}
|
|
9720
|
+
|
|
9692
9721
|
function registerEntries(fs, entry) {
|
|
9693
9722
|
const pendingEntries = [entry];
|
|
9694
9723
|
while (pendingEntries.length) {
|
|
@@ -9807,6 +9836,7 @@
|
|
|
9807
9836
|
exports.BlobWriter = BlobWriter;
|
|
9808
9837
|
exports.Data64URIReader = Data64URIReader;
|
|
9809
9838
|
exports.Data64URIWriter = Data64URIWriter;
|
|
9839
|
+
exports.ERR_ABORTED = ERR_ABORTED;
|
|
9810
9840
|
exports.ERR_AMBIGUOUS_ARCHIVE = ERR_AMBIGUOUS_ARCHIVE;
|
|
9811
9841
|
exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
|
|
9812
9842
|
exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
|