@zip.js/zip.js 2.6.41 → 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/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
- "filename", "rawFilename", "directory", "encrypted", "compressedSize", "uncompressedSize",
8344
- "lastModDate", "rawLastModDate", "comment", "rawComment", "signature", "extraField",
8345
- "rawExtraField", "bitFlag", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
8346
- "extraFieldAES", "filenameUTF8", "commentUTF8", "offset", "zip64", "compressionMethod",
8347
- "extraFieldNTFS", "lastAccessDate", "creationDate", "extraFieldExtendedTimestamp",
8348
- "version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute",
8349
- "diskNumberStart"];
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
- ["uncompressedSize", MAX_32_BITS],
8402
- ["compressedSize", MAX_32_BITS],
8403
- ["offset", MAX_32_BITS],
8404
- ["diskNumberStart", MAX_16_BITS]
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, "filename", "rawFilename", directory, fileEntry);
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, "comment", "rawComment", directory, fileEntry);
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("lastModDate");
8884
- timeRawProperties.push("rawLastModDate");
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("lastAccessDate");
8888
- timeRawProperties.push("rawLastAccessDate");
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("creationDate");
8892
- timeRawProperties.push("rawCreationDate");
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, "lastModDate") || new Date();
9120
- const lastAccessDate = getOptionValue(zipWriter, options, "lastAccessDate");
9121
- const creationDate = getOptionValue(zipWriter, options, "creationDate");
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, "msDosCompatible");
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, "internalFileAttribute") || 0;
9164
- const externalFileAttribute = getOptionValue(zipWriter, options, "externalFileAttribute") || 0;
9165
- let zip64 = getOptionValue(zipWriter, options, "zip64");
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 = {
@@ -9238,8 +9258,9 @@ async function addFile(zipWriter, name, reader, options) {
9238
9258
  let fileEntry;
9239
9259
  try {
9240
9260
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
9261
+ zipWriter.pendingEntriesSize -= maximumEntrySize;
9241
9262
  } catch (error) {
9242
- if (!error.corruptedEntry && maximumEntrySize) {
9263
+ if (!error.corruptedEntry) {
9243
9264
  zipWriter.pendingEntriesSize -= maximumEntrySize;
9244
9265
  }
9245
9266
  throw error;
@@ -9289,7 +9310,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
9289
9310
  if (zipWriter.addSplitZipSignature) {
9290
9311
  delete zipWriter.addSplitZipSignature;
9291
9312
  const signatureArray = new Uint8Array(4);
9292
- const signatureArrayView = new DataView(signatureArray.buffer);
9313
+ const signatureArrayView = getDataView(signatureArray);
9293
9314
  setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
9294
9315
  await writeData(writable, signatureArray);
9295
9316
  zipWriter.offset += 4;
@@ -9427,9 +9448,9 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
9427
9448
  externalFileAttribute,
9428
9449
  diskNumberStart
9429
9450
  };
9451
+ let compressedSize = 0;
9430
9452
  let uncompressedSize = 0;
9431
9453
  let signature;
9432
- let compressedSize = 0;
9433
9454
  const { writable } = writer;
9434
9455
  if (reader) {
9435
9456
  reader.chunkSize = getChunkSize(config);
@@ -9824,7 +9845,7 @@ async function closeFile(zipWriter, comment, options) {
9824
9845
  const endOfdirectoryView = getDataView(endOfdirectoryArray);
9825
9846
  let lastDiskNumber = writer.diskNumber;
9826
9847
  const { availableSize } = writer;
9827
- if (availableSize < endOfdirectoryArray.length) {
9848
+ if (availableSize < getLength(endOfdirectoryArray)) {
9828
9849
  lastDiskNumber++;
9829
9850
  }
9830
9851
  offset = 0;
@@ -10578,7 +10599,7 @@ try {
10578
10599
  configure({ baseURL });
10579
10600
  e(configure);
10580
10601
 
10581
- /// <reference types="./index.d.ts" />
10602
+ /// <reference types="./index" />
10582
10603
 
10583
10604
  configure({ Deflate: ZipDeflate, Inflate: ZipInflate });
10584
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 write `internalFileAttribute` and `externalFileAttribute` in MS-DOS format.
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
- msDosCompatible?: boolean
1046
+ dataDescriptor?: boolean
1034
1047
  /**
1035
- * The internal file attribute.
1048
+ * `true` to add the signature of the data descriptor.
1036
1049
  *
1037
- * @defaultValue 0
1050
+ * @defaultValue false
1038
1051
  */
1039
- internalFileAttribute?: number
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
@@ -1,4 +1,4 @@
1
- /// <reference types="./index.d.ts" />
1
+ /// <reference types="./index" />
2
2
 
3
3
  /*
4
4
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
@@ -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
- "filename", "rawFilename", "directory", "encrypted", "compressedSize", "uncompressedSize",
31
- "lastModDate", "rawLastModDate", "comment", "rawComment", "signature", "extraField",
32
- "rawExtraField", "bitFlag", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
33
- "extraFieldAES", "filenameUTF8", "commentUTF8", "offset", "zip64", "compressionMethod",
34
- "extraFieldNTFS", "lastAccessDate", "creationDate", "extraFieldExtendedTimestamp",
35
- "version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute",
36
- "diskNumberStart"];
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
  };
@@ -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 { Entry } from "./zip-entry.js";
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
- ["uncompressedSize", MAX_32_BITS],
97
- ["compressedSize", MAX_32_BITS],
98
- ["offset", MAX_32_BITS],
99
- ["diskNumberStart", MAX_16_BITS]
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, "filename", "rawFilename", directory, fileEntry);
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, "comment", "rawComment", directory, fileEntry);
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("lastModDate");
596
- timeRawProperties.push("rawLastModDate");
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("lastAccessDate");
600
- timeRawProperties.push("rawLastAccessDate");
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("creationDate");
604
- timeRawProperties.push("rawCreationDate");
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) => {
@@ -78,7 +78,16 @@ import {
78
78
  SplitZipWriter
79
79
  } from "./io.js";
80
80
  import { encodeText } from "./util/encode-text.js";
81
- import { Entry } from "./zip-entry.js";
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, "lastModDate") || new Date();
219
- const lastAccessDate = getOptionValue(zipWriter, options, "lastAccessDate");
220
- const creationDate = getOptionValue(zipWriter, options, "creationDate");
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, "msDosCompatible");
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, "internalFileAttribute") || 0;
263
- const externalFileAttribute = getOptionValue(zipWriter, options, "externalFileAttribute") || 0;
264
- let zip64 = getOptionValue(zipWriter, options, "zip64");
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 = {
@@ -337,8 +346,9 @@ async function addFile(zipWriter, name, reader, options) {
337
346
  let fileEntry;
338
347
  try {
339
348
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
349
+ zipWriter.pendingEntriesSize -= maximumEntrySize;
340
350
  } catch (error) {
341
- if (!error.corruptedEntry && maximumEntrySize) {
351
+ if (!error.corruptedEntry) {
342
352
  zipWriter.pendingEntriesSize -= maximumEntrySize;
343
353
  }
344
354
  throw error;
@@ -388,7 +398,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
388
398
  if (zipWriter.addSplitZipSignature) {
389
399
  delete zipWriter.addSplitZipSignature;
390
400
  const signatureArray = new Uint8Array(4);
391
- const signatureArrayView = new DataView(signatureArray.buffer);
401
+ const signatureArrayView = getDataView(signatureArray);
392
402
  setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
393
403
  await writeData(writable, signatureArray);
394
404
  zipWriter.offset += 4;
@@ -526,9 +536,9 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
526
536
  externalFileAttribute,
527
537
  diskNumberStart
528
538
  };
539
+ let compressedSize = 0;
529
540
  let uncompressedSize = 0;
530
541
  let signature;
531
- let compressedSize = 0;
532
542
  const { writable } = writer;
533
543
  if (reader) {
534
544
  reader.chunkSize = getChunkSize(config);
@@ -923,7 +933,7 @@ async function closeFile(zipWriter, comment, options) {
923
933
  const endOfdirectoryView = getDataView(endOfdirectoryArray);
924
934
  let lastDiskNumber = writer.diskNumber;
925
935
  const { availableSize } = writer;
926
- if (availableSize < endOfdirectoryArray.length) {
936
+ if (availableSize < getLength(endOfdirectoryArray)) {
927
937
  lastDiskNumber++;
928
938
  }
929
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.41",
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",