@zip.js/zip.js 2.6.40 → 2.6.42
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 +6 -5
- package/cli-deno/mc-zip.js +19 -13
- package/dist/zip-fs-full.js +54 -32
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +53 -31
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +53 -31
- 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 +53 -31
- package/dist/zip.min.js +1 -1
- package/index.cjs +54 -32
- package/index.d.ts +54 -29
- package/index.js +1 -1
- package/lib/core/zip-entry.js +45 -7
- package/lib/core/zip-reader.js +29 -13
- package/lib/core/zip-writer.js +24 -13
- package/package.json +3 -2
package/index.cjs
CHANGED
|
@@ -8339,14 +8339,34 @@ function decodeText(value, encoding) {
|
|
|
8339
8339
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
8340
8340
|
*/
|
|
8341
8341
|
|
|
8342
|
+
const PROPERTY_NAME_FILENAME = "filename";
|
|
8343
|
+
const PROPERTY_NAME_RAW_FILENAME = "rawFilename";
|
|
8344
|
+
const PROPERTY_NAME_COMMENT = "comment";
|
|
8345
|
+
const PROPERTY_NAME_RAW_COMMENT = "rawComment";
|
|
8346
|
+
const PROPERTY_NAME_UNCOMPPRESSED_SIZE = "uncompressedSize";
|
|
8347
|
+
const PROPERTY_NAME_COMPPRESSED_SIZE = "compressedSize";
|
|
8348
|
+
const PROPERTY_NAME_OFFSET = "offset";
|
|
8349
|
+
const PROPERTY_NAME_DISK_NUMBER_START = "diskNumberStart";
|
|
8350
|
+
const PROPERTY_NAME_LAST_MODIFICATION_DATE = "lastModDate";
|
|
8351
|
+
const PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE = "rawLastModDate";
|
|
8352
|
+
const PROPERTY_NAME_LAST_ACCESS_DATE = "lastAccessDate";
|
|
8353
|
+
const PROPERTY_NAME_RAW_LAST_ACCESS_DATE = "rawLastAccessDate";
|
|
8354
|
+
const PROPERTY_NAME_CREATION_DATE = "creationDate";
|
|
8355
|
+
const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
|
|
8356
|
+
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE = "internalFileAttribute";
|
|
8357
|
+
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
|
|
8358
|
+
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
8359
|
+
const PROPERTY_NAME_ZIP64 = "zip64";
|
|
8360
|
+
|
|
8342
8361
|
const PROPERTY_NAMES = [
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
"
|
|
8349
|
-
"
|
|
8362
|
+
PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
|
|
8363
|
+
PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
|
|
8364
|
+
PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
|
|
8365
|
+
PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
8366
|
+
PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
|
|
8367
|
+
"directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
|
|
8368
|
+
"extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
|
|
8369
|
+
"extraFieldExtendedTimestamp"];
|
|
8350
8370
|
|
|
8351
8371
|
class Entry {
|
|
8352
8372
|
|
|
@@ -8398,10 +8418,10 @@ const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
|
8398
8418
|
const CHARSET_UTF8 = "utf-8";
|
|
8399
8419
|
const CHARSET_CP437 = "cp437";
|
|
8400
8420
|
const ZIP64_PROPERTIES = [
|
|
8401
|
-
[
|
|
8402
|
-
[
|
|
8403
|
-
[
|
|
8404
|
-
[
|
|
8421
|
+
[PROPERTY_NAME_UNCOMPPRESSED_SIZE, MAX_32_BITS],
|
|
8422
|
+
[PROPERTY_NAME_COMPPRESSED_SIZE, MAX_32_BITS],
|
|
8423
|
+
[PROPERTY_NAME_OFFSET, MAX_32_BITS],
|
|
8424
|
+
[PROPERTY_NAME_DISK_NUMBER_START, MAX_16_BITS]
|
|
8405
8425
|
];
|
|
8406
8426
|
const ZIP64_EXTRACTION = {
|
|
8407
8427
|
[MAX_16_BITS]: {
|
|
@@ -8761,12 +8781,12 @@ async function readCommonFooter(fileEntry, directory, dataView, offset) {
|
|
|
8761
8781
|
}
|
|
8762
8782
|
const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
|
|
8763
8783
|
if (extraFieldUnicodePath) {
|
|
8764
|
-
await readExtraFieldUnicode(extraFieldUnicodePath,
|
|
8784
|
+
await readExtraFieldUnicode(extraFieldUnicodePath, PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, directory, fileEntry);
|
|
8765
8785
|
directory.extraFieldUnicodePath = extraFieldUnicodePath;
|
|
8766
8786
|
}
|
|
8767
8787
|
const extraFieldUnicodeComment = extraField.get(EXTRAFIELD_TYPE_UNICODE_COMMENT);
|
|
8768
8788
|
if (extraFieldUnicodeComment) {
|
|
8769
|
-
await readExtraFieldUnicode(extraFieldUnicodeComment,
|
|
8789
|
+
await readExtraFieldUnicode(extraFieldUnicodeComment, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT, directory, fileEntry);
|
|
8770
8790
|
directory.extraFieldUnicodeComment = extraFieldUnicodeComment;
|
|
8771
8791
|
}
|
|
8772
8792
|
const extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);
|
|
@@ -8880,16 +8900,16 @@ function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory)
|
|
|
8880
8900
|
const timeProperties = [];
|
|
8881
8901
|
const timeRawProperties = [];
|
|
8882
8902
|
if ((flags & 0x1) == 0x1) {
|
|
8883
|
-
timeProperties.push(
|
|
8884
|
-
timeRawProperties.push(
|
|
8903
|
+
timeProperties.push(PROPERTY_NAME_LAST_MODIFICATION_DATE);
|
|
8904
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE);
|
|
8885
8905
|
}
|
|
8886
8906
|
if ((flags & 0x2) == 0x2) {
|
|
8887
|
-
timeProperties.push(
|
|
8888
|
-
timeRawProperties.push(
|
|
8907
|
+
timeProperties.push(PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
8908
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_LAST_ACCESS_DATE);
|
|
8889
8909
|
}
|
|
8890
8910
|
if ((flags & 0x4) == 0x4) {
|
|
8891
|
-
timeProperties.push(
|
|
8892
|
-
timeRawProperties.push(
|
|
8911
|
+
timeProperties.push(PROPERTY_NAME_CREATION_DATE);
|
|
8912
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_CREATION_DATE);
|
|
8893
8913
|
}
|
|
8894
8914
|
let offset = 1;
|
|
8895
8915
|
timeProperties.forEach((propertyName, indexProperty) => {
|
|
@@ -9116,9 +9136,9 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
9116
9136
|
if (versionMadeBy > MAX_16_BITS) {
|
|
9117
9137
|
throw new Error(ERR_INVALID_VERSION);
|
|
9118
9138
|
}
|
|
9119
|
-
const lastModDate = getOptionValue(zipWriter, options,
|
|
9120
|
-
const lastAccessDate = getOptionValue(zipWriter, options,
|
|
9121
|
-
const creationDate = getOptionValue(zipWriter, options,
|
|
9139
|
+
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
|
|
9140
|
+
const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
9141
|
+
const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
9122
9142
|
const password = getOptionValue(zipWriter, options, "password");
|
|
9123
9143
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
9124
9144
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
@@ -9156,13 +9176,13 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
9156
9176
|
keepOrder = true;
|
|
9157
9177
|
}
|
|
9158
9178
|
let uncompressedSize = 0;
|
|
9159
|
-
let msDosCompatible = getOptionValue(zipWriter, options,
|
|
9179
|
+
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
9160
9180
|
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
9161
9181
|
msDosCompatible = true;
|
|
9162
9182
|
}
|
|
9163
|
-
const internalFileAttribute = getOptionValue(zipWriter, options,
|
|
9164
|
-
const externalFileAttribute = getOptionValue(zipWriter, options,
|
|
9165
|
-
let zip64 = getOptionValue(zipWriter, options,
|
|
9183
|
+
const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
|
|
9184
|
+
const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
|
|
9185
|
+
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
9166
9186
|
if (reader) {
|
|
9167
9187
|
if (reader instanceof ReadableStream) {
|
|
9168
9188
|
reader = {
|
|
@@ -9181,7 +9201,8 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
9181
9201
|
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
9182
9202
|
}
|
|
9183
9203
|
}
|
|
9184
|
-
|
|
9204
|
+
const { diskOffset } = zipWriter.writer;
|
|
9205
|
+
if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
|
|
9185
9206
|
uncompressedSize >= MAX_32_BITS ||
|
|
9186
9207
|
maximumCompressedSize >= MAX_32_BITS) {
|
|
9187
9208
|
if (zip64 === false || !keepOrder) {
|
|
@@ -9237,8 +9258,9 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
9237
9258
|
let fileEntry;
|
|
9238
9259
|
try {
|
|
9239
9260
|
fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
|
|
9261
|
+
zipWriter.pendingEntriesSize -= maximumEntrySize;
|
|
9240
9262
|
} catch (error) {
|
|
9241
|
-
if (!error.corruptedEntry
|
|
9263
|
+
if (!error.corruptedEntry) {
|
|
9242
9264
|
zipWriter.pendingEntriesSize -= maximumEntrySize;
|
|
9243
9265
|
}
|
|
9244
9266
|
throw error;
|
|
@@ -9288,7 +9310,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
9288
9310
|
if (zipWriter.addSplitZipSignature) {
|
|
9289
9311
|
delete zipWriter.addSplitZipSignature;
|
|
9290
9312
|
const signatureArray = new Uint8Array(4);
|
|
9291
|
-
const signatureArrayView =
|
|
9313
|
+
const signatureArrayView = getDataView(signatureArray);
|
|
9292
9314
|
setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
|
|
9293
9315
|
await writeData(writable, signatureArray);
|
|
9294
9316
|
zipWriter.offset += 4;
|
|
@@ -9426,9 +9448,9 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
9426
9448
|
externalFileAttribute,
|
|
9427
9449
|
diskNumberStart
|
|
9428
9450
|
};
|
|
9451
|
+
let compressedSize = 0;
|
|
9429
9452
|
let uncompressedSize = 0;
|
|
9430
9453
|
let signature;
|
|
9431
|
-
let compressedSize = 0;
|
|
9432
9454
|
const { writable } = writer;
|
|
9433
9455
|
if (reader) {
|
|
9434
9456
|
reader.chunkSize = getChunkSize(config);
|
|
@@ -9823,7 +9845,7 @@ async function closeFile(zipWriter, comment, options) {
|
|
|
9823
9845
|
const endOfdirectoryView = getDataView(endOfdirectoryArray);
|
|
9824
9846
|
let lastDiskNumber = writer.diskNumber;
|
|
9825
9847
|
const { availableSize } = writer;
|
|
9826
|
-
if (availableSize < endOfdirectoryArray
|
|
9848
|
+
if (availableSize < getLength(endOfdirectoryArray)) {
|
|
9827
9849
|
lastDiskNumber++;
|
|
9828
9850
|
}
|
|
9829
9851
|
offset = 0;
|
|
@@ -10577,7 +10599,7 @@ try {
|
|
|
10577
10599
|
configure({ baseURL });
|
|
10578
10600
|
e(configure);
|
|
10579
10601
|
|
|
10580
|
-
/// <reference types="./index
|
|
10602
|
+
/// <reference types="./index" />
|
|
10581
10603
|
|
|
10582
10604
|
configure({ Deflate: ZipDeflate, Inflate: ZipInflate });
|
|
10583
10605
|
|
package/index.d.ts
CHANGED
|
@@ -944,11 +944,15 @@ interface ZipWriterConstructorOptions {
|
|
|
944
944
|
/**
|
|
945
945
|
* `true` to use Zip64 to store the entry.
|
|
946
946
|
*
|
|
947
|
+
* `zip64` is automatically set to `true` when necessary (e.g. compressed data larger than 4GB or with unknown size).
|
|
948
|
+
*
|
|
947
949
|
* @defaultValue false
|
|
948
950
|
*/
|
|
949
951
|
zip64?: boolean
|
|
950
952
|
/**
|
|
951
|
-
* The level of compression.
|
|
953
|
+
* The level of compression.
|
|
954
|
+
*
|
|
955
|
+
* The minimum value is 0 and means that no compression is applied. The maximum value is 9.
|
|
952
956
|
*
|
|
953
957
|
* @defaultValue 5
|
|
954
958
|
*/
|
|
@@ -956,19 +960,20 @@ interface ZipWriterConstructorOptions {
|
|
|
956
960
|
/**
|
|
957
961
|
* `true` to write entry data in a buffer before appending it to the zip file.
|
|
958
962
|
*
|
|
963
|
+
* `bufferedWrite` is automatically set to `true` when compressing more than one entry in parallel.
|
|
964
|
+
*
|
|
959
965
|
* @defaultValue false
|
|
960
966
|
*/
|
|
961
967
|
bufferedWrite?: boolean
|
|
962
968
|
/**
|
|
963
|
-
* `true` to keep the order of the entry physically in the zip file.
|
|
969
|
+
* `true` to keep the order of the entry physically in the zip file.
|
|
970
|
+
*
|
|
971
|
+
* When set to `true`, the use of web workers will be improved. However, it also prevents files larger than 4GB from being created without setting the `zip54` option to `true` explicitly.
|
|
972
|
+
* Another solution to improve the use of web workers is to add entries from smallest to largest in uncompressed size.
|
|
964
973
|
*
|
|
965
974
|
* @defaultValue true
|
|
966
975
|
*/
|
|
967
976
|
keepOrder?: boolean
|
|
968
|
-
/**
|
|
969
|
-
* The "Version" field.
|
|
970
|
-
*/
|
|
971
|
-
version?: number
|
|
972
977
|
/**
|
|
973
978
|
* The password used to encrypt the content of the entry.
|
|
974
979
|
*/
|
|
@@ -979,24 +984,6 @@ interface ZipWriterConstructorOptions {
|
|
|
979
984
|
* @defaultValue 3
|
|
980
985
|
*/
|
|
981
986
|
encryptionStrength?: 1 | 2 | 3
|
|
982
|
-
/**
|
|
983
|
-
* `true` to use the ZipCrypto algorithm to encrypt the content of the entry.
|
|
984
|
-
*
|
|
985
|
-
* @defaultValue false
|
|
986
|
-
*/
|
|
987
|
-
zipCrypto?: boolean
|
|
988
|
-
/**
|
|
989
|
-
* `true` to to add a data descriptor.
|
|
990
|
-
*
|
|
991
|
-
* @defaultValue true
|
|
992
|
-
*/
|
|
993
|
-
dataDescriptor?: boolean
|
|
994
|
-
/**
|
|
995
|
-
* `true` to add the signature of the data descriptor.
|
|
996
|
-
*
|
|
997
|
-
* @defaultValue false
|
|
998
|
-
*/
|
|
999
|
-
dataDescriptorSignature?: boolean
|
|
1000
987
|
/**
|
|
1001
988
|
* The `AbortSignal` instance used to cancel the compression.
|
|
1002
989
|
*/
|
|
@@ -1010,39 +997,77 @@ interface ZipWriterConstructorOptions {
|
|
|
1010
997
|
/**
|
|
1011
998
|
* The last access date.
|
|
1012
999
|
*
|
|
1000
|
+
* This option is ignored if the `extendedTimestamp` option is set to `false`.
|
|
1001
|
+
*
|
|
1013
1002
|
* @defaultValue The current date.
|
|
1014
1003
|
*/
|
|
1015
1004
|
lastAccessDate?: Date
|
|
1016
1005
|
/**
|
|
1017
1006
|
* The creation date.
|
|
1018
1007
|
*
|
|
1008
|
+
* This option is ignored if the `extendedTimestamp` option is set to `false`.
|
|
1009
|
+
*
|
|
1019
1010
|
* @defaultValue The current date.
|
|
1020
1011
|
*/
|
|
1021
1012
|
creationDate?: Date
|
|
1022
1013
|
/**
|
|
1023
1014
|
* `true` to store extended timestamp extra fields.
|
|
1024
1015
|
*
|
|
1016
|
+
* When set to `false`, the maximum last modification date cannot exceed November 31, 2107 and the maximum accuracy is 2 seconds.
|
|
1017
|
+
*
|
|
1025
1018
|
* @defaultValue true
|
|
1026
1019
|
*/
|
|
1027
1020
|
extendedTimestamp?: boolean
|
|
1028
1021
|
/**
|
|
1029
|
-
* `true` to
|
|
1022
|
+
* `true` to use the ZipCrypto algorithm to encrypt the content of the entry.
|
|
1023
|
+
*
|
|
1024
|
+
* It is not recommended to set `zipCrypto` to `true` because the ZipCrypto encryption can be easily broken.
|
|
1025
|
+
*
|
|
1026
|
+
* @defaultValue false
|
|
1027
|
+
*/
|
|
1028
|
+
zipCrypto?: boolean
|
|
1029
|
+
/**
|
|
1030
|
+
* The "Version" field.
|
|
1031
|
+
*/
|
|
1032
|
+
version?: number
|
|
1033
|
+
/**
|
|
1034
|
+
* The "Version made by" field.
|
|
1035
|
+
*
|
|
1036
|
+
* @defaultValue 20
|
|
1037
|
+
*/
|
|
1038
|
+
versionMadeBy?: number
|
|
1039
|
+
/**
|
|
1040
|
+
* `true` to to add a data descriptor.
|
|
1041
|
+
*
|
|
1042
|
+
* When set to `false`, the `bufferedWrite` option will automatically be set to `true`.
|
|
1030
1043
|
*
|
|
1031
1044
|
* @defaultValue true
|
|
1032
1045
|
*/
|
|
1033
|
-
|
|
1046
|
+
dataDescriptor?: boolean
|
|
1034
1047
|
/**
|
|
1035
|
-
*
|
|
1048
|
+
* `true` to add the signature of the data descriptor.
|
|
1036
1049
|
*
|
|
1037
|
-
* @defaultValue
|
|
1050
|
+
* @defaultValue false
|
|
1038
1051
|
*/
|
|
1039
|
-
|
|
1052
|
+
dataDescriptorSignature?: boolean
|
|
1053
|
+
/**
|
|
1054
|
+
* `true` to write `externalFileAttribute` in MS-DOS format for folder entries.
|
|
1055
|
+
*
|
|
1056
|
+
* @defaultValue true
|
|
1057
|
+
*/
|
|
1058
|
+
msDosCompatible?: boolean
|
|
1040
1059
|
/**
|
|
1041
1060
|
* The external file attribute.
|
|
1042
1061
|
*
|
|
1043
1062
|
* @defaultValue 0
|
|
1044
1063
|
*/
|
|
1045
1064
|
externalFileAttribute?: number
|
|
1065
|
+
/**
|
|
1066
|
+
* The internal file attribute.
|
|
1067
|
+
*
|
|
1068
|
+
* @defaultValue 0
|
|
1069
|
+
*/
|
|
1070
|
+
internalFileAttribute?: number
|
|
1046
1071
|
}
|
|
1047
1072
|
|
|
1048
1073
|
/**
|
package/index.js
CHANGED
package/lib/core/zip-entry.js
CHANGED
|
@@ -26,14 +26,34 @@
|
|
|
26
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
const PROPERTY_NAME_FILENAME = "filename";
|
|
30
|
+
const PROPERTY_NAME_RAW_FILENAME = "rawFilename";
|
|
31
|
+
const PROPERTY_NAME_COMMENT = "comment";
|
|
32
|
+
const PROPERTY_NAME_RAW_COMMENT = "rawComment";
|
|
33
|
+
const PROPERTY_NAME_UNCOMPPRESSED_SIZE = "uncompressedSize";
|
|
34
|
+
const PROPERTY_NAME_COMPPRESSED_SIZE = "compressedSize";
|
|
35
|
+
const PROPERTY_NAME_OFFSET = "offset";
|
|
36
|
+
const PROPERTY_NAME_DISK_NUMBER_START = "diskNumberStart";
|
|
37
|
+
const PROPERTY_NAME_LAST_MODIFICATION_DATE = "lastModDate";
|
|
38
|
+
const PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE = "rawLastModDate";
|
|
39
|
+
const PROPERTY_NAME_LAST_ACCESS_DATE = "lastAccessDate";
|
|
40
|
+
const PROPERTY_NAME_RAW_LAST_ACCESS_DATE = "rawLastAccessDate";
|
|
41
|
+
const PROPERTY_NAME_CREATION_DATE = "creationDate";
|
|
42
|
+
const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
|
|
43
|
+
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE = "internalFileAttribute";
|
|
44
|
+
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
|
|
45
|
+
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
46
|
+
const PROPERTY_NAME_ZIP64 = "zip64";
|
|
47
|
+
|
|
29
48
|
const PROPERTY_NAMES = [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
49
|
+
PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
|
|
50
|
+
PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
|
|
51
|
+
PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
|
|
52
|
+
PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
53
|
+
PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
|
|
54
|
+
"directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
|
|
55
|
+
"extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
|
|
56
|
+
"extraFieldExtendedTimestamp"];
|
|
37
57
|
|
|
38
58
|
class Entry {
|
|
39
59
|
|
|
@@ -44,5 +64,23 @@ class Entry {
|
|
|
44
64
|
}
|
|
45
65
|
|
|
46
66
|
export {
|
|
67
|
+
PROPERTY_NAME_FILENAME,
|
|
68
|
+
PROPERTY_NAME_RAW_FILENAME,
|
|
69
|
+
PROPERTY_NAME_COMMENT,
|
|
70
|
+
PROPERTY_NAME_RAW_COMMENT,
|
|
71
|
+
PROPERTY_NAME_UNCOMPPRESSED_SIZE,
|
|
72
|
+
PROPERTY_NAME_COMPPRESSED_SIZE,
|
|
73
|
+
PROPERTY_NAME_OFFSET,
|
|
74
|
+
PROPERTY_NAME_DISK_NUMBER_START,
|
|
75
|
+
PROPERTY_NAME_LAST_MODIFICATION_DATE,
|
|
76
|
+
PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE,
|
|
77
|
+
PROPERTY_NAME_LAST_ACCESS_DATE,
|
|
78
|
+
PROPERTY_NAME_RAW_LAST_ACCESS_DATE,
|
|
79
|
+
PROPERTY_NAME_CREATION_DATE,
|
|
80
|
+
PROPERTY_NAME_RAW_CREATION_DATE,
|
|
81
|
+
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE,
|
|
82
|
+
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
83
|
+
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
84
|
+
PROPERTY_NAME_ZIP64,
|
|
47
85
|
Entry
|
|
48
86
|
};
|
package/lib/core/zip-reader.js
CHANGED
|
@@ -77,7 +77,23 @@ import {
|
|
|
77
77
|
} from "./io.js";
|
|
78
78
|
import { decodeText } from "./util/decode-text.js";
|
|
79
79
|
import { Crc32 } from "./streams/codecs/crc32.js";
|
|
80
|
-
import {
|
|
80
|
+
import {
|
|
81
|
+
PROPERTY_NAME_RAW_FILENAME,
|
|
82
|
+
PROPERTY_NAME_FILENAME,
|
|
83
|
+
PROPERTY_NAME_RAW_COMMENT,
|
|
84
|
+
PROPERTY_NAME_COMMENT,
|
|
85
|
+
PROPERTY_NAME_UNCOMPPRESSED_SIZE,
|
|
86
|
+
PROPERTY_NAME_COMPPRESSED_SIZE,
|
|
87
|
+
PROPERTY_NAME_OFFSET,
|
|
88
|
+
PROPERTY_NAME_DISK_NUMBER_START,
|
|
89
|
+
PROPERTY_NAME_LAST_MODIFICATION_DATE,
|
|
90
|
+
PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE,
|
|
91
|
+
PROPERTY_NAME_LAST_ACCESS_DATE,
|
|
92
|
+
PROPERTY_NAME_RAW_LAST_ACCESS_DATE,
|
|
93
|
+
PROPERTY_NAME_CREATION_DATE,
|
|
94
|
+
PROPERTY_NAME_RAW_CREATION_DATE,
|
|
95
|
+
Entry
|
|
96
|
+
} from "./zip-entry.js";
|
|
81
97
|
|
|
82
98
|
const ERR_BAD_FORMAT = "File format is not recognized";
|
|
83
99
|
const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
|
|
@@ -93,10 +109,10 @@ const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
|
93
109
|
const CHARSET_UTF8 = "utf-8";
|
|
94
110
|
const CHARSET_CP437 = "cp437";
|
|
95
111
|
const ZIP64_PROPERTIES = [
|
|
96
|
-
[
|
|
97
|
-
[
|
|
98
|
-
[
|
|
99
|
-
[
|
|
112
|
+
[PROPERTY_NAME_UNCOMPPRESSED_SIZE, MAX_32_BITS],
|
|
113
|
+
[PROPERTY_NAME_COMPPRESSED_SIZE, MAX_32_BITS],
|
|
114
|
+
[PROPERTY_NAME_OFFSET, MAX_32_BITS],
|
|
115
|
+
[PROPERTY_NAME_DISK_NUMBER_START, MAX_16_BITS]
|
|
100
116
|
];
|
|
101
117
|
const ZIP64_EXTRACTION = {
|
|
102
118
|
[MAX_16_BITS]: {
|
|
@@ -473,12 +489,12 @@ async function readCommonFooter(fileEntry, directory, dataView, offset) {
|
|
|
473
489
|
}
|
|
474
490
|
const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
|
|
475
491
|
if (extraFieldUnicodePath) {
|
|
476
|
-
await readExtraFieldUnicode(extraFieldUnicodePath,
|
|
492
|
+
await readExtraFieldUnicode(extraFieldUnicodePath, PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, directory, fileEntry);
|
|
477
493
|
directory.extraFieldUnicodePath = extraFieldUnicodePath;
|
|
478
494
|
}
|
|
479
495
|
const extraFieldUnicodeComment = extraField.get(EXTRAFIELD_TYPE_UNICODE_COMMENT);
|
|
480
496
|
if (extraFieldUnicodeComment) {
|
|
481
|
-
await readExtraFieldUnicode(extraFieldUnicodeComment,
|
|
497
|
+
await readExtraFieldUnicode(extraFieldUnicodeComment, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT, directory, fileEntry);
|
|
482
498
|
directory.extraFieldUnicodeComment = extraFieldUnicodeComment;
|
|
483
499
|
}
|
|
484
500
|
const extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);
|
|
@@ -592,16 +608,16 @@ function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory)
|
|
|
592
608
|
const timeProperties = [];
|
|
593
609
|
const timeRawProperties = [];
|
|
594
610
|
if ((flags & 0x1) == 0x1) {
|
|
595
|
-
timeProperties.push(
|
|
596
|
-
timeRawProperties.push(
|
|
611
|
+
timeProperties.push(PROPERTY_NAME_LAST_MODIFICATION_DATE);
|
|
612
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE);
|
|
597
613
|
}
|
|
598
614
|
if ((flags & 0x2) == 0x2) {
|
|
599
|
-
timeProperties.push(
|
|
600
|
-
timeRawProperties.push(
|
|
615
|
+
timeProperties.push(PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
616
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_LAST_ACCESS_DATE);
|
|
601
617
|
}
|
|
602
618
|
if ((flags & 0x4) == 0x4) {
|
|
603
|
-
timeProperties.push(
|
|
604
|
-
timeRawProperties.push(
|
|
619
|
+
timeProperties.push(PROPERTY_NAME_CREATION_DATE);
|
|
620
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_CREATION_DATE);
|
|
605
621
|
}
|
|
606
622
|
let offset = 1;
|
|
607
623
|
timeProperties.forEach((propertyName, indexProperty) => {
|
package/lib/core/zip-writer.js
CHANGED
|
@@ -78,7 +78,16 @@ import {
|
|
|
78
78
|
SplitZipWriter
|
|
79
79
|
} from "./io.js";
|
|
80
80
|
import { encodeText } from "./util/encode-text.js";
|
|
81
|
-
import {
|
|
81
|
+
import {
|
|
82
|
+
PROPERTY_NAME_LAST_MODIFICATION_DATE,
|
|
83
|
+
PROPERTY_NAME_LAST_ACCESS_DATE,
|
|
84
|
+
PROPERTY_NAME_CREATION_DATE,
|
|
85
|
+
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE,
|
|
86
|
+
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
87
|
+
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
88
|
+
PROPERTY_NAME_ZIP64,
|
|
89
|
+
Entry
|
|
90
|
+
} from "./zip-entry.js";
|
|
82
91
|
|
|
83
92
|
const ERR_DUPLICATED_NAME = "File already exists";
|
|
84
93
|
const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
|
|
@@ -215,9 +224,9 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
215
224
|
if (versionMadeBy > MAX_16_BITS) {
|
|
216
225
|
throw new Error(ERR_INVALID_VERSION);
|
|
217
226
|
}
|
|
218
|
-
const lastModDate = getOptionValue(zipWriter, options,
|
|
219
|
-
const lastAccessDate = getOptionValue(zipWriter, options,
|
|
220
|
-
const creationDate = getOptionValue(zipWriter, options,
|
|
227
|
+
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
|
|
228
|
+
const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
229
|
+
const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
221
230
|
const password = getOptionValue(zipWriter, options, "password");
|
|
222
231
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
223
232
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
@@ -255,13 +264,13 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
255
264
|
keepOrder = true;
|
|
256
265
|
}
|
|
257
266
|
let uncompressedSize = 0;
|
|
258
|
-
let msDosCompatible = getOptionValue(zipWriter, options,
|
|
267
|
+
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
259
268
|
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
260
269
|
msDosCompatible = true;
|
|
261
270
|
}
|
|
262
|
-
const internalFileAttribute = getOptionValue(zipWriter, options,
|
|
263
|
-
const externalFileAttribute = getOptionValue(zipWriter, options,
|
|
264
|
-
let zip64 = getOptionValue(zipWriter, options,
|
|
271
|
+
const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
|
|
272
|
+
const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
|
|
273
|
+
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
265
274
|
if (reader) {
|
|
266
275
|
if (reader instanceof ReadableStream) {
|
|
267
276
|
reader = {
|
|
@@ -280,7 +289,8 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
280
289
|
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
281
290
|
}
|
|
282
291
|
}
|
|
283
|
-
|
|
292
|
+
const { diskOffset } = zipWriter.writer;
|
|
293
|
+
if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
|
|
284
294
|
uncompressedSize >= MAX_32_BITS ||
|
|
285
295
|
maximumCompressedSize >= MAX_32_BITS) {
|
|
286
296
|
if (zip64 === false || !keepOrder) {
|
|
@@ -336,8 +346,9 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
336
346
|
let fileEntry;
|
|
337
347
|
try {
|
|
338
348
|
fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
|
|
349
|
+
zipWriter.pendingEntriesSize -= maximumEntrySize;
|
|
339
350
|
} catch (error) {
|
|
340
|
-
if (!error.corruptedEntry
|
|
351
|
+
if (!error.corruptedEntry) {
|
|
341
352
|
zipWriter.pendingEntriesSize -= maximumEntrySize;
|
|
342
353
|
}
|
|
343
354
|
throw error;
|
|
@@ -387,7 +398,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
387
398
|
if (zipWriter.addSplitZipSignature) {
|
|
388
399
|
delete zipWriter.addSplitZipSignature;
|
|
389
400
|
const signatureArray = new Uint8Array(4);
|
|
390
|
-
const signatureArrayView =
|
|
401
|
+
const signatureArrayView = getDataView(signatureArray);
|
|
391
402
|
setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
|
|
392
403
|
await writeData(writable, signatureArray);
|
|
393
404
|
zipWriter.offset += 4;
|
|
@@ -525,9 +536,9 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
|
|
|
525
536
|
externalFileAttribute,
|
|
526
537
|
diskNumberStart
|
|
527
538
|
};
|
|
539
|
+
let compressedSize = 0;
|
|
528
540
|
let uncompressedSize = 0;
|
|
529
541
|
let signature;
|
|
530
|
-
let compressedSize = 0;
|
|
531
542
|
const { writable } = writer;
|
|
532
543
|
if (reader) {
|
|
533
544
|
reader.chunkSize = getChunkSize(config);
|
|
@@ -922,7 +933,7 @@ async function closeFile(zipWriter, comment, options) {
|
|
|
922
933
|
const endOfdirectoryView = getDataView(endOfdirectoryArray);
|
|
923
934
|
let lastDiskNumber = writer.diskNumber;
|
|
924
935
|
const { availableSize } = writer;
|
|
925
|
-
if (availableSize < endOfdirectoryArray
|
|
936
|
+
if (availableSize < getLength(endOfdirectoryArray)) {
|
|
926
937
|
lastDiskNumber++;
|
|
927
938
|
}
|
|
928
939
|
offset = 0;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
|
|
4
4
|
"author": "Gildas Lormeau",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
|
-
"version": "2.6.
|
|
6
|
+
"version": "2.6.42",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"zip",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"web-workers",
|
|
23
23
|
"deno",
|
|
24
24
|
"node.js",
|
|
25
|
-
"multi-core"
|
|
25
|
+
"multi-core",
|
|
26
|
+
"split-zip"
|
|
26
27
|
],
|
|
27
28
|
"engines": {
|
|
28
29
|
"deno": ">=1.0.0",
|