@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-native.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() {
|
|
@@ -3350,8 +3347,10 @@
|
|
|
3350
3347
|
async pull(controller) {
|
|
3351
3348
|
const dataSize = size === UNDEFINED_VALUE ? chunkSize : Math.min(chunkSize, size - chunkOffset);
|
|
3352
3349
|
const data = await readUint8Array(reader, offset + chunkOffset, dataSize);
|
|
3353
|
-
|
|
3354
|
-
|
|
3350
|
+
if (data.length) {
|
|
3351
|
+
controller.enqueue(data);
|
|
3352
|
+
}
|
|
3353
|
+
if ((chunkOffset + chunkSize >= size) || (size === UNDEFINED_VALUE && !data.length && dataSize)) {
|
|
3355
3354
|
controller.close();
|
|
3356
3355
|
} else {
|
|
3357
3356
|
chunkOffset += chunkSize;
|
|
@@ -3429,6 +3428,7 @@
|
|
|
3429
3428
|
constructor(contentType) {
|
|
3430
3429
|
super();
|
|
3431
3430
|
Object.assign(this, {
|
|
3431
|
+
contentType,
|
|
3432
3432
|
data: "data:" + (contentType || "") + ";base64,",
|
|
3433
3433
|
pending: []
|
|
3434
3434
|
});
|
|
@@ -3530,6 +3530,7 @@
|
|
|
3530
3530
|
return transformStream.writable;
|
|
3531
3531
|
}
|
|
3532
3532
|
});
|
|
3533
|
+
writer.contentType = contentType;
|
|
3533
3534
|
writer.blob = streamToBlob(transformStream.readable, contentType);
|
|
3534
3535
|
writer.blob.catch(() => { });
|
|
3535
3536
|
}
|
|
@@ -3546,6 +3547,26 @@
|
|
|
3546
3547
|
}
|
|
3547
3548
|
}
|
|
3548
3549
|
|
|
3550
|
+
function getTextSize(text) {
|
|
3551
|
+
let size = 0;
|
|
3552
|
+
for (let indexCharacter = 0; indexCharacter < text.length; indexCharacter++) {
|
|
3553
|
+
const characterCode = text.charCodeAt(indexCharacter);
|
|
3554
|
+
if (characterCode < 0x80) {
|
|
3555
|
+
size += 1;
|
|
3556
|
+
} else if (characterCode < 0x800) {
|
|
3557
|
+
size += 2;
|
|
3558
|
+
} else if (characterCode < 0xd800 || characterCode >= 0xe000) {
|
|
3559
|
+
size += 3;
|
|
3560
|
+
} else if (characterCode < 0xdc00 && (text.charCodeAt(indexCharacter + 1) & 0xfc00) == 0xdc00) {
|
|
3561
|
+
size += 4;
|
|
3562
|
+
indexCharacter++;
|
|
3563
|
+
} else {
|
|
3564
|
+
size += 3;
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
return size;
|
|
3568
|
+
}
|
|
3569
|
+
|
|
3549
3570
|
class TextWriter extends BlobWriter {
|
|
3550
3571
|
|
|
3551
3572
|
constructor(encoding) {
|
|
@@ -4209,6 +4230,10 @@
|
|
|
4209
4230
|
}
|
|
4210
4231
|
}
|
|
4211
4232
|
|
|
4233
|
+
function ownsWritable(writer) {
|
|
4234
|
+
return Boolean(writer && writer.getData);
|
|
4235
|
+
}
|
|
4236
|
+
|
|
4212
4237
|
function isHttpFamily(url) {
|
|
4213
4238
|
const { baseURI } = getConfiguration();
|
|
4214
4239
|
const { protocol } = new URL(url, baseURI);
|
|
@@ -4353,6 +4378,8 @@
|
|
|
4353
4378
|
const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
|
|
4354
4379
|
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES = "internalFileAttributes";
|
|
4355
4380
|
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttributes";
|
|
4381
|
+
const PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES = "internalFileAttribute";
|
|
4382
|
+
const PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttribute";
|
|
4356
4383
|
const PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW = "msdosAttributesRaw";
|
|
4357
4384
|
const PROPERTY_NAME_MSDOS_ATTRIBUTES = "msdosAttributes";
|
|
4358
4385
|
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
@@ -4363,6 +4390,7 @@
|
|
|
4363
4390
|
const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
|
|
4364
4391
|
const PROPERTY_NAME_DIRECTORY = "directory";
|
|
4365
4392
|
const PROPERTY_NAME_EXECUTABLE = "executable";
|
|
4393
|
+
const PROPERTY_NAME_SYMLINK = "symlink";
|
|
4366
4394
|
const PROPERTY_NAME_COMPRESSION_METHOD = "compressionMethod";
|
|
4367
4395
|
const PROPERTY_NAME_SIGNATURE = "signature";
|
|
4368
4396
|
const PROPERTY_NAME_CRC32 = "crc32";
|
|
@@ -4406,6 +4434,8 @@
|
|
|
4406
4434
|
PROPERTY_NAME_DISK_NUMBER_START,
|
|
4407
4435
|
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
|
|
4408
4436
|
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
|
|
4437
|
+
PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES,
|
|
4438
|
+
PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES,
|
|
4409
4439
|
PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW,
|
|
4410
4440
|
PROPERTY_NAME_MSDOS_ATTRIBUTES,
|
|
4411
4441
|
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
@@ -4416,6 +4446,7 @@
|
|
|
4416
4446
|
PROPERTY_NAME_ZIPCRYPTO,
|
|
4417
4447
|
PROPERTY_NAME_DIRECTORY,
|
|
4418
4448
|
PROPERTY_NAME_EXECUTABLE,
|
|
4449
|
+
PROPERTY_NAME_SYMLINK,
|
|
4419
4450
|
PROPERTY_NAME_COMPRESSION_METHOD,
|
|
4420
4451
|
PROPERTY_NAME_SIGNATURE,
|
|
4421
4452
|
PROPERTY_NAME_CRC32,
|
|
@@ -4878,15 +4909,18 @@
|
|
|
4878
4909
|
const setuid = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_SETUID_MASK);
|
|
4879
4910
|
const setgid = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_SETGID_MASK);
|
|
4880
4911
|
const sticky = Boolean(fileEntry.unixMode & FILE_ATTR_UNIX_STICKY_MASK);
|
|
4881
|
-
const
|
|
4912
|
+
const unixType = fileEntry.unixMode === UNDEFINED_VALUE ? unixExternalUpper : fileEntry.unixMode;
|
|
4913
|
+
const symlink = (unixType & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_SYMLINK;
|
|
4914
|
+
const executable = !symlink && ((fileEntry.unixMode !== UNDEFINED_VALUE)
|
|
4882
4915
|
? ((fileEntry.unixMode & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)
|
|
4883
|
-
: (unixCompatible && ((unixExternalUpper & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0));
|
|
4916
|
+
: (unixCompatible && ((unixExternalUpper & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0)));
|
|
4884
4917
|
const modeIsDir = fileEntry.unixMode !== UNDEFINED_VALUE && ((fileEntry.unixMode & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR);
|
|
4885
4918
|
const upperIsDir = ((unixExternalUpper & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR);
|
|
4886
4919
|
Object.assign(fileEntry, {
|
|
4887
4920
|
setuid,
|
|
4888
4921
|
setgid,
|
|
4889
4922
|
sticky,
|
|
4923
|
+
symlink,
|
|
4890
4924
|
unixExternalUpper,
|
|
4891
4925
|
internalFileAttribute: fileEntry.internalFileAttributes,
|
|
4892
4926
|
externalFileAttribute: fileEntry.externalFileAttributes,
|
|
@@ -4952,6 +4986,10 @@
|
|
|
4952
4986
|
}
|
|
4953
4987
|
|
|
4954
4988
|
async close() {
|
|
4989
|
+
const { reader } = this;
|
|
4990
|
+
if (!reader.readUint8Array && reader.readable && !reader.readable.locked) {
|
|
4991
|
+
await reader.readable.cancel();
|
|
4992
|
+
}
|
|
4955
4993
|
}
|
|
4956
4994
|
}
|
|
4957
4995
|
|
|
@@ -5176,7 +5214,7 @@
|
|
|
5176
5214
|
throw error;
|
|
5177
5215
|
}
|
|
5178
5216
|
} finally {
|
|
5179
|
-
const preventClose = getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5217
|
+
const preventClose = !ownsWritable(writer) && getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
|
|
5180
5218
|
if (!preventClose && writable && !writable.locked) {
|
|
5181
5219
|
const writableWriter = writable.getWriter();
|
|
5182
5220
|
if (abortError) {
|
|
@@ -5420,8 +5458,8 @@
|
|
|
5420
5458
|
return;
|
|
5421
5459
|
}
|
|
5422
5460
|
const extraFieldView = getDataView(extraField.data);
|
|
5423
|
-
const lastAccessDate = new Date(getUint32(extraFieldView, 0) * 1000);
|
|
5424
|
-
const lastModDate = new Date(getUint32(extraFieldView, 4) * 1000);
|
|
5461
|
+
const lastAccessDate = new Date((getUint32(extraFieldView, 0) | 0) * 1000);
|
|
5462
|
+
const lastModDate = new Date((getUint32(extraFieldView, 4) | 0) * 1000);
|
|
5425
5463
|
const extraFieldData = { lastAccessDate, lastModDate };
|
|
5426
5464
|
if (extraField.data.length >= 12) {
|
|
5427
5465
|
extraFieldData.uid = getUint16(extraFieldView, 8);
|
|
@@ -5852,6 +5890,7 @@
|
|
|
5852
5890
|
const ERR_INVALID_VERSION = "Version exceeds 65535";
|
|
5853
5891
|
const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
|
|
5854
5892
|
const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
|
|
5893
|
+
const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
|
|
5855
5894
|
const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
|
|
5856
5895
|
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
5857
5896
|
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
@@ -5861,6 +5900,7 @@
|
|
|
5861
5900
|
const MAX_NTFS_TIME = BigInt("0x7fffffffffffffff");
|
|
5862
5901
|
const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
|
|
5863
5902
|
const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
|
|
5903
|
+
const ERR_UNDETERMINED_SIZE = "Undetermined size";
|
|
5864
5904
|
const ERR_UNDEFINED_READER = "Undefined reader";
|
|
5865
5905
|
const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
|
|
5866
5906
|
const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
|
|
@@ -6068,7 +6108,7 @@
|
|
|
6068
6108
|
await Promise.allSettled(Array.from(pendingAddFileCalls));
|
|
6069
6109
|
}
|
|
6070
6110
|
await closeFile(zipWriter, comment, options);
|
|
6071
|
-
const preventClose = getOptionValue(zipWriter, options, OPTION_PREVENT_CLOSE);
|
|
6111
|
+
const preventClose = !ownsWritable(writer) && getOptionValue(zipWriter, options, OPTION_PREVENT_CLOSE);
|
|
6072
6112
|
if (!preventClose) {
|
|
6073
6113
|
await writable.getWriter().close();
|
|
6074
6114
|
}
|
|
@@ -6227,7 +6267,7 @@
|
|
|
6227
6267
|
if (versionMadeBy > MAX_16_BITS) {
|
|
6228
6268
|
throw new Error(ERR_INVALID_VERSION);
|
|
6229
6269
|
}
|
|
6230
|
-
let externalFileAttributes =
|
|
6270
|
+
let externalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES);
|
|
6231
6271
|
const externalFileAttributesProvided = externalFileAttributes !== UNDEFINED_VALUE;
|
|
6232
6272
|
if (!externalFileAttributesProvided) {
|
|
6233
6273
|
externalFileAttributes = 0;
|
|
@@ -6275,7 +6315,9 @@
|
|
|
6275
6315
|
}
|
|
6276
6316
|
if (!externalFileAttributesProvided || unixModeProvided) {
|
|
6277
6317
|
if (directory) {
|
|
6278
|
-
unixMode
|
|
6318
|
+
unixMode = (unixMode & ~FILE_ATTR_UNIX_TYPE_MASK) | FILE_ATTR_UNIX_TYPE_DIR;
|
|
6319
|
+
} else if (!(unixMode & FILE_ATTR_UNIX_TYPE_MASK)) {
|
|
6320
|
+
unixMode |= FILE_ATTR_UNIX_TYPE_FILE;
|
|
6279
6321
|
}
|
|
6280
6322
|
externalFileAttributes = ((unixMode & MAX_16_BITS) << 16) | (externalFileAttributes & MAX_16_BITS);
|
|
6281
6323
|
}
|
|
@@ -6328,15 +6370,12 @@
|
|
|
6328
6370
|
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
|
|
6329
6371
|
const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
6330
6372
|
const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
6331
|
-
const internalFileAttributes =
|
|
6373
|
+
const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
|
|
6332
6374
|
const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
|
|
6338
|
-
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
6339
|
-
}
|
|
6375
|
+
const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
6376
|
+
const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
6377
|
+
if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
|
|
6378
|
+
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
6340
6379
|
}
|
|
6341
6380
|
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
6342
6381
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
@@ -6449,14 +6488,24 @@
|
|
|
6449
6488
|
}
|
|
6450
6489
|
|
|
6451
6490
|
async function resolveSizes(zipWriter, reader, { resolvedOptions: metadata }, options) {
|
|
6491
|
+
if (metadata.passThrough && !reader && !getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY)) {
|
|
6492
|
+
throw new Error(ERR_UNDEFINED_READER);
|
|
6493
|
+
}
|
|
6494
|
+
let contentSize;
|
|
6495
|
+
if (reader) {
|
|
6496
|
+
reader = new GenericReader(reader);
|
|
6497
|
+
await initStream(reader);
|
|
6498
|
+
({ size: contentSize } = reader);
|
|
6499
|
+
}
|
|
6500
|
+
return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
|
|
6501
|
+
}
|
|
6502
|
+
|
|
6503
|
+
function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options) {
|
|
6452
6504
|
const { passThrough, zipCrypto, password, rawPassword, encryptionStrength } = metadata;
|
|
6453
6505
|
let { dataDescriptor, zip64, level, compressionMethod } = metadata;
|
|
6454
6506
|
let maximumCompressedSize = 0;
|
|
6455
6507
|
let uncompressedSize = 0;
|
|
6456
|
-
if (passThrough) {
|
|
6457
|
-
if (!reader) {
|
|
6458
|
-
throw new Error(ERR_UNDEFINED_READER);
|
|
6459
|
-
}
|
|
6508
|
+
if (passThrough && hasContent) {
|
|
6460
6509
|
uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
|
|
6461
6510
|
if (uncompressedSize === UNDEFINED_VALUE) {
|
|
6462
6511
|
throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
|
|
@@ -6464,29 +6513,30 @@
|
|
|
6464
6513
|
}
|
|
6465
6514
|
const zip64Enabled = zip64 === true;
|
|
6466
6515
|
const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
|
|
6467
|
-
|
|
6468
|
-
|
|
6516
|
+
if (hasContent && passThrough && !encrypted && getLength(password, rawPassword)) {
|
|
6517
|
+
throw new Error(ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH);
|
|
6518
|
+
}
|
|
6519
|
+
const encryptedEntry = hasContent && (Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted));
|
|
6520
|
+
if (!hasContent) {
|
|
6469
6521
|
level = 0;
|
|
6470
6522
|
compressionMethod = COMPRESSION_METHOD_STORE;
|
|
6471
6523
|
}
|
|
6472
6524
|
const encryptionOverhead = encryptedEntry ? (zipCrypto ? 12 : 16 + encryptionStrength * 4) : 0;
|
|
6473
|
-
if (
|
|
6474
|
-
reader = new GenericReader(reader);
|
|
6475
|
-
await initStream(reader);
|
|
6525
|
+
if (hasContent) {
|
|
6476
6526
|
if (!passThrough) {
|
|
6477
|
-
if (
|
|
6527
|
+
if (contentSize === UNDEFINED_VALUE) {
|
|
6478
6528
|
dataDescriptor = true;
|
|
6479
6529
|
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
6480
6530
|
zip64 = true;
|
|
6481
6531
|
uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
|
|
6482
6532
|
}
|
|
6483
6533
|
} else {
|
|
6484
|
-
options.uncompressedSize = uncompressedSize =
|
|
6485
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize) + encryptionOverhead;
|
|
6534
|
+
options.uncompressedSize = uncompressedSize = contentSize;
|
|
6535
|
+
maximumCompressedSize = (isCompressed(compressionMethod, level) ? getMaximumCompressedSize(uncompressedSize) : uncompressedSize) + encryptionOverhead;
|
|
6486
6536
|
}
|
|
6487
6537
|
} else {
|
|
6488
6538
|
options.uncompressedSize = uncompressedSize;
|
|
6489
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize) + encryptionOverhead;
|
|
6539
|
+
maximumCompressedSize = contentSize === UNDEFINED_VALUE ? getMaximumCompressedSize(uncompressedSize) + encryptionOverhead : contentSize;
|
|
6490
6540
|
}
|
|
6491
6541
|
}
|
|
6492
6542
|
const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
|
|
@@ -6500,7 +6550,7 @@
|
|
|
6500
6550
|
}
|
|
6501
6551
|
zip64 = zip64 || false;
|
|
6502
6552
|
return {
|
|
6503
|
-
|
|
6553
|
+
maximumCompressedSize,
|
|
6504
6554
|
resolvedOptions: {
|
|
6505
6555
|
dataDescriptor,
|
|
6506
6556
|
zip64,
|
|
@@ -6514,6 +6564,78 @@
|
|
|
6514
6564
|
};
|
|
6515
6565
|
}
|
|
6516
6566
|
|
|
6567
|
+
async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comment) {
|
|
6568
|
+
const zipWriter = { options: writerOptions, config: getConfiguration() };
|
|
6569
|
+
if (writerOptions[OPTION_SIGN_CENTRAL_DIRECTORY]) {
|
|
6570
|
+
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
6571
|
+
}
|
|
6572
|
+
const commentLength = getLength(comment);
|
|
6573
|
+
if (commentLength > MAX_16_BITS) {
|
|
6574
|
+
throw new Error(ERR_INVALID_COMMENT);
|
|
6575
|
+
}
|
|
6576
|
+
const usdz = writerOptions[OPTION_USDZ];
|
|
6577
|
+
const files = new Map();
|
|
6578
|
+
let layoutDependsOnWriteOrder = Boolean(usdz);
|
|
6579
|
+
let offset = 0;
|
|
6580
|
+
for (const entry of entries) {
|
|
6581
|
+
let { name } = entry;
|
|
6582
|
+
const { size } = entry;
|
|
6583
|
+
const options = Object.assign({}, entry.options);
|
|
6584
|
+
name = name.trim();
|
|
6585
|
+
if (getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY) && !name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
6586
|
+
name += DIRECTORY_SIGNATURE;
|
|
6587
|
+
}
|
|
6588
|
+
const attributesInfo = resolveAttributes(zipWriter, name, options);
|
|
6589
|
+
({ name } = attributesInfo);
|
|
6590
|
+
const { resolvedOptions: metadata } = resolveMetadata(zipWriter, name, options);
|
|
6591
|
+
if (metadata.level != 0 && metadata.compressionMethod === UNDEFINED_VALUE &&
|
|
6592
|
+
!metadata.passThrough && !(await supportsDeflate(zipWriter.config))) {
|
|
6593
|
+
metadata.level = 0;
|
|
6594
|
+
}
|
|
6595
|
+
const hasContent = !getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY);
|
|
6596
|
+
if (hasContent && size === UNDEFINED_VALUE) {
|
|
6597
|
+
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
6598
|
+
}
|
|
6599
|
+
const { maximumCompressedSize, resolvedOptions: sizes } = resolveEntrySizes(zipWriter, hasContent, size, metadata, options);
|
|
6600
|
+
if (hasContent && !metadata.passThrough && isCompressed(sizes.compressionMethod, sizes.level)) {
|
|
6601
|
+
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
6602
|
+
}
|
|
6603
|
+
const entryOptions = Object.assign({}, options, attributesInfo.resolvedOptions, metadata, sizes);
|
|
6604
|
+
const headerInfo = getHeaderInfo(entryOptions);
|
|
6605
|
+
const dataDescriptorInfo = getDataDescriptorInfo(entryOptions);
|
|
6606
|
+
const entryInfo = {
|
|
6607
|
+
headerInfo,
|
|
6608
|
+
metadataSize: getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray)
|
|
6609
|
+
};
|
|
6610
|
+
if (usdz) {
|
|
6611
|
+
appendExtraFieldUSDZ(entryInfo, offset);
|
|
6612
|
+
}
|
|
6613
|
+
const compressedSize = hasContent ? maximumCompressedSize : 0;
|
|
6614
|
+
if (offset >= MAX_32_BITS) {
|
|
6615
|
+
layoutDependsOnWriteOrder = true;
|
|
6616
|
+
}
|
|
6617
|
+
files.set(name, Object.assign({}, entryOptions, headerInfo, {
|
|
6618
|
+
offset,
|
|
6619
|
+
diskNumberStart: 0,
|
|
6620
|
+
compressedSize
|
|
6621
|
+
}));
|
|
6622
|
+
offset += entryInfo.metadataSize + compressedSize;
|
|
6623
|
+
}
|
|
6624
|
+
if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
|
|
6625
|
+
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
6626
|
+
}
|
|
6627
|
+
const directoryDataLength = createDirectoryRecords(files);
|
|
6628
|
+
let zip64 = getOptionValue(zipWriter, writerOptions, PROPERTY_NAME_ZIP64);
|
|
6629
|
+
if (offset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || files.size >= MAX_16_BITS) {
|
|
6630
|
+
if (zip64 === false) {
|
|
6631
|
+
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
6632
|
+
} else {
|
|
6633
|
+
zip64 = true;
|
|
6634
|
+
}
|
|
6635
|
+
}
|
|
6636
|
+
return offset + directoryDataLength + commentLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
|
|
6637
|
+
}
|
|
6638
|
+
|
|
6517
6639
|
async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
6518
6640
|
const {
|
|
6519
6641
|
files,
|
|
@@ -6885,9 +7007,7 @@
|
|
|
6885
7007
|
crc32
|
|
6886
7008
|
} = options;
|
|
6887
7009
|
let { version, compressionMethod } = options;
|
|
6888
|
-
const compressed = !directory && (compressionMethod
|
|
6889
|
-
? (level === UNDEFINED_VALUE || level > 0)
|
|
6890
|
-
: compressionMethod !== COMPRESSION_METHOD_STORE);
|
|
7010
|
+
const compressed = !directory && isCompressed(compressionMethod, level);
|
|
6891
7011
|
let rawLocalExtraFieldZip64;
|
|
6892
7012
|
const uncompressedFile = passThrough || !compressed;
|
|
6893
7013
|
const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
|
|
@@ -7574,6 +7694,16 @@
|
|
|
7574
7694
|
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7575
7695
|
}
|
|
7576
7696
|
|
|
7697
|
+
function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
|
|
7698
|
+
const value = getAliasedValue(options, name, deprecatedName);
|
|
7699
|
+
const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
|
|
7700
|
+
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7701
|
+
}
|
|
7702
|
+
|
|
7703
|
+
function getAliasedValue(options, name, deprecatedName) {
|
|
7704
|
+
return options[name] === UNDEFINED_VALUE ? options[deprecatedName] : options[name];
|
|
7705
|
+
}
|
|
7706
|
+
|
|
7577
7707
|
function getNumberOptionValue(zipWriter, options, name, defaultValue) {
|
|
7578
7708
|
return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
|
|
7579
7709
|
}
|
|
@@ -7586,6 +7716,12 @@
|
|
|
7586
7716
|
return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
|
|
7587
7717
|
}
|
|
7588
7718
|
|
|
7719
|
+
function isCompressed(compressionMethod, level) {
|
|
7720
|
+
return compressionMethod === UNDEFINED_VALUE
|
|
7721
|
+
? (level === UNDEFINED_VALUE || level > 0)
|
|
7722
|
+
: compressionMethod !== COMPRESSION_METHOD_STORE;
|
|
7723
|
+
}
|
|
7724
|
+
|
|
7589
7725
|
function setUint8(view, offset, value) {
|
|
7590
7726
|
view.setUint8(offset, value);
|
|
7591
7727
|
}
|
|
@@ -8234,6 +8370,7 @@
|
|
|
8234
8370
|
|
|
8235
8371
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
8236
8372
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
8373
|
+
const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
|
|
8237
8374
|
const ERR_ABORT_EXPORT = "zipjs-abort-export";
|
|
8238
8375
|
const ERR_ABORTED = "The operation was aborted";
|
|
8239
8376
|
const ABORT_ERROR_NAME = "AbortError";
|
|
@@ -8271,6 +8408,7 @@
|
|
|
8271
8408
|
parent,
|
|
8272
8409
|
children: [],
|
|
8273
8410
|
uncompressedSize: params.uncompressedSize || 0,
|
|
8411
|
+
undeterminedSize: params.undeterminedSize || params.uncompressedSize === UNDEFINED_VALUE,
|
|
8274
8412
|
passThrough: params.passThrough
|
|
8275
8413
|
});
|
|
8276
8414
|
if (parent || !fs.root) {
|
|
@@ -8338,16 +8476,17 @@
|
|
|
8338
8476
|
|
|
8339
8477
|
async getData(writer, options = {}) {
|
|
8340
8478
|
const zipEntry = this;
|
|
8341
|
-
if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data)) {
|
|
8479
|
+
if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data && keepsContentType(writer, zipEntry.data))) {
|
|
8342
8480
|
return zipEntry.data;
|
|
8343
8481
|
} else {
|
|
8344
8482
|
const reader = zipEntry.reader = createReader(zipEntry.Reader, zipEntry.data, options);
|
|
8345
|
-
const
|
|
8346
|
-
await Promise.all([initStream(reader), initStream(writer,
|
|
8347
|
-
const { readable } = reader;
|
|
8483
|
+
const dataSize = zipEntry.uncompressedSize || reader.size;
|
|
8484
|
+
await Promise.all([initStream(reader), initStream(writer, dataSize)]);
|
|
8348
8485
|
const { signal } = options;
|
|
8486
|
+
const readable = createProgressReadable(zipEntry, reader, options, signal);
|
|
8487
|
+
const preventClose = !ownsWritable(writer) && Boolean(options.preventClose);
|
|
8349
8488
|
zipEntry.uncompressedSize = reader.size;
|
|
8350
|
-
await toCompatibleReadable(readable).pipeTo(toCompatibleWritable(writer.writable), { signal });
|
|
8489
|
+
await toCompatibleReadable(readable).pipeTo(toCompatibleWritable(writer.writable), { signal, preventClose, preventAbort: preventClose });
|
|
8351
8490
|
return writer.getData ? writer.getData() : writer.writable;
|
|
8352
8491
|
}
|
|
8353
8492
|
}
|
|
@@ -8478,7 +8617,7 @@
|
|
|
8478
8617
|
Reader: TextReader,
|
|
8479
8618
|
Writer: TextWriter,
|
|
8480
8619
|
options,
|
|
8481
|
-
uncompressedSize: text
|
|
8620
|
+
uncompressedSize: getTextSize(text)
|
|
8482
8621
|
});
|
|
8483
8622
|
}
|
|
8484
8623
|
|
|
@@ -8607,10 +8746,16 @@
|
|
|
8607
8746
|
}
|
|
8608
8747
|
|
|
8609
8748
|
async importZip(reader, options = {}) {
|
|
8610
|
-
|
|
8611
|
-
|
|
8749
|
+
let zipReader;
|
|
8750
|
+
if (reader && typeof reader.getEntries == FUNCTION_TYPE) {
|
|
8751
|
+
zipReader = reader;
|
|
8752
|
+
options = Object.assign({}, zipReader.options, options);
|
|
8753
|
+
} else {
|
|
8754
|
+
await initStream(reader);
|
|
8755
|
+
zipReader = new ZipReader(reader, options);
|
|
8756
|
+
}
|
|
8612
8757
|
const importedEntries = [];
|
|
8613
|
-
const entries = await zipReader.getEntries();
|
|
8758
|
+
const entries = await zipReader.getEntries(options);
|
|
8614
8759
|
for (const entry of entries) {
|
|
8615
8760
|
let parent = this;
|
|
8616
8761
|
try {
|
|
@@ -8632,7 +8777,7 @@
|
|
|
8632
8777
|
importedEntries.push(addChild(parent, name, {
|
|
8633
8778
|
data: entry,
|
|
8634
8779
|
Reader: getZipBlobReader(Object.assign({}, options)),
|
|
8635
|
-
uncompressedSize: entry.uncompressedSize,
|
|
8780
|
+
uncompressedSize: options.passThrough ? entry.compressedSize : entry.uncompressedSize,
|
|
8636
8781
|
passThrough: options.passThrough
|
|
8637
8782
|
}));
|
|
8638
8783
|
} else {
|
|
@@ -8674,11 +8819,25 @@
|
|
|
8674
8819
|
}
|
|
8675
8820
|
const [readers] = await Promise.all([initReaders(zipEntry, options.readerOptions), initStream(writer)]);
|
|
8676
8821
|
const zipWriter = new ZipWriter(writer, options);
|
|
8677
|
-
await exportZip(zipWriter, zipEntry, getTotalSize([zipEntry],
|
|
8678
|
-
await zipWriter.close();
|
|
8822
|
+
await exportZip(zipWriter, zipEntry, getTotalSize([zipEntry], getUncompressedSize), options, readers);
|
|
8823
|
+
await zipWriter.close(options.globalComment);
|
|
8679
8824
|
return writer.getData ? writer.getData() : writer.writable;
|
|
8680
8825
|
}
|
|
8681
8826
|
|
|
8827
|
+
getExportedSize(options = {}) {
|
|
8828
|
+
const zipEntry = this;
|
|
8829
|
+
options = Object.assign({}, options);
|
|
8830
|
+
if (options.bufferedWrite === UNDEFINED_VALUE) {
|
|
8831
|
+
options.bufferedWrite = true;
|
|
8832
|
+
}
|
|
8833
|
+
const writeOrderGuaranteed = !options.bufferedWrite ||
|
|
8834
|
+
(options.keepOrder !== false && zipEntry.children.every(child => !child.children.length));
|
|
8835
|
+
return getEntriesSize(options, Array.from(zipEntry.getChildren({ recursive: true }), child => {
|
|
8836
|
+
const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
|
|
8837
|
+
return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
|
|
8838
|
+
}), writeOrderGuaranteed, options.globalComment);
|
|
8839
|
+
}
|
|
8840
|
+
|
|
8682
8841
|
getChildByName(name) {
|
|
8683
8842
|
const children = this.children;
|
|
8684
8843
|
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
@@ -8886,6 +9045,10 @@
|
|
|
8886
9045
|
return this.root.exportZip(writer, options);
|
|
8887
9046
|
}
|
|
8888
9047
|
|
|
9048
|
+
getExportedSize(options) {
|
|
9049
|
+
return this.root.getExportedSize(options);
|
|
9050
|
+
}
|
|
9051
|
+
|
|
8889
9052
|
isPasswordProtected() {
|
|
8890
9053
|
return this.root.isPasswordProtected();
|
|
8891
9054
|
}
|
|
@@ -8897,12 +9060,12 @@
|
|
|
8897
9060
|
|
|
8898
9061
|
const fs = { FS, ZipDirectoryEntry, ZipFileEntry };
|
|
8899
9062
|
|
|
8900
|
-
function getTotalSize(entries,
|
|
9063
|
+
function getTotalSize(entries, getEntrySize) {
|
|
8901
9064
|
let size = 0;
|
|
8902
9065
|
const pendingEntries = Array.from(entries);
|
|
8903
9066
|
while (pendingEntries.length) {
|
|
8904
9067
|
const entry = pendingEntries.pop();
|
|
8905
|
-
size += entry
|
|
9068
|
+
size += getEntrySize(entry) || 0;
|
|
8906
9069
|
for (const child of entry.children) {
|
|
8907
9070
|
pendingEntries.push(child);
|
|
8908
9071
|
}
|
|
@@ -8910,6 +9073,15 @@
|
|
|
8910
9073
|
return size;
|
|
8911
9074
|
}
|
|
8912
9075
|
|
|
9076
|
+
function getUncompressedSize(entry) {
|
|
9077
|
+
return entry.uncompressedSize;
|
|
9078
|
+
}
|
|
9079
|
+
|
|
9080
|
+
function getExtractedSize(entry, passThrough) {
|
|
9081
|
+
const { data } = entry;
|
|
9082
|
+
return passThrough && data instanceof Entry ? data.compressedSize : entry.uncompressedSize;
|
|
9083
|
+
}
|
|
9084
|
+
|
|
8913
9085
|
function getReadableReader(readable) {
|
|
8914
9086
|
let consumed;
|
|
8915
9087
|
return function () {
|
|
@@ -8932,10 +9104,17 @@
|
|
|
8932
9104
|
|
|
8933
9105
|
async init() {
|
|
8934
9106
|
const zipBlobReader = this;
|
|
8935
|
-
|
|
8936
|
-
const
|
|
9107
|
+
const readerOptions = Object.assign({}, options, zipBlobReader.options);
|
|
9108
|
+
const { checkOverlappingEntry, checkOverlappingEntryOnly } = readerOptions;
|
|
9109
|
+
const data = await zipBlobReader.entry.getData(new BlobWriter(), Object.assign(readerOptions, {
|
|
9110
|
+
checkPasswordOnly: false,
|
|
9111
|
+
checkOverlappingEntry: checkOverlappingEntryOnly || checkOverlappingEntry,
|
|
9112
|
+
checkOverlappingEntryOnly: false,
|
|
9113
|
+
preventClose: false
|
|
9114
|
+
}));
|
|
8937
9115
|
zipBlobReader.data = data;
|
|
8938
9116
|
zipBlobReader.blobReader = new BlobReader(data);
|
|
9117
|
+
zipBlobReader.size = data.size;
|
|
8939
9118
|
super.init();
|
|
8940
9119
|
}
|
|
8941
9120
|
|
|
@@ -8949,6 +9128,30 @@
|
|
|
8949
9128
|
return Reader.prototype ? new Reader(data, options) : Reader(data, options);
|
|
8950
9129
|
}
|
|
8951
9130
|
|
|
9131
|
+
function keepsContentType(writer, data) {
|
|
9132
|
+
const { contentType } = writer;
|
|
9133
|
+
if (contentType === UNDEFINED_VALUE) {
|
|
9134
|
+
return true;
|
|
9135
|
+
} else if (writer.constructor == BlobWriter) {
|
|
9136
|
+
return data.type == contentType;
|
|
9137
|
+
} else if (writer.constructor == Data64URIWriter) {
|
|
9138
|
+
return data.startsWith(writer.data);
|
|
9139
|
+
} else {
|
|
9140
|
+
return true;
|
|
9141
|
+
}
|
|
9142
|
+
}
|
|
9143
|
+
|
|
9144
|
+
function createProgressReadable(zipEntry, reader, options, signal) {
|
|
9145
|
+
const { onstart, onprogress, onend } = options;
|
|
9146
|
+
const { readable } = reader;
|
|
9147
|
+
const coreReaderReportsProgress = zipEntry.data instanceof Entry;
|
|
9148
|
+
if (coreReaderReportsProgress || (!onstart && !onprogress && !onend)) {
|
|
9149
|
+
return readable;
|
|
9150
|
+
} else {
|
|
9151
|
+
return toCompatibleReadable(readable).pipeThrough(new ProgressWatcherStream({ onstart, onprogress, onend, size: reader.size }), { signal });
|
|
9152
|
+
}
|
|
9153
|
+
}
|
|
9154
|
+
|
|
8952
9155
|
async function initReaders(entry, options) {
|
|
8953
9156
|
const fileEntries = [];
|
|
8954
9157
|
const pendingEntries = [entry];
|
|
@@ -8981,6 +9184,7 @@
|
|
|
8981
9184
|
}
|
|
8982
9185
|
if (reader.size !== UNDEFINED_VALUE) {
|
|
8983
9186
|
child.uncompressedSize = reader.size;
|
|
9187
|
+
child.undeterminedSize = false;
|
|
8984
9188
|
}
|
|
8985
9189
|
}));
|
|
8986
9190
|
return readers;
|
|
@@ -9030,6 +9234,90 @@
|
|
|
9030
9234
|
return error;
|
|
9031
9235
|
}
|
|
9032
9236
|
|
|
9237
|
+
function getChildEntryOptions(child, selectedEntry, options) {
|
|
9238
|
+
const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
|
|
9239
|
+
const childOptions = child.options || {};
|
|
9240
|
+
let zipEntryMetadata = {};
|
|
9241
|
+
let passThroughOptions = {};
|
|
9242
|
+
if (child.data instanceof Entry) {
|
|
9243
|
+
const {
|
|
9244
|
+
externalFileAttributes,
|
|
9245
|
+
versionMadeBy,
|
|
9246
|
+
comment,
|
|
9247
|
+
lastModDate,
|
|
9248
|
+
creationDate,
|
|
9249
|
+
lastAccessDate,
|
|
9250
|
+
uncompressedSize,
|
|
9251
|
+
encrypted,
|
|
9252
|
+
zipCrypto,
|
|
9253
|
+
crc32,
|
|
9254
|
+
compressionMethod,
|
|
9255
|
+
extraFieldAES,
|
|
9256
|
+
internalFileAttributes,
|
|
9257
|
+
extraField,
|
|
9258
|
+
uid,
|
|
9259
|
+
gid
|
|
9260
|
+
} = child.data;
|
|
9261
|
+
zipEntryMetadata = {
|
|
9262
|
+
externalFileAttributes,
|
|
9263
|
+
versionMadeBy,
|
|
9264
|
+
comment,
|
|
9265
|
+
lastModDate,
|
|
9266
|
+
creationDate,
|
|
9267
|
+
lastAccessDate,
|
|
9268
|
+
internalFileAttributes
|
|
9269
|
+
};
|
|
9270
|
+
const userExtraField = getUserExtraField(extraField);
|
|
9271
|
+
if (userExtraField) {
|
|
9272
|
+
zipEntryMetadata.extraField = userExtraField;
|
|
9273
|
+
}
|
|
9274
|
+
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
9275
|
+
Object.assign(zipEntryMetadata, {
|
|
9276
|
+
uid,
|
|
9277
|
+
gid,
|
|
9278
|
+
unixExtraFieldType: INFOZIP_EXTRA_FIELD_TYPE
|
|
9279
|
+
});
|
|
9280
|
+
}
|
|
9281
|
+
if (isPassThrough(child, options)) {
|
|
9282
|
+
let level, encryptionStrength;
|
|
9283
|
+
if (compressionMethod === 0) {
|
|
9284
|
+
level = 0;
|
|
9285
|
+
}
|
|
9286
|
+
if (extraFieldAES) {
|
|
9287
|
+
encryptionStrength = extraFieldAES.strength;
|
|
9288
|
+
}
|
|
9289
|
+
passThroughOptions = {
|
|
9290
|
+
passThrough: true,
|
|
9291
|
+
encrypted,
|
|
9292
|
+
zipCrypto,
|
|
9293
|
+
crc32,
|
|
9294
|
+
uncompressedSize,
|
|
9295
|
+
level,
|
|
9296
|
+
encryptionStrength,
|
|
9297
|
+
compressionMethod
|
|
9298
|
+
};
|
|
9299
|
+
}
|
|
9300
|
+
}
|
|
9301
|
+
const entryOptions = Object.assign({}, zipEntryMetadata, options, passThroughOptions, childOptions, { directory: child.directory });
|
|
9302
|
+
if (!child.directory && entryOptions.passThrough && entryOptions.uncompressedSize === UNDEFINED_VALUE) {
|
|
9303
|
+
throw new Error(ERR_INVALID_PASS_THROUGH);
|
|
9304
|
+
}
|
|
9305
|
+
return { name, entryOptions };
|
|
9306
|
+
}
|
|
9307
|
+
|
|
9308
|
+
function getDeterminedSize(child, passThrough) {
|
|
9309
|
+
const { reader } = child;
|
|
9310
|
+
if (reader && reader.size !== UNDEFINED_VALUE) {
|
|
9311
|
+
return reader.size;
|
|
9312
|
+
}
|
|
9313
|
+
return child.undeterminedSize ? UNDEFINED_VALUE : getExtractedSize(child, passThrough);
|
|
9314
|
+
}
|
|
9315
|
+
|
|
9316
|
+
function isPassThrough(child, options) {
|
|
9317
|
+
const { readerOptions } = options;
|
|
9318
|
+
return Boolean(!child.directory && (child.passThrough || (readerOptions && readerOptions.passThrough)));
|
|
9319
|
+
}
|
|
9320
|
+
|
|
9033
9321
|
function getUserExtraField(extraField) {
|
|
9034
9322
|
if (extraField) {
|
|
9035
9323
|
const userExtraField = new Map();
|
|
@@ -9045,8 +9333,14 @@
|
|
|
9045
9333
|
}
|
|
9046
9334
|
|
|
9047
9335
|
async function exportZip(zipWriter, entry, totalSize, options, readers) {
|
|
9336
|
+
const { onstart, onprogress, onend, onentryprogress } = options;
|
|
9048
9337
|
const selectedEntry = entry;
|
|
9049
|
-
const
|
|
9338
|
+
const totalEntries = getTotalSize(entry.children, () => 1);
|
|
9339
|
+
let writtenSize = 0;
|
|
9340
|
+
let writtenEntries = 0;
|
|
9341
|
+
if (onstart) {
|
|
9342
|
+
await callHandler(onstart, totalSize);
|
|
9343
|
+
}
|
|
9050
9344
|
if (options.bufferedWrite) {
|
|
9051
9345
|
await processChildren(entry);
|
|
9052
9346
|
} else {
|
|
@@ -9054,6 +9348,9 @@
|
|
|
9054
9348
|
await addChild(child);
|
|
9055
9349
|
}
|
|
9056
9350
|
}
|
|
9351
|
+
if (onend) {
|
|
9352
|
+
await callHandler(onend, writtenSize);
|
|
9353
|
+
}
|
|
9057
9354
|
|
|
9058
9355
|
async function processChildren(entry) {
|
|
9059
9356
|
const results = await Promise.allSettled(entry.children.map(async child => {
|
|
@@ -9067,81 +9364,23 @@
|
|
|
9067
9364
|
}
|
|
9068
9365
|
|
|
9069
9366
|
async function addChild(child) {
|
|
9070
|
-
const name
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
externalFileAttributes,
|
|
9076
|
-
versionMadeBy,
|
|
9077
|
-
comment,
|
|
9078
|
-
lastModDate,
|
|
9079
|
-
creationDate,
|
|
9080
|
-
lastAccessDate,
|
|
9081
|
-
uncompressedSize,
|
|
9082
|
-
encrypted,
|
|
9083
|
-
zipCrypto,
|
|
9084
|
-
crc32,
|
|
9085
|
-
compressionMethod,
|
|
9086
|
-
extraFieldAES,
|
|
9087
|
-
internalFileAttributes,
|
|
9088
|
-
extraField,
|
|
9089
|
-
uid,
|
|
9090
|
-
gid
|
|
9091
|
-
} = child.data;
|
|
9092
|
-
zipEntryOptions = {
|
|
9093
|
-
externalFileAttributes,
|
|
9094
|
-
versionMadeBy,
|
|
9095
|
-
comment,
|
|
9096
|
-
lastModDate,
|
|
9097
|
-
creationDate,
|
|
9098
|
-
lastAccessDate,
|
|
9099
|
-
internalFileAttributes
|
|
9100
|
-
};
|
|
9101
|
-
const userExtraField = getUserExtraField(extraField);
|
|
9102
|
-
if (userExtraField) {
|
|
9103
|
-
zipEntryOptions.extraField = userExtraField;
|
|
9104
|
-
}
|
|
9105
|
-
if (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE) {
|
|
9106
|
-
Object.assign(zipEntryOptions, {
|
|
9107
|
-
uid,
|
|
9108
|
-
gid,
|
|
9109
|
-
unixExtraFieldType: options.unixExtraFieldType || INFOZIP_EXTRA_FIELD_TYPE
|
|
9110
|
-
});
|
|
9111
|
-
}
|
|
9112
|
-
if (child.passThrough) {
|
|
9113
|
-
let level, encryptionStrength;
|
|
9114
|
-
if (compressionMethod === 0) {
|
|
9115
|
-
level = 0;
|
|
9116
|
-
}
|
|
9117
|
-
if (extraFieldAES) {
|
|
9118
|
-
encryptionStrength = extraFieldAES.strength;
|
|
9119
|
-
}
|
|
9120
|
-
zipEntryOptions = Object.assign(zipEntryOptions, {
|
|
9121
|
-
passThrough: true,
|
|
9122
|
-
encrypted,
|
|
9123
|
-
zipCrypto,
|
|
9124
|
-
crc32,
|
|
9125
|
-
uncompressedSize,
|
|
9126
|
-
level,
|
|
9127
|
-
encryptionStrength,
|
|
9128
|
-
compressionMethod
|
|
9129
|
-
});
|
|
9130
|
-
}
|
|
9131
|
-
}
|
|
9132
|
-
await zipWriter.add(name, readers.get(child), Object.assign({}, options, zipEntryOptions, childOptions, {
|
|
9133
|
-
directory: child.directory,
|
|
9367
|
+
const { name, entryOptions } = getChildEntryOptions(child, selectedEntry, options);
|
|
9368
|
+
let entryWrittenSize = 0;
|
|
9369
|
+
const entryMetadata = await zipWriter.add(name, readers.get(child), Object.assign(entryOptions, {
|
|
9370
|
+
onstart: UNDEFINED_VALUE,
|
|
9371
|
+
onend: UNDEFINED_VALUE,
|
|
9134
9372
|
onprogress: async indexProgress => {
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
} catch {
|
|
9140
|
-
// ignored
|
|
9141
|
-
}
|
|
9373
|
+
writtenSize += indexProgress - entryWrittenSize;
|
|
9374
|
+
entryWrittenSize = indexProgress;
|
|
9375
|
+
if (onprogress) {
|
|
9376
|
+
await callHandler(onprogress, writtenSize, totalSize);
|
|
9142
9377
|
}
|
|
9143
9378
|
}
|
|
9144
9379
|
}));
|
|
9380
|
+
writtenEntries++;
|
|
9381
|
+
if (onentryprogress) {
|
|
9382
|
+
await callHandler(onentryprogress, writtenEntries, totalEntries, entryMetadata);
|
|
9383
|
+
}
|
|
9145
9384
|
}
|
|
9146
9385
|
}
|
|
9147
9386
|
|
|
@@ -9169,7 +9408,7 @@
|
|
|
9169
9408
|
})
|
|
9170
9409
|
);
|
|
9171
9410
|
} else if (handle.kind == "directory") {
|
|
9172
|
-
const directoryEntry = parentEntry.addDirectory(handle.name);
|
|
9411
|
+
const directoryEntry = parentEntry.addDirectory(handle.name, options);
|
|
9173
9412
|
addedEntries.push(directoryEntry);
|
|
9174
9413
|
for await (const childHandle of handle.values()) {
|
|
9175
9414
|
await addFile(directoryEntry, childHandle, addedEntries, entryName);
|
|
@@ -9191,15 +9430,29 @@
|
|
|
9191
9430
|
}
|
|
9192
9431
|
|
|
9193
9432
|
async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
|
|
9194
|
-
const
|
|
9195
|
-
const writtenSizes = new Map();
|
|
9433
|
+
const { onstart, onprogress, onend } = options;
|
|
9196
9434
|
const abortController = new AbortController();
|
|
9197
9435
|
const { signal } = abortController;
|
|
9198
9436
|
const releaseSignal = forwardAbort(options.signal, abortController);
|
|
9437
|
+
const getDataOptions = Object.assign({}, options, options.readerOptions, {
|
|
9438
|
+
signal,
|
|
9439
|
+
onstart: UNDEFINED_VALUE,
|
|
9440
|
+
onprogress: UNDEFINED_VALUE,
|
|
9441
|
+
onend: UNDEFINED_VALUE,
|
|
9442
|
+
preventClose: false
|
|
9443
|
+
});
|
|
9444
|
+
const totalSize = getTotalSize([zipEntry], entry => getExtractedSize(entry, getDataOptions.passThrough));
|
|
9199
9445
|
const exportedEntryNames = [];
|
|
9200
9446
|
let exportAborted = false;
|
|
9447
|
+
let writtenSize = 0;
|
|
9201
9448
|
try {
|
|
9449
|
+
if (onstart) {
|
|
9450
|
+
await callHandler(onstart, totalSize);
|
|
9451
|
+
}
|
|
9202
9452
|
await exportChildren(zipEntry, directoryHandle);
|
|
9453
|
+
if (onend) {
|
|
9454
|
+
await callHandler(onend, writtenSize);
|
|
9455
|
+
}
|
|
9203
9456
|
} catch (error) {
|
|
9204
9457
|
try {
|
|
9205
9458
|
error.exportedEntryNames = exportedEntryNames;
|
|
@@ -9212,6 +9465,25 @@
|
|
|
9212
9465
|
}
|
|
9213
9466
|
return directoryHandle;
|
|
9214
9467
|
|
|
9468
|
+
function createProgressWritable(writable) {
|
|
9469
|
+
const writer = writable.getWriter();
|
|
9470
|
+
return new WritableStream({
|
|
9471
|
+
async write(chunk) {
|
|
9472
|
+
await writer.write(chunk);
|
|
9473
|
+
writtenSize += chunk.length;
|
|
9474
|
+
if (onprogress) {
|
|
9475
|
+
await callHandler(onprogress, writtenSize, totalSize);
|
|
9476
|
+
}
|
|
9477
|
+
},
|
|
9478
|
+
close() {
|
|
9479
|
+
return writer.close();
|
|
9480
|
+
},
|
|
9481
|
+
abort(reason) {
|
|
9482
|
+
return writer.abort(reason);
|
|
9483
|
+
}
|
|
9484
|
+
});
|
|
9485
|
+
}
|
|
9486
|
+
|
|
9215
9487
|
async function exportChildren(entry, parentHandle) {
|
|
9216
9488
|
if (options.concurrent) {
|
|
9217
9489
|
const results = await Promise.allSettled(entry.children.map(child => exportChild(child, parentHandle)));
|
|
@@ -9243,19 +9515,7 @@
|
|
|
9243
9515
|
const fileHandle = await parentHandle.getFileHandle(child.name, { create: true });
|
|
9244
9516
|
const writable = await fileHandle.createWritable();
|
|
9245
9517
|
try {
|
|
9246
|
-
await child.getData({ writable
|
|
9247
|
-
signal,
|
|
9248
|
-
onprogress: async progress => {
|
|
9249
|
-
if (options.onprogress) {
|
|
9250
|
-
writtenSizes.set(child.id, progress);
|
|
9251
|
-
try {
|
|
9252
|
-
await options.onprogress(Array.from(writtenSizes.values()).reduce((previousValue, currentValue) => previousValue + currentValue, 0), totalSize);
|
|
9253
|
-
} catch {
|
|
9254
|
-
// ignored
|
|
9255
|
-
}
|
|
9256
|
-
}
|
|
9257
|
-
}
|
|
9258
|
-
}));
|
|
9518
|
+
await child.getData({ writable: createProgressWritable(writable) }, getDataOptions);
|
|
9259
9519
|
} catch (error) {
|
|
9260
9520
|
throw exportAborted ? new Error(ERR_ABORT_EXPORT) : error;
|
|
9261
9521
|
}
|
|
@@ -9499,6 +9759,7 @@
|
|
|
9499
9759
|
exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
|
|
9500
9760
|
exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
|
|
9501
9761
|
exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
|
|
9762
|
+
exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
|
|
9502
9763
|
exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
|
|
9503
9764
|
exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
|
|
9504
9765
|
exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
|
|
@@ -9516,11 +9777,13 @@
|
|
|
9516
9777
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
9517
9778
|
exports.ERR_UNDEFINED_READER = ERR_UNDEFINED_READER;
|
|
9518
9779
|
exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
|
|
9780
|
+
exports.ERR_UNDETERMINED_SIZE = ERR_UNDETERMINED_SIZE;
|
|
9519
9781
|
exports.ERR_UNSAFE_FILENAME = ERR_UNSAFE_FILENAME;
|
|
9520
9782
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION$1;
|
|
9521
9783
|
exports.ERR_UNSUPPORTED_CONTEXT = ERR_UNSUPPORTED_CONTEXT;
|
|
9522
9784
|
exports.ERR_UNSUPPORTED_CRYPTO_API = ERR_UNSUPPORTED_CRYPTO_API;
|
|
9523
9785
|
exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
|
|
9786
|
+
exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
|
|
9524
9787
|
exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
|
|
9525
9788
|
exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
|
|
9526
9789
|
exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
|