@zip.js/zip.js 2.8.57 → 2.8.59
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 +458 -200
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +472 -199
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +481 -201
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +497 -193
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +481 -201
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +498 -202
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +499 -203
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +474 -201
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +474 -201
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +475 -202
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +498 -202
- package/index-native.min.js +1 -1
- package/index.cjs +499 -203
- package/index.d.cts +297 -10
- package/index.d.ts +297 -10
- package/index.min.js +1 -1
- package/lib/core/constants.js +4 -0
- package/lib/core/options.js +2 -0
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-fs.js +27 -1
- package/lib/core/zip-reader.js +168 -38
- package/lib/core/zip-writer.js +290 -161
- package/lib/core/zlib-streams-inline.js +1 -1
- package/lib/zip-core-reader.js +16 -1
- package/package.json +1 -1
|
@@ -74,6 +74,7 @@ const BITFLAG_LEVEL_MAX_MASK = 0b010;
|
|
|
74
74
|
const BITFLAG_LEVEL_FAST_MASK = 0b100;
|
|
75
75
|
const BITFLAG_LEVEL_SUPER_FAST_MASK = 0b110;
|
|
76
76
|
const BITFLAG_DATA_DESCRIPTOR = 0b1000;
|
|
77
|
+
const BITFLAG_COMPRESSED_PATCHED_DATA = 0b100000;
|
|
77
78
|
const BITFLAG_STRONG_ENCRYPTION = 0b1000000;
|
|
78
79
|
const BITFLAG_LANG_ENCODING_FLAG = 0b100000000000;
|
|
79
80
|
const BITFLAG_MASKED_LOCAL_HEADERS = 0b10000000000000;
|
|
@@ -92,6 +93,7 @@ const FILE_ATTR_UNIX_SETUID_MASK = 0o4000;
|
|
|
92
93
|
const FILE_ATTR_UNIX_SETGID_MASK = 0o2000;
|
|
93
94
|
const FILE_ATTR_UNIX_STICKY_MASK = 0o1000;
|
|
94
95
|
|
|
96
|
+
const VERSION_STORE = 0x0A;
|
|
95
97
|
const VERSION_DEFLATE = 0x14;
|
|
96
98
|
const VERSION_ZIP64 = 0x2D;
|
|
97
99
|
const VERSION_AES = 0x33;
|
|
@@ -190,6 +192,7 @@ const OPTION_OFFSET = "offset";
|
|
|
190
192
|
const OPTION_USDZ = "usdz";
|
|
191
193
|
const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
|
|
192
194
|
const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
|
|
195
|
+
const OPTION_CENTRAL_EXTRA_FIELD = "centralExtraField";
|
|
193
196
|
const OPTION_STRICTNESS = "strictness";
|
|
194
197
|
const OPTION_FILENAME_VALIDATION = "filenameValidation";
|
|
195
198
|
const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
|
|
@@ -4739,6 +4742,21 @@ const ERR_INVALID_STRICTNESS = "Invalid strictness (must be 'strict', 'balanced'
|
|
|
4739
4742
|
const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
|
|
4740
4743
|
const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
|
|
4741
4744
|
const ERR_UNSUPPORTED_UINT64 = "64-bit value exceeds Number.MAX_SAFE_INTEGER";
|
|
4745
|
+
const WARNING_UNSORTED_CENTRAL_DIRECTORY = "unsorted central directory";
|
|
4746
|
+
const WARNING_UNKNOWN_VERSION = "unknown version needed to extract";
|
|
4747
|
+
const WARNING_COMPRESSED_PATCHED_DATA = "compressed patched data";
|
|
4748
|
+
const WARNING_MALFORMED_EXTRA_FIELD = "malformed extra field";
|
|
4749
|
+
const WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA = "unknown zip64 extensible data";
|
|
4750
|
+
const WARNING_WRAPPED_ENTRIES_COUNT = "wrapped entries count";
|
|
4751
|
+
const WARNING_APPENDED_DATA = "appended data";
|
|
4752
|
+
const WARNING_PREPENDED_DATA = "prepended data";
|
|
4753
|
+
const WARNING_TRAILING_CENTRAL_DIRECTORY_DATA = "trailing central directory data";
|
|
4754
|
+
const WARNING_DUPLICATE_FILENAME = "duplicate filename";
|
|
4755
|
+
const WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY = "mismatched zip64 end of central directory record";
|
|
4756
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG = "mismatched local file header (general purpose bit flag)";
|
|
4757
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD = "mismatched local file header (compression method)";
|
|
4758
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES = "mismatched local file header (crc32 or sizes)";
|
|
4759
|
+
const MAX_KNOWN_VERSION = 63;
|
|
4742
4760
|
const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
|
|
4743
4761
|
const CHARSET_UTF8 = "utf-8";
|
|
4744
4762
|
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
|
|
@@ -4789,6 +4807,7 @@ class ZipReader {
|
|
|
4789
4807
|
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
4790
4808
|
throw new Error(ERR_BAD_FORMAT);
|
|
4791
4809
|
}
|
|
4810
|
+
const warnings = zipReader.warnings = [];
|
|
4792
4811
|
const strictness = getStrictness(options, zipReader.options);
|
|
4793
4812
|
const checkAmbiguity = strictness == STRICTNESS_STRICT;
|
|
4794
4813
|
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
@@ -4812,8 +4831,12 @@ class ZipReader {
|
|
|
4812
4831
|
const commentOffset = endOfDirectoryInfo.offset;
|
|
4813
4832
|
const commentLength = getUint16$1(endOfDirectoryView, 20);
|
|
4814
4833
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
4815
|
-
|
|
4816
|
-
|
|
4834
|
+
const appendedDataLength = reader.size - appendedDataOffset;
|
|
4835
|
+
if (appendedDataLength > maxAppendedDataSize) {
|
|
4836
|
+
throwAmbiguousArchive(WARNING_APPENDED_DATA);
|
|
4837
|
+
}
|
|
4838
|
+
if (appendedDataLength > 0) {
|
|
4839
|
+
addWarning(warnings, WARNING_APPENDED_DATA);
|
|
4817
4840
|
}
|
|
4818
4841
|
let lastDiskNumber = getUint16$1(endOfDirectoryView, 4);
|
|
4819
4842
|
const expectedLastDiskNumber = reader.lastDiskNumber || 0;
|
|
@@ -4867,23 +4890,23 @@ class ZipReader {
|
|
|
4867
4890
|
}
|
|
4868
4891
|
if (lastDiskNumber == MAX_16_BITS) {
|
|
4869
4892
|
lastDiskNumber = getUint32$1(endOfDirectoryView, 16);
|
|
4870
|
-
} else if (
|
|
4871
|
-
|
|
4893
|
+
} else if (lastDiskNumber != getUint32$1(endOfDirectoryView, 16)) {
|
|
4894
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4872
4895
|
}
|
|
4873
4896
|
if (diskNumber == MAX_16_BITS) {
|
|
4874
4897
|
diskNumber = getUint32$1(endOfDirectoryView, 20);
|
|
4875
|
-
} else if (
|
|
4876
|
-
|
|
4898
|
+
} else if (diskNumber != getUint32$1(endOfDirectoryView, 20)) {
|
|
4899
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4877
4900
|
}
|
|
4878
4901
|
if (filesLength == MAX_16_BITS) {
|
|
4879
4902
|
filesLength = getBigUint64(endOfDirectoryView, 32);
|
|
4880
|
-
} else if (
|
|
4881
|
-
|
|
4903
|
+
} else if (filesLength != getBigUint64(endOfDirectoryView, 32)) {
|
|
4904
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4882
4905
|
}
|
|
4883
4906
|
if (directoryDataLength == MAX_32_BITS) {
|
|
4884
4907
|
directoryDataLength = getBigUint64(endOfDirectoryView, 40);
|
|
4885
|
-
} else if (
|
|
4886
|
-
|
|
4908
|
+
} else if (directoryDataLength != getBigUint64(endOfDirectoryView, 40)) {
|
|
4909
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4887
4910
|
}
|
|
4888
4911
|
directoryDataOffset = getDiskOffset$1(reader, diskNumber) + getBigUint64(endOfDirectoryView, 48) + prependedDataLength;
|
|
4889
4912
|
}
|
|
@@ -4952,11 +4975,23 @@ class ZipReader {
|
|
|
4952
4975
|
declaredDirectoryDataLength = directoryArray.length;
|
|
4953
4976
|
decryptedDirectory = true;
|
|
4954
4977
|
}
|
|
4978
|
+
if (directoryEncryptionInfo && !decryptedDirectory &&
|
|
4979
|
+
(directoryArray.length < 4 || getUint32$1(directoryView, 0) == CENTRAL_FILE_HEADER_SIGNATURE)) {
|
|
4980
|
+
addWarning(warnings, WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA);
|
|
4981
|
+
}
|
|
4955
4982
|
startOffset = directoryDataOffset;
|
|
4956
4983
|
const filenameEncoding = getOptionValue$1(zipReader, options, OPTION_FILENAME_ENCODING);
|
|
4957
4984
|
const commentEncoding = getOptionValue$1(zipReader, options, OPTION_COMMENT_ENCODING);
|
|
4958
|
-
const filenames =
|
|
4985
|
+
const filenames = new Set();
|
|
4959
4986
|
let duplicateFilename;
|
|
4987
|
+
let previousEntryPosition = -1;
|
|
4988
|
+
const recoverWrappedFilesLength = !checkAmbiguity && !zip64EndOfDirectory;
|
|
4989
|
+
if (!filesLength && recoverWrappedFilesLength) {
|
|
4990
|
+
filesLength = getWrappedFilesLength(directoryView, directoryArray, offset);
|
|
4991
|
+
if (filesLength) {
|
|
4992
|
+
addWarning(warnings, WARNING_WRAPPED_ENTRIES_COUNT);
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4960
4995
|
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
4961
4996
|
const fileEntry = new ZipEntry(reader, zipReader.options);
|
|
4962
4997
|
if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32$1(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
@@ -5034,15 +5069,26 @@ class ZipReader {
|
|
|
5034
5069
|
filename,
|
|
5035
5070
|
comment
|
|
5036
5071
|
});
|
|
5037
|
-
readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6)
|
|
5072
|
+
if (readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6)) {
|
|
5073
|
+
addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD, filename);
|
|
5074
|
+
}
|
|
5038
5075
|
fileEntry.offset += prependedDataLength;
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5076
|
+
const entryPosition = getDiskOffset$1(reader, fileEntry.diskNumberStart) + fileEntry.offset;
|
|
5077
|
+
startOffset = Math.min(entryPosition, startOffset);
|
|
5078
|
+
if (entryPosition < previousEntryPosition) {
|
|
5079
|
+
addWarning(warnings, WARNING_UNSORTED_CENTRAL_DIRECTORY, filename);
|
|
5080
|
+
}
|
|
5081
|
+
previousEntryPosition = entryPosition;
|
|
5082
|
+
if ((fileEntry.version & MAX_8_BITS) > MAX_KNOWN_VERSION) {
|
|
5083
|
+
addWarning(warnings, WARNING_UNKNOWN_VERSION, filename);
|
|
5084
|
+
}
|
|
5085
|
+
if ((fileEntry.rawBitFlag & BITFLAG_COMPRESSED_PATCHED_DATA) == BITFLAG_COMPRESSED_PATCHED_DATA) {
|
|
5086
|
+
addWarning(warnings, WARNING_COMPRESSED_PATCHED_DATA, filename);
|
|
5045
5087
|
}
|
|
5088
|
+
if (filenames.has(fileEntry.filename)) {
|
|
5089
|
+
duplicateFilename = true;
|
|
5090
|
+
}
|
|
5091
|
+
filenames.add(fileEntry.filename);
|
|
5046
5092
|
const unixExternalUpper = (fileEntry.externalFileAttributes >> 16) & MAX_16_BITS;
|
|
5047
5093
|
if (fileEntry.unixMode === UNDEFINED_VALUE && (unixExternalUpper & (FILE_ATTR_UNIX_DEFAULT_MASK | FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_TYPE_DIR)) != 0) {
|
|
5048
5094
|
fileEntry.unixMode = unixExternalUpper;
|
|
@@ -5066,7 +5112,7 @@ class ZipReader {
|
|
|
5066
5112
|
internalFileAttribute: fileEntry.internalFileAttributes,
|
|
5067
5113
|
externalFileAttribute: fileEntry.externalFileAttributes,
|
|
5068
5114
|
executable,
|
|
5069
|
-
directory: modeIsDir || upperIsDir || (msDosCompatible && msdosAttributes.directory) ||
|
|
5115
|
+
directory: modeIsDir || upperIsDir || (msDosCompatible && msdosAttributes.directory) || fileEntry.filename.endsWith(DIRECTORY_SIGNATURE),
|
|
5070
5116
|
zipCrypto: fileEntry.encrypted && !fileEntry.extraFieldAES
|
|
5071
5117
|
});
|
|
5072
5118
|
const entry = new Entry(fileEntry);
|
|
@@ -5079,6 +5125,13 @@ class ZipReader {
|
|
|
5079
5125
|
return arrayBufferPromise;
|
|
5080
5126
|
};
|
|
5081
5127
|
offset = endOffset;
|
|
5128
|
+
if (indexFile == filesLength - 1 && recoverWrappedFilesLength) {
|
|
5129
|
+
const wrappedFilesLength = getWrappedFilesLength(directoryView, directoryArray, offset);
|
|
5130
|
+
if (wrappedFilesLength) {
|
|
5131
|
+
filesLength += wrappedFilesLength;
|
|
5132
|
+
addWarning(warnings, WARNING_WRAPPED_ENTRIES_COUNT);
|
|
5133
|
+
}
|
|
5134
|
+
}
|
|
5082
5135
|
const { onprogress } = options;
|
|
5083
5136
|
if (onprogress) {
|
|
5084
5137
|
try {
|
|
@@ -5103,18 +5156,22 @@ class ZipReader {
|
|
|
5103
5156
|
zipReader.digitalSignature = digitalSignature;
|
|
5104
5157
|
offsetAfterSignature = offset + 6 + digitalSignature.length;
|
|
5105
5158
|
}
|
|
5106
|
-
if (
|
|
5107
|
-
|
|
5159
|
+
if ((offset != declaredDirectoryDataLength && offsetAfterSignature != declaredDirectoryDataLength) ||
|
|
5160
|
+
(!decryptedDirectory && offset != directoryDataLength && offsetAfterSignature != directoryDataLength)) {
|
|
5161
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_TRAILING_CENTRAL_DIRECTORY_DATA);
|
|
5108
5162
|
}
|
|
5109
5163
|
if (duplicateFilename) {
|
|
5110
|
-
|
|
5164
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_DUPLICATE_FILENAME);
|
|
5111
5165
|
}
|
|
5112
5166
|
const extractPrependedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
|
|
5113
5167
|
const extractAppendedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
|
|
5114
5168
|
const splitZipSignatureLength = (checkAmbiguity || extractPrependedData) && filesLength &&
|
|
5115
5169
|
startOffset == SPLIT_ZIP_FILE_SIGNATURE_LENGTH && await startsWithSplitZipMarker(reader) ? SPLIT_ZIP_FILE_SIGNATURE_LENGTH : 0;
|
|
5116
5170
|
if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > splitZipSignatureLength))) {
|
|
5117
|
-
throwAmbiguousArchive(
|
|
5171
|
+
throwAmbiguousArchive(WARNING_PREPENDED_DATA);
|
|
5172
|
+
}
|
|
5173
|
+
if (prependedDataLength || (filesLength && startOffset > SPLIT_ZIP_FILE_SIGNATURE_LENGTH)) {
|
|
5174
|
+
addWarning(warnings, WARNING_PREPENDED_DATA);
|
|
5118
5175
|
}
|
|
5119
5176
|
if (extractPrependedData) {
|
|
5120
5177
|
zipReader.prependedData = startOffset > splitZipSignatureLength ?
|
|
@@ -5184,6 +5241,28 @@ class ZipReaderStream {
|
|
|
5184
5241
|
}
|
|
5185
5242
|
}
|
|
5186
5243
|
|
|
5244
|
+
async function isZipFile(reader, options = {}) {
|
|
5245
|
+
reader = new GenericReader(reader);
|
|
5246
|
+
await initStream(reader);
|
|
5247
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
5248
|
+
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
5249
|
+
await initStream(reader);
|
|
5250
|
+
}
|
|
5251
|
+
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
5252
|
+
return false;
|
|
5253
|
+
}
|
|
5254
|
+
const strictness = getStrictness(options, {});
|
|
5255
|
+
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
5256
|
+
const maxAppendedDataSize = getMaxAppendedDataSize(options[OPTION_MAX_APPENDED_DATA_SIZE], strictness);
|
|
5257
|
+
const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
|
|
5258
|
+
if (!endOfDirectoryInfo || (strictness == STRICTNESS_STRICT && endOfDirectoryReachingEndCount > 1)) {
|
|
5259
|
+
return false;
|
|
5260
|
+
}
|
|
5261
|
+
const commentLength = getUint16$1(getDataView(endOfDirectoryInfo), 20);
|
|
5262
|
+
const appendedDataOffset = endOfDirectoryInfo.offset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
5263
|
+
return reader.size - appendedDataOffset <= maxAppendedDataSize;
|
|
5264
|
+
}
|
|
5265
|
+
|
|
5187
5266
|
class ZipEntry {
|
|
5188
5267
|
|
|
5189
5268
|
constructor(reader, options) {
|
|
@@ -5215,6 +5294,7 @@ class ZipEntry {
|
|
|
5215
5294
|
dataDescriptor
|
|
5216
5295
|
} = bitFlag;
|
|
5217
5296
|
const localDirectory = fileEntry.localDirectory = {};
|
|
5297
|
+
const warnings = fileEntry.warnings = [];
|
|
5218
5298
|
const localHeaderOffset = getDiskOffset$1(reader, diskNumberStart) + offset;
|
|
5219
5299
|
const dataArray = await readUint8Array(reader, localHeaderOffset, HEADER_SIZE);
|
|
5220
5300
|
const dataView = getDataView(dataArray);
|
|
@@ -5237,6 +5317,7 @@ class ZipEntry {
|
|
|
5237
5317
|
extraFieldLength,
|
|
5238
5318
|
filenameLength
|
|
5239
5319
|
} = localDirectory;
|
|
5320
|
+
const dataOffset = localDirectory.dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
|
|
5240
5321
|
const checkLocalDirectoryOption = getOptionValue$1(zipEntry, options, OPTION_CHECK_LOCAL_DIRECTORY);
|
|
5241
5322
|
const entryStrictness = getStrictness(options, zipEntry.options);
|
|
5242
5323
|
const checkLocalDirectory = getCheckLocalDirectory(checkLocalDirectoryOption, entryStrictness);
|
|
@@ -5254,10 +5335,10 @@ class ZipEntry {
|
|
|
5254
5335
|
if (checkLocalFilename) {
|
|
5255
5336
|
localDirectory.rawFilename = rawLocalFilename;
|
|
5256
5337
|
}
|
|
5257
|
-
readCommonFooter(zipEntry, localDirectory, dataView, 4, true)
|
|
5258
|
-
|
|
5259
|
-
validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename);
|
|
5338
|
+
if (readCommonFooter(zipEntry, localDirectory, dataView, 4, true)) {
|
|
5339
|
+
addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD);
|
|
5260
5340
|
}
|
|
5341
|
+
validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename, checkLocalDirectory ? UNDEFINED_VALUE : warnings);
|
|
5261
5342
|
const { lastAccessDate, creationDate, uid, gid } = localDirectory;
|
|
5262
5343
|
if (lastAccessDate) {
|
|
5263
5344
|
fileEntry.lastAccessDate = lastAccessDate;
|
|
@@ -5290,7 +5371,6 @@ class ZipEntry {
|
|
|
5290
5371
|
throw new Error(ERR_ENCRYPTED);
|
|
5291
5372
|
}
|
|
5292
5373
|
}
|
|
5293
|
-
const dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
|
|
5294
5374
|
if (dataOffset + compressedSize > reader.size) {
|
|
5295
5375
|
throw new Error(ERR_ENTRY_DATA_OUT_OF_BOUNDS);
|
|
5296
5376
|
}
|
|
@@ -5410,6 +5490,16 @@ function detectEncryptedCentralDirectory(directoryView) {
|
|
|
5410
5490
|
return false;
|
|
5411
5491
|
}
|
|
5412
5492
|
|
|
5493
|
+
function getWrappedFilesLength(directoryView, directoryArray, offset) {
|
|
5494
|
+
let wrappedFilesLength = 0;
|
|
5495
|
+
while (offset + CENTRAL_FILE_HEADER_LENGTH <= directoryArray.length && getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
5496
|
+
offset += CENTRAL_FILE_HEADER_LENGTH +
|
|
5497
|
+
getUint16$1(directoryView, offset + 28) + getUint16$1(directoryView, offset + 30) + getUint16$1(directoryView, offset + 32);
|
|
5498
|
+
wrappedFilesLength++;
|
|
5499
|
+
}
|
|
5500
|
+
return wrappedFilesLength % (MAX_16_BITS + 1) ? 0 : wrappedFilesLength;
|
|
5501
|
+
}
|
|
5502
|
+
|
|
5413
5503
|
function readDigitalSignature(signatureRecordArray) {
|
|
5414
5504
|
if (signatureRecordArray.length >= 6) {
|
|
5415
5505
|
const signatureRecordView = getDataView(signatureRecordArray);
|
|
@@ -5474,6 +5564,7 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5474
5564
|
const extraField = directory.extraField = new Map();
|
|
5475
5565
|
const rawExtraFieldView = getDataView(rawExtraField);
|
|
5476
5566
|
let offsetExtraField = 0;
|
|
5567
|
+
let malformedExtraField = false;
|
|
5477
5568
|
try {
|
|
5478
5569
|
while (offsetExtraField < rawExtraField.length) {
|
|
5479
5570
|
const type = getUint16$1(rawExtraFieldView, offsetExtraField);
|
|
@@ -5485,7 +5576,10 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5485
5576
|
offsetExtraField += 4 + size;
|
|
5486
5577
|
}
|
|
5487
5578
|
} catch {
|
|
5488
|
-
|
|
5579
|
+
malformedExtraField = true;
|
|
5580
|
+
}
|
|
5581
|
+
if (offsetExtraField > rawExtraField.length) {
|
|
5582
|
+
malformedExtraField = true;
|
|
5489
5583
|
}
|
|
5490
5584
|
const compressionMethod = getUint16$1(dataView, offset + 4);
|
|
5491
5585
|
Object.assign(directory, {
|
|
@@ -5553,6 +5647,7 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5553
5647
|
if (extraFieldUSDZ) {
|
|
5554
5648
|
directory.extraFieldUSDZ = extraFieldUSDZ;
|
|
5555
5649
|
}
|
|
5650
|
+
return malformedExtraField;
|
|
5556
5651
|
}
|
|
5557
5652
|
|
|
5558
5653
|
function readExtraFieldZip64(extraFieldZip64, directory) {
|
|
@@ -5582,10 +5677,11 @@ function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName,
|
|
|
5582
5677
|
const computedCrc32View = getDataView(new Uint8Array(4));
|
|
5583
5678
|
computedCrc32View.setUint32(0, computedCrc32.get(), true);
|
|
5584
5679
|
const nameCrc32 = getUint32$1(extraFieldView, 1);
|
|
5680
|
+
const version = getUint8(extraFieldView, 0);
|
|
5585
5681
|
Object.assign(extraFieldUnicode, {
|
|
5586
|
-
version
|
|
5682
|
+
version,
|
|
5587
5683
|
[propertyName]: decodeText(extraFieldUnicode.data.subarray(5)),
|
|
5588
|
-
valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
|
|
5684
|
+
valid: version == 1 && !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
|
|
5589
5685
|
});
|
|
5590
5686
|
if (extraFieldUnicode.valid) {
|
|
5591
5687
|
directory[propertyName] = extraFieldUnicode[propertyName];
|
|
@@ -6013,27 +6109,46 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
|
|
|
6013
6109
|
return UNDEFINED_VALUE;
|
|
6014
6110
|
}
|
|
6015
6111
|
|
|
6016
|
-
function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
|
|
6112
|
+
function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename, warnings) {
|
|
6017
6113
|
const { rawFilename } = zipEntry;
|
|
6114
|
+
const reject = !warnings;
|
|
6018
6115
|
const maskedLocalDirectory = zipEntry.decryptedDirectory &&
|
|
6019
6116
|
(localDirectory.rawBitFlag & BITFLAG_MASKED_LOCAL_HEADERS) == BITFLAG_MASKED_LOCAL_HEADERS;
|
|
6020
6117
|
if (checkLocalFilename && !maskedLocalDirectory &&
|
|
6021
6118
|
(rawLocalFilename.length != rawFilename.length ||
|
|
6022
6119
|
rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
|
|
6023
|
-
|
|
6120
|
+
reportAmbiguity(reject, warnings, "mismatched local file header (filename)");
|
|
6024
6121
|
}
|
|
6025
6122
|
if ((localDirectory.rawBitFlag & BITFLAG_AMBIGUITY_MASK) != (zipEntry.rawBitFlag & BITFLAG_AMBIGUITY_MASK)) {
|
|
6026
|
-
|
|
6123
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG);
|
|
6027
6124
|
}
|
|
6028
6125
|
if (localDirectory.compressionMethod != zipEntry.compressionMethod) {
|
|
6029
|
-
|
|
6126
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD);
|
|
6030
6127
|
}
|
|
6031
6128
|
if (!localDirectory.bitFlag.dataDescriptor && !maskedLocalDirectory &&
|
|
6032
6129
|
(localDirectory.crc32 || localDirectory.compressedSize || localDirectory.uncompressedSize) &&
|
|
6033
6130
|
(localDirectory.crc32 != zipEntry.crc32 ||
|
|
6034
6131
|
localDirectory.compressedSize != zipEntry.compressedSize ||
|
|
6035
6132
|
localDirectory.uncompressedSize != zipEntry.uncompressedSize)) {
|
|
6036
|
-
|
|
6133
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES);
|
|
6134
|
+
}
|
|
6135
|
+
}
|
|
6136
|
+
|
|
6137
|
+
function reportAmbiguity(reject, warnings, reason) {
|
|
6138
|
+
if (reject) {
|
|
6139
|
+
throwAmbiguousArchive(reason);
|
|
6140
|
+
} else {
|
|
6141
|
+
addWarning(warnings, reason);
|
|
6142
|
+
}
|
|
6143
|
+
}
|
|
6144
|
+
|
|
6145
|
+
function addWarning(warnings, reason, filename) {
|
|
6146
|
+
if (!warnings.some(warning => warning.reason == reason)) {
|
|
6147
|
+
const warning = { reason };
|
|
6148
|
+
if (filename !== UNDEFINED_VALUE) {
|
|
6149
|
+
warning.filename = filename;
|
|
6150
|
+
}
|
|
6151
|
+
warnings.push(warning);
|
|
6037
6152
|
}
|
|
6038
6153
|
}
|
|
6039
6154
|
|
|
@@ -6054,7 +6169,8 @@ function getFunctionOptionValue$1(zipReader, options, name) {
|
|
|
6054
6169
|
|
|
6055
6170
|
function getDate(timeRaw) {
|
|
6056
6171
|
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
|
|
6057
|
-
|
|
6172
|
+
const result = new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
|
|
6173
|
+
return result < MIN_DATE ? MIN_DATE : result;
|
|
6058
6174
|
}
|
|
6059
6175
|
|
|
6060
6176
|
function getDateNTFS(timeRaw) {
|
|
@@ -6109,8 +6225,23 @@ var zipReader = /*#__PURE__*/Object.freeze({
|
|
|
6109
6225
|
ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
|
|
6110
6226
|
ERR_UNSUPPORTED_UINT64: ERR_UNSUPPORTED_UINT64,
|
|
6111
6227
|
ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
|
|
6228
|
+
WARNING_APPENDED_DATA: WARNING_APPENDED_DATA,
|
|
6229
|
+
WARNING_COMPRESSED_PATCHED_DATA: WARNING_COMPRESSED_PATCHED_DATA,
|
|
6230
|
+
WARNING_DUPLICATE_FILENAME: WARNING_DUPLICATE_FILENAME,
|
|
6231
|
+
WARNING_MALFORMED_EXTRA_FIELD: WARNING_MALFORMED_EXTRA_FIELD,
|
|
6232
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG: WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG,
|
|
6233
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD: WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD,
|
|
6234
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES: WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES,
|
|
6235
|
+
WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY: WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY,
|
|
6236
|
+
WARNING_PREPENDED_DATA: WARNING_PREPENDED_DATA,
|
|
6237
|
+
WARNING_TRAILING_CENTRAL_DIRECTORY_DATA: WARNING_TRAILING_CENTRAL_DIRECTORY_DATA,
|
|
6238
|
+
WARNING_UNKNOWN_VERSION: WARNING_UNKNOWN_VERSION,
|
|
6239
|
+
WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA: WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA,
|
|
6240
|
+
WARNING_UNSORTED_CENTRAL_DIRECTORY: WARNING_UNSORTED_CENTRAL_DIRECTORY,
|
|
6241
|
+
WARNING_WRAPPED_ENTRIES_COUNT: WARNING_WRAPPED_ENTRIES_COUNT,
|
|
6112
6242
|
ZipReader: ZipReader,
|
|
6113
|
-
ZipReaderStream: ZipReaderStream
|
|
6243
|
+
ZipReaderStream: ZipReaderStream,
|
|
6244
|
+
isZipFile: isZipFile
|
|
6114
6245
|
});
|
|
6115
6246
|
|
|
6116
6247
|
/*
|
|
@@ -6207,153 +6338,151 @@ class ZipWriter {
|
|
|
6207
6338
|
offset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? writer.size || writer.writable.size || 0 : options[OPTION_OFFSET],
|
|
6208
6339
|
initialOffset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : options[OPTION_OFFSET] - (writer.size || writer.writable.size || 0),
|
|
6209
6340
|
pendingAddFileCalls: new Set(),
|
|
6341
|
+
pendingErrors: [],
|
|
6210
6342
|
bufferedWrites: 0,
|
|
6211
6343
|
lastFileEntry: UNDEFINED_VALUE
|
|
6212
6344
|
});
|
|
6213
6345
|
}
|
|
6214
6346
|
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
6222
|
-
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
6223
|
-
await initStream(reader);
|
|
6224
|
-
}
|
|
6225
|
-
const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
|
|
6226
|
-
const zipReader$1 = new ZipReader(reader);
|
|
6227
|
-
const entries = await zipReader$1.getEntries();
|
|
6228
|
-
await zipReader$1.close();
|
|
6229
|
-
await initStream(this.writer);
|
|
6230
|
-
const { directoryOffset } = zipReader$1;
|
|
6231
|
-
if (this.addSplitZipSignature) {
|
|
6232
|
-
delete this.addSplitZipSignature;
|
|
6233
|
-
if (!await startsWithSplitZipSignature(reader)) {
|
|
6234
|
-
await writeData(this.writer, getSplitZipSignatureArray());
|
|
6235
|
-
this.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6236
|
-
}
|
|
6237
|
-
}
|
|
6238
|
-
const entryPositions = await copyZipData(this, reader, entries, directoryOffset);
|
|
6239
|
-
this.filenames = new Set(entries.map(entry => entry.filename));
|
|
6240
|
-
this.fileEntries = new Map(entries.map(entry => {
|
|
6241
|
-
const {
|
|
6242
|
-
version,
|
|
6243
|
-
rawLastModDate,
|
|
6244
|
-
lastAccessDate,
|
|
6245
|
-
creationDate,
|
|
6246
|
-
rawFilename,
|
|
6247
|
-
bitFlag,
|
|
6248
|
-
encrypted,
|
|
6249
|
-
uncompressedSize,
|
|
6250
|
-
compressedSize,
|
|
6251
|
-
extraFieldZip64
|
|
6252
|
-
} = entry;
|
|
6253
|
-
let {
|
|
6254
|
-
compressionMethod,
|
|
6255
|
-
rawExtraFieldZip64,
|
|
6256
|
-
rawExtraFieldAES,
|
|
6257
|
-
rawExtraFieldExtendedTimestamp,
|
|
6258
|
-
rawExtraFieldNTFS,
|
|
6259
|
-
rawExtraFieldUnix,
|
|
6260
|
-
rawExtraField,
|
|
6261
|
-
} = entry;
|
|
6262
|
-
const { level, languageEncodingFlag, dataDescriptor } = bitFlag;
|
|
6263
|
-
rawExtraFieldZip64 = rawExtraFieldZip64 || EMPTY_UINT8_ARRAY;
|
|
6264
|
-
rawExtraFieldAES = rawExtraFieldAES || EMPTY_UINT8_ARRAY;
|
|
6265
|
-
rawExtraFieldExtendedTimestamp = rawExtraFieldExtendedTimestamp || EMPTY_UINT8_ARRAY;
|
|
6266
|
-
rawExtraFieldNTFS = rawExtraFieldNTFS || EMPTY_UINT8_ARRAY;
|
|
6267
|
-
rawExtraFieldUnix = rawExtraFieldUnix || EMPTY_UINT8_ARRAY;
|
|
6268
|
-
rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
|
|
6269
|
-
if (entry.extraFieldAES) {
|
|
6270
|
-
compressionMethod = COMPRESSION_METHOD_AES;
|
|
6271
|
-
}
|
|
6272
|
-
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
|
|
6273
|
-
const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
|
|
6274
|
-
const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
|
|
6275
|
-
const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
|
|
6276
|
-
const {
|
|
6277
|
-
headerArray,
|
|
6278
|
-
headerView
|
|
6279
|
-
} = getHeaderArrayData({
|
|
6280
|
-
version,
|
|
6281
|
-
bitFlag: bitFlagValue,
|
|
6282
|
-
compressionMethod,
|
|
6283
|
-
uncompressedSize,
|
|
6284
|
-
compressedSize,
|
|
6285
|
-
rawLastModDate,
|
|
6286
|
-
rawFilename,
|
|
6287
|
-
zip64CompressedSize,
|
|
6288
|
-
zip64UncompressedSize,
|
|
6289
|
-
extraFieldLength
|
|
6290
|
-
});
|
|
6291
|
-
const { crc32 } = entry;
|
|
6292
|
-
if (crc32 !== UNDEFINED_VALUE) {
|
|
6293
|
-
setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
|
|
6294
|
-
}
|
|
6295
|
-
const { offset, diskNumberStart } = entryPositions.get(entry);
|
|
6296
|
-
Object.assign(entry, {
|
|
6297
|
-
zip64UncompressedSize,
|
|
6298
|
-
zip64CompressedSize,
|
|
6299
|
-
offset,
|
|
6300
|
-
diskNumberStart,
|
|
6301
|
-
zip64DiskNumberStart: false,
|
|
6302
|
-
rawExtraFieldZip64,
|
|
6303
|
-
rawExtraFieldAES,
|
|
6304
|
-
rawExtraFieldExtendedTimestamp,
|
|
6305
|
-
rawExtraFieldNTFS,
|
|
6306
|
-
rawExtraFieldUnix,
|
|
6307
|
-
rawExtraField,
|
|
6308
|
-
extendedTimestamp: rawExtraFieldExtendedTimestamp.length > 0 || rawExtraFieldNTFS.length > 0,
|
|
6309
|
-
extraFieldExtendedTimestampFlag: 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0),
|
|
6310
|
-
headerArray,
|
|
6311
|
-
headerView
|
|
6312
|
-
});
|
|
6313
|
-
return [entry.filename, entry];
|
|
6314
|
-
}));
|
|
6347
|
+
prependZip(reader) {
|
|
6348
|
+
return watchPromiseError(this, prependZipEntries(this, reader));
|
|
6349
|
+
}
|
|
6350
|
+
|
|
6351
|
+
appendZip(reader) {
|
|
6352
|
+
return watchPromiseError(this, this.appendZipEntries(reader));
|
|
6315
6353
|
}
|
|
6316
6354
|
|
|
6317
|
-
async
|
|
6355
|
+
async appendZipEntries(reader) {
|
|
6318
6356
|
const zipWriter = this;
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
workers++;
|
|
6323
|
-
} else {
|
|
6324
|
-
await new Promise(resolve => pendingEntries.push(resolve));
|
|
6357
|
+
const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
|
|
6358
|
+
while (pendingAddFileCalls.size) {
|
|
6359
|
+
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6325
6360
|
}
|
|
6326
|
-
let
|
|
6327
|
-
|
|
6361
|
+
let resolveAppendZip;
|
|
6362
|
+
const promiseAppendZip = new Promise(resolve => resolveAppendZip = resolve);
|
|
6363
|
+
pendingAddFileCalls.add(promiseAppendZip);
|
|
6364
|
+
const appendedFilenames = [];
|
|
6365
|
+
let releaseLockWriter;
|
|
6328
6366
|
try {
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
}
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6367
|
+
reader = new GenericReader(reader);
|
|
6368
|
+
await initStream(reader);
|
|
6369
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
6370
|
+
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
6371
|
+
await initStream(reader);
|
|
6372
|
+
}
|
|
6373
|
+
const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
|
|
6374
|
+
const zipReader$1 = new ZipReader(reader);
|
|
6375
|
+
const entries = await zipReader$1.getEntries();
|
|
6376
|
+
await zipReader$1.close();
|
|
6377
|
+
await initStream(zipWriter.writer);
|
|
6378
|
+
const { directoryOffset } = zipReader$1;
|
|
6379
|
+
entries.forEach(({ filename }) => {
|
|
6380
|
+
if (filenames.has(filename)) {
|
|
6381
|
+
throw new Error(ERR_DUPLICATED_NAME);
|
|
6382
|
+
}
|
|
6383
|
+
filenames.add(filename);
|
|
6384
|
+
appendedFilenames.push(filename);
|
|
6385
|
+
});
|
|
6386
|
+
zipWriter.writerLocked = true;
|
|
6387
|
+
const { lockWriter } = zipWriter;
|
|
6388
|
+
zipWriter.lockWriter = new Promise(resolve => releaseLockWriter = () => {
|
|
6389
|
+
zipWriter.writerLocked = false;
|
|
6390
|
+
resolve();
|
|
6391
|
+
});
|
|
6392
|
+
await lockWriter;
|
|
6393
|
+
if (zipWriter.addSplitZipSignature) {
|
|
6394
|
+
delete zipWriter.addSplitZipSignature;
|
|
6395
|
+
if (!await startsWithSplitZipSignature(reader)) {
|
|
6396
|
+
await writeData(zipWriter.writer, getSplitZipSignatureArray());
|
|
6397
|
+
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6398
|
+
}
|
|
6344
6399
|
}
|
|
6400
|
+
const entryPositions = await copyZipData(zipWriter, reader, entries, directoryOffset);
|
|
6401
|
+
entries.forEach(entry => {
|
|
6402
|
+
const {
|
|
6403
|
+
version,
|
|
6404
|
+
rawLastModDate,
|
|
6405
|
+
rawFilename,
|
|
6406
|
+
bitFlag,
|
|
6407
|
+
encrypted,
|
|
6408
|
+
uncompressedSize,
|
|
6409
|
+
compressedSize,
|
|
6410
|
+
extraFieldZip64
|
|
6411
|
+
} = entry;
|
|
6412
|
+
let {
|
|
6413
|
+
compressionMethod,
|
|
6414
|
+
rawExtraField,
|
|
6415
|
+
} = entry;
|
|
6416
|
+
const { level, languageEncodingFlag, dataDescriptor } = bitFlag;
|
|
6417
|
+
rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
|
|
6418
|
+
if (entry.extraFieldAES) {
|
|
6419
|
+
compressionMethod = COMPRESSION_METHOD_AES;
|
|
6420
|
+
}
|
|
6421
|
+
const extraFieldLength = getLength(rawExtraField);
|
|
6422
|
+
const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
|
|
6423
|
+
const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
|
|
6424
|
+
const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
|
|
6425
|
+
const {
|
|
6426
|
+
headerArray,
|
|
6427
|
+
headerView
|
|
6428
|
+
} = getHeaderArrayData({
|
|
6429
|
+
version,
|
|
6430
|
+
bitFlag: bitFlagValue,
|
|
6431
|
+
compressionMethod,
|
|
6432
|
+
uncompressedSize,
|
|
6433
|
+
compressedSize,
|
|
6434
|
+
rawLastModDate,
|
|
6435
|
+
rawFilename,
|
|
6436
|
+
zip64CompressedSize,
|
|
6437
|
+
zip64UncompressedSize,
|
|
6438
|
+
extraFieldLength
|
|
6439
|
+
});
|
|
6440
|
+
const { crc32 } = entry;
|
|
6441
|
+
if (crc32 !== UNDEFINED_VALUE) {
|
|
6442
|
+
setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
|
|
6443
|
+
}
|
|
6444
|
+
const { offset, diskNumberStart } = entryPositions.get(entry);
|
|
6445
|
+
Object.assign(entry, {
|
|
6446
|
+
zip64UncompressedSize,
|
|
6447
|
+
zip64CompressedSize,
|
|
6448
|
+
offset,
|
|
6449
|
+
diskNumberStart,
|
|
6450
|
+
zip64DiskNumberStart: false,
|
|
6451
|
+
rawExtraFieldZip64: EMPTY_UINT8_ARRAY,
|
|
6452
|
+
rawExtraFieldAES: EMPTY_UINT8_ARRAY,
|
|
6453
|
+
rawExtraFieldExtendedTimestamp: EMPTY_UINT8_ARRAY,
|
|
6454
|
+
rawExtraFieldNTFS: EMPTY_UINT8_ARRAY,
|
|
6455
|
+
rawExtraFieldUnix: EMPTY_UINT8_ARRAY,
|
|
6456
|
+
rawExtraField,
|
|
6457
|
+
rawCentralExtraField: EMPTY_UINT8_ARRAY,
|
|
6458
|
+
extendedTimestamp: false,
|
|
6459
|
+
headerArray,
|
|
6460
|
+
headerView
|
|
6461
|
+
});
|
|
6462
|
+
fileEntries.set(entry.filename, entry);
|
|
6463
|
+
});
|
|
6464
|
+
} catch (error) {
|
|
6465
|
+
appendedFilenames.forEach(filename => filenames.delete(filename));
|
|
6345
6466
|
throw error;
|
|
6346
6467
|
} finally {
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
if (
|
|
6350
|
-
|
|
6351
|
-
} else {
|
|
6352
|
-
workers--;
|
|
6468
|
+
resolveAppendZip();
|
|
6469
|
+
pendingAddFileCalls.delete(promiseAppendZip);
|
|
6470
|
+
if (releaseLockWriter) {
|
|
6471
|
+
releaseLockWriter();
|
|
6353
6472
|
}
|
|
6354
6473
|
}
|
|
6355
6474
|
}
|
|
6356
6475
|
|
|
6476
|
+
add(name = "", reader, options = {}) {
|
|
6477
|
+
const zipWriter = this;
|
|
6478
|
+
const { pendingAddFileCalls } = zipWriter;
|
|
6479
|
+
const promiseAddFile = addFileEntry(zipWriter, name, reader, options);
|
|
6480
|
+
pendingAddFileCalls.add(promiseAddFile);
|
|
6481
|
+
const deletePendingAddFileCall = () => pendingAddFileCalls.delete(promiseAddFile);
|
|
6482
|
+
Promise.prototype.then.call(promiseAddFile, deletePendingAddFileCall, deletePendingAddFileCall);
|
|
6483
|
+
return watchPromiseError(zipWriter, promiseAddFile);
|
|
6484
|
+
}
|
|
6485
|
+
|
|
6357
6486
|
remove(entry) {
|
|
6358
6487
|
const { filenames, fileEntries } = this;
|
|
6359
6488
|
// deno-lint-ignore valid-typeof
|
|
@@ -6384,6 +6513,19 @@ class ZipWriter {
|
|
|
6384
6513
|
while (pendingAddFileCalls.size) {
|
|
6385
6514
|
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6386
6515
|
}
|
|
6516
|
+
await Promise.allSettled(zipWriter.pendingErrors.map(watcher => watcher.recorded));
|
|
6517
|
+
const unobservedWatchers = zipWriter.pendingErrors.filter(watcher => watcher.error && !watcher.observed);
|
|
6518
|
+
if (unobservedWatchers.length) {
|
|
6519
|
+
const unobservedErrors = unobservedWatchers.map(watcher => watcher.error);
|
|
6520
|
+
unobservedWatchers.forEach(watcher => watcher.observed = true);
|
|
6521
|
+
const [error] = unobservedErrors;
|
|
6522
|
+
try {
|
|
6523
|
+
error.entryErrors = unobservedErrors;
|
|
6524
|
+
} catch {
|
|
6525
|
+
// ignored
|
|
6526
|
+
}
|
|
6527
|
+
throw error;
|
|
6528
|
+
}
|
|
6387
6529
|
await closeFile(zipWriter, comment, options);
|
|
6388
6530
|
const preventClose = !ownsWritable(writer) && getOptionValue(zipWriter, options, OPTION_PREVENT_CLOSE);
|
|
6389
6531
|
if (!preventClose) {
|
|
@@ -6418,11 +6560,7 @@ class ZipWriterStream {
|
|
|
6418
6560
|
try {
|
|
6419
6561
|
await zipWriter.close();
|
|
6420
6562
|
} catch (error) {
|
|
6421
|
-
|
|
6422
|
-
await zipWriter.writer.writable.abort(error);
|
|
6423
|
-
} catch {
|
|
6424
|
-
// ignored
|
|
6425
|
-
}
|
|
6563
|
+
await abortWritable(zipWriter, error);
|
|
6426
6564
|
}
|
|
6427
6565
|
}
|
|
6428
6566
|
}
|
|
@@ -6439,8 +6577,89 @@ class ZipWriterStream {
|
|
|
6439
6577
|
}
|
|
6440
6578
|
|
|
6441
6579
|
async close(comment = UNDEFINED_VALUE, options = {}) {
|
|
6442
|
-
|
|
6443
|
-
|
|
6580
|
+
const { zipWriter } = this;
|
|
6581
|
+
const results = await Promise.allSettled(Array.from(this.pendingAddFileCalls));
|
|
6582
|
+
const entryErrors = results.filter(result => result.status == "rejected").map(result => result.reason);
|
|
6583
|
+
if (entryErrors.length) {
|
|
6584
|
+
const [error] = entryErrors;
|
|
6585
|
+
try {
|
|
6586
|
+
error.entryErrors = entryErrors;
|
|
6587
|
+
} catch {
|
|
6588
|
+
// ignored
|
|
6589
|
+
}
|
|
6590
|
+
await abortWritable(zipWriter, error);
|
|
6591
|
+
throw error;
|
|
6592
|
+
}
|
|
6593
|
+
try {
|
|
6594
|
+
return await zipWriter.close(comment, options);
|
|
6595
|
+
} catch (error) {
|
|
6596
|
+
await abortWritable(zipWriter, error);
|
|
6597
|
+
throw error;
|
|
6598
|
+
}
|
|
6599
|
+
}
|
|
6600
|
+
}
|
|
6601
|
+
|
|
6602
|
+
class WatchedPromise extends Promise {
|
|
6603
|
+
|
|
6604
|
+
then(onFulfilled, onRejected) {
|
|
6605
|
+
const { watcher } = this;
|
|
6606
|
+
if (watcher) {
|
|
6607
|
+
watcher.observed = true;
|
|
6608
|
+
}
|
|
6609
|
+
return super.then(onFulfilled, onRejected);
|
|
6610
|
+
}
|
|
6611
|
+
}
|
|
6612
|
+
|
|
6613
|
+
function watchPromiseError(zipWriter, promise) {
|
|
6614
|
+
const watchedPromise = new WatchedPromise((resolve, reject) => Promise.prototype.then.call(promise, resolve, reject));
|
|
6615
|
+
const watcher = {};
|
|
6616
|
+
watchedPromise.watcher = watcher;
|
|
6617
|
+
watcher.recorded = Promise.prototype.then.call(watchedPromise, UNDEFINED_VALUE, error => watcher.error = error);
|
|
6618
|
+
zipWriter.pendingErrors.push(watcher);
|
|
6619
|
+
return watchedPromise;
|
|
6620
|
+
}
|
|
6621
|
+
|
|
6622
|
+
async function prependZipEntries(zipWriter, reader) {
|
|
6623
|
+
if (zipWriter.filenames.size) {
|
|
6624
|
+
throw new Error(ERR_ZIP_NOT_EMPTY);
|
|
6625
|
+
}
|
|
6626
|
+
await zipWriter.appendZipEntries(reader);
|
|
6627
|
+
}
|
|
6628
|
+
|
|
6629
|
+
async function addFileEntry(zipWriter, name, reader, options) {
|
|
6630
|
+
options = Object.assign({}, options);
|
|
6631
|
+
if (getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY) && !name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
6632
|
+
name += DIRECTORY_SIGNATURE;
|
|
6633
|
+
}
|
|
6634
|
+
if (zipWriter.filenames.has(name)) {
|
|
6635
|
+
throw new Error(ERR_DUPLICATED_NAME);
|
|
6636
|
+
}
|
|
6637
|
+
zipWriter.filenames.add(name);
|
|
6638
|
+
if (workers < getConfiguration().maxWorkers) {
|
|
6639
|
+
workers++;
|
|
6640
|
+
} else {
|
|
6641
|
+
await new Promise(resolve => pendingEntries.push(resolve));
|
|
6642
|
+
}
|
|
6643
|
+
try {
|
|
6644
|
+
return await addFile(zipWriter, name, reader, options);
|
|
6645
|
+
} catch (error) {
|
|
6646
|
+
zipWriter.filenames.delete(name);
|
|
6647
|
+
throw error;
|
|
6648
|
+
} finally {
|
|
6649
|
+
const pendingEntry = pendingEntries.shift();
|
|
6650
|
+
if (pendingEntry) {
|
|
6651
|
+
pendingEntry();
|
|
6652
|
+
} else {
|
|
6653
|
+
workers--;
|
|
6654
|
+
}
|
|
6655
|
+
}
|
|
6656
|
+
}
|
|
6657
|
+
|
|
6658
|
+
async function abortWritable(zipWriter, error) {
|
|
6659
|
+
try {
|
|
6660
|
+
await zipWriter.writer.writable.abort(error);
|
|
6661
|
+
} catch {
|
|
6662
|
+
// ignored
|
|
6444
6663
|
}
|
|
6445
6664
|
}
|
|
6446
6665
|
|
|
@@ -6499,7 +6718,6 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
6499
6718
|
}
|
|
6500
6719
|
|
|
6501
6720
|
function resolveAttributes(zipWriter, name, options) {
|
|
6502
|
-
name = name.trim();
|
|
6503
6721
|
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
6504
6722
|
let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? VERSION_MADE_BY_MSDOS : VERSION_MADE_BY_UNIX);
|
|
6505
6723
|
const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
|
|
@@ -6643,11 +6861,12 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6643
6861
|
if (getLength(rawComment) > MAX_16_BITS) {
|
|
6644
6862
|
throw new Error(ERR_INVALID_ENTRY_COMMENT);
|
|
6645
6863
|
}
|
|
6646
|
-
const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION
|
|
6647
|
-
if (version > MAX_16_BITS) {
|
|
6864
|
+
const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION);
|
|
6865
|
+
if (version !== UNDEFINED_VALUE && version > MAX_16_BITS) {
|
|
6648
6866
|
throw new Error(ERR_INVALID_VERSION);
|
|
6649
6867
|
}
|
|
6650
6868
|
const lastModDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
|
|
6869
|
+
const rawLastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE);
|
|
6651
6870
|
const lastAccessDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
6652
6871
|
const creationDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
6653
6872
|
const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
|
|
@@ -6691,7 +6910,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6691
6910
|
if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
|
|
6692
6911
|
dataDescriptor = false;
|
|
6693
6912
|
}
|
|
6694
|
-
if (dataDescriptor === UNDEFINED_VALUE || zipCrypto) {
|
|
6913
|
+
if (dataDescriptor === UNDEFINED_VALUE || (zipCrypto && !passThrough)) {
|
|
6695
6914
|
dataDescriptor = true;
|
|
6696
6915
|
}
|
|
6697
6916
|
if (level !== UNDEFINED_VALUE && level != 6) {
|
|
@@ -6703,6 +6922,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6703
6922
|
}
|
|
6704
6923
|
const rawExtraField = serializeExtraField(options[PROPERTY_NAME_EXTRA_FIELD]);
|
|
6705
6924
|
const rawLocalExtraField = serializeExtraField(options[OPTION_LOCAL_EXTRA_FIELD]);
|
|
6925
|
+
const rawCentralExtraField = serializeExtraField(options[OPTION_CENTRAL_EXTRA_FIELD]);
|
|
6706
6926
|
return {
|
|
6707
6927
|
comment,
|
|
6708
6928
|
resolvedOptions: {
|
|
@@ -6710,6 +6930,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6710
6930
|
rawComment,
|
|
6711
6931
|
version,
|
|
6712
6932
|
lastModDate,
|
|
6933
|
+
rawLastModDate,
|
|
6713
6934
|
lastAccessDate,
|
|
6714
6935
|
creationDate,
|
|
6715
6936
|
internalFileAttributes,
|
|
@@ -6737,7 +6958,8 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6737
6958
|
dataDescriptor,
|
|
6738
6959
|
zip64,
|
|
6739
6960
|
rawExtraField,
|
|
6740
|
-
rawLocalExtraField
|
|
6961
|
+
rawLocalExtraField,
|
|
6962
|
+
rawCentralExtraField
|
|
6741
6963
|
}
|
|
6742
6964
|
};
|
|
6743
6965
|
}
|
|
@@ -6906,10 +7128,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
6906
7128
|
}
|
|
6907
7129
|
await initStream(fileWriter);
|
|
6908
7130
|
const diskOffset = getDiskOffset(writer);
|
|
6909
|
-
if (zipWriter.addSplitZipSignature) {
|
|
6910
|
-
|
|
6911
|
-
await writeData(writer, getSplitZipSignatureArray());
|
|
6912
|
-
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
7131
|
+
if (zipWriter.addSplitZipSignature && !bufferedWrite) {
|
|
7132
|
+
await writeSplitZipSignature(zipWriter, writer);
|
|
6913
7133
|
}
|
|
6914
7134
|
if (usdz && !bufferedWrite) {
|
|
6915
7135
|
appendExtraFieldUSDZ(entryInfo, zipWriter.offset - diskOffset);
|
|
@@ -6936,6 +7156,9 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
6936
7156
|
if (bufferedWrite) {
|
|
6937
7157
|
await Promise.all([fileWriter.writable.getWriter().close(), lockPreviousFileEntry]);
|
|
6938
7158
|
await requestLockWriter();
|
|
7159
|
+
if (zipWriter.addSplitZipSignature) {
|
|
7160
|
+
await writeSplitZipSignature(zipWriter, writer);
|
|
7161
|
+
}
|
|
6939
7162
|
writingBufferedEntryData = true;
|
|
6940
7163
|
writerSizeBeforeEntry = writer.size;
|
|
6941
7164
|
await skipDiskIfNeeded();
|
|
@@ -7055,6 +7278,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
|
|
|
7055
7278
|
versionMadeBy,
|
|
7056
7279
|
rawComment,
|
|
7057
7280
|
rawExtraField,
|
|
7281
|
+
rawCentralExtraField,
|
|
7058
7282
|
useWebWorkers,
|
|
7059
7283
|
transferStreams,
|
|
7060
7284
|
onstart,
|
|
@@ -7098,6 +7322,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
|
|
|
7098
7322
|
rawExtraFieldUnix,
|
|
7099
7323
|
rawExtraFieldAES,
|
|
7100
7324
|
rawExtraField,
|
|
7325
|
+
rawCentralExtraField,
|
|
7101
7326
|
extendedTimestamp,
|
|
7102
7327
|
msDosCompatible,
|
|
7103
7328
|
internalFileAttributes,
|
|
@@ -7207,6 +7432,7 @@ function getHeaderInfo(options) {
|
|
|
7207
7432
|
const {
|
|
7208
7433
|
rawFilename,
|
|
7209
7434
|
lastModDate,
|
|
7435
|
+
rawLastModDate: rawLastModDateOption,
|
|
7210
7436
|
lastAccessDate,
|
|
7211
7437
|
creationDate,
|
|
7212
7438
|
level,
|
|
@@ -7340,6 +7566,9 @@ function getHeaderInfo(options) {
|
|
|
7340
7566
|
if (compressionMethod === UNDEFINED_VALUE) {
|
|
7341
7567
|
compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
|
|
7342
7568
|
}
|
|
7569
|
+
if (version === UNDEFINED_VALUE) {
|
|
7570
|
+
version = compressionMethod == COMPRESSION_METHOD_STORE && !directory && !encrypted ? VERSION_STORE : VERSION_DEFLATE;
|
|
7571
|
+
}
|
|
7343
7572
|
const { codecVersionNeeded } = options;
|
|
7344
7573
|
if (compressed && codecVersionNeeded !== UNDEFINED_VALUE) {
|
|
7345
7574
|
version = version > codecVersionNeeded ? version : codecVersionNeeded;
|
|
@@ -7372,6 +7601,7 @@ function getHeaderInfo(options) {
|
|
|
7372
7601
|
compressionMethod,
|
|
7373
7602
|
uncompressedSize,
|
|
7374
7603
|
lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
|
|
7604
|
+
rawLastModDate: rawLastModDateOption,
|
|
7375
7605
|
rawFilename,
|
|
7376
7606
|
zip64CompressedSize,
|
|
7377
7607
|
zip64UncompressedSize,
|
|
@@ -7578,9 +7808,9 @@ function updateLocalHeader({
|
|
|
7578
7808
|
|
|
7579
7809
|
async function closeFile(zipWriter, comment, options) {
|
|
7580
7810
|
const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
|
|
7581
|
-
const { directoryStart, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
|
|
7811
|
+
const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
|
|
7582
7812
|
const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
|
|
7583
|
-
await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength, signatureLength });
|
|
7813
|
+
await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
|
|
7584
7814
|
}
|
|
7585
7815
|
|
|
7586
7816
|
function createDirectoryRecords(files) {
|
|
@@ -7593,6 +7823,7 @@ function createDirectoryRecords(files) {
|
|
|
7593
7823
|
rawExtraFieldNTFS,
|
|
7594
7824
|
rawExtraFieldUnix,
|
|
7595
7825
|
rawExtraField,
|
|
7826
|
+
rawCentralExtraField,
|
|
7596
7827
|
extendedTimestamp,
|
|
7597
7828
|
extraFieldExtendedTimestampFlag,
|
|
7598
7829
|
lastModDate,
|
|
@@ -7647,7 +7878,8 @@ function createDirectoryRecords(files) {
|
|
|
7647
7878
|
rawExtraFieldNTFS,
|
|
7648
7879
|
rawExtraFieldUnix,
|
|
7649
7880
|
rawExtraFieldTimestamp,
|
|
7650
|
-
rawExtraField
|
|
7881
|
+
rawExtraField,
|
|
7882
|
+
rawCentralExtraField);
|
|
7651
7883
|
if (extraFieldLength > MAX_16_BITS) {
|
|
7652
7884
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
7653
7885
|
}
|
|
@@ -7664,6 +7896,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7664
7896
|
let directoryDiskOffset = 0;
|
|
7665
7897
|
let directoryStartDiskNumber = getDiskNumber(writer);
|
|
7666
7898
|
let directoryStartDiskOffset = getDiskOffset(writer);
|
|
7899
|
+
let directoryEndDiskEntriesLength = 0;
|
|
7667
7900
|
for (const [indexFileEntry, fileEntry] of Array.from(fileEntries.values()).entries()) {
|
|
7668
7901
|
const {
|
|
7669
7902
|
offset: fileEntryOffset,
|
|
@@ -7674,6 +7907,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7674
7907
|
rawExtraFieldNTFS,
|
|
7675
7908
|
rawExtraFieldUnix,
|
|
7676
7909
|
rawExtraField,
|
|
7910
|
+
rawCentralExtraField,
|
|
7677
7911
|
rawComment,
|
|
7678
7912
|
versionMadeBy,
|
|
7679
7913
|
headerArray,
|
|
@@ -7688,11 +7922,12 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7688
7922
|
uncompressedSize,
|
|
7689
7923
|
compressedSize
|
|
7690
7924
|
} = fileEntry;
|
|
7691
|
-
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
|
|
7925
|
+
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField, rawCentralExtraField);
|
|
7692
7926
|
const directoryRecordLength = CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
|
|
7693
7927
|
if (exceedsAvailableSize(writer, offset + directoryRecordLength - directoryDiskOffset)) {
|
|
7694
7928
|
await writeData(writer, directoryArray.slice(directoryDiskOffset, offset));
|
|
7695
7929
|
directoryDiskOffset = offset;
|
|
7930
|
+
directoryEndDiskEntriesLength = 0;
|
|
7696
7931
|
await writer.closeDisk();
|
|
7697
7932
|
}
|
|
7698
7933
|
if (indexFileEntry == 0) {
|
|
@@ -7725,9 +7960,11 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7725
7960
|
directoryRecord.writeBytes(rawExtraFieldNTFS);
|
|
7726
7961
|
directoryRecord.writeBytes(rawExtraFieldUnix);
|
|
7727
7962
|
directoryRecord.writeBytes(rawExtraField);
|
|
7963
|
+
directoryRecord.writeBytes(rawCentralExtraField);
|
|
7728
7964
|
directoryRecord.writeBytes(rawComment);
|
|
7729
7965
|
arraySet(directoryArray, directoryRecord.array, offset);
|
|
7730
7966
|
offset += directoryRecordLength;
|
|
7967
|
+
directoryEndDiskEntriesLength++;
|
|
7731
7968
|
if (options.onprogress) {
|
|
7732
7969
|
try {
|
|
7733
7970
|
await options.onprogress(indexFileEntry + 1, fileEntries.size, new Entry(fileEntry));
|
|
@@ -7739,6 +7976,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7739
7976
|
await writeData(writer, directoryDiskOffset ? directoryArray.slice(directoryDiskOffset) : directoryArray);
|
|
7740
7977
|
return {
|
|
7741
7978
|
directoryStart: { diskNumber: directoryStartDiskNumber, diskOffset: directoryStartDiskOffset },
|
|
7979
|
+
directoryEnd: { diskNumber: getDiskNumber(writer), entriesLength: directoryEndDiskEntriesLength },
|
|
7742
7980
|
directoryArray
|
|
7743
7981
|
};
|
|
7744
7982
|
}
|
|
@@ -7767,16 +8005,20 @@ async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
|
|
|
7767
8005
|
|
|
7768
8006
|
async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
7769
8007
|
const { writer } = zipWriter;
|
|
7770
|
-
const { directoryStart, signatureLength } = cdInfo;
|
|
8008
|
+
const { directoryStart, directoryEnd, signatureLength } = cdInfo;
|
|
7771
8009
|
let { directoryDataLength } = cdInfo;
|
|
7772
8010
|
let fileEntriesLength = zipWriter.fileEntries.size;
|
|
7773
8011
|
let diskNumber = directoryStart.diskNumber;
|
|
7774
8012
|
let directoryOffset = getSegmentOffset(zipWriter, directoryStart);
|
|
8013
|
+
const commentLength = getLength(comment);
|
|
8014
|
+
if (commentLength > MAX_16_BITS) {
|
|
8015
|
+
throw new Error(ERR_INVALID_COMMENT);
|
|
8016
|
+
}
|
|
8017
|
+
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
7775
8018
|
let lastDiskNumber = getDiskNumber(writer);
|
|
7776
|
-
if (exceedsAvailableSize(writer, END_OF_CENTRAL_DIR_LENGTH)) {
|
|
8019
|
+
if (exceedsAvailableSize(writer, (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH) + commentLength)) {
|
|
7777
8020
|
lastDiskNumber++;
|
|
7778
8021
|
}
|
|
7779
|
-
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
7780
8022
|
if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || fileEntriesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
|
|
7781
8023
|
if (zip64 === false) {
|
|
7782
8024
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
@@ -7784,15 +8026,12 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
|
7784
8026
|
zip64 = true;
|
|
7785
8027
|
}
|
|
7786
8028
|
}
|
|
7787
|
-
const commentLength = getLength(comment);
|
|
7788
|
-
if (commentLength > MAX_16_BITS) {
|
|
7789
|
-
throw new Error(ERR_INVALID_COMMENT);
|
|
7790
|
-
}
|
|
7791
8029
|
const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
|
|
7792
8030
|
if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
|
|
7793
8031
|
await writer.closeDisk();
|
|
7794
8032
|
}
|
|
7795
8033
|
lastDiskNumber = getDiskNumber(writer);
|
|
8034
|
+
let diskFileEntriesLength = lastDiskNumber == directoryEnd.diskNumber ? directoryEnd.entriesLength : 0;
|
|
7796
8035
|
if (zip64) {
|
|
7797
8036
|
endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
|
|
7798
8037
|
endOfdirectoryRecord.writeUint64(44);
|
|
@@ -7800,7 +8039,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
|
7800
8039
|
endOfdirectoryRecord.writeUint16(45);
|
|
7801
8040
|
endOfdirectoryRecord.writeUint32(lastDiskNumber);
|
|
7802
8041
|
endOfdirectoryRecord.writeUint32(diskNumber);
|
|
7803
|
-
endOfdirectoryRecord.writeUint64(
|
|
8042
|
+
endOfdirectoryRecord.writeUint64(diskFileEntriesLength);
|
|
7804
8043
|
endOfdirectoryRecord.writeUint64(fileEntriesLength);
|
|
7805
8044
|
endOfdirectoryRecord.writeUint64(directoryDataLength);
|
|
7806
8045
|
endOfdirectoryRecord.writeUint64(directoryOffset);
|
|
@@ -7813,6 +8052,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
|
7813
8052
|
lastDiskNumber = MAX_16_BITS;
|
|
7814
8053
|
diskNumber = MAX_16_BITS;
|
|
7815
8054
|
}
|
|
8055
|
+
diskFileEntriesLength = MAX_16_BITS;
|
|
7816
8056
|
fileEntriesLength = MAX_16_BITS;
|
|
7817
8057
|
directoryOffset = MAX_32_BITS;
|
|
7818
8058
|
directoryDataLength = MAX_32_BITS;
|
|
@@ -7820,7 +8060,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
|
7820
8060
|
endOfdirectoryRecord.writeUint32(END_OF_CENTRAL_DIR_SIGNATURE);
|
|
7821
8061
|
endOfdirectoryRecord.writeUint16(lastDiskNumber);
|
|
7822
8062
|
endOfdirectoryRecord.writeUint16(diskNumber);
|
|
7823
|
-
endOfdirectoryRecord.writeUint16(
|
|
8063
|
+
endOfdirectoryRecord.writeUint16(diskFileEntriesLength);
|
|
7824
8064
|
endOfdirectoryRecord.writeUint16(fileEntriesLength);
|
|
7825
8065
|
endOfdirectoryRecord.writeUint32(directoryDataLength);
|
|
7826
8066
|
endOfdirectoryRecord.writeUint32(directoryOffset);
|
|
@@ -7919,9 +8159,21 @@ async function copyZipData(zipWriter, reader, entries, directoryOffset) {
|
|
|
7919
8159
|
async function copyData(zipWriter, reader, offset, size) {
|
|
7920
8160
|
if (size > 0) {
|
|
7921
8161
|
const { writer } = zipWriter;
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
8162
|
+
let copiedLength = 0;
|
|
8163
|
+
try {
|
|
8164
|
+
await flushBufferedData(createReadable(reader, { offset, size }), writer, UNDEFINED_VALUE, chunkLength => copiedLength += chunkLength);
|
|
8165
|
+
} catch (error) {
|
|
8166
|
+
zipWriter.hasCorruptedEntries = true;
|
|
8167
|
+
try {
|
|
8168
|
+
error.corruptedEntry = true;
|
|
8169
|
+
} catch {
|
|
8170
|
+
// ignored
|
|
8171
|
+
}
|
|
8172
|
+
throw error;
|
|
8173
|
+
} finally {
|
|
8174
|
+
writer.size += copiedLength;
|
|
8175
|
+
zipWriter.offset += copiedLength;
|
|
8176
|
+
}
|
|
7925
8177
|
}
|
|
7926
8178
|
}
|
|
7927
8179
|
|
|
@@ -7946,6 +8198,12 @@ function getSplitZipSignatureArray() {
|
|
|
7946
8198
|
return signatureArray;
|
|
7947
8199
|
}
|
|
7948
8200
|
|
|
8201
|
+
async function writeSplitZipSignature(zipWriter, writer) {
|
|
8202
|
+
delete zipWriter.addSplitZipSignature;
|
|
8203
|
+
await writeData(writer, getSplitZipSignatureArray());
|
|
8204
|
+
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
8205
|
+
}
|
|
8206
|
+
|
|
7949
8207
|
async function writeData(writer, array) {
|
|
7950
8208
|
const { writable } = writer;
|
|
7951
8209
|
const streamWriter = writable.getWriter();
|
|
@@ -8999,4 +9257,4 @@ function terminateWorkersAndModule() {
|
|
|
8999
9257
|
|
|
9000
9258
|
configureExternalAssets();
|
|
9001
9259
|
|
|
9002
|
-
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, 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_ENCRYPTION_STRENGTH, 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_PASSWORD_TYPE, ERR_INVALID_SIGNAL, ERR_INVALID_SIGNATURE, 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_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_COMPRESSION_METHOD, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION$1 as 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_UINT64, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|
|
9260
|
+
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, 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_ENCRYPTION_STRENGTH, 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_PASSWORD_TYPE, ERR_INVALID_SIGNAL, ERR_INVALID_SIGNATURE, 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_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_COMPRESSION_METHOD, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION$1 as 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_UINT64, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, WARNING_APPENDED_DATA, WARNING_COMPRESSED_PATCHED_DATA, 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_ZIP64_END_OF_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, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, getMimeType, isZipFile, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|