@poe-platform/safe-bash 0.1.756 → 0.1.758

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 (161) hide show
  1. package/dist/image-ast/index.browser.js +76 -23
  2. package/dist/image-ast/index.js +76 -23
  3. package/dist/pdf-ast/ast.d.ts +3 -0
  4. package/dist/pdf-ast/index.js +88 -36
  5. package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
  6. package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
  7. package/dist/safe-bash/command-chunks/{chunk-F3J5ZLKF.js → chunk-522TDVLS.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-VFS2MDAB.js → chunk-6YLD37NH.js} +2 -2
  9. package/dist/safe-bash/command-chunks/{chunk-YI3GKJ7Q.js → chunk-766IWMTB.js} +2 -2
  10. package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
  11. package/dist/safe-bash/command-chunks/{chunk-KSH2F6RG.js → chunk-CUFCNL6G.js} +1 -1
  12. package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
  13. package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
  14. package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
  15. package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-J2NPH7DO.js} +11 -7
  16. package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
  17. package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
  18. package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
  19. package/dist/safe-bash/command-chunks/{chunk-KBBI4CSU.js → chunk-L2C5TIII.js} +2 -2
  20. package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
  21. package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
  22. package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
  23. package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
  24. package/dist/safe-bash/command-chunks/{chunk-H2FQA4OU.js → chunk-TCAGGM44.js} +72 -19
  25. package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
  26. package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
  27. package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
  28. package/dist/safe-bash/command-chunks/{chunk-WI35236J.js → chunk-XYCWDGOG.js} +1 -1
  29. package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
  30. package/dist/safe-bash/command-chunks/{chunk-4F6PG2OT.js → chunk-YJWWRCIG.js} +8 -8
  31. package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
  32. package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
  33. package/dist/safe-bash/commands/pandoc/index.js +5 -3
  34. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  35. package/dist/safe-bash/commands/python/index.js +6 -0
  36. package/dist/safe-bash/commands/python/jspi.js +11 -2
  37. package/dist/safe-bash/core.browser.js +6 -4
  38. package/dist/safe-bash-command-column/column.js +3 -3
  39. package/dist/safe-bash-command-column/index.js +3 -3
  40. package/dist/safe-bash-command-column/layout.js +2 -2
  41. package/dist/safe-bash-command-csvkit/index.js +8 -8
  42. package/dist/safe-bash-command-factor/command.js +2 -2
  43. package/dist/safe-bash-command-factor/index.js +2 -2
  44. package/dist/safe-bash-command-ffmpeg/index.js +5923 -5893
  45. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  46. package/dist/safe-bash-command-pandoc/command.js +3 -3
  47. package/dist/safe-bash-command-pandoc/index.js +3 -3
  48. package/dist/safe-bash-command-pdfimages/index.js +72 -19
  49. package/dist/safe-bash-command-pdfinfo/index.js +88 -36
  50. package/dist/safe-bash-command-pdftk/index.js +72 -19
  51. package/dist/safe-bash-command-pdftoppm/index.js +88 -36
  52. package/dist/safe-bash-command-pdftotext/index.js +72 -19
  53. package/dist/safe-bash-command-qpdf/index.js +72 -19
  54. package/dist/safe-bash-command-sips/index.js +2 -2
  55. package/dist/safe-bash-command-soffice/index.js +17 -17
  56. package/dist/safe-bash-command-ssconvert/command-bindings.d.ts +18 -0
  57. package/dist/safe-bash-command-ssconvert/command.d.ts +5 -14
  58. package/dist/safe-bash-command-ssconvert/commands.d.ts +6 -0
  59. package/dist/safe-bash-command-ssconvert/commands.js +871 -0
  60. package/dist/safe-bash-command-ssconvert/core.js +8 -8
  61. package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
  62. package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
  63. package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
  64. package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
  65. package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
  66. package/dist/safe-bash-command-ssconvert/index.js +376 -236
  67. package/dist/safe-bash-command-wkhtmltopdf/index.js +72 -19
  68. package/dist/safe-bash-command-yq/index.js +4 -4
  69. package/dist/safe-bash-compression-engine/files.js +2 -2
  70. package/dist/safe-bash-compression-engine/operand.js +4 -4
  71. package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
  72. package/dist/safe-bash-contracts/filesystem-output.js +1 -1
  73. package/dist/safe-bash-markdown-engine/commonmark-blocks.js +4 -4
  74. package/dist/safe-bash-markdown-engine/commonmark-inlines.js +4 -4
  75. package/dist/safe-bash-markdown-engine/commonmark-syntax.js +2 -2
  76. package/dist/safe-bash-markdown-engine/gfm-syntax.js +3 -3
  77. package/dist/safe-bash-markdown-engine/index.js +7 -7
  78. package/dist/safe-bash-mcp/index.js +4 -4
  79. package/dist/safe-bash-query-engine/index.js +5 -5
  80. package/dist/safe-bash-query-engine/interpreter.js +4 -4
  81. package/dist/safe-bash-query-engine/query-core.js +5 -5
  82. package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
  83. package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
  84. package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
  85. package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
  86. package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
  87. package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
  88. package/dist/spreadsheet-engine/formulas/parser.js +34 -0
  89. package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
  90. package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
  91. package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
  92. package/dist/xlsx-ast/formula-semantics.js +2 -0
  93. package/package.json +6 -2
  94. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +16 -0
  95. package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
  96. package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
  97. package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
  98. package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
  99. package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
  100. package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
  101. package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
  102. package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
  103. package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
  104. package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
  105. package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
  106. package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
  107. package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
  108. package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
  109. package/dist/safe-bash/chunks/chunk-CBVANNKK.js +0 -174814
  110. package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
  111. package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
  112. package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
  113. package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
  114. package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
  115. package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
  116. package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
  117. package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
  118. package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
  119. package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
  120. package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
  121. package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
  122. package/dist/safe-bash/chunks/chunk-JCN3FXLP.js +0 -38983
  123. package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
  124. package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
  125. package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
  126. package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
  127. package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
  128. package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
  129. package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
  130. package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
  131. package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
  132. package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
  133. package/dist/safe-bash/chunks/chunk-OSUXMC43.js +0 -2317
  134. package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
  135. package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
  136. package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
  137. package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
  138. package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
  139. package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
  140. package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
  141. package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
  142. package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
  143. package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
  144. package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
  145. package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
  146. package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
  147. package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
  148. package/dist/safe-bash/chunks/pdf-renderer-CMF3CSVU.js +0 -22
  149. package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
  150. package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
  151. package/dist/safe-bash/chunks/src-MXIKQCIC.js +0 -187
  152. package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
  153. package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
  154. package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
  155. package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
  156. package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
  157. package/dist/safe-bash/command-chunks/{chunk-OQVIJMBY.js → chunk-7HINP7ZK.js} +4 -4
  158. package/dist/safe-bash/command-chunks/{chunk-XAYEDOV5.js → chunk-CG4JSOK2.js} +3 -3
  159. package/dist/safe-bash/command-chunks/{chunk-YIK4ZYQ4.js → chunk-DC52GWRK.js} +9 -9
  160. package/dist/safe-bash/command-chunks/{chunk-TOTZFBDT.js → chunk-TKACIO4X.js} +4 -4
  161. package/dist/safe-bash/command-chunks/{chunk-VTWKS4RM.js → chunk-WF2LSKMI.js} +3 -3
