@zip.js/zip.js 2.6.43 → 2.6.44
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/dist/zip-fs-full.js +63 -64
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +62 -63
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +62 -63
- package/dist/zip-full.min.js +1 -1
- package/dist/zip-no-worker-deflate.min.js +1 -1
- package/dist/zip-no-worker-inflate.min.js +1 -1
- package/dist/zip-no-worker.min.js +1 -1
- package/dist/zip.js +62 -63
- package/dist/zip.min.js +1 -1
- package/index-fflate.js +2 -0
- package/index.cjs +63 -64
- package/index.d.ts +24 -4
- package/index.js +3 -1
- package/lib/core/io.js +8 -2
- package/lib/core/zip-reader.js +2 -2
- package/lib/core/zip-writer.js +54 -61
- package/package.json +1 -1
- package/tests/all/test-http-split-zip.js +1 -1
- package/tests/all/test-split-data.js +37 -0
- package/tests/all/test-split-zip.js +2 -2
- package/tests/tests-data.js +2 -1
package/dist/zip.js
CHANGED
|
@@ -2883,7 +2883,7 @@
|
|
|
2883
2883
|
}
|
|
2884
2884
|
}
|
|
2885
2885
|
|
|
2886
|
-
class
|
|
2886
|
+
class SplitDataReader extends Reader {
|
|
2887
2887
|
|
|
2888
2888
|
constructor(readers) {
|
|
2889
2889
|
super();
|
|
@@ -2929,7 +2929,7 @@
|
|
|
2929
2929
|
}
|
|
2930
2930
|
}
|
|
2931
2931
|
|
|
2932
|
-
class
|
|
2932
|
+
class SplitDataWriter extends Stream {
|
|
2933
2933
|
|
|
2934
2934
|
constructor(writerGenerator, maxSize = 4294967296) {
|
|
2935
2935
|
super();
|
|
@@ -2950,6 +2950,7 @@
|
|
|
2950
2950
|
} else {
|
|
2951
2951
|
diskSourceWriter = value;
|
|
2952
2952
|
diskSourceWriter.size = 0;
|
|
2953
|
+
await initStream(diskSourceWriter);
|
|
2953
2954
|
diskWritable = value.writable;
|
|
2954
2955
|
diskWriter = diskWritable.getWriter();
|
|
2955
2956
|
}
|
|
@@ -3010,6 +3011,9 @@
|
|
|
3010
3011
|
return reader.readUint8Array(offset, size, diskNumber);
|
|
3011
3012
|
}
|
|
3012
3013
|
|
|
3014
|
+
const SplitZipReader = SplitDataReader;
|
|
3015
|
+
const SplitZipWriter = SplitDataWriter;
|
|
3016
|
+
|
|
3013
3017
|
/*
|
|
3014
3018
|
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
3015
3019
|
|
|
@@ -3236,7 +3240,7 @@
|
|
|
3236
3240
|
await initStream(reader);
|
|
3237
3241
|
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
3238
3242
|
if (Array.isArray(reader)) {
|
|
3239
|
-
reader = new
|
|
3243
|
+
reader = new SplitDataReader(reader);
|
|
3240
3244
|
} else {
|
|
3241
3245
|
reader = new BlobReader(await new Response(reader.readable).blob());
|
|
3242
3246
|
}
|
|
@@ -3814,7 +3818,7 @@
|
|
|
3814
3818
|
|
|
3815
3819
|
constructor(writer, options = {}) {
|
|
3816
3820
|
if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
|
|
3817
|
-
writer = new
|
|
3821
|
+
writer = new SplitDataWriter(writer);
|
|
3818
3822
|
}
|
|
3819
3823
|
if (writer instanceof WritableStream) {
|
|
3820
3824
|
writer = { writable: writer };
|
|
@@ -3822,7 +3826,7 @@
|
|
|
3822
3826
|
if (writer.writable.size === UNDEFINED_VALUE) {
|
|
3823
3827
|
writer.writable.size = 0;
|
|
3824
3828
|
}
|
|
3825
|
-
const splitZipFile = writer instanceof
|
|
3829
|
+
const splitZipFile = writer instanceof SplitDataWriter;
|
|
3826
3830
|
if (!splitZipFile) {
|
|
3827
3831
|
Object.assign(writer, {
|
|
3828
3832
|
diskNumber: 0,
|
|
@@ -3879,13 +3883,15 @@
|
|
|
3879
3883
|
}
|
|
3880
3884
|
|
|
3881
3885
|
async close(comment = new Uint8Array(), options = {}) {
|
|
3886
|
+
const zipWriter = this;
|
|
3882
3887
|
const { pendingAddFileCalls, writer } = this;
|
|
3883
3888
|
const { writable } = writer;
|
|
3884
3889
|
while (pendingAddFileCalls.size) {
|
|
3885
3890
|
await Promise.all(Array.from(pendingAddFileCalls));
|
|
3886
3891
|
}
|
|
3887
3892
|
await closeFile(this, comment, options);
|
|
3888
|
-
|
|
3893
|
+
const preventClose = getOptionValue(zipWriter, options, "preventClose");
|
|
3894
|
+
if (!preventClose) {
|
|
3889
3895
|
await writable.close();
|
|
3890
3896
|
}
|
|
3891
3897
|
return writer.getData ? writer.getData() : writable;
|
|
@@ -3908,20 +3914,33 @@
|
|
|
3908
3914
|
if (getLength(rawComment) > MAX_16_BITS) {
|
|
3909
3915
|
throw new Error(ERR_INVALID_ENTRY_COMMENT);
|
|
3910
3916
|
}
|
|
3911
|
-
const version = zipWriter
|
|
3917
|
+
const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
|
|
3912
3918
|
if (version > MAX_16_BITS) {
|
|
3913
3919
|
throw new Error(ERR_INVALID_VERSION);
|
|
3914
3920
|
}
|
|
3915
|
-
const versionMadeBy = zipWriter
|
|
3921
|
+
const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
|
|
3916
3922
|
if (versionMadeBy > MAX_16_BITS) {
|
|
3917
3923
|
throw new Error(ERR_INVALID_VERSION);
|
|
3918
3924
|
}
|
|
3919
|
-
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE
|
|
3925
|
+
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
|
|
3920
3926
|
const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
3921
3927
|
const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
3928
|
+
const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
|
|
3929
|
+
const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
|
|
3930
|
+
const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
|
|
3922
3931
|
const password = getOptionValue(zipWriter, options, "password");
|
|
3923
|
-
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength"
|
|
3932
|
+
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
|
|
3924
3933
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
3934
|
+
const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
|
|
3935
|
+
const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
|
|
3936
|
+
const level = getOptionValue(zipWriter, options, "level");
|
|
3937
|
+
const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
|
|
3938
|
+
const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
|
|
3939
|
+
const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
|
|
3940
|
+
const signal = getOptionValue(zipWriter, options, "signal");
|
|
3941
|
+
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
3942
|
+
let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
|
|
3943
|
+
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
3925
3944
|
if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
3926
3945
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
3927
3946
|
}
|
|
@@ -3945,24 +3964,9 @@
|
|
|
3945
3964
|
offset += 4 + getLength(data);
|
|
3946
3965
|
});
|
|
3947
3966
|
}
|
|
3948
|
-
let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
|
|
3949
|
-
if (extendedTimestamp === UNDEFINED_VALUE) {
|
|
3950
|
-
extendedTimestamp = true;
|
|
3951
|
-
}
|
|
3952
3967
|
let maximumCompressedSize = 0;
|
|
3953
3968
|
let maximumEntrySize = 0;
|
|
3954
|
-
let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
|
|
3955
|
-
if (keepOrder === UNDEFINED_VALUE) {
|
|
3956
|
-
keepOrder = true;
|
|
3957
|
-
}
|
|
3958
3969
|
let uncompressedSize = 0;
|
|
3959
|
-
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
3960
|
-
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
3961
|
-
msDosCompatible = true;
|
|
3962
|
-
}
|
|
3963
|
-
const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
|
|
3964
|
-
const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
|
|
3965
|
-
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
3966
3970
|
if (reader) {
|
|
3967
3971
|
if (reader instanceof ReadableStream) {
|
|
3968
3972
|
reader = {
|
|
@@ -3971,7 +3975,7 @@
|
|
|
3971
3975
|
}
|
|
3972
3976
|
await initStream(reader);
|
|
3973
3977
|
if (reader.size === UNDEFINED_VALUE) {
|
|
3974
|
-
|
|
3978
|
+
dataDescriptor = true;
|
|
3975
3979
|
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
3976
3980
|
zip64 = true;
|
|
3977
3981
|
maximumCompressedSize = MAX_32_BITS;
|
|
@@ -3981,10 +3985,11 @@
|
|
|
3981
3985
|
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
3982
3986
|
}
|
|
3983
3987
|
}
|
|
3984
|
-
const { diskOffset } = zipWriter.writer;
|
|
3988
|
+
const { diskOffset, diskNumber } = zipWriter.writer;
|
|
3985
3989
|
if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
|
|
3986
3990
|
uncompressedSize >= MAX_32_BITS ||
|
|
3987
|
-
maximumCompressedSize >= MAX_32_BITS
|
|
3991
|
+
maximumCompressedSize >= MAX_32_BITS ||
|
|
3992
|
+
diskNumber >= MAX_16_BITS) {
|
|
3988
3993
|
if (zip64 === false || !keepOrder) {
|
|
3989
3994
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
3990
3995
|
} else {
|
|
@@ -3992,19 +3997,6 @@
|
|
|
3992
3997
|
}
|
|
3993
3998
|
}
|
|
3994
3999
|
zip64 = zip64 || false;
|
|
3995
|
-
const level = getOptionValue(zipWriter, options, "level");
|
|
3996
|
-
const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
|
|
3997
|
-
const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
|
|
3998
|
-
let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
|
|
3999
|
-
let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
|
|
4000
|
-
const signal = getOptionValue(zipWriter, options, "signal");
|
|
4001
|
-
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
4002
|
-
if (dataDescriptor === UNDEFINED_VALUE) {
|
|
4003
|
-
dataDescriptor = true;
|
|
4004
|
-
}
|
|
4005
|
-
if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
|
|
4006
|
-
dataDescriptorSignature = false;
|
|
4007
|
-
}
|
|
4008
4000
|
options = Object.assign({}, options, {
|
|
4009
4001
|
rawFilename,
|
|
4010
4002
|
rawComment,
|
|
@@ -4077,8 +4069,7 @@
|
|
|
4077
4069
|
await initStream(writer);
|
|
4078
4070
|
} else {
|
|
4079
4071
|
fileWriter = writer;
|
|
4080
|
-
|
|
4081
|
-
releaseLockWriter = () => delete zipWriter.lockWriter;
|
|
4072
|
+
initLockWriter();
|
|
4082
4073
|
}
|
|
4083
4074
|
await initStream(fileWriter);
|
|
4084
4075
|
const { writable, diskNumber } = writer;
|
|
@@ -4107,7 +4098,7 @@
|
|
|
4107
4098
|
await requestLockWriter();
|
|
4108
4099
|
writingBufferedEntryData = true;
|
|
4109
4100
|
if (!dataDescriptor) {
|
|
4110
|
-
blob = await
|
|
4101
|
+
blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
|
|
4111
4102
|
}
|
|
4112
4103
|
fileEntry.diskNumberStart = writer.diskNumber;
|
|
4113
4104
|
diskOffset = writer.diskOffset;
|
|
@@ -4117,7 +4108,7 @@
|
|
|
4117
4108
|
}
|
|
4118
4109
|
fileEntry.offset = zipWriter.offset - diskOffset;
|
|
4119
4110
|
if (fileEntry.zip64) {
|
|
4120
|
-
|
|
4111
|
+
setZip64OffsetInfo(fileEntry);
|
|
4121
4112
|
} else if (fileEntry.offset >= MAX_32_BITS) {
|
|
4122
4113
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
4123
4114
|
}
|
|
@@ -4150,6 +4141,11 @@
|
|
|
4150
4141
|
fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
|
|
4151
4142
|
}
|
|
4152
4143
|
|
|
4144
|
+
function initLockWriter() {
|
|
4145
|
+
zipWriter.lockWriter = Promise.resolve();
|
|
4146
|
+
releaseLockWriter = () => delete zipWriter.lockWriter;
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4153
4149
|
async function requestLockWriter() {
|
|
4154
4150
|
const { lockWriter } = zipWriter;
|
|
4155
4151
|
if (lockWriter) {
|
|
@@ -4308,6 +4304,7 @@
|
|
|
4308
4304
|
} = options;
|
|
4309
4305
|
const compressed = level !== 0 && !directory;
|
|
4310
4306
|
const encrypted = Boolean(password && getLength(password));
|
|
4307
|
+
let version = options.version;
|
|
4311
4308
|
let rawExtraFieldAES;
|
|
4312
4309
|
if (encrypted && !zipCrypto) {
|
|
4313
4310
|
rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
|
|
@@ -4359,7 +4356,6 @@
|
|
|
4359
4356
|
if (compressed) {
|
|
4360
4357
|
compressionMethod = COMPRESSION_METHOD_DEFLATE;
|
|
4361
4358
|
}
|
|
4362
|
-
let version = options.version || VERSION_DEFLATE;
|
|
4363
4359
|
if (zip64) {
|
|
4364
4360
|
version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
|
|
4365
4361
|
}
|
|
@@ -4493,7 +4489,7 @@
|
|
|
4493
4489
|
}
|
|
4494
4490
|
}
|
|
4495
4491
|
|
|
4496
|
-
async function
|
|
4492
|
+
async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
|
|
4497
4493
|
const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
|
|
4498
4494
|
const arrayBufferView = new DataView(arrayBuffer);
|
|
4499
4495
|
if (!fileEntry.encrypted || zipCrypto) {
|
|
@@ -4510,7 +4506,7 @@
|
|
|
4510
4506
|
return entryData.slice(arrayBuffer.byteLength);
|
|
4511
4507
|
}
|
|
4512
4508
|
|
|
4513
|
-
function
|
|
4509
|
+
function setZip64OffsetInfo(fileEntry) {
|
|
4514
4510
|
const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
|
|
4515
4511
|
const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
|
|
4516
4512
|
setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
|
|
@@ -4519,10 +4515,10 @@
|
|
|
4519
4515
|
|
|
4520
4516
|
async function closeFile(zipWriter, comment, options) {
|
|
4521
4517
|
const { files, writer } = zipWriter;
|
|
4522
|
-
let offset = 0;
|
|
4523
|
-
let directoryDataLength = 0;
|
|
4524
4518
|
const { diskOffset, writable } = writer;
|
|
4525
4519
|
let { diskNumber } = writer;
|
|
4520
|
+
let offset = 0;
|
|
4521
|
+
let directoryDataLength = 0;
|
|
4526
4522
|
let directoryOffset = zipWriter.offset - diskOffset;
|
|
4527
4523
|
let filesLength = files.size;
|
|
4528
4524
|
for (const [, {
|
|
@@ -4544,14 +4540,6 @@
|
|
|
4544
4540
|
rawExtraFieldNTFS,
|
|
4545
4541
|
rawExtraField);
|
|
4546
4542
|
}
|
|
4547
|
-
let zip64 = options.zip64 || zipWriter.options.zip64 || false;
|
|
4548
|
-
if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
|
|
4549
|
-
if (options.zip64 === false || zipWriter.options.zip64 === false) {
|
|
4550
|
-
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
4551
|
-
} else {
|
|
4552
|
-
zip64 = true;
|
|
4553
|
-
}
|
|
4554
|
-
}
|
|
4555
4543
|
const directoryArray = new Uint8Array(directoryDataLength);
|
|
4556
4544
|
const directoryView = getDataView(directoryArray);
|
|
4557
4545
|
for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
|
|
@@ -4617,13 +4605,21 @@
|
|
|
4617
4605
|
}
|
|
4618
4606
|
await initStream(writer);
|
|
4619
4607
|
await writeData(writable, directoryArray);
|
|
4620
|
-
const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
|
|
4621
|
-
const endOfdirectoryView = getDataView(endOfdirectoryArray);
|
|
4622
4608
|
let lastDiskNumber = writer.diskNumber;
|
|
4623
4609
|
const { availableSize } = writer;
|
|
4624
|
-
if (availableSize <
|
|
4610
|
+
if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
|
|
4625
4611
|
lastDiskNumber++;
|
|
4626
4612
|
}
|
|
4613
|
+
let zip64 = getOptionValue(zipWriter, options, "zip64");
|
|
4614
|
+
if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
|
|
4615
|
+
if (zip64 === false) {
|
|
4616
|
+
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
4617
|
+
} else {
|
|
4618
|
+
zip64 = true;
|
|
4619
|
+
}
|
|
4620
|
+
}
|
|
4621
|
+
const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
|
|
4622
|
+
const endOfdirectoryView = getDataView(endOfdirectoryArray);
|
|
4627
4623
|
offset = 0;
|
|
4628
4624
|
if (zip64) {
|
|
4629
4625
|
setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
|
|
@@ -4688,8 +4684,9 @@
|
|
|
4688
4684
|
}
|
|
4689
4685
|
}
|
|
4690
4686
|
|
|
4691
|
-
function getOptionValue(zipWriter, options, name) {
|
|
4692
|
-
|
|
4687
|
+
function getOptionValue(zipWriter, options, name, defaultValue) {
|
|
4688
|
+
const result = options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
|
|
4689
|
+
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
4693
4690
|
}
|
|
4694
4691
|
|
|
4695
4692
|
function getMaximumCompressedSize(uncompressedSize) {
|
|
@@ -4794,6 +4791,8 @@
|
|
|
4794
4791
|
exports.HttpRangeReader = HttpRangeReader;
|
|
4795
4792
|
exports.HttpReader = HttpReader;
|
|
4796
4793
|
exports.Reader = Reader;
|
|
4794
|
+
exports.SplitDataReader = SplitDataReader;
|
|
4795
|
+
exports.SplitDataWriter = SplitDataWriter;
|
|
4797
4796
|
exports.SplitZipReader = SplitZipReader;
|
|
4798
4797
|
exports.SplitZipWriter = SplitZipWriter;
|
|
4799
4798
|
exports.TextReader = TextReader;
|