@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/index-native.cjs
CHANGED
|
@@ -8229,6 +8229,8 @@ setDefaultConfiguration({
|
|
|
8229
8229
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
8230
8230
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
8231
8231
|
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
8232
|
+
const ERR_ABORTED = "The operation was aborted";
|
|
8233
|
+
const ABORT_ERROR_NAME = "AbortError";
|
|
8232
8234
|
const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
|
|
8233
8235
|
const INTERPRETED_EXTRA_FIELD_TYPES = new Set([
|
|
8234
8236
|
EXTRAFIELD_TYPE_ZIP64,
|
|
@@ -8681,6 +8683,10 @@ class ZipDirectoryEntry extends ZipEntry {
|
|
|
8681
8683
|
}
|
|
8682
8684
|
}
|
|
8683
8685
|
|
|
8686
|
+
getChildren(options = {}) {
|
|
8687
|
+
return collectChildren(this, options.recursive);
|
|
8688
|
+
}
|
|
8689
|
+
|
|
8684
8690
|
isPasswordProtected() {
|
|
8685
8691
|
const children = this.children;
|
|
8686
8692
|
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
@@ -8772,6 +8778,10 @@ class FS {
|
|
|
8772
8778
|
return this.root.getChildByName(name);
|
|
8773
8779
|
}
|
|
8774
8780
|
|
|
8781
|
+
getChildren(options) {
|
|
8782
|
+
return this.root.getChildren(options);
|
|
8783
|
+
}
|
|
8784
|
+
|
|
8775
8785
|
addDirectory(name, options) {
|
|
8776
8786
|
return this.root.addDirectory(name, options);
|
|
8777
8787
|
}
|
|
@@ -9031,103 +9041,101 @@ function getUserExtraField(extraField) {
|
|
|
9031
9041
|
async function exportZip(zipWriter, entry, totalSize, options, readers) {
|
|
9032
9042
|
const selectedEntry = entry;
|
|
9033
9043
|
const entryOffsets = new Map();
|
|
9034
|
-
|
|
9044
|
+
if (options.bufferedWrite) {
|
|
9045
|
+
await processChildren(entry);
|
|
9046
|
+
} else {
|
|
9047
|
+
for (const child of entry.getChildren({ recursive: true })) {
|
|
9048
|
+
await addChild(child);
|
|
9049
|
+
}
|
|
9050
|
+
}
|
|
9035
9051
|
|
|
9036
|
-
async function
|
|
9037
|
-
await
|
|
9052
|
+
async function processChildren(entry) {
|
|
9053
|
+
const results = await Promise.allSettled(entry.children.map(async child => {
|
|
9054
|
+
await addChild(child);
|
|
9055
|
+
await processChildren(child);
|
|
9056
|
+
}));
|
|
9057
|
+
const errorResult = results.find(result => result.status == "rejected");
|
|
9058
|
+
if (errorResult) {
|
|
9059
|
+
throw errorResult.reason;
|
|
9060
|
+
}
|
|
9061
|
+
}
|
|
9038
9062
|
|
|
9039
|
-
|
|
9040
|
-
|
|
9041
|
-
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
|
|
9063
|
+
async function addChild(child) {
|
|
9064
|
+
const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
|
|
9065
|
+
const childOptions = child.options || {};
|
|
9066
|
+
let zipEntryOptions = {};
|
|
9067
|
+
if (child.data instanceof Entry) {
|
|
9068
|
+
const {
|
|
9069
|
+
externalFileAttributes,
|
|
9070
|
+
versionMadeBy,
|
|
9071
|
+
comment,
|
|
9072
|
+
lastModDate,
|
|
9073
|
+
creationDate,
|
|
9074
|
+
lastAccessDate,
|
|
9075
|
+
uncompressedSize,
|
|
9076
|
+
encrypted,
|
|
9077
|
+
zipCrypto,
|
|
9078
|
+
crc32,
|
|
9079
|
+
compressionMethod,
|
|
9080
|
+
extraFieldAES,
|
|
9081
|
+
internalFileAttributes,
|
|
9082
|
+
extraField,
|
|
9083
|
+
uid,
|
|
9084
|
+
gid
|
|
9085
|
+
} = child.data;
|
|
9086
|
+
zipEntryOptions = {
|
|
9087
|
+
externalFileAttributes,
|
|
9088
|
+
versionMadeBy,
|
|
9089
|
+
comment,
|
|
9090
|
+
lastModDate,
|
|
9091
|
+
creationDate,
|
|
9092
|
+
lastAccessDate,
|
|
9093
|
+
internalFileAttributes
|
|
9094
|
+
};
|
|
9095
|
+
const userExtraField = getUserExtraField(extraField);
|
|
9096
|
+
if (userExtraField) {
|
|
9097
|
+
zipEntryOptions.extraField = userExtraField;
|
|
9098
|
+
}
|
|
9099
|
+
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
9100
|
+
Object.assign(zipEntryOptions, {
|
|
9101
|
+
uid,
|
|
9102
|
+
gid,
|
|
9103
|
+
unixExtraFieldType: options.unixExtraFieldType || INFOZIP_EXTRA_FIELD_TYPE
|
|
9104
|
+
});
|
|
9105
|
+
}
|
|
9106
|
+
if (child.passThrough) {
|
|
9107
|
+
let level, encryptionStrength;
|
|
9108
|
+
if (compressionMethod === 0) {
|
|
9109
|
+
level = 0;
|
|
9045
9110
|
}
|
|
9046
|
-
|
|
9047
|
-
|
|
9048
|
-
await processChild(child);
|
|
9111
|
+
if (extraFieldAES) {
|
|
9112
|
+
encryptionStrength = extraFieldAES.strength;
|
|
9049
9113
|
}
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
async function processChild(child) {
|
|
9054
|
-
const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
|
|
9055
|
-
const childOptions = child.options || {};
|
|
9056
|
-
let zipEntryOptions = {};
|
|
9057
|
-
if (child.data instanceof Entry) {
|
|
9058
|
-
const {
|
|
9059
|
-
externalFileAttributes,
|
|
9060
|
-
versionMadeBy,
|
|
9061
|
-
comment,
|
|
9062
|
-
lastModDate,
|
|
9063
|
-
creationDate,
|
|
9064
|
-
lastAccessDate,
|
|
9065
|
-
uncompressedSize,
|
|
9114
|
+
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
9115
|
+
passThrough: true,
|
|
9066
9116
|
encrypted,
|
|
9067
9117
|
zipCrypto,
|
|
9068
9118
|
crc32,
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
gid
|
|
9075
|
-
} = child.data;
|
|
9076
|
-
zipEntryOptions = {
|
|
9077
|
-
externalFileAttributes,
|
|
9078
|
-
versionMadeBy,
|
|
9079
|
-
comment,
|
|
9080
|
-
lastModDate,
|
|
9081
|
-
creationDate,
|
|
9082
|
-
lastAccessDate,
|
|
9083
|
-
internalFileAttributes
|
|
9084
|
-
};
|
|
9085
|
-
const userExtraField = getUserExtraField(extraField);
|
|
9086
|
-
if (userExtraField) {
|
|
9087
|
-
zipEntryOptions.extraField = userExtraField;
|
|
9088
|
-
}
|
|
9089
|
-
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
9090
|
-
Object.assign(zipEntryOptions, {
|
|
9091
|
-
uid,
|
|
9092
|
-
gid,
|
|
9093
|
-
unixExtraFieldType: options.unixExtraFieldType || INFOZIP_EXTRA_FIELD_TYPE
|
|
9094
|
-
});
|
|
9095
|
-
}
|
|
9096
|
-
if (child.passThrough) {
|
|
9097
|
-
let level, encryptionStrength;
|
|
9098
|
-
if (compressionMethod === 0) {
|
|
9099
|
-
level = 0;
|
|
9100
|
-
}
|
|
9101
|
-
if (extraFieldAES) {
|
|
9102
|
-
encryptionStrength = extraFieldAES.strength;
|
|
9103
|
-
}
|
|
9104
|
-
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
9105
|
-
passThrough: true,
|
|
9106
|
-
encrypted,
|
|
9107
|
-
zipCrypto,
|
|
9108
|
-
crc32,
|
|
9109
|
-
uncompressedSize,
|
|
9110
|
-
level,
|
|
9111
|
-
encryptionStrength,
|
|
9112
|
-
compressionMethod
|
|
9113
|
-
});
|
|
9114
|
-
}
|
|
9119
|
+
uncompressedSize,
|
|
9120
|
+
level,
|
|
9121
|
+
encryptionStrength,
|
|
9122
|
+
compressionMethod
|
|
9123
|
+
});
|
|
9115
9124
|
}
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9125
|
+
}
|
|
9126
|
+
await zipWriter.add(name, readers.get(child), Object.assign({}, options, zipEntryOptions, childOptions, {
|
|
9127
|
+
directory: child.directory,
|
|
9128
|
+
onprogress: async indexProgress => {
|
|
9129
|
+
if (options.onprogress) {
|
|
9130
|
+
entryOffsets.set(name, indexProgress);
|
|
9131
|
+
try {
|
|
9132
|
+
await options.onprogress(Array.from(entryOffsets.values()).reduce((previousValue, currentValue) => previousValue + currentValue), totalSize);
|
|
9133
|
+
} catch {
|
|
9134
|
+
// ignored
|
|
9126
9135
|
}
|
|
9127
9136
|
}
|
|
9128
|
-
}
|
|
9129
|
-
|
|
9130
|
-
}
|
|
9137
|
+
}
|
|
9138
|
+
}));
|
|
9131
9139
|
}
|
|
9132
9140
|
}
|
|
9133
9141
|
|
|
@@ -9183,6 +9191,7 @@ async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
|
|
|
9183
9191
|
const { signal } = abortController;
|
|
9184
9192
|
const releaseSignal = forwardAbort(options.signal, abortController);
|
|
9185
9193
|
const exportedEntryNames = [];
|
|
9194
|
+
let exportAborted = false;
|
|
9186
9195
|
try {
|
|
9187
9196
|
await exportChildren(zipEntry, directoryHandle);
|
|
9188
9197
|
} catch (error) {
|
|
@@ -9215,10 +9224,10 @@ async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
|
|
|
9215
9224
|
|
|
9216
9225
|
async function exportChild(child, parentHandle) {
|
|
9217
9226
|
if (signal.aborted) {
|
|
9218
|
-
if (isExportAborted(signal.reason)) {
|
|
9227
|
+
if (exportAborted || isExportAborted(signal.reason)) {
|
|
9219
9228
|
return;
|
|
9220
9229
|
}
|
|
9221
|
-
throw signal.reason;
|
|
9230
|
+
throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
|
|
9222
9231
|
}
|
|
9223
9232
|
try {
|
|
9224
9233
|
if (child.directory) {
|
|
@@ -9227,22 +9236,27 @@ async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
|
|
|
9227
9236
|
} else {
|
|
9228
9237
|
const fileHandle = await parentHandle.getFileHandle(child.name, { create: true });
|
|
9229
9238
|
const writable = await fileHandle.createWritable();
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
+
try {
|
|
9240
|
+
await child.getData({ writable }, Object.assign({}, options, {
|
|
9241
|
+
signal,
|
|
9242
|
+
onprogress: async progress => {
|
|
9243
|
+
if (options.onprogress) {
|
|
9244
|
+
writtenSizes.set(child.id, progress);
|
|
9245
|
+
try {
|
|
9246
|
+
await options.onprogress(Array.from(writtenSizes.values()).reduce((previousValue, currentValue) => previousValue + currentValue, 0), totalSize);
|
|
9247
|
+
} catch {
|
|
9248
|
+
// ignored
|
|
9249
|
+
}
|
|
9239
9250
|
}
|
|
9240
9251
|
}
|
|
9241
|
-
}
|
|
9242
|
-
})
|
|
9252
|
+
}));
|
|
9253
|
+
} catch (error) {
|
|
9254
|
+
throw exportAborted ? new Error(ERR_ABORT_EXPORT) : error;
|
|
9255
|
+
}
|
|
9243
9256
|
exportedEntryNames.push(child.getRelativeName(zipEntry));
|
|
9244
9257
|
}
|
|
9245
9258
|
} catch (error) {
|
|
9259
|
+
exportAborted = true;
|
|
9246
9260
|
abortController.abort(new Error(ERR_ABORT_EXPORT));
|
|
9247
9261
|
try {
|
|
9248
9262
|
if (error.entryName === UNDEFINED_VALUE) {
|
|
@@ -9314,6 +9328,21 @@ function resetFS(fs) {
|
|
|
9314
9328
|
fs.root = new ZipDirectoryEntry(fs);
|
|
9315
9329
|
}
|
|
9316
9330
|
|
|
9331
|
+
function collectChildren(directory, recursive) {
|
|
9332
|
+
const children = [];
|
|
9333
|
+
const pendingDirectories = [directory];
|
|
9334
|
+
let directoryIndex = 0;
|
|
9335
|
+
while (directoryIndex < pendingDirectories.length) {
|
|
9336
|
+
for (const child of pendingDirectories[directoryIndex++].children) {
|
|
9337
|
+
children.push(child);
|
|
9338
|
+
if (recursive) {
|
|
9339
|
+
pendingDirectories.push(child);
|
|
9340
|
+
}
|
|
9341
|
+
}
|
|
9342
|
+
}
|
|
9343
|
+
return children;
|
|
9344
|
+
}
|
|
9345
|
+
|
|
9317
9346
|
function registerEntries(fs, entry) {
|
|
9318
9347
|
const pendingEntries = [entry];
|
|
9319
9348
|
while (pendingEntries.length) {
|
|
@@ -9432,6 +9461,7 @@ exports.BlobReader = BlobReader;
|
|
|
9432
9461
|
exports.BlobWriter = BlobWriter;
|
|
9433
9462
|
exports.Data64URIReader = Data64URIReader;
|
|
9434
9463
|
exports.Data64URIWriter = Data64URIWriter;
|
|
9464
|
+
exports.ERR_ABORTED = ERR_ABORTED;
|
|
9435
9465
|
exports.ERR_AMBIGUOUS_ARCHIVE = ERR_AMBIGUOUS_ARCHIVE;
|
|
9436
9466
|
exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
|
|
9437
9467
|
exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
|