@zip.js/zip.js 2.14.0 → 2.14.1

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.
Files changed (39) hide show
  1. package/BENCHMARKS.md +342 -454
  2. package/deno.json +1 -1
  3. package/dist/zip-core-external.js +262 -81
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +260 -74
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +262 -81
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +260 -74
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +262 -81
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +262 -76
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +266 -85
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +262 -76
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-module.wasm +0 -0
  20. package/dist/zip-native.js +262 -76
  21. package/dist/zip-native.min.js +1 -1
  22. package/dist/zip-web-worker-native.js +1 -1
  23. package/dist/zip-web-worker.js +1 -1
  24. package/dist/zip.js +266 -85
  25. package/dist/zip.min.js +1 -1
  26. package/index-native.cjs +262 -76
  27. package/index-native.min.js +1 -1
  28. package/index.cjs +266 -85
  29. package/index.min.js +1 -1
  30. package/lib/core/codec-worker.js +6 -5
  31. package/lib/core/streams/codecs/aes-hmac-sha1.js +194 -56
  32. package/lib/core/streams/zlib-wasm/zlib-streams.js +2 -7
  33. package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
  34. package/lib/core/version.js +1 -1
  35. package/lib/core/web-worker-inline-native.js +1 -1
  36. package/lib/core/web-worker-inline-wasm.js +1 -1
  37. package/lib/core/zip-reader.js +53 -6
  38. package/lib/core/zlib-streams-inline.js +1 -1
  39. package/package.json +1 -1
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zip-js/zip-js",
3
- "version": "2.14.0",
3
+ "version": "2.14.1",
4
4
  "exports": {
5
5
  ".": "./index.js",
6
6
  "./external": "./lib/zip-fs-external.js",
@@ -763,7 +763,7 @@ const BLOCK_LENGTH$1 = 16;
763
763
  const ROUND_KEYS_LENGTH = 60;
764
764
  const SHA1_BLOCK_LENGTH = 64;
765
765
  const SHA1_DIGEST_LENGTH = 20;
766
- const SHA1_SCHEDULE_LENGTH = 80;
766
+ const SHA1_SCHEDULE_LENGTH = 16;
767
767
  const SHA1_LENGTH_OFFSET = 56;
768
768
  const SHA1_PADDING = new Uint8Array([0x80]);
769
769
  const SHA1_ZERO = new Uint8Array(1);
@@ -782,9 +782,12 @@ function createEngine$2(key, authenticationKey) {
782
782
  initTables();
783
783
  const roundKeys = new Int32Array(ROUND_KEYS_LENGTH);
784
784
  const rounds = expandKey(key, roundKeys);
785
- const counter = new Uint8Array(BLOCK_LENGTH$1);
786
785
  const keystream = new Int32Array(BLOCK_LENGTH$1 / 4);
787
786
  const hmac = createHmac(authenticationKey);
787
+ let counter0 = 0;
788
+ let counter1 = 0;
789
+ let counter2 = 0;
790
+ let counter3 = 0;
788
791
  return {
789
792
  process(data, decrypt) {
790
793
  if (decrypt) {
@@ -820,31 +823,83 @@ function createEngine$2(key, authenticationKey) {
820
823
  }
821
824
 
822
825
  function nextKeystream() {
823
- for (let indexByte = 0; indexByte < BLOCK_LENGTH$1; indexByte++) {
824
- counter[indexByte]++;
825
- if (counter[indexByte] !== 0) {
826
- break;
827
- }
828
- }
829
- let s0 = ((counter[0] << 24) | (counter[1] << 16) | (counter[2] << 8) | counter[3]) ^ roundKeys[0];
830
- let s1 = ((counter[4] << 24) | (counter[5] << 16) | (counter[6] << 8) | counter[7]) ^ roundKeys[1];
831
- let s2 = ((counter[8] << 24) | (counter[9] << 16) | (counter[10] << 8) | counter[11]) ^ roundKeys[2];
832
- let s3 = ((counter[12] << 24) | (counter[13] << 16) | (counter[14] << 8) | counter[15]) ^ roundKeys[3];
833
- let indexKey = 4;
834
- for (let round = 1; round < rounds; round++, indexKey += 4) {
835
- const t0 = T0[s0 >>> 24] ^ T1[(s1 >>> 16) & 255] ^ T2[(s2 >>> 8) & 255] ^ T3[s3 & 255] ^ roundKeys[indexKey];
836
- const t1 = T0[s1 >>> 24] ^ T1[(s2 >>> 16) & 255] ^ T2[(s3 >>> 8) & 255] ^ T3[s0 & 255] ^ roundKeys[indexKey + 1];
837
- const t2 = T0[s2 >>> 24] ^ T1[(s3 >>> 16) & 255] ^ T2[(s0 >>> 8) & 255] ^ T3[s1 & 255] ^ roundKeys[indexKey + 2];
838
- const t3 = T0[s3 >>> 24] ^ T1[(s0 >>> 16) & 255] ^ T2[(s1 >>> 8) & 255] ^ T3[s2 & 255] ^ roundKeys[indexKey + 3];
839
- s0 = t0;
840
- s1 = t1;
841
- s2 = t2;
842
- s3 = t3;
843
- }
844
- keystream[0] = ((S_BOX[s0 >>> 24] << 24) | (S_BOX[(s1 >>> 16) & 255] << 16) | (S_BOX[(s2 >>> 8) & 255] << 8) | S_BOX[s3 & 255]) ^ roundKeys[indexKey];
845
- keystream[1] = ((S_BOX[s1 >>> 24] << 24) | (S_BOX[(s2 >>> 16) & 255] << 16) | (S_BOX[(s3 >>> 8) & 255] << 8) | S_BOX[s0 & 255]) ^ roundKeys[indexKey + 1];
846
- keystream[2] = ((S_BOX[s2 >>> 24] << 24) | (S_BOX[(s3 >>> 16) & 255] << 16) | (S_BOX[(s0 >>> 8) & 255] << 8) | S_BOX[s1 & 255]) ^ roundKeys[indexKey + 2];
847
- keystream[3] = ((S_BOX[s3 >>> 24] << 24) | (S_BOX[(s0 >>> 16) & 255] << 16) | (S_BOX[(s1 >>> 8) & 255] << 8) | S_BOX[s2 & 255]) ^ roundKeys[indexKey + 3];
826
+ counter0 = (counter0 + 1) | 0;
827
+ if (!counter0) {
828
+ counter1 = (counter1 + 1) | 0;
829
+ if (!counter1) {
830
+ counter2 = (counter2 + 1) | 0;
831
+ if (!counter2) {
832
+ counter3 = (counter3 + 1) | 0;
833
+ }
834
+ }
835
+ }
836
+ let s0 = swapBytes(counter0) ^ roundKeys[0];
837
+ let s1 = swapBytes(counter1) ^ roundKeys[1];
838
+ let s2 = swapBytes(counter2) ^ roundKeys[2];
839
+ let s3 = swapBytes(counter3) ^ roundKeys[3];
840
+ let t0 = T0[s0 >>> 24] ^ T1[(s1 >>> 16) & 255] ^ T2[(s2 >>> 8) & 255] ^ T3[s3 & 255] ^ roundKeys[4];
841
+ let t1 = T0[s1 >>> 24] ^ T1[(s2 >>> 16) & 255] ^ T2[(s3 >>> 8) & 255] ^ T3[s0 & 255] ^ roundKeys[5];
842
+ let t2 = T0[s2 >>> 24] ^ T1[(s3 >>> 16) & 255] ^ T2[(s0 >>> 8) & 255] ^ T3[s1 & 255] ^ roundKeys[6];
843
+ let t3 = T0[s3 >>> 24] ^ T1[(s0 >>> 16) & 255] ^ T2[(s1 >>> 8) & 255] ^ T3[s2 & 255] ^ roundKeys[7];
844
+ s0 = T0[t0 >>> 24] ^ T1[(t1 >>> 16) & 255] ^ T2[(t2 >>> 8) & 255] ^ T3[t3 & 255] ^ roundKeys[8];
845
+ s1 = T0[t1 >>> 24] ^ T1[(t2 >>> 16) & 255] ^ T2[(t3 >>> 8) & 255] ^ T3[t0 & 255] ^ roundKeys[9];
846
+ s2 = T0[t2 >>> 24] ^ T1[(t3 >>> 16) & 255] ^ T2[(t0 >>> 8) & 255] ^ T3[t1 & 255] ^ roundKeys[10];
847
+ s3 = T0[t3 >>> 24] ^ T1[(t0 >>> 16) & 255] ^ T2[(t1 >>> 8) & 255] ^ T3[t2 & 255] ^ roundKeys[11];
848
+ t0 = T0[s0 >>> 24] ^ T1[(s1 >>> 16) & 255] ^ T2[(s2 >>> 8) & 255] ^ T3[s3 & 255] ^ roundKeys[12];
849
+ t1 = T0[s1 >>> 24] ^ T1[(s2 >>> 16) & 255] ^ T2[(s3 >>> 8) & 255] ^ T3[s0 & 255] ^ roundKeys[13];
850
+ t2 = T0[s2 >>> 24] ^ T1[(s3 >>> 16) & 255] ^ T2[(s0 >>> 8) & 255] ^ T3[s1 & 255] ^ roundKeys[14];
851
+ t3 = T0[s3 >>> 24] ^ T1[(s0 >>> 16) & 255] ^ T2[(s1 >>> 8) & 255] ^ T3[s2 & 255] ^ roundKeys[15];
852
+ s0 = T0[t0 >>> 24] ^ T1[(t1 >>> 16) & 255] ^ T2[(t2 >>> 8) & 255] ^ T3[t3 & 255] ^ roundKeys[16];
853
+ s1 = T0[t1 >>> 24] ^ T1[(t2 >>> 16) & 255] ^ T2[(t3 >>> 8) & 255] ^ T3[t0 & 255] ^ roundKeys[17];
854
+ s2 = T0[t2 >>> 24] ^ T1[(t3 >>> 16) & 255] ^ T2[(t0 >>> 8) & 255] ^ T3[t1 & 255] ^ roundKeys[18];
855
+ s3 = T0[t3 >>> 24] ^ T1[(t0 >>> 16) & 255] ^ T2[(t1 >>> 8) & 255] ^ T3[t2 & 255] ^ roundKeys[19];
856
+ t0 = T0[s0 >>> 24] ^ T1[(s1 >>> 16) & 255] ^ T2[(s2 >>> 8) & 255] ^ T3[s3 & 255] ^ roundKeys[20];
857
+ t1 = T0[s1 >>> 24] ^ T1[(s2 >>> 16) & 255] ^ T2[(s3 >>> 8) & 255] ^ T3[s0 & 255] ^ roundKeys[21];
858
+ t2 = T0[s2 >>> 24] ^ T1[(s3 >>> 16) & 255] ^ T2[(s0 >>> 8) & 255] ^ T3[s1 & 255] ^ roundKeys[22];
859
+ t3 = T0[s3 >>> 24] ^ T1[(s0 >>> 16) & 255] ^ T2[(s1 >>> 8) & 255] ^ T3[s2 & 255] ^ roundKeys[23];
860
+ s0 = T0[t0 >>> 24] ^ T1[(t1 >>> 16) & 255] ^ T2[(t2 >>> 8) & 255] ^ T3[t3 & 255] ^ roundKeys[24];
861
+ s1 = T0[t1 >>> 24] ^ T1[(t2 >>> 16) & 255] ^ T2[(t3 >>> 8) & 255] ^ T3[t0 & 255] ^ roundKeys[25];
862
+ s2 = T0[t2 >>> 24] ^ T1[(t3 >>> 16) & 255] ^ T2[(t0 >>> 8) & 255] ^ T3[t1 & 255] ^ roundKeys[26];
863
+ s3 = T0[t3 >>> 24] ^ T1[(t0 >>> 16) & 255] ^ T2[(t1 >>> 8) & 255] ^ T3[t2 & 255] ^ roundKeys[27];
864
+ t0 = T0[s0 >>> 24] ^ T1[(s1 >>> 16) & 255] ^ T2[(s2 >>> 8) & 255] ^ T3[s3 & 255] ^ roundKeys[28];
865
+ t1 = T0[s1 >>> 24] ^ T1[(s2 >>> 16) & 255] ^ T2[(s3 >>> 8) & 255] ^ T3[s0 & 255] ^ roundKeys[29];
866
+ t2 = T0[s2 >>> 24] ^ T1[(s3 >>> 16) & 255] ^ T2[(s0 >>> 8) & 255] ^ T3[s1 & 255] ^ roundKeys[30];
867
+ t3 = T0[s3 >>> 24] ^ T1[(s0 >>> 16) & 255] ^ T2[(s1 >>> 8) & 255] ^ T3[s2 & 255] ^ roundKeys[31];
868
+ s0 = T0[t0 >>> 24] ^ T1[(t1 >>> 16) & 255] ^ T2[(t2 >>> 8) & 255] ^ T3[t3 & 255] ^ roundKeys[32];
869
+ s1 = T0[t1 >>> 24] ^ T1[(t2 >>> 16) & 255] ^ T2[(t3 >>> 8) & 255] ^ T3[t0 & 255] ^ roundKeys[33];
870
+ s2 = T0[t2 >>> 24] ^ T1[(t3 >>> 16) & 255] ^ T2[(t0 >>> 8) & 255] ^ T3[t1 & 255] ^ roundKeys[34];
871
+ s3 = T0[t3 >>> 24] ^ T1[(t0 >>> 16) & 255] ^ T2[(t1 >>> 8) & 255] ^ T3[t2 & 255] ^ roundKeys[35];
872
+ t0 = T0[s0 >>> 24] ^ T1[(s1 >>> 16) & 255] ^ T2[(s2 >>> 8) & 255] ^ T3[s3 & 255] ^ roundKeys[36];
873
+ t1 = T0[s1 >>> 24] ^ T1[(s2 >>> 16) & 255] ^ T2[(s3 >>> 8) & 255] ^ T3[s0 & 255] ^ roundKeys[37];
874
+ t2 = T0[s2 >>> 24] ^ T1[(s3 >>> 16) & 255] ^ T2[(s0 >>> 8) & 255] ^ T3[s1 & 255] ^ roundKeys[38];
875
+ t3 = T0[s3 >>> 24] ^ T1[(s0 >>> 16) & 255] ^ T2[(s1 >>> 8) & 255] ^ T3[s2 & 255] ^ roundKeys[39];
876
+ let indexKey = 40;
877
+ if (rounds > 10) {
878
+ s0 = T0[t0 >>> 24] ^ T1[(t1 >>> 16) & 255] ^ T2[(t2 >>> 8) & 255] ^ T3[t3 & 255] ^ roundKeys[40];
879
+ s1 = T0[t1 >>> 24] ^ T1[(t2 >>> 16) & 255] ^ T2[(t3 >>> 8) & 255] ^ T3[t0 & 255] ^ roundKeys[41];
880
+ s2 = T0[t2 >>> 24] ^ T1[(t3 >>> 16) & 255] ^ T2[(t0 >>> 8) & 255] ^ T3[t1 & 255] ^ roundKeys[42];
881
+ s3 = T0[t3 >>> 24] ^ T1[(t0 >>> 16) & 255] ^ T2[(t1 >>> 8) & 255] ^ T3[t2 & 255] ^ roundKeys[43];
882
+ t0 = T0[s0 >>> 24] ^ T1[(s1 >>> 16) & 255] ^ T2[(s2 >>> 8) & 255] ^ T3[s3 & 255] ^ roundKeys[44];
883
+ t1 = T0[s1 >>> 24] ^ T1[(s2 >>> 16) & 255] ^ T2[(s3 >>> 8) & 255] ^ T3[s0 & 255] ^ roundKeys[45];
884
+ t2 = T0[s2 >>> 24] ^ T1[(s3 >>> 16) & 255] ^ T2[(s0 >>> 8) & 255] ^ T3[s1 & 255] ^ roundKeys[46];
885
+ t3 = T0[s3 >>> 24] ^ T1[(s0 >>> 16) & 255] ^ T2[(s1 >>> 8) & 255] ^ T3[s2 & 255] ^ roundKeys[47];
886
+ indexKey = 48;
887
+ }
888
+ if (rounds > 12) {
889
+ s0 = T0[t0 >>> 24] ^ T1[(t1 >>> 16) & 255] ^ T2[(t2 >>> 8) & 255] ^ T3[t3 & 255] ^ roundKeys[48];
890
+ s1 = T0[t1 >>> 24] ^ T1[(t2 >>> 16) & 255] ^ T2[(t3 >>> 8) & 255] ^ T3[t0 & 255] ^ roundKeys[49];
891
+ s2 = T0[t2 >>> 24] ^ T1[(t3 >>> 16) & 255] ^ T2[(t0 >>> 8) & 255] ^ T3[t1 & 255] ^ roundKeys[50];
892
+ s3 = T0[t3 >>> 24] ^ T1[(t0 >>> 16) & 255] ^ T2[(t1 >>> 8) & 255] ^ T3[t2 & 255] ^ roundKeys[51];
893
+ t0 = T0[s0 >>> 24] ^ T1[(s1 >>> 16) & 255] ^ T2[(s2 >>> 8) & 255] ^ T3[s3 & 255] ^ roundKeys[52];
894
+ t1 = T0[s1 >>> 24] ^ T1[(s2 >>> 16) & 255] ^ T2[(s3 >>> 8) & 255] ^ T3[s0 & 255] ^ roundKeys[53];
895
+ t2 = T0[s2 >>> 24] ^ T1[(s3 >>> 16) & 255] ^ T2[(s0 >>> 8) & 255] ^ T3[s1 & 255] ^ roundKeys[54];
896
+ t3 = T0[s3 >>> 24] ^ T1[(s0 >>> 16) & 255] ^ T2[(s1 >>> 8) & 255] ^ T3[s2 & 255] ^ roundKeys[55];
897
+ indexKey = 56;
898
+ }
899
+ keystream[0] = ((S_BOX[t0 >>> 24] << 24) | (S_BOX[(t1 >>> 16) & 255] << 16) | (S_BOX[(t2 >>> 8) & 255] << 8) | S_BOX[t3 & 255]) ^ roundKeys[indexKey];
900
+ keystream[1] = ((S_BOX[t1 >>> 24] << 24) | (S_BOX[(t2 >>> 16) & 255] << 16) | (S_BOX[(t3 >>> 8) & 255] << 8) | S_BOX[t0 & 255]) ^ roundKeys[indexKey + 1];
901
+ keystream[2] = ((S_BOX[t2 >>> 24] << 24) | (S_BOX[(t3 >>> 16) & 255] << 16) | (S_BOX[(t0 >>> 8) & 255] << 8) | S_BOX[t1 & 255]) ^ roundKeys[indexKey + 2];
902
+ keystream[3] = ((S_BOX[t3 >>> 24] << 24) | (S_BOX[(t0 >>> 16) & 255] << 16) | (S_BOX[(t1 >>> 8) & 255] << 8) | S_BOX[t2 & 255]) ^ roundKeys[indexKey + 3];
848
903
  }
849
904
  }
850
905
 
@@ -968,47 +1023,126 @@ function createSha1() {
968
1023
  for (let index = 0; index < 16; index++) {
969
1024
  schedule[index] = view.getInt32(offset + 4 * index);
970
1025
  }
971
- for (let index = 16; index < SHA1_SCHEDULE_LENGTH; index++) {
972
- const word = schedule[index - 3] ^ schedule[index - 8] ^ schedule[index - 14] ^ schedule[index - 16];
973
- schedule[index] = (word << 1) | (word >>> 31);
974
- }
975
1026
  let a = state[0];
976
1027
  let b = state[1];
977
1028
  let c = state[2];
978
1029
  let d = state[3];
979
1030
  let e = state[4];
980
1031
  let t;
981
- for (let index = 0; index < 20; index++) {
982
- t = (((a << 5) | (a >>> 27)) + ((b & c) | (~b & d)) + e + 0x5A827999 + schedule[index]) | 0;
983
- e = d;
984
- d = c;
985
- c = (b << 30) | (b >>> 2);
986
- b = a;
987
- a = t;
988
- }
989
- for (let index = 20; index < 40; index++) {
990
- t = (((a << 5) | (a >>> 27)) + (b ^ c ^ d) + e + 0x6ED9EBA1 + schedule[index]) | 0;
991
- e = d;
992
- d = c;
993
- c = (b << 30) | (b >>> 2);
994
- b = a;
995
- a = t;
996
- }
997
- for (let index = 40; index < 60; index++) {
998
- t = (((a << 5) | (a >>> 27)) + ((b & c) | (b & d) | (c & d)) + e + 0x8F1BBCDC + schedule[index]) | 0;
999
- e = d;
1000
- d = c;
1001
- c = (b << 30) | (b >>> 2);
1002
- b = a;
1003
- a = t;
1004
- }
1005
- for (let index = 60; index < SHA1_SCHEDULE_LENGTH; index++) {
1006
- t = (((a << 5) | (a >>> 27)) + (b ^ c ^ d) + e + 0xCA62C1D6 + schedule[index]) | 0;
1007
- e = d;
1008
- d = c;
1009
- c = (b << 30) | (b >>> 2);
1010
- b = a;
1011
- a = t;
1032
+ for (let index = 0; index < 15; index += 5) {
1033
+ e = (((a << 5) | (a >>> 27)) + (((c ^ d) & b) ^ d) + e + 0x5A827999 + schedule[index]) | 0;
1034
+ b = (b << 30) | (b >>> 2);
1035
+ d = (((e << 5) | (e >>> 27)) + (((b ^ c) & a) ^ c) + d + 0x5A827999 + schedule[index + 1]) | 0;
1036
+ a = (a << 30) | (a >>> 2);
1037
+ c = (((d << 5) | (d >>> 27)) + (((a ^ b) & e) ^ b) + c + 0x5A827999 + schedule[index + 2]) | 0;
1038
+ e = (e << 30) | (e >>> 2);
1039
+ b = (((c << 5) | (c >>> 27)) + (((e ^ a) & d) ^ a) + b + 0x5A827999 + schedule[index + 3]) | 0;
1040
+ d = (d << 30) | (d >>> 2);
1041
+ a = (((b << 5) | (b >>> 27)) + (((d ^ e) & c) ^ e) + a + 0x5A827999 + schedule[index + 4]) | 0;
1042
+ c = (c << 30) | (c >>> 2);
1043
+ }
1044
+ e = (((a << 5) | (a >>> 27)) + (((c ^ d) & b) ^ d) + e + 0x5A827999 + schedule[15]) | 0;
1045
+ b = (b << 30) | (b >>> 2);
1046
+ t = schedule[13] ^ schedule[8] ^ schedule[2] ^ schedule[0];
1047
+ t = (t << 1) | (t >>> 31);
1048
+ schedule[0] = t;
1049
+ d = (((e << 5) | (e >>> 27)) + (((b ^ c) & a) ^ c) + d + 0x5A827999 + t) | 0;
1050
+ a = (a << 30) | (a >>> 2);
1051
+ t = schedule[14] ^ schedule[9] ^ schedule[3] ^ schedule[1];
1052
+ t = (t << 1) | (t >>> 31);
1053
+ schedule[1] = t;
1054
+ c = (((d << 5) | (d >>> 27)) + (((a ^ b) & e) ^ b) + c + 0x5A827999 + t) | 0;
1055
+ e = (e << 30) | (e >>> 2);
1056
+ t = schedule[15] ^ schedule[10] ^ schedule[4] ^ schedule[2];
1057
+ t = (t << 1) | (t >>> 31);
1058
+ schedule[2] = t;
1059
+ b = (((c << 5) | (c >>> 27)) + (((e ^ a) & d) ^ a) + b + 0x5A827999 + t) | 0;
1060
+ d = (d << 30) | (d >>> 2);
1061
+ t = schedule[0] ^ schedule[11] ^ schedule[5] ^ schedule[3];
1062
+ t = (t << 1) | (t >>> 31);
1063
+ schedule[3] = t;
1064
+ a = (((b << 5) | (b >>> 27)) + (((d ^ e) & c) ^ e) + a + 0x5A827999 + t) | 0;
1065
+ c = (c << 30) | (c >>> 2);
1066
+ for (let index = 20; index < 40; index += 5) {
1067
+ t = schedule[(index - 3) & 15] ^ schedule[(index - 8) & 15] ^ schedule[(index - 14) & 15] ^ schedule[(index) & 15];
1068
+ t = (t << 1) | (t >>> 31);
1069
+ schedule[(index) & 15] = t;
1070
+ e = (((a << 5) | (a >>> 27)) + (b ^ c ^ d) + e + 0x6ED9EBA1 + t) | 0;
1071
+ b = (b << 30) | (b >>> 2);
1072
+ t = schedule[(index - 2) & 15] ^ schedule[(index - 7) & 15] ^ schedule[(index - 13) & 15] ^ schedule[(index + 1) & 15];
1073
+ t = (t << 1) | (t >>> 31);
1074
+ schedule[(index + 1) & 15] = t;
1075
+ d = (((e << 5) | (e >>> 27)) + (a ^ b ^ c) + d + 0x6ED9EBA1 + t) | 0;
1076
+ a = (a << 30) | (a >>> 2);
1077
+ t = schedule[(index - 1) & 15] ^ schedule[(index - 6) & 15] ^ schedule[(index - 12) & 15] ^ schedule[(index + 2) & 15];
1078
+ t = (t << 1) | (t >>> 31);
1079
+ schedule[(index + 2) & 15] = t;
1080
+ c = (((d << 5) | (d >>> 27)) + (e ^ a ^ b) + c + 0x6ED9EBA1 + t) | 0;
1081
+ e = (e << 30) | (e >>> 2);
1082
+ t = schedule[(index) & 15] ^ schedule[(index - 5) & 15] ^ schedule[(index - 11) & 15] ^ schedule[(index + 3) & 15];
1083
+ t = (t << 1) | (t >>> 31);
1084
+ schedule[(index + 3) & 15] = t;
1085
+ b = (((c << 5) | (c >>> 27)) + (d ^ e ^ a) + b + 0x6ED9EBA1 + t) | 0;
1086
+ d = (d << 30) | (d >>> 2);
1087
+ t = schedule[(index + 1) & 15] ^ schedule[(index - 4) & 15] ^ schedule[(index - 10) & 15] ^ schedule[(index + 4) & 15];
1088
+ t = (t << 1) | (t >>> 31);
1089
+ schedule[(index + 4) & 15] = t;
1090
+ a = (((b << 5) | (b >>> 27)) + (c ^ d ^ e) + a + 0x6ED9EBA1 + t) | 0;
1091
+ c = (c << 30) | (c >>> 2);
1092
+ }
1093
+ for (let index = 40; index < 60; index += 5) {
1094
+ t = schedule[(index - 3) & 15] ^ schedule[(index - 8) & 15] ^ schedule[(index - 14) & 15] ^ schedule[(index) & 15];
1095
+ t = (t << 1) | (t >>> 31);
1096
+ schedule[(index) & 15] = t;
1097
+ e = (((a << 5) | (a >>> 27)) + ((b & c) | ((b | c) & d)) + e + 0x8F1BBCDC + t) | 0;
1098
+ b = (b << 30) | (b >>> 2);
1099
+ t = schedule[(index - 2) & 15] ^ schedule[(index - 7) & 15] ^ schedule[(index - 13) & 15] ^ schedule[(index + 1) & 15];
1100
+ t = (t << 1) | (t >>> 31);
1101
+ schedule[(index + 1) & 15] = t;
1102
+ d = (((e << 5) | (e >>> 27)) + ((a & b) | ((a | b) & c)) + d + 0x8F1BBCDC + t) | 0;
1103
+ a = (a << 30) | (a >>> 2);
1104
+ t = schedule[(index - 1) & 15] ^ schedule[(index - 6) & 15] ^ schedule[(index - 12) & 15] ^ schedule[(index + 2) & 15];
1105
+ t = (t << 1) | (t >>> 31);
1106
+ schedule[(index + 2) & 15] = t;
1107
+ c = (((d << 5) | (d >>> 27)) + ((e & a) | ((e | a) & b)) + c + 0x8F1BBCDC + t) | 0;
1108
+ e = (e << 30) | (e >>> 2);
1109
+ t = schedule[(index) & 15] ^ schedule[(index - 5) & 15] ^ schedule[(index - 11) & 15] ^ schedule[(index + 3) & 15];
1110
+ t = (t << 1) | (t >>> 31);
1111
+ schedule[(index + 3) & 15] = t;
1112
+ b = (((c << 5) | (c >>> 27)) + ((d & e) | ((d | e) & a)) + b + 0x8F1BBCDC + t) | 0;
1113
+ d = (d << 30) | (d >>> 2);
1114
+ t = schedule[(index + 1) & 15] ^ schedule[(index - 4) & 15] ^ schedule[(index - 10) & 15] ^ schedule[(index + 4) & 15];
1115
+ t = (t << 1) | (t >>> 31);
1116
+ schedule[(index + 4) & 15] = t;
1117
+ a = (((b << 5) | (b >>> 27)) + ((c & d) | ((c | d) & e)) + a + 0x8F1BBCDC + t) | 0;
1118
+ c = (c << 30) | (c >>> 2);
1119
+ }
1120
+ for (let index = 60; index < 80; index += 5) {
1121
+ t = schedule[(index - 3) & 15] ^ schedule[(index - 8) & 15] ^ schedule[(index - 14) & 15] ^ schedule[(index) & 15];
1122
+ t = (t << 1) | (t >>> 31);
1123
+ schedule[(index) & 15] = t;
1124
+ e = (((a << 5) | (a >>> 27)) + (b ^ c ^ d) + e + 0xCA62C1D6 + t) | 0;
1125
+ b = (b << 30) | (b >>> 2);
1126
+ t = schedule[(index - 2) & 15] ^ schedule[(index - 7) & 15] ^ schedule[(index - 13) & 15] ^ schedule[(index + 1) & 15];
1127
+ t = (t << 1) | (t >>> 31);
1128
+ schedule[(index + 1) & 15] = t;
1129
+ d = (((e << 5) | (e >>> 27)) + (a ^ b ^ c) + d + 0xCA62C1D6 + t) | 0;
1130
+ a = (a << 30) | (a >>> 2);
1131
+ t = schedule[(index - 1) & 15] ^ schedule[(index - 6) & 15] ^ schedule[(index - 12) & 15] ^ schedule[(index + 2) & 15];
1132
+ t = (t << 1) | (t >>> 31);
1133
+ schedule[(index + 2) & 15] = t;
1134
+ c = (((d << 5) | (d >>> 27)) + (e ^ a ^ b) + c + 0xCA62C1D6 + t) | 0;
1135
+ e = (e << 30) | (e >>> 2);
1136
+ t = schedule[(index) & 15] ^ schedule[(index - 5) & 15] ^ schedule[(index - 11) & 15] ^ schedule[(index + 3) & 15];
1137
+ t = (t << 1) | (t >>> 31);
1138
+ schedule[(index + 3) & 15] = t;
1139
+ b = (((c << 5) | (c >>> 27)) + (d ^ e ^ a) + b + 0xCA62C1D6 + t) | 0;
1140
+ d = (d << 30) | (d >>> 2);
1141
+ t = schedule[(index + 1) & 15] ^ schedule[(index - 4) & 15] ^ schedule[(index - 10) & 15] ^ schedule[(index + 4) & 15];
1142
+ t = (t << 1) | (t >>> 31);
1143
+ schedule[(index + 4) & 15] = t;
1144
+ a = (((b << 5) | (b >>> 27)) + (c ^ d ^ e) + a + 0xCA62C1D6 + t) | 0;
1145
+ c = (c << 30) | (c >>> 2);
1012
1146
  }
1013
1147
  state[0] = (state[0] + a) | 0;
1014
1148
  state[1] = (state[1] + b) | 0;
@@ -1071,6 +1205,10 @@ function substituteWord(word) {
1071
1205
  return (S_BOX[word >>> 24] << 24) | (S_BOX[(word >>> 16) & 255] << 16) | (S_BOX[(word >>> 8) & 255] << 8) | S_BOX[word & 255];
1072
1206
  }
1073
1207
 
1208
+ function swapBytes(value) {
1209
+ return (value << 24) | ((value & 0xff00) << 8) | ((value >>> 8) & 0xff00) | (value >>> 24);
1210
+ }
1211
+
1074
1212
  function multiplyByTwo(value) {
1075
1213
  return ((value << 1) ^ ((value >> 7) * 0x1b)) & 255;
1076
1214
  }
@@ -2368,7 +2506,8 @@ class CodecWorker {
2368
2506
  return new Promise(resolve => {
2369
2507
  const { worker, busy } = workerData;
2370
2508
  if (busy) {
2371
- workerData.resolveTerminated = resolve;
2509
+ workerData.terminateResolvers = workerData.terminateResolvers || [];
2510
+ workerData.terminateResolvers.push(resolve);
2372
2511
  } else {
2373
2512
  if (worker) {
2374
2513
  worker.terminate();
@@ -2381,14 +2520,14 @@ class CodecWorker {
2381
2520
  },
2382
2521
  onTaskFinished() {
2383
2522
  if (workerData.busy) {
2384
- const { resolveTerminated, worker } = workerData;
2385
- if (resolveTerminated) {
2386
- workerData.resolveTerminated = null;
2523
+ const { terminateResolvers, worker } = workerData;
2524
+ if (terminateResolvers) {
2525
+ workerData.terminateResolvers = null;
2387
2526
  if (worker) {
2388
2527
  workerData.terminated = true;
2389
2528
  worker.terminate();
2390
2529
  }
2391
- resolveTerminated();
2530
+ terminateResolvers.forEach(resolve => resolve());
2392
2531
  }
2393
2532
  workerData.busy = false;
2394
2533
  onTaskFinished(workerData);
@@ -4554,7 +4693,7 @@ class ZipReader {
4554
4693
  Object.assign(this, {
4555
4694
  reader: new GenericReader(reader),
4556
4695
  options,
4557
- readRanges: new Map()
4696
+ readRanges: { indexes: new Set(), sortedRanges: [], pendingRanges: [] }
4558
4697
  });
4559
4698
  }
4560
4699
 
@@ -5199,7 +5338,6 @@ class ZipEntry {
5199
5338
  throw new Error(ERR_ENTRY_DATA_OUT_OF_BOUNDS);
5200
5339
  }
5201
5340
  const size = compressedSize;
5202
- const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5203
5341
  const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5204
5342
  throwIfAborted(signal);
5205
5343
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
@@ -5273,6 +5411,7 @@ class ZipEntry {
5273
5411
  writer = new GenericWriter(writer);
5274
5412
  await initStream(writer, getDecodableOutputSize(outputSize, compressedSize, compressed));
5275
5413
  ({ writable } = writer);
5414
+ const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5276
5415
  const { outputSize: writtenSize } = await runWorker({ readable, writable }, workerOptions);
5277
5416
  if (writtenSize != outputSize) {
5278
5417
  throw Object.assign(new Error(ERR_INVALID_UNCOMPRESSED_SIZE), { outputSize: writtenSize });
@@ -5708,14 +5847,61 @@ async function detectOverlappingEntry({
5708
5847
  end: dataOffset + compressedSize + dataDescriptorLength,
5709
5848
  fileEntry
5710
5849
  };
5711
- for (const [otherIndex, otherRange] of readRanges) {
5712
- if (otherIndex != index && range.start < otherRange.end && otherRange.start < range.end) {
5850
+ const { indexes, sortedRanges, pendingRanges } = readRanges;
5851
+ if (!indexes.has(index)) {
5852
+ const overlappingRange = findOverlappingRange(sortedRanges, range) || pendingRanges.find(otherRange => rangesOverlap(range, otherRange));
5853
+ if (overlappingRange) {
5713
5854
  const error = new Error(ERR_OVERLAPPING_ENTRY);
5714
- error.overlappingEntry = otherRange.fileEntry;
5855
+ error.overlappingEntry = overlappingRange.fileEntry;
5715
5856
  throw error;
5716
5857
  }
5858
+ indexes.add(index);
5859
+ pendingRanges.push(range);
5860
+ if (pendingRanges.length * pendingRanges.length > sortedRanges.length) {
5861
+ pendingRanges.sort((range, otherRange) => range.start - otherRange.start);
5862
+ readRanges.sortedRanges = mergeRanges(sortedRanges, pendingRanges);
5863
+ pendingRanges.length = 0;
5864
+ }
5865
+ }
5866
+ }
5867
+
5868
+ function findOverlappingRange(sortedRanges, range) {
5869
+ let low = 0;
5870
+ let high = sortedRanges.length;
5871
+ while (low < high) {
5872
+ const middle = (low + high) >>> 1;
5873
+ if (sortedRanges[middle].start < range.start) {
5874
+ low = middle + 1;
5875
+ } else {
5876
+ high = middle;
5877
+ }
5878
+ }
5879
+ const previousRange = sortedRanges[low - 1];
5880
+ const nextRange = sortedRanges[low];
5881
+ if (previousRange && rangesOverlap(range, previousRange)) {
5882
+ return previousRange;
5883
+ }
5884
+ if (nextRange && rangesOverlap(range, nextRange)) {
5885
+ return nextRange;
5886
+ }
5887
+ }
5888
+
5889
+ function rangesOverlap(range, otherRange) {
5890
+ return range.start < otherRange.end && otherRange.start < range.end;
5891
+ }
5892
+
5893
+ function mergeRanges(sortedRanges, pendingRanges) {
5894
+ const mergedRanges = [];
5895
+ let indexSorted = 0;
5896
+ let indexPending = 0;
5897
+ while (indexSorted < sortedRanges.length || indexPending < pendingRanges.length) {
5898
+ if (indexPending == pendingRanges.length || (indexSorted < sortedRanges.length && sortedRanges[indexSorted].start < pendingRanges[indexPending].start)) {
5899
+ mergedRanges.push(sortedRanges[indexSorted++]);
5900
+ } else {
5901
+ mergedRanges.push(pendingRanges[indexPending++]);
5902
+ }
5717
5903
  }
5718
- readRanges.set(index, range);
5904
+ return mergedRanges;
5719
5905
  }
5720
5906
 
5721
5907
  function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
@@ -8548,7 +8734,7 @@ function formatSupported(StreamClass, format) {
8548
8734
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8549
8735
  */
8550
8736
 
8551
- const VERSION = "2.14.0";
8737
+ const VERSION = "2.14.1";
8552
8738
 
8553
8739
  /*
8554
8740
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9071,7 +9257,6 @@ function _make(isCompress, type, options = {}) {
9071
9257
  if (!this.out || !this.in) {
9072
9258
  throw new Error("allocation failed");
9073
9259
  }
9074
- this._scratch = new Uint8Array(outBufferSize);
9075
9260
  if (isCompress) {
9076
9261
  this._process = wasm$1.deflate_process;
9077
9262
  this._last_consumed = wasm$1.deflate_last_consumed;
@@ -9120,7 +9305,6 @@ function _make(isCompress, type, options = {}) {
9120
9305
  const process = this._process;
9121
9306
  const last_consumed = this._last_consumed;
9122
9307
  const out = this.out;
9123
- const scratch = this._scratch;
9124
9308
  let offset = 0;
9125
9309
  while (offset < buffer.length) {
9126
9310
  const toRead = Math.min(buffer.length - offset, 32 * 1024);
@@ -9145,8 +9329,7 @@ function _make(isCompress, type, options = {}) {
9145
9329
  }
9146
9330
  const prod = result & 0x00ffffff;
9147
9331
  if (prod) {
9148
- scratch.set(heap.subarray(out, out + prod), 0);
9149
- controller.enqueue(scratch.slice(0, prod));
9332
+ controller.enqueue(heap.slice(out, out + prod));
9150
9333
  }
9151
9334
  const consumed = last_consumed(this.streamHandle);
9152
9335
  if (consumed === 0 && prod === 0) {
@@ -9164,7 +9347,6 @@ function _make(isCompress, type, options = {}) {
9164
9347
  const heap = new Uint8Array(memory.buffer);
9165
9348
  const process = this._process;
9166
9349
  const out = this.out;
9167
- const scratch = this._scratch;
9168
9350
  while (true) {
9169
9351
  const result = process(this.streamHandle, 0, 0, out, outBufferSize, 4);
9170
9352
  const code = (result >> 24) & 0xff;
@@ -9174,8 +9356,7 @@ function _make(isCompress, type, options = {}) {
9174
9356
  }
9175
9357
  const produced = result & 0x00ffffff;
9176
9358
  if (produced) {
9177
- scratch.set(heap.subarray(out, out + produced), 0);
9178
- controller.enqueue(scratch.slice(0, produced));
9359
+ controller.enqueue(heap.slice(out, out + produced));
9179
9360
  }
9180
9361
  if (code === 1 || produced === 0) {
9181
9362
  break;