@zip.js/zip.js 2.8.22 → 2.8.23

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.
@@ -169,7 +169,7 @@ const ERR_INVALID_VERSION = "Version exceeds 65535";
169
169
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
170
170
  const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
171
171
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
172
- const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
172
+ const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
173
173
  const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
174
174
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
175
175
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
@@ -601,14 +601,11 @@ async function addFile(zipWriter, name, reader, options) {
601
601
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
602
602
  }
603
603
  }
604
- const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
604
+ const { diskOffset, diskNumber } = zipWriter.writer;
605
605
  const zip64UncompressedSize = zip64Enabled || uncompressedSize > MAX_32_BITS;
606
606
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize > MAX_32_BITS;
607
- const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset > MAX_32_BITS;
608
- const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
609
- const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) > MAX_16_BITS;
610
- if (zip64Offset || zip64UncompressedSize || zip64CompressedSize || zip64DiskNumberStart) {
611
- if (zip64 === false || !keepOrder) {
607
+ if (zip64UncompressedSize || zip64CompressedSize) {
608
+ if (zip64 === false) {
612
609
  throw new Error(ERR_UNSUPPORTED_FORMAT);
613
610
  } else {
614
611
  zip64 = true;
@@ -628,8 +625,6 @@ async function addFile(zipWriter, name, reader, options) {
628
625
  zip64,
629
626
  zip64UncompressedSize,
630
627
  zip64CompressedSize,
631
- zip64Offset,
632
- zip64DiskNumberStart,
633
628
  password,
634
629
  rawPassword,
635
630
  level,
@@ -757,7 +752,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
757
752
  await writeData(fileWriter, localHeaderArray);
758
753
  }
759
754
  fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
760
- const { zip64 } = fileEntry;
761
755
  if (!bufferedWrite) {
762
756
  writingEntryData = false;
763
757
  }
@@ -769,9 +763,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
769
763
  writingBufferedEntryData = true;
770
764
  fileEntry.diskNumberStart = writer.diskNumber;
771
765
  fileEntry.offset = zipWriter.offset - writer.diskOffset;
772
- if (zip64) {
773
- updateZip64ExtraField(fileEntry);
774
- }
775
766
  updateLocalHeader(fileEntry, localHeaderView, options);
776
767
  await skipDiskIfNeeded(writable);
777
768
  await writeData(writer, localHeaderArray);
@@ -780,12 +771,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
780
771
  writingBufferedEntryData = false;
781
772
  } else {
782
773
  fileEntry.offset = zipWriter.offset - diskOffset;
783
- if (zip64) {
784
- updateZip64ExtraField(fileEntry);
785
- }
786
- }
787
- if (fileEntry.offset > MAX_32_BITS && !zip64) {
788
- throw new Error(ERR_UNSUPPORTED_FORMAT);
789
774
  }
790
775
  zipWriter.offset += fileEntry.size;
791
776
  return fileEntry;
@@ -875,8 +860,6 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
875
860
  zip64,
876
861
  zip64UncompressedSize,
877
862
  zip64CompressedSize,
878
- zip64Offset,
879
- zip64DiskNumberStart,
880
863
  zipCrypto,
881
864
  dataDescriptor,
882
865
  directory,
@@ -1014,9 +997,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
1014
997
  signature,
1015
998
  extraFieldExtendedTimestampFlag,
1016
999
  zip64UncompressedSize,
1017
- zip64CompressedSize,
1018
- zip64Offset,
1019
- zip64DiskNumberStart
1000
+ zip64CompressedSize
1020
1001
  });
1021
1002
  return fileEntry;
1022
1003
  }
@@ -1040,74 +1021,41 @@ function getHeaderInfo(options) {
1040
1021
  encrypted,
1041
1022
  zip64UncompressedSize,
1042
1023
  zip64CompressedSize,
1043
- zip64Offset,
1044
- zip64DiskNumberStart,
1045
- uncompressedSize,
1046
- offset,
1047
- diskNumberStart
1024
+ uncompressedSize
1048
1025
  } = options;
1049
1026
  let { version, compressionMethod } = options;
1050
1027
  const compressed = !directory && (level > 0 || (level === UNDEFINED_VALUE && compressionMethod !== 0));
1051
- let rawExtraFieldZip64;
1052
1028
  let rawLocalExtraFieldZip64;
1053
1029
  const uncompressedFile = passThrough || !compressed;
1054
1030
  const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
