@cj-tech-master/excelts 4.2.0 → 4.2.1-canary.20260111102127.f808a37

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 (241) hide show
  1. package/THIRD_PARTY_NOTICES.md +0 -31
  2. package/dist/browser/index.browser.d.ts +1 -0
  3. package/dist/browser/index.browser.js +12 -0
  4. package/dist/{types/modules/archive → browser/modules/archive/compression}/compress.base.d.ts +1 -0
  5. package/dist/browser/modules/archive/{compress.base.js → compression/compress.base.js} +2 -1
  6. package/dist/{types/modules/archive → browser/modules/archive/compression}/compress.browser.d.ts +10 -8
  7. package/dist/{esm/modules/archive → browser/modules/archive/compression}/compress.browser.js +18 -19
  8. package/dist/browser/modules/archive/{compress.d.ts → compression/compress.d.ts} +2 -2
  9. package/dist/browser/modules/archive/{compress.js → compression/compress.js} +1 -1
  10. package/dist/browser/modules/archive/{crc32.browser.d.ts → compression/crc32.browser.d.ts} +1 -1
  11. package/dist/browser/modules/archive/{crc32.d.ts → compression/crc32.d.ts} +1 -1
  12. package/dist/browser/modules/archive/{crc32.js → compression/crc32.js} +1 -1
  13. package/dist/browser/modules/archive/{deflate-fallback.js → compression/deflate-fallback.js} +1 -1
  14. package/dist/browser/modules/archive/{streaming-compress.browser.d.ts → compression/streaming-compress.browser.d.ts} +2 -2
  15. package/dist/browser/modules/archive/{streaming-compress.browser.js → compression/streaming-compress.browser.js} +3 -3
  16. package/dist/browser/modules/archive/{streaming-compress.d.ts → compression/streaming-compress.d.ts} +2 -2
  17. package/dist/browser/modules/archive/{streaming-compress.js → compression/streaming-compress.js} +2 -2
  18. package/dist/browser/modules/archive/defaults.d.ts +1 -0
  19. package/dist/browser/modules/archive/defaults.js +6 -3
  20. package/dist/browser/modules/archive/index.base.d.ts +4 -4
  21. package/dist/browser/modules/archive/index.base.js +3 -6
  22. package/dist/browser/modules/archive/index.browser.d.ts +3 -4
  23. package/dist/browser/modules/archive/index.browser.js +3 -7
  24. package/dist/browser/modules/archive/index.d.ts +3 -4
  25. package/dist/browser/modules/archive/index.js +3 -5
  26. package/dist/browser/modules/archive/internal/byte-queue.d.ts +33 -0
  27. package/dist/browser/modules/archive/internal/byte-queue.js +407 -0
  28. package/dist/browser/modules/archive/io/archive-sink.d.ts +9 -0
  29. package/dist/browser/modules/archive/io/archive-sink.js +77 -0
  30. package/dist/browser/modules/archive/io/archive-source.d.ts +8 -0
  31. package/dist/browser/modules/archive/io/archive-source.js +107 -0
  32. package/dist/browser/modules/archive/{extract.d.ts → unzip/extract.d.ts} +2 -2
  33. package/dist/browser/modules/archive/unzip/index.d.ts +40 -0
  34. package/dist/browser/modules/archive/unzip/index.js +164 -0
  35. package/dist/browser/modules/archive/{parse.base.d.ts → unzip/stream.base.d.ts} +58 -3
  36. package/dist/browser/modules/archive/unzip/stream.base.js +1022 -0
  37. package/dist/browser/modules/archive/{parse.browser.d.ts → unzip/stream.browser.d.ts} +1 -1
  38. package/dist/browser/modules/archive/{parse.browser.js → unzip/stream.browser.js} +376 -110
  39. package/dist/browser/modules/archive/{parse.d.ts → unzip/stream.d.ts} +2 -2
  40. package/dist/{esm/modules/archive/parse.js → browser/modules/archive/unzip/stream.js} +7 -6
  41. package/dist/{types/modules/archive → browser/modules/archive/unzip}/zip-parser.d.ts +1 -1
  42. package/dist/{esm/modules/archive → browser/modules/archive/unzip}/zip-parser.js +38 -24
  43. package/dist/browser/modules/archive/utils/async-queue.d.ts +7 -0
  44. package/dist/browser/modules/archive/utils/async-queue.js +103 -0
  45. package/dist/browser/modules/archive/utils/bytes.js +16 -16
  46. package/dist/browser/modules/archive/utils/compressibility.d.ts +10 -0
  47. package/dist/browser/modules/archive/utils/compressibility.js +57 -0
  48. package/dist/browser/modules/archive/utils/parse-buffer.js +21 -23
  49. package/dist/browser/modules/archive/utils/pattern-scanner.d.ts +21 -0
  50. package/dist/browser/modules/archive/utils/pattern-scanner.js +27 -0
  51. package/dist/browser/modules/archive/utils/timestamps.js +62 -1
  52. package/dist/browser/modules/archive/utils/zip-extra-fields.d.ts +1 -1
  53. package/dist/browser/modules/archive/utils/zip-extra-fields.js +26 -14
  54. package/dist/browser/modules/archive/zip/index.d.ts +42 -0
  55. package/dist/browser/modules/archive/zip/index.js +157 -0
  56. package/dist/browser/modules/archive/{streaming-zip.d.ts → zip/stream.d.ts} +28 -5
  57. package/dist/browser/modules/archive/{streaming-zip.js → zip/stream.js} +192 -48
  58. package/dist/browser/modules/archive/zip/zip-bytes.d.ts +73 -0
  59. package/dist/browser/modules/archive/zip/zip-bytes.js +239 -0
  60. package/dist/{esm/modules/archive → browser/modules/archive/zip}/zip-entry-metadata.js +3 -3
  61. package/dist/browser/modules/archive/{zip-records.d.ts → zip-spec/zip-records.d.ts} +20 -0
  62. package/dist/browser/modules/archive/zip-spec/zip-records.js +126 -0
  63. package/dist/browser/modules/excel/form-control.d.ts +2 -0
  64. package/dist/browser/modules/excel/form-control.js +54 -16
  65. package/dist/browser/modules/excel/stream/workbook-reader.browser.js +1 -1
  66. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
  67. package/dist/browser/modules/excel/stream/workbook-writer.browser.js +1 -1
  68. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +17 -3
  69. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +3 -6
  70. package/dist/browser/modules/excel/xlsx/xlsx.js +1 -1
  71. package/dist/browser/modules/stream/streams.browser.d.ts +28 -28
  72. package/dist/browser/modules/stream/streams.browser.js +850 -697
  73. package/dist/browser/modules/stream/streams.js +140 -58
  74. package/dist/cjs/modules/archive/{compress.base.js → compression/compress.base.js} +2 -1
  75. package/dist/cjs/modules/archive/{compress.browser.js → compression/compress.browser.js} +18 -19
  76. package/dist/cjs/modules/archive/{compress.js → compression/compress.js} +1 -1
  77. package/dist/cjs/modules/archive/{crc32.js → compression/crc32.js} +1 -1
  78. package/dist/cjs/modules/archive/{deflate-fallback.js → compression/deflate-fallback.js} +1 -1
  79. package/dist/cjs/modules/archive/{streaming-compress.browser.js → compression/streaming-compress.browser.js} +3 -3
  80. package/dist/cjs/modules/archive/{streaming-compress.js → compression/streaming-compress.js} +2 -2
  81. package/dist/cjs/modules/archive/defaults.js +7 -4
  82. package/dist/cjs/modules/archive/index.base.js +9 -19
  83. package/dist/cjs/modules/archive/index.browser.js +4 -10
  84. package/dist/cjs/modules/archive/index.js +4 -8
  85. package/dist/cjs/modules/archive/internal/byte-queue.js +411 -0
  86. package/dist/cjs/modules/archive/io/archive-sink.js +82 -0
  87. package/dist/cjs/modules/archive/io/archive-source.js +114 -0
  88. package/dist/cjs/modules/archive/unzip/index.js +170 -0
  89. package/dist/cjs/modules/archive/unzip/stream.base.js +1044 -0
  90. package/dist/cjs/modules/archive/{parse.browser.js → unzip/stream.browser.js} +377 -111
  91. package/dist/cjs/modules/archive/{parse.js → unzip/stream.js} +9 -8
  92. package/dist/cjs/modules/archive/{zip-parser.js → unzip/zip-parser.js} +47 -33
  93. package/dist/cjs/modules/archive/utils/async-queue.js +106 -0
  94. package/dist/cjs/modules/archive/utils/bytes.js +16 -16
  95. package/dist/cjs/modules/archive/utils/compressibility.js +60 -0
  96. package/dist/cjs/modules/archive/utils/parse-buffer.js +21 -23
  97. package/dist/cjs/modules/archive/utils/pattern-scanner.js +31 -0
  98. package/dist/cjs/modules/archive/utils/timestamps.js +64 -3
  99. package/dist/cjs/modules/archive/utils/zip-extra-fields.js +26 -14
  100. package/dist/cjs/modules/archive/zip/index.js +162 -0
  101. package/dist/cjs/modules/archive/{streaming-zip.js → zip/stream.js} +194 -50
  102. package/dist/cjs/modules/archive/zip/zip-bytes.js +242 -0
  103. package/dist/cjs/modules/archive/{zip-entry-metadata.js → zip/zip-entry-metadata.js} +5 -5
  104. package/dist/cjs/modules/archive/zip-spec/zip-records.js +136 -0
  105. package/dist/cjs/modules/excel/form-control.js +54 -16
  106. package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +2 -2
  107. package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +4 -4
  108. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +17 -3
  109. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +6 -9
  110. package/dist/cjs/modules/excel/xlsx/xlsx.js +2 -2
  111. package/dist/cjs/modules/stream/streams.browser.js +850 -697
  112. package/dist/cjs/modules/stream/streams.js +140 -58
  113. package/dist/esm/index.browser.js +12 -0
  114. package/dist/esm/modules/archive/{compress.base.js → compression/compress.base.js} +2 -1
  115. package/dist/{browser/modules/archive → esm/modules/archive/compression}/compress.browser.js +18 -19
  116. package/dist/esm/modules/archive/{compress.js → compression/compress.js} +1 -1
  117. package/dist/esm/modules/archive/{crc32.js → compression/crc32.js} +1 -1
  118. package/dist/esm/modules/archive/{deflate-fallback.js → compression/deflate-fallback.js} +1 -1
  119. package/dist/esm/modules/archive/{streaming-compress.browser.js → compression/streaming-compress.browser.js} +3 -3
  120. package/dist/esm/modules/archive/{streaming-compress.js → compression/streaming-compress.js} +2 -2
  121. package/dist/esm/modules/archive/defaults.js +6 -3
  122. package/dist/esm/modules/archive/index.base.js +3 -6
  123. package/dist/esm/modules/archive/index.browser.js +3 -7
  124. package/dist/esm/modules/archive/index.js +3 -5
  125. package/dist/esm/modules/archive/internal/byte-queue.js +407 -0
  126. package/dist/esm/modules/archive/io/archive-sink.js +77 -0
  127. package/dist/esm/modules/archive/io/archive-source.js +107 -0
  128. package/dist/esm/modules/archive/unzip/index.js +164 -0
  129. package/dist/esm/modules/archive/unzip/stream.base.js +1022 -0
  130. package/dist/esm/modules/archive/{parse.browser.js → unzip/stream.browser.js} +376 -110
  131. package/dist/{browser/modules/archive/parse.js → esm/modules/archive/unzip/stream.js} +7 -6
  132. package/dist/{browser/modules/archive → esm/modules/archive/unzip}/zip-parser.js +38 -24
  133. package/dist/esm/modules/archive/utils/async-queue.js +103 -0
  134. package/dist/esm/modules/archive/utils/bytes.js +16 -16
  135. package/dist/esm/modules/archive/utils/compressibility.js +57 -0
  136. package/dist/esm/modules/archive/utils/parse-buffer.js +21 -23
  137. package/dist/esm/modules/archive/utils/pattern-scanner.js +27 -0
  138. package/dist/esm/modules/archive/utils/timestamps.js +62 -1
  139. package/dist/esm/modules/archive/utils/zip-extra-fields.js +26 -14
  140. package/dist/esm/modules/archive/zip/index.js +157 -0
  141. package/dist/esm/modules/archive/{streaming-zip.js → zip/stream.js} +192 -48
  142. package/dist/esm/modules/archive/zip/zip-bytes.js +239 -0
  143. package/dist/{browser/modules/archive → esm/modules/archive/zip}/zip-entry-metadata.js +3 -3
  144. package/dist/esm/modules/archive/zip-spec/zip-records.js +126 -0
  145. package/dist/esm/modules/excel/form-control.js +54 -16
  146. package/dist/esm/modules/excel/stream/workbook-reader.browser.js +1 -1
  147. package/dist/esm/modules/excel/stream/workbook-writer.browser.js +1 -1
  148. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +17 -3
  149. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +3 -6
  150. package/dist/esm/modules/excel/xlsx/xlsx.js +1 -1
  151. package/dist/esm/modules/stream/streams.browser.js +850 -697
  152. package/dist/esm/modules/stream/streams.js +140 -58
  153. package/dist/iife/THIRD_PARTY_NOTICES.md +81 -0
  154. package/dist/iife/excelts.iife.js +4777 -2863
  155. package/dist/iife/excelts.iife.js.map +1 -1
  156. package/dist/iife/excelts.iife.min.js +103 -31
  157. package/dist/types/index.browser.d.ts +1 -0
  158. package/dist/{browser/modules/archive → types/modules/archive/compression}/compress.base.d.ts +1 -0
  159. package/dist/{browser/modules/archive → types/modules/archive/compression}/compress.browser.d.ts +10 -8
  160. package/dist/types/modules/archive/{streaming-compress.browser.d.ts → compression/streaming-compress.browser.d.ts} +1 -1
  161. package/dist/types/modules/archive/defaults.d.ts +1 -0
  162. package/dist/types/modules/archive/index.base.d.ts +4 -4
  163. package/dist/types/modules/archive/index.browser.d.ts +3 -4
  164. package/dist/types/modules/archive/index.d.ts +3 -4
  165. package/dist/types/modules/archive/internal/byte-queue.d.ts +33 -0
  166. package/dist/types/modules/archive/io/archive-sink.d.ts +9 -0
  167. package/dist/types/modules/archive/io/archive-source.d.ts +8 -0
  168. package/dist/types/modules/archive/unzip/index.d.ts +40 -0
  169. package/dist/types/modules/archive/{parse.base.d.ts → unzip/stream.base.d.ts} +60 -5
  170. package/dist/types/modules/archive/{parse.browser.d.ts → unzip/stream.browser.d.ts} +2 -2
  171. package/dist/types/modules/archive/{parse.d.ts → unzip/stream.d.ts} +3 -3
  172. package/dist/{browser/modules/archive → types/modules/archive/unzip}/zip-parser.d.ts +1 -1
  173. package/dist/types/modules/archive/utils/async-queue.d.ts +7 -0
  174. package/dist/types/modules/archive/utils/compressibility.d.ts +10 -0
  175. package/dist/types/modules/archive/utils/pattern-scanner.d.ts +21 -0
  176. package/dist/types/modules/archive/utils/zip-extra-fields.d.ts +1 -1
  177. package/dist/types/modules/archive/zip/index.d.ts +42 -0
  178. package/dist/types/modules/archive/{streaming-zip.d.ts → zip/stream.d.ts} +29 -6
  179. package/dist/types/modules/archive/zip/zip-bytes.d.ts +73 -0
  180. package/dist/types/modules/archive/{zip-entry-metadata.d.ts → zip/zip-entry-metadata.d.ts} +1 -1
  181. package/dist/types/modules/archive/{zip-records.d.ts → zip-spec/zip-records.d.ts} +20 -0
  182. package/dist/types/modules/excel/form-control.d.ts +2 -0
  183. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
  184. package/dist/types/modules/stream/streams.browser.d.ts +28 -28
  185. package/package.json +10 -6
  186. package/dist/browser/modules/archive/byte-queue.d.ts +0 -18
  187. package/dist/browser/modules/archive/byte-queue.js +0 -125
  188. package/dist/browser/modules/archive/parse.base.js +0 -610
  189. package/dist/browser/modules/archive/utils/zip-extra.d.ts +0 -18
  190. package/dist/browser/modules/archive/utils/zip-extra.js +0 -68
  191. package/dist/browser/modules/archive/zip-builder.d.ts +0 -117
  192. package/dist/browser/modules/archive/zip-builder.js +0 -292
  193. package/dist/browser/modules/archive/zip-constants.d.ts +0 -18
  194. package/dist/browser/modules/archive/zip-constants.js +0 -23
  195. package/dist/browser/modules/archive/zip-records.js +0 -84
  196. package/dist/cjs/modules/archive/byte-queue.js +0 -129
  197. package/dist/cjs/modules/archive/parse.base.js +0 -632
  198. package/dist/cjs/modules/archive/utils/zip-extra.js +0 -74
  199. package/dist/cjs/modules/archive/zip-builder.js +0 -297
  200. package/dist/cjs/modules/archive/zip-constants.js +0 -26
  201. package/dist/cjs/modules/archive/zip-records.js +0 -90
  202. package/dist/esm/modules/archive/byte-queue.js +0 -125
  203. package/dist/esm/modules/archive/parse.base.js +0 -610
  204. package/dist/esm/modules/archive/utils/zip-extra.js +0 -68
  205. package/dist/esm/modules/archive/zip-builder.js +0 -292
  206. package/dist/esm/modules/archive/zip-constants.js +0 -23
  207. package/dist/esm/modules/archive/zip-records.js +0 -84
  208. package/dist/types/modules/archive/byte-queue.d.ts +0 -18
  209. package/dist/types/modules/archive/utils/zip-extra.d.ts +0 -18
  210. package/dist/types/modules/archive/zip-builder.d.ts +0 -117
  211. package/dist/types/modules/archive/zip-constants.d.ts +0 -18
  212. /package/dist/browser/modules/archive/{crc32.base.d.ts → compression/crc32.base.d.ts} +0 -0
  213. /package/dist/browser/modules/archive/{crc32.base.js → compression/crc32.base.js} +0 -0
  214. /package/dist/browser/modules/archive/{crc32.browser.js → compression/crc32.browser.js} +0 -0
  215. /package/dist/browser/modules/archive/{deflate-fallback.d.ts → compression/deflate-fallback.d.ts} +0 -0
  216. /package/dist/browser/modules/archive/{streaming-compress.base.d.ts → compression/streaming-compress.base.d.ts} +0 -0
  217. /package/dist/browser/modules/archive/{streaming-compress.base.js → compression/streaming-compress.base.js} +0 -0
  218. /package/dist/browser/modules/archive/{extract.js → unzip/extract.js} +0 -0
  219. /package/dist/browser/modules/archive/{zip-entry-metadata.d.ts → zip/zip-entry-metadata.d.ts} +0 -0
  220. /package/dist/browser/modules/archive/{zip-entry-info.d.ts → zip-spec/zip-entry-info.d.ts} +0 -0
  221. /package/dist/browser/modules/archive/{zip-entry-info.js → zip-spec/zip-entry-info.js} +0 -0
  222. /package/dist/cjs/modules/archive/{crc32.base.js → compression/crc32.base.js} +0 -0
  223. /package/dist/cjs/modules/archive/{crc32.browser.js → compression/crc32.browser.js} +0 -0
  224. /package/dist/cjs/modules/archive/{streaming-compress.base.js → compression/streaming-compress.base.js} +0 -0
  225. /package/dist/cjs/modules/archive/{extract.js → unzip/extract.js} +0 -0
  226. /package/dist/cjs/modules/archive/{zip-entry-info.js → zip-spec/zip-entry-info.js} +0 -0
  227. /package/dist/esm/modules/archive/{crc32.base.js → compression/crc32.base.js} +0 -0
  228. /package/dist/esm/modules/archive/{crc32.browser.js → compression/crc32.browser.js} +0 -0
  229. /package/dist/esm/modules/archive/{streaming-compress.base.js → compression/streaming-compress.base.js} +0 -0
  230. /package/dist/esm/modules/archive/{extract.js → unzip/extract.js} +0 -0
  231. /package/dist/esm/modules/archive/{zip-entry-info.js → zip-spec/zip-entry-info.js} +0 -0
  232. /package/dist/{LICENSE → iife/LICENSE} +0 -0
  233. /package/dist/types/modules/archive/{compress.d.ts → compression/compress.d.ts} +0 -0
  234. /package/dist/types/modules/archive/{crc32.base.d.ts → compression/crc32.base.d.ts} +0 -0
  235. /package/dist/types/modules/archive/{crc32.browser.d.ts → compression/crc32.browser.d.ts} +0 -0
  236. /package/dist/types/modules/archive/{crc32.d.ts → compression/crc32.d.ts} +0 -0
  237. /package/dist/types/modules/archive/{deflate-fallback.d.ts → compression/deflate-fallback.d.ts} +0 -0
  238. /package/dist/types/modules/archive/{streaming-compress.base.d.ts → compression/streaming-compress.base.d.ts} +0 -0
  239. /package/dist/types/modules/archive/{streaming-compress.d.ts → compression/streaming-compress.d.ts} +0 -0
  240. /package/dist/types/modules/archive/{extract.d.ts → unzip/extract.d.ts} +0 -0
  241. /package/dist/types/modules/archive/{zip-entry-info.d.ts → zip-spec/zip-entry-info.d.ts} +0 -0
