@zip.js/zip.js 2.8.57 → 2.8.58
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 +303 -163
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +303 -163
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +327 -164
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +344 -157
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +327 -164
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +329 -165
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +330 -166
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +305 -165
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +305 -165
- 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 +306 -166
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +329 -165
- package/index-native.min.js +1 -1
- package/index.cjs +330 -166
- package/index.d.cts +113 -9
- package/index.d.ts +113 -9
- package/index.min.js +1 -1
- package/lib/core/constants.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 +26 -6
- package/lib/core/zip-writer.js +278 -156
- package/lib/core/zlib-streams-inline.js +1 -1
- package/package.json +1 -1
|
@@ -92,6 +92,7 @@ const FILE_ATTR_UNIX_SETUID_MASK = 0o4000;
|
|
|
92
92
|
const FILE_ATTR_UNIX_SETGID_MASK = 0o2000;
|
|
93
93
|
const FILE_ATTR_UNIX_STICKY_MASK = 0o1000;
|
|
94
94
|
|
|
95
|
+
const VERSION_STORE = 0x0A;
|
|
95
96
|
const VERSION_DEFLATE = 0x14;
|
|
96
97
|
const VERSION_ZIP64 = 0x2D;
|
|
97
98
|
const VERSION_AES = 0x33;
|
|
@@ -4977,6 +4978,10 @@ class ZipReader {
|
|
|
4977
4978
|
const commentEncoding = getOptionValue$1(zipReader, options, OPTION_COMMENT_ENCODING);
|
|
4978
4979
|
const filenames = checkAmbiguity ? new Set() : UNDEFINED_VALUE;
|
|
4979
4980
|
let duplicateFilename;
|
|
4981
|
+
const recoverWrappedFilesLength = !checkAmbiguity && !zip64EndOfDirectory;
|
|
4982
|
+
if (!filesLength && recoverWrappedFilesLength) {
|
|
4983
|
+
filesLength = getWrappedFilesLength(directoryView, directoryArray, offset);
|
|
4984
|
+
}
|
|
4980
4985
|
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
4981
4986
|
const fileEntry = new ZipEntry$1(reader, zipReader.options);
|
|
4982
4987
|
if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32$1(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
@@ -5086,7 +5091,7 @@ class ZipReader {
|
|
|
5086
5091
|
internalFileAttribute: fileEntry.internalFileAttributes,
|
|
5087
5092
|
externalFileAttribute: fileEntry.externalFileAttributes,
|
|
5088
5093
|
executable,
|
|
5089
|
-
directory: modeIsDir || upperIsDir || (msDosCompatible && msdosAttributes.directory) ||
|
|
5094
|
+
directory: modeIsDir || upperIsDir || (msDosCompatible && msdosAttributes.directory) || fileEntry.filename.endsWith(DIRECTORY_SIGNATURE),
|
|
5090
5095
|
zipCrypto: fileEntry.encrypted && !fileEntry.extraFieldAES
|
|
5091
5096
|
});
|
|
5092
5097
|
const entry = new Entry(fileEntry);
|
|
@@ -5099,6 +5104,9 @@ class ZipReader {
|
|
|
5099
5104
|
return arrayBufferPromise;
|
|
5100
5105
|
};
|
|
5101
5106
|
offset = endOffset;
|
|
5107
|
+
if (indexFile == filesLength - 1 && recoverWrappedFilesLength) {
|
|
5108
|
+
filesLength += getWrappedFilesLength(directoryView, directoryArray, offset);
|
|
5109
|
+
}
|
|
5102
5110
|
const { onprogress } = options;
|
|
5103
5111
|
if (onprogress) {
|
|
5104
5112
|
try {
|
|
@@ -5257,6 +5265,7 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5257
5265
|
extraFieldLength,
|
|
5258
5266
|
filenameLength
|
|
5259
5267
|
} = localDirectory;
|
|
5268
|
+
const dataOffset = localDirectory.dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
|
|
5260
5269
|
const checkLocalDirectoryOption = getOptionValue$1(zipEntry, options, OPTION_CHECK_LOCAL_DIRECTORY);
|
|
5261
5270
|
const entryStrictness = getStrictness(options, zipEntry.options);
|
|
5262
5271
|
const checkLocalDirectory = getCheckLocalDirectory(checkLocalDirectoryOption, entryStrictness);
|
|
@@ -5310,7 +5319,6 @@ let ZipEntry$1 = class ZipEntry {
|
|
|
5310
5319
|
throw new Error(ERR_ENCRYPTED);
|
|
5311
5320
|
}
|
|
5312
5321
|
}
|
|
5313
|
-
const dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
|
|
5314
5322
|
if (dataOffset + compressedSize > reader.size) {
|
|
5315
5323
|
throw new Error(ERR_ENTRY_DATA_OUT_OF_BOUNDS);
|
|
5316
5324
|
}
|
|
@@ -5430,6 +5438,16 @@ function detectEncryptedCentralDirectory(directoryView) {
|
|
|
5430
5438
|
return false;
|
|
5431
5439
|
}
|
|
5432
5440
|
|
|
5441
|
+
function getWrappedFilesLength(directoryView, directoryArray, offset) {
|
|
5442
|
+
let wrappedFilesLength = 0;
|
|
5443
|
+
while (offset + CENTRAL_FILE_HEADER_LENGTH <= directoryArray.length && getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
5444
|
+
offset += CENTRAL_FILE_HEADER_LENGTH +
|
|
5445
|
+
getUint16$1(directoryView, offset + 28) + getUint16$1(directoryView, offset + 30) + getUint16$1(directoryView, offset + 32);
|
|
5446
|
+
wrappedFilesLength++;
|
|
5447
|
+
}
|
|
5448
|
+
return wrappedFilesLength % (MAX_16_BITS + 1) ? 0 : wrappedFilesLength;
|
|
5449
|
+
}
|
|
5450
|
+
|
|
5433
5451
|
function readDigitalSignature(signatureRecordArray) {
|
|
5434
5452
|
if (signatureRecordArray.length >= 6) {
|
|
5435
5453
|
const signatureRecordView = getDataView(signatureRecordArray);
|
|
@@ -5602,10 +5620,11 @@ function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName,
|
|
|
5602
5620
|
const computedCrc32View = getDataView(new Uint8Array(4));
|
|
5603
5621
|
computedCrc32View.setUint32(0, computedCrc32.get(), true);
|
|
5604
5622
|
const nameCrc32 = getUint32$1(extraFieldView, 1);
|
|
5623
|
+
const version = getUint8(extraFieldView, 0);
|
|
5605
5624
|
Object.assign(extraFieldUnicode, {
|
|
5606
|
-
version
|
|
5625
|
+
version,
|
|
5607
5626
|
[propertyName]: decodeText(extraFieldUnicode.data.subarray(5)),
|
|
5608
|
-
valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
|
|
5627
|
+
valid: version == 1 && !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
|
|
5609
5628
|
});
|
|
5610
5629
|
if (extraFieldUnicode.valid) {
|
|
5611
5630
|
directory[propertyName] = extraFieldUnicode[propertyName];
|
|
@@ -6074,7 +6093,8 @@ function getFunctionOptionValue$1(zipReader, options, name) {
|
|
|
6074
6093
|
|
|
6075
6094
|
function getDate(timeRaw) {
|
|
6076
6095
|
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
|
|
6077
|
-
|
|
6096
|
+
const result = new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
|
|
6097
|
+
return result < MIN_DATE ? MIN_DATE : result;
|
|
6078
6098
|
}
|
|
6079
6099
|
|
|
6080
6100
|
function getDateNTFS(timeRaw) {
|
|
@@ -6227,153 +6247,150 @@ class ZipWriter {
|
|
|
6227
6247
|
offset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? writer.size || writer.writable.size || 0 : options[OPTION_OFFSET],
|
|
6228
6248
|
initialOffset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : options[OPTION_OFFSET] - (writer.size || writer.writable.size || 0),
|
|
6229
6249
|
pendingAddFileCalls: new Set(),
|
|
6250
|
+
pendingErrors: [],
|
|
6230
6251
|
bufferedWrites: 0,
|
|
6231
6252
|
lastFileEntry: UNDEFINED_VALUE
|
|
6232
6253
|
});
|
|
6233
6254
|
}
|
|
6234
6255
|
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
6242
|
-
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
6243
|
-
await initStream(reader);
|
|
6244
|
-
}
|
|
6245
|
-
const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
|
|
6246
|
-
const zipReader$1 = new ZipReader(reader);
|
|
6247
|
-
const entries = await zipReader$1.getEntries();
|
|
6248
|
-
await zipReader$1.close();
|
|
6249
|
-
await initStream(this.writer);
|
|
6250
|
-
const { directoryOffset } = zipReader$1;
|
|
6251
|
-
if (this.addSplitZipSignature) {
|
|
6252
|
-
delete this.addSplitZipSignature;
|
|
6253
|
-
if (!await startsWithSplitZipSignature(reader)) {
|
|
6254
|
-
await writeData(this.writer, getSplitZipSignatureArray());
|
|
6255
|
-
this.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6256
|
-
}
|
|
6257
|
-
}
|
|
6258
|
-
const entryPositions = await copyZipData(this, reader, entries, directoryOffset);
|
|
6259
|
-
this.filenames = new Set(entries.map(entry => entry.filename));
|
|
6260
|
-
this.fileEntries = new Map(entries.map(entry => {
|
|
6261
|
-
const {
|
|
6262
|
-
version,
|
|
6263
|
-
rawLastModDate,
|
|
6264
|
-
lastAccessDate,
|
|
6265
|
-
creationDate,
|
|
6266
|
-
rawFilename,
|
|
6267
|
-
bitFlag,
|
|
6268
|
-
encrypted,
|
|
6269
|
-
uncompressedSize,
|
|
6270
|
-
compressedSize,
|
|
6271
|
-
extraFieldZip64
|
|
6272
|
-
} = entry;
|
|
6273
|
-
let {
|
|
6274
|
-
compressionMethod,
|
|
6275
|
-
rawExtraFieldZip64,
|
|
6276
|
-
rawExtraFieldAES,
|
|
6277
|
-
rawExtraFieldExtendedTimestamp,
|
|
6278
|
-
rawExtraFieldNTFS,
|
|
6279
|
-
rawExtraFieldUnix,
|
|
6280
|
-
rawExtraField,
|
|
6281
|
-
} = entry;
|
|
6282
|
-
const { level, languageEncodingFlag, dataDescriptor } = bitFlag;
|
|
6283
|
-
rawExtraFieldZip64 = rawExtraFieldZip64 || EMPTY_UINT8_ARRAY;
|
|
6284
|
-
rawExtraFieldAES = rawExtraFieldAES || EMPTY_UINT8_ARRAY;
|
|
6285
|
-
rawExtraFieldExtendedTimestamp = rawExtraFieldExtendedTimestamp || EMPTY_UINT8_ARRAY;
|
|
6286
|
-
rawExtraFieldNTFS = rawExtraFieldNTFS || EMPTY_UINT8_ARRAY;
|
|
6287
|
-
rawExtraFieldUnix = rawExtraFieldUnix || EMPTY_UINT8_ARRAY;
|
|
6288
|
-
rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
|
|
6289
|
-
if (entry.extraFieldAES) {
|
|
6290
|
-
compressionMethod = COMPRESSION_METHOD_AES;
|
|
6291
|
-
}
|
|
6292
|
-
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
|
|
6293
|
-
const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
|
|
6294
|
-
const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
|
|
6295
|
-
const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
|
|
6296
|
-
const {
|
|
6297
|
-
headerArray,
|
|
6298
|
-
headerView
|
|
6299
|
-
} = getHeaderArrayData({
|
|
6300
|
-
version,
|
|
6301
|
-
bitFlag: bitFlagValue,
|
|
6302
|
-
compressionMethod,
|
|
6303
|
-
uncompressedSize,
|
|
6304
|
-
compressedSize,
|
|
6305
|
-
rawLastModDate,
|
|
6306
|
-
rawFilename,
|
|
6307
|
-
zip64CompressedSize,
|
|
6308
|
-
zip64UncompressedSize,
|
|
6309
|
-
extraFieldLength
|
|
6310
|
-
});
|
|
6311
|
-
const { crc32 } = entry;
|
|
6312
|
-
if (crc32 !== UNDEFINED_VALUE) {
|
|
6313
|
-
setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
|
|
6314
|
-
}
|
|
6315
|
-
const { offset, diskNumberStart } = entryPositions.get(entry);
|
|
6316
|
-
Object.assign(entry, {
|
|
6317
|
-
zip64UncompressedSize,
|
|
6318
|
-
zip64CompressedSize,
|
|
6319
|
-
offset,
|
|
6320
|
-
diskNumberStart,
|
|
6321
|
-
zip64DiskNumberStart: false,
|
|
6322
|
-
rawExtraFieldZip64,
|
|
6323
|
-
rawExtraFieldAES,
|
|
6324
|
-
rawExtraFieldExtendedTimestamp,
|
|
6325
|
-
rawExtraFieldNTFS,
|
|
6326
|
-
rawExtraFieldUnix,
|
|
6327
|
-
rawExtraField,
|
|
6328
|
-
extendedTimestamp: rawExtraFieldExtendedTimestamp.length > 0 || rawExtraFieldNTFS.length > 0,
|
|
6329
|
-
extraFieldExtendedTimestampFlag: 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0),
|
|
6330
|
-
headerArray,
|
|
6331
|
-
headerView
|
|
6332
|
-
});
|
|
6333
|
-
return [entry.filename, entry];
|
|
6334
|
-
}));
|
|
6256
|
+
prependZip(reader) {
|
|
6257
|
+
return watchPromiseError(this, prependZipEntries(this, reader));
|
|
6258
|
+
}
|
|
6259
|
+
|
|
6260
|
+
appendZip(reader) {
|
|
6261
|
+
return watchPromiseError(this, this.appendZipEntries(reader));
|
|
6335
6262
|
}
|
|
6336
6263
|
|
|
6337
|
-
async
|
|
6264
|
+
async appendZipEntries(reader) {
|
|
6338
6265
|
const zipWriter = this;
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
workers++;
|
|
6343
|
-
} else {
|
|
6344
|
-
await new Promise(resolve => pendingEntries.push(resolve));
|
|
6266
|
+
const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
|
|
6267
|
+
while (pendingAddFileCalls.size) {
|
|
6268
|
+
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6345
6269
|
}
|
|
6346
|
-
let
|
|
6347
|
-
|
|
6270
|
+
let resolveAppendZip;
|
|
6271
|
+
const promiseAppendZip = new Promise(resolve => resolveAppendZip = resolve);
|
|
6272
|
+
pendingAddFileCalls.add(promiseAppendZip);
|
|
6273
|
+
const appendedFilenames = [];
|
|
6274
|
+
let releaseLockWriter;
|
|
6348
6275
|
try {
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
}
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6276
|
+
reader = new GenericReader(reader);
|
|
6277
|
+
await initStream(reader);
|
|
6278
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
6279
|
+
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
6280
|
+
await initStream(reader);
|
|
6281
|
+
}
|
|
6282
|
+
const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
|
|
6283
|
+
const zipReader$1 = new ZipReader(reader);
|
|
6284
|
+
const entries = await zipReader$1.getEntries();
|
|
6285
|
+
await zipReader$1.close();
|
|
6286
|
+
await initStream(zipWriter.writer);
|
|
6287
|
+
const { directoryOffset } = zipReader$1;
|
|
6288
|
+
entries.forEach(({ filename }) => {
|
|
6289
|
+
if (filenames.has(filename)) {
|
|
6290
|
+
throw new Error(ERR_DUPLICATED_NAME);
|
|
6291
|
+
}
|
|
6292
|
+
filenames.add(filename);
|
|
6293
|
+
appendedFilenames.push(filename);
|
|
6294
|
+
});
|
|
6295
|
+
zipWriter.writerLocked = true;
|
|
6296
|
+
const { lockWriter } = zipWriter;
|
|
6297
|
+
zipWriter.lockWriter = new Promise(resolve => releaseLockWriter = () => {
|
|
6298
|
+
zipWriter.writerLocked = false;
|
|
6299
|
+
resolve();
|
|
6300
|
+
});
|
|
6301
|
+
await lockWriter;
|
|
6302
|
+
if (zipWriter.addSplitZipSignature) {
|
|
6303
|
+
delete zipWriter.addSplitZipSignature;
|
|
6304
|
+
if (!await startsWithSplitZipSignature(reader)) {
|
|
6305
|
+
await writeData(zipWriter.writer, getSplitZipSignatureArray());
|
|
6306
|
+
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6307
|
+
}
|
|
6364
6308
|
}
|
|
6309
|
+
const entryPositions = await copyZipData(zipWriter, reader, entries, directoryOffset);
|
|
6310
|
+
entries.forEach(entry => {
|
|
6311
|
+
const {
|
|
6312
|
+
version,
|
|
6313
|
+
rawLastModDate,
|
|
6314
|
+
rawFilename,
|
|
6315
|
+
bitFlag,
|
|
6316
|
+
encrypted,
|
|
6317
|
+
uncompressedSize,
|
|
6318
|
+
compressedSize,
|
|
6319
|
+
extraFieldZip64
|
|
6320
|
+
} = entry;
|
|
6321
|
+
let {
|
|
6322
|
+
compressionMethod,
|
|
6323
|
+
rawExtraField,
|
|
6324
|
+
} = entry;
|
|
6325
|
+
const { level, languageEncodingFlag, dataDescriptor } = bitFlag;
|
|
6326
|
+
rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
|
|
6327
|
+
if (entry.extraFieldAES) {
|
|
6328
|
+
compressionMethod = COMPRESSION_METHOD_AES;
|
|
6329
|
+
}
|
|
6330
|
+
const extraFieldLength = getLength(rawExtraField);
|
|
6331
|
+
const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
|
|
6332
|
+
const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
|
|
6333
|
+
const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
|
|
6334
|
+
const {
|
|
6335
|
+
headerArray,
|
|
6336
|
+
headerView
|
|
6337
|
+
} = getHeaderArrayData({
|
|
6338
|
+
version,
|
|
6339
|
+
bitFlag: bitFlagValue,
|
|
6340
|
+
compressionMethod,
|
|
6341
|
+
uncompressedSize,
|
|
6342
|
+
compressedSize,
|
|
6343
|
+
rawLastModDate,
|
|
6344
|
+
rawFilename,
|
|
6345
|
+
zip64CompressedSize,
|
|
6346
|
+
zip64UncompressedSize,
|
|
6347
|
+
extraFieldLength
|
|
6348
|
+
});
|
|
6349
|
+
const { crc32 } = entry;
|
|
6350
|
+
if (crc32 !== UNDEFINED_VALUE) {
|
|
6351
|
+
setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
|
|
6352
|
+
}
|
|
6353
|
+
const { offset, diskNumberStart } = entryPositions.get(entry);
|
|
6354
|
+
Object.assign(entry, {
|
|
6355
|
+
zip64UncompressedSize,
|
|
6356
|
+
zip64CompressedSize,
|
|
6357
|
+
offset,
|
|
6358
|
+
diskNumberStart,
|
|
6359
|
+
zip64DiskNumberStart: false,
|
|
6360
|
+
rawExtraFieldZip64: EMPTY_UINT8_ARRAY,
|
|
6361
|
+
rawExtraFieldAES: EMPTY_UINT8_ARRAY,
|
|
6362
|
+
rawExtraFieldExtendedTimestamp: EMPTY_UINT8_ARRAY,
|
|
6363
|
+
rawExtraFieldNTFS: EMPTY_UINT8_ARRAY,
|
|
6364
|
+
rawExtraFieldUnix: EMPTY_UINT8_ARRAY,
|
|
6365
|
+
rawExtraField,
|
|
6366
|
+
extendedTimestamp: false,
|
|
6367
|
+
headerArray,
|
|
6368
|
+
headerView
|
|
6369
|
+
});
|
|
6370
|
+
fileEntries.set(entry.filename, entry);
|
|
6371
|
+
});
|
|
6372
|
+
} catch (error) {
|
|
6373
|
+
appendedFilenames.forEach(filename => filenames.delete(filename));
|
|
6365
6374
|
throw error;
|
|
6366
6375
|
} finally {
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
if (
|
|
6370
|
-
|
|
6371
|
-
} else {
|
|
6372
|
-
workers--;
|
|
6376
|
+
resolveAppendZip();
|
|
6377
|
+
pendingAddFileCalls.delete(promiseAppendZip);
|
|
6378
|
+
if (releaseLockWriter) {
|
|
6379
|
+
releaseLockWriter();
|
|
6373
6380
|
}
|
|
6374
6381
|
}
|
|
6375
6382
|
}
|
|
6376
6383
|
|
|
6384
|
+
add(name = "", reader, options = {}) {
|
|
6385
|
+
const zipWriter = this;
|
|
6386
|
+
const { pendingAddFileCalls } = zipWriter;
|
|
6387
|
+
const promiseAddFile = addFileEntry(zipWriter, name, reader, options);
|
|
6388
|
+
pendingAddFileCalls.add(promiseAddFile);
|
|
6389
|
+
const deletePendingAddFileCall = () => pendingAddFileCalls.delete(promiseAddFile);
|
|
6390
|
+
Promise.prototype.then.call(promiseAddFile, deletePendingAddFileCall, deletePendingAddFileCall);
|
|
6391
|
+
return watchPromiseError(zipWriter, promiseAddFile);
|
|
6392
|
+
}
|
|
6393
|
+
|
|
6377
6394
|
remove(entry) {
|
|
6378
6395
|
const { filenames, fileEntries } = this;
|
|
6379
6396
|
// deno-lint-ignore valid-typeof
|
|
@@ -6404,6 +6421,19 @@ class ZipWriter {
|
|
|
6404
6421
|
while (pendingAddFileCalls.size) {
|
|
6405
6422
|
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6406
6423
|
}
|
|
6424
|
+
await Promise.allSettled(zipWriter.pendingErrors.map(watcher => watcher.recorded));
|
|
6425
|
+
const unobservedWatchers = zipWriter.pendingErrors.filter(watcher => watcher.error && !watcher.observed);
|
|
6426
|
+
if (unobservedWatchers.length) {
|
|
6427
|
+
const unobservedErrors = unobservedWatchers.map(watcher => watcher.error);
|
|
6428
|
+
unobservedWatchers.forEach(watcher => watcher.observed = true);
|
|
6429
|
+
const [error] = unobservedErrors;
|
|
6430
|
+
try {
|
|
6431
|
+
error.entryErrors = unobservedErrors;
|
|
6432
|
+
} catch {
|
|
6433
|
+
// ignored
|
|
6434
|
+
}
|
|
6435
|
+
throw error;
|
|
6436
|
+
}
|
|
6407
6437
|
await closeFile(zipWriter, comment, options);
|
|
6408
6438
|
const preventClose = !ownsWritable(writer) && getOptionValue(zipWriter, options, OPTION_PREVENT_CLOSE);
|
|
6409
6439
|
if (!preventClose) {
|
|
@@ -6438,11 +6468,7 @@ class ZipWriterStream {
|
|
|
6438
6468
|
try {
|
|
6439
6469
|
await zipWriter.close();
|
|
6440
6470
|
} catch (error) {
|
|
6441
|
-
|
|
6442
|
-
await zipWriter.writer.writable.abort(error);
|
|
6443
|
-
} catch {
|
|
6444
|
-
// ignored
|
|
6445
|
-
}
|
|
6471
|
+
await abortWritable(zipWriter, error);
|
|
6446
6472
|
}
|
|
6447
6473
|
}
|
|
6448
6474
|
}
|
|
@@ -6459,8 +6485,90 @@ class ZipWriterStream {
|
|
|
6459
6485
|
}
|
|
6460
6486
|
|
|
6461
6487
|
async close(comment = UNDEFINED_VALUE, options = {}) {
|
|
6462
|
-
|
|
6463
|
-
|
|
6488
|
+
const { zipWriter } = this;
|
|
6489
|
+
const results = await Promise.allSettled(Array.from(this.pendingAddFileCalls));
|
|
6490
|
+
const entryErrors = results.filter(result => result.status == "rejected").map(result => result.reason);
|
|
6491
|
+
if (entryErrors.length) {
|
|
6492
|
+
const [error] = entryErrors;
|
|
6493
|
+
try {
|
|
6494
|
+
error.entryErrors = entryErrors;
|
|
6495
|
+
} catch {
|
|
6496
|
+
// ignored
|
|
6497
|
+
}
|
|
6498
|
+
await abortWritable(zipWriter, error);
|
|
6499
|
+
throw error;
|
|
6500
|
+
}
|
|
6501
|
+
try {
|
|
6502
|
+
return await zipWriter.close(comment, options);
|
|
6503
|
+
} catch (error) {
|
|
6504
|
+
await abortWritable(zipWriter, error);
|
|
6505
|
+
throw error;
|
|
6506
|
+
}
|
|
6507
|
+
}
|
|
6508
|
+
}
|
|
6509
|
+
|
|
6510
|
+
class WatchedPromise extends Promise {
|
|
6511
|
+
|
|
6512
|
+
then(onFulfilled, onRejected) {
|
|
6513
|
+
const { watcher } = this;
|
|
6514
|
+
if (watcher) {
|
|
6515
|
+
watcher.observed = true;
|
|
6516
|
+
}
|
|
6517
|
+
return super.then(onFulfilled, onRejected);
|
|
6518
|
+
}
|
|
6519
|
+
}
|
|
6520
|
+
|
|
6521
|
+
function watchPromiseError(zipWriter, promise) {
|
|
6522
|
+
const watchedPromise = new WatchedPromise((resolve, reject) => Promise.prototype.then.call(promise, resolve, reject));
|
|
6523
|
+
const watcher = {};
|
|
6524
|
+
watchedPromise.watcher = watcher;
|
|
6525
|
+
watcher.recorded = Promise.prototype.then.call(watchedPromise, UNDEFINED_VALUE, error => watcher.error = error);
|
|
6526
|
+
zipWriter.pendingErrors.push(watcher);
|
|
6527
|
+
return watchedPromise;
|
|
6528
|
+
}
|
|
6529
|
+
|
|
6530
|
+
async function prependZipEntries(zipWriter, reader) {
|
|
6531
|
+
if (zipWriter.filenames.size) {
|
|
6532
|
+
throw new Error(ERR_ZIP_NOT_EMPTY);
|
|
6533
|
+
}
|
|
6534
|
+
await zipWriter.appendZipEntries(reader);
|
|
6535
|
+
}
|
|
6536
|
+
|
|
6537
|
+
async function addFileEntry(zipWriter, name, reader, options) {
|
|
6538
|
+
options = Object.assign({}, options);
|
|
6539
|
+
name = name.trim();
|
|
6540
|
+
if (getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY) && !name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
6541
|
+
name += DIRECTORY_SIGNATURE;
|
|
6542
|
+
}
|
|
6543
|
+
if (zipWriter.filenames.has(name)) {
|
|
6544
|
+
throw new Error(ERR_DUPLICATED_NAME);
|
|
6545
|
+
}
|
|
6546
|
+
zipWriter.filenames.add(name);
|
|
6547
|
+
if (workers < getConfiguration().maxWorkers) {
|
|
6548
|
+
workers++;
|
|
6549
|
+
} else {
|
|
6550
|
+
await new Promise(resolve => pendingEntries.push(resolve));
|
|
6551
|
+
}
|
|
6552
|
+
try {
|
|
6553
|
+
return await addFile(zipWriter, name, reader, options);
|
|
6554
|
+
} catch (error) {
|
|
6555
|
+
zipWriter.filenames.delete(name);
|
|
6556
|
+
throw error;
|
|
6557
|
+
} finally {
|
|
6558
|
+
const pendingEntry = pendingEntries.shift();
|
|
6559
|
+
if (pendingEntry) {
|
|
6560
|
+
pendingEntry();
|
|
6561
|
+
} else {
|
|
6562
|
+
workers--;
|
|
6563
|
+
}
|
|
6564
|
+
}
|
|
6565
|
+
}
|
|
6566
|
+
|
|
6567
|
+
async function abortWritable(zipWriter, error) {
|
|
6568
|
+
try {
|
|
6569
|
+
await zipWriter.writer.writable.abort(error);
|
|
6570
|
+
} catch {
|
|
6571
|
+
// ignored
|
|
6464
6572
|
}
|
|
6465
6573
|
}
|
|
6466
6574
|
|
|
@@ -6663,11 +6771,12 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6663
6771
|
if (getLength(rawComment) > MAX_16_BITS) {
|
|
6664
6772
|
throw new Error(ERR_INVALID_ENTRY_COMMENT);
|
|
6665
6773
|
}
|
|
6666
|
-
const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION
|
|
6667
|
-
if (version > MAX_16_BITS) {
|
|
6774
|
+
const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION);
|
|
6775
|
+
if (version !== UNDEFINED_VALUE && version > MAX_16_BITS) {
|
|
6668
6776
|
throw new Error(ERR_INVALID_VERSION);
|
|
6669
6777
|
}
|
|
6670
6778
|
const lastModDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
|
|
6779
|
+
const rawLastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE);
|
|
6671
6780
|
const lastAccessDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
6672
6781
|
const creationDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
6673
6782
|
const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
|
|
@@ -6711,7 +6820,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6711
6820
|
if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
|
|
6712
6821
|
dataDescriptor = false;
|
|
6713
6822
|
}
|
|
6714
|
-
if (dataDescriptor === UNDEFINED_VALUE || zipCrypto) {
|
|
6823
|
+
if (dataDescriptor === UNDEFINED_VALUE || (zipCrypto && !passThrough)) {
|
|
6715
6824
|
dataDescriptor = true;
|
|
6716
6825
|
}
|
|
6717
6826
|
if (level !== UNDEFINED_VALUE && level != 6) {
|
|
@@ -6730,6 +6839,7 @@ function resolveMetadata(zipWriter, name, options) {
|
|
|
6730
6839
|
rawComment,
|
|
6731
6840
|
version,
|
|
6732
6841
|
lastModDate,
|
|
6842
|
+
rawLastModDate,
|
|
6733
6843
|
lastAccessDate,
|
|
6734
6844
|
creationDate,
|
|
6735
6845
|
internalFileAttributes,
|
|
@@ -7005,10 +7115,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
7005
7115
|
}
|
|
7006
7116
|
await initStream(fileWriter);
|
|
7007
7117
|
const diskOffset = getDiskOffset(writer);
|
|
7008
|
-
if (zipWriter.addSplitZipSignature) {
|
|
7009
|
-
|
|
7010
|
-
await writeData(writer, getSplitZipSignatureArray());
|
|
7011
|
-
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
7118
|
+
if (zipWriter.addSplitZipSignature && !bufferedWrite) {
|
|
7119
|
+
await writeSplitZipSignature(zipWriter, writer);
|
|
7012
7120
|
}
|
|
7013
7121
|
if (usdz && !bufferedWrite) {
|
|
7014
7122
|
appendExtraFieldUSDZ(entryInfo, zipWriter.offset - diskOffset);
|
|
@@ -7035,6 +7143,9 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
7035
7143
|
if (bufferedWrite) {
|
|
7036
7144
|
await Promise.all([fileWriter.writable.getWriter().close(), lockPreviousFileEntry]);
|
|
7037
7145
|
await requestLockWriter();
|
|
7146
|
+
if (zipWriter.addSplitZipSignature) {
|
|
7147
|
+
await writeSplitZipSignature(zipWriter, writer);
|
|
7148
|
+
}
|
|
7038
7149
|
writingBufferedEntryData = true;
|
|
7039
7150
|
writerSizeBeforeEntry = writer.size;
|
|
7040
7151
|
await skipDiskIfNeeded();
|
|
@@ -7306,6 +7417,7 @@ function getHeaderInfo(options) {
|
|
|
7306
7417
|
const {
|
|
7307
7418
|
rawFilename,
|
|
7308
7419
|
lastModDate,
|
|
7420
|
+
rawLastModDate: rawLastModDateOption,
|
|
7309
7421
|
lastAccessDate,
|
|
7310
7422
|
creationDate,
|
|
7311
7423
|
level,
|
|
@@ -7439,6 +7551,9 @@ function getHeaderInfo(options) {
|
|
|
7439
7551
|
if (compressionMethod === UNDEFINED_VALUE) {
|
|
7440
7552
|
compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
|
|
7441
7553
|
}
|
|
7554
|
+
if (version === UNDEFINED_VALUE) {
|
|
7555
|
+
version = compressionMethod == COMPRESSION_METHOD_STORE && !directory && !encrypted ? VERSION_STORE : VERSION_DEFLATE;
|
|
7556
|
+
}
|
|
7442
7557
|
const { codecVersionNeeded } = options;
|
|
7443
7558
|
if (compressed && codecVersionNeeded !== UNDEFINED_VALUE) {
|
|
7444
7559
|
version = version > codecVersionNeeded ? version : codecVersionNeeded;
|
|
@@ -7471,6 +7586,7 @@ function getHeaderInfo(options) {
|
|
|
7471
7586
|
compressionMethod,
|
|
7472
7587
|
uncompressedSize,
|
|
7473
7588
|
lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
|
|
7589
|
+
rawLastModDate: rawLastModDateOption,
|
|
7474
7590
|
rawFilename,
|
|
7475
7591
|
zip64CompressedSize,
|
|
7476
7592
|
zip64UncompressedSize,
|
|
@@ -7677,9 +7793,9 @@ function updateLocalHeader({
|
|
|
7677
7793
|
|
|
7678
7794
|
async function closeFile(zipWriter, comment, options) {
|
|
7679
7795
|
const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
|
|
7680
|
-
const { directoryStart, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
|
|
7796
|
+
const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
|
|
7681
7797
|
const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
|
|
7682
|
-
await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength, signatureLength });
|
|
7798
|
+
await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
|
|
7683
7799
|
}
|
|
7684
7800
|
|
|
7685
7801
|
function createDirectoryRecords(files) {
|
|
@@ -7763,6 +7879,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7763
7879
|
let directoryDiskOffset = 0;
|
|
7764
7880
|
let directoryStartDiskNumber = getDiskNumber(writer);
|
|
7765
7881
|
let directoryStartDiskOffset = getDiskOffset(writer);
|
|
7882
|
+
let directoryEndDiskEntriesLength = 0;
|
|
7766
7883
|
for (const [indexFileEntry, fileEntry] of Array.from(fileEntries.values()).entries()) {
|
|
7767
7884
|
const {
|
|
7768
7885
|
offset: fileEntryOffset,
|
|
@@ -7792,6 +7909,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7792
7909
|
if (exceedsAvailableSize(writer, offset + directoryRecordLength - directoryDiskOffset)) {
|
|
7793
7910
|
await writeData(writer, directoryArray.slice(directoryDiskOffset, offset));
|
|
7794
7911
|
directoryDiskOffset = offset;
|
|
7912
|
+
directoryEndDiskEntriesLength = 0;
|
|
7795
7913
|
await writer.closeDisk();
|
|
7796
7914
|
}
|
|
7797
7915
|
if (indexFileEntry == 0) {
|
|
@@ -7827,6 +7945,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7827
7945
|
directoryRecord.writeBytes(rawComment);
|
|
7828
7946
|
arraySet(directoryArray, directoryRecord.array, offset);
|
|
7829
7947
|
offset += directoryRecordLength;
|
|
7948
|
+
directoryEndDiskEntriesLength++;
|
|
7830
7949
|
if (options.onprogress) {
|
|
7831
7950
|
try {
|
|
7832
7951
|
await options.onprogress(indexFileEntry + 1, fileEntries.size, new Entry(fileEntry));
|
|
@@ -7838,6 +7957,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
|
7838
7957
|
await writeData(writer, directoryDiskOffset ? directoryArray.slice(directoryDiskOffset) : directoryArray);
|
|
7839
7958
|
return {
|
|
7840
7959
|
directoryStart: { diskNumber: directoryStartDiskNumber, diskOffset: directoryStartDiskOffset },
|
|
7960
|
+
directoryEnd: { diskNumber: getDiskNumber(writer), entriesLength: directoryEndDiskEntriesLength },
|
|
7841
7961
|
directoryArray
|
|
7842
7962
|
};
|
|
7843
7963
|
}
|
|
@@ -7866,16 +7986,20 @@ async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
|
|
|
7866
7986
|
|
|
7867
7987
|
async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
7868
7988
|
const { writer } = zipWriter;
|
|
7869
|
-
const { directoryStart, signatureLength } = cdInfo;
|
|
7989
|
+
const { directoryStart, directoryEnd, signatureLength } = cdInfo;
|
|
7870
7990
|
let { directoryDataLength } = cdInfo;
|
|
7871
7991
|
let fileEntriesLength = zipWriter.fileEntries.size;
|
|
7872
7992
|
let diskNumber = directoryStart.diskNumber;
|
|
7873
7993
|
let directoryOffset = getSegmentOffset(zipWriter, directoryStart);
|
|
7994
|
+
const commentLength = getLength(comment);
|
|
7995
|
+
if (commentLength > MAX_16_BITS) {
|
|
7996
|
+
throw new Error(ERR_INVALID_COMMENT);
|
|
7997
|
+
}
|
|
7998
|
+
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
7874
7999
|
let lastDiskNumber = getDiskNumber(writer);
|
|
7875
|
-
if (exceedsAvailableSize(writer, END_OF_CENTRAL_DIR_LENGTH)) {
|
|
8000
|
+
if (exceedsAvailableSize(writer, (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH) + commentLength)) {
|
|
7876
8001
|
lastDiskNumber++;
|
|
7877
8002
|
}
|
|
7878
|
-
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
7879
8003
|
if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || fileEntriesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
|
|
7880
8004
|
if (zip64 === false) {
|
|
7881
8005
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
@@ -7883,15 +8007,12 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
|
7883
8007
|
zip64 = true;
|
|
7884
8008
|
}
|
|
7885
8009
|
}
|
|
7886
|
-
const commentLength = getLength(comment);
|
|
7887
|
-
if (commentLength > MAX_16_BITS) {
|
|
7888
|
-
throw new Error(ERR_INVALID_COMMENT);
|
|
7889
|
-
}
|
|
7890
8010
|
const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
|
|
7891
8011
|
if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
|
|
7892
8012
|
await writer.closeDisk();
|
|
7893
8013
|
}
|
|
7894
8014
|
lastDiskNumber = getDiskNumber(writer);
|
|
8015
|
+
let diskFileEntriesLength = lastDiskNumber == directoryEnd.diskNumber ? directoryEnd.entriesLength : 0;
|
|
7895
8016
|
if (zip64) {
|
|
7896
8017
|
endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
|
|
7897
8018
|
endOfdirectoryRecord.writeUint64(44);
|
|
@@ -7899,7 +8020,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
|
7899
8020
|
endOfdirectoryRecord.writeUint16(45);
|
|
7900
8021
|
endOfdirectoryRecord.writeUint32(lastDiskNumber);
|
|
7901
8022
|
endOfdirectoryRecord.writeUint32(diskNumber);
|
|
7902
|
-
endOfdirectoryRecord.writeUint64(
|
|
8023
|
+
endOfdirectoryRecord.writeUint64(diskFileEntriesLength);
|
|
7903
8024
|
endOfdirectoryRecord.writeUint64(fileEntriesLength);
|
|
7904
8025
|
endOfdirectoryRecord.writeUint64(directoryDataLength);
|
|
7905
8026
|
endOfdirectoryRecord.writeUint64(directoryOffset);
|
|
@@ -7912,6 +8033,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
|
7912
8033
|
lastDiskNumber = MAX_16_BITS;
|
|
7913
8034
|
diskNumber = MAX_16_BITS;
|
|
7914
8035
|
}
|
|
8036
|
+
diskFileEntriesLength = MAX_16_BITS;
|
|
7915
8037
|
fileEntriesLength = MAX_16_BITS;
|
|
7916
8038
|
directoryOffset = MAX_32_BITS;
|
|
7917
8039
|
directoryDataLength = MAX_32_BITS;
|
|
@@ -7919,7 +8041,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
|
|
|
7919
8041
|
endOfdirectoryRecord.writeUint32(END_OF_CENTRAL_DIR_SIGNATURE);
|
|
7920
8042
|
endOfdirectoryRecord.writeUint16(lastDiskNumber);
|
|
7921
8043
|
endOfdirectoryRecord.writeUint16(diskNumber);
|
|
7922
|
-
endOfdirectoryRecord.writeUint16(
|
|
8044
|
+
endOfdirectoryRecord.writeUint16(diskFileEntriesLength);
|
|
7923
8045
|
endOfdirectoryRecord.writeUint16(fileEntriesLength);
|
|
7924
8046
|
endOfdirectoryRecord.writeUint32(directoryDataLength);
|
|
7925
8047
|
endOfdirectoryRecord.writeUint32(directoryOffset);
|
|
@@ -8018,9 +8140,21 @@ async function copyZipData(zipWriter, reader, entries, directoryOffset) {
|
|
|
8018
8140
|
async function copyData(zipWriter, reader, offset, size) {
|
|
8019
8141
|
if (size > 0) {
|
|
8020
8142
|
const { writer } = zipWriter;
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8143
|
+
let copiedLength = 0;
|
|
8144
|
+
try {
|
|
8145
|
+
await flushBufferedData(createReadable(reader, { offset, size }), writer, UNDEFINED_VALUE, chunkLength => copiedLength += chunkLength);
|
|
8146
|
+
} catch (error) {
|
|
8147
|
+
zipWriter.hasCorruptedEntries = true;
|
|
8148
|
+
try {
|
|
8149
|
+
error.corruptedEntry = true;
|
|
8150
|
+
} catch {
|
|
8151
|
+
// ignored
|
|
8152
|
+
}
|
|
8153
|
+
throw error;
|
|
8154
|
+
} finally {
|
|
8155
|
+
writer.size += copiedLength;
|
|
8156
|
+
zipWriter.offset += copiedLength;
|
|
8157
|
+
}
|
|
8024
8158
|
}
|
|
8025
8159
|
}
|
|
8026
8160
|
|
|
@@ -8045,6 +8179,12 @@ function getSplitZipSignatureArray() {
|
|
|
8045
8179
|
return signatureArray;
|
|
8046
8180
|
}
|
|
8047
8181
|
|
|
8182
|
+
async function writeSplitZipSignature(zipWriter, writer) {
|
|
8183
|
+
delete zipWriter.addSplitZipSignature;
|
|
8184
|
+
await writeData(writer, getSplitZipSignatureArray());
|
|
8185
|
+
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
8186
|
+
}
|
|
8187
|
+
|
|
8048
8188
|
async function writeData(writer, array) {
|
|
8049
8189
|
const { writable } = writer;
|
|
8050
8190
|
const streamWriter = writable.getWriter();
|
|
@@ -9131,6 +9271,7 @@ const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
|
9131
9271
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
9132
9272
|
const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
|
|
9133
9273
|
const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
|
|
9274
|
+
const ERR_ZIP_CRYPTO_LAST_MOD_DATE = "The last modification date of an entry encrypted with ZipCrypto cannot be changed when passThrough is set";
|
|
9134
9275
|
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
9135
9276
|
const ERR_ABORTED = "The operation was aborted";
|
|
9136
9277
|
const ABORT_ERROR_NAME = "AbortError";
|
|
@@ -9998,6 +10139,7 @@ function getChildEntryOptions(child, selectedEntry, options) {
|
|
|
9998
10139
|
versionMadeBy,
|
|
9999
10140
|
comment,
|
|
10000
10141
|
lastModDate,
|
|
10142
|
+
rawLastModDate,
|
|
10001
10143
|
creationDate,
|
|
10002
10144
|
lastAccessDate,
|
|
10003
10145
|
uncompressedSize,
|
|
@@ -10008,6 +10150,7 @@ function getChildEntryOptions(child, selectedEntry, options) {
|
|
|
10008
10150
|
extraFieldAES,
|
|
10009
10151
|
internalFileAttributes,
|
|
10010
10152
|
extraField,
|
|
10153
|
+
bitFlag,
|
|
10011
10154
|
uid,
|
|
10012
10155
|
gid
|
|
10013
10156
|
} = child.data;
|
|
@@ -10045,6 +10188,16 @@ function getChildEntryOptions(child, selectedEntry, options) {
|
|
|
10045
10188
|
encryptionStrength,
|
|
10046
10189
|
compressionMethod
|
|
10047
10190
|
};
|
|
10191
|
+
if (bitFlag) {
|
|
10192
|
+
passThroughOptions.dataDescriptor = bitFlag.dataDescriptor;
|
|
10193
|
+
}
|
|
10194
|
+
const lastModDateOverride = childOptions.lastModDate === UNDEFINED_VALUE ? options.lastModDate : childOptions.lastModDate;
|
|
10195
|
+
if (lastModDateOverride === UNDEFINED_VALUE) {
|
|
10196
|
+
passThroughOptions.rawLastModDate = rawLastModDate;
|
|
10197
|
+
} else if (zipCrypto && (!bitFlag || bitFlag.dataDescriptor) && lastModDateOverride instanceof Date &&
|
|
10198
|
+
getDosTimeHighByte(lastModDateOverride) != ((rawLastModDate >>> 8) & MAX_8_BITS)) {
|
|
10199
|
+
throw new Error(ERR_ZIP_CRYPTO_LAST_MOD_DATE);
|
|
10200
|
+
}
|
|
10048
10201
|
}
|
|
10049
10202
|
}
|
|
10050
10203
|
const entryOptions = Object.assign({ lastModDate: child.defaultLastModDate }, zipEntryMetadata, options, childOptions, passThroughOptions, { directory: child.directory });
|
|
@@ -10054,6 +10207,16 @@ function getChildEntryOptions(child, selectedEntry, options) {
|
|
|
10054
10207
|
return { name, entryOptions };
|
|
10055
10208
|
}
|
|
10056
10209
|
|
|
10210
|
+
function getDosTimeHighByte(lastModDate) {
|
|
10211
|
+
let dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
|
|
10212
|
+
if (dosLastModDate < MIN_DATE) {
|
|
10213
|
+
dosLastModDate = MIN_DATE;
|
|
10214
|
+
} else if (dosLastModDate > MAX_DATE) {
|
|
10215
|
+
dosLastModDate = MAX_DATE;
|
|
10216
|
+
}
|
|
10217
|
+
return ((dosLastModDate.getHours() << 3) | (dosLastModDate.getMinutes() >> 3)) & MAX_8_BITS;
|
|
10218
|
+
}
|
|
10219
|
+
|
|
10057
10220
|
function getDeterminedSize(child, passThrough) {
|
|
10058
10221
|
const { reader } = child;
|
|
10059
10222
|
if (reader && reader.size !== UNDEFINED_VALUE) {
|
|
@@ -10392,4 +10555,4 @@ function addChild(parent, name, params, directory) {
|
|
|
10392
10555
|
}
|
|
10393
10556
|
}
|
|
10394
10557
|
|
|
10395
|
-
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, 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_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_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_PASS_THROUGH, ERR_INVALID_READER_OPTIONS, 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_READABLE_CONSUMED, 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, ZipDirectoryEntry, ZipEntry, ZipFS, ZipFileEntry, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|
|
10558
|
+
export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, 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_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_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_PASS_THROUGH, ERR_INVALID_READER_OPTIONS, 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_READABLE_CONSUMED, 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_CRYPTO_LAST_MOD_DATE, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipDirectoryEntry, ZipEntry, ZipFS, ZipFileEntry, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
|