1055
1031
  if (zip64) {
1056
- let rawExtraFieldZip64Length = 4;
1057
1032
  let rawLocalExtraFieldZip64Length = 4;
1058
1033
  if (zip64UncompressedSize) {
1059
- rawExtraFieldZip64Length += 8;
1060
1034
  rawLocalExtraFieldZip64Length += 8;
1061
1035
  }
1062
1036
  if (zip64CompressedSize) {
1063
- rawExtraFieldZip64Length += 8;
1064
1037
  rawLocalExtraFieldZip64Length += 8;
1065
1038
  }
1066
- if (zip64Offset) {
1067
- rawExtraFieldZip64Length += 8;
1068
- }
1069
- if (zip64DiskNumberStart) {
1070
- rawExtraFieldZip64Length += 4;
1071
- }
1072
- rawExtraFieldZip64 = new Uint8Array(rawExtraFieldZip64Length);
1073
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
1074
1039
  rawLocalExtraFieldZip64 = new Uint8Array(rawLocalExtraFieldZip64Length);
1075
1040
  const rawLocalExtraFieldZip64View = getDataView(rawLocalExtraFieldZip64);
1076
- setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
1077
- setUint16(rawExtraFieldZip64View, 2, getLength(rawExtraFieldZip64) - 4);
1078
1041
  setUint16(rawLocalExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
1079
1042
  setUint16(rawLocalExtraFieldZip64View, 2, getLength(rawLocalExtraFieldZip64) - 4);
1080
1043
  if (zip64ExtraFieldComplete) {
1081
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
1082
1044
  const rawLocalExtraFieldZip64View = getDataView(rawLocalExtraFieldZip64);
1083
- let rawExtraFieldZip64Offset = 4;
1084
1045
  let rawLocalExtraFieldZip64Offset = 4;
1085
1046
  if (zip64UncompressedSize) {
1086
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
1087
- rawExtraFieldZip64Offset += 8;
1088
1047
  setBigUint64(rawLocalExtraFieldZip64View, rawLocalExtraFieldZip64Offset, BigInt(uncompressedSize));
1089
1048
  rawLocalExtraFieldZip64Offset += 8;
1090
1049
  }
1091
1050
  if (zip64CompressedSize && uncompressedFile) {
1092
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
1093
- rawExtraFieldZip64Offset += 8;
1094
1051
  setBigUint64(rawLocalExtraFieldZip64View, rawLocalExtraFieldZip64Offset, BigInt(uncompressedSize));
1095
1052
  rawLocalExtraFieldZip64Offset += 8;
1096
1053
  }
1097
- if (zip64Offset) {
1098
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
1099
- rawExtraFieldZip64Offset += 8;
1100
- }
1101
- if (zip64DiskNumberStart) {
1102
- setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
1103
- rawExtraFieldZip64Offset += 4;
1104
- }
1105
1054
  if (rawLocalExtraFieldZip64Offset == 4) {
1106
1055
  rawLocalExtraFieldZip64 = new Uint8Array();
1107
1056
  }
1108
1057
  }
1109
1058
  } else {
1110
- rawExtraFieldZip64 = new Uint8Array();
1111
1059
  rawLocalExtraFieldZip64 = new Uint8Array();
1112
1060
  }
1113
1061
  let rawExtraFieldAES;
@@ -1264,7 +1212,7 @@ function getHeaderInfo(options) {
1264
1212
  version,
1265
1213
  compressionMethod,
1266
1214
  extraFieldExtendedTimestampFlag,
1267
- rawExtraFieldZip64,
1215
+ rawExtraFieldZip64: new Uint8Array(),
1268
1216
  localExtraFieldZip64Length,
1269
1217
  rawExtraFieldExtendedTimestamp,
1270
1218
  rawExtraFieldNTFS,
@@ -1436,35 +1384,6 @@ function updateLocalHeader({
1436
1384
  }
1437
1385
  }
1438
1386
 
1439
- function updateZip64ExtraField({
1440
- compressedSize,
1441
- uncompressedSize,
1442
- offset,
1443
- diskNumberStart,
1444
- zip64UncompressedSize,
1445
- zip64CompressedSize,
1446
- zip64Offset,
1447
- zip64DiskNumberStart,
1448
- rawExtraFieldZip64
1449
- }) {
1450
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
1451
- let rawExtraFieldZip64Offset = 4;
1452
- if (zip64UncompressedSize) {
1453
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
1454
- rawExtraFieldZip64Offset += 8;
1455
- }
1456
- if (zip64CompressedSize) {
1457
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(compressedSize));
1458
- rawExtraFieldZip64Offset += 8;
1459
- }
1460
- if (zip64Offset) {
1461
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
1462
- rawExtraFieldZip64Offset += 8;
1463
- }
1464
- if (zip64DiskNumberStart) {
1465
- setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
1466
- }
1467
- }
1468
1387
 
1469
1388
  async function closeFile(zipWriter, comment, options) {
1470
1389
  const { files, writer } = zipWriter;
@@ -1477,7 +1396,6 @@ async function closeFile(zipWriter, comment, options) {
1477
1396
  for (const [, fileEntry] of files) {
1478
1397
  const {
1479
1398
  rawFilename,
1480
- rawExtraFieldZip64,
1481
1399
  rawExtraFieldAES,
1482
1400
  rawComment,
1483
1401
  rawExtraFieldNTFS,
@@ -1485,8 +1403,36 @@ async function closeFile(zipWriter, comment, options) {
1485
1403
  rawExtraField,
1486
1404
  extendedTimestamp,
1487
1405
  extraFieldExtendedTimestampFlag,
1488
- lastModDate
1406
+ lastModDate,
1407
+ zip64UncompressedSize,
1408
+ zip64CompressedSize,
1409
+ uncompressedSize,
1410
+ compressedSize
1489
1411
  } = fileEntry;
1412
+ const zip64Offset = fileEntry.offset > MAX_32_BITS;
1413
+ const zip64DiskNumberStart = fileEntry.diskNumberStart > MAX_16_BITS;
1414
+ let rawExtraFieldZip64;
1415
+ if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
1416
+ let length = 4;
1417
+ if (zip64UncompressedSize) length += 8;
1418
+ if (zip64CompressedSize) length += 8;
1419
+ if (zip64Offset) length += 8;
1420
+ if (zip64DiskNumberStart) length += 4;
1421
+ rawExtraFieldZip64 = new Uint8Array(length);
1422
+ const zip64View = getDataView(rawExtraFieldZip64);
1423
+ setUint16(zip64View, 0, EXTRAFIELD_TYPE_ZIP64);
1424
+ setUint16(zip64View, 2, length - 4);
1425
+ let zip64FieldOffset = 4;
1426
+ if (zip64UncompressedSize) { setBigUint64(zip64View, zip64FieldOffset, BigInt(uncompressedSize)); zip64FieldOffset += 8; }
1427
+ if (zip64CompressedSize) { setBigUint64(zip64View, zip64FieldOffset, BigInt(compressedSize)); zip64FieldOffset += 8; }
1428
+ if (zip64Offset) { setBigUint64(zip64View, zip64FieldOffset, BigInt(fileEntry.offset)); zip64FieldOffset += 8; }
1429
+ if (zip64DiskNumberStart) { setUint32(zip64View, zip64FieldOffset, fileEntry.diskNumberStart); }
1430
+ } else {
1431
+ rawExtraFieldZip64 = new Uint8Array();
1432
+ }
1433
+ fileEntry.rawExtraFieldZip64 = rawExtraFieldZip64;
1434
+ fileEntry.zip64Offset = zip64Offset;
1435
+ fileEntry.zip64DiskNumberStart = zip64DiskNumberStart;
1490
1436
  let rawExtraFieldTimestamp;
1491
1437
  if (extendedTimestamp) {
1492
1438
  rawExtraFieldTimestamp = new Uint8Array(9);
@@ -1528,7 +1474,6 @@ async function closeFile(zipWriter, comment, options) {
1528
1474
  versionMadeBy,
1529
1475
  headerArray,
1530
1476
  headerView,
1531
- zip64,
1532
1477
  zip64UncompressedSize,
1533
1478
  zip64CompressedSize,
1534
1479
  zip64DiskNumberStart,
@@ -1554,7 +1499,7 @@ async function closeFile(zipWriter, comment, options) {
1554
1499
  directoryOffset += 2;
1555
1500
  setUint16(directoryView, directoryOffset, getLength(rawComment));
1556
1501
  directoryOffset += 2;
1557
- setUint16(directoryView, directoryOffset, zip64 && zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
1502
+ setUint16(directoryView, directoryOffset, zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
1558
1503
  directoryOffset += 2;
1559
1504
  setUint16(directoryView, directoryOffset, internalFileAttributes);
1560
1505
  directoryOffset += 2;
@@ -1562,7 +1507,7 @@ async function closeFile(zipWriter, comment, options) {
1562
1507
  setUint32(directoryView, directoryOffset, externalFileAttributes);
1563
1508
  }
1564
1509
  directoryOffset += 4;
1565
- setUint32(directoryView, directoryOffset, zip64 && zip64Offset ? MAX_32_BITS : fileEntryOffset);
1510
+ setUint32(directoryView, directoryOffset, zip64Offset ? MAX_32_BITS : fileEntryOffset);
1566
1511
  directoryOffset += 4;
1567
1512
  arraySet(directoryArray, rawFilename, directoryOffset);
1568
1513
  directoryOffset += getLength(rawFilename);
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.8.22",
6
+ "version": "2.8.23",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",
@@ -155,7 +155,7 @@
155
155
  "homepage": "https://gildas-lormeau.github.io/zip.js",
156
156
  "devDependencies": {
157
157
  "@rollup/plugin-replace": "^6.0.3",
158
- "@rollup/plugin-terser": "^0.4.4",
158
+ "@rollup/plugin-terser": "^1.0.0",
159
159
  "eslint": "^10.0.2",
160
160
  "http-server": "^14.1.1",
161
161
  "rollup": "^4.59.0",