@@ -62,20 +62,34 @@ 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;
65
66
  // Create a pass-through wrapper that proxies to the underlying stream
66
67
  super({
67
68
  highWaterMark: options?.highWaterMark,
68
69
  objectMode: options?.objectMode,
69
70
  write(chunk, encoding, callback) {
70
- options.stream.write(chunk, encoding, callback);
71
+ underlying.write(chunk, encoding, callback);
71
72
  },
72
73
  final(callback) {
73
- options.stream.end(callback);
74
+ underlying.end(callback);
74
75
  }
75
76
  });
76
- // Proxy events from underlying stream
77
- options.stream.on("error", err => this.emit("error", err));
78
- options.stream.on("close", () => this.emit("close"));
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);
79
93
  }
80
94
  else {
81
95
  super({
@@ -100,17 +114,16 @@ function normalizeWritable(stream) {
100
114
  if (stream instanceof Writable) {
101
115
  return stream;
102
116
  }
103
- // Node.js Writable: accept structurally even if typed as unknown.
117
+ // Node.js Writable: already compatible, avoid extra wrapper allocation.
104
118
  if (stream instanceof stream_1.Writable) {
105
- return new Writable({ stream: stream });
119
+ return stream;
106
120
  }
107
121
  // Web WritableStream: detect by getWriter() (avoid relying on global WritableStream).
108
122
  if (stream?.getWriter) {
109
- const nodeWritable = stream_1.Writable.fromWeb(stream);
110
- return new Writable({ stream: nodeWritable });
123
+ return stream_1.Writable.fromWeb(stream);
111
124
  }
112
- // Assume it structurally matches Node's Writable; wrap for consistent API.
113
- return new Writable({ stream: stream });
125
+ // Assume it structurally matches Node's Writable.
126
+ return stream;
114
127
  }
115
128
  // Import for internal use
116
129
  const shared_1 = require("./shared.js");
@@ -223,12 +236,13 @@ function finished(stream, optionsOrCallback, callback) {
223
236
  const promise = new Promise((resolve, reject) => {
224
237
  const normalizedStream = toNodePipelineStream(stream);
225
238
  stream_1.finished(normalizedStream, options, (err) => {
226
- if (err && !(options && options.error)) {
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) {
227
242
  reject(err);
243
+ return;
228
244
  }
229
- else {
230
- resolve();
231
- }
245
+ resolve();
232
246
  });
233
247
  });
234
248
  if (cb) {
@@ -581,13 +595,28 @@ function addAbortSignal(signal, stream) {
581
595
  stream.destroy(new Error("Aborted"));
582
596
  return stream;
583
597
  }
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
+ };
584
605
  const onAbort = () => {
606
+ cleanup();
585
607
  stream.destroy(new Error("Aborted"));
586
608
  };
609
+ const onDone = () => {
610
+ cleanup();
611
+ };
612
+ const onError = () => {
613
+ cleanup();
614
+ };
587
615
  signal.addEventListener("abort", onAbort, { once: true });
588
- stream.on("close", () => {
589
- signal.removeEventListener("abort", onAbort);
590
- });
616
+ stream.once?.("close", onDone);
617
+ stream.once?.("end", onDone);
618
+ stream.once?.("finish", onDone);
619
+ stream.once?.("error", onError);
591
620
  return stream;
592
621
  }
593
622
  /**
@@ -630,56 +659,109 @@ function compose(...transforms) {
630
659
  if (len === 1 && isNativeTransform(transforms[0])) {
631
660
  return transforms[0];
632
661
  }
633
- // Chain all transforms together
662
+ // Chain all transforms together once.
634
663
  for (let i = 0; i < len - 1; i++) {
635
664
  transforms[i].pipe(transforms[i + 1]);
636
665
  }
637
- // Create a Duplex that writes to first and reads from last
638
666
  const first = transforms[0];
639
667
  const last = transforms[len - 1];
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);
649
- }
650
- return first.write(chunk, encodingOrCallback, callback);
651
- };
652
- // Override end to end first transform
653
- composed.end = function (chunkOrCallback, encodingOrCallback, callback) {
654
- if (typeof chunkOrCallback === "function") {
655
- first.end(chunkOrCallback);
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;
656
676
  }
657
- else if (typeof encodingOrCallback === "function") {
658
- first.end(chunkOrCallback, encodingOrCallback);
677
+ while (true) {
678
+ const chunk = output.read();
679
+ if (chunk === null) {
680
+ break;
681
+ }
682
+ if (!target.push(chunk)) {
683
+ break;
684
+ }
659
685
  }
660
- else {
661
- first.end(chunkOrCallback, encodingOrCallback, callback);
686
+ };
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
+ }
662
730
  }
663
- return composed;
731
+ });
732
+ const onOutputReadable = () => {
733
+ pumpOutput(composed);
664
734
  };
665
- // Override pipe to pipe from last transform
666
- composed.pipe = function (dest) {
667
- return last.pipe(dest);
735
+ const onOutputEnd = () => {
736
+ cleanupListeners();
737
+ outputEnded = true;
738
+ composed.push(null);
668
739
  };
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();
676
- });
677
- // Forward errors from any transform
678
- for (const transform of transforms) {
679
- transform.on("error", (err) => {
680
- composed.emit("error", err);
681
- });
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);
751
+ }
752
+ transformErrorListeners.length = 0;
753
+ };
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 });
682
761
  }
762
+ composed.once("close", () => {
763
+ cleanupListeners();
764
+ });
683
765
  return composed;
684
766
  }
685
767
  /**
@@ -760,7 +842,7 @@ function once(emitter, event, options) {
760
842
  onAbort();
761
843
  return;
762
844
  }
763
- options.signal.addEventListener("abort", onAbort);
845
+ options.signal.addEventListener("abort", onAbort, { once: true });
764
846
  }
765
847
  });
766
848
  }
@@ -39,3 +39,15 @@ 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";
@@ -8,11 +8,12 @@
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 "./byte-queue.js";
11
+ import { ByteQueue } from "../internal/byte-queue.js";
12
12
  /**
13
13
  * Default threshold (in bytes) to choose the lower-overhead path.
14
14
  *
15
15
  * This is a performance knob, not a correctness requirement.
16
+ * Default: 8MB.
16
17
  */
17
18
  export const DEFAULT_COMPRESS_THRESHOLD_BYTES = 8 * 1024 * 1024;
18
19
  /**
@@ -10,23 +10,18 @@
10
10
  * - Safari >= 14.1
11
11
  * - Edge >= 89
12
12
  */
13
- import { compressWithStream, decompressWithStream, hasDeflateRawCompressionStream, hasDeflateRawDecompressionStream, resolveCompressThresholdBytes } from "./compress.base.js";
13
+ import { compressWithStream, decompressWithStream, hasCompressionStream, 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
- /**
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
- }
18
+ export { hasCompressionStream };
27
19
  /**
28
20
  * Compress data using browser's native CompressionStream or JS fallback
29
21
  *
22
+ * Note: We always prefer native CompressionStream when available because
23
+ * it's significantly faster than pure JS implementation.
24
+ *
30
25
  * @param data - Data to compress
31
26
  * @param options - Compression options
32
27
  * @returns Compressed data
@@ -39,16 +34,15 @@ export function hasCompressionStream() {
39
34
  */
40
35
  export async function compress(data, options = {}) {
41
36
  const level = options.level ?? DEFAULT_COMPRESS_LEVEL;
42
- const thresholdBytes = resolveCompressThresholdBytes(options);
43
37
  // Level 0 means no compression
44
38
  if (level === 0) {
45
39
  return data;
46
40
  }
47
- // Use native CompressionStream only for larger inputs.
48
- if (hasDeflateRawCompressionStream() && data.byteLength > thresholdBytes) {
41
+ // Always use native CompressionStream when available - it's much faster than JS
42
+ if (hasDeflateRawCompressionStream()) {
49
43
  return compressWithStream(data);
50
44
  }
51
- // Fallback to pure JS implementation
45
+ // Fallback to pure JS implementation only when native is unavailable
52
46
  return deflateRawCompressed(data);
53
47
  }
54
48
  /**
@@ -70,16 +64,21 @@ export function compressSync(data, options = {}) {
70
64
  /**
71
65
  * Decompress data using browser's native DecompressionStream or JS fallback
72
66
  *
67
+ * Note: We always prefer native DecompressionStream when available because
68
+ * it's significantly faster than pure JS implementation, regardless of data size.
69
+ * The threshold is only useful for compression where the overhead matters more.
70
+ *
73
71
  * @param data - Compressed data (deflate-raw format)
72
+ * @param options - Decompression options (kept for API parity; currently unused in browser)
74
73
  * @returns Decompressed data
75
74
  */
76
75
  export async function decompress(data, options = {}) {
77
- const thresholdBytes = resolveCompressThresholdBytes(options);
78
- // Use native DecompressionStream only for larger inputs.
79
- if (hasDeflateRawDecompressionStream() && data.byteLength > thresholdBytes) {
76
+ void options;
77
+ // Always use native DecompressionStream when available - it's much faster than JS
78
+ if (hasDeflateRawDecompressionStream()) {
80
79
  return decompressWithStream(data);
81
80
  }
82
- // Fallback to pure JS implementation
81
+ // Fallback to pure JS implementation only when native is unavailable
83
82
  return inflateRaw(data);
84
83
  }
85
84
  /**
@@ -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;
@@ -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
  // ============================================================================
@@ -6,11 +6,11 @@
6
6
  *
7
7
  * API compatible with Node.js version - supports .on("data"), .on("end"), .write(callback), .end()
8
8
  */
9
- import { EventEmitter } from "../stream/index.js";
9
+ import { EventEmitter } from "../../stream/index.js";
10
10
  import { deflateRawCompressed, inflateRaw } from "./deflate-fallback.js";
11
11
  import { hasDeflateRawWebStreams } from "./compress.base.js";
12
- import { concatUint8Arrays } from "./utils/bytes.js";
13
- import { DEFAULT_COMPRESS_LEVEL } from "./defaults.js";
12
+ import { concatUint8Arrays } from "../utils/bytes.js";
13
+ import { DEFAULT_COMPRESS_LEVEL } from "../defaults.js";
14
14
  import { asError } from "./streaming-compress.base.js";
15
15
  /**
16
16
  * Check if deflate-raw streaming compression is supported by this library.
@@ -5,8 +5,8 @@
5
5
  * Each write() immediately produces compressed output without waiting for end().
6
6
  */
7
7
  import { createDeflateRaw, createInflateRaw, constants } from "zlib";
8
- import { Transform } from "../stream/index.js";
9
- import { DEFAULT_COMPRESS_LEVEL } from "./defaults.js";
8
+ import { Transform } from "../../stream/index.js";
9
+ import { DEFAULT_COMPRESS_LEVEL } from "../defaults.js";
10
10
  /**
11
11
  * Wrapper around zlib DeflateRaw that flushes after every write
12
12
  * This ensures true streaming behavior - data is emitted immediately, not buffered
@@ -1,3 +1,6 @@
1
- export const DEFAULT_COMPRESS_LEVEL = 6;
2
- export const DEFAULT_ZIP_LEVEL = 6;
3
- export const DEFAULT_ZIP_TIMESTAMPS = "dos+utc";
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";
@@ -5,9 +5,6 @@
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
- // 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";
8
+ // High-level APIs
9
+ export { zip, ZipArchive } from "./zip/index.js";
10
+ export { unzip, ZipReader, UnzipEntry } from "./unzip/index.js";
@@ -6,12 +6,8 @@
6
6
  */
7
7
  export * from "./index.base.js";
8
8
  // CRC32
9
- export { crc32, crc32Update, crc32Finalize } from "./crc32.browser.js";
9
+ export { crc32, crc32Update, crc32Finalize } from "./compression/crc32.browser.js";
10
10
  // Compression
11
- export { compress, compressSync, decompress, decompressSync, hasCompressionStream } from "./compress.browser.js";
11
+ export { compress, compressSync, decompress, decompressSync, hasCompressionStream } from "./compression/compress.browser.js";
12
12
  // Streaming compression
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)
13
+ export { createDeflateStream, createInflateStream, hasDeflateRaw } from "./compression/streaming-compress.browser.js";
@@ -6,10 +6,8 @@
6
6
  */
7
7
  export * from "./index.base.js";
8
8
  // CRC32
9
- export { crc32, crc32Update, crc32Finalize } from "./crc32.js";
9
+ export { crc32, crc32Update, crc32Finalize } from "./compression/crc32.js";
10
10
  // Compression
11
- export { compress, compressSync, decompress, decompressSync, hasCompressionStream } from "./compress.js";
11
+ export { compress, compressSync, decompress, decompressSync, hasCompressionStream } from "./compression/compress.js";
12
12
  // Streaming compression
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";
13
+ export { createDeflateStream, createInflateStream, hasDeflateRaw } from "./compression/streaming-compress.js";