@@ -1,1031 +0,0 @@
1
- import {
2
- ZStream,
3
- Z_BUF_ERROR,
4
- Z_DATA_ERROR,
5
- Z_FINISH,
6
- Z_NO_FLUSH,
7
- Z_OK,
8
- Z_STREAM_END,
9
- deflate$1,
10
- deflateEnd,
11
- deflateInit2,
12
- inflate$1,
13
- inflateEnd,
14
- inflateInit2,
15
- inflateReset
16
- } from "./chunk-64OE6Q6X.js";
17
- import {
18
- init_platform
19
- } from "./chunk-ZG7GWQ5P.js";
20
-
21
- // packages/office-package/src/runtime.ts
22
- init_platform();
23
- var CodecError = class extends Error {
24
- code;
25
- constructor(message) {
26
- super(message);
27
- this.name = "CodecError";
28
- this.code = message.includes("limit") ? "resource-limit" : "invalid-package";
29
- }
30
- };
31
- function yieldEventLoop() {
32
- return new Promise((resolve) => {
33
- const immediate = globalThis.setImmediate;
34
- if (typeof immediate === "function") immediate(resolve);
35
- else setTimeout(resolve, 0);
36
- });
37
- }
38
- var defaultRuntime = {
39
- async yieldTurn(signal) {
40
- signal.throwIfAborted();
41
- await yieldEventLoop();
42
- signal.throwIfAborted();
43
- },
44
- async *readBytes(source, signal) {
45
- signal.throwIfAborted();
46
- for await (const bytes of source) {
47
- signal.throwIfAborted();
48
- if (!(bytes instanceof Uint8Array)) throw new TypeError("Expected byte chunks");
49
- yield bytes;
50
- }
51
- signal.throwIfAborted();
52
- },
53
- diagnostic(error) {
54
- return error instanceof Error ? new CodecError(error.message) : error;
55
- }
56
- };
57
-
58
- // packages/office-package/src/compression.ts
59
- init_platform();
60
- function createCompressionCodec(runtime = defaultRuntime) {
61
- const { yieldTurn, readBytes, diagnostic } = runtime;
62
- class CodecReader {
63
- constructor(source, signal) {
64
- this.signal = signal;
65
- this.iterator = readBytes(source, signal);
66
- }
67
- signal;
68
- iterator;
69
- pending = new Uint8Array();
70
- pulls = 0;
71
- closing;
72
- async chunk() {
73
- this.signal.throwIfAborted();
74
- if (this.closing) return void 0;
75
- if (this.pending.length) {
76
- const bytes = this.pending;
77
- this.pending = new Uint8Array();
78
- return bytes;
79
- }
80
- for (; ; ) {
81
- if (++this.pulls % 64 === 0) await yieldTurn(this.signal);
82
- const next = await this.iterator.next();
83
- if (next.done) return void 0;
84
- if (next.value.length) return next.value;
85
- }
86
- }
87
- restore(bytes) {
88
- this.pending = bytes;
89
- }
90
- close() {
91
- this.pending = new Uint8Array();
92
- return this.closing ??= this.iterator.return(void 0).then(() => {
93
- });
94
- }
95
- }
96
- function codecError(status, message) {
97
- const error = new Error(message || "internal error");
98
- Object.assign(error, {
99
- code: status === Z_BUF_ERROR ? "Z_BUF_ERROR" : status === Z_DATA_ERROR ? "Z_DATA_ERROR" : "Z_STREAM_ERROR"
100
- });
101
- return diagnostic(error);
102
- }
103
- async function* codec(input, options, signal) {
104
- signal.throwIfAborted();
105
- const requestedSize = options.chunkSize ?? 64 * 1024;
106
- if (!Number.isSafeInteger(requestedSize) || requestedSize <= 0)
107
- throw new RangeError("invalid codec chunk size");
108
- const chunkSize = Math.min(requestedSize, 64 * 1024);
109
- let output = new Uint8Array(chunkSize);
110
- const encoding = options.mode === "gzip" || options.mode === "deflate-raw";
111
- const stream = new ZStream();
112
- const initialized = encoding ? deflateInit2(
113
- stream,
114
- options.level ?? 6,
115
- 8,
116
- options.mode === "deflate-raw" ? -15 : 31,
117
- 8,
118
- 0,
119
- true
120
- ) : inflateInit2(stream, options.mode === "inflate-raw" ? -15 : 31);
121
- if (initialized !== Z_OK) {
122
- if (encoding) deflateEnd(stream);
123
- else inflateEnd(stream);
124
- throw codecError(initialized, stream.msg);
125
- }
126
- let current = new Uint8Array();
127
- let offset = 0;
128
- let eof = false;
129
- let needsInput = true;
130
- let memberEnded = false;
131
- let calls = 0;
132
- let work = 0;
133
- let filled = 0;
134
- try {
135
- if (options.mode === "gunzip") options.onMember?.();
136
- for (; ; ) {
137
- signal.throwIfAborted();
138
- if (needsInput || memberEnded) {
139
- if (offset === current.length && !eof) {
140
- let ready = false;
141
- const pending = input.chunk().then(
142
- (value) => {
143
- ready = true;
144
- return value;
145
- },
146
- (error) => {
147
- options.onFailure?.(error);
148
- throw error;
149
- }
150
- );
151
- if (filled) {
152
- const turn = new AbortController();
153
- try {
154
- await Promise.race([pending, yieldTurn(AbortSignal.any([signal, turn.signal]))]);
155
- } finally {
156
- turn.abort();
157
- }
158
- if (!ready) {
159
- yield output.subarray(0, filled);
160
- output = new Uint8Array(chunkSize);
161
- filled = 0;
162
- signal.throwIfAborted();
163
- }
164
- }
165
- current = await pending ?? new Uint8Array();
166
- offset = 0;
167
- eof = current.length === 0;
168
- }
169
- if (memberEnded) {
170
- if (eof) return;
171
- if (current[offset] === 0 && options.padding !== "members") {
172
- while (await input.chunk() !== void 0) await yieldTurn(signal);
173
- return;
174
- }
175
- while (current[offset] === 0) {
176
- signal.throwIfAborted();
177
- offset++;
178
- if (++work >= 64 * 1024) {
179
- await yieldTurn(signal);
180
- work = 0;
181
- }
182
- if (offset === current.length) {
183
- current = await input.chunk() ?? new Uint8Array();
184
- offset = 0;
185
- if (!current.length) return;
186
- }
187
- }
188
- options.onMember?.();
189
- const reset = inflateReset(stream);
190
- if (reset !== Z_OK) throw codecError(reset, stream.msg);
191
- memberEnded = false;
192
- }
193
- stream.input = current;
194
- stream.next_in = offset;
195
- stream.avail_in = Math.min(current.length - offset, 64 * 1024);
196
- }
197
- stream.output = output;
198
- stream.next_out = filled;
199
- stream.avail_out = chunkSize - filled;
200
- const before = stream.avail_in;
201
- const status = encoding ? deflate$1(stream, eof ? Z_FINISH : Z_NO_FLUSH) : inflate$1(stream, Z_NO_FLUSH);
202
- offset = stream.next_in;
203
- const consumed = before - stream.avail_in;
204
- const produced = stream.next_out - filled;
205
- filled = stream.next_out;
206
- if (status !== Z_OK && status !== Z_STREAM_END && status !== Z_BUF_ERROR)
207
- throw codecError(status, stream.msg);
208
- if (filled === chunkSize || status === Z_STREAM_END && filled) {
209
- yield output.subarray(0, filled);
210
- output = new Uint8Array(chunkSize);
211
- filled = 0;
212
- }
213
- signal.throwIfAborted();
214
- work += consumed + produced;
215
- if (++calls >= 64 || work >= 64 * 1024) {
216
- await yieldTurn(signal);
217
- calls = 0;
218
- work = 0;
219
- }
220
- if (status === Z_STREAM_END) {
221
- if (options.mode === "inflate-raw") {
222
- input.restore(current.subarray(offset));
223
- return;
224
- }
225
- if (encoding) return;
226
- memberEnded = true;
227
- }
228
- if (!consumed && !produced && status !== Z_STREAM_END) {
229
- if (eof) throw diagnostic(new CodecError("unexpected end of file"));
230
- if (stream.avail_in) throw codecError(status, stream.msg);
231
- }
232
- needsInput = stream.avail_in === 0 && stream.avail_out !== 0;
233
- }
234
- } catch (error) {
235
- options.onFailure?.(error);
236
- throw error;
237
- } finally {
238
- if (encoding) deflateEnd(stream);
239
- else inflateEnd(stream);
240
- stream.input = new Uint8Array();
241
- stream.output = new Uint8Array();
242
- }
243
- }
244
- return { codec, CodecReader, memberAdmission: true };
245
- }
246
-
247
- // packages/office-package/src/zip.ts
248
- init_platform();
249
- var defaults = {
250
- yieldTurn: defaultRuntime.yieldTurn,
251
- fail(message) {
252
- throw new CodecError(message);
253
- },
254
- compression: createCompressionCodec()
255
- };
256
- var encoder = new TextEncoder();
257
- var cp437 = "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xA2\xA3\xA5\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0";
258
- var crcTable = Uint32Array.from({ length: 256 }, (_, index) => {
259
- let value = index;
260
- for (let bit = 0; bit < 8; bit++) value = value >>> 1 ^ (value & 1 ? 3988292384 : 0);
261
- return value >>> 0;
262
- });
263
- function crc32(bytes, previous = 0) {
264
- let value = previous ^ 4294967295;
265
- for (const byte of bytes) value = value >>> 8 ^ crcTable[(value ^ byte) & 255];
266
- return (value ^ 4294967295) >>> 0;
267
- }
268
- function createZipCodec(runtime = defaults, profile = {}) {
269
- const { yieldTurn, fail } = runtime;
270
- const { codec, CodecReader } = runtime.compression;
271
- const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
272
- function text(bytes) {
273
- try {
274
- return decoder.decode(bytes);
275
- } catch {
276
- return fail("invalid UTF-8 archive name or metadata");
277
- }
278
- }
279
- function number(value, maximum, label) {
280
- if (!Number.isSafeInteger(value) || value < 0 || value > maximum)
281
- fail(`ZIP ${label} limit exceeded or invalid value`);
282
- }
283
- function admit(limits, signal) {
284
- signal.throwIfAborted();
285
- for (const key of [
286
- "maxArchiveBytes",
287
- "maxEntryBytes",
288
- "maxTotalBytes",
289
- "maxMembers",
290
- "maxPathBytes",
291
- "maxDepth",
292
- "maxPaxBytes",
293
- "maxTextBytes",
294
- "chunkSize"
295
- ]) {
296
- if (key === "chunkSize" || limits[key] !== Infinity)
297
- number(limits[key], Number.MAX_SAFE_INTEGER, key);
298
- }
299
- if (limits.chunkSize < 512 || limits.chunkSize > 1024 * 1024)
300
- fail("ZIP chunk size must be between 512 and 1048576");
301
- return Math.min(limits.chunkSize, 64 * 1024);
302
- }
303
- function pathBytes(name, limits) {
304
- if (name.length > Math.min(limits.maxPathBytes, 65535)) fail("ZIP path byte limit exceeded");
305
- const bytes = encoder.encode(name);
306
- if (!name || text(bytes) !== name || name.includes("\0")) fail("ZIP invalid or unsafe path");
307
- number(bytes.length, Math.min(limits.maxPathBytes, 65535), "path byte");
308
- const parts = name.split("/");
309
- if (parts.at(-1) === "") parts.pop();
310
- if (parts.some((part) => !part || part === "." || part === ".."))
311
- fail("ZIP unsafe traversal or absolute path");
312
- number(parts.length, limits.maxDepth, "path depth");
313
- return bytes;
314
- }
315
- function equal(first, second) {
316
- return first.length === second.length && first.every((byte, index) => byte === second[index]);
317
- }
318
- function legacyName(bytes) {
319
- let name = "";
320
- for (const byte of bytes) name += byte < 128 ? String.fromCharCode(byte) : cp437[byte - 128];
321
- return name;
322
- }
323
- function extras(bytes, rawName, comment, central, limits, writing = false) {
324
- number(bytes.length, Math.min(limits.maxPaxBytes, 65535), "extra field");
325
- const result = {};
326
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
327
- const seen = /* @__PURE__ */ new Set();
328
- let offset = 0;
329
- while (offset < bytes.length) {
330
- if (offset + 4 > bytes.length) fail("ZIP truncated extra field");
331
- const identifier = view.getUint16(offset, true);
332
- const length = view.getUint16(offset + 2, true);
333
- offset += 4;
334
- if (offset + length > bytes.length) fail("ZIP truncated extra field payload");
335
- if (seen.has(identifier)) fail("ZIP duplicate extra field");
336
- seen.add(identifier);
337
- if (identifier === 1 && (!profile.zip64 || writing)) fail("ZIP64 is unsupported");
338
- if (identifier === 39169 || identifier === 23 || identifier === 24 || identifier === 25)
339
- fail("ZIP encryption is unsupported");
340
- if (identifier === 28789 || identifier === 25461) {
341
- if (length < 5 || bytes[offset] !== 1)
342
- fail("ZIP unsupported or truncated Unicode extra field");
343
- const original = identifier === 28789 ? rawName : comment;
344
- if (view.getUint32(offset + 1, true) !== crc32(original))
345
- fail("ZIP Unicode extra field CRC mismatch");
346
- const decoded = text(bytes.subarray(offset + 5, offset + length));
347
- if (identifier === 28789) {
348
- pathBytes(decoded, limits);
349
- result.name = decoded;
350
- } else number(length - 5, limits.maxTextBytes, "Unicode comment");
351
- }
352
- if (identifier === 21589) {
353
- if (!length) fail("ZIP truncated timestamp extra field");
354
- const flags = bytes[offset];
355
- if (flags & ~7) fail("ZIP unsupported timestamp flags");
356
- const count = (flags & 1) + (central ? 0 : (flags >>> 1 & 1) + (flags >>> 2 & 1));
357
- if (length !== 1 + count * 4) fail("ZIP truncated or inconsistent timestamp extra field");
358
- if (flags & 1) result.modified = view.getInt32(offset + 1, true) * 1e3;
359
- }
360
- offset += length;
361
- }
362
- return result;
363
- }
364
- function nameFrom(rawName, flags, metadata, limits) {
365
- number(rawName.length, Math.min(limits.maxPathBytes, 65535), "raw path byte");
366
- const raw = flags & 2048 ? text(rawName) : legacyName(rawName);
367
- pathBytes(raw, limits);
368
- if (flags & 2048 && metadata.name !== void 0 && metadata.name !== raw)
369
- fail("ZIP conflicting UTF-8 and Unicode extra names");
370
- return metadata.name ?? raw;
371
- }
372
- function format(method, flags, version) {
373
- number(flags, 65535, "general purpose flags");
374
- if (flags & (1 | 64 | 8192)) fail("ZIP encryption is unsupported");
375
- if (flags & ~2062 || method === 0 && flags & 6)
376
- fail("ZIP unsupported general purpose flags");
377
- if (method !== 0 && method !== 8) fail("ZIP unsupported compression method");
378
- if (version < (method === 8 || flags & 8 ? 20 : 10) || version > (profile.zip64 ? 45 : 20))
379
- fail("ZIP unsupported extraction version (including ZIP64)");
380
- }
381
- function dosModified(date, time) {
382
- if (!date && !time)
383
- return new Date(
384
- profile.utcDates === false ? new Date(1980, 0, 1).getTime() : Date.UTC(1980, 0, 1)
385
- );
386
- const year = 1980 + (date >>> 9);
387
- const month = (date >>> 5 & 15) - 1;
388
- const day = date & 31;
389
- const hours = time >>> 11;
390
- const minutes = time >>> 5 & 63;
391
- const seconds = (time & 31) * 2;
392
- const result = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
393
- if (result.getUTCFullYear() !== year || result.getUTCMonth() !== month || result.getUTCDate() !== day || hours > 23 || minutes > 59 || seconds > 59)
394
- fail("ZIP invalid DOS timestamp");
395
- return profile.utcDates === false ? new Date(year, month, day, hours, minutes, seconds) : result;
396
- }
397
- function wide(view, offset, maximum, label, structural = false) {
398
- if (offset < 0 || offset + 8 > view.byteLength) fail("ZIP truncated 64-bit field");
399
- const value = view.getBigUint64(offset, true);
400
- if (value > BigInt(Math.min(maximum, Number.MAX_SAFE_INTEGER))) {
401
- if (structural) fail(`ZIP invalid ${label}`);
402
- fail(`ZIP ${label} limit exceeded`);
403
- }
404
- return Number(value);
405
- }
406
- function extendedFields(bytes, fields) {
407
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
408
- const required = fields.filter((field) => field.value === field.sentinel);
409
- let found = false;
410
- let retained = bytes;
411
- const values = fields.map((field) => field.value);
412
- for (let offset = 0; offset < bytes.length; ) {
413
- if (offset + 4 > bytes.length) fail("ZIP truncated extra field");
414
- const length = view.getUint16(offset + 2, true);
415
- const next = offset + 4 + length;
416
- if (next > bytes.length) fail("ZIP truncated extra field payload");
417
- if (view.getUint16(offset, true) === 1) {
418
- if (!profile.zip64) fail("ZIP64 is unsupported");
419
- if (found || !required.length) fail("ZIP unexpected or duplicate ZIP64 extra field");
420
- found = true;
421
- const expected = required.reduce(
422
- (sum, field) => sum + (field.sentinel === 65535 ? 4 : 8),
423
- 0
424
- );
425
- if (length !== expected) fail("ZIP inconsistent ZIP64 extra field length");
426
- let position = offset + 4;
427
- for (const [index, field] of fields.entries()) {
428
- if (field.value !== field.sentinel) continue;
429
- values[index] = field.sentinel === 65535 ? view.getUint32(position, true) : wide(view, position, field.maximum, field.label, field.structural);
430
- number(values[index], field.maximum, field.label);
431
- position += field.sentinel === 65535 ? 4 : 8;
432
- }
433
- retained = new Uint8Array(bytes.length - length - 4);
434
- retained.set(bytes.subarray(0, offset));
435
- retained.set(bytes.subarray(next), offset);
436
- }
437
- offset = next;
438
- }
439
- if (required.length && !found) fail("ZIP missing ZIP64 extra field");
440
- return { values, retained };
441
- }
442
- function entryBounds(entry, limits, dataLimit = limits.maxArchiveBytes, writing = false) {
443
- pathBytes(entry.name, limits);
444
- const maximum = writing || !profile.zip64 ? 4294967294 : Number.MAX_SAFE_INTEGER;
445
- number(entry.size, Math.min(limits.maxEntryBytes, limits.maxTotalBytes, maximum), "entry byte");
446
- number(entry.data.length, Math.min(dataLimit, maximum), "compressed byte");
447
- number(entry.crc32, 4294967295, "CRC32");
448
- number(entry.mode, 65535, "mode");
449
- format(
450
- entry.method,
451
- entry.flags ?? 2048,
452
- entry.method === 8 || (entry.flags ?? 0) & 8 ? 20 : 10
453
- );
454
- if (entry.directory !== entry.name.endsWith("/") || entry.directory && (entry.symlink || entry.size !== 0))
455
- fail("ZIP inconsistent directory metadata");
456
- const type = entry.mode & 61440;
457
- if (type !== 0 && type !== (entry.directory ? 16384 : entry.symlink ? 40960 : 32768))
458
- fail("ZIP unsupported or conflicting file type");
459
- if (!Number.isFinite(entry.modified.getTime())) fail("ZIP invalid modification time");
460
- }
461
- async function copyBytes(source, destination, start, chunkSize, signal) {
462
- for (let offset = 0; offset < source.length; offset += chunkSize) {
463
- signal.throwIfAborted();
464
- destination.set(source.subarray(offset, offset + chunkSize), start + offset);
465
- if (offset + chunkSize < source.length) await yieldTurn(signal);
466
- }
467
- }
468
- async function readZipArchive(bytes, limits, signal) {
469
- const chunkSize = admit(limits, signal);
470
- number(bytes.length, Math.min(limits.maxArchiveBytes, 4294967294), "archive byte");
471
- bytes = new Uint8Array(bytes);
472
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
473
- let end = -1;
474
- const lower = Math.max(0, bytes.length - 22 - 65535);
475
- for (let offset2 = bytes.length - 22; offset2 >= lower; offset2--) {
476
- if ((bytes.length - offset2) % 4096 === 0) await yieldTurn(signal);
477
- if (view.getUint32(offset2, true) === 101010256 && offset2 + 22 + view.getUint16(offset2 + 20, true) === bytes.length) {
478
- const size = view.getUint32(offset2 + 12, true);
479
- const start = view.getUint32(offset2 + 16, true);
480
- const zip64 = size === 4294967295 || start === 4294967295 || view.getUint16(offset2 + 10, true) === 65535 || offset2 >= 20 && view.getUint32(offset2 - 20, true) === 117853008;
481
- if (!zip64 && start + size !== offset2) continue;
482
- if (end !== -1) fail("ZIP ambiguous end records");
483
- end = offset2;
484
- }
485
- }
486
- if (end === -1) fail("ZIP truncated or missing end of central directory");
487
- let members = view.getUint16(end + 10, true);
488
- let centralSize = view.getUint32(end + 12, true);
489
- let centralStart = view.getUint32(end + 16, true);
490
- let centralEnd = end;
491
- const locator = end - 20;
492
- const hasLocator = locator >= 0 && view.getUint32(locator, true) === 117853008;
493
- const diskMembers = view.getUint16(end + 8, true);
494
- if (view.getUint16(end + 4, true) || view.getUint16(end + 6, true) || !hasLocator && diskMembers !== members)
495
- fail("ZIP multi-disk or inconsistent member count is unsupported");
496
- if (members === 65535 || centralSize === 4294967295 || centralStart === 4294967295 || hasLocator) {
497
- if (!profile.zip64) fail("ZIP64 is unsupported");
498
- if (!hasLocator || view.getUint32(locator + 4, true) || view.getUint32(locator + 16, true) !== 1)
499
- fail("ZIP invalid or multi-disk ZIP64 locator");
500
- const record = wide(view, locator + 8, bytes.length, "ZIP64 offset", true);
501
- if (record + 56 > locator || view.getUint32(record, true) !== 101075792)
502
- fail("ZIP truncated ZIP64 end record");
503
- const recordSize = wide(view, record + 4, bytes.length, "ZIP64 record", true);
504
- if (recordSize < 44 || record + 12 + recordSize !== locator)
505
- fail("ZIP inconsistent ZIP64 end span");
506
- if (view.getUint16(record + 14, true) !== 45 || view.getUint32(record + 16, true) || view.getUint32(record + 20, true))
507
- fail("ZIP unsupported ZIP64 version or multi-disk record");
508
- const count = wide(view, record + 32, limits.maxMembers, "member");
509
- if (wide(view, record + 24, limits.maxMembers, "member") !== count)
510
- fail("ZIP inconsistent ZIP64 member counts");
511
- const size = wide(view, record + 40, bytes.length, "central byte", true);
512
- const start = wide(view, record + 48, bytes.length, "central offset", true);
513
- if (diskMembers !== 65535 && diskMembers !== count || members !== 65535 && members !== count || centralSize !== 4294967295 && centralSize !== size || centralStart !== 4294967295 && centralStart !== start)
514
- fail("ZIP classic/ZIP64 end disagreement");
515
- members = count;
516
- centralSize = size;
517
- centralStart = start;
518
- centralEnd = record;
519
- }
520
- if (centralStart + centralSize !== centralEnd)
521
- fail("ZIP invalid central directory span or unsupported ZIP64/trailing records");
522
- number(members, limits.maxMembers, "member");
523
- number(bytes.length - end - 22, limits.maxTextBytes, "archive comment");
524
- const entries = [];
525
- const spans = [];
526
- const names = /* @__PURE__ */ new Set();
527
- let offset = centralStart;
528
- let total = 0;
529
- for (let index = 0; index < members; index++) {
530
- await yieldTurn(signal);
531
- if (offset + 46 > centralEnd || view.getUint32(offset, true) !== 33639248)
532
- fail("ZIP truncated or invalid central header");
533
- const versionMadeBy = view.getUint16(offset + 4, true);
534
- const version = view.getUint16(offset + 6, true);
535
- const flags = view.getUint16(offset + 8, true);
536
- const method = view.getUint16(offset + 10, true);
537
- format(method, flags, version);
538
- const dosTime = view.getUint16(offset + 12, true);
539
- const dosDate = view.getUint16(offset + 14, true);
540
- const checksum = view.getUint32(offset + 16, true);
541
- let compressedSize = view.getUint32(offset + 20, true);
542
- let size = view.getUint32(offset + 24, true);
543
- const extendedSize = compressedSize === 4294967295 || size === 4294967295;
544
- const nameLength = view.getUint16(offset + 28, true);
545
- const extraLength = view.getUint16(offset + 30, true);
546
- const commentLength = view.getUint16(offset + 32, true);
547
- const internalAttributes = view.getUint16(offset + 36, true);
548
- if (internalAttributes & ~1) fail("ZIP unsupported internal attributes");
549
- const externalAttributes = view.getUint32(offset + 38, true);
550
- let local = view.getUint32(offset + 42, true);
551
- const next = offset + 46 + nameLength + extraLength + commentLength;
552
- if (next > centralEnd) fail("ZIP truncated central metadata");
553
- number(commentLength, limits.maxTextBytes, "entry comment");
554
- const rawName = bytes.subarray(offset + 46, offset + 46 + nameLength);
555
- let centralExtra = bytes.subarray(offset + 46 + nameLength, next - commentLength);
556
- const comment = bytes.subarray(next - commentLength, next);
557
- if (flags & 2048) text(comment);
558
- const centralMetadata = extras(centralExtra, rawName, comment, true, limits);
559
- const centralWide = extendedFields(centralExtra, [
560
- { value: size, sentinel: 4294967295, maximum: limits.maxEntryBytes, label: "entry byte" },
561
- {
562
- value: compressedSize,
563
- sentinel: 4294967295,
564
- maximum: limits.maxArchiveBytes,
565
- label: "compressed byte"
566
- },
567
- {
568
- value: local,
569
- sentinel: 4294967295,
570
- maximum: centralStart,
571
- label: "local offset",
572
- structural: true
573
- },
574
- {
575
- value: view.getUint16(offset + 34, true),
576
- sentinel: 65535,
577
- maximum: 4294967295,
578
- label: "disk"
579
- }
580
- ]);
581
- if (centralWide.retained.length !== centralExtra.length && version < 45)
582
- fail("ZIP64 requires extraction version 45");
583
- [size, compressedSize, local] = centralWide.values;
584
- if (centralWide.values[3]) fail("ZIP multi-disk member is unsupported");
585
- centralExtra = centralWide.retained;
586
- number(size, limits.maxEntryBytes, "entry byte");
587
- if (method === 0 && compressedSize !== size) fail("ZIP stored size mismatch");
588
- total += size;
589
- number(total, limits.maxTotalBytes, "total byte");
590
- const name = nameFrom(rawName, flags, centralMetadata, limits);
591
- if (profile.rejectDuplicateNames && names.has(name)) fail("ZIP duplicate member name");
592
- names.add(name);
593
- if (local + 30 > centralStart || view.getUint32(local, true) !== 67324752)
594
- fail("ZIP invalid local header span");
595
- if (view.getUint16(local + 4, true) !== version || view.getUint16(local + 6, true) !== flags || view.getUint16(local + 8, true) !== method || view.getUint16(local + 10, true) !== dosTime || view.getUint16(local + 12, true) !== dosDate)
596
- fail("ZIP central/local metadata mismatch");
597
- const localNameLength = view.getUint16(local + 26, true);
598
- const localExtraLength = view.getUint16(local + 28, true);
599
- const payloadStart = local + 30 + localNameLength + localExtraLength;
600
- let payloadEnd = payloadStart + compressedSize;
601
- if (payloadEnd > centralStart) fail("ZIP truncated or overlapping local payload");
602
- const localName = bytes.subarray(local + 30, local + 30 + localNameLength);
603
- if (!equal(rawName, localName)) fail("ZIP central/local filename mismatch");
604
- let localExtra = bytes.subarray(local + 30 + localNameLength, payloadStart);
605
- const localMetadata = extras(localExtra, localName, comment, false, limits);
606
- const localWide = extendedFields(localExtra, [
607
- {
608
- value: view.getUint32(local + 22, true),
609
- sentinel: 4294967295,
610
- maximum: limits.maxEntryBytes,
611
- label: "entry byte"
612
- },
613
- {
614
- value: view.getUint32(local + 18, true),
615
- sentinel: 4294967295,
616
- maximum: limits.maxArchiveBytes,
617
- label: "compressed byte"
618
- }
619
- ]);
620
- if (localWide.retained.length !== localExtra.length && version < 45)
621
- fail("ZIP64 requires extraction version 45");
622
- localExtra = localWide.retained;
623
- const localEffective = nameFrom(localName, flags, localMetadata, limits);
624
- if (localMetadata.name !== void 0 && localEffective !== name)
625
- fail("ZIP central/local Unicode name mismatch");
626
- if (centralMetadata.modified !== void 0 && localMetadata.modified !== void 0 && centralMetadata.modified !== localMetadata.modified)
627
- fail("ZIP central/local timestamp mismatch");
628
- for (const [position, expected] of [
629
- [14, checksum],
630
- [18, compressedSize],
631
- [22, size]
632
- ]) {
633
- const actual = position === 22 ? localWide.values[0] : position === 18 ? localWide.values[1] : view.getUint32(local + position, true);
634
- if (actual !== expected && (!(flags & 8) || actual !== 0))
635
- fail("ZIP central/local size or CRC mismatch");
636
- }
637
- if (flags & 8) {
638
- const matches = [];
639
- const descriptor64 = extendedSize || view.getUint32(local + 18, true) === 4294967295 || view.getUint32(local + 22, true) === 4294967295;
640
- for (const signed of [false, true]) {
641
- const descriptor = payloadEnd + (signed ? 4 : 0);
642
- const width = descriptor64 ? 20 : 12;
643
- if (descriptor + width <= centralStart && (!signed || view.getUint32(payloadEnd, true) === 134695760) && view.getUint32(descriptor, true) === checksum) {
644
- const actualCompressed = descriptor64 ? view.getBigUint64(descriptor + 4, true) : BigInt(view.getUint32(descriptor + 4, true));
645
- const actualSize = descriptor64 ? view.getBigUint64(descriptor + 12, true) : BigInt(view.getUint32(descriptor + 8, true));
646
- if (actualCompressed === BigInt(compressedSize) && actualSize === BigInt(size))
647
- matches.push(descriptor + width);
648
- }
649
- }
650
- if (matches.length !== 1) fail("ZIP truncated, ambiguous or mismatched data descriptor");
651
- payloadEnd = matches[0];
652
- }
653
- const host = versionMadeBy >>> 8;
654
- const unixMode = host === 3 || host === 19 ? externalAttributes >>> 16 : 0;
655
- const directory = name.endsWith("/");
656
- if (Boolean(externalAttributes & 16) && !directory)
657
- fail("ZIP conflicting directory attributes");
658
- const mode = unixMode || (directory ? 16877 : 33188);
659
- const symlink = (mode & 61440) === 40960;
660
- const modified = dosModified(dosDate, dosTime);
661
- const timestamp = centralMetadata.modified ?? localMetadata.modified;
662
- if (timestamp !== void 0) modified.setTime(timestamp);
663
- const entry = {
664
- name,
665
- data: bytes.subarray(payloadStart, payloadStart + compressedSize),
666
- size,
667
- method,
668
- crc32: checksum,
669
- modified,
670
- mode,
671
- directory,
672
- symlink,
673
- rawName,
674
- localName,
675
- comment,
676
- localExtra,
677
- centralExtra,
678
- centralHeaderBytes: next - offset,
679
- flags,
680
- versionMadeBy,
681
- internalAttributes,
682
- externalAttributes,
683
- dosTime,
684
- dosDate
685
- };
686
- entryBounds(entry, limits);
687
- entries.push(entry);
688
- spans.push({ start: local, end: payloadEnd });
689
- offset = next;
690
- }
691
- if (offset !== centralEnd) fail("ZIP central directory size or member count mismatch");
692
- spans.sort((first, second) => first.start - second.start);
693
- let covered = 0;
694
- for (const span of spans) {
695
- if (span.start !== covered)
696
- fail("ZIP overlapping spans, gaps or self-extracting prefix are unsupported");
697
- covered = span.end;
698
- }
699
- if (covered !== centralStart) fail("ZIP unreferenced local data is unsupported");
700
- for (const entry of entries) {
701
- const data = new Uint8Array(entry.data.length);
702
- await copyBytes(entry.data, data, 0, chunkSize, signal);
703
- entry.data = data;
704
- entry.rawName = new Uint8Array(entry.rawName);
705
- entry.localName = new Uint8Array(entry.localName);
706
- entry.comment = new Uint8Array(entry.comment);
707
- entry.localExtra = new Uint8Array(entry.localExtra);
708
- entry.centralExtra = new Uint8Array(entry.centralExtra);
709
- await yieldTurn(signal);
710
- }
711
- return { entries, comment: new Uint8Array(bytes.subarray(end + 22)) };
712
- }
713
- async function* decodeZipEntry(entry, limits, signal) {
714
- const chunkSize = admit(limits, signal);
715
- entryBounds(entry, limits);
716
- const reader = new CodecReader(
717
- (async function* () {
718
- yield entry.data;
719
- })(),
720
- signal
721
- );
722
- let length = 0;
723
- let checksum = 0;
724
- const source = entry.method === 8 ? codec(reader, { mode: "inflate-raw", chunkSize }, signal) : (async function* () {
725
- for (let offset = 0; offset < entry.data.length; offset += chunkSize) {
726
- yield new Uint8Array(entry.data.subarray(offset, offset + chunkSize));
727
- await yieldTurn(signal);
728
- }
729
- })();
730
- try {
731
- for await (const chunk of source) {
732
- signal.throwIfAborted();
733
- length += chunk.length;
734
- number(length, Math.min(limits.maxEntryBytes, limits.maxTotalBytes), "decoded byte");
735
- checksum = crc32(chunk, checksum);
736
- yield chunk;
737
- }
738
- if (entry.method === 8 && await reader.chunk() !== void 0)
739
- fail("ZIP trailing compressed data");
740
- if (length !== entry.size) fail("ZIP uncompressed size mismatch");
741
- if (checksum !== entry.crc32) fail("ZIP CRC32 mismatch");
742
- } finally {
743
- await reader.close();
744
- }
745
- }
746
- async function makeZipEntry(name, bytes, attributes, limits, signal) {
747
- const chunkSize = admit(limits, signal);
748
- const { compression = "auto", ...metadata } = attributes;
749
- if (!["auto", "store", "deflate"].includes(compression))
750
- fail("ZIP unsupported compression choice");
751
- const entry = {
752
- name,
753
- data: bytes,
754
- size: bytes.length,
755
- method: 0,
756
- crc32: 0,
757
- ...metadata,
758
- modified: new Date(attributes.modified.getTime())
759
- };
760
- entryBounds(
761
- entry,
762
- limits,
763
- compression === "deflate" ? limits.maxEntryBytes : limits.maxArchiveBytes,
764
- true
765
- );
766
- bytes = new Uint8Array(bytes);
767
- entry.data = bytes;
768
- for (let offset = 0; offset < bytes.length; offset += chunkSize) {
769
- entry.crc32 = crc32(bytes.subarray(offset, offset + chunkSize), entry.crc32);
770
- await yieldTurn(signal);
771
- }
772
- const reader = new CodecReader(
773
- (async function* () {
774
- yield bytes;
775
- })(),
776
- signal
777
- );
778
- try {
779
- if (compression === "deflate" || compression === "auto" && bytes.length && !entry.directory && !entry.symlink) {
780
- const chunks = [];
781
- let length = 0;
782
- for await (const chunk of codec(reader, { mode: "deflate-raw", chunkSize }, signal)) {
783
- length += chunk.length;
784
- if (compression === "auto" && length >= bytes.length) break;
785
- number(length, Math.min(limits.maxArchiveBytes, 4294967294), "compressed byte");
786
- chunks.push(new Uint8Array(chunk));
787
- }
788
- if (compression === "deflate" || length < bytes.length) {
789
- entry.data = new Uint8Array(length);
790
- let offset = 0;
791
- for (const chunk of chunks) {
792
- entry.data.set(chunk, offset);
793
- offset += chunk.length;
794
- await yieldTurn(signal);
795
- }
796
- entry.method = 8;
797
- signal.throwIfAborted();
798
- return entry;
799
- }
800
- }
801
- signal.throwIfAborted();
802
- return entry;
803
- } finally {
804
- await reader.close();
805
- signal.throwIfAborted();
806
- }
807
- }
808
- function timestampExtra(modified) {
809
- const seconds = Math.floor(modified.getTime() / 1e3);
810
- if (seconds < -2147483648 || seconds > 2147483647) return new Uint8Array();
811
- const bytes = new Uint8Array(9);
812
- const view = new DataView(bytes.buffer);
813
- view.setUint16(0, 21589, true);
814
- view.setUint16(2, 5, true);
815
- bytes[4] = 1;
816
- view.setInt32(5, seconds, true);
817
- return bytes;
818
- }
819
- async function writeZipArchive(archive, limits, signal) {
820
- const chunkSize = admit(limits, signal);
821
- number(archive.entries.length, Math.min(limits.maxMembers, 65534), "member");
822
- number(archive.comment.length, Math.min(limits.maxTextBytes, 65535), "archive comment");
823
- if (profile.validatePayloads) {
824
- let serialized = 22 + archive.comment.length;
825
- let decoded = 0;
826
- const prepared = archive.entries.map((entry) => {
827
- entryBounds(entry, limits, limits.maxArchiveBytes, true);
828
- decoded += entry.size;
829
- number(decoded, limits.maxTotalBytes, "total byte");
830
- const rawName = entry.rawName ?? pathBytes(entry.name, limits);
831
- number(rawName.length, Math.min(limits.maxPathBytes, 65535), "raw path byte");
832
- if (entry.localName && !equal(rawName, entry.localName))
833
- fail("ZIP retained filename metadata mismatch");
834
- const localExtra = entry.localExtra ?? timestampExtra(entry.modified);
835
- const centralExtra = entry.centralExtra ?? timestampExtra(entry.modified);
836
- const comment = entry.comment ?? new Uint8Array();
837
- number(localExtra.length, Math.min(limits.maxPaxBytes, 65535), "extra field");
838
- number(centralExtra.length, Math.min(limits.maxPaxBytes, 65535), "extra field");
839
- number(comment.length, Math.min(limits.maxTextBytes, 65535), "entry comment");
840
- serialized += 76 + 2 * rawName.length + localExtra.length + centralExtra.length + comment.length + entry.data.length;
841
- number(serialized, Math.min(limits.maxArchiveBytes, 4294967294), "archive byte");
842
- return { ...entry, rawName, localExtra, centralExtra, comment };
843
- });
844
- number(serialized, Math.min(limits.maxArchiveBytes, 4294967294), "archive byte");
845
- archive = {
846
- comment: new Uint8Array(archive.comment),
847
- entries: prepared.map((entry) => ({
848
- ...entry,
849
- modified: new Date(entry.modified.getTime()),
850
- data: new Uint8Array(entry.data),
851
- rawName: new Uint8Array(entry.rawName),
852
- localName: new Uint8Array(entry.localName ?? entry.rawName),
853
- localExtra: new Uint8Array(entry.localExtra),
854
- centralExtra: new Uint8Array(entry.centralExtra),
855
- comment: new Uint8Array(entry.comment)
856
- }))
857
- };
858
- }
859
- let length = 22 + archive.comment.length;
860
- let localLength = 0;
861
- let total = 0;
862
- const encoded = [];
863
- const names = /* @__PURE__ */ new Set();
864
- for (const entry of archive.entries) {
865
- await yieldTurn(signal);
866
- entryBounds(entry, limits, limits.maxArchiveBytes, true);
867
- if (profile.rejectDuplicateNames && names.has(entry.name)) fail("ZIP duplicate member name");
868
- names.add(entry.name);
869
- if (entry.method === 0 && entry.data.length !== entry.size) fail("ZIP stored size mismatch");
870
- total += entry.size;
871
- number(total, limits.maxTotalBytes, "total byte");
872
- const rawName = entry.rawName ?? pathBytes(entry.name, limits);
873
- const flags = (entry.flags ?? 2048) & ~8;
874
- const comment = entry.comment ?? new Uint8Array();
875
- number(comment.length, Math.min(limits.maxTextBytes, 65535), "entry comment");
876
- if (flags & 2048) text(comment);
877
- const localExtra = entry.localExtra ?? timestampExtra(entry.modified);
878
- const centralExtra = entry.centralExtra ?? timestampExtra(entry.modified);
879
- const localMetadata = extras(
880
- localExtra,
881
- rawName,
882
- comment,
883
- false,
884
- limits,
885
- profile.validatePayloads
886
- );
887
- const centralMetadata = extras(
888
- centralExtra,
889
- rawName,
890
- comment,
891
- true,
892
- limits,
893
- profile.validatePayloads
894
- );
895
- if (nameFrom(rawName, flags, centralMetadata, limits) !== entry.name || localMetadata.name !== void 0 && nameFrom(rawName, flags, localMetadata, limits) !== entry.name || entry.localName && !equal(rawName, entry.localName))
896
- fail("ZIP retained filename metadata mismatch");
897
- if (localMetadata.modified !== void 0 && centralMetadata.modified !== void 0 && localMetadata.modified !== centralMetadata.modified)
898
- fail("ZIP retained timestamp metadata mismatch");
899
- const rounded = new Date(Math.ceil(Math.floor(entry.modified.getTime() / 1e3) / 2) * 2e3);
900
- const utc = profile.utcDates !== false;
901
- const year = Math.max(
902
- 1980,
903
- Math.min(2107, utc ? rounded.getUTCFullYear() : rounded.getFullYear())
904
- );
905
- const date = entry.dosDate ?? year - 1980 << 9 | (utc ? rounded.getUTCMonth() : rounded.getMonth()) + 1 << 5 | (utc ? rounded.getUTCDate() : rounded.getDate());
906
- const time = entry.dosTime ?? (utc ? rounded.getUTCHours() : rounded.getHours()) << 11 | (utc ? rounded.getUTCMinutes() : rounded.getMinutes()) << 5 | (utc ? rounded.getUTCSeconds() : rounded.getSeconds()) >>> 1;
907
- number(date, 65535, "DOS date");
908
- number(time, 65535, "DOS time");
909
- const dosTimestamp = dosModified(date, time).getTime();
910
- const extendedTimestamp = centralMetadata.modified ?? localMetadata.modified;
911
- if (extendedTimestamp === void 0 ? dosTimestamp !== rounded.getTime() : Math.floor(extendedTimestamp / 1e3) !== Math.floor(entry.modified.getTime() / 1e3))
912
- fail("ZIP retained or unrepresentable timestamp metadata mismatch");
913
- for (const [value, maximum, label] of [
914
- [entry.versionMadeBy ?? 798, 65535, "creator version"],
915
- [entry.internalAttributes ?? 0, 65535, "internal attributes"],
916
- [entry.externalAttributes ?? 0, 4294967295, "external attributes"]
917
- ])
918
- number(value, maximum, label);
919
- if ((entry.internalAttributes ?? 0) & ~1) fail("ZIP unsupported internal attributes");
920
- if (entry.externalAttributes !== void 0) {
921
- const host = (entry.versionMadeBy ?? 798) >>> 8;
922
- const unixMode = host === 3 || host === 19 ? entry.externalAttributes >>> 16 : 0;
923
- const mode = unixMode || (entry.directory ? 16877 : 33188);
924
- if (mode !== entry.mode || Boolean(entry.externalAttributes & 16) && !entry.directory)
925
- fail("ZIP retained file attributes mismatch");
926
- }
927
- encoded.push({
928
- entry,
929
- rawName,
930
- flags,
931
- localExtra,
932
- centralExtra,
933
- comment,
934
- date,
935
- time,
936
- offset: localLength
937
- });
938
- localLength += 30 + rawName.length + localExtra.length + entry.data.length;
939
- length += 76 + 2 * rawName.length + localExtra.length + centralExtra.length + comment.length + entry.data.length;
940
- number(length, Math.min(limits.maxArchiveBytes, 4294967294), "archive byte");
941
- }
942
- number(length, Math.min(limits.maxArchiveBytes, 4294967294), "archive byte");
943
- const bytes = new Uint8Array(length);
944
- const view = new DataView(bytes.buffer);
945
- let central = localLength;
946
- for (const item of encoded) {
947
- await yieldTurn(signal);
948
- const { entry, rawName, flags, localExtra, centralExtra, comment, date, time, offset } = item;
949
- const version = entry.method === 8 ? 20 : 10;
950
- view.setUint32(offset, 67324752, true);
951
- view.setUint16(offset + 4, version, true);
952
- view.setUint16(offset + 6, flags, true);
953
- view.setUint16(offset + 8, entry.method, true);
954
- view.setUint16(offset + 10, time, true);
955
- view.setUint16(offset + 12, date, true);
956
- view.setUint32(offset + 14, entry.crc32, true);
957
- view.setUint32(offset + 18, entry.data.length, true);
958
- view.setUint32(offset + 22, entry.size, true);
959
- view.setUint16(offset + 26, rawName.length, true);
960
- view.setUint16(offset + 28, localExtra.length, true);
961
- bytes.set(rawName, offset + 30);
962
- bytes.set(localExtra, offset + 30 + rawName.length);
963
- await copyBytes(
964
- entry.data,
965
- bytes,
966
- offset + 30 + rawName.length + localExtra.length,
967
- chunkSize,
968
- signal
969
- );
970
- if (profile.validatePayloads) {
971
- const stored = {
972
- ...entry,
973
- data: bytes.subarray(
974
- offset + 30 + rawName.length + localExtra.length,
975
- offset + 30 + rawName.length + localExtra.length + entry.data.length
976
- )
977
- };
978
- for await (const chunk of decodeZipEntry(stored, limits, signal)) {
979
- signal.throwIfAborted();
980
- void chunk;
981
- }
982
- }
983
- view.setUint32(central, 33639248, true);
984
- view.setUint16(central + 4, entry.versionMadeBy ?? 798, true);
985
- view.setUint16(central + 6, version, true);
986
- view.setUint16(central + 8, flags, true);
987
- view.setUint16(central + 10, entry.method, true);
988
- view.setUint16(central + 12, time, true);
989
- view.setUint16(central + 14, date, true);
990
- view.setUint32(central + 16, entry.crc32, true);
991
- view.setUint32(central + 20, entry.data.length, true);
992
- view.setUint32(central + 24, entry.size, true);
993
- view.setUint16(central + 28, rawName.length, true);
994
- view.setUint16(central + 30, centralExtra.length, true);
995
- view.setUint16(central + 32, comment.length, true);
996
- view.setUint16(central + 36, entry.internalAttributes ?? 0, true);
997
- view.setUint32(
998
- central + 38,
999
- entry.externalAttributes ?? (entry.mode | (entry.directory ? 16384 : entry.symlink ? 40960 : 32768)) * 65536 + (entry.directory ? 16 : 0),
1000
- true
1001
- );
1002
- view.setUint32(central + 42, offset, true);
1003
- bytes.set(rawName, central + 46);
1004
- bytes.set(centralExtra, central + 46 + rawName.length);
1005
- bytes.set(comment, central + 46 + rawName.length + centralExtra.length);
1006
- central += 46 + rawName.length + centralExtra.length + comment.length;
1007
- }
1008
- view.setUint32(central, 101010256, true);
1009
- view.setUint16(central + 8, encoded.length, true);
1010
- view.setUint16(central + 10, encoded.length, true);
1011
- view.setUint32(central + 12, central - localLength, true);
1012
- view.setUint32(central + 16, localLength, true);
1013
- view.setUint16(central + 20, archive.comment.length, true);
1014
- bytes.set(archive.comment, central + 22);
1015
- signal.throwIfAborted();
1016
- return bytes;
1017
- }
1018
- return { readZipArchive, decodeZipEntry, makeZipEntry, writeZipArchive };
1019
- }
1020
-
1021
- // packages/office-package/src/index.ts
1022
- init_platform();
1023
-
1024
- export {
1025
- CodecError,
1026
- yieldEventLoop,
1027
- createCompressionCodec,
1028
- crc32,
1029
- createZipCodec
1030
- };
1031
- //# sourceMappingURL=chunk-EMAJ7WUW.js.map