@zip.js/zip.js 2.8.51 → 2.8.53
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/README.md +8 -3
- package/deno.json +1 -1
- package/dist/zip-core-external.js +241 -95
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +243 -94
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +564 -199
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +551 -194
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +564 -199
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +567 -198
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +567 -198
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +243 -94
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +243 -94
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +243 -94
- package/dist/zip.min.js +1 -1
- package/eslint.config.mjs +1 -1
- package/index-native.cjs +567 -198
- package/index-native.min.js +1 -1
- package/index.cjs +567 -198
- package/index.d.cts +551 -45
- package/index.d.ts +551 -45
- package/index.min.js +1 -1
- package/lib/core/codec-worker-web.js +13 -4
- package/lib/core/codec-worker.js +2 -0
- package/lib/core/constants.js +9 -0
- package/lib/core/io.js +43 -4
- package/lib/core/options.js +2 -0
- package/lib/core/util/compatible-streams.js +3 -8
- package/lib/core/zip-entry.js +16 -0
- package/lib/core/zip-fs.js +236 -107
- package/lib/core/zip-reader.js +106 -40
- package/lib/core/zip-writer.js +171 -41
- package/lib/zip-core-writer.js +3 -0
- package/package.json +9 -7
package/dist/zip.js
CHANGED
|
@@ -90,6 +90,8 @@
|
|
|
90
90
|
const FILE_ATTR_MSDOS_ARCHIVE_MASK = 0x20;
|
|
91
91
|
const FILE_ATTR_UNIX_TYPE_MASK = 0o170000;
|
|
92
92
|
const FILE_ATTR_UNIX_TYPE_DIR = 0o040000;
|
|
93
|
+
const FILE_ATTR_UNIX_TYPE_SYMLINK = 0o120000;
|
|
94
|
+
const FILE_ATTR_UNIX_TYPE_FILE = 0o100000;
|
|
93
95
|
const FILE_ATTR_UNIX_EXECUTABLE_MASK = 0o111;
|
|
94
96
|
const FILE_ATTR_UNIX_DEFAULT_MASK = 0o644;
|
|
95
97
|
const FILE_ATTR_UNIX_SETUID_MASK = 0o4000;
|
|
@@ -100,6 +102,9 @@
|
|
|
100
102
|
const VERSION_ZIP64 = 0x2D;
|
|
101
103
|
const VERSION_AES = 0x33;
|
|
102
104
|
|
|
105
|
+
const VERSION_MADE_BY_MSDOS = 0x0014;
|
|
106
|
+
const VERSION_MADE_BY_UNIX = 0x0300;
|
|
107
|
+
|
|
103
108
|
const DIRECTORY_SIGNATURE = "/";
|
|
104
109
|
|
|
105
110
|
const HEADER_SIZE = 30;
|
|
@@ -1781,8 +1786,6 @@
|
|
|
1781
1786
|
*/
|
|
1782
1787
|
|
|
1783
1788
|
|
|
1784
|
-
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
1785
|
-
|
|
1786
1789
|
function toCompatibleReadable(readable) {
|
|
1787
1790
|
if (readable instanceof ReadableStream) {
|
|
1788
1791
|
return readable;
|
|
@@ -1805,12 +1808,9 @@
|
|
|
1805
1808
|
|
|
1806
1809
|
function streamToBlob(readable, contentType) {
|
|
1807
1810
|
readable = toCompatibleReadable(readable);
|
|
1811
|
+
const blobOptions = contentType ? { type: contentType } : {};
|
|
1808
1812
|
if (responseSupportsGlobalReadable()) {
|
|
1809
|
-
|
|
1810
|
-
if (contentType) {
|
|
1811
|
-
options.headers = [[HTTP_HEADER_CONTENT_TYPE, contentType]];
|
|
1812
|
-
}
|
|
1813
|
-
return new Response(readable, options).blob();
|
|
1813
|
+
return new Response(readable).blob().then(blob => contentType ? new Blob([blob], blobOptions) : blob);
|
|
1814
1814
|
}
|
|
1815
1815
|
const chunks = [];
|
|
1816
1816
|
return readable
|
|
@@ -1819,7 +1819,7 @@
|
|
|
1819
1819
|
chunks.push(chunk);
|
|
1820
1820
|
}
|
|
1821
1821
|
}))
|
|
1822
|
-
.then(() => new Blob(chunks,
|
|
1822
|
+
.then(() => new Blob(chunks, blobOptions));
|
|
1823
1823
|
}
|
|
1824
1824
|
|
|
1825
1825
|
function responseSupportsGlobalReadable() {
|
|
@@ -2765,6 +2765,7 @@
|
|
|
2765
2765
|
worker,
|
|
2766
2766
|
workerAlive: false,
|
|
2767
2767
|
terminated: false,
|
|
2768
|
+
startupError: null,
|
|
2768
2769
|
interface: {
|
|
2769
2770
|
run: async () => {
|
|
2770
2771
|
try {
|
|
@@ -2792,6 +2793,13 @@
|
|
|
2792
2793
|
}
|
|
2793
2794
|
|
|
2794
2795
|
async function runWebWorker(workerData, config) {
|
|
2796
|
+
if (!workerData.worker) {
|
|
2797
|
+
const { startupError } = workerData;
|
|
2798
|
+
workerData.startupError = null;
|
|
2799
|
+
const error = startupError || new Error(ERR_WORKER_STARTUP_TIMEOUT);
|
|
2800
|
+
error.workerStartupFailed = true;
|
|
2801
|
+
throw error;
|
|
2802
|
+
}
|
|
2795
2803
|
let resolveResult, rejectResult;
|
|
2796
2804
|
const result = new Promise((resolve, reject) => {
|
|
2797
2805
|
resolveResult = resolve;
|
|
@@ -3005,11 +3013,12 @@
|
|
|
3005
3013
|
if (!workerAlive) {
|
|
3006
3014
|
workerData.worker = null;
|
|
3007
3015
|
}
|
|
3016
|
+
let error = event.error || new Error(event.message || ERROR_EVENT_TYPE);
|
|
3017
|
+
if (!workerAlive) {
|
|
3018
|
+
error = Object.assign(new Error(error.message || ERROR_EVENT_TYPE), { workerStartupFailed: true });
|
|
3019
|
+
workerData.startupError = error;
|
|
3020
|
+
}
|
|
3008
3021
|
if (rejectResult) {
|
|
3009
|
-
let error = event.error || new Error(event.message || ERROR_EVENT_TYPE);
|
|
3010
|
-
if (!workerAlive) {
|
|
3011
|
-
error = Object.assign(new Error(error.message || ERROR_EVENT_TYPE), { workerStartupFailed: true });
|
|
3012
|
-
}
|
|
3013
3022
|
rejectResult(error);
|
|
3014
3023
|
if (writer) {
|
|
3015
3024
|
writer.releaseLock();
|
|
@@ -3354,8 +3363,10 @@
|
|
|
3354
3363
|
async pull(controller) {
|
|
3355
3364
|
const dataSize = size === UNDEFINED_VALUE ? chunkSize : Math.min(chunkSize, size - chunkOffset);
|
|
3356
3365
|
const data = await readUint8Array(reader, offset + chunkOffset, dataSize);
|
|
3357
|
-
|
|
3358
|
-
|
|
3366
|
+
if (data.length) {
|
|
3367
|
+
controller.enqueue(data);
|
|
3368
|
+
}
|
|
3369
|
+
if ((chunkOffset + chunkSize >= size) || (size === UNDEFINED_VALUE && !data.length && dataSize)) {
|
|
3359
3370
|
controller.close();
|
|
3360
3371
|
} else {
|
|
3361
3372
|
chunkOffset += chunkSize;
|
|
@@ -3433,6 +3444,7 @@
|
|
|
3433
3444
|
constructor(contentType) {
|
|
3434
3445
|
super();
|
|
3435
3446
|
Object.assign(this, {
|
|
3447
|
+
contentType,
|
|
3436
3448
|
data: "data:" + (contentType || "") + ";base64,",
|
|
3437
3449
|
pending: []
|
|
3438
3450
|
});
|
|
@@ -3534,6 +3546,7 @@
|
|
|
3534
3546
|
return transformStream.writable;
|
|
3535
3547
|
}
|
|
3536
3548
|
});
|
|
3549
|
+
writer.contentType = contentType;
|
|
3537
3550
|
writer.blob = streamToBlob(transformStream.readable, contentType);
|
|
3538
3551
|
writer.blob.catch(() => { });
|
|
3539
3552
|
}
|
|
@@ -4034,9 +4047,8 @@
|
|
|
4034
4047
|
|
|
4035
4048
|
async init() {
|
|
4036
4049
|
const reader = this;
|
|
4037
|
-
const { readers } = reader;
|
|
4038
4050
|
reader.lastDiskNumber = 0;
|
|
4039
|
-
await Promise.all(readers.map(
|
|
4051
|
+
const readers = reader.readers = await Promise.all(reader.readers.map(initDiskReader));
|
|
4040
4052
|
reader.diskOffsets = readers.map(diskReader => {
|
|
4041
4053
|
const diskOffset = reader.size;
|
|
4042
4054
|
reader.size += diskReader.size;
|
|
@@ -4213,6 +4225,10 @@
|
|
|
4213
4225
|
}
|
|
4214
4226
|
}
|
|
4215
4227
|
|
|
4228
|
+
function ownsWritable(writer) {
|
|
4229
|
+
return Boolean(writer && writer.getData);
|
|
4230
|
+
}
|
|
4231
|
+
|
|
4216
4232
|
function isHttpFamily(url) {
|
|
4217
4233
|
const { baseURI } = getConfiguration();
|
|
4218
4234
|
const { protocol } = new URL(url, baseURI);
|
|
@@ -4227,6 +4243,16 @@
|
|
|
4227
4243
|
}
|
|
4228
4244
|
}
|
|
4229
4245
|
|
|
4246
|
+
async function initDiskReader(diskReader) {
|
|
4247
|
+
diskReader = new GenericReader(diskReader);
|
|
4248
|
+
await initStream(diskReader);
|
|
4249
|
+
if (diskReader.size === UNDEFINED_VALUE || !diskReader.readUint8Array) {
|
|
4250
|
+
diskReader = new BlobReader(await streamToBlob(diskReader.readable));
|
|
4251
|
+
await initStream(diskReader);
|
|
4252
|
+
}
|
|
4253
|
+
return diskReader;
|
|
4254
|
+
}
|
|
4255
|
+
|
|
4230
4256
|
function readUint8Array(reader, offset, size) {
|
|
4231
4257
|
return reader.readUint8Array(offset, size);
|
|
4232
4258
|
}
|
|
@@ -4357,6 +4383,8 @@
|
|
|
4357
4383
|
const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
|
|
4358
4384
|
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES = "internalFileAttributes";
|
|
4359
4385
|
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttributes";
|
|
4386
|
+
const PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES = "internalFileAttribute";
|
|
4387
|
+
const PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttribute";
|
|
4360
4388
|
const PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW = "msdosAttributesRaw";
|
|
4361
4389
|
const PROPERTY_NAME_MSDOS_ATTRIBUTES = "msdosAttributes";
|
|
4362
4390
|
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
@@ -4367,6 +4395,7 @@
|
|
|
4367
4395
|
const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
|
|
4368
4396
|
const PROPERTY_NAME_DIRECTORY = "directory";
|
|
4369
4397
|
const PROPERTY_NAME_EXECUTABLE = "executable";
|
|
4398
|
+
const PROPERTY_NAME_SYMLINK = "symlink";
|
|
4370
4399
|
const PROPERTY_NAME_COMPRESSION_METHOD = "compressionMethod";
|
|
4371
4400
|
const PROPERTY_NAME_SIGNATURE = "signature";
|
|
4372
4401
|
const PROPERTY_NAME_CRC32 = "crc32";
|
|
@@ -4382,6 +4411,10 @@
|
|
|
4382
4411
|
const PROPERTY_NAME_SETGID = "setgid";
|
|
4383
4412
|
const PROPERTY_NAME_STICKY = "sticky";
|
|
4384
4413
|
const PROPERTY_NAME_BITFLAG = "bitFlag";
|
|
4414
|
+
const PROPERTY_NAME_RAW_BITFLAG = "rawBitFlag";
|
|
4415
|
+
const PROPERTY_NAME_FILENAME_LENGTH = "filenameLength";
|
|
4416
|
+
const PROPERTY_NAME_EXTRA_FIELD_LENGTH = "extraFieldLength";
|
|
4417
|
+
const PROPERTY_NAME_UNIX_EXTERNAL_UPPER = "unixExternalUpper";
|
|
4385
4418
|
const PROPERTY_NAME_FILENAME_UTF8 = "filenameUTF8";
|
|
4386
4419
|
const PROPERTY_NAME_COMMENT_UTF8 = "commentUTF8";
|
|
4387
4420
|
const PROPERTY_NAME_RAW_EXTRA_FIELD = "rawExtraField";
|
|
@@ -4410,6 +4443,8 @@
|
|
|
4410
4443
|
PROPERTY_NAME_DISK_NUMBER_START,
|
|
4411
4444
|
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
|
|
4412
4445
|
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
|
|
4446
|
+
PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES,
|
|
4447
|
+
PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES,
|
|
4413
4448
|
PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW,
|
|
4414
4449
|
PROPERTY_NAME_MSDOS_ATTRIBUTES,
|
|
4415
4450
|
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
@@ -4420,6 +4455,7 @@
|
|
|
4420
4455
|
PROPERTY_NAME_ZIPCRYPTO,
|
|
4421
4456
|
PROPERTY_NAME_DIRECTORY,
|
|
4422
4457
|
PROPERTY_NAME_EXECUTABLE,
|
|
4458
|
+
PROPERTY_NAME_SYMLINK,
|
|
4423
4459
|
PROPERTY_NAME_COMPRESSION_METHOD,
|
|
4424
4460
|
PROPERTY_NAME_SIGNATURE,
|
|
4425
4461
|
PROPERTY_NAME_CRC32,
|
|
@@ -4431,10 +4467,14 @@
|
|
|
4431
4467
|
PROPERTY_NAME_UID,
|
|
4432
4468
|
PROPERTY_NAME_GID,
|
|
4433
4469
|
PROPERTY_NAME_UNIX_MODE,
|
|
4470
|
+
PROPERTY_NAME_UNIX_EXTERNAL_UPPER,
|
|
4434
4471
|
PROPERTY_NAME_SETUID,
|
|
4435
4472
|
PROPERTY_NAME_SETGID,
|
|
4436
4473
|
PROPERTY_NAME_STICKY,
|
|
4437
4474
|
PROPERTY_NAME_BITFLAG,
|
|
4475
|
+
PROPERTY_NAME_RAW_BITFLAG,
|
|
4476
|
+
PROPERTY_NAME_FILENAME_LENGTH,
|
|
4477
|
+
PROPERTY_NAME_EXTRA_FIELD_LENGTH,
|
|
4438
4478
|
PROPERTY_NAME_FILENAME_UTF8,
|
|
4439
4479
|
PROPERTY_NAME_COMMENT_UTF8,
|
|
4440
4480
|
PROPERTY_NAME_RAW_EXTRA_FIELD,
|
|
@@ -4496,6 +4536,7 @@
|
|
|
4496
4536
|
const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
|
|
4497
4537
|
const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
|
|
4498
4538
|
const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
|
|
4539
|
+
const OPTION_CHECK_LOCAL_DIRECTORY = "checkLocalDirectory";
|
|
4499
4540
|
const OPTION_CHECK_SIGNATURE = "checkSignature";
|
|
4500
4541
|
const OPTION_CHECK_CRC32 = "checkCrc32";
|
|
4501
4542
|
const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
|
|
@@ -4627,7 +4668,7 @@
|
|
|
4627
4668
|
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
4628
4669
|
throw new Error(ERR_BAD_FORMAT);
|
|
4629
4670
|
}
|
|
4630
|
-
const strictness = getStrictness(
|
|
4671
|
+
const strictness = getStrictness(options, zipReader.options);
|
|
4631
4672
|
const checkAmbiguity = strictness == STRICTNESS_STRICT;
|
|
4632
4673
|
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
4633
4674
|
const maxAppendedDataSize = getMaxAppendedDataSize(getOptionValue$1(zipReader, options, OPTION_MAX_APPENDED_DATA_SIZE), strictness);
|
|
@@ -4849,6 +4890,7 @@
|
|
|
4849
4890
|
index: indexFile,
|
|
4850
4891
|
versionMadeBy,
|
|
4851
4892
|
msDosCompatible,
|
|
4893
|
+
zip64: false,
|
|
4852
4894
|
compressedSize: 0,
|
|
4853
4895
|
uncompressedSize: 0,
|
|
4854
4896
|
commentLength,
|
|
@@ -4882,15 +4924,18 @@
|
|
|
4882
4924
|
const setuid = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_SETUID_MASK);
|
|
4883
4925
|
const setgid = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_SETGID_MASK);
|
|
4884
4926
|
const sticky = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_STICKY_MASK);
|
|
4885
|
-
const
|
|
4927
|
+
const unixType = fileEntry.unixMode === UNDEFINED_VALUE ? unixExternalUpper : fileEntry.unixMode;
|
|
4928
|
+
const symlink = (unixType & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_SYMLINK;
|
|
4929
|
+
const executable = !symlink && ((fileEntry.unixMode !== UNDEFINED_VALUE)
|
|
4886
4930
|
? ((fileEntry.unixMode & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)
|
|
4887
|
-
: (unixCompatible && ((unixExternalUpper & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0));
|
|
4931
|
+
: (unixCompatible && ((unixExternalUpper & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)));
|
|
4888
4932
|
const modeIsDir = fileEntry.unixMode !== UNDEFINED_VALUE && ((fileEntry.unixMode & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR);
|
|
4889
4933
|
const upperIsDir = ((unixExternalUpper & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR);
|
|
4890
4934
|
Object.assign(fileEntry, {
|
|
4891
4935
|
setuid,
|
|
4892
4936
|
setgid,
|
|
4893
4937
|
sticky,
|
|
4938
|
+
symlink,
|
|
4894
4939
|
unixExternalUpper,
|
|
4895
4940
|
internalFileAttribute: fileEntry.internalFileAttributes,
|
|
4896
4941
|
externalFileAttribute: fileEntry.externalFileAttributes,
|
|
@@ -4956,6 +5001,10 @@
|
|
|
4956
5001
|
}
|
|
4957
5002
|
|
|
4958
5003
|
async close() {
|
|
5004
|
+
const { reader } = this;
|
|
5005
|
+
if (!reader.readUint8Array && reader.readable && !reader.readable.locked) {
|
|
5006
|
+
await reader.readable.cancel();
|
|
5007
|
+
}
|
|
4959
5008
|
}
|
|
4960
5009
|
}
|
|
4961
5010
|
|
|
@@ -5052,9 +5101,12 @@
|
|
|
5052
5101
|
extraFieldLength,
|
|
5053
5102
|
filenameLength
|
|
5054
5103
|
} = localDirectory;
|
|
5055
|
-
const
|
|
5104
|
+
const checkLocalDirectoryOption = getOptionValue$1(zipEntry, options, OPTION_CHECK_LOCAL_DIRECTORY);
|
|
5105
|
+
const entryStrictness = getStrictness(options, zipEntry.options);
|
|
5106
|
+
const checkLocalDirectory = getCheckLocalDirectory(checkLocalDirectoryOption, entryStrictness);
|
|
5107
|
+
const checkLocalFilename = getCheckLocalFilename(checkLocalDirectoryOption, entryStrictness);
|
|
5056
5108
|
let rawLocalFilename = EMPTY_UINT8_ARRAY;
|
|
5057
|
-
if (
|
|
5109
|
+
if (checkLocalFilename && (filenameLength || extraFieldLength)) {
|
|
5058
5110
|
const trailingDataArray = await readUint8Array(reader, localHeaderOffset + HEADER_SIZE, filenameLength + extraFieldLength);
|
|
5059
5111
|
rawLocalFilename = trailingDataArray.subarray(0, filenameLength);
|
|
5060
5112
|
localDirectory.rawExtraField = trailingDataArray.subarray(filenameLength);
|
|
@@ -5063,17 +5115,26 @@
|
|
|
5063
5115
|
await readUint8Array(reader, localHeaderOffset + HEADER_SIZE + filenameLength, extraFieldLength) :
|
|
5064
5116
|
EMPTY_UINT8_ARRAY;
|
|
5065
5117
|
}
|
|
5118
|
+
if (checkLocalFilename) {
|
|
5119
|
+
localDirectory.rawFilename = rawLocalFilename;
|
|
5120
|
+
}
|
|
5066
5121
|
readCommonFooter(zipEntry, localDirectory, dataView, 4, true);
|
|
5067
|
-
if (
|
|
5068
|
-
|
|
5122
|
+
if (checkLocalDirectory) {
|
|
5123
|
+
validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename);
|
|
5069
5124
|
}
|
|
5070
|
-
const { lastAccessDate, creationDate } = localDirectory;
|
|
5125
|
+
const { lastAccessDate, creationDate, uid, gid } = localDirectory;
|
|
5071
5126
|
if (lastAccessDate) {
|
|
5072
5127
|
fileEntry.lastAccessDate = lastAccessDate;
|
|
5073
5128
|
}
|
|
5074
5129
|
if (creationDate) {
|
|
5075
5130
|
fileEntry.creationDate = creationDate;
|
|
5076
5131
|
}
|
|
5132
|
+
if (uid !== UNDEFINED_VALUE && fileEntry.uid === UNDEFINED_VALUE) {
|
|
5133
|
+
fileEntry.uid = uid;
|
|
5134
|
+
}
|
|
5135
|
+
if (gid !== UNDEFINED_VALUE && fileEntry.gid === UNDEFINED_VALUE) {
|
|
5136
|
+
fileEntry.gid = gid;
|
|
5137
|
+
}
|
|
5077
5138
|
const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
|
|
5078
5139
|
const zipCrypto = encrypted && !extraFieldAES;
|
|
5079
5140
|
if (!passThrough) {
|
|
@@ -5180,7 +5241,7 @@
|
|
|
5180
5241
|
throw error;
|
|
5181
5242
|
}
|
|
5182
5243
|
} finally {
|
|
5183
|
-
const preventClose = getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5244
|
+
const preventClose = !ownsWritable(writer) && getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5184
5245
|
if (!preventClose && writable && !writable.locked) {
|
|
5185
5246
|
const writableWriter = writable.getWriter();
|
|
5186
5247
|
if (abortError) {
|
|
@@ -5309,10 +5370,12 @@
|
|
|
5309
5370
|
directory.extraFieldNTFS = extraFieldNTFS;
|
|
5310
5371
|
}
|
|
5311
5372
|
const extraFieldUnix = extraField.get(EXTRAFIELD_TYPE_UNIX);
|
|
5373
|
+
let unixIdsRead;
|
|
5312
5374
|
if (extraFieldUnix) {
|
|
5313
|
-
readExtraFieldUnix(extraFieldUnix, directory, false);
|
|
5375
|
+
unixIdsRead = readExtraFieldUnix(extraFieldUnix, directory, false);
|
|
5314
5376
|
directory.extraFieldUnix = extraFieldUnix;
|
|
5315
|
-
}
|
|
5377
|
+
}
|
|
5378
|
+
if (!unixIdsRead) {
|
|
5316
5379
|
const extraFieldInfoZip = extraField.get(EXTRAFIELD_TYPE_INFOZIP);
|
|
5317
5380
|
if (extraFieldInfoZip) {
|
|
5318
5381
|
readExtraFieldUnix(extraFieldInfoZip, directory, true);
|
|
@@ -5415,7 +5478,7 @@
|
|
|
5415
5478
|
const creationDate = getDateNTFS(rawCreationDate);
|
|
5416
5479
|
const extraFieldData = { lastModDate, lastAccessDate, creationDate };
|
|
5417
5480
|
Object.assign(extraFieldNTFS, extraFieldData);
|
|
5418
|
-
Object.assign(directory, extraFieldData);
|
|
5481
|
+
Object.assign(directory, extraFieldData, { rawLastAccessDate, rawCreationDate });
|
|
5419
5482
|
}
|
|
5420
5483
|
}
|
|
5421
5484
|
|
|
@@ -5424,8 +5487,8 @@
|
|
|
5424
5487
|
return;
|
|
5425
5488
|
}
|
|
5426
5489
|
const extraFieldView = getDataView(extraField.data);
|
|
5427
|
-
const lastAccessDate = new Date(getUint32(extraFieldView, 0) * 1000);
|
|
5428
|
-
const lastModDate = new Date(getUint32(extraFieldView, 4) * 1000);
|
|
5490
|
+
const lastAccessDate = new Date((getUint32(extraFieldView, 0) | 0) * 1000);
|
|
5491
|
+
const lastModDate = new Date((getUint32(extraFieldView, 4) | 0) * 1000);
|
|
5429
5492
|
const extraFieldData = { lastAccessDate, lastModDate };
|
|
5430
5493
|
if (extraField.data.length >= 12) {
|
|
5431
5494
|
extraFieldData.uid = getUint16(extraFieldView, 8);
|
|
@@ -5459,6 +5522,7 @@
|
|
|
5459
5522
|
if (gid !== UNDEFINED_VALUE) {
|
|
5460
5523
|
directory.gid = gid;
|
|
5461
5524
|
}
|
|
5525
|
+
return uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE;
|
|
5462
5526
|
} catch {
|
|
5463
5527
|
// ignored
|
|
5464
5528
|
}
|
|
@@ -5531,26 +5595,25 @@
|
|
|
5531
5595
|
}
|
|
5532
5596
|
if (dataDescriptorLength) {
|
|
5533
5597
|
const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
|
|
5534
|
-
const
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
if (extraFieldZip64) {
|
|
5541
|
-
readCompressedSize = getBigUint64(getDataView(dataDescriptorArray), 8);
|
|
5542
|
-
readUncompressedSize = getBigUint64(getDataView(dataDescriptorArray), 16);
|
|
5543
|
-
} else {
|
|
5544
|
-
readCompressedSize = getUint32(getDataView(dataDescriptorArray), 8);
|
|
5545
|
-
readUncompressedSize = getUint32(getDataView(dataDescriptorArray), 12);
|
|
5546
|
-
}
|
|
5547
|
-
const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || readCrc32 == crc32;
|
|
5598
|
+
const dataDescriptorView = getDataView(dataDescriptorArray);
|
|
5599
|
+
let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
|
|
5600
|
+
getUint32(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
|
|
5601
|
+
if (signature) {
|
|
5602
|
+
const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
|
|
5603
|
+
const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
|
|
5548
5604
|
if (matchCrc32 &&
|
|
5549
|
-
|
|
5550
|
-
|
|
5605
|
+
signedDataDescriptor.compressedSize == compressedSize &&
|
|
5606
|
+
signedDataDescriptor.uncompressedSize == uncompressedSize) {
|
|
5551
5607
|
dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
|
|
5608
|
+
} else {
|
|
5609
|
+
signature = false;
|
|
5552
5610
|
}
|
|
5553
5611
|
}
|
|
5612
|
+
if (dataDescriptorArray.length >= dataDescriptorLength) {
|
|
5613
|
+
const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
|
|
5614
|
+
localDataDescriptor.signature = signature;
|
|
5615
|
+
fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
|
|
5616
|
+
}
|
|
5554
5617
|
}
|
|
5555
5618
|
const range = {
|
|
5556
5619
|
start: offset,
|
|
@@ -5567,6 +5630,20 @@
|
|
|
5567
5630
|
readRanges.set(index, range);
|
|
5568
5631
|
}
|
|
5569
5632
|
|
|
5633
|
+
function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
|
|
5634
|
+
const crc32 = getUint32(dataDescriptorView, offset);
|
|
5635
|
+
let compressedSize;
|
|
5636
|
+
let uncompressedSize;
|
|
5637
|
+
if (extraFieldZip64) {
|
|
5638
|
+
compressedSize = getBigUint64(dataDescriptorView, offset + 4);
|
|
5639
|
+
uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
|
|
5640
|
+
} else {
|
|
5641
|
+
compressedSize = getUint32(dataDescriptorView, offset + 4);
|
|
5642
|
+
uncompressedSize = getUint32(dataDescriptorView, offset + 8);
|
|
5643
|
+
}
|
|
5644
|
+
return { crc32, compressedSize, uncompressedSize };
|
|
5645
|
+
}
|
|
5646
|
+
|
|
5570
5647
|
function getDiskOffset$1(reader, diskNumber) {
|
|
5571
5648
|
return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
|
|
5572
5649
|
}
|
|
@@ -5575,14 +5652,40 @@
|
|
|
5575
5652
|
return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
|
|
5576
5653
|
}
|
|
5577
5654
|
|
|
5578
|
-
function getStrictness(
|
|
5579
|
-
|
|
5580
|
-
|
|
5655
|
+
function getStrictness(options, inheritedOptions) {
|
|
5656
|
+
return resolveStrictness(options, resolveStrictness(inheritedOptions, STRICTNESS_BALANCED));
|
|
5657
|
+
}
|
|
5658
|
+
|
|
5659
|
+
function resolveStrictness(options, inheritedStrictness) {
|
|
5660
|
+
const strictness = options[OPTION_STRICTNESS];
|
|
5661
|
+
if (strictness !== UNDEFINED_VALUE) {
|
|
5662
|
+
if (!isStrictnessValue(strictness)) {
|
|
5663
|
+
throw new Error(ERR_INVALID_STRICTNESS);
|
|
5664
|
+
}
|
|
5665
|
+
return strictness;
|
|
5581
5666
|
}
|
|
5582
|
-
|
|
5583
|
-
|
|
5667
|
+
const checkAmbiguity = options[OPTION_CHECK_AMBIGUITY];
|
|
5668
|
+
if (checkAmbiguity === UNDEFINED_VALUE) {
|
|
5669
|
+
return inheritedStrictness;
|
|
5670
|
+
}
|
|
5671
|
+
if (checkAmbiguity) {
|
|
5672
|
+
return STRICTNESS_STRICT;
|
|
5673
|
+
}
|
|
5674
|
+
return inheritedStrictness == STRICTNESS_TOLERANT ? STRICTNESS_TOLERANT : STRICTNESS_BALANCED;
|
|
5675
|
+
}
|
|
5676
|
+
|
|
5677
|
+
function getCheckLocalDirectory(checkLocalDirectory, strictness) {
|
|
5678
|
+
if (checkLocalDirectory === UNDEFINED_VALUE) {
|
|
5679
|
+
return strictness != STRICTNESS_TOLERANT;
|
|
5584
5680
|
}
|
|
5585
|
-
return
|
|
5681
|
+
return Boolean(checkLocalDirectory);
|
|
5682
|
+
}
|
|
5683
|
+
|
|
5684
|
+
function getCheckLocalFilename(checkLocalFilename, strictness) {
|
|
5685
|
+
if (checkLocalFilename === UNDEFINED_VALUE) {
|
|
5686
|
+
return strictness == STRICTNESS_STRICT;
|
|
5687
|
+
}
|
|
5688
|
+
return Boolean(checkLocalFilename);
|
|
5586
5689
|
}
|
|
5587
5690
|
|
|
5588
5691
|
function getFilenameValidation(filenameValidation, strictness) {
|
|
@@ -5730,10 +5833,11 @@
|
|
|
5730
5833
|
return UNDEFINED_VALUE;
|
|
5731
5834
|
}
|
|
5732
5835
|
|
|
5733
|
-
function
|
|
5836
|
+
function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
|
|
5734
5837
|
const { rawFilename } = zipEntry;
|
|
5735
|
-
if (
|
|
5736
|
-
rawLocalFilename.
|
|
5838
|
+
if (checkLocalFilename &&
|
|
5839
|
+
(rawLocalFilename.length != rawFilename.length ||
|
|
5840
|
+
rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
|
|
5737
5841
|
throwAmbiguousArchive("mismatched local file header (filename)");
|
|
5738
5842
|
}
|
|
5739
5843
|
if ((localDirectory.rawBitFlag & BITFLAG_AMBIGUITY_MASK) != (zipEntry.rawBitFlag & BITFLAG_AMBIGUITY_MASK)) {
|
|
@@ -5851,11 +5955,13 @@
|
|
|
5851
5955
|
|
|
5852
5956
|
const ERR_DUPLICATED_NAME = "File already exists";
|
|
5853
5957
|
const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
|
|
5958
|
+
const ERR_INVALID_COMMENT_TYPE = "Invalid zip file comment (must be a Uint8Array)";
|
|
5854
5959
|
const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
|
|
5855
5960
|
const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
|
|
5856
5961
|
const ERR_INVALID_VERSION = "Version exceeds 65535";
|
|
5857
5962
|
const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
|
|
5858
5963
|
const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
|
|
5964
|
+
const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
|
|
5859
5965
|
const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
|
|
5860
5966
|
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
5861
5967
|
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
@@ -5865,6 +5971,7 @@
|
|
|
5865
5971
|
const MAX_NTFS_TIME = BigInt("0x7fffffffffffffff");
|
|
5866
5972
|
const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
|
|
5867
5973
|
const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
|
|
5974
|
+
const ERR_UNDETERMINED_SIZE = "Undetermined size";
|
|
5868
5975
|
const ERR_UNDEFINED_READER = "Undefined reader";
|
|
5869
5976
|
const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
|
|
5870
5977
|
const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
|
|
@@ -5917,6 +6024,10 @@
|
|
|
5917
6024
|
}
|
|
5918
6025
|
reader = new GenericReader(reader);
|
|
5919
6026
|
await initStream(reader);
|
|
6027
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
6028
|
+
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
6029
|
+
await initStream(reader);
|
|
6030
|
+
}
|
|
5920
6031
|
const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
|
|
5921
6032
|
const zipReader$1 = new ZipReader(reader.readable);
|
|
5922
6033
|
const entries = await zipReader$1.getEntries();
|
|
@@ -6065,6 +6176,9 @@
|
|
|
6065
6176
|
const zipWriter = this;
|
|
6066
6177
|
const { pendingAddFileCalls, writer } = this;
|
|
6067
6178
|
const { writable } = writer;
|
|
6179
|
+
if (!(comment instanceof Uint8Array)) {
|
|
6180
|
+
throw new Error(ERR_INVALID_COMMENT_TYPE);
|
|
6181
|
+
}
|
|
6068
6182
|
if (getLength(comment) > MAX_16_BITS) {
|
|
6069
6183
|
throw new Error(ERR_INVALID_COMMENT);
|
|
6070
6184
|
}
|
|
@@ -6072,7 +6186,7 @@
|
|
|
6072
6186
|
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6073
6187
|
}
|
|
6074
6188
|
await closeFile(zipWriter, comment, options);
|
|
6075
|
-
const preventClose = getOptionValue(zipWriter, options, OPTION_PREVENT_CLOSE);
|
|
6189
|
+
const preventClose = !ownsWritable(writer) && getOptionValue(zipWriter, options, OPTION_PREVENT_CLOSE);
|
|
6076
6190
|
if (!preventClose) {
|
|
6077
6191
|
await writable.getWriter().close();
|
|
6078
6192
|
}
|
|
@@ -6161,8 +6275,6 @@
|
|
|
6161
6275
|
const diskOffset = getDiskOffset(zipWriter.writer);
|
|
6162
6276
|
const diskNumber = getDiskNumber(zipWriter.writer);
|
|
6163
6277
|
options = Object.assign({}, options, attributesInfo.resolvedOptions, metadataInfo.resolvedOptions, sizesInfo.resolvedOptions, {
|
|
6164
|
-
internalFileAttribute: metadataInfo.resolvedOptions.internalFileAttributes,
|
|
6165
|
-
externalFileAttribute: attributesInfo.resolvedOptions.externalFileAttributes,
|
|
6166
6278
|
signature: options[PROPERTY_NAME_SIGNATURE],
|
|
6167
6279
|
crc32: options.crc32 === UNDEFINED_VALUE ? options[PROPERTY_NAME_SIGNATURE] : options.crc32,
|
|
6168
6280
|
offset: zipWriter.offset - diskOffset,
|
|
@@ -6176,14 +6288,20 @@
|
|
|
6176
6288
|
zipWriter.files.delete(name);
|
|
6177
6289
|
throw error;
|
|
6178
6290
|
}
|
|
6179
|
-
Object.assign(fileEntry, {
|
|
6291
|
+
Object.assign(fileEntry, {
|
|
6292
|
+
name,
|
|
6293
|
+
comment,
|
|
6294
|
+
extraField,
|
|
6295
|
+
[PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES]: fileEntry.internalFileAttributes,
|
|
6296
|
+
[PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES]: fileEntry.externalFileAttributes
|
|
6297
|
+
});
|
|
6180
6298
|
return new Entry(fileEntry);
|
|
6181
6299
|
}
|
|
6182
6300
|
|
|
6183
6301
|
function resolveAttributes(zipWriter, name, options) {
|
|
6184
6302
|
name = name.trim();
|
|
6185
6303
|
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
6186
|
-
let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ?
|
|
6304
|
+
let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? VERSION_MADE_BY_MSDOS : VERSION_MADE_BY_UNIX);
|
|
6187
6305
|
const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
|
|
6188
6306
|
const uid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UID);
|
|
6189
6307
|
const gid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_GID);
|
|
@@ -6217,7 +6335,7 @@
|
|
|
6217
6335
|
const hasMsDosProvided = msdosAttributesRaw !== UNDEFINED_VALUE || msdosAttributes !== UNDEFINED_VALUE;
|
|
6218
6336
|
if (hasUnixMetadata) {
|
|
6219
6337
|
msDosCompatible = false;
|
|
6220
|
-
versionMadeBy = (versionMadeBy &
|
|
6338
|
+
versionMadeBy = (versionMadeBy & MAX_8_BITS) | VERSION_MADE_BY_UNIX;
|
|
6221
6339
|
} else if (hasMsDosProvided) {
|
|
6222
6340
|
msDosCompatible = true;
|
|
6223
6341
|
versionMadeBy = (versionMadeBy & MAX_8_BITS);
|
|
@@ -6231,7 +6349,7 @@
|
|
|
6231
6349
|
if (versionMadeBy > MAX_16_BITS) {
|
|
6232
6350
|
throw new Error(ERR_INVALID_VERSION);
|
|
6233
6351
|
}
|
|
6234
|
-
let externalFileAttributes =
|
|
6352
|
+
let externalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES);
|
|
6235
6353
|
const externalFileAttributesProvided = externalFileAttributes !== UNDEFINED_VALUE;
|
|
6236
6354
|
if (!externalFileAttributesProvided) {
|
|
6237
6355
|
externalFileAttributes = 0;
|
|
@@ -6257,11 +6375,10 @@
|
|
|
6257
6375
|
externalFileAttributes = FILE_ATTR_UNIX_DEFAULT_MASK << 16;
|
|
6258
6376
|
}
|
|
6259
6377
|
}
|
|
6260
|
-
let unixExternalUpper;
|
|
6261
6378
|
if (!msDosCompatible) {
|
|
6262
6379
|
const unixModeProvided = unixMode !== UNDEFINED_VALUE || Boolean(setuid || setgid || sticky);
|
|
6263
|
-
|
|
6264
|
-
unixMode = unixMode === UNDEFINED_VALUE ?
|
|
6380
|
+
const defaultUnixMode = (externalFileAttributes >> 16) & MAX_16_BITS;
|
|
6381
|
+
unixMode = unixMode === UNDEFINED_VALUE ? defaultUnixMode : (unixMode & MAX_16_BITS);
|
|
6265
6382
|
if (setuid) {
|
|
6266
6383
|
unixMode |= FILE_ATTR_UNIX_SETUID_MASK;
|
|
6267
6384
|
} else {
|
|
@@ -6279,7 +6396,9 @@
|
|
|
6279
6396
|
}
|
|
6280
6397
|
if (!externalFileAttributesProvided || unixModeProvided) {
|
|
6281
6398
|
if (directory) {
|
|
6282
|
-
unixMode
|
|
6399
|
+
unixMode = (unixMode & ~FILE_ATTR_UNIX_TYPE_MASK) | FILE_ATTR_UNIX_TYPE_DIR;
|
|
6400
|
+
} else if (!(unixMode & FILE_ATTR_UNIX_TYPE_MASK)) {
|
|
6401
|
+
unixMode |= FILE_ATTR_UNIX_TYPE_FILE;
|
|
6283
6402
|
}
|
|
6284
6403
|
externalFileAttributes = ((unixMode & MAX_16_BITS) << 16) | (externalFileAttributes & MAX_16_BITS);
|
|
6285
6404
|
}
|
|
@@ -6288,17 +6407,20 @@
|
|
|
6288
6407
|
if (hasMsDosProvided) {
|
|
6289
6408
|
externalFileAttributes = (externalFileAttributes & MAX_32_BITS) | (msdosAttributesRaw & MAX_8_BITS);
|
|
6290
6409
|
}
|
|
6410
|
+
const unixExternalUpper = (externalFileAttributes >> 16) & MAX_16_BITS;
|
|
6411
|
+
const symlink = unixMode !== UNDEFINED_VALUE && ((unixMode & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_SYMLINK);
|
|
6291
6412
|
return {
|
|
6292
6413
|
name,
|
|
6293
6414
|
resolvedOptions: {
|
|
6294
6415
|
versionMadeBy,
|
|
6295
|
-
msDosCompatible,
|
|
6416
|
+
msDosCompatible: Boolean(msDosCompatible),
|
|
6296
6417
|
externalFileAttributes,
|
|
6297
6418
|
unixExternalUpper,
|
|
6298
6419
|
uid,
|
|
6299
6420
|
gid,
|
|
6300
6421
|
unixMode,
|
|
6301
6422
|
unixExtraFieldType,
|
|
6423
|
+
symlink,
|
|
6302
6424
|
setuid,
|
|
6303
6425
|
setgid,
|
|
6304
6426
|
sticky,
|
|
@@ -6332,15 +6454,12 @@
|
|
|
6332
6454
|
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
|
|
6333
6455
|
const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
6334
6456
|
const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
6335
|
-
const internalFileAttributes =
|
|
6457
|
+
const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
|
|
6336
6458
|
const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
|
|
6342
|
-
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
6343
|
-
}
|
|
6459
|
+
const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
6460
|
+
const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
6461
|
+
if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
|
|
6462
|
+
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
6344
6463
|
}
|
|
6345
6464
|
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
6346
6465
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
@@ -6453,14 +6572,24 @@
|
|
|
6453
6572
|
}
|
|
6454
6573
|
|
|
6455
6574
|
async function resolveSizes(zipWriter, reader, { resolvedOptions: metadata }, options) {
|
|
6575
|
+
if (metadata.passThrough && !reader && !getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY)) {
|
|
6576
|
+
throw new Error(ERR_UNDEFINED_READER);
|
|
6577
|
+
}
|
|
6578
|
+
let contentSize;
|
|
6579
|
+
if (reader) {
|
|
6580
|
+
reader = new GenericReader(reader);
|
|
6581
|
+
await initStream(reader);
|
|
6582
|
+
({ size: contentSize } = reader);
|
|
6583
|
+
}
|
|
6584
|
+
return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
|
|
6585
|
+
}
|
|
6586
|
+
|
|
6587
|
+
function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options) {
|
|
6456
6588
|
const { passThrough, zipCrypto, password, rawPassword, encryptionStrength } = metadata;
|
|
6457
6589
|
let { dataDescriptor, zip64, level, compressionMethod } = metadata;
|
|
6458
6590
|
let maximumCompressedSize = 0;
|
|
6459
6591
|
let uncompressedSize = 0;
|
|
6460
|
-
if (passThrough) {
|
|
6461
|
-
if (!reader) {
|
|
6462
|
-
throw new Error(ERR_UNDEFINED_READER);
|
|
6463
|
-
}
|
|
6592
|
+
if (passThrough && hasContent) {
|
|
6464
6593
|
uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
|
|
6465
6594
|
if (uncompressedSize === UNDEFINED_VALUE) {
|
|
6466
6595
|
throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
|
|
@@ -6468,29 +6597,30 @@
|
|
|
6468
6597
|
}
|
|
6469
6598
|
const zip64Enabled = zip64 === true;
|
|
6470
6599
|
const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
|
|
6471
|
-
|
|
6472
|
-
|
|
6600
|
+
if (hasContent && passThrough && !encrypted && getLength(password, rawPassword)) {
|
|
6601
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH);
|
|
6602
|
+
}
|
|
6603
|
+
const encryptedEntry = hasContent && (Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted));
|
|
6604
|
+
if (!hasContent) {
|
|
6473
6605
|
level = 0;
|
|
6474
6606
|
compressionMethod = COMPRESSION_METHOD_STORE;
|
|
6475
6607
|
}
|
|
6476
6608
|
const encryptionOverhead = encryptedEntry ? (zipCrypto ? 12 : 16 + encryptionStrength * 4) : 0;
|
|
6477
|
-
if (
|
|
6478
|
-
reader = new GenericReader(reader);
|
|
6479
|
-
await initStream(reader);
|
|
6609
|
+
if (hasContent) {
|
|
6480
6610
|
if (!passThrough) {
|
|
6481
|
-
if (
|
|
6611
|
+
if (contentSize === UNDEFINED_VALUE) {
|
|
6482
6612
|
dataDescriptor = true;
|
|
6483
6613
|
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
6484
6614
|
zip64 = true;
|
|
6485
6615
|
uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
|
|
6486
6616
|
}
|
|
6487
6617
|
} else {
|
|
6488
|
-
options.uncompressedSize = uncompressedSize =
|
|
6489
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize) + encryptionOverhead;
|
|
6618
|
+
options.uncompressedSize = uncompressedSize = contentSize;
|
|
6619
|
+
maximumCompressedSize = (isCompressed(compressionMethod, level) ? getMaximumCompressedSize(uncompressedSize) : uncompressedSize) + encryptionOverhead;
|
|
6490
6620
|
}
|
|
6491
6621
|
} else {
|
|
6492
6622
|
options.uncompressedSize = uncompressedSize;
|
|
6493
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize) + encryptionOverhead;
|
|
6623
|
+
maximumCompressedSize = contentSize === UNDEFINED_VALUE ? getMaximumCompressedSize(uncompressedSize) + encryptionOverhead : contentSize;
|
|
6494
6624
|
}
|
|
6495
6625
|
}
|
|
6496
6626
|
const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
|
|
@@ -6504,7 +6634,7 @@
|
|
|
6504
6634
|
}
|
|
6505
6635
|
zip64 = zip64 || false;
|
|
6506
6636
|
return {
|
|
6507
|
-
|
|
6637
|
+
maximumCompressedSize,
|
|
6508
6638
|
resolvedOptions: {
|
|
6509
6639
|
dataDescriptor,
|
|
6510
6640
|
zip64,
|
|
@@ -6732,6 +6862,7 @@
|
|
|
6732
6862
|
uid,
|
|
6733
6863
|
gid,
|
|
6734
6864
|
unixMode,
|
|
6865
|
+
symlink,
|
|
6735
6866
|
setuid,
|
|
6736
6867
|
setgid,
|
|
6737
6868
|
sticky,
|
|
@@ -6768,6 +6899,7 @@
|
|
|
6768
6899
|
uid,
|
|
6769
6900
|
gid,
|
|
6770
6901
|
unixMode,
|
|
6902
|
+
symlink: Boolean(symlink),
|
|
6771
6903
|
setuid,
|
|
6772
6904
|
setgid,
|
|
6773
6905
|
sticky,
|
|
@@ -6848,8 +6980,8 @@
|
|
|
6848
6980
|
rawLastModDate,
|
|
6849
6981
|
creationDate,
|
|
6850
6982
|
lastAccessDate,
|
|
6851
|
-
encrypted,
|
|
6852
|
-
zipCrypto,
|
|
6983
|
+
encrypted: Boolean(encrypted),
|
|
6984
|
+
zipCrypto: Boolean(zipCrypto),
|
|
6853
6985
|
size: metadataSize + compressedSize,
|
|
6854
6986
|
compressionMethod,
|
|
6855
6987
|
version,
|
|
@@ -6889,9 +7021,7 @@
|
|
|
6889
7021
|
crc32
|
|
6890
7022
|
} = options;
|
|
6891
7023
|
let { version, compressionMethod } = options;
|
|
6892
|
-
const compressed = !directory && (compressionMethod
|
|
6893
|
-
? (level === UNDEFINED_VALUE || level > 0)
|
|
6894
|
-
: compressionMethod !== COMPRESSION_METHOD_STORE);
|
|
7024
|
+
const compressed = !directory && isCompressed(compressionMethod, level);
|
|
6895
7025
|
let rawLocalExtraFieldZip64;
|
|
6896
7026
|
const uncompressedFile = passThrough || !compressed;
|
|
6897
7027
|
const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
|
|
@@ -7578,6 +7708,16 @@
|
|
|
7578
7708
|
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7579
7709
|
}
|
|
7580
7710
|
|
|
7711
|
+
function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
|
|
7712
|
+
const value = getAliasedValue(options, name, deprecatedName);
|
|
7713
|
+
const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
|
|
7714
|
+
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7715
|
+
}
|
|
7716
|
+
|
|
7717
|
+
function getAliasedValue(options, name, deprecatedName) {
|
|
7718
|
+
return options[name] === UNDEFINED_VALUE ? options[deprecatedName] : options[name];
|
|
7719
|
+
}
|
|
7720
|
+
|
|
7581
7721
|
function getNumberOptionValue(zipWriter, options, name, defaultValue) {
|
|
7582
7722
|
return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
|
|
7583
7723
|
}
|
|
@@ -7590,6 +7730,12 @@
|
|
|
7590
7730
|
return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
|
|
7591
7731
|
}
|
|
7592
7732
|
|
|
7733
|
+
function isCompressed(compressionMethod, level) {
|
|
7734
|
+
return compressionMethod === UNDEFINED_VALUE
|
|
7735
|
+
? (level === UNDEFINED_VALUE || level > 0)
|
|
7736
|
+
: compressionMethod !== COMPRESSION_METHOD_STORE;
|
|
7737
|
+
}
|
|
7738
|
+
|
|
7593
7739
|
function setUint8(view, offset, value) {
|
|
7594
7740
|
view.setUint8(offset, value);
|
|
7595
7741
|
}
|
|
@@ -8622,6 +8768,7 @@
|
|
|
8622
8768
|
exports.ERR_INVALID_CODEC_DEFINITION = ERR_INVALID_CODEC_DEFINITION;
|
|
8623
8769
|
exports.ERR_INVALID_CODEC_MODULE = ERR_INVALID_CODEC_MODULE;
|
|
8624
8770
|
exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
|
|
8771
|
+
exports.ERR_INVALID_COMMENT_TYPE = ERR_INVALID_COMMENT_TYPE;
|
|
8625
8772
|
exports.ERR_INVALID_COMPRESSED_DATA = ERR_INVALID_COMPRESSED_DATA;
|
|
8626
8773
|
exports.ERR_INVALID_CRC32 = ERR_INVALID_CRC32;
|
|
8627
8774
|
exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
|
|
@@ -8653,11 +8800,13 @@
|
|
|
8653
8800
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
8654
8801
|
exports.ERR_UNDEFINED_READER = ERR_UNDEFINED_READER;
|
|
8655
8802
|
exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
|
|
8803
|
+
exports.ERR_UNDETERMINED_SIZE = ERR_UNDETERMINED_SIZE;
|
|
8656
8804
|
exports.ERR_UNSAFE_FILENAME = ERR_UNSAFE_FILENAME;
|
|
8657
8805
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION$1;
|
|
8658
8806
|
exports.ERR_UNSUPPORTED_CONTEXT = ERR_UNSUPPORTED_CONTEXT;
|
|
8659
8807
|
exports.ERR_UNSUPPORTED_CRYPTO_API = ERR_UNSUPPORTED_CRYPTO_API;
|
|
8660
8808
|
exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
|
|
8809
|
+
exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
|
|
8661
8810
|
exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
|
|
8662
8811
|
exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
|
|
8663
8812
|
exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
|