@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
@@ -62,34 +62,20 @@ class Writable extends stream_1.Writable {
62
62
  constructor(options) {
63
63
  // If wrapping an existing stream, proxy to it
64
64
  if (options?.stream) {
65
- const underlying = options.stream;
66
65
  // Create a pass-through wrapper that proxies to the underlying stream
67
66
  super({
68
67
  highWaterMark: options?.highWaterMark,
69
68
  objectMode: options?.objectMode,
70
69
  write(chunk, encoding, callback) {
71
- underlying.write(chunk, encoding, callback);
70
+ options.stream.write(chunk, encoding, callback);
72
71
  },
73
72
  final(callback) {
74
- underlying.end(callback);
73
+ options.stream.end(callback);
75
74
  }
76
75
  });
77
- // Proxy events from underlying stream, but ensure we clean up listeners so
78
- // the underlying stream cannot retain this wrapper longer than necessary.
79
- const onUnderlyingError = (err) => {
80
- this.emit("error", err);
81
- };
82
- const onUnderlyingClose = () => {
83
- this.emit("close");
84
- };
85
- const cleanup = () => {
86
- underlying.off("error", onUnderlyingError);
87
- underlying.off("close", onUnderlyingClose);
88
- };
89
- underlying.on("error", onUnderlyingError);
90
- underlying.on("close", onUnderlyingClose);
91
- this.once("close", cleanup);
92
- this.once("finish", cleanup);
76
+ // Proxy events from underlying stream
77
+ options.stream.on("error", err => this.emit("error", err));
78
+ options.stream.on("close", () => this.emit("close"));
93
79
  }
94
80
  else {
95
81
  super({
@@ -114,16 +100,17 @@ function normalizeWritable(stream) {
114
100
  if (stream instanceof Writable) {
115
101
  return stream;
116
102
  }
117
- // Node.js Writable: already compatible, avoid extra wrapper allocation.
103
+ // Node.js Writable: accept structurally even if typed as unknown.
118
104
  if (stream instanceof stream_1.Writable) {
119
- return stream;
105
+ return new Writable({ stream: stream });
120
106
  }
121
107
  // Web WritableStream: detect by getWriter() (avoid relying on global WritableStream).
122
108
  if (stream?.getWriter) {
123
- return stream_1.Writable.fromWeb(stream);
109
+ const nodeWritable = stream_1.Writable.fromWeb(stream);
110
+ return new Writable({ stream: nodeWritable });
124
111
  }
125
- // Assume it structurally matches Node's Writable.
126
- return stream;
112
+ // Assume it structurally matches Node's Writable; wrap for consistent API.
113
+ return new Writable({ stream: stream });
127
114
  }
128
115
  // Import for internal use
129
116
  const shared_1 = require("./shared.js");
@@ -236,13 +223,12 @@ function finished(stream, optionsOrCallback, callback) {
236
223
  const promise = new Promise((resolve, reject) => {
237
224
  const normalizedStream = toNodePipelineStream(stream);
238
225
  stream_1.finished(normalizedStream, options, (err) => {
239
- // Node.js semantics: options.error defaults to true (report errors).
240
- // If options.error === false, ignore errors and resolve.
241
- if (err && options?.error !== false) {
226
+ if (err && !(options && options.error)) {
242
227
  reject(err);
243
- return;
244
228
  }
245
- resolve();
229
+ else {
230
+ resolve();
231
+ }
246
232
  });
247
233
  });
248
234
  if (cb) {
@@ -595,28 +581,13 @@ function addAbortSignal(signal, stream) {
595
581
  stream.destroy(new Error("Aborted"));
596
582
  return stream;
597
583
  }
598
- const cleanup = () => {
599
- signal.removeEventListener("abort", onAbort);
600
- stream.off?.("close", onDone);
601
- stream.off?.("end", onDone);
602
- stream.off?.("finish", onDone);
603
- stream.off?.("error", onError);
604
- };
605
584
  const onAbort = () => {
606
- cleanup();
607
585
  stream.destroy(new Error("Aborted"));
608
586
  };
609
- const onDone = () => {
610
- cleanup();
611
- };
612
- const onError = () => {
613
- cleanup();
614
- };
615
587
  signal.addEventListener("abort", onAbort, { once: true });
616
- stream.once?.("close", onDone);
617
- stream.once?.("end", onDone);
618
- stream.once?.("finish", onDone);
619
- stream.once?.("error", onError);
588
+ stream.on("close", () => {
589
+ signal.removeEventListener("abort", onAbort);
590
+ });
620
591
  return stream;
621
592
  }
622
593
  /**
@@ -659,109 +630,56 @@ function compose(...transforms) {
659
630
  if (len === 1 && isNativeTransform(transforms[0])) {
660
631
  return transforms[0];
661
632
  }
662
- // Chain all transforms together once.
633
+ // Chain all transforms together
663
634
  for (let i = 0; i < len - 1; i++) {
664
635
  transforms[i].pipe(transforms[i + 1]);
665
636
  }
637
+ // Create a Duplex that writes to first and reads from last
666
638
  const first = transforms[0];
667
639
  const last = transforms[len - 1];
668
- // Use a private output stream so we don't have to monkey-patch `write()` on the
669
- // public composed stream (which would break piping into it).
670
- const output = new stream_1.PassThrough({ objectMode: last.readableObjectMode ?? true });
671
- last.pipe(output);
672
- let outputEnded = false;
673
- const pumpOutput = (target) => {
674
- if (outputEnded) {
675
- return;
676
- }
677
- while (true) {
678
- const chunk = output.read();
679
- if (chunk === null) {
680
- break;
681
- }
682
- if (!target.push(chunk)) {
683
- break;
684
- }
640
+ // Create a PassThrough as the composed stream
641
+ const composed = new stream_1.PassThrough({ objectMode: first.readableObjectMode });
642
+ // Store original methods for forwarding
643
+ const passthroughWrite = composed.write.bind(composed);
644
+ const passthroughEnd = composed.end.bind(composed);
645
+ // Override write to write to first transform
646
+ composed.write = function (chunk, encodingOrCallback, callback) {
647
+ if (typeof encodingOrCallback === "function") {
648
+ return first.write(chunk, encodingOrCallback);
685
649
  }
650
+ return first.write(chunk, encodingOrCallback, callback);
686
651
  };
687
- const composed = new stream_1.Transform({
688
- readableObjectMode: last.readableObjectMode,
689
- writableObjectMode: first.writableObjectMode,
690
- transform(chunk, encoding, callback) {
691
- try {
692
- // Forward writes into the head of the chain.
693
- first.write(chunk, encoding, callback);
694
- }
695
- catch (err) {
696
- callback(err);
697
- }
698
- },
699
- flush(callback) {
700
- // End the head of the chain; readable completion is driven by `output` ending.
701
- const onFinish = () => {
702
- cleanupFlush();
703
- callback();
704
- };
705
- const onError = (err) => {
706
- cleanupFlush();
707
- callback(err);
708
- };
709
- const cleanupFlush = () => {
710
- first.off?.("finish", onFinish);
711
- first.off?.("error", onError);
712
- };
713
- first.once?.("finish", onFinish);
714
- first.once?.("error", onError);
715
- first.end();
716
- },
717
- read() {
718
- pumpOutput(this);
719
- },
720
- destroy(err, callback) {
721
- try {
722
- output.destroy(err ?? undefined);
723
- for (const t of transforms) {
724
- t.destroy?.(err ?? undefined);
725
- }
726
- }
727
- finally {
728
- callback(err);
729
- }
652
+ // Override end to end first transform
653
+ composed.end = function (chunkOrCallback, encodingOrCallback, callback) {
654
+ if (typeof chunkOrCallback === "function") {
655
+ first.end(chunkOrCallback);
730
656
  }
731
- });
732
- const onOutputReadable = () => {
733
- pumpOutput(composed);
734
- };
735
- const onOutputEnd = () => {
736
- cleanupListeners();
737
- outputEnded = true;
738
- composed.push(null);
739
- };
740
- const onAnyError = (err) => {
741
- cleanupListeners();
742
- composed.destroy(err);
743
- };
744
- const transformErrorListeners = [];
745
- const cleanupListeners = () => {
746
- output.off("readable", onOutputReadable);
747
- output.off("end", onOutputEnd);
748
- output.off("error", onAnyError);
749
- for (const { t, fn } of transformErrorListeners) {
750
- t.off?.("error", fn);
657
+ else if (typeof encodingOrCallback === "function") {
658
+ first.end(chunkOrCallback, encodingOrCallback);
659
+ }
660
+ else {
661
+ first.end(chunkOrCallback, encodingOrCallback, callback);
751
662
  }
752
- transformErrorListeners.length = 0;
663
+ return composed;
753
664
  };
754
- output.on("readable", onOutputReadable);
755
- output.once("end", onOutputEnd);
756
- output.once("error", onAnyError);
757
- for (const t of transforms) {
758
- const tt = t;
759
- tt.once?.("error", onAnyError);
760
- transformErrorListeners.push({ t: tt, fn: onAnyError });
761
- }
762
- composed.once("close", () => {
763
- cleanupListeners();
665
+ // Override pipe to pipe from last transform
666
+ composed.pipe = function (dest) {
667
+ return last.pipe(dest);
668
+ };
669
+ // Forward data from last to composed
670
+ last.on("data", (chunk) => {
671
+ passthroughWrite(chunk);
672
+ });
673
+ // Forward end from last
674
+ last.on("end", () => {
675
+ passthroughEnd();
764
676
  });
677
+ // Forward errors from any transform
678
+ for (const transform of transforms) {
679
+ transform.on("error", (err) => {
680
+ composed.emit("error", err);
681
+ });
682
+ }
765
683
  return composed;
766
684
  }
767
685
  /**
@@ -842,7 +760,7 @@ function once(emitter, event, options) {
842
760
  onAbort();
843
761
  return;
844
762
  }
845
- options.signal.addEventListener("abort", onAbort, { once: true });
763
+ options.signal.addEventListener("abort", onAbort);
846
764
  }
847
765
  });
848
766
  }
@@ -39,15 +39,3 @@ export { CsvParserStream, CsvFormatterStream } from "./modules/csv/csv.browser.j
39
39
  // Utilities
40
40
  // =============================================================================
41
41
  export * from "./modules/excel/utils/sheet-utils.js";
42
- // =============================================================================
43
- // Archive (ZIP) support (Browser-compatible)
44
- // =============================================================================
45
- export {
46
- // High-level archive API
47
- zip, unzip, ZipArchive, ZipReader, UnzipEntry,
48
- // CRC32
49
- crc32, crc32Update, crc32Finalize,
50
- // Compression utilities
51
- compress, compressSync, decompress, decompressSync, hasCompressionStream,
52
- // Streaming compression
53
- createDeflateStream, createInflateStream, hasDeflateRaw } from "./modules/archive/index.browser.js";
@@ -0,0 +1,125 @@
1
+ export class ByteQueue {
2
+ constructor(initial) {
3
+ this._start = 0;
4
+ this._end = 0;
5
+ this._cachedView = null;
6
+ this._cachedBuf = null;
7
+ this._cachedStart = 0;
8
+ this._cachedEnd = 0;
9
+ this._buf = new Uint8Array(0);
10
+ if (initial && initial.length > 0) {
11
+ this.reset(initial);
12
+ }
13
+ }
14
+ get length() {
15
+ return this._end - this._start;
16
+ }
17
+ isEmpty() {
18
+ return this.length === 0;
19
+ }
20
+ view() {
21
+ if (this._start === this._end) {
22
+ return ByteQueue.EMPTY;
23
+ }
24
+ if (this._cachedView &&
25
+ this._cachedBuf === this._buf &&
26
+ this._cachedStart === this._start &&
27
+ this._cachedEnd === this._end) {
28
+ return this._cachedView;
29
+ }
30
+ const view = this._buf.subarray(this._start, this._end);
31
+ this._cachedView = view;
32
+ this._cachedBuf = this._buf;
33
+ this._cachedStart = this._start;
34
+ this._cachedEnd = this._end;
35
+ return view;
36
+ }
37
+ reset(data) {
38
+ this._cachedView = null;
39
+ this._cachedBuf = null;
40
+ if (!data || data.length === 0) {
41
+ this._buf = ByteQueue.EMPTY;
42
+ this._start = 0;
43
+ this._end = 0;
44
+ return;
45
+ }
46
+ // Keep a private copy to ensure future writes cannot mutate the source.
47
+ const copy = new Uint8Array(data.length);
48
+ copy.set(data);
49
+ this._buf = copy;
50
+ this._start = 0;
51
+ this._end = copy.length;
52
+ }
53
+ append(chunk) {
54
+ if (chunk.length === 0) {
55
+ return;
56
+ }
57
+ this._cachedView = null;
58
+ this._cachedBuf = null;
59
+ const unread = this.length;
60
+ // Fast path: enough tail room.
61
+ if (this._end + chunk.length <= this._buf.length) {
62
+ this._buf.set(chunk, this._end);
63
+ this._end += chunk.length;
64
+ return;
65
+ }
66
+ // Allocate a new buffer and copy unread bytes (never compacts in-place).
67
+ const required = unread + chunk.length;
68
+ const nextSize = this._buf.length === 0 ? required : Math.max(this._buf.length * 2, required);
69
+ const next = new Uint8Array(nextSize);
70
+ if (unread > 0) {
71
+ next.set(this._buf.subarray(this._start, this._end), 0);
72
+ }
73
+ next.set(chunk, unread);
74
+ this._buf = next;
75
+ this._start = 0;
76
+ this._end = required;
77
+ }
78
+ read(length) {
79
+ if (length <= 0) {
80
+ return new Uint8Array(0);
81
+ }
82
+ if (length > this.length) {
83
+ throw new RangeError("ByteQueue: read beyond available data");
84
+ }
85
+ // Return a view for performance.
86
+ // To keep this safe for async consumers, we must ensure we never write into
87
+ // the same backing buffer again after it becomes fully consumed.
88
+ const out = this._buf.subarray(this._start, this._start + length);
89
+ this._start += length;
90
+ this._cachedView = null;
91
+ this._cachedBuf = null;
92
+ if (this._start === this._end) {
93
+ // Release backing storage to avoid reusing memory that might still be
94
+ // referenced by previously returned views.
95
+ this._buf = ByteQueue.EMPTY;
96
+ this._start = 0;
97
+ this._end = 0;
98
+ }
99
+ return out;
100
+ }
101
+ discard(length) {
102
+ if (length <= 0) {
103
+ return;
104
+ }
105
+ if (length >= this.length) {
106
+ // Release backing storage for the same reason as read(): previously
107
+ // returned views may still be referenced by consumers.
108
+ this._buf = ByteQueue.EMPTY;
109
+ this._start = 0;
110
+ this._end = 0;
111
+ this._cachedView = null;
112
+ this._cachedBuf = null;
113
+ return;
114
+ }
115
+ this._start += length;
116
+ this._cachedView = null;
117
+ this._cachedBuf = null;
118
+ if (this._start === this._end) {
119
+ this._buf = ByteQueue.EMPTY;
120
+ this._start = 0;
121
+ this._end = 0;
122
+ }
123
+ }
124
+ }
125
+ ByteQueue.EMPTY = new Uint8Array(0);
@@ -8,7 +8,7 @@
8
8
  * Browser fallback: For browsers without deflate-raw support (Firefox < 113, Safari < 16.4),
9
9
  * see deflate-fallback.ts for pure JS implementation
10
10
  */
11
- import { ByteQueue } from "../internal/byte-queue.js";
11
+ import { ByteQueue } from "./byte-queue.js";
12
12
  /**
13
13
  * Default threshold (in bytes) to choose the lower-overhead path.
14
14
  *
@@ -10,12 +10,20 @@
10
10
  * - Safari >= 14.1
11
11
  * - Edge >= 89
12
12
  */
13
- import { compressWithStream, decompressWithStream, hasCompressionStream, hasDeflateRawCompressionStream, hasDeflateRawDecompressionStream } from "./compress.base.js";
13
+ import { compressWithStream, decompressWithStream, hasDeflateRawCompressionStream, hasDeflateRawDecompressionStream } from "./compress.base.js";
14
14
  import { inflateRaw, deflateRawCompressed } from "./deflate-fallback.js";
15
- import { DEFAULT_COMPRESS_LEVEL } from "../defaults.js";
15
+ import { DEFAULT_COMPRESS_LEVEL } from "./defaults.js";
16
16
  // Re-export shared types
17
17
  export {};
18
- export { hasCompressionStream };
18
+ /**
19
+ * Check if CompressionStream is available in this environment.
20
+ *
21
+ * Note: Some environments may expose CompressionStream but not support
22
+ * the "deflate-raw" format that ZIP requires.
23
+ */
24
+ export function hasCompressionStream() {
25
+ return typeof CompressionStream !== "undefined";
26
+ }
19
27
  /**
20
28
  * Compress data using browser's native CompressionStream or JS fallback
21
29
  *
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { promisify } from "util";
8
8
  import * as zlib from "zlib";
9
- import { DEFAULT_COMPRESS_LEVEL } from "../defaults.js";
9
+ import { DEFAULT_COMPRESS_LEVEL } from "./defaults.js";
10
10
  // Re-export shared types and utilities
11
11
  export { hasCompressionStream } from "./compress.base.js";
12
12
  function uint8ArrayToBufferView(data) {
@@ -8,7 +8,7 @@
8
8
  * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
9
9
  * Represented as 0xEDB88320 in reversed (LSB-first) form
10
10
  */
11
- import { isNode } from "../../../utils/env.js";
11
+ import { isNode } from "../../utils/env.js";
12
12
  import { crc32JS, crc32UpdateJS, crc32Finalize } from "./crc32.base.js";
13
13
  // Lazy-loaded zlib module for Node.js
14
14
  let _zlib = null;
@@ -1,6 +1,3 @@
1
- export const DEFAULT_DEFLATE_LEVEL = 6;
2
- // Backward-compatible aliases (avoid default drift across modules).
3
- export const DEFAULT_COMPRESS_LEVEL = DEFAULT_DEFLATE_LEVEL;
4
- export const DEFAULT_ZIP_LEVEL = DEFAULT_DEFLATE_LEVEL;
5
- // Prefer reproducible output by default: omit the Info-ZIP UTC mtime extra field.
6
- export const DEFAULT_ZIP_TIMESTAMPS = "dos";
1
+ export const DEFAULT_COMPRESS_LEVEL = 6;
2
+ export const DEFAULT_ZIP_LEVEL = 6;
3
+ export const DEFAULT_ZIP_TIMESTAMPS = "dos+utc";
@@ -10,7 +10,7 @@
10
10
  * - Safari < 16.4
11
11
  * - Chrome < 103
12
12
  */
13
- import { concatUint8Arrays } from "../utils/bytes.js";
13
+ import { concatUint8Arrays } from "./utils/bytes.js";
14
14
  // ============================================================================
15
15
  // DEFLATE Decompression (Full implementation)
16
16
  // ============================================================================
@@ -5,6 +5,9 @@
5
5
  * Platform-specific entrypoints (index.ts / index.browser.ts) should re-export
6
6
  * from this file and then layer their platform-specific bindings.
7
7
  */
8
- // High-level APIs
9
- export { zip, ZipArchive } from "./zip/index.js";
10
- export { unzip, ZipReader, UnzipEntry } from "./unzip/index.js";
8
+ // ZIP builders
9
+ export { createZip, createZipSync, ZipBuilder } from "./zip-builder.js";
10
+ // Streaming ZIP (fflate-like API)
11
+ export { StreamingZip, ZipDeflateFile, Zip, ZipDeflate } from "./streaming-zip.js";
12
+ // Buffer-based unzip API (cross-platform)
13
+ export { extractAll, extractFile, listFiles, forEachEntry, ZipParser } from "./extract.js";
@@ -6,8 +6,12 @@
6
6
  */
7
7
  export * from "./index.base.js";
8
8
  // CRC32
9
- export { crc32, crc32Update, crc32Finalize } from "./compression/crc32.browser.js";
9
+ export { crc32, crc32Update, crc32Finalize } from "./crc32.browser.js";
10
10
  // Compression
11
- export { compress, compressSync, decompress, decompressSync, hasCompressionStream } from "./compression/compress.browser.js";
11
+ export { compress, compressSync, decompress, decompressSync, hasCompressionStream } from "./compress.browser.js";
12
12
  // Streaming compression
13
- export { createDeflateStream, createInflateStream, hasDeflateRaw } from "./compression/streaming-compress.browser.js";
13
+ export { createDeflateStream, createInflateStream, hasDeflateRaw } from "./streaming-compress.browser.js";
14
+ // Stream-based unzip API (browser implementation)
15
+ export { Parse, createParse } from "./parse.browser.js";
16
+ // Buffer-based unzip API (cross-platform)
17
+ // (re-exported from ./index.base)
@@ -6,8 +6,10 @@
6
6
  */
7
7
  export * from "./index.base.js";
8
8
  // CRC32
9
- export { crc32, crc32Update, crc32Finalize } from "./compression/crc32.js";
9
+ export { crc32, crc32Update, crc32Finalize } from "./crc32.js";
10
10
  // Compression
11
- export { compress, compressSync, decompress, decompressSync, hasCompressionStream } from "./compression/compress.js";
11
+ export { compress, compressSync, decompress, decompressSync, hasCompressionStream } from "./compress.js";
12
12
  // Streaming compression
13
- export { createDeflateStream, createInflateStream, hasDeflateRaw } from "./compression/streaming-compress.js";
13
+ export { createDeflateStream, createInflateStream, hasDeflateRaw } from "./streaming-compress.js";
14
+ // Stream-based unzip API (Node.js; browser build aliases to ./parse.browser.ts)
15
+ export { Parse, createParse } from "./parse.js";