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