@zip.js/zip.js 2.19.0 → 2.21.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/BENCHMARKS.md +154 -130
- package/deno.json +1 -1
- package/dist/zip-core-external.js +440 -225
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +441 -224
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +440 -225
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +441 -224
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +440 -225
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +441 -224
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +441 -224
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +441 -224
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +441 -224
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +441 -224
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +441 -224
- package/index-native.min.js +1 -1
- package/index.cjs +441 -224
- package/index.d.cts +117 -24
- package/index.d.ts +117 -24
- package/index.min.js +1 -1
- package/lib/core/constants.js +7 -0
- package/lib/core/version.js +1 -1
- package/lib/core/zip-reader.js +225 -76
- package/lib/core/zip-writer.js +214 -147
- package/lib/zip-core-reader.js +2 -0
- package/package.json +1 -1
|
@@ -117,6 +117,10 @@ const MIN_DATE = new Date(1980, 0, 1);
|
|
|
117
117
|
|
|
118
118
|
const UNDEFINED_VALUE = undefined;
|
|
119
119
|
const INFINITY_VALUE = Infinity;
|
|
120
|
+
const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
|
|
121
|
+
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
122
|
+
const ERR_EXTRAFIELD_ZIP64_NOT_FOUND = "Zip64 extra field not found";
|
|
123
|
+
|
|
120
124
|
const UNDEFINED_TYPE = "undefined";
|
|
121
125
|
const FUNCTION_TYPE = "function";
|
|
122
126
|
const OBJECT_TYPE = "object";
|
|
@@ -4810,12 +4814,9 @@ const ERR_BAD_FORMAT = "File format is not recognized";
|
|
|
4810
4814
|
const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
|
|
4811
4815
|
const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = "End of Zip64 central directory locator not found";
|
|
4812
4816
|
const ERR_CENTRAL_DIRECTORY_NOT_FOUND = "Central directory header not found";
|
|
4813
|
-
const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
|
|
4814
|
-
const ERR_EXTRAFIELD_ZIP64_NOT_FOUND = "Zip64 extra field not found";
|
|
4815
4817
|
const ERR_ENCRYPTED = "File contains encrypted entry";
|
|
4816
4818
|
const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
|
|
4817
4819
|
const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
4818
|
-
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
4819
4820
|
const ERR_ENTRY_DATA_OUT_OF_BOUNDS = "Entry data out of bounds";
|
|
4820
4821
|
const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
|
|
4821
4822
|
const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
|
|
@@ -4834,6 +4835,8 @@ const WARNING_APPENDED_DATA = "appended data";
|
|
|
4834
4835
|
const WARNING_PREPENDED_DATA = "prepended data";
|
|
4835
4836
|
const WARNING_PREPENDED_CENTRAL_DIRECTORY = "prepended central directory";
|
|
4836
4837
|
const WARNING_TRAILING_CENTRAL_DIRECTORY_DATA = "trailing central directory data";
|
|
4838
|
+
const WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET = "mismatched central directory offset";
|
|
4839
|
+
const WARNING_MISSING_ZIP64_EXTRA_FIELD = "missing zip64 extra field";
|
|
4837
4840
|
const WARNING_DUPLICATE_FILENAME = "duplicate filename";
|
|
4838
4841
|
const WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY = "mismatched zip64 end of central directory record";
|
|
4839
4842
|
const WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY = "multiple end of central directory records";
|
|
@@ -4878,7 +4881,8 @@ class ZipReader {
|
|
|
4878
4881
|
Object.assign(this, {
|
|
4879
4882
|
reader: new GenericReader(reader),
|
|
4880
4883
|
options,
|
|
4881
|
-
readRanges: { indexes: new Set(), sortedRanges: [], pendingRanges: [] }
|
|
4884
|
+
readRanges: { indexes: new Set(), sortedRanges: [], pendingRanges: [] },
|
|
4885
|
+
entriesMissingZip64ExtraField: new WeakSet()
|
|
4882
4886
|
});
|
|
4883
4887
|
}
|
|
4884
4888
|
|
|
@@ -4949,16 +4953,22 @@ class ZipReader {
|
|
|
4949
4953
|
directoryDataOffset = getDiskOffset$1(reader, getUint32$1(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
|
|
4950
4954
|
let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
|
|
4951
4955
|
let endOfDirectoryView = getDataView(endOfDirectoryArray);
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4956
|
+
if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
|
|
4957
|
+
const locatorOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH;
|
|
4958
|
+
let expectedDirectoryDataOffset = locatorOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
4959
|
+
if (!await startsWithSignature(reader, expectedDirectoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE)) {
|
|
4960
|
+
expectedDirectoryDataOffset = await findZip64EndOfDirectoryOffset(reader, locatorOffset);
|
|
4961
|
+
}
|
|
4962
|
+
if (expectedDirectoryDataOffset !== UNDEFINED_VALUE && expectedDirectoryDataOffset >= 0 &&
|
|
4963
|
+
directoryDataOffset != expectedDirectoryDataOffset) {
|
|
4964
|
+
const originalDirectoryDataOffset = directoryDataOffset;
|
|
4965
|
+
directoryDataOffset = expectedDirectoryDataOffset;
|
|
4966
|
+
if (directoryDataOffset > originalDirectoryDataOffset) {
|
|
4967
|
+
prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
|
|
4968
|
+
}
|
|
4969
|
+
endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
|
|
4970
|
+
endOfDirectoryView = getDataView(endOfDirectoryArray);
|
|
4959
4971
|
}
|
|
4960
|
-
endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
|
|
4961
|
-
endOfDirectoryView = getDataView(endOfDirectoryArray);
|
|
4962
4972
|
}
|
|
4963
4973
|
if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
|
|
4964
4974
|
throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
|
|
@@ -4996,15 +5006,13 @@ class ZipReader {
|
|
|
4996
5006
|
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4997
5007
|
}
|
|
4998
5008
|
directoryDataOffset = getDiskOffset$1(reader, diskNumber) + getBigUint64(endOfDirectoryView, 48) + prependedDataLength;
|
|
5009
|
+
} else if (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || diskNumber == MAX_16_BITS) {
|
|
5010
|
+
throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
|
|
4999
5011
|
}
|
|
5000
5012
|
}
|
|
5001
5013
|
let declaredDirectoryDataLength = directoryDataLength;
|
|
5002
5014
|
const centralDirectoryEndOffset = endOfDirectoryInfo.offset -
|
|
5003
5015
|
(zip64EndOfDirectory ? zip64EndOfDirectoryLength + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
|
|
5004
|
-
if (directoryDataOffset >= reader.size) {
|
|
5005
|
-
prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
5006
|
-
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
5007
|
-
}
|
|
5008
5016
|
if (expectedLastDiskNumber != lastDiskNumber) {
|
|
5009
5017
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
5010
5018
|
}
|
|
@@ -5012,33 +5020,64 @@ class ZipReader {
|
|
|
5012
5020
|
throw new Error(ERR_BAD_FORMAT);
|
|
5013
5021
|
}
|
|
5014
5022
|
let offset = 0;
|
|
5015
|
-
let directoryArray =
|
|
5023
|
+
let directoryArray = directoryDataOffset < reader.size ?
|
|
5024
|
+
await readUint8Array(reader, directoryDataOffset, directoryDataLength) :
|
|
5025
|
+
EMPTY_UINT8_ARRAY;
|
|
5016
5026
|
let directoryView = getDataView(directoryArray);
|
|
5017
5027
|
if (directoryDataLength) {
|
|
5018
|
-
|
|
5019
|
-
throw new Error(ERR_BAD_FORMAT);
|
|
5020
|
-
}
|
|
5021
|
-
const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
|
|
5028
|
+
let expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
|
|
5022
5029
|
if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
|
|
5023
|
-
const storedPointsAtDirectory =
|
|
5030
|
+
const storedPointsAtDirectory = directoryArray.length >= 4 && (
|
|
5031
|
+
getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE ||
|
|
5024
5032
|
Boolean(directoryEncryptionInfo && directoryEncryptionInfo.compressedSize) ||
|
|
5025
|
-
detectEncryptedCentralDirectory(directoryView);
|
|
5033
|
+
detectEncryptedCentralDirectory(directoryView));
|
|
5034
|
+
if (!storedPointsAtDirectory && expectedDirectoryDataOffset < 0) {
|
|
5035
|
+
throw new Error(ERR_BAD_FORMAT);
|
|
5036
|
+
}
|
|
5026
5037
|
let reconcile = !storedPointsAtDirectory;
|
|
5027
|
-
if (
|
|
5028
|
-
|
|
5029
|
-
|
|
5038
|
+
if (expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
|
|
5039
|
+
let expectedPointsAtDirectory = await pointsAtDirectory(reader, expectedDirectoryDataOffset);
|
|
5040
|
+
if (!expectedPointsAtDirectory) {
|
|
5041
|
+
const signatureRecordOffset = await findDigitalSignatureRecordOffset(reader, centralDirectoryEndOffset);
|
|
5042
|
+
const signedDirectoryDataOffset = signatureRecordOffset - directoryDataLength;
|
|
5043
|
+
if (signatureRecordOffset !== UNDEFINED_VALUE && signedDirectoryDataOffset >= 0 &&
|
|
5044
|
+
await pointsAtDirectory(reader, signedDirectoryDataOffset)) {
|
|
5045
|
+
expectedDirectoryDataOffset = signedDirectoryDataOffset;
|
|
5046
|
+
expectedPointsAtDirectory = true;
|
|
5047
|
+
}
|
|
5048
|
+
}
|
|
5049
|
+
if (storedPointsAtDirectory) {
|
|
5050
|
+
reconcile = expectedPointsAtDirectory;
|
|
5051
|
+
}
|
|
5030
5052
|
}
|
|
5031
|
-
if (reconcile) {
|
|
5053
|
+
if (reconcile && expectedDirectoryDataOffset != directoryDataOffset) {
|
|
5032
5054
|
const originalDirectoryDataOffset = directoryDataOffset;
|
|
5033
5055
|
directoryDataOffset = expectedDirectoryDataOffset;
|
|
5034
|
-
if (directoryDataOffset > originalDirectoryDataOffset) {
|
|
5035
|
-
prependedDataLength += directoryDataOffset - originalDirectoryDataOffset;
|
|
5036
|
-
prependedCentralDirectory = storedPointsAtDirectory;
|
|
5037
|
-
}
|
|
5038
5056
|
directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);
|
|
5039
5057
|
directoryView = getDataView(directoryArray);
|
|
5058
|
+
const offsetDelta = directoryDataOffset - originalDirectoryDataOffset;
|
|
5059
|
+
const localHeaderOffset = getFirstLocalHeaderOffset(directoryArray, directoryView);
|
|
5060
|
+
const localHeaderFound = localHeaderOffset !== UNDEFINED_VALUE &&
|
|
5061
|
+
await startsWithSignature(reader, localHeaderOffset, LOCAL_FILE_HEADER_SIGNATURE);
|
|
5062
|
+
const shiftedLocalHeaderFound = localHeaderOffset !== UNDEFINED_VALUE &&
|
|
5063
|
+
await startsWithSignature(reader, localHeaderOffset + offsetDelta, LOCAL_FILE_HEADER_SIGNATURE);
|
|
5064
|
+
if (offsetDelta > 0 && !(localHeaderFound && !shiftedLocalHeaderFound)) {
|
|
5065
|
+
prependedDataLength += offsetDelta;
|
|
5066
|
+
prependedCentralDirectory = storedPointsAtDirectory;
|
|
5067
|
+
} else {
|
|
5068
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET);
|
|
5069
|
+
if (offsetDelta < 0 && !localHeaderFound && shiftedLocalHeaderFound) {
|
|
5070
|
+
prependedDataLength += offsetDelta;
|
|
5071
|
+
}
|
|
5072
|
+
}
|
|
5040
5073
|
}
|
|
5041
5074
|
}
|
|
5075
|
+
if (directoryArray.length < 4) {
|
|
5076
|
+
throw new Error(ERR_BAD_FORMAT);
|
|
5077
|
+
}
|
|
5078
|
+
} else if (!filesLength && directoryDataOffset < centralDirectoryEndOffset && diskNumber == lastDiskNumber) {
|
|
5079
|
+
prependedDataLength += centralDirectoryEndOffset - directoryDataOffset;
|
|
5080
|
+
directoryDataOffset = centralDirectoryEndOffset;
|
|
5042
5081
|
}
|
|
5043
5082
|
const expectedDirectoryDataLength = centralDirectoryEndOffset - directoryDataOffset;
|
|
5044
5083
|
if (directoryDataLength != expectedDirectoryDataLength && expectedDirectoryDataLength >= 0 && diskNumber == lastDiskNumber) {
|
|
@@ -5080,8 +5119,10 @@ class ZipReader {
|
|
|
5080
5119
|
addWarning(warnings, WARNING_WRAPPED_ENTRIES_COUNT);
|
|
5081
5120
|
}
|
|
5082
5121
|
}
|
|
5122
|
+
const entryOptions = Object.assign({}, zipReader.options, options, { [OPTION_STRICTNESS]: strictness });
|
|
5123
|
+
delete entryOptions[OPTION_CHECK_AMBIGUITY];
|
|
5083
5124
|
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
5084
|
-
const fileEntry = new ZipEntry$1(reader,
|
|
5125
|
+
const fileEntry = new ZipEntry$1(reader, entryOptions);
|
|
5085
5126
|
if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32$1(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
5086
5127
|
if (indexFile == 0 && !decryptedDirectory && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
|
|
5087
5128
|
throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
|
|
@@ -5147,7 +5188,16 @@ class ZipReader {
|
|
|
5147
5188
|
filename,
|
|
5148
5189
|
comment
|
|
5149
5190
|
});
|
|
5150
|
-
|
|
5191
|
+
let malformedExtraField;
|
|
5192
|
+
try {
|
|
5193
|
+
malformedExtraField = readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
|
|
5194
|
+
} catch (error) {
|
|
5195
|
+
if (checkAmbiguity || error.message != ERR_EXTRAFIELD_ZIP64_NOT_FOUND) {
|
|
5196
|
+
throw error;
|
|
5197
|
+
}
|
|
5198
|
+
fileEntry.zip64ExtraFieldMissing = true;
|
|
5199
|
+
addWarning(warnings, WARNING_MISSING_ZIP64_EXTRA_FIELD, fileEntry.filename);
|
|
5200
|
+
}
|
|
5151
5201
|
filename = fileEntry.filename;
|
|
5152
5202
|
if (normalizeFilename) {
|
|
5153
5203
|
const normalizedFilename = normalizeFilename(filename);
|
|
@@ -5163,13 +5213,17 @@ class ZipReader {
|
|
|
5163
5213
|
if (malformedExtraField) {
|
|
5164
5214
|
addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD, filename);
|
|
5165
5215
|
}
|
|
5166
|
-
fileEntry.offset
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5216
|
+
if (fileEntry.zip64ExtraFieldMissing && fileEntry.offset == MAX_32_BITS) {
|
|
5217
|
+
startOffset = 0;
|
|
5218
|
+
} else {
|
|
5219
|
+
fileEntry.offset += prependedDataLength;
|
|
5220
|
+
const entryPosition = getDiskOffset$1(reader, fileEntry.diskNumberStart) + fileEntry.offset;
|
|
5221
|
+
startOffset = Math.min(entryPosition, startOffset);
|
|
5222
|
+
if (entryPosition < previousEntryPosition) {
|
|
5223
|
+
addWarning(warnings, WARNING_UNSORTED_CENTRAL_DIRECTORY, filename);
|
|
5224
|
+
}
|
|
5225
|
+
previousEntryPosition = entryPosition;
|
|
5171
5226
|
}
|
|
5172
|
-
previousEntryPosition = entryPosition;
|
|
5173
5227
|
if ((fileEntry.version & MAX_8_BITS) > MAX_KNOWN_VERSION) {
|
|
5174
5228
|
addWarning(warnings, WARNING_UNKNOWN_VERSION, filename);
|
|
5175
5229
|
}
|
|
@@ -5189,11 +5243,12 @@ class ZipReader {
|
|
|
5189
5243
|
const sticky = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_STICKY_MASK);
|
|
5190
5244
|
const unixType = fileEntry.unixMode === UNDEFINED_VALUE ? unixExternalUpper : fileEntry.unixMode;
|
|
5191
5245
|
const symlink = (unixType & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_SYMLINK;
|
|
5192
|
-
const executable = !symlink && ((fileEntry.unixMode !== UNDEFINED_VALUE)
|
|
5193
|
-
? ((fileEntry.unixMode & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)
|
|
5194
|
-
: (unixCompatible && ((unixExternalUpper & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)));
|
|
5195
5246
|
const modeIsDir = fileEntry.unixMode !== UNDEFINED_VALUE && ((fileEntry.unixMode & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR);
|
|
5196
5247
|
const upperIsDir = ((unixExternalUpper & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR);
|
|
5248
|
+
const directory = modeIsDir || upperIsDir || (msDosCompatible && msdosAttributes.directory) || fileEntry.filename.endsWith(DIRECTORY_SIGNATURE);
|
|
5249
|
+
const executable = !symlink && !directory && ((fileEntry.unixMode !== UNDEFINED_VALUE)
|
|
5250
|
+
? ((fileEntry.unixMode & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)
|
|
5251
|
+
: (unixCompatible && ((unixExternalUpper & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)));
|
|
5197
5252
|
Object.assign(fileEntry, {
|
|
5198
5253
|
setuid,
|
|
5199
5254
|
setgid,
|
|
@@ -5201,16 +5256,19 @@ class ZipReader {
|
|
|
5201
5256
|
symlink,
|
|
5202
5257
|
unixExternalUpper,
|
|
5203
5258
|
executable,
|
|
5204
|
-
directory
|
|
5259
|
+
directory,
|
|
5205
5260
|
zipCrypto: fileEntry.encrypted && !fileEntry.extraFieldAES
|
|
5206
5261
|
});
|
|
5207
5262
|
const entry = new Entry(fileEntry);
|
|
5208
|
-
|
|
5263
|
+
if (fileEntry.zip64ExtraFieldMissing) {
|
|
5264
|
+
zipReader.entriesMissingZip64ExtraField.add(entry);
|
|
5265
|
+
}
|
|
5266
|
+
entry.getData = (writer, options) => fileEntry.getData(writer, entry, zipReader, options);
|
|
5209
5267
|
entry.arrayBuffer = async options => {
|
|
5210
5268
|
const writer = new TransformStream();
|
|
5211
5269
|
const arrayBufferPromise = streamToBlob(writer.readable).then(blob => blob.arrayBuffer());
|
|
5212
5270
|
arrayBufferPromise.catch(() => { });
|
|
5213
|
-
await fileEntry.getData(writer, entry, zipReader
|
|
5271
|
+
await fileEntry.getData(writer, entry, zipReader,
|
|
5214
5272
|
Object.assign({}, options, { preventClose: false }));
|
|
5215
5273
|
return arrayBufferPromise;
|
|
5216
5274
|
};
|
|
@@ -5257,10 +5315,10 @@ class ZipReader {
|
|
|
5257
5315
|
const extractAppendedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
|
|
5258
5316
|
const splitZipSignatureLength = (checkAmbiguity || extractPrependedData) && filesLength &&
|
|
5259
5317
|
startOffset == SPLIT_ZIP_FILE_SIGNATURE_LENGTH && await startsWithSplitZipMarker(reader) ? SPLIT_ZIP_FILE_SIGNATURE_LENGTH : 0;
|
|
5260
|
-
if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > splitZipSignatureLength))) {
|
|
5318
|
+
if (checkAmbiguity && (prependedDataLength > 0 || (filesLength && startOffset > splitZipSignatureLength))) {
|
|
5261
5319
|
throwAmbiguousArchive(WARNING_PREPENDED_DATA);
|
|
5262
5320
|
}
|
|
5263
|
-
if (prependedDataLength || (filesLength && startOffset > SPLIT_ZIP_FILE_SIGNATURE_LENGTH)) {
|
|
5321
|
+
if (prependedDataLength > 0 || (filesLength && startOffset > SPLIT_ZIP_FILE_SIGNATURE_LENGTH)) {
|
|
5264
5322
|
addWarning(warnings, WARNING_PREPENDED_DATA);
|
|
5265
5323
|
}
|
|
5266
5324
|
if (prependedCentralDirectory) {
|
|
@@ -5418,8 +5476,12 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5418
5476
|
});
|
|
5419
5477
|
}
|
|
5420
5478
|
|
|
5421
|
-
async getData(writer, fileEntry,
|
|
5479
|
+
async getData(writer, fileEntry, zipReader, options = {}) {
|
|
5422
5480
|
const zipEntry = this;
|
|
5481
|
+
const { readRanges, directoryOffset } = zipReader;
|
|
5482
|
+
if (zipEntry.zip64ExtraFieldMissing) {
|
|
5483
|
+
throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
|
|
5484
|
+
}
|
|
5423
5485
|
const config = getConfiguration();
|
|
5424
5486
|
const {
|
|
5425
5487
|
reader,
|
|
@@ -5490,10 +5552,10 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5490
5552
|
}
|
|
5491
5553
|
validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename, checkLocalDirectory ? UNDEFINED_VALUE : warnings);
|
|
5492
5554
|
const { lastAccessDate, creationDate, uid, gid } = localDirectory;
|
|
5493
|
-
if (lastAccessDate) {
|
|
5555
|
+
if (lastAccessDate && fileEntry.lastAccessDate === UNDEFINED_VALUE) {
|
|
5494
5556
|
fileEntry.lastAccessDate = lastAccessDate;
|
|
5495
5557
|
}
|
|
5496
|
-
if (creationDate) {
|
|
5558
|
+
if (creationDate && fileEntry.creationDate === UNDEFINED_VALUE) {
|
|
5497
5559
|
fileEntry.creationDate = creationDate;
|
|
5498
5560
|
}
|
|
5499
5561
|
if (uid !== UNDEFINED_VALUE && fileEntry.uid === UNDEFINED_VALUE) {
|
|
@@ -5522,7 +5584,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5522
5584
|
throw new Error(ERR_ENCRYPTED);
|
|
5523
5585
|
}
|
|
5524
5586
|
}
|
|
5525
|
-
if (dataOffset + compressedSize > reader.size) {
|
|
5587
|
+
if (dataOffset + compressedSize > Math.min(reader.size, directoryOffset)) {
|
|
5526
5588
|
throw new Error(ERR_ENTRY_DATA_OUT_OF_BOUNDS);
|
|
5527
5589
|
}
|
|
5528
5590
|
const size = compressedSize;
|
|
@@ -5588,6 +5650,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5588
5650
|
extraFieldZip64: extraFieldZip64 || localDirectory.extraFieldZip64,
|
|
5589
5651
|
readRanges
|
|
5590
5652
|
});
|
|
5653
|
+
validateDataDescriptor(zipEntry, localDirectory, checkLocalDirectory ? UNDEFINED_VALUE : warnings);
|
|
5591
5654
|
}
|
|
5592
5655
|
let writable, abortError, aborted;
|
|
5593
5656
|
try {
|
|
@@ -5607,10 +5670,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5607
5670
|
writer.size += writtenSize;
|
|
5608
5671
|
}
|
|
5609
5672
|
} catch (error) {
|
|
5610
|
-
|
|
5611
|
-
if (failedOutputSize !== UNDEFINED_VALUE) {
|
|
5612
|
-
writer.size += failedOutputSize;
|
|
5613
|
-
} else if (isErrorObject(error) && error.outputSize !== UNDEFINED_VALUE) {
|
|
5673
|
+
if (isErrorObject(error) && error.outputSize !== UNDEFINED_VALUE) {
|
|
5614
5674
|
writer.size += error.outputSize;
|
|
5615
5675
|
}
|
|
5616
5676
|
if (!checkPasswordOnly || !isErrorObject(error) || error.message != ERR_ABORT_CHECK_PASSWORD) {
|
|
@@ -5638,13 +5698,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5638
5698
|
};
|
|
5639
5699
|
|
|
5640
5700
|
function detectEncryptedCentralDirectory(directoryView) {
|
|
5641
|
-
|
|
5642
|
-
for (let offset = 0; offset < maxOffset; offset++) {
|
|
5643
|
-
if (getUint32$1(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
|
|
5644
|
-
return true;
|
|
5645
|
-
}
|
|
5646
|
-
}
|
|
5647
|
-
return false;
|
|
5701
|
+
return directoryView.byteLength >= 4 && getUint32$1(directoryView, 0) == ARCHIVE_EXTRA_DATA_SIGNATURE;
|
|
5648
5702
|
}
|
|
5649
5703
|
|
|
5650
5704
|
function getWrappedFilesLength(directoryView, directoryArray, offset) {
|
|
@@ -5657,6 +5711,70 @@ function getWrappedFilesLength(directoryView, directoryArray, offset) {
|
|
|
5657
5711
|
return wrappedFilesLength % (MAX_16_BITS + 1) ? 0 : wrappedFilesLength;
|
|
5658
5712
|
}
|
|
5659
5713
|
|
|
5714
|
+
function pointsAtDirectory(reader, offset) {
|
|
5715
|
+
return startsWithSignature(reader, offset, CENTRAL_FILE_HEADER_SIGNATURE);
|
|
5716
|
+
}
|
|
5717
|
+
|
|
5718
|
+
async function startsWithSignature(reader, offset, signature) {
|
|
5719
|
+
if (offset < 0 || offset + 4 > reader.size) {
|
|
5720
|
+
return false;
|
|
5721
|
+
}
|
|
5722
|
+
const signatureArray = await readUint8Array(reader, offset, 4);
|
|
5723
|
+
return getUint32$1(getDataView(signatureArray), 0) == signature;
|
|
5724
|
+
}
|
|
5725
|
+
|
|
5726
|
+
async function findDigitalSignatureRecordOffset(reader, endOffset) {
|
|
5727
|
+
const startOffset = Math.max(0, endOffset - (6 + MAX_16_BITS));
|
|
5728
|
+
const tailArray = await readUint8Array(reader, startOffset, endOffset - startOffset);
|
|
5729
|
+
const tailView = getDataView(tailArray);
|
|
5730
|
+
for (let indexByte = tailArray.length - 6; indexByte >= 0; indexByte--) {
|
|
5731
|
+
if (getUint32$1(tailView, indexByte) == DIGITAL_SIGNATURE_RECORD_SIGNATURE &&
|
|
5732
|
+
indexByte + 6 + getUint16$1(tailView, indexByte + 4) == tailArray.length) {
|
|
5733
|
+
return startOffset + indexByte;
|
|
5734
|
+
}
|
|
5735
|
+
}
|
|
5736
|
+
}
|
|
5737
|
+
|
|
5738
|
+
async function findZip64EndOfDirectoryOffset(reader, endOffset) {
|
|
5739
|
+
const startOffset = Math.max(0, endOffset - (ZIP64_END_OF_CENTRAL_DIR_LENGTH + MAX_16_BITS));
|
|
5740
|
+
const tailArray = await readUint8Array(reader, startOffset, endOffset - startOffset);
|
|
5741
|
+
const tailView = getDataView(tailArray);
|
|
5742
|
+
for (let indexByte = tailArray.length - ZIP64_END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
|
|
5743
|
+
if (getUint32$1(tailView, indexByte) == ZIP64_END_OF_CENTRAL_DIR_SIGNATURE &&
|
|
5744
|
+
indexByte + 12 + Number(tailView.getBigUint64(indexByte + 4, true)) == tailArray.length) {
|
|
5745
|
+
return startOffset + indexByte;
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5748
|
+
}
|
|
5749
|
+
|
|
5750
|
+
function getFirstLocalHeaderOffset(directoryArray, directoryView) {
|
|
5751
|
+
if (directoryArray.length < CENTRAL_FILE_HEADER_LENGTH) {
|
|
5752
|
+
return UNDEFINED_VALUE;
|
|
5753
|
+
}
|
|
5754
|
+
const localHeaderOffset = getUint32$1(directoryView, 42);
|
|
5755
|
+
if (localHeaderOffset != MAX_32_BITS) {
|
|
5756
|
+
return localHeaderOffset;
|
|
5757
|
+
}
|
|
5758
|
+
let offsetExtraField = CENTRAL_FILE_HEADER_LENGTH + getUint16$1(directoryView, 28);
|
|
5759
|
+
const endExtraField = Math.min(offsetExtraField + getUint16$1(directoryView, 30), directoryArray.length);
|
|
5760
|
+
while (offsetExtraField + 4 <= endExtraField) {
|
|
5761
|
+
const type = getUint16$1(directoryView, offsetExtraField);
|
|
5762
|
+
const size = getUint16$1(directoryView, offsetExtraField + 2);
|
|
5763
|
+
if (type == EXTRAFIELD_TYPE_ZIP64) {
|
|
5764
|
+
let offsetValue = offsetExtraField + 4;
|
|
5765
|
+
if (getUint32$1(directoryView, 24) == MAX_32_BITS) {
|
|
5766
|
+
offsetValue += 8;
|
|
5767
|
+
}
|
|
5768
|
+
if (getUint32$1(directoryView, 20) == MAX_32_BITS) {
|
|
5769
|
+
offsetValue += 8;
|
|
5770
|
+
}
|
|
5771
|
+
return offsetValue + 8 <= endExtraField ? getBigUint64(directoryView, offsetValue) : UNDEFINED_VALUE;
|
|
5772
|
+
}
|
|
5773
|
+
offsetExtraField += 4 + size;
|
|
5774
|
+
}
|
|
5775
|
+
return UNDEFINED_VALUE;
|
|
5776
|
+
}
|
|
5777
|
+
|
|
5660
5778
|
function readDigitalSignature(signatureRecordArray) {
|
|
5661
5779
|
if (signatureRecordArray.length >= 6) {
|
|
5662
5780
|
const signatureRecordView = getDataView(signatureRecordArray);
|
|
@@ -5746,6 +5864,7 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5746
5864
|
uncompressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
|
|
5747
5865
|
});
|
|
5748
5866
|
const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
|
|
5867
|
+
let extraFieldZip64Missing;
|
|
5749
5868
|
if (extraFieldZip64) {
|
|
5750
5869
|
if (!readExtraFieldZip64(extraFieldZip64, directory, localDirectory)) {
|
|
5751
5870
|
malformedExtraField = true;
|
|
@@ -5755,7 +5874,7 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5755
5874
|
if (localDirectory) {
|
|
5756
5875
|
malformedExtraField = true;
|
|
5757
5876
|
} else {
|
|
5758
|
-
|
|
5877
|
+
extraFieldZip64Missing = true;
|
|
5759
5878
|
}
|
|
5760
5879
|
}
|
|
5761
5880
|
const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
|
|
@@ -5788,6 +5907,11 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5788
5907
|
readExtraFieldUnixDates(extraFieldUnixType1, directory);
|
|
5789
5908
|
directory.extraFieldUnixType1 = extraFieldUnixType1;
|
|
5790
5909
|
}
|
|
5910
|
+
const extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
|
|
5911
|
+
if (extraFieldExtendedTimestamp) {
|
|
5912
|
+
readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory, localDirectory);
|
|
5913
|
+
directory.extraFieldExtendedTimestamp = extraFieldExtendedTimestamp;
|
|
5914
|
+
}
|
|
5791
5915
|
const extraFieldNTFS = extraField.get(EXTRAFIELD_TYPE_NTFS);
|
|
5792
5916
|
if (extraFieldNTFS) {
|
|
5793
5917
|
readExtraFieldNTFS(extraFieldNTFS, directory);
|
|
@@ -5804,15 +5928,13 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5804
5928
|
readExtraFieldUnix(extraFieldUnix, unixIdsRead ? {} : directory, false);
|
|
5805
5929
|
directory.extraFieldUnix = extraFieldUnix;
|
|
5806
5930
|
}
|
|
5807
|
-
const extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
|
|
5808
|
-
if (extraFieldExtendedTimestamp) {
|
|
5809
|
-
readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory, localDirectory);
|
|
5810
|
-
directory.extraFieldExtendedTimestamp = extraFieldExtendedTimestamp;
|
|
5811
|
-
}
|
|
5812
5931
|
const extraFieldUSDZ = extraField.get(EXTRAFIELD_TYPE_USDZ);
|
|
5813
5932
|
if (extraFieldUSDZ) {
|
|
5814
5933
|
directory.extraFieldUSDZ = extraFieldUSDZ;
|
|
5815
5934
|
}
|
|
5935
|
+
if (extraFieldZip64Missing) {
|
|
5936
|
+
throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
|
|
5937
|
+
}
|
|
5816
5938
|
return malformedExtraField;
|
|
5817
5939
|
}
|
|
5818
5940
|
|
|
@@ -6027,13 +6149,7 @@ async function detectOverlappingEntry({
|
|
|
6027
6149
|
let dataDescriptorLength = 0;
|
|
6028
6150
|
if (dataDescriptor) {
|
|
6029
6151
|
const zip64 = Boolean(extraFieldZip64);
|
|
6030
|
-
const
|
|
6031
|
-
const dataDescriptorView = getDataView(dataDescriptorArray);
|
|
6032
|
-
const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
|
|
6033
|
-
.map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
|
|
6034
|
-
.filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
|
|
6035
|
-
const localDataDescriptor = candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
|
|
6036
|
-
readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
|
|
6152
|
+
const localDataDescriptor = await readLocalDataDescriptor(reader, dataOffset + compressedSize, { crc32, compressedSize, uncompressedSize, zip64 });
|
|
6037
6153
|
if (localDataDescriptor) {
|
|
6038
6154
|
fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
|
|
6039
6155
|
dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
|
|
@@ -6103,6 +6219,25 @@ function mergeRanges(sortedRanges, pendingRanges) {
|
|
|
6103
6219
|
return mergedRanges;
|
|
6104
6220
|
}
|
|
6105
6221
|
|
|
6222
|
+
async function readLocalDataDescriptor(reader, offset, { crc32, compressedSize, uncompressedSize, zip64 }) {
|
|
6223
|
+
const maxLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
|
|
6224
|
+
const length = Math.min(maxLength, Math.max(0, reader.size - offset));
|
|
6225
|
+
const dataDescriptorArray = length ? await readUint8Array(reader, offset, length) : EMPTY_UINT8_ARRAY;
|
|
6226
|
+
const dataDescriptorView = getDataView(dataDescriptorArray);
|
|
6227
|
+
const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
|
|
6228
|
+
.map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
|
|
6229
|
+
.filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
|
|
6230
|
+
return candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
|
|
6231
|
+
readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
|
|
6232
|
+
}
|
|
6233
|
+
|
|
6234
|
+
async function getEntryDataDescriptorLength(reader, offset, { crc32, compressedSize, uncompressedSize, extraFieldZip64 }) {
|
|
6235
|
+
const dataDescriptor = await readLocalDataDescriptor(reader, offset, { crc32, compressedSize, uncompressedSize, zip64: Boolean(extraFieldZip64) });
|
|
6236
|
+
if (dataDescriptor && dataDescriptor.compressedSize == compressedSize && dataDescriptor.uncompressedSize == uncompressedSize) {
|
|
6237
|
+
return getDataDescriptorLength(dataDescriptor.zip64, dataDescriptor.signature);
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
|
|
6106
6241
|
function readDataDescriptor(dataDescriptorView, zip64, signature) {
|
|
6107
6242
|
const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
|
|
6108
6243
|
if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
|
|
@@ -6362,6 +6497,18 @@ function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, chec
|
|
|
6362
6497
|
}
|
|
6363
6498
|
}
|
|
6364
6499
|
|
|
6500
|
+
function validateDataDescriptor(zipEntry, localDirectory, warnings) {
|
|
6501
|
+
const { dataDescriptor } = localDirectory;
|
|
6502
|
+
const maskedLocalDirectory = zipEntry.decryptedDirectory &&
|
|
6503
|
+
(localDirectory.rawBitFlag & BITFLAG_MASKED_LOCAL_HEADERS) == BITFLAG_MASKED_LOCAL_HEADERS;
|
|
6504
|
+
if (dataDescriptor && !maskedLocalDirectory &&
|
|
6505
|
+
((zipEntry.crc32 !== UNDEFINED_VALUE && dataDescriptor.crc32 != zipEntry.crc32) ||
|
|
6506
|
+
dataDescriptor.compressedSize != zipEntry.compressedSize ||
|
|
6507
|
+
dataDescriptor.uncompressedSize != zipEntry.uncompressedSize)) {
|
|
6508
|
+
reportAmbiguity(!warnings, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES);
|
|
6509
|
+
}
|
|
6510
|
+
}
|
|
6511
|
+
|
|
6365
6512
|
function reportAmbiguity(reject, warnings, reason) {
|
|
6366
6513
|
if (reject) {
|
|
6367
6514
|
throwAmbiguousArchive(reason);
|
|
@@ -6447,11 +6594,13 @@ var zipReader = /*#__PURE__*/Object.freeze({
|
|
|
6447
6594
|
WARNING_COMPRESSED_PATCHED_DATA: WARNING_COMPRESSED_PATCHED_DATA,
|
|
6448
6595
|
WARNING_DUPLICATE_FILENAME: WARNING_DUPLICATE_FILENAME,
|
|
6449
6596
|
WARNING_MALFORMED_EXTRA_FIELD: WARNING_MALFORMED_EXTRA_FIELD,
|
|
6597
|
+
WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET: WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET,
|
|
6450
6598
|
WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG: WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG,
|
|
6451
6599
|
WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD: WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD,
|
|
6452
6600
|
WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES: WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES,
|
|
6453
6601
|
WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME: WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME,
|
|
6454
6602
|
WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY: WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY,
|
|
6603
|
+
WARNING_MISSING_ZIP64_EXTRA_FIELD: WARNING_MISSING_ZIP64_EXTRA_FIELD,
|
|
6455
6604
|
WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY: WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY,
|
|
6456
6605
|
WARNING_PREPENDED_CENTRAL_DIRECTORY: WARNING_PREPENDED_CENTRAL_DIRECTORY,
|
|
6457
6606
|
WARNING_PREPENDED_DATA: WARNING_PREPENDED_DATA,
|
|
@@ -6462,6 +6611,7 @@ var zipReader = /*#__PURE__*/Object.freeze({
|
|
|
6462
6611
|
WARNING_WRAPPED_ENTRIES_COUNT: WARNING_WRAPPED_ENTRIES_COUNT,
|
|
6463
6612
|
ZipReader: ZipReader,
|
|
6464
6613
|
ZipReaderStream: ZipReaderStream,
|
|
6614
|
+
getEntryDataDescriptorLength: getEntryDataDescriptorLength,
|
|
6465
6615
|
isZipFile: isZipFile
|
|
6466
6616
|
});
|
|
6467
6617
|
|
|
@@ -6584,130 +6734,8 @@ class ZipWriter {
|
|
|
6584
6734
|
return watchPromiseError(this, prependZipEntries(this, reader));
|
|
6585
6735
|
}
|
|
6586
6736
|
|
|
6587
|
-
appendZip(reader) {
|
|
6588
|
-
return watchPromiseError(this,
|
|
6589
|
-
}
|
|
6590
|
-
|
|
6591
|
-
async appendZipEntries(reader) {
|
|
6592
|
-
const zipWriter = this;
|
|
6593
|
-
const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
|
|
6594
|
-
while (pendingAddFileCalls.size) {
|
|
6595
|
-
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6596
|
-
}
|
|
6597
|
-
let resolveAppendZip;
|
|
6598
|
-
const promiseAppendZip = new Promise(resolve => resolveAppendZip = resolve);
|
|
6599
|
-
pendingAddFileCalls.add(promiseAppendZip);
|
|
6600
|
-
const appendedFilenames = [];
|
|
6601
|
-
let releaseLockWriter;
|
|
6602
|
-
try {
|
|
6603
|
-
reader = new GenericReader(reader);
|
|
6604
|
-
await initStream(reader);
|
|
6605
|
-
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
6606
|
-
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
6607
|
-
await initStream(reader);
|
|
6608
|
-
}
|
|
6609
|
-
const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
|
|
6610
|
-
const zipReader$1 = new ZipReader(reader);
|
|
6611
|
-
const entries = await zipReader$1.getEntries();
|
|
6612
|
-
await zipReader$1.close();
|
|
6613
|
-
await initStream(zipWriter.writer);
|
|
6614
|
-
const { directoryOffset } = zipReader$1;
|
|
6615
|
-
entries.forEach(({ filename }) => {
|
|
6616
|
-
if (filenames.has(filename)) {
|
|
6617
|
-
throw new Error(ERR_DUPLICATED_NAME);
|
|
6618
|
-
}
|
|
6619
|
-
filenames.add(filename);
|
|
6620
|
-
appendedFilenames.push(filename);
|
|
6621
|
-
});
|
|
6622
|
-
zipWriter.writerLocked = true;
|
|
6623
|
-
const { lockWriter } = zipWriter;
|
|
6624
|
-
zipWriter.lockWriter = new Promise(resolve => releaseLockWriter = () => {
|
|
6625
|
-
zipWriter.writerLocked = false;
|
|
6626
|
-
resolve();
|
|
6627
|
-
});
|
|
6628
|
-
await lockWriter;
|
|
6629
|
-
if (zipWriter.addSplitZipSignature) {
|
|
6630
|
-
delete zipWriter.addSplitZipSignature;
|
|
6631
|
-
if (!await startsWithSplitZipSignature(reader)) {
|
|
6632
|
-
await writeData(zipWriter.writer, getSplitZipSignatureArray());
|
|
6633
|
-
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6634
|
-
}
|
|
6635
|
-
}
|
|
6636
|
-
const entryPositions = await copyZipData(zipWriter, reader, entries, directoryOffset);
|
|
6637
|
-
entries.forEach(entry => {
|
|
6638
|
-
const {
|
|
6639
|
-
version,
|
|
6640
|
-
rawLastModDate,
|
|
6641
|
-
rawFilename,
|
|
6642
|
-
bitFlag,
|
|
6643
|
-
encrypted,
|
|
6644
|
-
uncompressedSize,
|
|
6645
|
-
compressedSize,
|
|
6646
|
-
extraFieldZip64
|
|
6647
|
-
} = entry;
|
|
6648
|
-
let {
|
|
6649
|
-
compressionMethod,
|
|
6650
|
-
rawExtraField,
|
|
6651
|
-
} = entry;
|
|
6652
|
-
const { level, languageEncodingFlag, dataDescriptor } = bitFlag;
|
|
6653
|
-
rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
|
|
6654
|
-
if (entry.extraFieldAES) {
|
|
6655
|
-
compressionMethod = COMPRESSION_METHOD_AES;
|
|
6656
|
-
}
|
|
6657
|
-
const extraFieldLength = getLength(rawExtraField);
|
|
6658
|
-
const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
|
|
6659
|
-
const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
|
|
6660
|
-
const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
|
|
6661
|
-
const {
|
|
6662
|
-
headerArray,
|
|
6663
|
-
headerView
|
|
6664
|
-
} = getHeaderArrayData({
|
|
6665
|
-
version,
|
|
6666
|
-
bitFlag: bitFlagValue,
|
|
6667
|
-
compressionMethod,
|
|
6668
|
-
uncompressedSize,
|
|
6669
|
-
compressedSize,
|
|
6670
|
-
rawLastModDate,
|
|
6671
|
-
rawFilename,
|
|
6672
|
-
zip64CompressedSize,
|
|
6673
|
-
zip64UncompressedSize,
|
|
6674
|
-
extraFieldLength
|
|
6675
|
-
});
|
|
6676
|
-
const { crc32 } = entry;
|
|
6677
|
-
if (crc32 !== UNDEFINED_VALUE) {
|
|
6678
|
-
setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
|
|
6679
|
-
}
|
|
6680
|
-
const { offset, diskNumberStart } = entryPositions.get(entry);
|
|
6681
|
-
Object.assign(entry, {
|
|
6682
|
-
zip64Enabled: true,
|
|
6683
|
-
zip64UncompressedSize,
|
|
6684
|
-
zip64CompressedSize,
|
|
6685
|
-
offset,
|
|
6686
|
-
diskNumberStart,
|
|
6687
|
-
zip64DiskNumberStart: false,
|
|
6688
|
-
rawExtraFieldZip64: EMPTY_UINT8_ARRAY,
|
|
6689
|
-
rawExtraFieldAES: EMPTY_UINT8_ARRAY,
|
|
6690
|
-
rawExtraFieldExtendedTimestamp: EMPTY_UINT8_ARRAY,
|
|
6691
|
-
rawExtraFieldNTFS: EMPTY_UINT8_ARRAY,
|
|
6692
|
-
rawExtraFieldUnix: EMPTY_UINT8_ARRAY,
|
|
6693
|
-
rawCentralExtraFieldUnix: EMPTY_UINT8_ARRAY,
|
|
6694
|
-
rawExtraField,
|
|
6695
|
-
rawCentralExtraField: EMPTY_UINT8_ARRAY,
|
|
6696
|
-
headerArray,
|
|
6697
|
-
headerView
|
|
6698
|
-
});
|
|
6699
|
-
fileEntries.set(entry.filename, entry);
|
|
6700
|
-
});
|
|
6701
|
-
} catch (error) {
|
|
6702
|
-
appendedFilenames.forEach(filename => filenames.delete(filename));
|
|
6703
|
-
throw error;
|
|
6704
|
-
} finally {
|
|
6705
|
-
resolveAppendZip();
|
|
6706
|
-
pendingAddFileCalls.delete(promiseAppendZip);
|
|
6707
|
-
if (releaseLockWriter) {
|
|
6708
|
-
releaseLockWriter();
|
|
6709
|
-
}
|
|
6710
|
-
}
|
|
6737
|
+
appendZip(reader, options = {}) {
|
|
6738
|
+
return watchPromiseError(this, appendZipEntries(this, reader, options));
|
|
6711
6739
|
}
|
|
6712
6740
|
|
|
6713
6741
|
add(name = "", reader, options = {}) {
|
|
@@ -6869,11 +6897,140 @@ function watchPromiseError(zipWriter, promise) {
|
|
|
6869
6897
|
return watchedPromise;
|
|
6870
6898
|
}
|
|
6871
6899
|
|
|
6900
|
+
async function appendZipEntries(zipWriter, reader, options = {}) {
|
|
6901
|
+
const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
|
|
6902
|
+
const filter = checkFunctionOption(options.filter);
|
|
6903
|
+
while (pendingAddFileCalls.size) {
|
|
6904
|
+
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6905
|
+
}
|
|
6906
|
+
let resolveAppendZip;
|
|
6907
|
+
const promiseAppendZip = new Promise(resolve => resolveAppendZip = resolve);
|
|
6908
|
+
pendingAddFileCalls.add(promiseAppendZip);
|
|
6909
|
+
const appendedFilenames = [];
|
|
6910
|
+
let releaseLockWriter;
|
|
6911
|
+
try {
|
|
6912
|
+
reader = new GenericReader(reader);
|
|
6913
|
+
await initStream(reader);
|
|
6914
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
6915
|
+
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
6916
|
+
await initStream(reader);
|
|
6917
|
+
}
|
|
6918
|
+
const { ZipReader, getEntryDataDescriptorLength } = await Promise.resolve().then(function () { return zipReader; });
|
|
6919
|
+
const zipReader$1 = new ZipReader(reader);
|
|
6920
|
+
const entries = await zipReader$1.getEntries();
|
|
6921
|
+
const keptEntries = [];
|
|
6922
|
+
for (const entry of entries) {
|
|
6923
|
+
if (!filter || await filter(entry)) {
|
|
6924
|
+
keptEntries.push(entry);
|
|
6925
|
+
}
|
|
6926
|
+
}
|
|
6927
|
+
await zipReader$1.close();
|
|
6928
|
+
await initStream(zipWriter.writer);
|
|
6929
|
+
const { directoryOffset, entriesMissingZip64ExtraField } = zipReader$1;
|
|
6930
|
+
keptEntries.forEach(entry => {
|
|
6931
|
+
const { filename } = entry;
|
|
6932
|
+
if (entriesMissingZip64ExtraField.has(entry)) {
|
|
6933
|
+
throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
|
|
6934
|
+
}
|
|
6935
|
+
if (filenames.has(filename)) {
|
|
6936
|
+
throw new Error(ERR_DUPLICATED_NAME);
|
|
6937
|
+
}
|
|
6938
|
+
filenames.add(filename);
|
|
6939
|
+
appendedFilenames.push(filename);
|
|
6940
|
+
});
|
|
6941
|
+
zipWriter.writerLocked = true;
|
|
6942
|
+
const { lockWriter } = zipWriter;
|
|
6943
|
+
zipWriter.lockWriter = new Promise(resolve => releaseLockWriter = () => {
|
|
6944
|
+
zipWriter.writerLocked = false;
|
|
6945
|
+
resolve();
|
|
6946
|
+
});
|
|
6947
|
+
await lockWriter;
|
|
6948
|
+
if (zipWriter.addSplitZipSignature) {
|
|
6949
|
+
delete zipWriter.addSplitZipSignature;
|
|
6950
|
+
if (filter || !await startsWithSplitZipSignature(reader)) {
|
|
6951
|
+
await writeData(zipWriter.writer, getSplitZipSignatureArray());
|
|
6952
|
+
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6953
|
+
}
|
|
6954
|
+
}
|
|
6955
|
+
const entryPositions = await copyZipData(zipWriter, reader, entries, keptEntries, directoryOffset, Boolean(filter), getEntryDataDescriptorLength);
|
|
6956
|
+
keptEntries.forEach(entry => {
|
|
6957
|
+
const {
|
|
6958
|
+
version,
|
|
6959
|
+
rawLastModDate,
|
|
6960
|
+
rawFilename,
|
|
6961
|
+
rawBitFlag,
|
|
6962
|
+
uncompressedSize,
|
|
6963
|
+
compressedSize,
|
|
6964
|
+
extraFieldZip64
|
|
6965
|
+
} = entry;
|
|
6966
|
+
let {
|
|
6967
|
+
compressionMethod,
|
|
6968
|
+
rawExtraField,
|
|
6969
|
+
} = entry;
|
|
6970
|
+
rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
|
|
6971
|
+
if (entry.extraFieldAES) {
|
|
6972
|
+
compressionMethod = COMPRESSION_METHOD_AES;
|
|
6973
|
+
}
|
|
6974
|
+
const extraFieldLength = getLength(rawExtraField);
|
|
6975
|
+
const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
|
|
6976
|
+
const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
|
|
6977
|
+
const {
|
|
6978
|
+
headerArray,
|
|
6979
|
+
headerView
|
|
6980
|
+
} = getHeaderArrayData({
|
|
6981
|
+
version,
|
|
6982
|
+
bitFlag: rawBitFlag,
|
|
6983
|
+
compressionMethod,
|
|
6984
|
+
uncompressedSize,
|
|
6985
|
+
compressedSize,
|
|
6986
|
+
rawLastModDate,
|
|
6987
|
+
rawFilename,
|
|
6988
|
+
zip64CompressedSize,
|
|
6989
|
+
zip64UncompressedSize,
|
|
6990
|
+
extraFieldLength
|
|
6991
|
+
});
|
|
6992
|
+
const { crc32 } = entry;
|
|
6993
|
+
if (crc32 !== UNDEFINED_VALUE) {
|
|
6994
|
+
setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
|
|
6995
|
+
}
|
|
6996
|
+
const { offset, diskNumberStart } = entryPositions.get(entry);
|
|
6997
|
+
Object.assign(entry, {
|
|
6998
|
+
zip64Enabled: true,
|
|
6999
|
+
zip64UncompressedSize,
|
|
7000
|
+
zip64CompressedSize,
|
|
7001
|
+
offset,
|
|
7002
|
+
diskNumberStart,
|
|
7003
|
+
zip64DiskNumberStart: false,
|
|
7004
|
+
rawExtraFieldZip64: EMPTY_UINT8_ARRAY,
|
|
7005
|
+
rawExtraFieldAES: EMPTY_UINT8_ARRAY,
|
|
7006
|
+
rawExtraFieldExtendedTimestamp: EMPTY_UINT8_ARRAY,
|
|
7007
|
+
rawExtraFieldNTFS: EMPTY_UINT8_ARRAY,
|
|
7008
|
+
rawExtraFieldUnix: EMPTY_UINT8_ARRAY,
|
|
7009
|
+
rawCentralExtraFieldUnix: EMPTY_UINT8_ARRAY,
|
|
7010
|
+
rawExtraField,
|
|
7011
|
+
rawCentralExtraField: EMPTY_UINT8_ARRAY,
|
|
7012
|
+
headerArray,
|
|
7013
|
+
headerView
|
|
7014
|
+
});
|
|
7015
|
+
fileEntries.set(entry.filename, entry);
|
|
7016
|
+
});
|
|
7017
|
+
} catch (error) {
|
|
7018
|
+
appendedFilenames.forEach(filename => filenames.delete(filename));
|
|
7019
|
+
throw error;
|
|
7020
|
+
} finally {
|
|
7021
|
+
resolveAppendZip();
|
|
7022
|
+
pendingAddFileCalls.delete(promiseAppendZip);
|
|
7023
|
+
if (releaseLockWriter) {
|
|
7024
|
+
releaseLockWriter();
|
|
7025
|
+
}
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
7028
|
+
|
|
6872
7029
|
async function prependZipEntries(zipWriter, reader) {
|
|
6873
7030
|
if (zipWriter.filenames.size) {
|
|
6874
7031
|
throw new Error(ERR_ZIP_NOT_EMPTY);
|
|
6875
7032
|
}
|
|
6876
|
-
await
|
|
7033
|
+
await appendZipEntries(zipWriter, reader);
|
|
6877
7034
|
}
|
|
6878
7035
|
|
|
6879
7036
|
async function addFileEntry(zipWriter, name, reader, options) {
|
|
@@ -8645,26 +8802,63 @@ function removeExtraFieldZip64(rawExtraField) {
|
|
|
8645
8802
|
return rawExtraField;
|
|
8646
8803
|
}
|
|
8647
8804
|
|
|
8648
|
-
async function copyZipData(zipWriter, reader, entries, directoryOffset) {
|
|
8805
|
+
async function copyZipData(zipWriter, reader, entries, keptEntries, directoryOffset, compact, getEntryDataDescriptorLength) {
|
|
8649
8806
|
const { writer } = zipWriter;
|
|
8650
8807
|
const entryPositions = new Map();
|
|
8651
|
-
if (writer.closeDisk) {
|
|
8808
|
+
if (writer.closeDisk || compact) {
|
|
8652
8809
|
const sortedEntries = Array.from(entries).sort((firstEntry, secondEntry) =>
|
|
8653
8810
|
getSourceOffset(reader, firstEntry) - getSourceOffset(reader, secondEntry));
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8811
|
+
const regionEnds = getRegionEnds(reader, sortedEntries, directoryOffset);
|
|
8812
|
+
const keptEntrySet = new Set(keptEntries);
|
|
8813
|
+
const localHeaderLengths = new Map();
|
|
8814
|
+
for (let indexEntry = 0; indexEntry < sortedEntries.length; indexEntry++) {
|
|
8815
|
+
const entry = sortedEntries[indexEntry];
|
|
8816
|
+
if (keptEntrySet.has(entry)) {
|
|
8817
|
+
const sourceOffset = getSourceOffset(reader, entry);
|
|
8818
|
+
const localHeaderLength = await getLocalHeaderLength(reader, sourceOffset);
|
|
8819
|
+
if (localHeaderLength === UNDEFINED_VALUE) {
|
|
8820
|
+
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
8821
|
+
}
|
|
8822
|
+
let entryEnd = sourceOffset + localHeaderLength + entry.compressedSize;
|
|
8823
|
+
if (entry.bitFlag.dataDescriptor) {
|
|
8824
|
+
const dataDescriptorLength = await getEntryDataDescriptorLength(reader, entryEnd, entry);
|
|
8825
|
+
entryEnd = dataDescriptorLength === UNDEFINED_VALUE ? Math.max(entryEnd, regionEnds[indexEntry]) : entryEnd + dataDescriptorLength;
|
|
8826
|
+
}
|
|
8827
|
+
if (entryEnd > regionEnds[indexEntry]) {
|
|
8828
|
+
throw new Error(ERR_OVERLAPPING_ENTRY);
|
|
8829
|
+
}
|
|
8830
|
+
regionEnds[indexEntry] = entryEnd;
|
|
8831
|
+
localHeaderLengths.set(entry, localHeaderLength);
|
|
8832
|
+
}
|
|
8833
|
+
}
|
|
8834
|
+
let copiedOffset = 0;
|
|
8835
|
+
let lastPosition;
|
|
8836
|
+
for (let indexEntry = 0; indexEntry < sortedEntries.length; indexEntry++) {
|
|
8837
|
+
const entry = sortedEntries[indexEntry];
|
|
8838
|
+
if (keptEntrySet.has(entry)) {
|
|
8839
|
+
const sourceOffset = getSourceOffset(reader, entry);
|
|
8840
|
+
if (sourceOffset < copiedOffset) {
|
|
8841
|
+
entryPositions.set(entry, lastPosition);
|
|
8842
|
+
} else {
|
|
8843
|
+
if (!compact) {
|
|
8844
|
+
await copyData(zipWriter, reader, copiedOffset, sourceOffset - copiedOffset);
|
|
8845
|
+
}
|
|
8846
|
+
if (writer.closeDisk && exceedsAvailableSize(writer, localHeaderLengths.get(entry))) {
|
|
8847
|
+
await writer.closeDisk();
|
|
8848
|
+
}
|
|
8849
|
+
lastPosition = {
|
|
8850
|
+
offset: getSegmentOffset(zipWriter, writer),
|
|
8851
|
+
diskNumberStart: getDiskNumber(writer)
|
|
8852
|
+
};
|
|
8853
|
+
entryPositions.set(entry, lastPosition);
|
|
8854
|
+
await copyData(zipWriter, reader, sourceOffset, regionEnds[indexEntry] - sourceOffset);
|
|
8855
|
+
copiedOffset = regionEnds[indexEntry];
|
|
8856
|
+
}
|
|
8857
|
+
}
|
|
8858
|
+
}
|
|
8859
|
+
if (!compact) {
|
|
8860
|
+
await copyData(zipWriter, reader, copiedOffset, directoryOffset - copiedOffset);
|
|
8666
8861
|
}
|
|
8667
|
-
await copyData(zipWriter, reader, copiedLength, directoryOffset - copiedLength);
|
|
8668
8862
|
} else {
|
|
8669
8863
|
const baseOffset = zipWriter.offset;
|
|
8670
8864
|
await copyData(zipWriter, reader, 0, directoryOffset);
|
|
@@ -8676,6 +8870,20 @@ async function copyZipData(zipWriter, reader, entries, directoryOffset) {
|
|
|
8676
8870
|
return entryPositions;
|
|
8677
8871
|
}
|
|
8678
8872
|
|
|
8873
|
+
function getRegionEnds(reader, sortedEntries, directoryOffset) {
|
|
8874
|
+
const regionEnds = new Array(sortedEntries.length);
|
|
8875
|
+
let regionEnd = directoryOffset;
|
|
8876
|
+
for (let indexEntry = sortedEntries.length - 1; indexEntry >= 0; indexEntry--) {
|
|
8877
|
+
const sourceOffset = getSourceOffset(reader, sortedEntries[indexEntry]);
|
|
8878
|
+
const nextEntry = sortedEntries[indexEntry + 1];
|
|
8879
|
+
if (nextEntry && getSourceOffset(reader, nextEntry) > sourceOffset) {
|
|
8880
|
+
regionEnd = Math.min(getSourceOffset(reader, nextEntry), directoryOffset);
|
|
8881
|
+
}
|
|
8882
|
+
regionEnds[indexEntry] = regionEnd;
|
|
8883
|
+
}
|
|
8884
|
+
return regionEnds;
|
|
8885
|
+
}
|
|
8886
|
+
|
|
8679
8887
|
async function copyData(zipWriter, reader, offset, size) {
|
|
8680
8888
|
if (size > 0) {
|
|
8681
8889
|
const { writer } = zipWriter;
|
|
@@ -8683,11 +8891,13 @@ async function copyData(zipWriter, reader, offset, size) {
|
|
|
8683
8891
|
try {
|
|
8684
8892
|
await flushBufferedData(createReadable(reader, { offset, size }), writer, UNDEFINED_VALUE, chunkLength => copiedLength += chunkLength);
|
|
8685
8893
|
} catch (error) {
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
|
|
8690
|
-
|
|
8894
|
+
if (copiedLength) {
|
|
8895
|
+
zipWriter.hasCorruptedEntries = true;
|
|
8896
|
+
try {
|
|
8897
|
+
error.corruptedEntry = true;
|
|
8898
|
+
} catch {
|
|
8899
|
+
// ignored
|
|
8900
|
+
}
|
|
8691
8901
|
}
|
|
8692
8902
|
throw error;
|
|
8693
8903
|
} finally {
|
|
@@ -8698,11 +8908,16 @@ async function copyData(zipWriter, reader, offset, size) {
|
|
|
8698
8908
|
}
|
|
8699
8909
|
|
|
8700
8910
|
async function getLocalHeaderLength(reader, offset) {
|
|
8701
|
-
const headerArray =
|
|
8911
|
+
const headerArray = offset >= 0 && offset + HEADER_SIZE <= reader.size ?
|
|
8912
|
+
await readUint8Array(reader, offset, HEADER_SIZE) :
|
|
8913
|
+
EMPTY_UINT8_ARRAY;
|
|
8702
8914
|
if (getLength(headerArray) < HEADER_SIZE) {
|
|
8703
|
-
return
|
|
8915
|
+
return UNDEFINED_VALUE;
|
|
8704
8916
|
}
|
|
8705
8917
|
const headerView = getDataView(headerArray);
|
|
8918
|
+
if (getUint32(headerView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
8919
|
+
return UNDEFINED_VALUE;
|
|
8920
|
+
}
|
|
8706
8921
|
return HEADER_SIZE +
|
|
8707
8922
|
getUint16(headerView, HEADER_OFFSET_FILENAME_LENGTH + LOCAL_HEADER_COMMON_OFFSET) +
|
|
8708
8923
|
getUint16(headerView, HEADER_OFFSET_EXTRAFIELD_LENGTH + LOCAL_HEADER_COMMON_OFFSET);
|
|
@@ -9053,7 +9268,7 @@ function formatSupported(StreamClass, format) {
|
|
|
9053
9268
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
9054
9269
|
*/
|
|
9055
9270
|
|
|
9056
|
-
const VERSION = "2.
|
|
9271
|
+
const VERSION = "2.21.0";
|
|
9057
9272
|
|
|
9058
9273
|
/*
|
|
9059
9274
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
@@ -11557,4 +11772,4 @@ function getPathParent(parent, path, movedEntry) {
|
|
|
11557
11772
|
return parent;
|
|
11558
11773
|
}
|
|
11559
11774
|
|
|
11560
|
-
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, ERR_AMBIGUOUS_ARCHIVE, ERR_ANCESTOR_ENTRY, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_CODEC_OUT_OF_MEMORY, ERR_DUPLICATED_NAME, ERR_DUPLICATE_IMPORTED_ENTRY, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_HTTP_STATUS, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_BASE_URI, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMMENT_TYPE, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_DATE, ERR_INVALID_DUPLICATES, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_COMMENT_TYPE, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_DATA_TYPE, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_FUNCTION_OPTION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MAX_WORKERS, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORDS, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_PASS_THROUGH, ERR_INVALID_PASS_THROUGH_VALUE, ERR_INVALID_READER, ERR_INVALID_READER_OPTIONS, ERR_INVALID_REQUEST_PASSWORD, ERR_INVALID_SIGNAL, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_STRICTNESS, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_URI, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_PARENT_NOT_DIRECTORY, ERR_READABLE_CONSUMED, ERR_RESERVED_COMPRESSION_METHOD, ERR_ROOT_DIRECTORY_NOT_MOVABLE, ERR_SPLIT_ZIP_FILE, ERR_TARGET_NOT_DIRECTORY, ERR_UNDEFINED_COMPRESSION_METHOD, ERR_UNDEFINED_CRC32, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_UNSUPPORTED_PASS_THROUGH_VALUE, ERR_UNSUPPORTED_SPLIT_USDZ, ERR_UNSUPPORTED_UINT64, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_WRITER_SIZE_NOT_WRITABLE, ERR_ZIP_CRYPTO_LAST_MOD_DATE, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, VERSION, WARNING_APPENDED_DATA, WARNING_CLAMPED_LAST_MODIFICATION_DATE, WARNING_COMPRESSED_PATCHED_DATA, WARNING_COMPRESSION_UNAVAILABLE, WARNING_DUPLICATE_FILENAME, WARNING_MALFORMED_EXTRA_FIELD, WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG, WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD, WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES, WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY, WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY, WARNING_PREPENDED_CENTRAL_DIRECTORY, WARNING_PREPENDED_DATA, WARNING_TRAILING_CENTRAL_DIRECTORY_DATA, WARNING_UNKNOWN_VERSION, WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA, WARNING_UNSORTED_CENTRAL_DIRECTORY, WARNING_WRAPPED_ENTRIES_COUNT, Writer, ZipDirectoryEntry, ZipEntry, ZipFS, ZipFileEntry, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, getRegisteredCodecs, getSupportedCompressionMethods, isZipFile, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|
|
11775
|
+
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, ERR_AMBIGUOUS_ARCHIVE, ERR_ANCESTOR_ENTRY, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_CODEC_OUT_OF_MEMORY, ERR_DUPLICATED_NAME, ERR_DUPLICATE_IMPORTED_ENTRY, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_HTTP_STATUS, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_BASE_URI, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMMENT_TYPE, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_DATE, ERR_INVALID_DUPLICATES, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_COMMENT_TYPE, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_DATA_TYPE, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_FUNCTION_OPTION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MAX_WORKERS, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORDS, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_PASS_THROUGH, ERR_INVALID_PASS_THROUGH_VALUE, ERR_INVALID_READER, ERR_INVALID_READER_OPTIONS, ERR_INVALID_REQUEST_PASSWORD, ERR_INVALID_SIGNAL, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_STRICTNESS, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_URI, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_PARENT_NOT_DIRECTORY, ERR_READABLE_CONSUMED, ERR_RESERVED_COMPRESSION_METHOD, ERR_ROOT_DIRECTORY_NOT_MOVABLE, ERR_SPLIT_ZIP_FILE, ERR_TARGET_NOT_DIRECTORY, ERR_UNDEFINED_COMPRESSION_METHOD, ERR_UNDEFINED_CRC32, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_UNSUPPORTED_PASS_THROUGH_VALUE, ERR_UNSUPPORTED_SPLIT_USDZ, ERR_UNSUPPORTED_UINT64, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_WRITER_SIZE_NOT_WRITABLE, ERR_ZIP_CRYPTO_LAST_MOD_DATE, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, VERSION, WARNING_APPENDED_DATA, WARNING_CLAMPED_LAST_MODIFICATION_DATE, WARNING_COMPRESSED_PATCHED_DATA, WARNING_COMPRESSION_UNAVAILABLE, WARNING_DUPLICATE_FILENAME, WARNING_MALFORMED_EXTRA_FIELD, WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET, WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG, WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD, WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES, WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY, WARNING_MISSING_ZIP64_EXTRA_FIELD, WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY, WARNING_PREPENDED_CENTRAL_DIRECTORY, WARNING_PREPENDED_DATA, WARNING_TRAILING_CENTRAL_DIRECTORY_DATA, WARNING_UNKNOWN_VERSION, WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA, WARNING_UNSORTED_CENTRAL_DIRECTORY, WARNING_WRAPPED_ENTRIES_COUNT, Writer, ZipDirectoryEntry, ZipEntry, ZipFS, ZipFileEntry, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, getRegisteredCodecs, getSupportedCompressionMethods, isZipFile, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|