@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
@@ -1,117 +0,0 @@
1
- /**
2
- * ZIP file format builder
3
- *
4
- * Implements ZIP file structure according to PKWARE's APPNOTE.TXT specification
5
- * https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
6
- *
7
- * ZIP file structure:
8
- * ┌──────────────────────────┐
9
- * │ Local File Header 1 │
10
- * │ File Data 1 │
11
- * ├──────────────────────────┤
12
- * │ Local File Header 2 │
13
- * │ File Data 2 │
14
- * ├──────────────────────────┤
15
- * │ ... │
16
- * ├──────────────────────────┤
17
- * │ Central Directory 1 │
18
- * │ Central Directory 2 │
19
- * │ ... │
20
- * ├──────────────────────────┤
21
- * │ End of Central Directory │
22
- * └──────────────────────────┘
23
- */
24
- import { type CompressOptions } from "@archive/compress";
25
- import { type ZipTimestampMode } from "@archive/utils/timestamps";
26
- /**
27
- * ZIP file entry
28
- */
29
- export interface ZipEntry {
30
- /** File name (can include directory path, use forward slashes) */
31
- name: string;
32
- /** File data (will be compressed unless level=0) */
33
- data: Uint8Array;
34
- /** File modification time (optional, defaults to current time) */
35
- modTime?: Date;
36
- /** File comment (optional) */
37
- comment?: string;
38
- }
39
- /**
40
- * ZIP builder options
41
- */
42
- export interface ZipOptions extends CompressOptions {
43
- /** ZIP file comment (optional) */
44
- comment?: string;
45
- /**
46
- * Timestamp writing strategy.
47
- * - "dos": only write DOS date/time fields (smallest output)
48
- * - "dos+utc": also write UTC mtime in 0x5455 extra field (default, best practice)
49
- */
50
- timestamps?: ZipTimestampMode;
51
- }
52
- /**
53
- * Create a ZIP file from entries (async)
54
- *
55
- * @param entries - Files to include in ZIP
56
- * @param options - ZIP options
57
- * @returns ZIP file as Uint8Array
58
- *
59
- * @example
60
- * ```ts
61
- * const zip = await createZip([
62
- * { name: "hello.txt", data: new TextEncoder().encode("Hello!") },
63
- * { name: "folder/file.txt", data: new TextEncoder().encode("Nested!") }
64
- * ], { level: 6 });
65
- * ```
66
- */
67
- export declare function createZip(entries: ZipEntry[], options?: ZipOptions): Promise<Uint8Array>;
68
- /**
69
- * Create a ZIP file from entries (sync)
70
- *
71
- * This is supported in both Node.js and browser builds.
72
- */
73
- export declare function createZipSync(entries: ZipEntry[], options?: ZipOptions): Uint8Array;
74
- /**
75
- * Streaming ZIP builder for large files
76
- * Writes chunks to a callback as they are generated
77
- */
78
- export declare class ZipBuilder {
79
- private entries;
80
- private currentOffset;
81
- private level;
82
- private zipComment;
83
- private timestamps;
84
- private compressOptions;
85
- private settings;
86
- private finalized;
87
- /**
88
- * Create a new ZIP builder
89
- * @param options - ZIP options
90
- */
91
- constructor(options?: ZipOptions);
92
- /**
93
- * Add a file to the ZIP (async)
94
- * @param entry - File entry
95
- * @returns Local file header and compressed data chunks
96
- */
97
- addFile(entry: ZipEntry): Promise<Uint8Array[]>;
98
- /**
99
- * Add a file to the ZIP (sync)
100
- * @param entry - File entry
101
- * @returns Local file header and compressed data chunks
102
- */
103
- addFileSync(entry: ZipEntry): Uint8Array[];
104
- /**
105
- * Finalize the ZIP and return central directory + end record
106
- * @returns Central directory and end of central directory chunks
107
- */
108
- finalize(): Uint8Array[];
109
- /**
110
- * Get current number of entries
111
- */
112
- get entryCount(): number;
113
- /**
114
- * Get current ZIP data size (without central directory)
115
- */
116
- get dataSize(): number;
117
- }
@@ -1,292 +0,0 @@
1
- /**
2
- * ZIP file format builder
3
- *
4
- * Implements ZIP file structure according to PKWARE's APPNOTE.TXT specification
5
- * https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
6
- *
7
- * ZIP file structure:
8
- * ┌──────────────────────────┐
9
- * │ Local File Header 1 │
10
- * │ File Data 1 │
11
- * ├──────────────────────────┤
12
- * │ Local File Header 2 │
13
- * │ File Data 2 │
14
- * ├──────────────────────────┤
15
- * │ ... │
16
- * ├──────────────────────────┤
17
- * │ Central Directory 1 │
18
- * │ Central Directory 2 │
19
- * │ ... │
20
- * ├──────────────────────────┤
21
- * │ End of Central Directory │
22
- * └──────────────────────────┘
23
- */
24
- import { compress, compressSync } from "./compress.browser.js";
25
- import { crc32 } from "./crc32.browser.js";
26
- import { concatUint8Arrays, sumUint8ArrayLengths } from "./utils/bytes.js";
27
- import {} from "./utils/timestamps.js";
28
- import { buildZipEntryMetadata, resolveZipCompressionMethod } from "./zip-entry-metadata.js";
29
- import { DEFAULT_ZIP_LEVEL, DEFAULT_ZIP_TIMESTAMPS } from "./defaults.js";
30
- import { buildCentralDirectoryHeader, buildEndOfCentralDirectory, buildLocalFileHeader } from "./zip-records.js";
31
- import { FLAG_UTF8, VERSION_MADE_BY, VERSION_NEEDED } from "./zip-constants.js";
32
- const LOCAL_FILE_HEADER_FIXED_SIZE = 30;
33
- function encodeZipComment(comment) {
34
- // Keep empty comment as empty bytes (no encoding surprises).
35
- return comment ? new TextEncoder().encode(comment) : new Uint8Array(0);
36
- }
37
- function shouldDeflate(level, data) {
38
- return level > 0 && data.length > 0;
39
- }
40
- function computeLocalRecordSize(entry) {
41
- return (LOCAL_FILE_HEADER_FIXED_SIZE +
42
- entry.name.length +
43
- entry.extraField.length +
44
- entry.compressedData.length);
45
- }
46
- function buildProcessedEntry(entry, offset, settings, compressedData) {
47
- const modDate = entry.modTime ?? settings.defaultModTime;
48
- const isCompressed = shouldDeflate(settings.level, entry.data);
49
- const metadata = buildZipEntryMetadata({
50
- name: entry.name,
51
- comment: entry.comment,
52
- modTime: modDate,
53
- timestamps: settings.timestamps,
54
- useDataDescriptor: false,
55
- deflate: isCompressed
56
- });
57
- return {
58
- name: metadata.nameBytes,
59
- data: entry.data,
60
- compressedData,
61
- crc: crc32(entry.data),
62
- compressionMethod: resolveZipCompressionMethod(isCompressed),
63
- modTime: metadata.dosTime,
64
- modDate: metadata.dosDate,
65
- extraField: metadata.extraField,
66
- comment: metadata.commentBytes,
67
- offset
68
- };
69
- }
70
- function appendProcessedEntry(processedEntries, entry, compressedData, currentOffset, settings) {
71
- const processedEntry = buildProcessedEntry(entry, currentOffset, settings, compressedData);
72
- processedEntries.push(processedEntry);
73
- return {
74
- processedEntry,
75
- nextOffset: currentOffset + computeLocalRecordSize(processedEntry)
76
- };
77
- }
78
- function finalizeZip(processedEntries, zipComment, centralDirOffset) {
79
- // Build ZIP structure
80
- const chunks = [];
81
- // Local file headers and data
82
- for (const entry of processedEntries) {
83
- chunks.push(buildLocalFileHeaderChunk(entry));
84
- chunks.push(entry.compressedData);
85
- }
86
- chunks.push(...buildCentralDirectorySection(processedEntries, centralDirOffset, zipComment));
87
- return concatUint8Arrays(chunks);
88
- }
89
- function buildLocalFileHeaderChunk(entry) {
90
- return buildLocalFileHeader({
91
- fileName: entry.name,
92
- extraField: entry.extraField,
93
- flags: FLAG_UTF8,
94
- compressionMethod: entry.compressionMethod,
95
- dosTime: entry.modTime,
96
- dosDate: entry.modDate,
97
- crc32: entry.crc,
98
- compressedSize: entry.compressedData.length,
99
- uncompressedSize: entry.data.length,
100
- versionNeeded: VERSION_NEEDED
101
- });
102
- }
103
- function buildCentralDirHeaderChunk(entry) {
104
- return buildCentralDirectoryHeader({
105
- fileName: entry.name,
106
- extraField: entry.extraField,
107
- comment: entry.comment,
108
- flags: FLAG_UTF8,
109
- compressionMethod: entry.compressionMethod,
110
- dosTime: entry.modTime,
111
- dosDate: entry.modDate,
112
- crc32: entry.crc,
113
- compressedSize: entry.compressedData.length,
114
- uncompressedSize: entry.data.length,
115
- localHeaderOffset: entry.offset,
116
- versionMadeBy: VERSION_MADE_BY,
117
- versionNeeded: VERSION_NEEDED
118
- });
119
- }
120
- function buildCentralDirectorySection(processedEntries, centralDirOffset, zipComment) {
121
- const chunks = [];
122
- for (const entry of processedEntries) {
123
- chunks.push(buildCentralDirHeaderChunk(entry));
124
- }
125
- const centralDirSize = sumUint8ArrayLengths(chunks);
126
- chunks.push(buildEndOfCentralDirectory({
127
- entryCount: processedEntries.length,
128
- centralDirSize,
129
- centralDirOffset,
130
- comment: zipComment
131
- }));
132
- return chunks;
133
- }
134
- /**
135
- * Create a ZIP file from entries (async)
136
- *
137
- * @param entries - Files to include in ZIP
138
- * @param options - ZIP options
139
- * @returns ZIP file as Uint8Array
140
- *
141
- * @example
142
- * ```ts
143
- * const zip = await createZip([
144
- * { name: "hello.txt", data: new TextEncoder().encode("Hello!") },
145
- * { name: "folder/file.txt", data: new TextEncoder().encode("Nested!") }
146
- * ], { level: 6 });
147
- * ```
148
- */
149
- export async function createZip(entries, options = {}) {
150
- const level = options.level ?? DEFAULT_ZIP_LEVEL;
151
- const timestamps = options.timestamps ?? DEFAULT_ZIP_TIMESTAMPS;
152
- const zipComment = encodeZipComment(options.comment);
153
- const defaultModTime = new Date();
154
- const settings = {
155
- level,
156
- timestamps,
157
- defaultModTime
158
- };
159
- const compressOptions = {
160
- level,
161
- thresholdBytes: options.thresholdBytes
162
- };
163
- const compressedDatas = await Promise.all(entries.map(async (entry) => {
164
- return shouldDeflate(level, entry.data) ? compress(entry.data, compressOptions) : entry.data;
165
- }));
166
- // Process entries
167
- const processedEntries = [];
168
- let currentOffset = 0;
169
- for (let i = 0; i < entries.length; i++) {
170
- const entry = entries[i];
171
- const compressedData = compressedDatas[i];
172
- const result = appendProcessedEntry(processedEntries, entry, compressedData, currentOffset, settings);
173
- currentOffset = result.nextOffset;
174
- }
175
- return finalizeZip(processedEntries, zipComment, currentOffset);
176
- }
177
- /**
178
- * Create a ZIP file from entries (sync)
179
- *
180
- * This is supported in both Node.js and browser builds.
181
- */
182
- export function createZipSync(entries, options = {}) {
183
- const level = options.level ?? DEFAULT_ZIP_LEVEL;
184
- const timestamps = options.timestamps ?? DEFAULT_ZIP_TIMESTAMPS;
185
- const zipComment = encodeZipComment(options.comment);
186
- const defaultModTime = new Date();
187
- const settings = {
188
- level,
189
- timestamps,
190
- defaultModTime
191
- };
192
- const compressOptions = {
193
- level,
194
- thresholdBytes: options.thresholdBytes
195
- };
196
- // Process entries
197
- const processedEntries = [];
198
- let currentOffset = 0;
199
- for (const entry of entries) {
200
- // Compress data
201
- const compressedData = shouldDeflate(level, entry.data)
202
- ? compressSync(entry.data, compressOptions)
203
- : entry.data;
204
- const result = appendProcessedEntry(processedEntries, entry, compressedData, currentOffset, settings);
205
- currentOffset = result.nextOffset;
206
- }
207
- return finalizeZip(processedEntries, zipComment, currentOffset);
208
- }
209
- /**
210
- * Streaming ZIP builder for large files
211
- * Writes chunks to a callback as they are generated
212
- */
213
- export class ZipBuilder {
214
- /**
215
- * Create a new ZIP builder
216
- * @param options - ZIP options
217
- */
218
- constructor(options = {}) {
219
- this.entries = [];
220
- this.currentOffset = 0;
221
- this.finalized = false;
222
- this.level = options.level ?? DEFAULT_ZIP_LEVEL;
223
- this.zipComment = encodeZipComment(options.comment);
224
- this.timestamps = options.timestamps ?? DEFAULT_ZIP_TIMESTAMPS;
225
- this.compressOptions = {
226
- level: this.level,
227
- thresholdBytes: options.thresholdBytes
228
- };
229
- this.settings = {
230
- level: this.level,
231
- timestamps: this.timestamps,
232
- defaultModTime: new Date()
233
- };
234
- }
235
- /**
236
- * Add a file to the ZIP (async)
237
- * @param entry - File entry
238
- * @returns Local file header and compressed data chunks
239
- */
240
- async addFile(entry) {
241
- if (this.finalized) {
242
- throw new Error("Cannot add files after finalizing");
243
- }
244
- // Compress data
245
- const compressedData = shouldDeflate(this.level, entry.data)
246
- ? await compress(entry.data, this.compressOptions)
247
- : entry.data;
248
- const result = appendProcessedEntry(this.entries, entry, compressedData, this.currentOffset, this.settings);
249
- this.currentOffset = result.nextOffset;
250
- return [buildLocalFileHeaderChunk(result.processedEntry), compressedData];
251
- }
252
- /**
253
- * Add a file to the ZIP (sync)
254
- * @param entry - File entry
255
- * @returns Local file header and compressed data chunks
256
- */
257
- addFileSync(entry) {
258
- if (this.finalized) {
259
- throw new Error("Cannot add files after finalizing");
260
- }
261
- // Compress data
262
- const compressedData = shouldDeflate(this.level, entry.data)
263
- ? compressSync(entry.data, this.compressOptions)
264
- : entry.data;
265
- const result = appendProcessedEntry(this.entries, entry, compressedData, this.currentOffset, this.settings);
266
- this.currentOffset = result.nextOffset;
267
- return [buildLocalFileHeaderChunk(result.processedEntry), compressedData];
268
- }
269
- /**
270
- * Finalize the ZIP and return central directory + end record
271
- * @returns Central directory and end of central directory chunks
272
- */
273
- finalize() {
274
- if (this.finalized) {
275
- throw new Error("ZIP already finalized");
276
- }
277
- this.finalized = true;
278
- return buildCentralDirectorySection(this.entries, this.currentOffset, this.zipComment);
279
- }
280
- /**
281
- * Get current number of entries
282
- */
283
- get entryCount() {
284
- return this.entries.length;
285
- }
286
- /**
287
- * Get current ZIP data size (without central directory)
288
- */
289
- get dataSize() {
290
- return this.currentOffset;
291
- }
292
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * ZIP format constants (PKWARE APPNOTE)
3
- * Shared by ZIP writer and parser implementations.
4
- */
5
- export declare const LOCAL_FILE_HEADER_SIG = 67324752;
6
- export declare const CENTRAL_DIR_HEADER_SIG = 33639248;
7
- export declare const END_OF_CENTRAL_DIR_SIG = 101010256;
8
- export declare const DATA_DESCRIPTOR_SIG = 134695760;
9
- export declare const ZIP64_END_OF_CENTRAL_DIR_SIG = 101075792;
10
- export declare const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG = 117853008;
11
- export declare const VERSION_NEEDED = 20;
12
- export declare const VERSION_MADE_BY = 20;
13
- export declare const COMPRESSION_STORE = 0;
14
- export declare const COMPRESSION_DEFLATE = 8;
15
- export declare const FLAG_UTF8 = 2048;
16
- export declare const FLAG_DATA_DESCRIPTOR = 8;
17
- export declare const UINT16_MAX = 65535;
18
- export declare const UINT32_MAX = 4294967295;
@@ -1,23 +0,0 @@
1
- /**
2
- * ZIP format constants (PKWARE APPNOTE)
3
- * Shared by ZIP writer and parser implementations.
4
- */
5
- // Signatures
6
- export const LOCAL_FILE_HEADER_SIG = 0x04034b50;
7
- export const CENTRAL_DIR_HEADER_SIG = 0x02014b50;
8
- export const END_OF_CENTRAL_DIR_SIG = 0x06054b50;
9
- export const DATA_DESCRIPTOR_SIG = 0x08074b50;
10
- export const ZIP64_END_OF_CENTRAL_DIR_SIG = 0x06064b50;
11
- export const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG = 0x07064b50;
12
- // Versions
13
- export const VERSION_NEEDED = 20; // 2.0 - supports DEFLATE
14
- export const VERSION_MADE_BY = 20; // 2.0
15
- // Compression methods
16
- export const COMPRESSION_STORE = 0;
17
- export const COMPRESSION_DEFLATE = 8;
18
- // General purpose bit flags
19
- export const FLAG_UTF8 = 0x0800;
20
- export const FLAG_DATA_DESCRIPTOR = 0x0008;
21
- // ZIP64 / sentinel sizes
22
- export const UINT16_MAX = 0xffff;
23
- export const UINT32_MAX = 0xffffffff;
@@ -1,84 +0,0 @@
1
- /**
2
- * ZIP record builders (PKWARE APPNOTE)
3
- *
4
- * Shared by streaming zip writer and buffer zip builder.
5
- */
6
- import { CENTRAL_DIR_HEADER_SIG, DATA_DESCRIPTOR_SIG, END_OF_CENTRAL_DIR_SIG, LOCAL_FILE_HEADER_SIG, VERSION_MADE_BY, VERSION_NEEDED } from "./zip-constants.js";
7
- export function buildLocalFileHeader(input) {
8
- const versionNeeded = input.versionNeeded ?? VERSION_NEEDED;
9
- const header = new Uint8Array(30 + input.fileName.length + input.extraField.length);
10
- const view = new DataView(header.buffer);
11
- view.setUint32(0, LOCAL_FILE_HEADER_SIG, true);
12
- view.setUint16(4, versionNeeded, true);
13
- view.setUint16(6, input.flags, true);
14
- view.setUint16(8, input.compressionMethod, true);
15
- view.setUint16(10, input.dosTime, true);
16
- view.setUint16(12, input.dosDate, true);
17
- view.setUint32(14, input.crc32, true);
18
- view.setUint32(18, input.compressedSize, true);
19
- view.setUint32(22, input.uncompressedSize, true);
20
- view.setUint16(26, input.fileName.length, true);
21
- view.setUint16(28, input.extraField.length, true);
22
- header.set(input.fileName, 30);
23
- if (input.extraField.length > 0) {
24
- header.set(input.extraField, 30 + input.fileName.length);
25
- }
26
- return header;
27
- }
28
- export function buildCentralDirectoryHeader(input) {
29
- const versionMadeBy = input.versionMadeBy ?? VERSION_MADE_BY;
30
- const versionNeeded = input.versionNeeded ?? VERSION_NEEDED;
31
- const externalAttributes = input.externalAttributes ?? 0;
32
- const header = new Uint8Array(46 + input.fileName.length + input.extraField.length + input.comment.length);
33
- const view = new DataView(header.buffer);
34
- view.setUint32(0, CENTRAL_DIR_HEADER_SIG, true);
35
- view.setUint16(4, versionMadeBy, true);
36
- view.setUint16(6, versionNeeded, true);
37
- view.setUint16(8, input.flags, true);
38
- view.setUint16(10, input.compressionMethod, true);
39
- view.setUint16(12, input.dosTime, true);
40
- view.setUint16(14, input.dosDate, true);
41
- view.setUint32(16, input.crc32, true);
42
- view.setUint32(20, input.compressedSize, true);
43
- view.setUint32(24, input.uncompressedSize, true);
44
- view.setUint16(28, input.fileName.length, true);
45
- view.setUint16(30, input.extraField.length, true);
46
- view.setUint16(32, input.comment.length, true);
47
- view.setUint16(34, 0, true); // disk number start
48
- view.setUint16(36, 0, true); // internal file attributes
49
- view.setUint32(38, externalAttributes, true);
50
- view.setUint32(42, input.localHeaderOffset, true);
51
- header.set(input.fileName, 46);
52
- if (input.extraField.length > 0) {
53
- header.set(input.extraField, 46 + input.fileName.length);
54
- }
55
- if (input.comment.length > 0) {
56
- header.set(input.comment, 46 + input.fileName.length + input.extraField.length);
57
- }
58
- return header;
59
- }
60
- export function buildEndOfCentralDirectory(input) {
61
- const record = new Uint8Array(22 + input.comment.length);
62
- const view = new DataView(record.buffer);
63
- view.setUint32(0, END_OF_CENTRAL_DIR_SIG, true);
64
- view.setUint16(4, 0, true);
65
- view.setUint16(6, 0, true);
66
- view.setUint16(8, input.entryCount, true);
67
- view.setUint16(10, input.entryCount, true);
68
- view.setUint32(12, input.centralDirSize, true);
69
- view.setUint32(16, input.centralDirOffset, true);
70
- view.setUint16(20, input.comment.length, true);
71
- if (input.comment.length > 0) {
72
- record.set(input.comment, 22);
73
- }
74
- return record;
75
- }
76
- export function buildDataDescriptor(crc32, compressedSize, uncompressedSize) {
77
- const descriptor = new Uint8Array(16);
78
- const view = new DataView(descriptor.buffer);
79
- view.setUint32(0, DATA_DESCRIPTOR_SIG, true);
80
- view.setUint32(4, crc32, true);
81
- view.setUint32(8, compressedSize, true);
82
- view.setUint32(12, uncompressedSize, true);
83
- return descriptor;
84
- }
@@ -1,129 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ByteQueue = void 0;
4
- class ByteQueue {
5
- constructor(initial) {
6
- this._start = 0;
7
- this._end = 0;
8
- this._cachedView = null;
9
- this._cachedBuf = null;
10
- this._cachedStart = 0;
11
- this._cachedEnd = 0;
12
- this._buf = new Uint8Array(0);
13
- if (initial && initial.length > 0) {
14
- this.reset(initial);
15
- }
16
- }
17
- get length() {
18
- return this._end - this._start;
19
- }
20
- isEmpty() {
21
- return this.length === 0;
22
- }
23
- view() {
24
- if (this._start === this._end) {
25
- return ByteQueue.EMPTY;
26
- }
27
- if (this._cachedView &&
28
- this._cachedBuf === this._buf &&
29
- this._cachedStart === this._start &&
30
- this._cachedEnd === this._end) {
31
- return this._cachedView;
32
- }
33
- const view = this._buf.subarray(this._start, this._end);
34
- this._cachedView = view;
35
- this._cachedBuf = this._buf;
36
- this._cachedStart = this._start;
37
- this._cachedEnd = this._end;
38
- return view;
39
- }
40
- reset(data) {
41
- this._cachedView = null;
42
- this._cachedBuf = null;
43
- if (!data || data.length === 0) {
44
- this._buf = ByteQueue.EMPTY;
45
- this._start = 0;
46
- this._end = 0;
47
- return;
48
- }
49
- // Keep a private copy to ensure future writes cannot mutate the source.
50
- const copy = new Uint8Array(data.length);
51
- copy.set(data);
52
- this._buf = copy;
53
- this._start = 0;
54
- this._end = copy.length;
55
- }
56
- append(chunk) {
57
- if (chunk.length === 0) {
58
- return;
59
- }
60
- this._cachedView = null;
61
- this._cachedBuf = null;
62
- const unread = this.length;
63
- // Fast path: enough tail room.
64
- if (this._end + chunk.length <= this._buf.length) {
65
- this._buf.set(chunk, this._end);
66
- this._end += chunk.length;
67
- return;
68
- }
69
- // Allocate a new buffer and copy unread bytes (never compacts in-place).
70
- const required = unread + chunk.length;
71
- const nextSize = this._buf.length === 0 ? required : Math.max(this._buf.length * 2, required);
72
- const next = new Uint8Array(nextSize);
73
- if (unread > 0) {
74
- next.set(this._buf.subarray(this._start, this._end), 0);
75
- }
76
- next.set(chunk, unread);
77
- this._buf = next;
78
- this._start = 0;
79
- this._end = required;
80
- }
81
- read(length) {
82
- if (length <= 0) {
83
- return new Uint8Array(0);
84
- }
85
- if (length > this.length) {
86
- throw new RangeError("ByteQueue: read beyond available data");
87
- }
88
- // Return a view for performance.
89
- // To keep this safe for async consumers, we must ensure we never write into
90
- // the same backing buffer again after it becomes fully consumed.
91
- const out = this._buf.subarray(this._start, this._start + length);
92
- this._start += length;
93
- this._cachedView = null;
94
- this._cachedBuf = null;
95
- if (this._start === this._end) {
96
- // Release backing storage to avoid reusing memory that might still be
97
- // referenced by previously returned views.
98
- this._buf = ByteQueue.EMPTY;
99
- this._start = 0;
100
- this._end = 0;
101
- }
102
- return out;
103
- }
104
- discard(length) {
105
- if (length <= 0) {
106
- return;
107
- }
108
- if (length >= this.length) {
109
- // Release backing storage for the same reason as read(): previously
110
- // returned views may still be referenced by consumers.
111
- this._buf = ByteQueue.EMPTY;
112
- this._start = 0;
113
- this._end = 0;
114
- this._cachedView = null;
115
- this._cachedBuf = null;
116
- return;
117
- }
118
- this._start += length;
119
- this._cachedView = null;
120
- this._cachedBuf = null;
121
- if (this._start === this._end) {
122
- this._buf = ByteQueue.EMPTY;
123
- this._start = 0;
124
- this._end = 0;
125
- }
126
- }
127
- }
128
- exports.ByteQueue = ByteQueue;
129
- ByteQueue.EMPTY = new Uint8Array(0);