@zip.js/zip.js 2.8.51 → 2.8.52
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 +88 -44
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +89 -43
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +408 -148
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +408 -147
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +408 -148
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +410 -147
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +410 -147
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +89 -43
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +89 -43
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +89 -43
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +410 -147
- package/index-native.min.js +1 -1
- package/index.cjs +410 -147
- package/index.d.cts +278 -10
- package/index.d.ts +278 -10
- package/index.min.js +1 -1
- package/lib/core/codec-worker.js +2 -0
- package/lib/core/constants.js +4 -0
- package/lib/core/io.js +32 -2
- package/lib/core/util/compatible-streams.js +3 -8
- package/lib/core/zip-entry.js +8 -0
- package/lib/core/zip-fs.js +236 -107
- package/lib/core/zip-reader.js +15 -6
- package/lib/core/zip-writer.js +135 -29
- package/lib/zip-core-writer.js +2 -0
- package/package.json +5 -5
package/dist/zip-fs.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;
|
|
@@ -1781,8 +1783,6 @@
|
|
|
1781
1783
|
*/
|
|
1782
1784
|
|
|
1783
1785
|
|
|
1784
|
-
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
1785
|
-
|
|
1786
1786
|
function toCompatibleReadable(readable) {
|
|
1787
1787
|
if (readable instanceof ReadableStream) {
|
|
1788
1788
|
return readable;
|
|
@@ -1805,12 +1805,9 @@
|
|
|
1805
1805
|
|
|
1806
1806
|
function streamToBlob(readable, contentType) {
|
|
1807
1807
|
readable = toCompatibleReadable(readable);
|
|
1808
|
+
const blobOptions = contentType ? { type: contentType } : {};
|
|
1808
1809
|
if (responseSupportsGlobalReadable()) {
|
|
1809
|
-
|
|
1810
|
-
if (contentType) {
|
|
1811
|
-
options.headers = [[HTTP_HEADER_CONTENT_TYPE, contentType]];
|
|
1812
|
-
}
|
|
1813
|
-
return new Response(readable, options).blob();
|
|
1810
|
+
return new Response(readable).blob().then(blob => contentType ? new Blob([blob], blobOptions) : blob);
|
|
1814
1811
|
}
|
|
1815
1812
|
const chunks = [];
|
|
1816
1813
|
return readable
|
|
@@ -1819,7 +1816,7 @@
|
|
|
1819
1816
|
chunks.push(chunk);
|
|
1820
1817
|
}
|
|
1821
1818
|
}))
|
|
1822
|
-
.then(() => new Blob(chunks,
|
|
1819
|
+
.then(() => new Blob(chunks, blobOptions));
|
|
1823
1820
|
}
|
|
1824
1821
|
|
|
1825
1822
|
function responseSupportsGlobalReadable() {
|
|
@@ -3354,8 +3351,10 @@
|
|
|
3354
3351
|
async pull(controller) {
|
|
3355
3352
|
const dataSize = size === UNDEFINED_VALUE ? chunkSize : Math.min(chunkSize, size - chunkOffset);
|
|
3356
3353
|
const data = await readUint8Array(reader, offset + chunkOffset, dataSize);
|
|
3357
|
-
|
|
3358
|
-
|
|
3354
|
+
if (data.length) {
|
|
3355
|
+
controller.enqueue(data);
|
|
3356
|
+
}
|
|
3357
|
+
if ((chunkOffset + chunkSize >= size) || (size === UNDEFINED_VALUE && !data.length && dataSize)) {
|
|
3359
3358
|
controller.close();
|
|
3360
3359
|
} else {
|
|
3361
3360
|
chunkOffset += chunkSize;
|
|
@@ -3433,6 +3432,7 @@
|
|
|
3433
3432
|
constructor(contentType) {
|
|
3434
3433
|
super();
|
|
3435
3434
|
Object.assign(this, {
|
|
3435
|
+
contentType,
|
|
3436
3436
|
data: "data:" + (contentType || "") + ";base64,",
|
|
3437
3437
|
pending: []
|
|
3438
3438
|
});
|
|
@@ -3534,6 +3534,7 @@
|
|
|
3534
3534
|
return transformStream.writable;
|
|
3535
3535
|
}
|
|
3536
3536
|
});
|
|
3537
|
+
writer.contentType = contentType;
|
|
3537
3538
|
writer.blob = streamToBlob(transformStream.readable, contentType);
|
|
3538
3539
|
writer.blob.catch(() => { });
|
|
3539
3540
|
}
|
|
@@ -3550,6 +3551,26 @@
|
|
|
3550
3551
|
}
|
|
3551
3552
|
}
|
|
3552
3553
|
|
|
3554
|
+
function getTextSize(text) {
|
|
3555
|
+
let size = 0;
|
|
3556
|
+
for (let indexCharacter = 0; indexCharacter < text.length; indexCharacter++) {
|
|
3557
|
+
const characterCode = text.charCodeAt(indexCharacter);
|
|
3558
|
+
if (characterCode < 0x80) {
|
|
3559
|
+
size += 1;
|
|
3560
|
+
} else if (characterCode < 0x800) {
|
|
3561
|
+
size += 2;
|
|
3562
|
+
} else if (characterCode < 0xd800 || characterCode >= 0xe000) {
|
|
3563
|
+
size += 3;
|
|
3564
|
+
} else if (characterCode < 0xdc00 && (text.charCodeAt(indexCharacter + 1) & 0xfc00) == 0xdc00) {
|
|
3565
|
+
size += 4;
|
|
3566
|
+
indexCharacter++;
|
|
3567
|
+
} else {
|
|
3568
|
+
size += 3;
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
return size;
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3553
3574
|
class TextWriter extends BlobWriter {
|
|
3554
3575
|
|
|
3555
3576
|
constructor(encoding) {
|
|
@@ -4213,6 +4234,10 @@
|
|
|
4213
4234
|
}
|
|
4214
4235
|
}
|
|
4215
4236
|
|
|
4237
|
+
function ownsWritable(writer) {
|
|
4238
|
+
return Boolean(writer && writer.getData);
|
|
4239
|
+
}
|
|
4240
|
+
|
|
4216
4241
|
function isHttpFamily(url) {
|
|
4217
4242
|
const { baseURI } = getConfiguration();
|
|
4218
4243
|
const { protocol } = new URL(url, baseURI);
|
|
@@ -4357,6 +4382,8 @@
|
|
|
4357
4382
|
const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
|
|
4358
4383
|
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES = "internalFileAttributes";
|
|
4359
4384
|
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttributes";
|
|
4385
|
+
const PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES = "internalFileAttribute";
|
|
4386
|
+
const PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttribute";
|
|
4360
4387
|
const PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW = "msdosAttributesRaw";
|
|
4361
4388
|
const PROPERTY_NAME_MSDOS_ATTRIBUTES = "msdosAttributes";
|
|
4362
4389
|
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
@@ -4367,6 +4394,7 @@
|
|
|
4367
4394
|
const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
|
|
4368
4395
|
const PROPERTY_NAME_DIRECTORY = "directory";
|
|
4369
4396
|
const PROPERTY_NAME_EXECUTABLE = "executable";
|
|
4397
|
+
const PROPERTY_NAME_SYMLINK = "symlink";
|
|
4370
4398
|
const PROPERTY_NAME_COMPRESSION_METHOD = "compressionMethod";
|
|
4371
4399
|
const PROPERTY_NAME_SIGNATURE = "signature";
|
|
4372
4400
|
const PROPERTY_NAME_CRC32 = "crc32";
|
|
@@ -4410,6 +4438,8 @@
|
|
|
4410
4438
|
PROPERTY_NAME_DISK_NUMBER_START,
|
|
4411
4439
|
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
|
|
4412
4440
|
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
|
|
4441
|
+
PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES,
|
|
4442
|
+
PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES,
|
|
4413
4443
|
PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW,
|
|
4414
4444
|
PROPERTY_NAME_MSDOS_ATTRIBUTES,
|
|
4415
4445
|
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
@@ -4420,6 +4450,7 @@
|
|
|
4420
4450
|
PROPERTY_NAME_ZIPCRYPTO,
|
|
4421
4451
|
PROPERTY_NAME_DIRECTORY,
|
|
4422
4452
|
PROPERTY_NAME_EXECUTABLE,
|
|
4453
|
+
PROPERTY_NAME_SYMLINK,
|
|
4423
4454
|
PROPERTY_NAME_COMPRESSION_METHOD,
|
|
4424
4455
|
PROPERTY_NAME_SIGNATURE,
|
|
4425
4456
|
PROPERTY_NAME_CRC32,
|
|
@@ -4882,15 +4913,18 @@
|
|
|
4882
4913
|
const setuid = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_SETUID_MASK);
|
|
4883
4914
|
const setgid = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_SETGID_MASK);
|
|
4884
4915
|
const sticky = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_STICKY_MASK);
|
|
4885
|
-
const
|
|
4916
|
+
const unixType = fileEntry.unixMode === UNDEFINED_VALUE ? unixExternalUpper : fileEntry.unixMode;
|
|
4917
|
+
const symlink = (unixType & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_SYMLINK;
|
|
4918
|
+
const executable = !symlink && ((fileEntry.unixMode !== UNDEFINED_VALUE)
|
|
4886
4919
|
? ((fileEntry.unixMode & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)
|
|
4887
|
-
: (unixCompatible && ((unixExternalUpper & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0));
|
|
4920
|
+
: (unixCompatible && ((unixExternalUpper & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)));
|
|
4888
4921
|
const modeIsDir = fileEntry.unixMode !== UNDEFINED_VALUE && ((fileEntry.unixMode & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR);
|
|
4889
4922
|
const upperIsDir = ((unixExternalUpper & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR);
|
|
4890
4923
|
Object.assign(fileEntry, {
|
|
4891
4924
|
setuid,
|
|
4892
4925
|
setgid,
|
|
4893
4926
|
sticky,
|
|
4927
|
+
symlink,
|
|
4894
4928
|
unixExternalUpper,
|
|
4895
4929
|
internalFileAttribute: fileEntry.internalFileAttributes,
|
|
4896
4930
|
externalFileAttribute: fileEntry.externalFileAttributes,
|
|
@@ -4956,6 +4990,10 @@
|
|
|
4956
4990
|
}
|
|
4957
4991
|
|
|
4958
4992
|
async close() {
|
|
4993
|
+
const { reader } = this;
|
|
4994
|
+
if (!reader.readUint8Array && reader.readable && !reader.readable.locked) {
|
|
4995
|
+
await reader.readable.cancel();
|
|
4996
|
+
}
|
|
4959
4997
|
}
|
|
4960
4998
|
}
|
|
4961
4999
|
|
|
@@ -5180,7 +5218,7 @@
|
|
|
5180
5218
|
throw error;
|
|
5181
5219
|
}
|
|
5182
5220
|
} finally {
|
|
5183
|
-
const preventClose = getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5221
|
+
const preventClose = !ownsWritable(writer) && getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5184
5222
|
if (!preventClose && writable && !writable.locked) {
|
|
5185
5223
|
const writableWriter = writable.getWriter();
|
|
5186
5224
|
if (abortError) {
|
|
@@ -5424,8 +5462,8 @@
|
|
|
5424
5462
|
return;
|
|
5425
5463
|
}
|
|
5426
5464
|
const extraFieldView = getDataView(extraField.data);
|
|
5427
|
-
const lastAccessDate = new Date(getUint32(extraFieldView, 0) * 1000);
|
|
5428
|
-
const lastModDate = new Date(getUint32(extraFieldView, 4) * 1000);
|
|
5465
|
+
const lastAccessDate = new Date((getUint32(extraFieldView, 0) | 0) * 1000);
|
|
5466
|
+
const lastModDate = new Date((getUint32(extraFieldView, 4) | 0) * 1000);
|
|
5429
5467
|
const extraFieldData = { lastAccessDate, lastModDate };
|
|
5430
5468
|
if (extraField.data.length >= 12) {
|
|
5431
5469
|
extraFieldData.uid = getUint16(extraFieldView, 8);
|
|
@@ -5856,6 +5894,7 @@
|
|
|
5856
5894
|
const ERR_INVALID_VERSION = "Version exceeds 65535";
|
|
5857
5895
|
const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
|
|
5858
5896
|
const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
|
|
5897
|
+
const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
|
|
5859
5898
|
const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
|
|
5860
5899
|
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
5861
5900
|
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
@@ -5865,6 +5904,7 @@
|
|
|
5865
5904
|
const MAX_NTFS_TIME = BigInt("0x7fffffffffffffff");
|
|
5866
5905
|
const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
|
|
5867
5906
|
const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
|
|
5907
|
+
const ERR_UNDETERMINED_SIZE = "Undetermined size";
|
|
5868
5908
|
const ERR_UNDEFINED_READER = "Undefined reader";
|
|
5869
5909
|
const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
|
|
5870
5910
|
const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
|
|
@@ -6072,7 +6112,7 @@
|
|
|
6072
6112
|
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6073
6113
|
}
|
|
6074
6114
|
await closeFile(zipWriter, comment, options);
|
|
6075
|
-
const preventClose = getOptionValue(zipWriter, options, OPTION_PREVENT_CLOSE);
|
|
6115
|
+
const preventClose = !ownsWritable(writer) && getOptionValue(zipWriter, options, OPTION_PREVENT_CLOSE);
|
|
6076
6116
|
if (!preventClose) {
|
|
6077
6117
|
await writable.getWriter().close();
|
|
6078
6118
|
}
|
|
@@ -6231,7 +6271,7 @@
|
|
|
6231
6271
|
if (versionMadeBy > MAX_16_BITS) {
|
|
6232
6272
|
throw new Error(ERR_INVALID_VERSION);
|
|
6233
6273
|
}
|
|
6234
|
-
let externalFileAttributes =
|
|
6274
|
+
let externalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES);
|
|
6235
6275
|
const externalFileAttributesProvided = externalFileAttributes !== UNDEFINED_VALUE;
|
|
6236
6276
|
if (!externalFileAttributesProvided) {
|
|
6237
6277
|
externalFileAttributes = 0;
|
|
@@ -6279,7 +6319,9 @@
|
|
|
6279
6319
|
}
|
|
6280
6320
|
if (!externalFileAttributesProvided || unixModeProvided) {
|
|
6281
6321
|
if (directory) {
|
|
6282
|
-
unixMode
|
|
6322
|
+
unixMode = (unixMode & ~FILE_ATTR_UNIX_TYPE_MASK) | FILE_ATTR_UNIX_TYPE_DIR;
|
|
6323
|
+
} else if (!(unixMode & FILE_ATTR_UNIX_TYPE_MASK)) {
|
|
6324
|
+
unixMode |= FILE_ATTR_UNIX_TYPE_FILE;
|
|
6283
6325
|
}
|
|
6284
6326
|
externalFileAttributes = ((unixMode & MAX_16_BITS) << 16) | (externalFileAttributes & MAX_16_BITS);
|
|
6285
6327
|
}
|
|
@@ -6332,15 +6374,12 @@
|
|
|
6332
6374
|
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
|
|
6333
6375
|
const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
6334
6376
|
const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
6335
|
-
const internalFileAttributes =
|
|
6377
|
+
const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
|
|
6336
6378
|
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
|
-
}
|
|
6379
|
+
const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
6380
|
+
const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
6381
|
+
if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
|
|
6382
|
+
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
6344
6383
|
}
|
|
6345
6384
|
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
6346
6385
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
@@ -6453,14 +6492,24 @@
|
|
|
6453
6492
|
}
|
|
6454
6493
|
|
|
6455
6494
|
async function resolveSizes(zipWriter, reader, { resolvedOptions: metadata }, options) {
|
|
6495
|
+
if (metadata.passThrough && !reader && !getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY)) {
|
|
6496
|
+
throw new Error(ERR_UNDEFINED_READER);
|
|
6497
|
+
}
|
|
6498
|
+
let contentSize;
|
|
6499
|
+
if (reader) {
|
|
6500
|
+
reader = new GenericReader(reader);
|
|
6501
|
+
await initStream(reader);
|
|
6502
|
+
({ size: contentSize } = reader);
|
|
6503
|
+
}
|
|
6504
|
+
return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
|
|
6505
|
+
}
|
|
6506
|
+
|
|
6507
|
+
function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options) {
|
|
6456
6508
|
const { passThrough, zipCrypto, password, rawPassword, encryptionStrength } = metadata;
|
|
6457
6509
|
let { dataDescriptor, zip64, level, compressionMethod } = metadata;
|
|
6458
6510
|
let maximumCompressedSize = 0;
|
|
6459
6511
|
let uncompressedSize = 0;
|
|
6460
|
-
if (passThrough) {
|
|
6461
|
-
if (!reader) {
|
|
6462
|
-
throw new Error(ERR_UNDEFINED_READER);
|
|
6463
|
-
}
|
|
6512
|
+
if (passThrough && hasContent) {
|
|
6464
6513
|
uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
|
|
6465
6514
|
if (uncompressedSize === UNDEFINED_VALUE) {
|
|
6466
6515
|
throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
|
|
@@ -6468,29 +6517,30 @@
|
|
|
6468
6517
|
}
|
|
6469
6518
|
const zip64Enabled = zip64 === true;
|
|
6470
6519
|
const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
|
|
6471
|
-
|
|
6472
|
-
|
|
6520
|
+
if (hasContent && passThrough && !encrypted && getLength(password, rawPassword)) {
|
|
6521
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH);
|
|
6522
|
+
}
|
|
6523
|
+
const encryptedEntry = hasContent && (Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted));
|
|
6524
|
+
if (!hasContent) {
|
|
6473
6525
|
level = 0;
|
|
6474
6526
|
compressionMethod = COMPRESSION_METHOD_STORE;
|
|
6475
6527
|
}
|
|
6476
6528
|
const encryptionOverhead = encryptedEntry ? (zipCrypto ? 12 : 16 + encryptionStrength * 4) : 0;
|
|
6477
|
-
if (
|
|
6478
|
-
reader = new GenericReader(reader);
|
|
6479
|
-
await initStream(reader);
|
|
6529
|
+
if (hasContent) {
|
|
6480
6530
|
if (!passThrough) {
|
|
6481
|
-
if (
|
|
6531
|
+
if (contentSize === UNDEFINED_VALUE) {
|
|
6482
6532
|
dataDescriptor = true;
|
|
6483
6533
|
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
6484
6534
|
zip64 = true;
|
|
6485
6535
|
uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
|
|
6486
6536
|
}
|
|
6487
6537
|
} else {
|
|
6488
|
-
options.uncompressedSize = uncompressedSize =
|
|
6489
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize) + encryptionOverhead;
|
|
6538
|
+
options.uncompressedSize = uncompressedSize = contentSize;
|
|
6539
|
+
maximumCompressedSize = (isCompressed(compressionMethod, level) ? getMaximumCompressedSize(uncompressedSize) : uncompressedSize) + encryptionOverhead;
|
|
6490
6540
|
}
|
|
6491
6541
|
} else {
|
|
6492
6542
|
options.uncompressedSize = uncompressedSize;
|
|
6493
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize) + encryptionOverhead;
|
|
6543
|
+
maximumCompressedSize = contentSize === UNDEFINED_VALUE ? getMaximumCompressedSize(uncompressedSize) + encryptionOverhead : contentSize;
|
|
6494
6544
|
}
|
|
6495
6545
|
}
|
|
6496
6546
|
const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
|
|
@@ -6504,7 +6554,7 @@
|
|
|
6504
6554
|
}
|
|
6505
6555
|
zip64 = zip64 || false;
|
|
6506
6556
|
return {
|
|
6507
|
-
|
|
6557
|
+
maximumCompressedSize,
|
|
6508
6558
|
resolvedOptions: {
|
|
6509
6559
|
dataDescriptor,
|
|
6510
6560
|
zip64,
|
|
@@ -6518,6 +6568,78 @@
|
|
|
6518
6568
|
};
|
|
6519
6569
|
}
|
|
6520
6570
|
|
|
6571
|
+
async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comment) {
|
|
6572
|
+
const zipWriter = { options: writerOptions, config: getConfiguration() };
|
|
6573
|
+
if (writerOptions[OPTION_SIGN_CENTRAL_DIRECTORY]) {
|
|
6574
|
+
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
6575
|
+
}
|
|
6576
|
+
const commentLength = getLength(comment);
|
|
6577
|
+
if (commentLength > MAX_16_BITS) {
|
|
6578
|
+
throw new Error(ERR_INVALID_COMMENT);
|
|
6579
|
+
}
|
|
6580
|
+
const usdz = writerOptions[OPTION_USDZ];
|
|
6581
|
+
const files = new Map();
|
|
6582
|
+
let layoutDependsOnWriteOrder = Boolean(usdz);
|
|
6583
|
+
let offset = 0;
|
|
6584
|
+
for (const entry of entries) {
|
|
6585
|
+
let { name } = entry;
|
|
6586
|
+
const { size } = entry;
|
|
6587
|
+
const options = Object.assign({}, entry.options);
|
|
6588
|
+
name = name.trim();
|
|
6589
|
+
if (getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY) && !name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
6590
|
+
name += DIRECTORY_SIGNATURE;
|
|
6591
|
+
}
|
|
6592
|
+
const attributesInfo = resolveAttributes(zipWriter, name, options);
|
|
6593
|
+
({ name } = attributesInfo);
|
|
6594
|
+
const { resolvedOptions: metadata } = resolveMetadata(zipWriter, name, options);
|
|
6595
|
+
if (metadata.level != 0 && metadata.compressionMethod === UNDEFINED_VALUE &&
|
|
6596
|
+
!metadata.passThrough && !(await supportsDeflate(zipWriter.config))) {
|
|
6597
|
+
metadata.level = 0;
|
|
6598
|
+
}
|
|
6599
|
+
const hasContent = !getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY);
|
|
6600
|
+
if (hasContent && size === UNDEFINED_VALUE) {
|
|
6601
|
+
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
6602
|
+
}
|
|
6603
|
+
const { maximumCompressedSize, resolvedOptions: sizes } = resolveEntrySizes(zipWriter, hasContent, size, metadata, options);
|
|
6604
|
+
if (hasContent && !metadata.passThrough && isCompressed(sizes.compressionMethod, sizes.level)) {
|
|
6605
|
+
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
6606
|
+
}
|
|
6607
|
+
const entryOptions = Object.assign({}, options, attributesInfo.resolvedOptions, metadata, sizes);
|
|
6608
|
+
const headerInfo = getHeaderInfo(entryOptions);
|
|
6609
|
+
const dataDescriptorInfo = getDataDescriptorInfo(entryOptions);
|
|
6610
|
+
const entryInfo = {
|
|
6611
|
+
headerInfo,
|
|
6612
|
+
metadataSize: getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray)
|
|
6613
|
+
};
|
|
6614
|
+
if (usdz) {
|
|
6615
|
+
appendExtraFieldUSDZ(entryInfo, offset);
|
|
6616
|
+
}
|
|
6617
|
+
const compressedSize = hasContent ? maximumCompressedSize : 0;
|
|
6618
|
+
if (offset >= MAX_32_BITS) {
|
|
6619
|
+
layoutDependsOnWriteOrder = true;
|
|
6620
|
+
}
|
|
6621
|
+
files.set(name, Object.assign({}, entryOptions, headerInfo, {
|
|
6622
|
+
offset,
|
|
6623
|
+
diskNumberStart: 0,
|
|
6624
|
+
compressedSize
|
|
6625
|
+
}));
|
|
6626
|
+
offset += entryInfo.metadataSize + compressedSize;
|
|
6627
|
+
}
|
|
6628
|
+
if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
|
|
6629
|
+
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
6630
|
+
}
|
|
6631
|
+
const directoryDataLength = createDirectoryRecords(files);
|
|
6632
|
+
let zip64 = getOptionValue(zipWriter, writerOptions, PROPERTY_NAME_ZIP64);
|
|
6633
|
+
if (offset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || files.size >= MAX_16_BITS) {
|
|
6634
|
+
if (zip64 === false) {
|
|
6635
|
+
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
6636
|
+
} else {
|
|
6637
|
+
zip64 = true;
|
|
6638
|
+
}
|
|
6639
|
+
}
|
|
6640
|
+
return offset + directoryDataLength + commentLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
|
|
6641
|
+
}
|
|
6642
|
+
|
|
6521
6643
|
async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
6522
6644
|
const {
|
|
6523
6645
|
files,
|
|
@@ -6889,9 +7011,7 @@
|
|
|
6889
7011
|
crc32
|
|
6890
7012
|
} = options;
|
|
6891
7013
|
let { version, compressionMethod } = options;
|
|
6892
|
-
const compressed = !directory && (compressionMethod
|
|
6893
|
-
? (level === UNDEFINED_VALUE || level > 0)
|
|
6894
|
-
: compressionMethod !== COMPRESSION_METHOD_STORE);
|
|
7014
|
+
const compressed = !directory && isCompressed(compressionMethod, level);
|
|
6895
7015
|
let rawLocalExtraFieldZip64;
|
|
6896
7016
|
const uncompressedFile = passThrough || !compressed;
|
|
6897
7017
|
const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
|
|
@@ -7578,6 +7698,16 @@
|
|
|
7578
7698
|
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7579
7699
|
}
|
|
7580
7700
|
|
|
7701
|
+
function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
|
|
7702
|
+
const value = getAliasedValue(options, name, deprecatedName);
|
|
7703
|
+
const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
|
|
7704
|
+
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7705
|
+
}
|
|
7706
|
+
|
|
7707
|
+
function getAliasedValue(options, name, deprecatedName) {
|
|
7708
|
+
return options[name] === UNDEFINED_VALUE ? options[deprecatedName] : options[name];
|
|
7709
|
+
}
|
|
7710
|
+
|
|
7581
7711
|
function getNumberOptionValue(zipWriter, options, name, defaultValue) {
|
|
7582
7712
|
return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
|
|
7583
7713
|
}
|
|
@@ -7590,6 +7720,12 @@
|
|
|
7590
7720
|
return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
|
|
7591
7721
|
}
|
|
7592
7722
|
|
|
7723
|
+
function isCompressed(compressionMethod, level) {
|
|
7724
|
+
return compressionMethod === UNDEFINED_VALUE
|
|
7725
|
+
? (level === UNDEFINED_VALUE || level > 0)
|
|
7726
|
+
: compressionMethod !== COMPRESSION_METHOD_STORE;
|
|
7727
|
+
}
|
|
7728
|
+
|
|
7593
7729
|
function setUint8(view, offset, value) {
|
|
7594
7730
|
view.setUint8(offset, value);
|
|
7595
7731
|
}
|
|
@@ -8603,6 +8739,7 @@
|
|
|
8603
8739
|
|
|
8604
8740
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
8605
8741
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
8742
|
+
const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
|
|
8606
8743
|
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
8607
8744
|
const ERR_ABORTED = "The operation was aborted";
|
|
8608
8745
|
const ABORT_ERROR_NAME = "AbortError";
|
|
@@ -8640,6 +8777,7 @@
|
|
|
8640
8777
|
parent,
|
|
8641
8778
|
children: [],
|
|
8642
8779
|
uncompressedSize: params.uncompressedSize || 0,
|
|
8780
|
+
undeterminedSize: params.undeterminedSize || params.uncompressedSize === UNDEFINED_VALUE,
|
|
8643
8781
|
passThrough: params.passThrough
|
|
8644
8782
|
});
|
|
8645
8783
|
if (parent || !fs.root) {
|
|
@@ -8707,16 +8845,17 @@
|
|
|
8707
8845
|
|
|
8708
8846
|
async getData(writer, options = {}) {
|
|
8709
8847
|
const zipEntry = this;
|
|
8710
|
-
if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data)) {
|
|
8848
|
+
if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data && keepsContentType(writer, zipEntry.data))) {
|
|
8711
8849
|
return zipEntry.data;
|
|
8712
8850
|
} else {
|
|
8713
8851
|
const reader = zipEntry.reader = createReader(zipEntry.Reader, zipEntry.data, options);
|
|
8714
|
-
const
|
|
8715
|
-
await Promise.all([initStream(reader), initStream(writer,
|
|
8716
|
-
const { readable } = reader;
|
|
8852
|
+
const dataSize = zipEntry.uncompressedSize || reader.size;
|
|
8853
|
+
await Promise.all([initStream(reader), initStream(writer, dataSize)]);
|
|
8717
8854
|
const { signal } = options;
|
|
8855
|
+
const readable = createProgressReadable(zipEntry, reader, options, signal);
|
|
8856
|
+
const preventClose = !ownsWritable(writer) && Boolean(options.preventClose);
|
|
8718
8857
|
zipEntry.uncompressedSize = reader.size;
|
|
8719
|
-
await toCompatibleReadable(readable).pipeTo(toCompatibleWritable(writer.writable), { signal });
|
|
8858
|
+
await toCompatibleReadable(readable).pipeTo(toCompatibleWritable(writer.writable), { signal, preventClose, preventAbort: preventClose });
|
|
8720
8859
|
return writer.getData ? writer.getData() : writer.writable;
|
|
8721
8860
|
}
|
|
8722
8861
|
}
|
|
@@ -8847,7 +8986,7 @@
|
|
|
8847
8986
|
Reader: TextReader,
|
|
8848
8987
|
Writer: TextWriter,
|
|
8849
8988
|
options,
|
|
8850
|
-
uncompressedSize: text
|
|
8989
|
+
uncompressedSize: getTextSize(text)
|
|
8851
8990
|
});
|
|
8852
8991
|
}
|
|
8853
8992
|
|
|
@@ -8976,10 +9115,16 @@
|
|
|
8976
9115
|
}
|
|
8977
9116
|
|
|
8978
9117
|
async importZip(reader, options = {}) {
|
|
8979
|
-
|
|
8980
|
-
|
|
9118
|
+
let zipReader;
|
|
9119
|
+
if (reader && typeof reader.getEntries == FUNCTION_TYPE) {
|
|
9120
|
+
zipReader = reader;
|
|
9121
|
+
options = Object.assign({}, zipReader.options, options);
|
|
9122
|
+
} else {
|
|
9123
|
+
await initStream(reader);
|
|
9124
|
+
zipReader = new ZipReader(reader, options);
|
|
9125
|
+
}
|
|
8981
9126
|
const importedEntries = [];
|
|
8982
|
-
const entries = await zipReader.getEntries();
|
|
9127
|
+
const entries = await zipReader.getEntries(options);
|
|
8983
9128
|
for (const entry of entries) {
|
|
8984
9129
|
let parent = this;
|
|
8985
9130
|
try {
|
|
@@ -9001,7 +9146,7 @@
|
|
|
9001
9146
|
importedEntries.push(addChild(parent, name, {
|
|
9002
9147
|
data: entry,
|
|
9003
9148
|
Reader: getZipBlobReader(Object.assign({}, options)),
|
|
9004
|
-
uncompressedSize: entry.uncompressedSize,
|
|
9149
|
+
uncompressedSize: options.passThrough ? entry.compressedSize : entry.uncompressedSize,
|
|
9005
9150
|
passThrough: options.passThrough
|
|
9006
9151
|
}));
|
|
9007
9152
|
} else {
|
|
@@ -9043,11 +9188,25 @@
|
|
|
9043
9188
|
}
|
|
9044
9189
|
const [readers] = await Promise.all([initReaders(zipEntry, options.readerOptions), initStream(writer)]);
|
|
9045
9190
|
const zipWriter = new ZipWriter(writer, options);
|
|
9046
|
-
await exportZip(zipWriter, zipEntry, getTotalSize([zipEntry],
|
|
9047
|
-
await zipWriter.close();
|
|
9191
|
+
await exportZip(zipWriter, zipEntry, getTotalSize([zipEntry], getUncompressedSize), options, readers);
|
|
9192
|
+
await zipWriter.close(options.globalComment);
|
|
9048
9193
|
return writer.getData ? writer.getData() : writer.writable;
|
|
9049
9194
|
}
|
|
9050
9195
|
|
|
9196
|
+
getExportedSize(options = {}) {
|
|
9197
|
+
const zipEntry = this;
|
|
9198
|
+
options = Object.assign({}, options);
|
|
9199
|
+
if (options.bufferedWrite === UNDEFINED_VALUE) {
|
|
9200
|
+
options.bufferedWrite = true;
|
|
9201
|
+
}
|
|
9202
|
+
const writeOrderGuaranteed = !options.bufferedWrite ||
|
|
9203
|
+
(options.keepOrder !== false && zipEntry.children.every(child => !child.children.length));
|
|
9204
|
+
return getEntriesSize(options, Array.from(zipEntry.getChildren({ recursive: true }), child => {
|
|
9205
|
+
const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
|
|
9206
|
+
return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
|
|
9207
|
+
}), writeOrderGuaranteed, options.globalComment);
|
|
9208
|
+
}
|
|
9209
|
+
|
|
9051
9210
|
getChildByName(name) {
|
|
9052
9211
|
const children = this.children;
|
|
9053
9212
|
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
@@ -9255,6 +9414,10 @@
|
|
|
9255
9414
|
return this.root.exportZip(writer, options);
|
|
9256
9415
|
}
|
|
9257
9416
|
|
|
9417
|
+
getExportedSize(options) {
|
|
9418
|
+
return this.root.getExportedSize(options);
|
|
9419
|
+
}
|
|
9420
|
+
|
|
9258
9421
|
isPasswordProtected() {
|
|
9259
9422
|
return this.root.isPasswordProtected();
|
|
9260
9423
|
}
|
|
@@ -9266,12 +9429,12 @@
|
|
|
9266
9429
|
|
|
9267
9430
|
const fs = { FS, ZipDirectoryEntry, ZipFileEntry };
|
|
9268
9431
|
|
|
9269
|
-
function getTotalSize(entries,
|
|
9432
|
+
function getTotalSize(entries, getEntrySize) {
|
|
9270
9433
|
let size = 0;
|
|
9271
9434
|
const pendingEntries = Array.from(entries);
|
|
9272
9435
|
while (pendingEntries.length) {
|
|
9273
9436
|
const entry = pendingEntries.pop();
|
|
9274
|
-
size += entry
|
|
9437
|
+
size += getEntrySize(entry) || 0;
|
|
9275
9438
|
for (const child of entry.children) {
|
|
9276
9439
|
pendingEntries.push(child);
|
|
9277
9440
|
}
|
|
@@ -9279,6 +9442,15 @@
|
|
|
9279
9442
|
return size;
|
|
9280
9443
|
}
|
|
9281
9444
|
|
|
9445
|
+
function getUncompressedSize(entry) {
|
|
9446
|
+
return entry.uncompressedSize;
|
|
9447
|
+
}
|
|
9448
|
+
|
|
9449
|
+
function getExtractedSize(entry, passThrough) {
|
|
9450
|
+
const { data } = entry;
|
|
9451
|
+
return passThrough && data instanceof Entry ? data.compressedSize : entry.uncompressedSize;
|
|
9452
|
+
}
|
|
9453
|
+
|
|
9282
9454
|
function getReadableReader(readable) {
|
|
9283
9455
|
let consumed;
|
|
9284
9456
|
return function () {
|
|
@@ -9301,10 +9473,17 @@
|
|
|
9301
9473
|
|
|
9302
9474
|
async init() {
|
|
9303
9475
|
const zipBlobReader = this;
|
|
9304
|
-
|
|
9305
|
-
const
|
|
9476
|
+
const readerOptions = Object.assign({}, options, zipBlobReader.options);
|
|
9477
|
+
const { checkOverlappingEntry, checkOverlappingEntryOnly } = readerOptions;
|
|
9478
|
+
const data = await zipBlobReader.entry.getData(new BlobWriter(), Object.assign(readerOptions, {
|
|
9479
|
+
checkPasswordOnly: false,
|
|
9480
|
+
checkOverlappingEntry: checkOverlappingEntryOnly || checkOverlappingEntry,
|
|
9481
|
+
checkOverlappingEntryOnly: false,
|
|
9482
|
+
preventClose: false
|
|
9483
|
+
}));
|
|
9306
9484
|
zipBlobReader.data = data;
|
|
9307
9485
|
zipBlobReader.blobReader = new BlobReader(data);
|
|
9486
|
+
zipBlobReader.size = data.size;
|
|
9308
9487
|
super.init();
|
|
9309
9488
|
}
|
|
9310
9489
|
|
|
@@ -9318,6 +9497,30 @@
|
|
|
9318
9497
|
return Reader.prototype ? new Reader(data, options) : Reader(data, options);
|
|
9319
9498
|
}
|
|
9320
9499
|
|
|
9500
|
+
function keepsContentType(writer, data) {
|
|
9501
|
+
const { contentType } = writer;
|
|
9502
|
+
if (contentType === UNDEFINED_VALUE) {
|
|
9503
|
+
return true;
|
|
9504
|
+
} else if (writer.constructor == BlobWriter) {
|
|
9505
|
+
return data.type == contentType;
|
|
9506
|
+
} else if (writer.constructor == Data64URIWriter) {
|
|
9507
|
+
return data.startsWith(writer.data);
|
|
9508
|
+
} else {
|
|
9509
|
+
return true;
|
|
9510
|
+
}
|
|
9511
|
+
}
|
|
9512
|
+
|
|
9513
|
+
function createProgressReadable(zipEntry, reader, options, signal) {
|
|
9514
|
+
const { onstart, onprogress, onend } = options;
|
|
9515
|
+
const { readable } = reader;
|
|
9516
|
+
const coreReaderReportsProgress = zipEntry.data instanceof Entry;
|
|
9517
|
+
if (coreReaderReportsProgress || (!onstart && !onprogress && !onend)) {
|
|
9518
|
+
return readable;
|
|
9519
|
+
} else {
|
|
9520
|
+
return toCompatibleReadable(readable).pipeThrough(new ProgressWatcherStream({ onstart, onprogress, onend, size: reader.size }), { signal });
|
|
9521
|
+
}
|
|
9522
|
+
}
|
|
9523
|
+
|
|
9321
9524
|
async function initReaders(entry, options) {
|
|
9322
9525
|
const fileEntries = [];
|
|
9323
9526
|
const pendingEntries = [entry];
|
|
@@ -9350,6 +9553,7 @@
|
|
|
9350
9553
|
}
|
|
9351
9554
|
if (reader.size !== UNDEFINED_VALUE) {
|
|
9352
9555
|
child.uncompressedSize = reader.size;
|
|
9556
|
+
child.undeterminedSize = false;
|
|
9353
9557
|
}
|
|
9354
9558
|
}));
|
|
9355
9559
|
return readers;
|
|
@@ -9399,6 +9603,90 @@
|
|
|
9399
9603
|
return error;
|
|
9400
9604
|
}
|
|
9401
9605
|
|
|
9606
|
+
function getChildEntryOptions(child, selectedEntry, options) {
|
|
9607
|
+
const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
|
|
9608
|
+
const childOptions = child.options || {};
|
|
9609
|
+
let zipEntryMetadata = {};
|
|
9610
|
+
let passThroughOptions = {};
|
|
9611
|
+
if (child.data instanceof Entry) {
|
|
9612
|
+
const {
|
|
9613
|
+
externalFileAttributes,
|
|
9614
|
+
versionMadeBy,
|
|
9615
|
+
comment,
|
|
9616
|
+
lastModDate,
|
|
9617
|
+
creationDate,
|
|
9618
|
+
lastAccessDate,
|
|
9619
|
+
uncompressedSize,
|
|
9620
|
+
encrypted,
|
|
9621
|
+
zipCrypto,
|
|
9622
|
+
crc32,
|
|
9623
|
+
compressionMethod,
|
|
9624
|
+
extraFieldAES,
|
|
9625
|
+
internalFileAttributes,
|
|
9626
|
+
extraField,
|
|
9627
|
+
uid,
|
|
9628
|
+
gid
|
|
9629
|
+
} = child.data;
|
|
9630
|
+
zipEntryMetadata = {
|
|
9631
|
+
externalFileAttributes,
|
|
9632
|
+
versionMadeBy,
|
|
9633
|
+
comment,
|
|
9634
|
+
lastModDate,
|
|
9635
|
+
creationDate,
|
|
9636
|
+
lastAccessDate,
|
|
9637
|
+
internalFileAttributes
|
|
9638
|
+
};
|
|
9639
|
+
const userExtraField = getUserExtraField(extraField);
|
|
9640
|
+
if (userExtraField) {
|
|
9641
|
+
zipEntryMetadata.extraField = userExtraField;
|
|
9642
|
+
}
|
|
9643
|
+
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
9644
|
+
Object.assign(zipEntryMetadata, {
|
|
9645
|
+
uid,
|
|
9646
|
+
gid,
|
|
9647
|
+
unixExtraFieldType: INFOZIP_EXTRA_FIELD_TYPE
|
|
9648
|
+
});
|
|
9649
|
+
}
|
|
9650
|
+
if (isPassThrough(child, options)) {
|
|
9651
|
+
let level, encryptionStrength;
|
|
9652
|
+
if (compressionMethod === 0) {
|
|
9653
|
+
level = 0;
|
|
9654
|
+
}
|
|
9655
|
+
if (extraFieldAES) {
|
|
9656
|
+
encryptionStrength = extraFieldAES.strength;
|
|
9657
|
+
}
|
|
9658
|
+
passThroughOptions = {
|
|
9659
|
+
passThrough: true,
|
|
9660
|
+
encrypted,
|
|
9661
|
+
zipCrypto,
|
|
9662
|
+
crc32,
|
|
9663
|
+
uncompressedSize,
|
|
9664
|
+
level,
|
|
9665
|
+
encryptionStrength,
|
|
9666
|
+
compressionMethod
|
|
9667
|
+
};
|
|
9668
|
+
}
|
|
9669
|
+
}
|
|
9670
|
+
const entryOptions = Object.assign({}, zipEntryMetadata, options, passThroughOptions, childOptions, { directory: child.directory });
|
|
9671
|
+
if (!child.directory && entryOptions.passThrough && entryOptions.uncompressedSize === UNDEFINED_VALUE) {
|
|
9672
|
+
throw new Error(ERR_INVALID_PASS_THROUGH);
|
|
9673
|
+
}
|
|
9674
|
+
return { name, entryOptions };
|
|
9675
|
+
}
|
|
9676
|
+
|
|
9677
|
+
function getDeterminedSize(child, passThrough) {
|
|
9678
|
+
const { reader } = child;
|
|
9679
|
+
if (reader && reader.size !== UNDEFINED_VALUE) {
|
|
9680
|
+
return reader.size;
|
|
9681
|
+
}
|
|
9682
|
+
return child.undeterminedSize ? UNDEFINED_VALUE : getExtractedSize(child, passThrough);
|
|
9683
|
+
}
|
|
9684
|
+
|
|
9685
|
+
function isPassThrough(child, options) {
|
|
9686
|
+
const { readerOptions } = options;
|
|
9687
|
+
return Boolean(!child.directory && (child.passThrough || (readerOptions && readerOptions.passThrough)));
|
|
9688
|
+
}
|
|
9689
|
+
|
|
9402
9690
|
function getUserExtraField(extraField) {
|
|
9403
9691
|
if (extraField) {
|
|
9404
9692
|
const userExtraField = new Map();
|
|
@@ -9414,8 +9702,14 @@
|
|
|
9414
9702
|
}
|
|
9415
9703
|
|
|
9416
9704
|
async function exportZip(zipWriter, entry, totalSize, options, readers) {
|
|
9705
|
+
const { onstart, onprogress, onend, onentryprogress } = options;
|
|
9417
9706
|
const selectedEntry = entry;
|
|
9418
|
-
const
|
|
9707
|
+
const totalEntries = getTotalSize(entry.children, () => 1);
|
|
9708
|
+
let writtenSize = 0;
|
|
9709
|
+
let writtenEntries = 0;
|
|
9710
|
+
if (onstart) {
|
|
9711
|
+
await callHandler(onstart, totalSize);
|
|
9712
|
+
}
|
|
9419
9713
|
if (options.bufferedWrite) {
|
|
9420
9714
|
await processChildren(entry);
|
|
9421
9715
|
} else {
|
|
@@ -9423,6 +9717,9 @@
|
|
|
9423
9717
|
await addChild(child);
|
|
9424
9718
|
}
|
|
9425
9719
|
}
|
|
9720
|
+
if (onend) {
|
|
9721
|
+
await callHandler(onend, writtenSize);
|
|
9722
|
+
}
|
|
9426
9723
|
|
|
9427
9724
|
async function processChildren(entry) {
|
|
9428
9725
|
const results = await Promise.allSettled(entry.children.map(async child => {
|
|
@@ -9436,81 +9733,23 @@
|
|
|
9436
9733
|
}
|
|
9437
9734
|
|
|
9438
9735
|
async function addChild(child) {
|
|
9439
|
-
const name
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
externalFileAttributes,
|
|
9445
|
-
versionMadeBy,
|
|
9446
|
-
comment,
|
|
9447
|
-
lastModDate,
|
|
9448
|
-
creationDate,
|
|
9449
|
-
lastAccessDate,
|
|
9450
|
-
uncompressedSize,
|
|
9451
|
-
encrypted,
|
|
9452
|
-
zipCrypto,
|
|
9453
|
-
crc32,
|
|
9454
|
-
compressionMethod,
|
|
9455
|
-
extraFieldAES,
|
|
9456
|
-
internalFileAttributes,
|
|
9457
|
-
extraField,
|
|
9458
|
-
uid,
|
|
9459
|
-
gid
|
|
9460
|
-
} = child.data;
|
|
9461
|
-
zipEntryOptions = {
|
|
9462
|
-
externalFileAttributes,
|
|
9463
|
-
versionMadeBy,
|
|
9464
|
-
comment,
|
|
9465
|
-
lastModDate,
|
|
9466
|
-
creationDate,
|
|
9467
|
-
lastAccessDate,
|
|
9468
|
-
internalFileAttributes
|
|
9469
|
-
};
|
|
9470
|
-
const userExtraField = getUserExtraField(extraField);
|
|
9471
|
-
if (userExtraField) {
|
|
9472
|
-
zipEntryOptions.extraField = userExtraField;
|
|
9473
|
-
}
|
|
9474
|
-
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
9475
|
-
Object.assign(zipEntryOptions, {
|
|
9476
|
-
uid,
|
|
9477
|
-
gid,
|
|
9478
|
-
unixExtraFieldType: options.unixExtraFieldType || INFOZIP_EXTRA_FIELD_TYPE
|
|
9479
|
-
});
|
|
9480
|
-
}
|
|
9481
|
-
if (child.passThrough) {
|
|
9482
|
-
let level, encryptionStrength;
|
|
9483
|
-
if (compressionMethod === 0) {
|
|
9484
|
-
level = 0;
|
|
9485
|
-
}
|
|
9486
|
-
if (extraFieldAES) {
|
|
9487
|
-
encryptionStrength = extraFieldAES.strength;
|
|
9488
|
-
}
|
|
9489
|
-
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
9490
|
-
passThrough: true,
|
|
9491
|
-
encrypted,
|
|
9492
|
-
zipCrypto,
|
|
9493
|
-
crc32,
|
|
9494
|
-
uncompressedSize,
|
|
9495
|
-
level,
|
|
9496
|
-
encryptionStrength,
|
|
9497
|
-
compressionMethod
|
|
9498
|
-
});
|
|
9499
|
-
}
|
|
9500
|
-
}
|
|
9501
|
-
await zipWriter.add(name, readers.get(child), Object.assign({}, options, zipEntryOptions, childOptions, {
|
|
9502
|
-
directory: child.directory,
|
|
9736
|
+
const { name, entryOptions } = getChildEntryOptions(child, selectedEntry, options);
|
|
9737
|
+
let entryWrittenSize = 0;
|
|
9738
|
+
const entryMetadata = await zipWriter.add(name, readers.get(child), Object.assign(entryOptions, {
|
|
9739
|
+
onstart: UNDEFINED_VALUE,
|
|
9740
|
+
onend: UNDEFINED_VALUE,
|
|
9503
9741
|
onprogress: async indexProgress => {
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
} catch {
|
|
9509
|
-
// ignored
|
|
9510
|
-
}
|
|
9742
|
+
writtenSize += indexProgress - entryWrittenSize;
|
|
9743
|
+
entryWrittenSize = indexProgress;
|
|
9744
|
+
if (onprogress) {
|
|
9745
|
+
await callHandler(onprogress, writtenSize, totalSize);
|
|
9511
9746
|
}
|
|
9512
9747
|
}
|
|
9513
9748
|
}));
|
|
9749
|
+
writtenEntries++;
|
|
9750
|
+
if (onentryprogress) {
|
|
9751
|
+
await callHandler(onentryprogress, writtenEntries, totalEntries, entryMetadata);
|
|
9752
|
+
}
|
|
9514
9753
|
}
|
|
9515
9754
|
}
|
|
9516
9755
|
|
|
@@ -9538,7 +9777,7 @@
|
|
|
9538
9777
|
})
|
|
9539
9778
|
);
|
|
9540
9779
|
} else if (handle.kind == "directory") {
|
|
9541
|
-
const directoryEntry = parentEntry.addDirectory(handle.name);
|
|
9780
|
+
const directoryEntry = parentEntry.addDirectory(handle.name, options);
|
|
9542
9781
|
addedEntries.push(directoryEntry);
|
|
9543
9782
|
for await (const childHandle of handle.values()) {
|
|
9544
9783
|
await addFile(directoryEntry, childHandle, addedEntries, entryName);
|
|
@@ -9560,15 +9799,29 @@
|
|
|
9560
9799
|
}
|
|
9561
9800
|
|
|
9562
9801
|
async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
|
|
9563
|
-
const
|
|
9564
|
-
const writtenSizes = new Map();
|
|
9802
|
+
const { onstart, onprogress, onend } = options;
|
|
9565
9803
|
const abortController = new AbortController();
|
|
9566
9804
|
const { signal } = abortController;
|
|
9567
9805
|
const releaseSignal = forwardAbort(options.signal, abortController);
|
|
9806
|
+
const getDataOptions = Object.assign({}, options, options.readerOptions, {
|
|
9807
|
+
signal,
|
|
9808
|
+
onstart: UNDEFINED_VALUE,
|
|
9809
|
+
onprogress: UNDEFINED_VALUE,
|
|
9810
|
+
onend: UNDEFINED_VALUE,
|
|
9811
|
+
preventClose: false
|
|
9812
|
+
});
|
|
9813
|
+
const totalSize = getTotalSize([zipEntry], entry => getExtractedSize(entry, getDataOptions.passThrough));
|
|
9568
9814
|
const exportedEntryNames = [];
|
|
9569
9815
|
let exportAborted = false;
|
|
9816
|
+
let writtenSize = 0;
|
|
9570
9817
|
try {
|
|
9818
|
+
if (onstart) {
|
|
9819
|
+
await callHandler(onstart, totalSize);
|
|
9820
|
+
}
|
|
9571
9821
|
await exportChildren(zipEntry, directoryHandle);
|
|
9822
|
+
if (onend) {
|
|
9823
|
+
await callHandler(onend, writtenSize);
|
|
9824
|
+
}
|
|
9572
9825
|
} catch (error) {
|
|
9573
9826
|
try {
|
|
9574
9827
|
error.exportedEntryNames = exportedEntryNames;
|
|
@@ -9581,6 +9834,25 @@
|
|
|
9581
9834
|
}
|
|
9582
9835
|
return directoryHandle;
|
|
9583
9836
|
|
|
9837
|
+
function createProgressWritable(writable) {
|
|
9838
|
+
const writer = writable.getWriter();
|
|
9839
|
+
return new WritableStream({
|
|
9840
|
+
async write(chunk) {
|
|
9841
|
+
await writer.write(chunk);
|
|
9842
|
+
writtenSize += chunk.length;
|
|
9843
|
+
if (onprogress) {
|
|
9844
|
+
await callHandler(onprogress, writtenSize, totalSize);
|
|
9845
|
+
}
|
|
9846
|
+
},
|
|
9847
|
+
close() {
|
|
9848
|
+
return writer.close();
|
|
9849
|
+
},
|
|
9850
|
+
abort(reason) {
|
|
9851
|
+
return writer.abort(reason);
|
|
9852
|
+
}
|
|
9853
|
+
});
|
|
9854
|
+
}
|
|
9855
|
+
|
|
9584
9856
|
async function exportChildren(entry, parentHandle) {
|
|
9585
9857
|
if (options.concurrent) {
|
|
9586
9858
|
const results = await Promise.allSettled(entry.children.map(child => exportChild(child, parentHandle)));
|
|
@@ -9612,19 +9884,7 @@
|
|
|
9612
9884
|
const fileHandle = await parentHandle.getFileHandle(child.name, { create: true });
|
|
9613
9885
|
const writable = await fileHandle.createWritable();
|
|
9614
9886
|
try {
|
|
9615
|
-
await child.getData({ writable
|
|
9616
|
-
signal,
|
|
9617
|
-
onprogress: async progress => {
|
|
9618
|
-
if (options.onprogress) {
|
|
9619
|
-
writtenSizes.set(child.id, progress);
|
|
9620
|
-
try {
|
|
9621
|
-
await options.onprogress(Array.from(writtenSizes.values()).reduce((previousValue, currentValue) => previousValue + currentValue, 0), totalSize);
|
|
9622
|
-
} catch {
|
|
9623
|
-
// ignored
|
|
9624
|
-
}
|
|
9625
|
-
}
|
|
9626
|
-
}
|
|
9627
|
-
}));
|
|
9887
|
+
await child.getData({ writable: createProgressWritable(writable) }, getDataOptions);
|
|
9628
9888
|
} catch (error) {
|
|
9629
9889
|
throw exportAborted ? new Error(ERR_ABORT_EXPORT) : error;
|
|
9630
9890
|
}
|
|
@@ -9868,6 +10128,7 @@
|
|
|
9868
10128
|
exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
|
|
9869
10129
|
exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
|
|
9870
10130
|
exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
|
|
10131
|
+
exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
|
|
9871
10132
|
exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
|
|
9872
10133
|
exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
|
|
9873
10134
|
exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
|
|
@@ -9885,11 +10146,13 @@
|
|
|
9885
10146
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
9886
10147
|
exports.ERR_UNDEFINED_READER = ERR_UNDEFINED_READER;
|
|
9887
10148
|
exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
|
|
10149
|
+
exports.ERR_UNDETERMINED_SIZE = ERR_UNDETERMINED_SIZE;
|
|
9888
10150
|
exports.ERR_UNSAFE_FILENAME = ERR_UNSAFE_FILENAME;
|
|
9889
10151
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION$1;
|
|
9890
10152
|
exports.ERR_UNSUPPORTED_CONTEXT = ERR_UNSUPPORTED_CONTEXT;
|
|
9891
10153
|
exports.ERR_UNSUPPORTED_CRYPTO_API = ERR_UNSUPPORTED_CRYPTO_API;
|
|
9892
10154
|
exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
|
|
10155
|
+
exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
|
|
9893
10156
|
exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
|
|
9894
10157
|
exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
|
|
9895
10158
|
exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
|