@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-core.js
CHANGED
|
@@ -7043,6 +7043,8 @@
|
|
|
7043
7043
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
7044
7044
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
7045
7045
|
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
7046
|
+
const ERR_ABORTED = "The operation was aborted";
|
|
7047
|
+
const ABORT_ERROR_NAME = "AbortError";
|
|
7046
7048
|
const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
|
|
7047
7049
|
const INTERPRETED_EXTRA_FIELD_TYPES = new Set([
|
|
7048
7050
|
EXTRAFIELD_TYPE_ZIP64,
|
|
@@ -7495,6 +7497,10 @@
|
|
|
7495
7497
|
}
|
|
7496
7498
|
}
|
|
7497
7499
|
|
|
7500
|
+
getChildren(options = {}) {
|
|
7501
|
+
return collectChildren(this, options.recursive);
|
|
7502
|
+
}
|
|
7503
|
+
|
|
7498
7504
|
isPasswordProtected() {
|
|
7499
7505
|
const children = this.children;
|
|
7500
7506
|
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
@@ -7586,6 +7592,10 @@
|
|
|
7586
7592
|
return this.root.getChildByName(name);
|
|
7587
7593
|
}
|
|
7588
7594
|
|
|
7595
|
+
getChildren(options) {
|
|
7596
|
+
return this.root.getChildren(options);
|
|
7597
|
+
}
|
|
7598
|
+
|
|
7589
7599
|
addDirectory(name, options) {
|
|
7590
7600
|
return this.root.addDirectory(name, options);
|
|
7591
7601
|
}
|
|
@@ -7845,103 +7855,101 @@
|
|
|
7845
7855
|
async function exportZip(zipWriter, entry, totalSize, options, readers) {
|
|
7846
7856
|
const selectedEntry = entry;
|
|
7847
7857
|
const entryOffsets = new Map();
|
|
7848
|
-
|
|
7858
|
+
if (options.bufferedWrite) {
|
|
7859
|
+
await processChildren(entry);
|
|
7860
|
+
} else {
|
|
7861
|
+
for (const child of entry.getChildren({ recursive: true })) {
|
|
7862
|
+
await addChild(child);
|
|
7863
|
+
}
|
|
7864
|
+
}
|
|
7849
7865
|
|
|
7850
|
-
async function
|
|
7851
|
-
await
|
|
7866
|
+
async function processChildren(entry) {
|
|
7867
|
+
const results = await Promise.allSettled(entry.children.map(async child => {
|
|
7868
|
+
await addChild(child);
|
|
7869
|
+
await processChildren(child);
|
|
7870
|
+
}));
|
|
7871
|
+
const errorResult = results.find(result => result.status == "rejected");
|
|
7872
|
+
if (errorResult) {
|
|
7873
|
+
throw errorResult.reason;
|
|
7874
|
+
}
|
|
7875
|
+
}
|
|
7852
7876
|
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7877
|
+
async function addChild(child) {
|
|
7878
|
+
const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
|
|
7879
|
+
const childOptions = child.options || {};
|
|
7880
|
+
let zipEntryOptions = {};
|
|
7881
|
+
if (child.data instanceof Entry) {
|
|
7882
|
+
const {
|
|
7883
|
+
externalFileAttributes,
|
|
7884
|
+
versionMadeBy,
|
|
7885
|
+
comment,
|
|
7886
|
+
lastModDate,
|
|
7887
|
+
creationDate,
|
|
7888
|
+
lastAccessDate,
|
|
7889
|
+
uncompressedSize,
|
|
7890
|
+
encrypted,
|
|
7891
|
+
zipCrypto,
|
|
7892
|
+
crc32,
|
|
7893
|
+
compressionMethod,
|
|
7894
|
+
extraFieldAES,
|
|
7895
|
+
internalFileAttributes,
|
|
7896
|
+
extraField,
|
|
7897
|
+
uid,
|
|
7898
|
+
gid
|
|
7899
|
+
} = child.data;
|
|
7900
|
+
zipEntryOptions = {
|
|
7901
|
+
externalFileAttributes,
|
|
7902
|
+
versionMadeBy,
|
|
7903
|
+
comment,
|
|
7904
|
+
lastModDate,
|
|
7905
|
+
creationDate,
|
|
7906
|
+
lastAccessDate,
|
|
7907
|
+
internalFileAttributes
|
|
7908
|
+
};
|
|
7909
|
+
const userExtraField = getUserExtraField(extraField);
|
|
7910
|
+
if (userExtraField) {
|
|
7911
|
+
zipEntryOptions.extraField = userExtraField;
|
|
7912
|
+
}
|
|
7913
|
+
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
7914
|
+
Object.assign(zipEntryOptions, {
|
|
7915
|
+
uid,
|
|
7916
|
+
gid,
|
|
7917
|
+
unixExtraFieldType: options.unixExtraFieldType || INFOZIP_EXTRA_FIELD_TYPE
|
|
7918
|
+
});
|
|
7919
|
+
}
|
|
7920
|
+
if (child.passThrough) {
|
|
7921
|
+
let level, encryptionStrength;
|
|
7922
|
+
if (compressionMethod === 0) {
|
|
7923
|
+
level = 0;
|
|
7859
7924
|
}
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
await processChild(child);
|
|
7925
|
+
if (extraFieldAES) {
|
|
7926
|
+
encryptionStrength = extraFieldAES.strength;
|
|
7863
7927
|
}
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
async function processChild(child) {
|
|
7868
|
-
const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
|
|
7869
|
-
const childOptions = child.options || {};
|
|
7870
|
-
let zipEntryOptions = {};
|
|
7871
|
-
if (child.data instanceof Entry) {
|
|
7872
|
-
const {
|
|
7873
|
-
externalFileAttributes,
|
|
7874
|
-
versionMadeBy,
|
|
7875
|
-
comment,
|
|
7876
|
-
lastModDate,
|
|
7877
|
-
creationDate,
|
|
7878
|
-
lastAccessDate,
|
|
7879
|
-
uncompressedSize,
|
|
7928
|
+
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
7929
|
+
passThrough: true,
|
|
7880
7930
|
encrypted,
|
|
7881
7931
|
zipCrypto,
|
|
7882
7932
|
crc32,
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
gid
|
|
7889
|
-
} = child.data;
|
|
7890
|
-
zipEntryOptions = {
|
|
7891
|
-
externalFileAttributes,
|
|
7892
|
-
versionMadeBy,
|
|
7893
|
-
comment,
|
|
7894
|
-
lastModDate,
|
|
7895
|
-
creationDate,
|
|
7896
|
-
lastAccessDate,
|
|
7897
|
-
internalFileAttributes
|
|
7898
|
-
};
|
|
7899
|
-
const userExtraField = getUserExtraField(extraField);
|
|
7900
|
-
if (userExtraField) {
|
|
7901
|
-
zipEntryOptions.extraField = userExtraField;
|
|
7902
|
-
}
|
|
7903
|
-
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
7904
|
-
Object.assign(zipEntryOptions, {
|
|
7905
|
-
uid,
|
|
7906
|
-
gid,
|
|
7907
|
-
unixExtraFieldType: options.unixExtraFieldType || INFOZIP_EXTRA_FIELD_TYPE
|
|
7908
|
-
});
|
|
7909
|
-
}
|
|
7910
|
-
if (child.passThrough) {
|
|
7911
|
-
let level, encryptionStrength;
|
|
7912
|
-
if (compressionMethod === 0) {
|
|
7913
|
-
level = 0;
|
|
7914
|
-
}
|
|
7915
|
-
if (extraFieldAES) {
|
|
7916
|
-
encryptionStrength = extraFieldAES.strength;
|
|
7917
|
-
}
|
|
7918
|
-
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
7919
|
-
passThrough: true,
|
|
7920
|
-
encrypted,
|
|
7921
|
-
zipCrypto,
|
|
7922
|
-
crc32,
|
|
7923
|
-
uncompressedSize,
|
|
7924
|
-
level,
|
|
7925
|
-
encryptionStrength,
|
|
7926
|
-
compressionMethod
|
|
7927
|
-
});
|
|
7928
|
-
}
|
|
7933
|
+
uncompressedSize,
|
|
7934
|
+
level,
|
|
7935
|
+
encryptionStrength,
|
|
7936
|
+
compressionMethod
|
|
7937
|
+
});
|
|
7929
7938
|
}
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
|
|
7939
|
-
|
|
7939
|
+
}
|
|
7940
|
+
await zipWriter.add(name, readers.get(child), Object.assign({}, options, zipEntryOptions, childOptions, {
|
|
7941
|
+
directory: child.directory,
|
|
7942
|
+
onprogress: async indexProgress => {
|
|
7943
|
+
if (options.onprogress) {
|
|
7944
|
+
entryOffsets.set(name, indexProgress);
|
|
7945
|
+
try {
|
|
7946
|
+
await options.onprogress(Array.from(entryOffsets.values()).reduce((previousValue, currentValue) => previousValue + currentValue), totalSize);
|
|
7947
|
+
} catch {
|
|
7948
|
+
// ignored
|
|
7940
7949
|
}
|
|
7941
7950
|
}
|
|
7942
|
-
}
|
|
7943
|
-
|
|
7944
|
-
}
|
|
7951
|
+
}
|
|
7952
|
+
}));
|
|
7945
7953
|
}
|
|
7946
7954
|
}
|
|
7947
7955
|
|
|
@@ -7997,6 +8005,7 @@
|
|
|
7997
8005
|
const { signal } = abortController;
|
|
7998
8006
|
const releaseSignal = forwardAbort(options.signal, abortController);
|
|
7999
8007
|
const exportedEntryNames = [];
|
|
8008
|
+
let exportAborted = false;
|
|
8000
8009
|
try {
|
|
8001
8010
|
await exportChildren(zipEntry, directoryHandle);
|
|
8002
8011
|
} catch (error) {
|
|
@@ -8029,10 +8038,10 @@
|
|
|
8029
8038
|
|
|
8030
8039
|
async function exportChild(child, parentHandle) {
|
|
8031
8040
|
if (signal.aborted) {
|
|
8032
|
-
if (isExportAborted(signal.reason)) {
|
|
8041
|
+
if (exportAborted || isExportAborted(signal.reason)) {
|
|
8033
8042
|
return;
|
|
8034
8043
|
}
|
|
8035
|
-
throw signal.reason;
|
|
8044
|
+
throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
|
|
8036
8045
|
}
|
|
8037
8046
|
try {
|
|
8038
8047
|
if (child.directory) {
|
|
@@ -8041,22 +8050,27 @@
|
|
|
8041
8050
|
} else {
|
|
8042
8051
|
const fileHandle = await parentHandle.getFileHandle(child.name, { create: true });
|
|
8043
8052
|
const writable = await fileHandle.createWritable();
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
+
try {
|
|
8054
|
+
await child.getData({ writable }, Object.assign({}, options, {
|
|
8055
|
+
signal,
|
|
8056
|
+
onprogress: async progress => {
|
|
8057
|
+
if (options.onprogress) {
|
|
8058
|
+
writtenSizes.set(child.id, progress);
|
|
8059
|
+
try {
|
|
8060
|
+
await options.onprogress(Array.from(writtenSizes.values()).reduce((previousValue, currentValue) => previousValue + currentValue, 0), totalSize);
|
|
8061
|
+
} catch {
|
|
8062
|
+
// ignored
|
|
8063
|
+
}
|
|
8053
8064
|
}
|
|
8054
8065
|
}
|
|
8055
|
-
}
|
|
8056
|
-
})
|
|
8066
|
+
}));
|
|
8067
|
+
} catch (error) {
|
|
8068
|
+
throw exportAborted ? new Error(ERR_ABORT_EXPORT) : error;
|
|
8069
|
+
}
|
|
8057
8070
|
exportedEntryNames.push(child.getRelativeName(zipEntry));
|
|
8058
8071
|
}
|
|
8059
8072
|
} catch (error) {
|
|
8073
|
+
exportAborted = true;
|
|
8060
8074
|
abortController.abort(new Error(ERR_ABORT_EXPORT));
|
|
8061
8075
|
try {
|
|
8062
8076
|
if (error.entryName === UNDEFINED_VALUE) {
|
|
@@ -8128,6 +8142,21 @@
|
|
|
8128
8142
|
fs.root = new ZipDirectoryEntry(fs);
|
|
8129
8143
|
}
|
|
8130
8144
|
|
|
8145
|
+
function collectChildren(directory, recursive) {
|
|
8146
|
+
const children = [];
|
|
8147
|
+
const pendingDirectories = [directory];
|
|
8148
|
+
let directoryIndex = 0;
|
|
8149
|
+
while (directoryIndex < pendingDirectories.length) {
|
|
8150
|
+
for (const child of pendingDirectories[directoryIndex++].children) {
|
|
8151
|
+
children.push(child);
|
|
8152
|
+
if (recursive) {
|
|
8153
|
+
pendingDirectories.push(child);
|
|
8154
|
+
}
|
|
8155
|
+
}
|
|
8156
|
+
}
|
|
8157
|
+
return children;
|
|
8158
|
+
}
|
|
8159
|
+
|
|
8131
8160
|
function registerEntries(fs, entry) {
|
|
8132
8161
|
const pendingEntries = [entry];
|
|
8133
8162
|
while (pendingEntries.length) {
|
|
@@ -8147,6 +8176,7 @@
|
|
|
8147
8176
|
}
|
|
8148
8177
|
}
|
|
8149
8178
|
|
|
8179
|
+
exports.ERR_ABORTED = ERR_ABORTED;
|
|
8150
8180
|
exports.ERR_ENTRY_EXISTS = ERR_ENTRY_EXISTS;
|
|
8151
8181
|
exports.ERR_READABLE_CONSUMED = ERR_READABLE_CONSUMED;
|
|
8152
8182
|
exports.fs = fs;
|