@zip.js/zip.js 2.8.58 → 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 +157 -39
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +171 -38
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +157 -40
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +156 -39
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +157 -40
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +171 -39
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +171 -39
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +171 -38
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +171 -38
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +171 -38
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +171 -39
- package/index-native.min.js +1 -1
- package/index.cjs +171 -39
- package/index.d.cts +184 -1
- package/index.d.ts +184 -1
- package/index.min.js +1 -1
- package/lib/core/constants.js +2 -0
- package/lib/core/options.js +2 -0
- package/lib/core/zip-reader.js +143 -33
- package/lib/core/zip-writer.js +13 -6
- package/lib/zip-core-reader.js +16 -1
- package/package.json +1 -1
package/index-native.cjs
CHANGED
|
@@ -77,6 +77,7 @@ const BITFLAG_LEVEL_MAX_MASK = 0b010;
|
|
|
77
77
|
const BITFLAG_LEVEL_FAST_MASK = 0b100;
|
|
78
78
|
const BITFLAG_LEVEL_SUPER_FAST_MASK = 0b110;
|
|
79
79
|
const BITFLAG_DATA_DESCRIPTOR = 0b1000;
|
|
80
|
+
const BITFLAG_COMPRESSED_PATCHED_DATA = 0b100000;
|
|
80
81
|
const BITFLAG_STRONG_ENCRYPTION = 0b1000000;
|
|
81
82
|
const BITFLAG_LANG_ENCODING_FLAG = 0b100000000000;
|
|
82
83
|
const BITFLAG_MASKED_LOCAL_HEADERS = 0b10000000000000;
|
|
@@ -194,6 +195,7 @@ const OPTION_OFFSET = "offset";
|
|
|
194
195
|
const OPTION_USDZ = "usdz";
|
|
195
196
|
const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
|
|
196
197
|
const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
|
|
198
|
+
const OPTION_CENTRAL_EXTRA_FIELD = "centralExtraField";
|
|
197
199
|
const OPTION_STRICTNESS = "strictness";
|
|
198
200
|
const OPTION_FILENAME_VALIDATION = "filenameValidation";
|
|
199
201
|
const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
|
|
@@ -4725,6 +4727,21 @@ const ERR_INVALID_STRICTNESS = "Invalid strictness (must be 'strict', 'balanced'
|
|
|
4725
4727
|
const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
|
|
4726
4728
|
const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
|
|
4727
4729
|
const ERR_UNSUPPORTED_UINT64 = "64-bit value exceeds Number.MAX_SAFE_INTEGER";
|
|
4730
|
+
const WARNING_UNSORTED_CENTRAL_DIRECTORY = "unsorted central directory";
|
|
4731
|
+
const WARNING_UNKNOWN_VERSION = "unknown version needed to extract";
|
|
4732
|
+
const WARNING_COMPRESSED_PATCHED_DATA = "compressed patched data";
|
|
4733
|
+
const WARNING_MALFORMED_EXTRA_FIELD = "malformed extra field";
|
|
4734
|
+
const WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA = "unknown zip64 extensible data";
|
|
4735
|
+
const WARNING_WRAPPED_ENTRIES_COUNT = "wrapped entries count";
|
|
4736
|
+
const WARNING_APPENDED_DATA = "appended data";
|
|
4737
|
+
const WARNING_PREPENDED_DATA = "prepended data";
|
|
4738
|
+
const WARNING_TRAILING_CENTRAL_DIRECTORY_DATA = "trailing central directory data";
|
|
4739
|
+
const WARNING_DUPLICATE_FILENAME = "duplicate filename";
|
|
4740
|
+
const WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY = "mismatched zip64 end of central directory record";
|
|
4741
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG = "mismatched local file header (general purpose bit flag)";
|
|
4742
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD = "mismatched local file header (compression method)";
|
|
4743
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES = "mismatched local file header (crc32 or sizes)";
|
|
4744
|
+
const MAX_KNOWN_VERSION = 63;
|
|
4728
4745
|
const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
|
|
4729
4746
|
const CHARSET_UTF8 = "utf-8";
|
|
4730
4747
|
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
|
|
@@ -4775,6 +4792,7 @@ class ZipReader {
|
|
|
4775
4792
|
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
4776
4793
|
throw new Error(ERR_BAD_FORMAT);
|
|
4777
4794
|
}
|
|
4795
|
+
const warnings = zipReader.warnings = [];
|
|
4778
4796
|
const strictness = getStrictness(options, zipReader.options);
|
|
4779
4797
|
const checkAmbiguity = strictness == STRICTNESS_STRICT;
|
|
4780
4798
|
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
@@ -4798,8 +4816,12 @@ class ZipReader {
|
|
|
4798
4816
|
const commentOffset = endOfDirectoryInfo.offset;
|
|
4799
4817
|
const commentLength = getUint16$1(endOfDirectoryView, 20);
|
|
4800
4818
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
4801
|
-
|
|
4802
|
-
|
|
4819
|
+
const appendedDataLength = reader.size - appendedDataOffset;
|
|
4820
|
+
if (appendedDataLength > maxAppendedDataSize) {
|
|
4821
|
+
throwAmbiguousArchive(WARNING_APPENDED_DATA);
|
|
4822
|
+
}
|
|
4823
|
+
if (appendedDataLength > 0) {
|
|
4824
|
+
addWarning(warnings, WARNING_APPENDED_DATA);
|
|
4803
4825
|
}
|
|
4804
4826
|
let lastDiskNumber = getUint16$1(endOfDirectoryView, 4);
|
|
4805
4827
|
const expectedLastDiskNumber = reader.lastDiskNumber || 0;
|
|
@@ -4853,23 +4875,23 @@ class ZipReader {
|
|
|
4853
4875
|
}
|
|
4854
4876
|
if (lastDiskNumber == MAX_16_BITS) {
|
|
4855
4877
|
lastDiskNumber = getUint32$1(endOfDirectoryView, 16);
|
|
4856
|
-
} else if (
|
|
4857
|
-
|
|
4878
|
+
} else if (lastDiskNumber != getUint32$1(endOfDirectoryView, 16)) {
|
|
4879
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4858
4880
|
}
|
|
4859
4881
|
if (diskNumber == MAX_16_BITS) {
|
|
4860
4882
|
diskNumber = getUint32$1(endOfDirectoryView, 20);
|
|
4861
|
-
} else if (
|
|
4862
|
-
|
|
4883
|
+
} else if (diskNumber != getUint32$1(endOfDirectoryView, 20)) {
|
|
4884
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4863
4885
|
}
|
|
4864
4886
|
if (filesLength == MAX_16_BITS) {
|
|
4865
4887
|
filesLength = getBigUint64(endOfDirectoryView, 32);
|
|
4866
|
-
} else if (
|
|
4867
|
-
|
|
4888
|
+
} else if (filesLength != getBigUint64(endOfDirectoryView, 32)) {
|
|
4889
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4868
4890
|
}
|
|
4869
4891
|
if (directoryDataLength == MAX_32_BITS) {
|
|
4870
4892
|
directoryDataLength = getBigUint64(endOfDirectoryView, 40);
|
|
4871
|
-
} else if (
|
|
4872
|
-
|
|
4893
|
+
} else if (directoryDataLength != getBigUint64(endOfDirectoryView, 40)) {
|
|
4894
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4873
4895
|
}
|
|
4874
4896
|
directoryDataOffset = getDiskOffset$1(reader, diskNumber) + getBigUint64(endOfDirectoryView, 48) + prependedDataLength;
|
|
4875
4897
|
}
|
|
@@ -4938,14 +4960,22 @@ class ZipReader {
|
|
|
4938
4960
|
declaredDirectoryDataLength = directoryArray.length;
|
|
4939
4961
|
decryptedDirectory = true;
|
|
4940
4962
|
}
|
|
4963
|
+
if (directoryEncryptionInfo && !decryptedDirectory &&
|
|
4964
|
+
(directoryArray.length < 4 || getUint32$1(directoryView, 0) == CENTRAL_FILE_HEADER_SIGNATURE)) {
|
|
4965
|
+
addWarning(warnings, WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA);
|
|
4966
|
+
}
|
|
4941
4967
|
startOffset = directoryDataOffset;
|
|
4942
4968
|
const filenameEncoding = getOptionValue$1(zipReader, options, OPTION_FILENAME_ENCODING);
|
|
4943
4969
|
const commentEncoding = getOptionValue$1(zipReader, options, OPTION_COMMENT_ENCODING);
|
|
4944
|
-
const filenames =
|
|
4970
|
+
const filenames = new Set();
|
|
4945
4971
|
let duplicateFilename;
|
|
4972
|
+
let previousEntryPosition = -1;
|
|
4946
4973
|
const recoverWrappedFilesLength = !checkAmbiguity && !zip64EndOfDirectory;
|
|
4947
4974
|
if (!filesLength && recoverWrappedFilesLength) {
|
|
4948
4975
|
filesLength = getWrappedFilesLength(directoryView, directoryArray, offset);
|
|
4976
|
+
if (filesLength) {
|
|
4977
|
+
addWarning(warnings, WARNING_WRAPPED_ENTRIES_COUNT);
|
|
4978
|
+
}
|
|
4949
4979
|
}
|
|
4950
4980
|
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
4951
4981
|
const fileEntry = new ZipEntry$1(reader, zipReader.options);
|
|
@@ -5024,15 +5054,26 @@ class ZipReader {
|
|
|
5024
5054
|
filename,
|
|
5025
5055
|
comment
|
|
5026
5056
|
});
|
|
5027
|
-
readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6)
|
|
5057
|
+
if (readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6)) {
|
|
5058
|
+
addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD, filename);
|
|
5059
|
+
}
|
|
5028
5060
|
fileEntry.offset += prependedDataLength;
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5061
|
+
const entryPosition = getDiskOffset$1(reader, fileEntry.diskNumberStart) + fileEntry.offset;
|
|
5062
|
+
startOffset = Math.min(entryPosition, startOffset);
|
|
5063
|
+
if (entryPosition < previousEntryPosition) {
|
|
5064
|
+
addWarning(warnings, WARNING_UNSORTED_CENTRAL_DIRECTORY, filename);
|
|
5065
|
+
}
|
|
5066
|
+
previousEntryPosition = entryPosition;
|
|
5067
|
+
if ((fileEntry.version & MAX_8_BITS) > MAX_KNOWN_VERSION) {
|
|
5068
|
+
addWarning(warnings, WARNING_UNKNOWN_VERSION, filename);
|
|
5069
|
+
}
|
|
5070
|
+
if ((fileEntry.rawBitFlag & BITFLAG_COMPRESSED_PATCHED_DATA) == BITFLAG_COMPRESSED_PATCHED_DATA) {
|
|
5071
|
+
addWarning(warnings, WARNING_COMPRESSED_PATCHED_DATA, filename);
|
|
5072
|
+
}
|
|
5073
|
+
if (filenames.has(fileEntry.filename)) {
|
|
5074
|
+
duplicateFilename = true;
|
|
5035
5075
|
}
|
|
5076
|
+
filenames.add(fileEntry.filename);
|
|
5036
5077
|
const unixExternalUpper = (fileEntry.externalFileAttributes >> 16) & MAX_16_BITS;
|
|
5037
5078
|
if (fileEntry.unixMode === UNDEFINED_VALUE && (unixExternalUpper & (FILE_ATTR_UNIX_DEFAULT_MASK | FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_TYPE_DIR)) != 0) {
|
|
5038
5079
|
fileEntry.unixMode = unixExternalUpper;
|
|
@@ -5070,7 +5111,11 @@ class ZipReader {
|
|
|
5070
5111
|
};
|
|
5071
5112
|
offset = endOffset;
|
|
5072
5113
|
if (indexFile == filesLength - 1 && recoverWrappedFilesLength) {
|
|
5073
|
-
|
|
5114
|
+
const wrappedFilesLength = getWrappedFilesLength(directoryView, directoryArray, offset);
|
|
5115
|
+
if (wrappedFilesLength) {
|
|
5116
|
+
filesLength += wrappedFilesLength;
|
|
5117
|
+
addWarning(warnings, WARNING_WRAPPED_ENTRIES_COUNT);
|
|
5118
|
+
}
|
|
5074
5119
|
}
|
|
5075
5120
|
const { onprogress } = options;
|
|
5076
5121
|
if (onprogress) {
|
|
@@ -5096,18 +5141,22 @@ class ZipReader {
|
|
|
5096
5141
|
zipReader.digitalSignature = digitalSignature;
|
|
5097
5142
|
offsetAfterSignature = offset + 6 + digitalSignature.length;
|
|
5098
5143
|
}
|
|
5099
|
-
if (
|
|
5100
|
-
|
|
5144
|
+
if ((offset != declaredDirectoryDataLength && offsetAfterSignature != declaredDirectoryDataLength) ||
|
|
5145
|
+
(!decryptedDirectory && offset != directoryDataLength && offsetAfterSignature != directoryDataLength)) {
|
|
5146
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_TRAILING_CENTRAL_DIRECTORY_DATA);
|
|
5101
5147
|
}
|
|
5102
5148
|
if (duplicateFilename) {
|
|
5103
|
-
|
|
5149
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_DUPLICATE_FILENAME);
|
|
5104
5150
|
}
|
|
5105
5151
|
const extractPrependedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
|
|
5106
5152
|
const extractAppendedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
|
|
5107
5153
|
const splitZipSignatureLength = (checkAmbiguity || extractPrependedData) && filesLength &&
|
|
5108
5154
|
startOffset == SPLIT_ZIP_FILE_SIGNATURE_LENGTH && await startsWithSplitZipMarker(reader) ? SPLIT_ZIP_FILE_SIGNATURE_LENGTH : 0;
|
|
5109
5155
|
if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > splitZipSignatureLength))) {
|
|
5110
|
-
throwAmbiguousArchive(
|
|
5156
|
+
throwAmbiguousArchive(WARNING_PREPENDED_DATA);
|
|
5157
|
+
}
|
|
5158
|
+
if (prependedDataLength || (filesLength && startOffset > SPLIT_ZIP_FILE_SIGNATURE_LENGTH)) {
|
|
5159
|
+
addWarning(warnings, WARNING_PREPENDED_DATA);
|
|
5111
5160
|
}
|
|
5112
5161
|
if (extractPrependedData) {
|
|
5113
5162
|
zipReader.prependedData = startOffset > splitZipSignatureLength ?
|
|
@@ -5177,6 +5226,28 @@ class ZipReaderStream {
|
|
|
5177
5226
|
}
|
|
5178
5227
|
}
|
|
5179
5228
|
|
|
5229
|
+
async function isZipFile(reader, options = {}) {
|
|
5230
|
+
reader = new GenericReader(reader);
|
|
5231
|
+
await initStream(reader);
|
|
5232
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
5233
|
+
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
5234
|
+
await initStream(reader);
|
|
5235
|
+
}
|
|
5236
|
+
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
5237
|
+
return false;
|
|
5238
|
+
}
|
|
5239
|
+
const strictness = getStrictness(options, {});
|
|
5240
|
+
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
5241
|
+
const maxAppendedDataSize = getMaxAppendedDataSize(options[OPTION_MAX_APPENDED_DATA_SIZE], strictness);
|
|
5242
|
+
const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
|
|
5243
|
+
if (!endOfDirectoryInfo || (strictness == STRICTNESS_STRICT && endOfDirectoryReachingEndCount > 1)) {
|
|
5244
|
+
return false;
|
|
5245
|
+
}
|
|
5246
|
+
const commentLength = getUint16$1(getDataView(endOfDirectoryInfo), 20);
|
|
5247
|
+
const appendedDataOffset = endOfDirectoryInfo.offset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
5248
|
+
return reader.size - appendedDataOffset <= maxAppendedDataSize;
|
|
5249
|
+
}
|
|
5250
|
+
|
|
5180
5251
|
let ZipEntry$1 = class ZipEntry {
|
|
5181
5252
|
|
|
5182
5253
|
constructor(reader, options) {
|
|
@@ -5208,6 +5279,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5208
5279
|
dataDescriptor
|
|
5209
5280
|
} = bitFlag;
|
|
5210
5281
|
const localDirectory = fileEntry.localDirectory = {};
|
|
5282
|
+
const warnings = fileEntry.warnings = [];
|
|
5211
5283
|
const localHeaderOffset = getDiskOffset$1(reader, diskNumberStart) + offset;
|
|
5212
5284
|
const dataArray = await readUint8Array(reader, localHeaderOffset, HEADER_SIZE);
|
|
5213
5285
|
const dataView = getDataView(dataArray);
|
|
@@ -5248,10 +5320,10 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5248
5320
|
if (checkLocalFilename) {
|
|
5249
5321
|
localDirectory.rawFilename = rawLocalFilename;
|
|
5250
5322
|
}
|
|
5251
|
-
readCommonFooter(zipEntry, localDirectory, dataView, 4, true)
|
|
5252
|
-
|
|
5253
|
-
validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename);
|
|
5323
|
+
if (readCommonFooter(zipEntry, localDirectory, dataView, 4, true)) {
|
|
5324
|
+
addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD);
|
|
5254
5325
|
}
|
|
5326
|
+
validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename, checkLocalDirectory ? UNDEFINED_VALUE : warnings);
|
|
5255
5327
|
const { lastAccessDate, creationDate, uid, gid } = localDirectory;
|
|
5256
5328
|
if (lastAccessDate) {
|
|
5257
5329
|
fileEntry.lastAccessDate = lastAccessDate;
|
|
@@ -5477,6 +5549,7 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5477
5549
|
const extraField = directory.extraField = new Map();
|
|
5478
5550
|
const rawExtraFieldView = getDataView(rawExtraField);
|
|
5479
5551
|
let offsetExtraField = 0;
|
|
5552
|
+
let malformedExtraField = false;
|
|
5480
5553
|
try {
|
|
5481
5554
|
while (offsetExtraField < rawExtraField.length) {
|
|
5482
5555
|
const type = getUint16$1(rawExtraFieldView, offsetExtraField);
|
|
@@ -5488,7 +5561,10 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5488
5561
|
offsetExtraField += 4 + size;
|
|
5489
5562
|
}
|
|
5490
5563
|
} catch {
|
|
5491
|
-
|
|
5564
|
+
malformedExtraField = true;
|
|
5565
|
+
}
|
|
5566
|
+
if (offsetExtraField > rawExtraField.length) {
|
|
5567
|
+
malformedExtraField = true;
|
|
5492
5568
|
}
|
|
5493
5569
|
const compressionMethod = getUint16$1(dataView, offset + 4);
|
|
5494
5570
|
Object.assign(directory, {
|
|
@@ -5556,6 +5632,7 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
|
|
|
5556
5632
|
if (extraFieldUSDZ) {
|
|
5557
5633
|
directory.extraFieldUSDZ = extraFieldUSDZ;
|
|
5558
5634
|
}
|
|
5635
|
+
return malformedExtraField;
|
|
5559
5636
|
}
|
|
5560
5637
|
|
|
5561
5638
|
function readExtraFieldZip64(extraFieldZip64, directory) {
|
|
@@ -6017,27 +6094,46 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
|
|
|
6017
6094
|
return UNDEFINED_VALUE;
|
|
6018
6095
|
}
|
|
6019
6096
|
|
|
6020
|
-
function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
|
|
6097
|
+
function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename, warnings) {
|
|
6021
6098
|
const { rawFilename } = zipEntry;
|
|
6099
|
+
const reject = !warnings;
|
|
6022
6100
|
const maskedLocalDirectory = zipEntry.decryptedDirectory &&
|
|
6023
6101
|
(localDirectory.rawBitFlag & BITFLAG_MASKED_LOCAL_HEADERS) == BITFLAG_MASKED_LOCAL_HEADERS;
|
|
6024
6102
|
if (checkLocalFilename && !maskedLocalDirectory &&
|
|
6025
6103
|
(rawLocalFilename.length != rawFilename.length ||
|
|
6026
6104
|
rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
|
|
6027
|
-
|
|
6105
|
+
reportAmbiguity(reject, warnings, "mismatched local file header (filename)");
|
|
6028
6106
|
}
|
|
6029
6107
|
if ((localDirectory.rawBitFlag & BITFLAG_AMBIGUITY_MASK) != (zipEntry.rawBitFlag & BITFLAG_AMBIGUITY_MASK)) {
|
|
6030
|
-
|
|
6108
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG);
|
|
6031
6109
|
}
|
|
6032
6110
|
if (localDirectory.compressionMethod != zipEntry.compressionMethod) {
|
|
6033
|
-
|
|
6111
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD);
|
|
6034
6112
|
}
|
|
6035
6113
|
if (!localDirectory.bitFlag.dataDescriptor && !maskedLocalDirectory &&
|
|
6036
6114
|
(localDirectory.crc32 || localDirectory.compressedSize || localDirectory.uncompressedSize) &&
|
|
6037
6115
|
(localDirectory.crc32 != zipEntry.crc32 ||
|
|
6038
6116
|
localDirectory.compressedSize != zipEntry.compressedSize ||
|
|
6039
6117
|
localDirectory.uncompressedSize != zipEntry.uncompressedSize)) {
|
|
6040
|
-
|
|
6118
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES);
|
|
6119
|
+
}
|
|
6120
|
+
}
|
|
6121
|
+
|
|
6122
|
+
function reportAmbiguity(reject, warnings, reason) {
|
|
6123
|
+
if (reject) {
|
|
6124
|
+
throwAmbiguousArchive(reason);
|
|
6125
|
+
} else {
|
|
6126
|
+
addWarning(warnings, reason);
|
|
6127
|
+
}
|
|
6128
|
+
}
|
|
6129
|
+
|
|
6130
|
+
function addWarning(warnings, reason, filename) {
|
|
6131
|
+
if (!warnings.some(warning => warning.reason == reason)) {
|
|
6132
|
+
const warning = { reason };
|
|
6133
|
+
if (filename !== UNDEFINED_VALUE) {
|
|
6134
|
+
warning.filename = filename;
|
|
6135
|
+
}
|
|
6136
|
+
warnings.push(warning);
|
|
6041
6137
|
}
|
|
6042
6138
|
}
|
|
6043
6139
|
|
|
@@ -6114,8 +6210,23 @@ var zipReader = /*#__PURE__*/Object.freeze({
|
|
|
6114
6210
|
ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
|
|
6115
6211
|
ERR_UNSUPPORTED_UINT64: ERR_UNSUPPORTED_UINT64,
|
|
6116
6212
|
ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
|
|
6213
|
+
WARNING_APPENDED_DATA: WARNING_APPENDED_DATA,
|
|
6214
|
+
WARNING_COMPRESSED_PATCHED_DATA: WARNING_COMPRESSED_PATCHED_DATA,
|
|
6215
|
+
WARNING_DUPLICATE_FILENAME: WARNING_DUPLICATE_FILENAME,
|
|
6216
|
+
WARNING_MALFORMED_EXTRA_FIELD: WARNING_MALFORMED_EXTRA_FIELD,
|
|
6217
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG: WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG,
|
|
6218
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD: WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD,
|
|
6219
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES: WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES,
|
|
6220
|
+
WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY: WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY,
|
|
6221
|
+
WARNING_PREPENDED_DATA: WARNING_PREPENDED_DATA,
|
|
6222
|
+
WARNING_TRAILING_CENTRAL_DIRECTORY_DATA: WARNING_TRAILING_CENTRAL_DIRECTORY_DATA,
|
|
6223
|
+
WARNING_UNKNOWN_VERSION: WARNING_UNKNOWN_VERSION,
|
|
6224
|
+
WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA: WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA,
|
|
6225
|
+
WARNING_UNSORTED_CENTRAL_DIRECTORY: WARNING_UNSORTED_CENTRAL_DIRECTORY,
|
|
6226
|
+
WARNING_WRAPPED_ENTRIES_COUNT: WARNING_WRAPPED_ENTRIES_COUNT,
|
|
6117
6227
|
ZipReader: ZipReader,
|
|
6118
|
-
ZipReaderStream: ZipReaderStream
|
|
6228
|
+
ZipReaderStream: ZipReaderStream,
|
|
6229
|
+
isZipFile: isZipFile
|
|
6119
6230
|
});
|
|
6120
6231
|
|
|
6121
6232
|
/*
|
|
@@ -6328,6 +6439,7 @@ class ZipWriter {
|
|
|
6328
6439
|
rawExtraFieldNTFS: EMPTY_UINT8_ARRAY,
|
|
6329
6440
|
rawExtraFieldUnix: EMPTY_UINT8_ARRAY,
|
|
6330
6441
|
rawExtraField,
|
|
6442
|
+
rawCentralExtraField: EMPTY_UINT8_ARRAY,
|
|
6331
6443
|
extendedTimestamp: false,
|
|
6332
6444
|
headerArray,
|
|
6333
6445
|
headerView
|
|
@@ -6501,7 +6613,6 @@ async function prependZipEntries(zipWriter, reader) {
|
|
|
6501
6613
|
|
|
6502
6614
|
async function addFileEntry(zipWriter, name, reader, options) {
|
|
6503
6615
|
options = Object.assign({}, options);
|
|
6504
|
-
name = name.trim();
|
|
6505
6616
|
if (getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY) && !name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
6506
6617
|
name += DIRECTORY_SIGNATURE;
|
|
6507
6618
|
}
|
|
@@ -6592,7 +6703,6 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
6592
6703
|
}
|
|
6593
6704
|
|
|
6594
6705
|
function resolveAttributes(zipWriter, name, options) {
|
|
6595
|
-
name = name.trim();
|
|
6596
6706
|
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
6597
6707
|
let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? VERSION_MADE_BY_MSDOS : VERSION_MADE_BY_UNIX);
|
|
6598
6708
|
const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
|
|
@@ -6797,6 +6907,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6797
6907
|
}
|
|
6798
6908
|
const rawExtraField = serializeExtraField(options[PROPERTY_NAME_EXTRA_FIELD]);
|
|
6799
6909
|
const rawLocalExtraField = serializeExtraField(options[OPTION_LOCAL_EXTRA_FIELD]);
|
|
6910
|
+
const rawCentralExtraField = serializeExtraField(options[OPTION_CENTRAL_EXTRA_FIELD]);
|
|
6800
6911
|
return {
|
|
6801
6912
|
comment,
|
|
6802
6913
|
resolvedOptions: {
|
|
@@ -6832,7 +6943,8 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6832
6943
|
dataDescriptor,
|
|
6833
6944
|
zip64,
|
|
6834
6945
|
rawExtraField,
|
|
6835
|
-
rawLocalExtraField
|
|
6946
|
+
rawLocalExtraField,
|
|
6947
|
+
rawCentralExtraField
|
|
6836
6948
|
}
|
|
6837
6949
|
};
|
|
6838
6950
|
}
|
|
@@ -6974,7 +7086,6 @@ async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comm
|
|
|
6974
7086
|
let { name } = entry;
|
|
6975
7087
|
const { size } = entry;
|
|
6976
7088
|
const options = Object.assign({}, entry.options);
|
|
6977
|
-
name = name.trim();
|
|
6978
7089
|
if (getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY) && !name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
6979
7090
|
name += DIRECTORY_SIGNATURE;
|
|
6980
7091
|
}
|
|
@@ -7230,6 +7341,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
|
|
|
7230
7341
|
versionMadeBy,
|
|
7231
7342
|
rawComment,
|
|
7232
7343
|
rawExtraField,
|
|
7344
|
+
rawCentralExtraField,
|
|
7233
7345
|
useWebWorkers,
|
|
7234
7346
|
transferStreams,
|
|
7235
7347
|
onstart,
|
|
@@ -7273,6 +7385,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
|
|
|
7273
7385
|
rawExtraFieldUnix,
|
|
7274
7386
|
rawExtraFieldAES,
|
|
7275
7387
|
rawExtraField,
|
|
7388
|
+
rawCentralExtraField,
|
|
7276
7389
|
extendedTimestamp,
|
|
7277
7390
|
msDosCompatible,
|
|
7278
7391
|
internalFileAttributes,
|
|
@@ -7773,6 +7886,7 @@ function createDirectoryRecords(files) {
|
|
|
7773
7886
|
rawExtraFieldNTFS,
|
|
7774
7887
|
rawExtraFieldUnix,
|
|
7775
7888
|
rawExtraField,
|
|
7889
|
+
rawCentralExtraField,
|
|
7776
7890
|
extendedTimestamp,
|
|
7777
7891
|
extraFieldExtendedTimestampFlag,
|
|
7778
7892
|
lastModDate,
|
|
@@ -7827,7 +7941,8 @@ function createDirectoryRecords(files) {
|
|
|
7827
7941
|
rawExtraFieldNTFS,
|
|
7828
7942
|
rawExtraFieldUnix,
|
|
7829
7943
|
rawExtraFieldTimestamp,
|
|
7830
|
-
rawExtraField
|
|
7944
|
+
rawExtraField,
|
|
7945
|
+
rawCentralExtraField);
|
|
7831
7946
|
if (extraFieldLength > MAX_16_BITS) {
|
|
7832
7947
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
7833
7948
|
}
|
|
@@ -7855,6 +7970,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7855
7970
|
rawExtraFieldNTFS,
|
|
7856
7971
|
rawExtraFieldUnix,
|
|
7857
7972
|
rawExtraField,
|
|
7973
|
+
rawCentralExtraField,
|
|
7858
7974
|
rawComment,
|
|
7859
7975
|
versionMadeBy,
|
|
7860
7976
|
headerArray,
|
|
@@ -7869,7 +7985,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7869
7985
|
uncompressedSize,
|
|
7870
7986
|
compressedSize
|
|
7871
7987
|
} = fileEntry;
|
|
7872
|
-
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
|
|
7988
|
+
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField, rawCentralExtraField);
|
|
7873
7989
|
const directoryRecordLength = CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
|
|
7874
7990
|
if (exceedsAvailableSize(writer, offset + directoryRecordLength - directoryDiskOffset)) {
|
|
7875
7991
|
await writeData(writer, directoryArray.slice(directoryDiskOffset, offset));
|
|
@@ -7907,6 +8023,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7907
8023
|
directoryRecord.writeBytes(rawExtraFieldNTFS);
|
|
7908
8024
|
directoryRecord.writeBytes(rawExtraFieldUnix);
|
|
7909
8025
|
directoryRecord.writeBytes(rawExtraField);
|
|
8026
|
+
directoryRecord.writeBytes(rawCentralExtraField);
|
|
7910
8027
|
directoryRecord.writeBytes(rawComment);
|
|
7911
8028
|
arraySet(directoryArray, directoryRecord.array, offset);
|
|
7912
8029
|
offset += directoryRecordLength;
|
|
@@ -10366,6 +10483,20 @@ exports.TextReader = TextReader;
|
|
|
10366
10483
|
exports.TextWriter = TextWriter;
|
|
10367
10484
|
exports.Uint8ArrayReader = Uint8ArrayReader;
|
|
10368
10485
|
exports.Uint8ArrayWriter = Uint8ArrayWriter;
|
|
10486
|
+
exports.WARNING_APPENDED_DATA = WARNING_APPENDED_DATA;
|
|
10487
|
+
exports.WARNING_COMPRESSED_PATCHED_DATA = WARNING_COMPRESSED_PATCHED_DATA;
|
|
10488
|
+
exports.WARNING_DUPLICATE_FILENAME = WARNING_DUPLICATE_FILENAME;
|
|
10489
|
+
exports.WARNING_MALFORMED_EXTRA_FIELD = WARNING_MALFORMED_EXTRA_FIELD;
|
|
10490
|
+
exports.WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG = WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG;
|
|
10491
|
+
exports.WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD = WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD;
|
|
10492
|
+
exports.WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES = WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES;
|
|
10493
|
+
exports.WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY = WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY;
|
|
10494
|
+
exports.WARNING_PREPENDED_DATA = WARNING_PREPENDED_DATA;
|
|
10495
|
+
exports.WARNING_TRAILING_CENTRAL_DIRECTORY_DATA = WARNING_TRAILING_CENTRAL_DIRECTORY_DATA;
|
|
10496
|
+
exports.WARNING_UNKNOWN_VERSION = WARNING_UNKNOWN_VERSION;
|
|
10497
|
+
exports.WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA = WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA;
|
|
10498
|
+
exports.WARNING_UNSORTED_CENTRAL_DIRECTORY = WARNING_UNSORTED_CENTRAL_DIRECTORY;
|
|
10499
|
+
exports.WARNING_WRAPPED_ENTRIES_COUNT = WARNING_WRAPPED_ENTRIES_COUNT;
|
|
10369
10500
|
exports.Writer = Writer;
|
|
10370
10501
|
exports.ZipDirectoryEntry = ZipDirectoryEntry;
|
|
10371
10502
|
exports.ZipEntry = ZipEntry;
|
|
@@ -10381,6 +10512,7 @@ exports.createOPFSTempStream = createOPFSTempStream;
|
|
|
10381
10512
|
exports.createSyncAccessHandleTempStream = createSyncAccessHandleTempStream;
|
|
10382
10513
|
exports.fs = fs;
|
|
10383
10514
|
exports.getMimeType = getMimeType;
|
|
10515
|
+
exports.isZipFile = isZipFile;
|
|
10384
10516
|
exports.registerCodec = registerCodec;
|
|
10385
10517
|
exports.resetConfiguration = resetConfiguration;
|
|
10386
10518
|
exports.terminateWorkers = terminateWorkers;
|