@cj-tech-master/excelts 4.2.1-canary.20260111102127.f808a37 → 4.2.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 (232) hide show
  1. package/THIRD_PARTY_NOTICES.md +31 -0
  2. package/dist/browser/index.browser.d.ts +0 -1
  3. package/dist/browser/index.browser.js +0 -12
  4. package/dist/browser/modules/archive/byte-queue.d.ts +18 -0
  5. package/dist/browser/modules/archive/byte-queue.js +125 -0
  6. package/dist/browser/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
  7. package/dist/browser/modules/archive/{compression/compress.browser.d.ts → compress.browser.d.ts} +8 -2
  8. package/dist/{esm/modules/archive/compression → browser/modules/archive}/compress.browser.js +11 -3
  9. package/dist/browser/modules/archive/{compression/compress.d.ts → compress.d.ts} +2 -2
  10. package/dist/{esm/modules/archive/compression → browser/modules/archive}/compress.js +1 -1
  11. package/dist/browser/modules/archive/{compression/crc32.browser.d.ts → crc32.browser.d.ts} +1 -1
  12. package/dist/browser/modules/archive/{compression/crc32.d.ts → crc32.d.ts} +1 -1
  13. package/dist/browser/modules/archive/{compression/crc32.js → crc32.js} +1 -1
  14. package/dist/browser/modules/archive/defaults.d.ts +0 -1
  15. package/dist/browser/modules/archive/defaults.js +3 -6
  16. package/dist/browser/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
  17. package/dist/browser/modules/archive/{unzip/extract.d.ts → extract.d.ts} +2 -2
  18. package/dist/browser/modules/archive/index.base.d.ts +4 -4
  19. package/dist/browser/modules/archive/index.base.js +6 -3
  20. package/dist/browser/modules/archive/index.browser.d.ts +4 -3
  21. package/dist/browser/modules/archive/index.browser.js +7 -3
  22. package/dist/browser/modules/archive/index.d.ts +4 -3
  23. package/dist/browser/modules/archive/index.js +5 -3
  24. package/dist/browser/modules/archive/{unzip/stream.base.d.ts → parse.base.d.ts} +2 -36
  25. package/dist/browser/modules/archive/parse.base.js +644 -0
  26. package/dist/browser/modules/archive/{unzip/stream.browser.d.ts → parse.browser.d.ts} +1 -1
  27. package/dist/{esm/modules/archive/unzip/stream.browser.js → browser/modules/archive/parse.browser.js} +110 -371
  28. package/dist/browser/modules/archive/{unzip/stream.d.ts → parse.d.ts} +2 -2
  29. package/dist/{esm/modules/archive/unzip/stream.js → browser/modules/archive/parse.js} +5 -6
  30. package/dist/browser/modules/archive/{compression/streaming-compress.browser.d.ts → streaming-compress.browser.d.ts} +2 -2
  31. package/dist/browser/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
  32. package/dist/browser/modules/archive/{compression/streaming-compress.d.ts → streaming-compress.d.ts} +2 -2
  33. package/dist/browser/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
  34. package/dist/browser/modules/archive/{zip/stream.d.ts → streaming-zip.d.ts} +5 -28
  35. package/dist/{esm/modules/archive/zip/stream.js → browser/modules/archive/streaming-zip.js} +48 -192
  36. package/dist/browser/modules/archive/utils/bytes.js +16 -16
  37. package/dist/browser/modules/archive/utils/parse-buffer.js +23 -21
  38. package/dist/browser/modules/archive/utils/timestamps.js +1 -62
  39. package/dist/browser/modules/archive/utils/zip-extra-fields.d.ts +1 -1
  40. package/dist/browser/modules/archive/utils/zip-extra-fields.js +14 -26
  41. package/dist/browser/modules/archive/utils/zip-extra.d.ts +18 -0
  42. package/dist/browser/modules/archive/utils/zip-extra.js +68 -0
  43. package/dist/browser/modules/archive/zip-builder.d.ts +117 -0
  44. package/dist/browser/modules/archive/zip-builder.js +292 -0
  45. package/dist/browser/modules/archive/zip-constants.d.ts +18 -0
  46. package/dist/browser/modules/archive/zip-constants.js +23 -0
  47. package/dist/{esm/modules/archive/zip → browser/modules/archive}/zip-entry-metadata.js +3 -3
  48. package/dist/{types/modules/archive/unzip → browser/modules/archive}/zip-parser.d.ts +1 -1
  49. package/dist/{esm/modules/archive/unzip → browser/modules/archive}/zip-parser.js +24 -38
  50. package/dist/browser/modules/archive/{zip-spec/zip-records.d.ts → zip-records.d.ts} +0 -20
  51. package/dist/browser/modules/archive/zip-records.js +84 -0
  52. package/dist/browser/modules/excel/stream/workbook-reader.browser.js +1 -1
  53. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
  54. package/dist/browser/modules/excel/stream/workbook-writer.browser.js +1 -1
  55. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +6 -3
  56. package/dist/browser/modules/excel/xlsx/xlsx.js +1 -1
  57. package/dist/browser/modules/stream/streams.browser.d.ts +30 -28
  58. package/dist/browser/modules/stream/streams.browser.js +710 -830
  59. package/dist/browser/modules/stream/streams.js +58 -140
  60. package/dist/cjs/modules/archive/byte-queue.js +129 -0
  61. package/dist/cjs/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
  62. package/dist/cjs/modules/archive/{compression/compress.browser.js → compress.browser.js} +11 -3
  63. package/dist/cjs/modules/archive/{compression/compress.js → compress.js} +1 -1
  64. package/dist/cjs/modules/archive/{compression/crc32.js → crc32.js} +1 -1
  65. package/dist/cjs/modules/archive/defaults.js +4 -7
  66. package/dist/cjs/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
  67. package/dist/cjs/modules/archive/index.base.js +19 -9
  68. package/dist/cjs/modules/archive/index.browser.js +10 -4
  69. package/dist/cjs/modules/archive/index.js +8 -4
  70. package/dist/cjs/modules/archive/parse.base.js +666 -0
  71. package/dist/cjs/modules/archive/{unzip/stream.browser.js → parse.browser.js} +111 -372
  72. package/dist/cjs/modules/archive/{unzip/stream.js → parse.js} +8 -9
  73. package/dist/cjs/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
  74. package/dist/cjs/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
  75. package/dist/cjs/modules/archive/{zip/stream.js → streaming-zip.js} +50 -194
  76. package/dist/cjs/modules/archive/utils/bytes.js +16 -16
  77. package/dist/cjs/modules/archive/utils/parse-buffer.js +23 -21
  78. package/dist/cjs/modules/archive/utils/timestamps.js +3 -64
  79. package/dist/cjs/modules/archive/utils/zip-extra-fields.js +14 -26
  80. package/dist/cjs/modules/archive/utils/zip-extra.js +74 -0
  81. package/dist/cjs/modules/archive/zip-builder.js +297 -0
  82. package/dist/cjs/modules/archive/zip-constants.js +26 -0
  83. package/dist/cjs/modules/archive/{zip/zip-entry-metadata.js → zip-entry-metadata.js} +5 -5
  84. package/dist/cjs/modules/archive/{unzip/zip-parser.js → zip-parser.js} +33 -47
  85. package/dist/cjs/modules/archive/zip-records.js +90 -0
  86. package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +2 -2
  87. package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +4 -4
  88. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +9 -6
  89. package/dist/cjs/modules/excel/xlsx/xlsx.js +2 -2
  90. package/dist/cjs/modules/stream/streams.browser.js +710 -830
  91. package/dist/cjs/modules/stream/streams.js +58 -140
  92. package/dist/esm/index.browser.js +0 -12
  93. package/dist/esm/modules/archive/byte-queue.js +125 -0
  94. package/dist/esm/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
  95. package/dist/{browser/modules/archive/compression → esm/modules/archive}/compress.browser.js +11 -3
  96. package/dist/{browser/modules/archive/compression → esm/modules/archive}/compress.js +1 -1
  97. package/dist/esm/modules/archive/{compression/crc32.js → crc32.js} +1 -1
  98. package/dist/esm/modules/archive/defaults.js +3 -6
  99. package/dist/esm/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
  100. package/dist/esm/modules/archive/index.base.js +6 -3
  101. package/dist/esm/modules/archive/index.browser.js +7 -3
  102. package/dist/esm/modules/archive/index.js +5 -3
  103. package/dist/esm/modules/archive/parse.base.js +644 -0
  104. package/dist/{browser/modules/archive/unzip/stream.browser.js → esm/modules/archive/parse.browser.js} +110 -371
  105. package/dist/{browser/modules/archive/unzip/stream.js → esm/modules/archive/parse.js} +5 -6
  106. package/dist/esm/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
  107. package/dist/esm/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
  108. package/dist/{browser/modules/archive/zip/stream.js → esm/modules/archive/streaming-zip.js} +48 -192
  109. package/dist/esm/modules/archive/utils/bytes.js +16 -16
  110. package/dist/esm/modules/archive/utils/parse-buffer.js +23 -21
  111. package/dist/esm/modules/archive/utils/timestamps.js +1 -62
  112. package/dist/esm/modules/archive/utils/zip-extra-fields.js +14 -26
  113. package/dist/esm/modules/archive/utils/zip-extra.js +68 -0
  114. package/dist/esm/modules/archive/zip-builder.js +292 -0
  115. package/dist/esm/modules/archive/zip-constants.js +23 -0
  116. package/dist/{browser/modules/archive/zip → esm/modules/archive}/zip-entry-metadata.js +3 -3
  117. package/dist/{browser/modules/archive/unzip → esm/modules/archive}/zip-parser.js +24 -38
  118. package/dist/esm/modules/archive/zip-records.js +84 -0
  119. package/dist/esm/modules/excel/stream/workbook-reader.browser.js +1 -1
  120. package/dist/esm/modules/excel/stream/workbook-writer.browser.js +1 -1
  121. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +6 -3
  122. package/dist/esm/modules/excel/xlsx/xlsx.js +1 -1
  123. package/dist/esm/modules/stream/streams.browser.js +710 -830
  124. package/dist/esm/modules/stream/streams.js +58 -140
  125. package/dist/iife/THIRD_PARTY_NOTICES.md +31 -0
  126. package/dist/iife/excelts.iife.js +4425 -6215
  127. package/dist/iife/excelts.iife.js.map +1 -1
  128. package/dist/iife/excelts.iife.min.js +31 -103
  129. package/dist/types/index.browser.d.ts +0 -1
  130. package/dist/types/modules/archive/byte-queue.d.ts +18 -0
  131. package/dist/types/modules/archive/{compression/compress.browser.d.ts → compress.browser.d.ts} +8 -2
  132. package/dist/types/modules/archive/defaults.d.ts +0 -1
  133. package/dist/types/modules/archive/index.base.d.ts +4 -4
  134. package/dist/types/modules/archive/index.browser.d.ts +4 -3
  135. package/dist/types/modules/archive/index.d.ts +4 -3
  136. package/dist/types/modules/archive/{unzip/stream.base.d.ts → parse.base.d.ts} +4 -38
  137. package/dist/types/modules/archive/{unzip/stream.browser.d.ts → parse.browser.d.ts} +2 -2
  138. package/dist/types/modules/archive/{unzip/stream.d.ts → parse.d.ts} +3 -3
  139. package/dist/types/modules/archive/{compression/streaming-compress.browser.d.ts → streaming-compress.browser.d.ts} +1 -1
  140. package/dist/types/modules/archive/{zip/stream.d.ts → streaming-zip.d.ts} +6 -29
  141. package/dist/types/modules/archive/utils/zip-extra-fields.d.ts +1 -1
  142. package/dist/types/modules/archive/utils/zip-extra.d.ts +18 -0
  143. package/dist/types/modules/archive/zip-builder.d.ts +117 -0
  144. package/dist/types/modules/archive/zip-constants.d.ts +18 -0
  145. package/dist/types/modules/archive/{zip/zip-entry-metadata.d.ts → zip-entry-metadata.d.ts} +1 -1
  146. package/dist/{browser/modules/archive/unzip → types/modules/archive}/zip-parser.d.ts +1 -1
  147. package/dist/types/modules/archive/{zip-spec/zip-records.d.ts → zip-records.d.ts} +0 -20
  148. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
  149. package/dist/types/modules/stream/streams.browser.d.ts +30 -28
  150. package/package.json +1 -5
  151. package/dist/browser/modules/archive/internal/byte-queue.d.ts +0 -33
  152. package/dist/browser/modules/archive/internal/byte-queue.js +0 -407
  153. package/dist/browser/modules/archive/io/archive-sink.d.ts +0 -9
  154. package/dist/browser/modules/archive/io/archive-sink.js +0 -77
  155. package/dist/browser/modules/archive/io/archive-source.d.ts +0 -8
  156. package/dist/browser/modules/archive/io/archive-source.js +0 -107
  157. package/dist/browser/modules/archive/unzip/index.d.ts +0 -40
  158. package/dist/browser/modules/archive/unzip/index.js +0 -164
  159. package/dist/browser/modules/archive/unzip/stream.base.js +0 -1022
  160. package/dist/browser/modules/archive/utils/async-queue.d.ts +0 -7
  161. package/dist/browser/modules/archive/utils/async-queue.js +0 -103
  162. package/dist/browser/modules/archive/utils/compressibility.d.ts +0 -10
  163. package/dist/browser/modules/archive/utils/compressibility.js +0 -57
  164. package/dist/browser/modules/archive/utils/pattern-scanner.d.ts +0 -21
  165. package/dist/browser/modules/archive/utils/pattern-scanner.js +0 -27
  166. package/dist/browser/modules/archive/zip/index.d.ts +0 -42
  167. package/dist/browser/modules/archive/zip/index.js +0 -157
  168. package/dist/browser/modules/archive/zip/zip-bytes.d.ts +0 -73
  169. package/dist/browser/modules/archive/zip/zip-bytes.js +0 -239
  170. package/dist/browser/modules/archive/zip-spec/zip-records.js +0 -126
  171. package/dist/cjs/modules/archive/internal/byte-queue.js +0 -411
  172. package/dist/cjs/modules/archive/io/archive-sink.js +0 -82
  173. package/dist/cjs/modules/archive/io/archive-source.js +0 -114
  174. package/dist/cjs/modules/archive/unzip/index.js +0 -170
  175. package/dist/cjs/modules/archive/unzip/stream.base.js +0 -1044
  176. package/dist/cjs/modules/archive/utils/async-queue.js +0 -106
  177. package/dist/cjs/modules/archive/utils/compressibility.js +0 -60
  178. package/dist/cjs/modules/archive/utils/pattern-scanner.js +0 -31
  179. package/dist/cjs/modules/archive/zip/index.js +0 -162
  180. package/dist/cjs/modules/archive/zip/zip-bytes.js +0 -242
  181. package/dist/cjs/modules/archive/zip-spec/zip-records.js +0 -136
  182. package/dist/esm/modules/archive/internal/byte-queue.js +0 -407
  183. package/dist/esm/modules/archive/io/archive-sink.js +0 -77
  184. package/dist/esm/modules/archive/io/archive-source.js +0 -107
  185. package/dist/esm/modules/archive/unzip/index.js +0 -164
  186. package/dist/esm/modules/archive/unzip/stream.base.js +0 -1022
  187. package/dist/esm/modules/archive/utils/async-queue.js +0 -103
  188. package/dist/esm/modules/archive/utils/compressibility.js +0 -57
  189. package/dist/esm/modules/archive/utils/pattern-scanner.js +0 -27
  190. package/dist/esm/modules/archive/zip/index.js +0 -157
  191. package/dist/esm/modules/archive/zip/zip-bytes.js +0 -239
  192. package/dist/esm/modules/archive/zip-spec/zip-records.js +0 -126
  193. package/dist/types/modules/archive/internal/byte-queue.d.ts +0 -33
  194. package/dist/types/modules/archive/io/archive-sink.d.ts +0 -9
  195. package/dist/types/modules/archive/io/archive-source.d.ts +0 -8
  196. package/dist/types/modules/archive/unzip/index.d.ts +0 -40
  197. package/dist/types/modules/archive/utils/async-queue.d.ts +0 -7
  198. package/dist/types/modules/archive/utils/compressibility.d.ts +0 -10
  199. package/dist/types/modules/archive/utils/pattern-scanner.d.ts +0 -21
  200. package/dist/types/modules/archive/zip/index.d.ts +0 -42
  201. package/dist/types/modules/archive/zip/zip-bytes.d.ts +0 -73
  202. /package/dist/browser/modules/archive/{compression/compress.base.d.ts → compress.base.d.ts} +0 -0
  203. /package/dist/browser/modules/archive/{compression/crc32.base.d.ts → crc32.base.d.ts} +0 -0
  204. /package/dist/browser/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
  205. /package/dist/browser/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
  206. /package/dist/browser/modules/archive/{compression/deflate-fallback.d.ts → deflate-fallback.d.ts} +0 -0
  207. /package/dist/browser/modules/archive/{unzip/extract.js → extract.js} +0 -0
  208. /package/dist/browser/modules/archive/{compression/streaming-compress.base.d.ts → streaming-compress.base.d.ts} +0 -0
  209. /package/dist/browser/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
  210. /package/dist/browser/modules/archive/{zip-spec/zip-entry-info.d.ts → zip-entry-info.d.ts} +0 -0
  211. /package/dist/browser/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
  212. /package/dist/browser/modules/archive/{zip/zip-entry-metadata.d.ts → zip-entry-metadata.d.ts} +0 -0
  213. /package/dist/cjs/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
  214. /package/dist/cjs/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
  215. /package/dist/cjs/modules/archive/{unzip/extract.js → extract.js} +0 -0
  216. /package/dist/cjs/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
  217. /package/dist/cjs/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
  218. /package/dist/esm/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
  219. /package/dist/esm/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
  220. /package/dist/esm/modules/archive/{unzip/extract.js → extract.js} +0 -0
  221. /package/dist/esm/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
  222. /package/dist/esm/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
  223. /package/dist/types/modules/archive/{compression/compress.base.d.ts → compress.base.d.ts} +0 -0
  224. /package/dist/types/modules/archive/{compression/compress.d.ts → compress.d.ts} +0 -0
  225. /package/dist/types/modules/archive/{compression/crc32.base.d.ts → crc32.base.d.ts} +0 -0
  226. /package/dist/types/modules/archive/{compression/crc32.browser.d.ts → crc32.browser.d.ts} +0 -0
  227. /package/dist/types/modules/archive/{compression/crc32.d.ts → crc32.d.ts} +0 -0
  228. /package/dist/types/modules/archive/{compression/deflate-fallback.d.ts → deflate-fallback.d.ts} +0 -0
  229. /package/dist/types/modules/archive/{unzip/extract.d.ts → extract.d.ts} +0 -0
  230. /package/dist/types/modules/archive/{compression/streaming-compress.base.d.ts → streaming-compress.base.d.ts} +0 -0
  231. /package/dist/types/modules/archive/{compression/streaming-compress.d.ts → streaming-compress.d.ts} +0 -0
  232. /package/dist/types/modules/archive/{zip-spec/zip-entry-info.d.ts → zip-entry-info.d.ts} +0 -0
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAsyncQueue = createAsyncQueue;
4
- function createAsyncQueue() {
5
- const values = [];
6
- let valuesHead = 0;
7
- const waiters = [];
8
- let waitersHead = 0;
9
- let done = false;
10
- let error = null;
11
- const maybeCompact = () => {
12
- // Prevent unbounded growth of the underlying arrays.
13
- if (valuesHead > 1024 && valuesHead * 2 > values.length) {
14
- values.splice(0, valuesHead);
15
- valuesHead = 0;
16
- }
17
- if (waitersHead > 1024 && waitersHead * 2 > waiters.length) {
18
- waiters.splice(0, waitersHead);
19
- waitersHead = 0;
20
- }
21
- };
22
- const shiftWaiter = () => {
23
- while (waitersHead < waiters.length) {
24
- const w = waiters[waitersHead];
25
- waiters[waitersHead] = undefined;
26
- waitersHead++;
27
- if (w) {
28
- maybeCompact();
29
- return w;
30
- }
31
- }
32
- maybeCompact();
33
- return undefined;
34
- };
35
- const shiftValue = () => {
36
- while (valuesHead < values.length) {
37
- const v = values[valuesHead];
38
- values[valuesHead] = undefined;
39
- valuesHead++;
40
- if (v !== undefined) {
41
- maybeCompact();
42
- return v;
43
- }
44
- }
45
- maybeCompact();
46
- return undefined;
47
- };
48
- const push = (value) => {
49
- if (done || error) {
50
- return;
51
- }
52
- const waiter = shiftWaiter();
53
- if (waiter) {
54
- waiter.resolve({ value, done: false });
55
- }
56
- else {
57
- values.push(value);
58
- }
59
- };
60
- const fail = (err) => {
61
- if (done || error) {
62
- return;
63
- }
64
- error = err;
65
- while (true) {
66
- const waiter = shiftWaiter();
67
- if (!waiter) {
68
- break;
69
- }
70
- waiter.reject(err);
71
- }
72
- };
73
- const close = () => {
74
- if (done || error) {
75
- return;
76
- }
77
- done = true;
78
- while (true) {
79
- const waiter = shiftWaiter();
80
- if (!waiter) {
81
- break;
82
- }
83
- waiter.resolve({ value: undefined, done: true });
84
- }
85
- };
86
- const iterable = {
87
- [Symbol.asyncIterator]() {
88
- return {
89
- next() {
90
- if (error) {
91
- return Promise.reject(error);
92
- }
93
- const value = shiftValue();
94
- if (value !== undefined) {
95
- return Promise.resolve({ value, done: false });
96
- }
97
- if (done) {
98
- return Promise.resolve({ value: undefined, done: true });
99
- }
100
- return new Promise((resolve, reject) => waiters.push({ resolve, reject }));
101
- }
102
- };
103
- }
104
- };
105
- return { push, fail, close, iterable };
106
- }
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isProbablyIncompressible = isProbablyIncompressible;
4
- const DEFAULT_SAMPLE_BYTES = 64 * 1024;
5
- const MIN_DECISION_BYTES = 16 * 1024;
6
- function log2(x) {
7
- return Math.log(x) / Math.LN2;
8
- }
9
- function shannonEntropy(bytes) {
10
- const counts = new Uint32Array(256);
11
- for (let i = 0; i < bytes.length; i++) {
12
- counts[bytes[i]] += 1;
13
- }
14
- let entropy = 0;
15
- const total = bytes.length;
16
- for (let i = 0; i < 256; i++) {
17
- const count = counts[i];
18
- if (count === 0) {
19
- continue;
20
- }
21
- const p = count / total;
22
- entropy -= p * log2(p);
23
- }
24
- return entropy;
25
- }
26
- /**
27
- * Heuristic: detect incompressible (high-entropy) data.
28
- *
29
- * This is a performance optimization: if data looks random, DEFLATE usually
30
- * wastes CPU and may even produce slightly larger output.
31
- */
32
- function isProbablyIncompressible(data, options = {}) {
33
- const sampleBytes = options.sampleBytes ?? DEFAULT_SAMPLE_BYTES;
34
- const minDecisionBytes = options.minDecisionBytes ?? MIN_DECISION_BYTES;
35
- const len = Math.min(data.length, sampleBytes);
36
- if (len < minDecisionBytes) {
37
- return false;
38
- }
39
- const sample = data.subarray(0, len);
40
- // Fast-ish early filter: if there are too few unique bytes, it's probably compressible.
41
- // (e.g. text, repeated patterns)
42
- const seen = new Uint8Array(256);
43
- let unique = 0;
44
- for (let i = 0; i < sample.length; i++) {
45
- const b = sample[i];
46
- if (seen[b] === 0) {
47
- seen[b] = 1;
48
- unique += 1;
49
- if (unique >= 200) {
50
- break;
51
- }
52
- }
53
- }
54
- if (unique < 200) {
55
- return false;
56
- }
57
- // Shannon entropy in bits/byte; random tends to ~8.
58
- // Threshold picked to be conservative.
59
- return shannonEntropy(sample) >= 7.95;
60
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PatternScanner = void 0;
4
- /**
5
- * Stateful helper for incremental pattern scanning in growing buffers.
6
- *
7
- * The scanner tracks a `searchFrom` cursor and an `overlap` region so callers
8
- * can avoid rescanning bytes that cannot start a match.
9
- */
10
- class PatternScanner {
11
- constructor(pattern) {
12
- this.searchFrom = 0;
13
- this.pattern = pattern;
14
- this.overlap = Math.max(0, pattern.length - 1);
15
- }
16
- /** Find the next match index starting at the current `searchFrom`. */
17
- find(target) {
18
- return target.indexOfPattern(this.pattern, this.searchFrom);
19
- }
20
- /** Update `searchFrom` after consuming `consumed` bytes from the front. */
21
- onConsume(consumed) {
22
- if (consumed > 0) {
23
- this.searchFrom = Math.max(0, this.searchFrom - consumed);
24
- }
25
- }
26
- /** Update `searchFrom` after a no-match scan on a buffer of length `bufferLength`. */
27
- onNoMatch(bufferLength) {
28
- this.searchFrom = Math.max(this.searchFrom, Math.max(0, bufferLength - this.overlap));
29
- }
30
- }
31
- exports.PatternScanner = PatternScanner;
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZipArchive = void 0;
4
- exports.zip = zip;
5
- const defaults_1 = require("../defaults.js");
6
- const stream_1 = require("./stream.js");
7
- const zip_bytes_1 = require("./zip-bytes.js");
8
- const archive_sink_1 = require("../io/archive-sink.js");
9
- const archive_source_1 = require("../io/archive-source.js");
10
- const async_queue_1 = require("../utils/async-queue.js");
11
- const REPRODUCIBLE_ZIP_MOD_TIME = new Date(1980, 0, 1, 0, 0, 0);
12
- class ZipArchive {
13
- constructor(options = {}) {
14
- this._entries = [];
15
- this._sealed = false;
16
- const reproducible = options.reproducible ?? false;
17
- this._options = {
18
- level: options.level ?? defaults_1.DEFAULT_ZIP_LEVEL,
19
- timestamps: options.timestamps ?? (reproducible ? "dos" : defaults_1.DEFAULT_ZIP_TIMESTAMPS),
20
- comment: options.comment,
21
- modTime: options.modTime ?? (reproducible ? REPRODUCIBLE_ZIP_MOD_TIME : new Date()),
22
- smartStore: options.smartStore ?? true
23
- };
24
- }
25
- add(name, source, options) {
26
- if (this._sealed) {
27
- throw new Error("Cannot add entries after output has started");
28
- }
29
- if (!name) {
30
- throw new Error("Entry name is required");
31
- }
32
- this._entries.push({ name, source, options });
33
- return this;
34
- }
35
- stream() {
36
- this._sealed = true;
37
- const queue = (0, async_queue_1.createAsyncQueue)();
38
- const zip = new stream_1.StreamingZip((err, data, final) => {
39
- if (err) {
40
- queue.fail(err);
41
- return;
42
- }
43
- if (data.length) {
44
- queue.push(data);
45
- }
46
- if (final) {
47
- queue.close();
48
- }
49
- }, { comment: this._options.comment });
50
- (async () => {
51
- try {
52
- for (const entry of this._entries) {
53
- const level = entry.options?.level ?? this._options.level;
54
- const file = new stream_1.ZipDeflateFile(entry.name, {
55
- level,
56
- modTime: entry.options?.modTime ?? this._options.modTime,
57
- timestamps: this._options.timestamps,
58
- comment: entry.options?.comment,
59
- smartStore: this._options.smartStore
60
- });
61
- zip.add(file);
62
- // Feed data
63
- if (entry.source instanceof Uint8Array ||
64
- entry.source instanceof ArrayBuffer ||
65
- typeof entry.source === "string" ||
66
- (typeof Blob !== "undefined" && entry.source instanceof Blob)) {
67
- const bytes = await (0, archive_source_1.toUint8Array)(entry.source);
68
- await file.push(bytes, true);
69
- }
70
- else {
71
- for await (const chunk of (0, archive_source_1.toAsyncIterable)(entry.source)) {
72
- await file.push(chunk, false);
73
- }
74
- await file.push(new Uint8Array(0), true);
75
- }
76
- await file.complete();
77
- }
78
- zip.end();
79
- }
80
- catch (e) {
81
- queue.fail(e instanceof Error ? e : new Error(String(e)));
82
- }
83
- })();
84
- return queue.iterable;
85
- }
86
- async bytes() {
87
- this._sealed = true;
88
- const allSourcesInMemory = this._entries.every(e => e.source instanceof Uint8Array ||
89
- e.source instanceof ArrayBuffer ||
90
- typeof e.source === "string" ||
91
- (typeof Blob !== "undefined" && e.source instanceof Blob));
92
- const hasBlobSource = this._entries.some(e => typeof Blob !== "undefined" && e.source instanceof Blob);
93
- // Fast-path: when all sources are already in memory and there are no
94
- // per-entry compression overrides, use the single-buffer ZIP builder.
95
- // This avoids the overhead of chunking + collecting from the streaming writer.
96
- if (allSourcesInMemory) {
97
- // Prefer the sync builder when possible (Node.js hot path): it avoids
98
- // async/Promise overhead and uses zlib sync fast paths.
99
- if (!hasBlobSource) {
100
- const entries = this._entries.map(e => ({
101
- name: e.name,
102
- data: (0, archive_source_1.toUint8ArraySync)(e.source),
103
- level: e.options?.level,
104
- modTime: e.options?.modTime,
105
- comment: e.options?.comment
106
- }));
107
- return (0, zip_bytes_1.createZipSync)(entries, {
108
- level: this._options.level,
109
- timestamps: this._options.timestamps,
110
- modTime: this._options.modTime,
111
- comment: this._options.comment,
112
- smartStore: this._options.smartStore
113
- });
114
- }
115
- const entries = await Promise.all(this._entries.map(async (e) => ({
116
- name: e.name,
117
- data: await (0, archive_source_1.toUint8Array)(e.source),
118
- level: e.options?.level,
119
- modTime: e.options?.modTime,
120
- comment: e.options?.comment
121
- })));
122
- return (0, zip_bytes_1.createZip)(entries, {
123
- level: this._options.level,
124
- timestamps: this._options.timestamps,
125
- modTime: this._options.modTime,
126
- comment: this._options.comment,
127
- smartStore: this._options.smartStore
128
- });
129
- }
130
- return (0, archive_sink_1.collect)(this.stream());
131
- }
132
- bytesSync() {
133
- this._sealed = true;
134
- const entries = this._entries.map(e => {
135
- if (!(e.source instanceof Uint8Array) &&
136
- !(e.source instanceof ArrayBuffer) &&
137
- typeof e.source !== "string") {
138
- throw new Error("bytesSync() only supports Uint8Array/ArrayBuffer/string sources");
139
- }
140
- return {
141
- name: e.name,
142
- data: (0, archive_source_1.toUint8ArraySync)(e.source),
143
- modTime: e.options?.modTime,
144
- comment: e.options?.comment
145
- };
146
- });
147
- return (0, zip_bytes_1.createZipSync)(entries, {
148
- level: this._options.level,
149
- timestamps: this._options.timestamps,
150
- modTime: this._options.modTime,
151
- comment: this._options.comment,
152
- smartStore: this._options.smartStore
153
- });
154
- }
155
- async pipeTo(sink) {
156
- await (0, archive_sink_1.pipeIterableToSink)(this.stream(), sink);
157
- }
158
- }
159
- exports.ZipArchive = ZipArchive;
160
- function zip(options) {
161
- return new ZipArchive(options);
162
- }
@@ -1,242 +0,0 @@
1
- "use strict";
2
- /**
3
- * ZIP file format encoder (single-buffer output)
4
- *
5
- * Implements ZIP file structure according to PKWARE's APPNOTE.TXT specification
6
- * https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
7
- *
8
- * This module focuses on producing a complete ZIP as a single Uint8Array.
9
- * For true streaming (push chunks while reading sources), use `zip()` / `ZipArchive.stream()`.
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createZip = createZip;
13
- exports.createZipSync = createZipSync;
14
- const compress_1 = require("../compression/compress.js");
15
- const crc32_1 = require("../compression/crc32.js");
16
- const defaults_1 = require("../defaults.js");
17
- const compressibility_1 = require("../utils/compressibility.js");
18
- const text_1 = require("../utils/text.js");
19
- const zip_entry_metadata_1 = require("./zip-entry-metadata.js");
20
- const zip_records_1 = require("../zip-spec/zip-records.js");
21
- const REPRODUCIBLE_ZIP_MOD_TIME = new Date(1980, 0, 1, 0, 0, 0);
22
- function encodeZipComment(comment) {
23
- // Keep empty comment as empty bytes (no encoding surprises).
24
- return comment ? (0, text_1.encodeUtf8)(comment) : new Uint8Array(0);
25
- }
26
- function shouldDeflate(level, data) {
27
- return level > 0 && data.length > 0;
28
- }
29
- async function compressEntryMaybe(entry, level, compressOptions, smartStore) {
30
- if (!shouldDeflate(level, entry.data)) {
31
- return { compressedData: entry.data, deflate: false };
32
- }
33
- if (!smartStore) {
34
- const compressed = await (0, compress_1.compress)(entry.data, compressOptions);
35
- return { compressedData: compressed, deflate: true };
36
- }
37
- // Heuristic: skip deflate for high-entropy inputs.
38
- if ((0, compressibility_1.isProbablyIncompressible)(entry.data)) {
39
- return { compressedData: entry.data, deflate: false };
40
- }
41
- const compressed = await (0, compress_1.compress)(entry.data, compressOptions);
42
- if (compressed.length >= entry.data.length) {
43
- return { compressedData: entry.data, deflate: false };
44
- }
45
- return { compressedData: compressed, deflate: true };
46
- }
47
- function compressEntryMaybeSync(entry, level, compressOptions, smartStore) {
48
- if (!shouldDeflate(level, entry.data)) {
49
- return { compressedData: entry.data, deflate: false };
50
- }
51
- if (!smartStore) {
52
- const compressed = (0, compress_1.compressSync)(entry.data, compressOptions);
53
- return { compressedData: compressed, deflate: true };
54
- }
55
- if ((0, compressibility_1.isProbablyIncompressible)(entry.data)) {
56
- return { compressedData: entry.data, deflate: false };
57
- }
58
- const compressed = (0, compress_1.compressSync)(entry.data, compressOptions);
59
- if (compressed.length >= entry.data.length) {
60
- return { compressedData: entry.data, deflate: false };
61
- }
62
- return { compressedData: compressed, deflate: true };
63
- }
64
- function computeLocalRecordSize(entry) {
65
- return (zip_records_1.ZIP_LOCAL_FILE_HEADER_FIXED_SIZE +
66
- entry.name.length +
67
- entry.extraField.length +
68
- entry.compressedData.length);
69
- }
70
- function computeCentralDirHeaderSize(entry) {
71
- return (zip_records_1.ZIP_CENTRAL_DIR_HEADER_FIXED_SIZE +
72
- entry.name.length +
73
- entry.extraField.length +
74
- entry.comment.length);
75
- }
76
- function buildProcessedEntry(entry, offset, settings, compressedData, deflate) {
77
- const modDate = entry.modTime ?? settings.defaultModTime;
78
- const metadata = (0, zip_entry_metadata_1.buildZipEntryMetadata)({
79
- name: entry.name,
80
- comment: entry.comment,
81
- modTime: modDate,
82
- timestamps: settings.timestamps,
83
- useDataDescriptor: false,
84
- deflate
85
- });
86
- return {
87
- name: metadata.nameBytes,
88
- uncompressedSize: entry.data.length,
89
- compressedData,
90
- crc: (0, crc32_1.crc32)(entry.data),
91
- compressionMethod: (0, zip_entry_metadata_1.resolveZipCompressionMethod)(deflate),
92
- modTime: metadata.dosTime,
93
- modDate: metadata.dosDate,
94
- extraField: metadata.extraField,
95
- comment: metadata.commentBytes,
96
- offset
97
- };
98
- }
99
- function appendProcessedEntry(processedEntries, entry, compressedData, deflate, currentOffset, settings) {
100
- const processedEntry = buildProcessedEntry(entry, currentOffset, settings, compressedData, deflate);
101
- processedEntries.push(processedEntry);
102
- return {
103
- processedEntry,
104
- nextOffset: currentOffset + computeLocalRecordSize(processedEntry)
105
- };
106
- }
107
- function finalizeZip(processedEntries, zipComment) {
108
- // Assemble ZIP into a single buffer to reduce allocations and copying.
109
- let localSectionSize = 0;
110
- let centralDirSize = 0;
111
- for (const entry of processedEntries) {
112
- localSectionSize += computeLocalRecordSize(entry);
113
- centralDirSize += computeCentralDirHeaderSize(entry);
114
- }
115
- // The central directory should start immediately after local section.
116
- const centralDirOffset = localSectionSize;
117
- const totalSize = localSectionSize + centralDirSize + zip_records_1.ZIP_END_OF_CENTRAL_DIR_FIXED_SIZE + zipComment.length;
118
- const out = new Uint8Array(totalSize);
119
- const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
120
- let offset = 0;
121
- // Local file headers and data
122
- for (const entry of processedEntries) {
123
- offset += (0, zip_records_1.writeLocalFileHeaderInto)(out, view, offset, {
124
- fileName: entry.name,
125
- extraField: entry.extraField,
126
- flags: zip_records_1.FLAG_UTF8,
127
- compressionMethod: entry.compressionMethod,
128
- dosTime: entry.modTime,
129
- dosDate: entry.modDate,
130
- crc32: entry.crc,
131
- compressedSize: entry.compressedData.length,
132
- uncompressedSize: entry.uncompressedSize
133
- });
134
- out.set(entry.compressedData, offset);
135
- offset += entry.compressedData.length;
136
- }
137
- // Central directory headers
138
- for (const entry of processedEntries) {
139
- offset += (0, zip_records_1.writeCentralDirectoryHeaderInto)(out, view, offset, {
140
- fileName: entry.name,
141
- extraField: entry.extraField,
142
- comment: entry.comment,
143
- flags: zip_records_1.FLAG_UTF8,
144
- compressionMethod: entry.compressionMethod,
145
- dosTime: entry.modTime,
146
- dosDate: entry.modDate,
147
- crc32: entry.crc,
148
- compressedSize: entry.compressedData.length,
149
- uncompressedSize: entry.uncompressedSize,
150
- localHeaderOffset: entry.offset
151
- });
152
- }
153
- // End of central directory
154
- (0, zip_records_1.writeEndOfCentralDirectoryInto)(out, view, offset, {
155
- entryCount: processedEntries.length,
156
- centralDirSize,
157
- centralDirOffset,
158
- comment: zipComment
159
- });
160
- return out;
161
- }
162
- /**
163
- * Create a ZIP file from entries (async)
164
- */
165
- async function createZip(entries, options = {}) {
166
- const reproducible = options.reproducible ?? false;
167
- const level = options.level ?? defaults_1.DEFAULT_ZIP_LEVEL;
168
- const smartStore = options.smartStore ?? true;
169
- const concurrency = options.concurrency ?? 4;
170
- const timestamps = options.timestamps ?? (reproducible ? "dos" : defaults_1.DEFAULT_ZIP_TIMESTAMPS);
171
- const zipComment = encodeZipComment(options.comment);
172
- const defaultModTime = options.modTime ?? (reproducible ? REPRODUCIBLE_ZIP_MOD_TIME : new Date());
173
- const settings = {
174
- level,
175
- timestamps,
176
- defaultModTime
177
- };
178
- const thresholdBytes = options.thresholdBytes;
179
- const limit = Math.max(1, Math.floor(concurrency));
180
- const processedEntries = new Array(entries.length);
181
- if (entries.length > 0) {
182
- let nextIndex = 0;
183
- const workerCount = Math.min(limit, entries.length);
184
- const workers = Array.from({ length: workerCount }, async () => {
185
- while (true) {
186
- const idx = nextIndex++;
187
- if (idx >= entries.length) {
188
- return;
189
- }
190
- const entry = entries[idx];
191
- const entryLevel = entry.level ?? level;
192
- const compressOptions = {
193
- level: entryLevel,
194
- thresholdBytes
195
- };
196
- const { compressedData, deflate } = await compressEntryMaybe(entry, entryLevel, compressOptions, smartStore);
197
- processedEntries[idx] = buildProcessedEntry(entry, 0, settings, compressedData, deflate);
198
- }
199
- });
200
- await Promise.all(workers);
201
- }
202
- // Compute offsets in original order.
203
- let currentOffset = 0;
204
- for (let i = 0; i < processedEntries.length; i++) {
205
- const processedEntry = processedEntries[i];
206
- processedEntry.offset = currentOffset;
207
- currentOffset += computeLocalRecordSize(processedEntry);
208
- }
209
- return finalizeZip(processedEntries, zipComment);
210
- }
211
- /**
212
- * Create a ZIP file from entries (sync)
213
- *
214
- * This is supported in both Node.js and browser builds.
215
- */
216
- function createZipSync(entries, options = {}) {
217
- const reproducible = options.reproducible ?? false;
218
- const level = options.level ?? defaults_1.DEFAULT_ZIP_LEVEL;
219
- const smartStore = options.smartStore ?? true;
220
- const timestamps = options.timestamps ?? (reproducible ? "dos" : defaults_1.DEFAULT_ZIP_TIMESTAMPS);
221
- const zipComment = encodeZipComment(options.comment);
222
- const defaultModTime = options.modTime ?? (reproducible ? REPRODUCIBLE_ZIP_MOD_TIME : new Date());
223
- const settings = {
224
- level,
225
- timestamps,
226
- defaultModTime
227
- };
228
- const thresholdBytes = options.thresholdBytes;
229
- const processedEntries = [];
230
- let currentOffset = 0;
231
- for (const entry of entries) {
232
- const entryLevel = entry.level ?? level;
233
- const compressOptions = {
234
- level: entryLevel,
235
- thresholdBytes
236
- };
237
- const { compressedData, deflate } = compressEntryMaybeSync(entry, entryLevel, compressOptions, smartStore);
238
- const result = appendProcessedEntry(processedEntries, entry, compressedData, deflate, currentOffset, settings);
239
- currentOffset = result.nextOffset;
240
- }
241
- return finalizeZip(processedEntries, zipComment);
242
- }