@zip.js/zip.js 2.21.0 → 2.22.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/deno.json +1 -1
- package/dist/zip-core-external.js +30 -15
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +30 -14
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +30 -18
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +30 -18
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +30 -18
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +30 -18
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +30 -18
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +30 -14
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +30 -14
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +30 -14
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +30 -18
- package/index-native.min.js +1 -1
- package/index.cjs +30 -18
- package/index.d.cts +36 -14
- package/index.d.ts +36 -14
- package/index.min.js +1 -1
- package/lib/core/configuration.js +1 -3
- package/lib/core/options.js +11 -0
- package/lib/core/version.js +1 -1
- package/lib/core/zip-fs.js +2 -6
- package/lib/core/zip-reader.js +1 -1
- package/lib/core/zip-writer.js +19 -9
- package/lib/zip-core-base.js +1 -0
- package/package.json +1 -1
|
@@ -63,7 +63,6 @@ const DEFAULT_CONFIGURATION = {
|
|
|
63
63
|
workerStartupTimeout: 5000,
|
|
64
64
|
useWebWorkers: true,
|
|
65
65
|
useCompressionStream: true,
|
|
66
|
-
transferStreams: true,
|
|
67
66
|
CompressionStream: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
|
|
68
67
|
DecompressionStream: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
|
|
69
68
|
};
|
|
@@ -77,8 +76,7 @@ const URI_PROPERTY_NAMES = [
|
|
|
77
76
|
];
|
|
78
77
|
const BOOLEAN_PROPERTY_NAMES = [
|
|
79
78
|
"useCompressionStream",
|
|
80
|
-
"useWebWorkers"
|
|
81
|
-
"transferStreams"
|
|
79
|
+
"useWebWorkers"
|
|
82
80
|
];
|
|
83
81
|
const NUMBER_PROPERTY_NAMES = [
|
|
84
82
|
"chunkSize",
|
package/lib/core/options.js
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
BOOLEAN_TYPE,
|
|
33
33
|
FUNCTION_TYPE,
|
|
34
34
|
STRING_TYPE,
|
|
35
|
+
OBJECT_TYPE,
|
|
35
36
|
UNDEFINED_VALUE
|
|
36
37
|
} from "./constants.js";
|
|
37
38
|
|
|
@@ -91,6 +92,7 @@ const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
|
|
|
91
92
|
const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
|
|
92
93
|
const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
|
|
93
94
|
const ERR_INVALID_PASS_THROUGH_VALUE = "Invalid passThrough option (must be a boolean or 'compressed')";
|
|
95
|
+
const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
|
|
94
96
|
const ERR_ABORTED = "The operation was aborted";
|
|
95
97
|
const ABORT_ERROR_NAME = "AbortError";
|
|
96
98
|
|
|
@@ -150,9 +152,11 @@ export {
|
|
|
150
152
|
ERR_INVALID_SIGNAL,
|
|
151
153
|
ERR_INVALID_PASSWORD_TYPE,
|
|
152
154
|
ERR_INVALID_PASS_THROUGH_VALUE,
|
|
155
|
+
ERR_INVALID_READER_OPTIONS,
|
|
153
156
|
ERR_ABORTED,
|
|
154
157
|
ABORT_ERROR_NAME,
|
|
155
158
|
checkFunctionOption,
|
|
159
|
+
checkReaderOptionsObject,
|
|
156
160
|
checkSignalOption,
|
|
157
161
|
throwIfAborted,
|
|
158
162
|
checkPasswordOption,
|
|
@@ -169,6 +173,13 @@ function checkFunctionOption(value) {
|
|
|
169
173
|
return value;
|
|
170
174
|
}
|
|
171
175
|
|
|
176
|
+
function checkReaderOptionsObject(readerOptions) {
|
|
177
|
+
if (readerOptions && (typeof readerOptions != OBJECT_TYPE || Array.isArray(readerOptions))) {
|
|
178
|
+
throw new Error(ERR_INVALID_READER_OPTIONS);
|
|
179
|
+
}
|
|
180
|
+
return readerOptions;
|
|
181
|
+
}
|
|
182
|
+
|
|
172
183
|
function checkSignalOption(signal) {
|
|
173
184
|
if (signal && (typeof signal.addEventListener != FUNCTION_TYPE || typeof signal.aborted != BOOLEAN_TYPE)) {
|
|
174
185
|
throw new Error(ERR_INVALID_SIGNAL);
|
package/lib/core/version.js
CHANGED
package/lib/core/zip-fs.js
CHANGED
|
@@ -60,12 +60,11 @@ import {
|
|
|
60
60
|
import {
|
|
61
61
|
Entry
|
|
62
62
|
} from "./zip-entry.js";
|
|
63
|
-
import { checkSignalOption, throwIfAborted, checkPassThroughOption, PASS_THROUGH_COMPRESSED } from "./options.js";
|
|
63
|
+
import { checkSignalOption, throwIfAborted, checkPassThroughOption, checkReaderOptionsObject, PASS_THROUGH_COMPRESSED, ERR_INVALID_READER_OPTIONS } from "./options.js";
|
|
64
64
|
import { ProgressWatcherStream, callHandler } from "./codec-worker.js";
|
|
65
65
|
import {
|
|
66
66
|
UNDEFINED_VALUE,
|
|
67
67
|
FUNCTION_TYPE,
|
|
68
|
-
OBJECT_TYPE,
|
|
69
68
|
STRING_TYPE
|
|
70
69
|
} from "./constants.js";
|
|
71
70
|
import { toExactUint8Array } from "./util/array.js";
|
|
@@ -85,7 +84,6 @@ const DUPLICATES_KEEP_FIRST = "keep-first";
|
|
|
85
84
|
const DUPLICATES_KEEP_LAST = "keep-last";
|
|
86
85
|
const DUPLICATES_VALUES = new Set([DUPLICATES_THROW, DUPLICATES_KEEP_FIRST, DUPLICATES_KEEP_LAST]);
|
|
87
86
|
const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
|
|
88
|
-
const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
|
|
89
87
|
const ERR_UNSUPPORTED_PASS_THROUGH_VALUE = "The 'compressed' passThrough option is only supported by Entry#getData() and ZipWriter#add()";
|
|
90
88
|
const ERR_INVALID_PASSWORDS = "Invalid passwords option (must be an array of strings)";
|
|
91
89
|
const ERR_INVALID_REQUEST_PASSWORD = "Invalid requestPassword option (must be a function returning a string or undefined)";
|
|
@@ -1012,9 +1010,7 @@ function getDeterminedSize(child, passThrough) {
|
|
|
1012
1010
|
}
|
|
1013
1011
|
|
|
1014
1012
|
function checkReaderOptions(readerOptions) {
|
|
1015
|
-
|
|
1016
|
-
throw new Error(ERR_INVALID_READER_OPTIONS);
|
|
1017
|
-
}
|
|
1013
|
+
checkReaderOptionsObject(readerOptions);
|
|
1018
1014
|
if (readerOptions) {
|
|
1019
1015
|
checkPassThroughValue(readerOptions.passThrough);
|
|
1020
1016
|
checkPasswordCandidatesOptions(readerOptions);
|
package/lib/core/zip-reader.js
CHANGED
|
@@ -257,7 +257,7 @@ class ZipReader {
|
|
|
257
257
|
constructor(reader, options = {}) {
|
|
258
258
|
Object.assign(this, {
|
|
259
259
|
reader: new GenericReader(reader),
|
|
260
|
-
options,
|
|
260
|
+
options: options || {},
|
|
261
261
|
readRanges: { indexes: new Set(), sortedRanges: [], pendingRanges: [] },
|
|
262
262
|
entriesMissingZip64ExtraField: new WeakSet()
|
|
263
263
|
});
|
package/lib/core/zip-writer.js
CHANGED
|
@@ -243,6 +243,7 @@ import {
|
|
|
243
243
|
TEXT_TYPE_COMMENT,
|
|
244
244
|
ERR_INVALID_PASSWORD_TYPE,
|
|
245
245
|
checkFunctionOption,
|
|
246
|
+
checkReaderOptionsObject,
|
|
246
247
|
checkSignalOption,
|
|
247
248
|
throwIfAborted,
|
|
248
249
|
checkPasswordOption,
|
|
@@ -510,6 +511,7 @@ function watchPromiseError(zipWriter, promise) {
|
|
|
510
511
|
async function appendZipEntries(zipWriter, reader, options = {}) {
|
|
511
512
|
const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
|
|
512
513
|
const filter = checkFunctionOption(options.filter);
|
|
514
|
+
const readerOptions = checkReaderOptionsObject(options.readerOptions);
|
|
513
515
|
while (pendingAddFileCalls.size) {
|
|
514
516
|
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
515
517
|
}
|
|
@@ -526,15 +528,19 @@ async function appendZipEntries(zipWriter, reader, options = {}) {
|
|
|
526
528
|
await initStream(reader);
|
|
527
529
|
}
|
|
528
530
|
const { ZipReader, getEntryDataDescriptorLength } = await import("./zip-reader.js");
|
|
529
|
-
const zipReader = new ZipReader(reader);
|
|
530
|
-
const entries = await zipReader.getEntries();
|
|
531
|
+
const zipReader = new ZipReader(reader, readerOptions);
|
|
531
532
|
const keptEntries = [];
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
533
|
+
let entries;
|
|
534
|
+
try {
|
|
535
|
+
entries = await zipReader.getEntries();
|
|
536
|
+
for (const entry of entries) {
|
|
537
|
+
if (!filter || await filter(entry, getExistingEntry(fileEntries, entry.filename))) {
|
|
538
|
+
keptEntries.push(entry);
|
|
539
|
+
}
|
|
535
540
|
}
|
|
541
|
+
} finally {
|
|
542
|
+
await zipReader.close();
|
|
536
543
|
}
|
|
537
|
-
await zipReader.close();
|
|
538
544
|
await initStream(zipWriter.writer);
|
|
539
545
|
const { directoryOffset, entriesMissingZip64ExtraField } = zipReader;
|
|
540
546
|
keptEntries.forEach(entry => {
|
|
@@ -604,7 +610,7 @@ async function appendZipEntries(zipWriter, reader, options = {}) {
|
|
|
604
610
|
setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
|
|
605
611
|
}
|
|
606
612
|
const { offset, diskNumberStart } = entryPositions.get(entry);
|
|
607
|
-
Object.assign(entry, {
|
|
613
|
+
fileEntries.set(entry.filename, Object.assign({}, entry, {
|
|
608
614
|
zip64Enabled: true,
|
|
609
615
|
zip64UncompressedSize,
|
|
610
616
|
zip64CompressedSize,
|
|
@@ -621,8 +627,7 @@ async function appendZipEntries(zipWriter, reader, options = {}) {
|
|
|
621
627
|
rawCentralExtraField: EMPTY_UINT8_ARRAY,
|
|
622
628
|
headerArray,
|
|
623
629
|
headerView
|
|
624
|
-
});
|
|
625
|
-
fileEntries.set(entry.filename, entry);
|
|
630
|
+
}));
|
|
626
631
|
});
|
|
627
632
|
} catch (error) {
|
|
628
633
|
appendedFilenames.forEach(filename => filenames.delete(filename));
|
|
@@ -636,6 +641,11 @@ async function appendZipEntries(zipWriter, reader, options = {}) {
|
|
|
636
641
|
}
|
|
637
642
|
}
|
|
638
643
|
|
|
644
|
+
function getExistingEntry(fileEntries, filename) {
|
|
645
|
+
const fileEntry = fileEntries.get(filename);
|
|
646
|
+
return fileEntry ? new Entry(fileEntry) : UNDEFINED_VALUE;
|
|
647
|
+
}
|
|
648
|
+
|
|
639
649
|
async function prependZipEntries(zipWriter, reader) {
|
|
640
650
|
if (zipWriter.filenames.size) {
|
|
641
651
|
throw new Error(ERR_ZIP_NOT_EMPTY);
|
package/lib/zip-core-base.js
CHANGED
package/package.json
CHANGED