@loaders.gl/archives 0.0.0-stage → 5.0.0-alpha.14

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 (168) hide show
  1. package/LICENSE +52 -0
  2. package/README.md +4 -2
  3. package/dist/dist.dev.js +5101 -0
  4. package/dist/dist.min.js +9 -0
  5. package/dist/index.cjs +2982 -0
  6. package/dist/index.cjs.map +6 -0
  7. package/dist/index.d.ts +11 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +11 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/tar/index.cjs +576 -0
  12. package/dist/tar/index.cjs.map +6 -0
  13. package/dist/tar/index.d.ts +8 -0
  14. package/dist/tar/index.d.ts.map +1 -0
  15. package/dist/tar/index.js +9 -0
  16. package/dist/tar/index.js.map +1 -0
  17. package/dist/tar/lib/header.d.ts +9 -0
  18. package/dist/tar/lib/header.d.ts.map +1 -0
  19. package/dist/tar/lib/header.js +76 -0
  20. package/dist/tar/lib/header.js.map +1 -0
  21. package/dist/tar/lib/tar.d.ts +29 -0
  22. package/dist/tar/lib/tar.d.ts.map +1 -0
  23. package/dist/tar/lib/tar.js +136 -0
  24. package/dist/tar/lib/tar.js.map +1 -0
  25. package/dist/tar/lib/types.d.ts +48 -0
  26. package/dist/tar/lib/types.d.ts.map +1 -0
  27. package/dist/tar/lib/types.js +5 -0
  28. package/dist/tar/lib/types.js.map +1 -0
  29. package/dist/tar/lib/utils.d.ts +23 -0
  30. package/dist/tar/lib/utils.d.ts.map +1 -0
  31. package/dist/tar/lib/utils.js +52 -0
  32. package/dist/tar/lib/utils.js.map +1 -0
  33. package/dist/tar/tar-archive.d.ts +4 -0
  34. package/dist/tar/tar-archive.d.ts.map +1 -0
  35. package/dist/tar/tar-archive.js +97 -0
  36. package/dist/tar/tar-archive.js.map +1 -0
  37. package/dist/tar/tar-builder.d.ts +28 -0
  38. package/dist/tar/tar-builder.d.ts.map +1 -0
  39. package/dist/tar/tar-builder.js +38 -0
  40. package/dist/tar/tar-builder.js.map +1 -0
  41. package/dist/tar/tar-format.d.ts +12 -0
  42. package/dist/tar/tar-format.d.ts.map +1 -0
  43. package/dist/tar/tar-format.js +15 -0
  44. package/dist/tar/tar-format.js.map +1 -0
  45. package/dist/tar/tar-loader-types.d.ts +15 -0
  46. package/dist/tar/tar-loader-types.d.ts.map +1 -0
  47. package/dist/tar/tar-loader-types.js +20 -0
  48. package/dist/tar/tar-loader-types.js.map +1 -0
  49. package/dist/tar/tar-loader.cjs +285 -0
  50. package/dist/tar/tar-loader.cjs.map +6 -0
  51. package/dist/tar/tar-loader.d.ts +3 -0
  52. package/dist/tar/tar-loader.d.ts.map +1 -0
  53. package/dist/tar/tar-loader.js +12 -0
  54. package/dist/tar/tar-loader.js.map +1 -0
  55. package/dist/tar/tar-writer.cjs +114 -0
  56. package/dist/tar/tar-writer.cjs.map +6 -0
  57. package/dist/tar/tar-writer.d.ts +20 -0
  58. package/dist/tar/tar-writer.d.ts.map +1 -0
  59. package/dist/tar/tar-writer.js +94 -0
  60. package/dist/tar/tar-writer.js.map +1 -0
  61. package/dist/zip/filesystems/IndexedArchive.d.ts +40 -0
  62. package/dist/zip/filesystems/IndexedArchive.d.ts.map +1 -0
  63. package/dist/zip/filesystems/IndexedArchive.js +99 -0
  64. package/dist/zip/filesystems/IndexedArchive.js.map +1 -0
  65. package/dist/zip/filesystems/zip-filesystem.d.ts +53 -0
  66. package/dist/zip/filesystems/zip-filesystem.d.ts.map +1 -0
  67. package/dist/zip/filesystems/zip-filesystem.js +231 -0
  68. package/dist/zip/filesystems/zip-filesystem.js.map +1 -0
  69. package/dist/zip/hash-file-utility.d.ts +20 -0
  70. package/dist/zip/hash-file-utility.d.ts.map +1 -0
  71. package/dist/zip/hash-file-utility.js +83 -0
  72. package/dist/zip/hash-file-utility.js.map +1 -0
  73. package/dist/zip/index.cjs +4614 -0
  74. package/dist/zip/index.cjs.map +6 -0
  75. package/dist/zip/index.d.ts +18 -0
  76. package/dist/zip/index.d.ts.map +1 -0
  77. package/dist/zip/index.js +14 -0
  78. package/dist/zip/index.js.map +1 -0
  79. package/dist/zip/indexed-zip-writer.cjs +1211 -0
  80. package/dist/zip/indexed-zip-writer.cjs.map +6 -0
  81. package/dist/zip/indexed-zip-writer.d.ts +46 -0
  82. package/dist/zip/indexed-zip-writer.d.ts.map +1 -0
  83. package/dist/zip/indexed-zip-writer.js +229 -0
  84. package/dist/zip/indexed-zip-writer.js.map +1 -0
  85. package/dist/zip/lib/zip-composition.d.ts +37 -0
  86. package/dist/zip/lib/zip-composition.d.ts.map +1 -0
  87. package/dist/zip/lib/zip-composition.js +157 -0
  88. package/dist/zip/lib/zip-composition.js.map +1 -0
  89. package/dist/zip/lib/zip-entry-metadata.d.ts +34 -0
  90. package/dist/zip/lib/zip-entry-metadata.d.ts.map +1 -0
  91. package/dist/zip/lib/zip-entry-metadata.js +132 -0
  92. package/dist/zip/lib/zip-entry-metadata.js.map +1 -0
  93. package/dist/zip/lib/zip-serialization.d.ts +36 -0
  94. package/dist/zip/lib/zip-serialization.d.ts.map +1 -0
  95. package/dist/zip/lib/zip-serialization.js +148 -0
  96. package/dist/zip/lib/zip-serialization.js.map +1 -0
  97. package/dist/zip/lib/zip64-extra-field.d.ts +20 -0
  98. package/dist/zip/lib/zip64-extra-field.d.ts.map +1 -0
  99. package/dist/zip/lib/zip64-extra-field.js +53 -0
  100. package/dist/zip/lib/zip64-extra-field.js.map +1 -0
  101. package/dist/zip/zip-archive-types.d.ts +56 -0
  102. package/dist/zip/zip-archive-types.d.ts.map +1 -0
  103. package/dist/zip/zip-archive-types.js +5 -0
  104. package/dist/zip/zip-archive-types.js.map +1 -0
  105. package/dist/zip/zip-archive.d.ts +101 -0
  106. package/dist/zip/zip-archive.d.ts.map +1 -0
  107. package/dist/zip/zip-archive.js +593 -0
  108. package/dist/zip/zip-archive.js.map +1 -0
  109. package/dist/zip/zip-encode-types.d.ts +41 -0
  110. package/dist/zip/zip-encode-types.d.ts.map +1 -0
  111. package/dist/zip/zip-encode-types.js +5 -0
  112. package/dist/zip/zip-encode-types.js.map +1 -0
  113. package/dist/zip/zip-encode.cjs +1154 -0
  114. package/dist/zip/zip-encode.cjs.map +6 -0
  115. package/dist/zip/zip-encode.d.ts +15 -0
  116. package/dist/zip/zip-encode.d.ts.map +1 -0
  117. package/dist/zip/zip-encode.js +312 -0
  118. package/dist/zip/zip-encode.js.map +1 -0
  119. package/dist/zip/zip-format.d.ts +14 -0
  120. package/dist/zip/zip-format.d.ts.map +1 -0
  121. package/dist/zip/zip-format.js +17 -0
  122. package/dist/zip/zip-format.js.map +1 -0
  123. package/dist/zip/zip-loader-types.d.ts +15 -0
  124. package/dist/zip/zip-loader-types.d.ts.map +1 -0
  125. package/dist/zip/zip-loader-types.js +20 -0
  126. package/dist/zip/zip-loader-types.js.map +1 -0
  127. package/dist/zip/zip-loader.cjs +2681 -0
  128. package/dist/zip/zip-loader.cjs.map +6 -0
  129. package/dist/zip/zip-loader.d.ts +3 -0
  130. package/dist/zip/zip-loader.d.ts.map +1 -0
  131. package/dist/zip/zip-loader.js +38 -0
  132. package/dist/zip/zip-loader.js.map +1 -0
  133. package/dist/zip/zip-writer.cjs +1208 -0
  134. package/dist/zip/zip-writer.cjs.map +6 -0
  135. package/dist/zip/zip-writer.d.ts +40 -0
  136. package/dist/zip/zip-writer.d.ts.map +1 -0
  137. package/dist/zip/zip-writer.js +48 -0
  138. package/dist/zip/zip-writer.js.map +1 -0
  139. package/package.json +88 -4
  140. package/src/index.ts +14 -0
  141. package/src/tar/index.ts +11 -0
  142. package/src/tar/lib/header.ts +82 -0
  143. package/src/tar/lib/tar.ts +160 -0
  144. package/src/tar/lib/types.ts +51 -0
  145. package/src/tar/lib/utils.ts +55 -0
  146. package/src/tar/tar-archive.ts +98 -0
  147. package/src/tar/tar-builder.ts +47 -0
  148. package/src/tar/tar-format.ts +17 -0
  149. package/src/tar/tar-loader-types.ts +36 -0
  150. package/src/tar/tar-loader.ts +17 -0
  151. package/src/tar/tar-writer.ts +102 -0
  152. package/src/zip/filesystems/IndexedArchive.ts +110 -0
  153. package/src/zip/filesystems/zip-filesystem.ts +244 -0
  154. package/src/zip/hash-file-utility.ts +109 -0
  155. package/src/zip/index.ts +38 -0
  156. package/src/zip/indexed-zip-writer.ts +345 -0
  157. package/src/zip/lib/zip-composition.ts +243 -0
  158. package/src/zip/lib/zip-entry-metadata.ts +157 -0
  159. package/src/zip/lib/zip-serialization.ts +206 -0
  160. package/src/zip/lib/zip64-extra-field.ts +84 -0
  161. package/src/zip/zip-archive-types.ts +64 -0
  162. package/src/zip/zip-archive.ts +733 -0
  163. package/src/zip/zip-encode-types.ts +53 -0
  164. package/src/zip/zip-encode.ts +370 -0
  165. package/src/zip/zip-format.ts +19 -0
  166. package/src/zip/zip-loader-types.ts +36 -0
  167. package/src/zip/zip-loader.ts +43 -0
  168. package/src/zip/zip-writer.ts +73 -0
@@ -0,0 +1,2681 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res, err) => function __init() {
9
+ if (err) throw err[0];
10
+ try {
11
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ } catch (e) {
13
+ throw err = [e], e;
14
+ }
15
+ };
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+
38
+ // src/zip/zip-format.ts
39
+ var ZipFormat2;
40
+ var init_zip_format = __esm({
41
+ "src/zip/zip-format.ts"() {
42
+ "use strict";
43
+ ZipFormat2 = {
44
+ name: "Zip Archive",
45
+ id: "zip",
46
+ module: "archives",
47
+ encoding: "zip",
48
+ format: "zip",
49
+ extensions: ["zip"],
50
+ mimeTypes: ["application/zip"],
51
+ category: "archive",
52
+ binary: true,
53
+ tests: ["PK"]
54
+ };
55
+ }
56
+ });
57
+
58
+ // src/zip/zip-loader-types.ts
59
+ var VERSION, ZipLoader;
60
+ var init_zip_loader_types = __esm({
61
+ "src/zip/zip-loader-types.ts"() {
62
+ "use strict";
63
+ init_zip_format();
64
+ VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
65
+ ZipLoader = {
66
+ ...ZipFormat2,
67
+ version: VERSION,
68
+ dataType: null,
69
+ batchType: null,
70
+ options: { zip: { maxTotalDecodedBytes: 64n * 1024n * 1024n } },
71
+ /** Loads the parser implementation through its installed package subpath. */
72
+ async preload() {
73
+ const { ZipLoaderWithParser: ZipLoaderWithParser3 } = await Promise.resolve().then(() => (init_zip_loader(), zip_loader_exports));
74
+ return ZipLoaderWithParser3;
75
+ }
76
+ };
77
+ }
78
+ });
79
+
80
+ // ../core/src/loader-utils/lib/module-utils/js-module-utils.ts
81
+ function registerJSModules(modules) {
82
+ globalThis.loaders ||= {};
83
+ globalThis.loaders.modules ||= {};
84
+ Object.assign(globalThis.loaders.modules, modules);
85
+ }
86
+ var init_js_module_utils = __esm({
87
+ "../core/src/loader-utils/lib/module-utils/js-module-utils.ts"() {
88
+ "use strict";
89
+ }
90
+ });
91
+
92
+ // ../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts
93
+ function concatenateArrayBuffers(...sources) {
94
+ return concatenateArrayBuffersFromArray(sources);
95
+ }
96
+ function concatenateArrayBuffersFromArray(sources) {
97
+ const sourceArrays = sources.map(
98
+ (source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
99
+ );
100
+ const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
101
+ const result = new Uint8Array(byteLength);
102
+ let offset = 0;
103
+ for (const sourceArray of sourceArrays) {
104
+ result.set(sourceArray, offset);
105
+ offset += sourceArray.byteLength;
106
+ }
107
+ return result.buffer;
108
+ }
109
+ var init_array_buffer_utils = __esm({
110
+ "../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts"() {
111
+ "use strict";
112
+ }
113
+ });
114
+
115
+ // ../core/src/loader-utils/lib/iterators/async-iteration.ts
116
+ async function concatenateArrayBuffersAsync(asyncIterator) {
117
+ const arrayBuffers = [];
118
+ for await (const chunk of asyncIterator) {
119
+ arrayBuffers.push(copyToArrayBuffer(chunk));
120
+ }
121
+ return concatenateArrayBuffers(...arrayBuffers);
122
+ }
123
+ function copyToArrayBuffer(chunk) {
124
+ if (chunk instanceof ArrayBuffer) {
125
+ return chunk;
126
+ }
127
+ if (ArrayBuffer.isView(chunk)) {
128
+ const { buffer, byteOffset, byteLength } = chunk;
129
+ return copyFromBuffer(buffer, byteOffset, byteLength);
130
+ }
131
+ return copyFromBuffer(chunk);
132
+ }
133
+ function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
134
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
135
+ const copy = new Uint8Array(view.length);
136
+ copy.set(view);
137
+ return copy.buffer;
138
+ }
139
+ var init_async_iteration = __esm({
140
+ "../core/src/loader-utils/lib/iterators/async-iteration.ts"() {
141
+ "use strict";
142
+ init_array_buffer_utils();
143
+ }
144
+ });
145
+
146
+ // ../core/src/loader-utils/lib/files/blob-file.ts
147
+ var BlobFile;
148
+ var init_blob_file = __esm({
149
+ "../core/src/loader-utils/lib/files/blob-file.ts"() {
150
+ "use strict";
151
+ BlobFile = class {
152
+ handle;
153
+ size;
154
+ bigsize;
155
+ url;
156
+ constructor(blob) {
157
+ this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
158
+ this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
159
+ this.bigsize = BigInt(this.size);
160
+ this.url = blob instanceof File ? blob.name : "";
161
+ }
162
+ async close() {
163
+ }
164
+ async stat() {
165
+ return {
166
+ size: this.handle.size,
167
+ bigsize: BigInt(this.handle.size),
168
+ isDirectory: false
169
+ };
170
+ }
171
+ async read(start, length, signal) {
172
+ if (signal == null ? void 0 : signal.aborted) {
173
+ throw new Error("Request aborted");
174
+ }
175
+ const arrayBuffer = await this.handle.slice(Number(start), Number(start) + Number(length)).arrayBuffer();
176
+ if (signal == null ? void 0 : signal.aborted) {
177
+ throw new Error("Request aborted");
178
+ }
179
+ return arrayBuffer;
180
+ }
181
+ };
182
+ }
183
+ });
184
+
185
+ // ../core/src/loader-utils/index.ts
186
+ var init_loader_utils = __esm({
187
+ "../core/src/loader-utils/index.ts"() {
188
+ "use strict";
189
+ init_js_module_utils();
190
+ init_async_iteration();
191
+ init_blob_file();
192
+ }
193
+ });
194
+
195
+ // ../compression/src/lib/compression.ts
196
+ var CompressionTransform, Decompressor;
197
+ var init_compression = __esm({
198
+ "../compression/src/lib/compression.ts"() {
199
+ "use strict";
200
+ init_loader_utils();
201
+ CompressionTransform = class {
202
+ /** Preloads any dynamic libraries. May enable sync functions */
203
+ async preload(modules = {}) {
204
+ registerJSModules(modules);
205
+ return void 0;
206
+ }
207
+ // HELPERS
208
+ concatenate(asyncIterator) {
209
+ return concatenateArrayBuffersAsync(asyncIterator);
210
+ }
211
+ improveError(error) {
212
+ if (!error.message.includes(this.name)) {
213
+ error.message = `${this.name} ${error.message}`;
214
+ }
215
+ return error;
216
+ }
217
+ };
218
+ Decompressor = class extends CompressionTransform {
219
+ constructor(options) {
220
+ super();
221
+ this.decompressBatches = this.decompressBatches.bind(this);
222
+ }
223
+ /** Asynchronously decompresses data. */
224
+ async decompress(input, size) {
225
+ await this.preload();
226
+ return this.decompressSync(input, size);
227
+ }
228
+ /** Synchronously decompresses data. */
229
+ decompressSync(input, size) {
230
+ throw new Error(`${this.name}: sync decompression not supported`);
231
+ }
232
+ /** Decompresses batches. */
233
+ async *decompressBatches(asyncIterator) {
234
+ const input = await this.concatenate(asyncIterator);
235
+ yield this.decompress(input);
236
+ }
237
+ };
238
+ }
239
+ });
240
+
241
+ // ../compression/src/lib/compress-utils-compression.ts
242
+ async function* transformBatches(stream, inputBatches, maximumOutputByteLength = Number.POSITIVE_INFINITY) {
243
+ let outputByteLength = 0;
244
+ try {
245
+ for await (const input of inputBatches) {
246
+ const output2 = stream.write(new Uint8Array(input));
247
+ if (output2.byteLength > maximumOutputByteLength - outputByteLength)
248
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
249
+ outputByteLength += output2.byteLength;
250
+ if (output2.byteLength > 0) yield copyArrayBuffer(output2);
251
+ }
252
+ const output = stream.finish();
253
+ if (output.byteLength > maximumOutputByteLength - outputByteLength)
254
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
255
+ if (output.byteLength > 0) yield copyArrayBuffer(output);
256
+ } finally {
257
+ stream.destroy();
258
+ }
259
+ }
260
+ function copyArrayBuffer(bytes) {
261
+ return bytes.slice().buffer;
262
+ }
263
+ function getDecompressOptions(options, size) {
264
+ const decodeOptions = {
265
+ ...options.compressUtils,
266
+ ...size === void 0 ? {} : { expectedSize: size }
267
+ };
268
+ const capacity = decodeOptions.expectedSize;
269
+ const maximum = getMaximumOutputByteLength(options);
270
+ if (capacity !== void 0 && (!Number.isSafeInteger(capacity) || capacity < 0 || capacity > maximum)) {
271
+ throw new RangeError("expectedSize exceeds the configured output capacity limit");
272
+ }
273
+ return decodeOptions;
274
+ }
275
+ function getMaximumOutputByteLength(options) {
276
+ const maximum = options.maxOutputByteLength ?? 512 * 1024 * 1024;
277
+ if (!Number.isSafeInteger(maximum) || maximum < 0 || maximum > 2147483647)
278
+ throw new RangeError("Invalid maxOutputByteLength");
279
+ return maximum;
280
+ }
281
+ function copyDecompressedOutput(bytes, options) {
282
+ if (bytes.byteLength > getMaximumOutputByteLength(options))
283
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
284
+ return copyArrayBuffer(bytes);
285
+ }
286
+ var CompressUtilsDecompressor;
287
+ var init_compress_utils_compression = __esm({
288
+ "../compression/src/lib/compress-utils-compression.ts"() {
289
+ "use strict";
290
+ init_compression();
291
+ CompressUtilsDecompressor = class extends Decompressor {
292
+ name;
293
+ extensions;
294
+ contentEncodings;
295
+ isSupported = true;
296
+ options;
297
+ loadModule;
298
+ /** Module initialized for synchronous operations. */
299
+ module = null;
300
+ /** Shared import and WASM initialization for concurrent callers. */
301
+ modulePromise = null;
302
+ /** Creates a format-specific compress-utils decoder. */
303
+ constructor(metadata3, loadModule, options = {}) {
304
+ super(options);
305
+ this.name = metadata3.name;
306
+ this.extensions = metadata3.extensions || [];
307
+ this.contentEncodings = metadata3.contentEncodings || [];
308
+ this.loadModule = loadModule;
309
+ this.options = options;
310
+ }
311
+ /** Imports and initializes the codec without loading the opposite direction. */
312
+ async preload(modules = {}) {
313
+ await super.preload(modules);
314
+ this.modulePromise ||= this.loadModule().then(async (module2) => {
315
+ var _a;
316
+ await ((_a = module2.preload) == null ? void 0 : _a.call(module2));
317
+ this.module = module2;
318
+ });
319
+ try {
320
+ await this.modulePromise;
321
+ } catch (error) {
322
+ this.modulePromise = null;
323
+ throw error;
324
+ }
325
+ }
326
+ /** Runs synchronously after preload has initialized the WASM codec. */
327
+ decompressSync(input, size) {
328
+ var _a;
329
+ if (!((_a = this.module) == null ? void 0 : _a.decompressSync))
330
+ throw new Error(`${this.name}: call preload() before decompressSync()`);
331
+ return copyDecompressedOutput(
332
+ this.module.decompressSync(new Uint8Array(input), getDecompressOptions(this.options, size)),
333
+ this.options
334
+ );
335
+ }
336
+ /** Decompresses one buffer with the selected compress-utils decoder. */
337
+ async decompress(input, size) {
338
+ const decodeOptions = getDecompressOptions(this.options, size);
339
+ await this.preload();
340
+ const module2 = this.module;
341
+ const output = await module2.decompress(new Uint8Array(input), decodeOptions);
342
+ return copyDecompressedOutput(output, this.options);
343
+ }
344
+ /** Incrementally decompresses input batches with compress-utils. */
345
+ async *decompressBatches(inputBatches) {
346
+ await this.preload();
347
+ const module2 = this.module;
348
+ if (!module2.createDecompressStream) {
349
+ yield await this.decompress(await this.concatenate(inputBatches));
350
+ return;
351
+ }
352
+ const maximum = getMaximumOutputByteLength(this.options);
353
+ const stream = await module2.createDecompressStream();
354
+ yield* transformBatches(stream, inputBatches, maximum);
355
+ }
356
+ };
357
+ }
358
+ });
359
+
360
+ // ../compression/src/deflate-decompressor-compress-utils.ts
361
+ var DeflateCompressUtilsDecompressor;
362
+ var init_deflate_decompressor_compress_utils = __esm({
363
+ "../compression/src/deflate-decompressor-compress-utils.ts"() {
364
+ "use strict";
365
+ init_compress_utils_compression();
366
+ DeflateCompressUtilsDecompressor = class extends CompressUtilsDecompressor {
367
+ constructor(options = {}) {
368
+ super(
369
+ { name: "deflate", contentEncodings: ["deflate"] },
370
+ () => options.raw ? import("compress-utils/deflate/decompress") : import("compress-utils/zlib/decompress"),
371
+ options
372
+ );
373
+ }
374
+ };
375
+ }
376
+ });
377
+
378
+ // ../compression/src/lib/decompression-stream.ts
379
+ async function decompressWithNativeDecompressionStream(input, format) {
380
+ const outputBatches = decompressBatchesWithNativeDecompressionStream([input], format);
381
+ return outputBatches ? await concatenateNativeDecompressionBatches(outputBatches) : null;
382
+ }
383
+ function decompressBatchesWithNativeDecompressionStream(inputBatches, format) {
384
+ const decompressionStream = createNativeDecompressionStream(format);
385
+ return decompressionStream ? transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) : null;
386
+ }
387
+ function createNativeDecompressionStream(format) {
388
+ var _a, _b;
389
+ if (typeof globalThis.DecompressionStream === "undefined") {
390
+ return null;
391
+ }
392
+ if (((_b = (_a = globalThis.process) == null ? void 0 : _a.release) == null ? void 0 : _b.name) === "node" && typeof globalThis.Buffer === "undefined") {
393
+ return null;
394
+ }
395
+ try {
396
+ const DecompressionStreamConstructor = globalThis.DecompressionStream;
397
+ return new DecompressionStreamConstructor(format);
398
+ } catch (error) {
399
+ if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
400
+ return null;
401
+ }
402
+ throw error;
403
+ }
404
+ }
405
+ async function* transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) {
406
+ const writer = decompressionStream.writable.getWriter();
407
+ const reader = decompressionStream.readable.getReader();
408
+ const writePromise = writeBatchesToNativeDecompressionStream(inputBatches, writer);
409
+ writePromise.catch(() => {
410
+ });
411
+ let outputCompleted = false;
412
+ try {
413
+ while (true) {
414
+ const { done, value } = await reader.read();
415
+ if (done) {
416
+ outputCompleted = true;
417
+ break;
418
+ }
419
+ yield copyExactArrayBuffer(value);
420
+ }
421
+ await writePromise;
422
+ } finally {
423
+ if (!outputCompleted) {
424
+ await reader.cancel().catch(() => {
425
+ });
426
+ await writer.abort().catch(() => {
427
+ });
428
+ await writePromise.catch(() => {
429
+ });
430
+ }
431
+ reader.releaseLock();
432
+ }
433
+ }
434
+ async function concatenateNativeDecompressionBatches(outputBatches) {
435
+ const batches = [];
436
+ let byteLength = 0;
437
+ for await (const outputBatch of outputBatches) {
438
+ const bytes = new Uint8Array(outputBatch);
439
+ batches.push(bytes);
440
+ byteLength += bytes.byteLength;
441
+ }
442
+ const output = new Uint8Array(byteLength);
443
+ let byteOffset = 0;
444
+ for (const batch of batches) {
445
+ output.set(batch, byteOffset);
446
+ byteOffset += batch.byteLength;
447
+ }
448
+ return output.buffer;
449
+ }
450
+ function copyExactArrayBuffer(value) {
451
+ return new Uint8Array(value).buffer;
452
+ }
453
+ async function writeBatchesToNativeDecompressionStream(inputBatches, writer) {
454
+ try {
455
+ for await (const inputBatch of inputBatches) {
456
+ await writer.write(new Uint8Array(inputBatch));
457
+ }
458
+ await writer.close();
459
+ } catch (error) {
460
+ await writer.abort(error).catch(() => {
461
+ });
462
+ throw error;
463
+ }
464
+ }
465
+ var init_decompression_stream = __esm({
466
+ "../compression/src/lib/decompression-stream.ts"() {
467
+ "use strict";
468
+ }
469
+ });
470
+
471
+ // ../compression/src/deflate-decompressor.ts
472
+ var DeflateDecompressor;
473
+ var init_deflate_decompressor = __esm({
474
+ "../compression/src/deflate-decompressor.ts"() {
475
+ "use strict";
476
+ init_deflate_decompressor_compress_utils();
477
+ init_decompression_stream();
478
+ DeflateDecompressor = class extends DeflateCompressUtilsDecompressor {
479
+ /** Decompresses with native streams when available, otherwise lazily initializes WASM. */
480
+ async decompress(input, size) {
481
+ if (this.options.useNative !== false) {
482
+ const output = await decompressWithNativeDecompressionStream(
483
+ input,
484
+ this.options.raw ? "deflate-raw" : "deflate"
485
+ );
486
+ if (output) return output;
487
+ }
488
+ return super.decompress(input, size);
489
+ }
490
+ /** Streams native batches when available, otherwise uses the WASM stream. */
491
+ async *decompressBatches(inputBatches) {
492
+ if (this.options.useNative !== false) {
493
+ const output = decompressBatchesWithNativeDecompressionStream(
494
+ inputBatches,
495
+ this.options.raw ? "deflate-raw" : "deflate"
496
+ );
497
+ if (output) {
498
+ yield* output;
499
+ return;
500
+ }
501
+ }
502
+ yield* super.decompressBatches(inputBatches);
503
+ }
504
+ };
505
+ }
506
+ });
507
+
508
+ // ../crypto/src/lib/hash.ts
509
+ var Hash;
510
+ var init_hash = __esm({
511
+ "../crypto/src/lib/hash.ts"() {
512
+ "use strict";
513
+ init_loader_utils();
514
+ Hash = class {
515
+ constructor(options = {}) {
516
+ this.hashBatches = this.hashBatches.bind(this);
517
+ }
518
+ async preload() {
519
+ return;
520
+ }
521
+ async *hashBatches(asyncIterator, encoding = "base64") {
522
+ var _a, _b;
523
+ const arrayBuffers = [];
524
+ for await (const arrayBuffer of asyncIterator) {
525
+ arrayBuffers.push(arrayBuffer);
526
+ yield arrayBuffer;
527
+ }
528
+ const output = await this.concatenate(arrayBuffers);
529
+ const hash = await this.hash(output, encoding);
530
+ (_b = (_a = this.options.crypto) == null ? void 0 : _a.onEnd) == null ? void 0 : _b.call(_a, { hash });
531
+ }
532
+ // HELPERS
533
+ async concatenate(asyncIterator) {
534
+ return await concatenateArrayBuffersAsync(asyncIterator);
535
+ }
536
+ };
537
+ }
538
+ });
539
+
540
+ // ../crypto/src/lib/algorithms/crc32.ts
541
+ function getCRC32Table() {
542
+ return CRC32TAB;
543
+ }
544
+ var CRC32, CRC32TAB;
545
+ var init_crc32 = __esm({
546
+ "../crypto/src/lib/algorithms/crc32.ts"() {
547
+ "use strict";
548
+ CRC32 = class {
549
+ crc;
550
+ constructor() {
551
+ this.crc = ~0;
552
+ }
553
+ update(arrayBuffer) {
554
+ const CRC32_TABLE = getCRC32Table();
555
+ const byteArray = new Uint8Array(arrayBuffer);
556
+ for (let i = 0; i < byteArray.byteLength; i++) {
557
+ this.crc = this.crc >>> 8 ^ CRC32_TABLE[(this.crc ^ byteArray[i]) & 255];
558
+ }
559
+ return this;
560
+ }
561
+ finalize() {
562
+ this.crc = (this.crc ^ -1) >>> 0;
563
+ return this.crc;
564
+ }
565
+ };
566
+ CRC32TAB = Uint32Array.of(
567
+ 0,
568
+ 1996959894,
569
+ 3993919788,
570
+ 2567524794,
571
+ 124634137,
572
+ 1886057615,
573
+ 3915621685,
574
+ 2657392035,
575
+ 249268274,
576
+ 2044508324,
577
+ 3772115230,
578
+ 2547177864,
579
+ 162941995,
580
+ 2125561021,
581
+ 3887607047,
582
+ 2428444049,
583
+ 498536548,
584
+ 1789927666,
585
+ 4089016648,
586
+ 2227061214,
587
+ 450548861,
588
+ 1843258603,
589
+ 4107580753,
590
+ 2211677639,
591
+ 325883990,
592
+ 1684777152,
593
+ 4251122042,
594
+ 2321926636,
595
+ 335633487,
596
+ 1661365465,
597
+ 4195302755,
598
+ 2366115317,
599
+ 997073096,
600
+ 1281953886,
601
+ 3579855332,
602
+ 2724688242,
603
+ 1006888145,
604
+ 1258607687,
605
+ 3524101629,
606
+ 2768942443,
607
+ 901097722,
608
+ 1119000684,
609
+ 3686517206,
610
+ 2898065728,
611
+ 853044451,
612
+ 1172266101,
613
+ 3705015759,
614
+ 2882616665,
615
+ 651767980,
616
+ 1373503546,
617
+ 3369554304,
618
+ 3218104598,
619
+ 565507253,
620
+ 1454621731,
621
+ 3485111705,
622
+ 3099436303,
623
+ 671266974,
624
+ 1594198024,
625
+ 3322730930,
626
+ 2970347812,
627
+ 795835527,
628
+ 1483230225,
629
+ 3244367275,
630
+ 3060149565,
631
+ 1994146192,
632
+ 31158534,
633
+ 2563907772,
634
+ 4023717930,
635
+ 1907459465,
636
+ 112637215,
637
+ 2680153253,
638
+ 3904427059,
639
+ 2013776290,
640
+ 251722036,
641
+ 2517215374,
642
+ 3775830040,
643
+ 2137656763,
644
+ 141376813,
645
+ 2439277719,
646
+ 3865271297,
647
+ 1802195444,
648
+ 476864866,
649
+ 2238001368,
650
+ 4066508878,
651
+ 1812370925,
652
+ 453092731,
653
+ 2181625025,
654
+ 4111451223,
655
+ 1706088902,
656
+ 314042704,
657
+ 2344532202,
658
+ 4240017532,
659
+ 1658658271,
660
+ 366619977,
661
+ 2362670323,
662
+ 4224994405,
663
+ 1303535960,
664
+ 984961486,
665
+ 2747007092,
666
+ 3569037538,
667
+ 1256170817,
668
+ 1037604311,
669
+ 2765210733,
670
+ 3554079995,
671
+ 1131014506,
672
+ 879679996,
673
+ 2909243462,
674
+ 3663771856,
675
+ 1141124467,
676
+ 855842277,
677
+ 2852801631,
678
+ 3708648649,
679
+ 1342533948,
680
+ 654459306,
681
+ 3188396048,
682
+ 3373015174,
683
+ 1466479909,
684
+ 544179635,
685
+ 3110523913,
686
+ 3462522015,
687
+ 1591671054,
688
+ 702138776,
689
+ 2966460450,
690
+ 3352799412,
691
+ 1504918807,
692
+ 783551873,
693
+ 3082640443,
694
+ 3233442989,
695
+ 3988292384,
696
+ 2596254646,
697
+ 62317068,
698
+ 1957810842,
699
+ 3939845945,
700
+ 2647816111,
701
+ 81470997,
702
+ 1943803523,
703
+ 3814918930,
704
+ 2489596804,
705
+ 225274430,
706
+ 2053790376,
707
+ 3826175755,
708
+ 2466906013,
709
+ 167816743,
710
+ 2097651377,
711
+ 4027552580,
712
+ 2265490386,
713
+ 503444072,
714
+ 1762050814,
715
+ 4150417245,
716
+ 2154129355,
717
+ 426522225,
718
+ 1852507879,
719
+ 4275313526,
720
+ 2312317920,
721
+ 282753626,
722
+ 1742555852,
723
+ 4189708143,
724
+ 2394877945,
725
+ 397917763,
726
+ 1622183637,
727
+ 3604390888,
728
+ 2714866558,
729
+ 953729732,
730
+ 1340076626,
731
+ 3518719985,
732
+ 2797360999,
733
+ 1068828381,
734
+ 1219638859,
735
+ 3624741850,
736
+ 2936675148,
737
+ 906185462,
738
+ 1090812512,
739
+ 3747672003,
740
+ 2825379669,
741
+ 829329135,
742
+ 1181335161,
743
+ 3412177804,
744
+ 3160834842,
745
+ 628085408,
746
+ 1382605366,
747
+ 3423369109,
748
+ 3138078467,
749
+ 570562233,
750
+ 1426400815,
751
+ 3317316542,
752
+ 2998733608,
753
+ 733239954,
754
+ 1555261956,
755
+ 3268935591,
756
+ 3050360625,
757
+ 752459403,
758
+ 1541320221,
759
+ 2607071920,
760
+ 3965973030,
761
+ 1969922972,
762
+ 40735498,
763
+ 2617837225,
764
+ 3943577151,
765
+ 1913087877,
766
+ 83908371,
767
+ 2512341634,
768
+ 3803740692,
769
+ 2075208622,
770
+ 213261112,
771
+ 2463272603,
772
+ 3855990285,
773
+ 2094854071,
774
+ 198958881,
775
+ 2262029012,
776
+ 4057260610,
777
+ 1759359992,
778
+ 534414190,
779
+ 2176718541,
780
+ 4139329115,
781
+ 1873836001,
782
+ 414664567,
783
+ 2282248934,
784
+ 4279200368,
785
+ 1711684554,
786
+ 285281116,
787
+ 2405801727,
788
+ 4167216745,
789
+ 1634467795,
790
+ 376229701,
791
+ 2685067896,
792
+ 3608007406,
793
+ 1308918612,
794
+ 956543938,
795
+ 2808555105,
796
+ 3495958263,
797
+ 1231636301,
798
+ 1047427035,
799
+ 2932959818,
800
+ 3654703836,
801
+ 1088359270,
802
+ 936918e3,
803
+ 2847714899,
804
+ 3736837829,
805
+ 1202900863,
806
+ 817233897,
807
+ 3183342108,
808
+ 3401237130,
809
+ 1404277552,
810
+ 615818150,
811
+ 3134207493,
812
+ 3453421203,
813
+ 1423857449,
814
+ 601450431,
815
+ 3009837614,
816
+ 3294710456,
817
+ 1567103746,
818
+ 711928724,
819
+ 3020668471,
820
+ 3272380065,
821
+ 1510334235,
822
+ 755167117
823
+ );
824
+ }
825
+ });
826
+
827
+ // ../crypto/src/lib/utils/base64-utils.ts
828
+ function asciiToBase64(string) {
829
+ string = `${string}`;
830
+ for (let i = 0; i < string.length; i++) {
831
+ if (string.charCodeAt(i) > 255) {
832
+ return null;
833
+ }
834
+ }
835
+ let out = "";
836
+ for (let i = 0; i < string.length; i += 3) {
837
+ const groupsOfSix = [void 0, void 0, void 0, void 0];
838
+ groupsOfSix[0] = string.charCodeAt(i) >> 2;
839
+ groupsOfSix[1] = (string.charCodeAt(i) & 3) << 4;
840
+ if (string.length > i + 1) {
841
+ groupsOfSix[1] |= string.charCodeAt(i + 1) >> 4;
842
+ groupsOfSix[2] = (string.charCodeAt(i + 1) & 15) << 2;
843
+ }
844
+ if (string.length > i + 2) {
845
+ groupsOfSix[2] |= string.charCodeAt(i + 2) >> 6;
846
+ groupsOfSix[3] = string.charCodeAt(i + 2) & 63;
847
+ }
848
+ for (let j = 0; j < groupsOfSix.length; j++) {
849
+ if (typeof groupsOfSix[j] === "undefined") {
850
+ out += "=";
851
+ } else {
852
+ out += btoaLookup(groupsOfSix[j]);
853
+ }
854
+ }
855
+ }
856
+ return out;
857
+ }
858
+ function btoaLookup(idx) {
859
+ if (idx < 26) {
860
+ return String.fromCharCode(idx + "A".charCodeAt(0));
861
+ }
862
+ if (idx < 52) {
863
+ return String.fromCharCode(idx - 26 + "a".charCodeAt(0));
864
+ }
865
+ if (idx < 62) {
866
+ return String.fromCharCode(idx - 52 + "0".charCodeAt(0));
867
+ }
868
+ if (idx === 62) {
869
+ return "+";
870
+ }
871
+ if (idx === 63) {
872
+ return "/";
873
+ }
874
+ return void 0;
875
+ }
876
+ var init_base64_utils = __esm({
877
+ "../crypto/src/lib/utils/base64-utils.ts"() {
878
+ "use strict";
879
+ }
880
+ });
881
+
882
+ // ../crypto/src/lib/utils/digest-utils.ts
883
+ function encodeNumber(number, encoding) {
884
+ switch (encoding) {
885
+ case "hex":
886
+ return convertNumberToHex(number);
887
+ case "base64":
888
+ return convertHexToBase64(convertNumberToHex(number));
889
+ default:
890
+ throw new Error(encoding);
891
+ }
892
+ }
893
+ function convertHexToBase64(hexstring) {
894
+ if (hexstring.length % 2 !== 0) {
895
+ hexstring = `0${hexstring}`;
896
+ }
897
+ const matches = hexstring.match(/\w{2}/g) || [];
898
+ const string = matches.map((a) => String.fromCharCode(parseInt(a, 16))).join("");
899
+ return asciiToBase64(string) || "";
900
+ }
901
+ function convertNumberToHex(cipher) {
902
+ const hexString = cipher.toString(16);
903
+ return hexString === "0" ? `0${hexString}` : hexString;
904
+ }
905
+ var init_digest_utils = __esm({
906
+ "../crypto/src/lib/utils/digest-utils.ts"() {
907
+ "use strict";
908
+ init_base64_utils();
909
+ }
910
+ });
911
+
912
+ // ../crypto/src/lib/crc32-hash.ts
913
+ var CRC32Hash;
914
+ var init_crc32_hash = __esm({
915
+ "../crypto/src/lib/crc32-hash.ts"() {
916
+ "use strict";
917
+ init_hash();
918
+ init_crc32();
919
+ init_digest_utils();
920
+ CRC32Hash = class extends Hash {
921
+ name = "crc32";
922
+ options;
923
+ constructor(options = {}) {
924
+ super();
925
+ this.options = { crypto: {}, ...options };
926
+ this.hashBatches = this.hashBatches.bind(this);
927
+ }
928
+ /**
929
+ * Atomic hash calculation
930
+ * @returns base64 encoded hash
931
+ */
932
+ async hash(input, encoding) {
933
+ return this.hashSync(input, encoding);
934
+ }
935
+ hashSync(input, encoding) {
936
+ const hash = new CRC32();
937
+ hash.update(input);
938
+ const digest = hash.finalize();
939
+ return encodeNumber(digest, encoding);
940
+ }
941
+ async *hashBatches(asyncIterator, encoding = "base64") {
942
+ var _a, _b;
943
+ const hash = new CRC32();
944
+ for await (const chunk of asyncIterator) {
945
+ hash.update(chunk);
946
+ yield chunk;
947
+ }
948
+ const digest = hash.finalize();
949
+ (_b = (_a = this.options.crypto) == null ? void 0 : _a.onEnd) == null ? void 0 : _b.call(_a, { hash: encodeNumber(digest, encoding) });
950
+ }
951
+ };
952
+ }
953
+ });
954
+
955
+ // ../crypto/src/index.ts
956
+ var init_src = __esm({
957
+ "../crypto/src/index.ts"() {
958
+ "use strict";
959
+ init_crc32_hash();
960
+ }
961
+ });
962
+
963
+ // src/zip/lib/zip64-extra-field.ts
964
+ function parseZip64ExtraField(extraField, expectedFields) {
965
+ const values = {};
966
+ if (expectedFields.length === 0) {
967
+ return values;
968
+ }
969
+ const expectedPayloadLength = expectedFields.reduce(
970
+ (totalByteLength, field) => totalByteLength + field.byteLength,
971
+ 0
972
+ );
973
+ let recordOffset = 0;
974
+ while (recordOffset < extraField.byteLength) {
975
+ if (recordOffset + 4 > extraField.byteLength) {
976
+ throw new Error(
977
+ "Invalid ZIP archive: truncated extra-field record header while reading ZIP64 data"
978
+ );
979
+ }
980
+ const headerId = extraField.getUint16(recordOffset, true);
981
+ const payloadLength = extraField.getUint16(recordOffset + 2, true);
982
+ const payloadOffset = recordOffset + 4;
983
+ const nextRecordOffset = payloadOffset + payloadLength;
984
+ if (nextRecordOffset > extraField.byteLength) {
985
+ throw new Error(
986
+ "Invalid ZIP archive: truncated extra-field record payload while reading ZIP64 data"
987
+ );
988
+ }
989
+ if (headerId === ZIP64_EXTRA_FIELD_ID) {
990
+ if (payloadLength !== expectedPayloadLength) {
991
+ throw new Error(
992
+ "Invalid ZIP archive: ZIP64 extended information has an unexpected payload size"
993
+ );
994
+ }
995
+ let fieldOffset = payloadOffset;
996
+ for (const field of expectedFields) {
997
+ values[field.name] = field.byteLength === 8 ? extraField.getBigUint64(fieldOffset, true) : BigInt(extraField.getUint32(fieldOffset, true));
998
+ fieldOffset += field.byteLength;
999
+ }
1000
+ return values;
1001
+ }
1002
+ recordOffset = nextRecordOffset;
1003
+ }
1004
+ throw new Error("Invalid ZIP archive: required ZIP64 extended information is missing");
1005
+ }
1006
+ var ZIP64_EXTRA_FIELD_ID;
1007
+ var init_zip64_extra_field = __esm({
1008
+ "src/zip/lib/zip64-extra-field.ts"() {
1009
+ "use strict";
1010
+ ZIP64_EXTRA_FIELD_ID = 1;
1011
+ }
1012
+ });
1013
+
1014
+ // src/zip/lib/zip-entry-metadata.ts
1015
+ function decodeZipHeader(bytes, central) {
1016
+ const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1017
+ const fixedBytes = central ? 46 : 30;
1018
+ if (bytes.byteLength < fixedBytes || header.getUint32(0, true) !== (central ? 33639248 : 67324752))
1019
+ throw new Error("Invalid ZIP archive: missing entry header");
1020
+ const nameLength = header.getUint16(central ? 28 : 26, true);
1021
+ const extraLength = header.getUint16(central ? 30 : 28, true);
1022
+ const commentLength = central ? header.getUint16(32, true) : 0;
1023
+ if (bytes.byteLength !== fixedBytes + nameLength + extraLength + commentLength)
1024
+ throw new Error("Invalid ZIP archive: truncated entry metadata");
1025
+ const flags = header.getUint16(central ? 8 : 6, true);
1026
+ const method = header.getUint16(central ? 10 : 8, true);
1027
+ if (flags & (1 | 64 | 8192)) throw new Error("Unsupported ZIP encryption");
1028
+ if (flags & ~(8 | 2048 | (method === 8 ? 6 : 0))) throw new Error("Unsupported ZIP flags");
1029
+ if (method !== 0 && method !== 8)
1030
+ throw new Error(`Unsupported ZIP compression method: ${method}`);
1031
+ let compressedSize = BigInt(header.getUint32(central ? 20 : 18, true));
1032
+ let size = BigInt(header.getUint32(central ? 24 : 22, true));
1033
+ let localHeaderOffset = central ? BigInt(header.getUint32(42, true)) : 0n;
1034
+ let disk = central ? BigInt(header.getUint16(34, true)) : 0n;
1035
+ let zip64 = compressedSize === 0xffffffffn || size === 0xffffffffn;
1036
+ const fields = [];
1037
+ if (central) {
1038
+ if (size === 0xffffffffn) fields.push({ name: "size", byteLength: 8 });
1039
+ if (compressedSize === 0xffffffffn) fields.push({ name: "compressedSize", byteLength: 8 });
1040
+ if (localHeaderOffset === 0xffffffffn) fields.push({ name: "localHeaderOffset", byteLength: 8 });
1041
+ if (disk === 0xffffn) fields.push({ name: "disk", byteLength: 4 });
1042
+ } else if (zip64)
1043
+ fields.push({ name: "size", byteLength: 8 }, { name: "compressedSize", byteLength: 8 });
1044
+ const extraBytes = bytes.subarray(fixedBytes + nameLength, fixedBytes + nameLength + extraLength);
1045
+ const extra = new DataView(extraBytes.buffer, extraBytes.byteOffset, extraBytes.byteLength);
1046
+ const extraValues = parseZip64ExtraField(extra, fields);
1047
+ if (size === 0xffffffffn) size = extraValues.size;
1048
+ if (compressedSize === 0xffffffffn) compressedSize = extraValues.compressedSize;
1049
+ if (localHeaderOffset === 0xffffffffn) localHeaderOffset = extraValues.localHeaderOffset;
1050
+ if (disk === 0xffffn) disk = extraValues.disk;
1051
+ if (disk !== 0n) throw new Error("Unsupported split ZIP archive");
1052
+ const nameBytes = bytes.subarray(fixedBytes, fixedBytes + nameLength);
1053
+ let path = decodeZipText(nameBytes, Boolean(flags & 2048));
1054
+ const commentBytes = bytes.subarray(fixedBytes + nameLength + extraLength);
1055
+ let comment = decodeZipText(commentBytes, Boolean(flags & 2048));
1056
+ for (let offset = 0; offset < extra.byteLength; ) {
1057
+ if (offset + 4 > extra.byteLength)
1058
+ throw new Error("Invalid ZIP archive: truncated extra field");
1059
+ const identifier = extra.getUint16(offset, true);
1060
+ const length = extra.getUint16(offset + 2, true);
1061
+ if (offset + 4 + length > extra.byteLength)
1062
+ throw new Error("Invalid ZIP archive: truncated extra field");
1063
+ if (!central && flags & 8 && identifier === 1) {
1064
+ if (length >= 16) zip64 = true;
1065
+ }
1066
+ if (identifier === 28789 || identifier === 25461) {
1067
+ const original = identifier === 28789 ? nameBytes : commentBytes;
1068
+ if (length < 5) throw new Error("Invalid ZIP archive: truncated Unicode extra field");
1069
+ if (extra.getUint8(offset + 4) === 1 && extra.getUint32(offset + 5, true) === calculateZipChecksum(original)) {
1070
+ const text = decodeZipText(extraBytes.subarray(offset + 9, offset + 4 + length), true);
1071
+ if (identifier === 28789) path = text;
1072
+ else comment = text;
1073
+ }
1074
+ }
1075
+ offset += 4 + length;
1076
+ }
1077
+ validateZipPath(path);
1078
+ return {
1079
+ path,
1080
+ nameBytes,
1081
+ flags,
1082
+ method,
1083
+ crc32: header.getUint32(central ? 16 : 14, true),
1084
+ compressedSize,
1085
+ size,
1086
+ localHeaderOffset,
1087
+ comment,
1088
+ zip64
1089
+ };
1090
+ }
1091
+ function decodeZipText(bytes, utf8) {
1092
+ if (utf8) return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
1093
+ return Array.from(
1094
+ bytes,
1095
+ (value) => value < 128 ? String.fromCharCode(value) : CP437_HIGH[value - 128]
1096
+ ).join("");
1097
+ }
1098
+ function validateZipPath(path) {
1099
+ const segments = path.endsWith("/") ? path.slice(0, -1).split("/") : path.split("/");
1100
+ if (!path || path.includes("\\") || path.includes("\0") || /^[A-Za-z]:/.test(path) || segments.some((segment) => !segment || segment === "." || segment === ".."))
1101
+ throw new Error("Invalid ZIP archive: noncanonical relative path");
1102
+ }
1103
+ function calculateZipChecksum(bytes) {
1104
+ return Number.parseInt(new CRC32Hash().hashSync(bytes.slice().buffer, "hex"), 16);
1105
+ }
1106
+ function encodeUtf8Text(value) {
1107
+ const bytes = new TextEncoder().encode(value);
1108
+ if (new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes) !== value)
1109
+ throw new TypeError("ZIP names and entry comments must be well-formed Unicode");
1110
+ return bytes;
1111
+ }
1112
+ var CP437_HIGH;
1113
+ var init_zip_entry_metadata = __esm({
1114
+ "src/zip/lib/zip-entry-metadata.ts"() {
1115
+ "use strict";
1116
+ init_src();
1117
+ init_zip64_extra_field();
1118
+ CP437_HIGH = "\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";
1119
+ }
1120
+ });
1121
+
1122
+ // src/zip/lib/zip-serialization.ts
1123
+ function encodeZipLocalHeader(entry) {
1124
+ validateHeaderEntry(entry);
1125
+ const bytes = new Uint8Array(30 + entry.nameBytes.length + (entry.zip64 ? 20 : 0));
1126
+ const view = new DataView(bytes.buffer);
1127
+ view.setUint32(0, 67324752, true);
1128
+ view.setUint16(4, getZipVersion(entry), true);
1129
+ view.setUint16(6, entry.flags, true);
1130
+ view.setUint16(8, entry.method, true);
1131
+ view.setUint32(10, encodeZipTimestamp(entry.date), true);
1132
+ const descriptor = Boolean(entry.flags & 8);
1133
+ view.setUint32(14, descriptor ? 0 : entry.crc32, true);
1134
+ view.setUint32(
1135
+ 18,
1136
+ entry.zip64 ? Number(ZIP32_SENTINEL) : descriptor ? 0 : Number(entry.compressedSize),
1137
+ true
1138
+ );
1139
+ view.setUint32(
1140
+ 22,
1141
+ entry.zip64 ? Number(ZIP32_SENTINEL) : descriptor ? 0 : Number(entry.size),
1142
+ true
1143
+ );
1144
+ view.setUint16(26, entry.nameBytes.length, true);
1145
+ view.setUint16(28, entry.zip64 ? 20 : 0, true);
1146
+ bytes.set(entry.nameBytes, 30);
1147
+ if (entry.zip64) {
1148
+ const extraOffset = 30 + entry.nameBytes.length;
1149
+ view.setUint16(extraOffset, 1, true);
1150
+ view.setUint16(extraOffset + 2, 16, true);
1151
+ view.setBigUint64(extraOffset + 4, descriptor ? 0n : entry.size, true);
1152
+ view.setBigUint64(extraOffset + 12, descriptor ? 0n : entry.compressedSize, true);
1153
+ }
1154
+ return bytes;
1155
+ }
1156
+ function encodeZipCentralHeader(entry) {
1157
+ validateHeaderEntry(entry);
1158
+ const comment = entry.commentBytes ?? new Uint8Array();
1159
+ const extraBytes = entry.zip64 ? 28 : 0;
1160
+ const bytes = new Uint8Array(46 + entry.nameBytes.length + extraBytes + comment.length);
1161
+ const view = new DataView(bytes.buffer);
1162
+ view.setUint32(0, 33639248, true);
1163
+ view.setUint16(4, entry.zip64 ? 45 : 20, true);
1164
+ view.setUint16(6, getZipVersion(entry), true);
1165
+ view.setUint16(8, entry.flags, true);
1166
+ view.setUint16(10, entry.method, true);
1167
+ view.setUint32(12, encodeZipTimestamp(entry.date), true);
1168
+ view.setUint32(16, entry.crc32, true);
1169
+ view.setUint32(20, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.compressedSize), true);
1170
+ view.setUint32(24, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.size), true);
1171
+ view.setUint16(28, entry.nameBytes.length, true);
1172
+ view.setUint16(30, extraBytes, true);
1173
+ view.setUint16(32, comment.length, true);
1174
+ view.setUint32(38, entry.directory ? 16 : 0, true);
1175
+ view.setUint32(42, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.localHeaderOffset), true);
1176
+ bytes.set(entry.nameBytes, 46);
1177
+ if (entry.zip64) {
1178
+ const extraOffset = 46 + entry.nameBytes.length;
1179
+ view.setUint16(extraOffset, 1, true);
1180
+ view.setUint16(extraOffset + 2, 24, true);
1181
+ view.setBigUint64(extraOffset + 4, entry.size, true);
1182
+ view.setBigUint64(extraOffset + 12, entry.compressedSize, true);
1183
+ view.setBigUint64(extraOffset + 20, entry.localHeaderOffset, true);
1184
+ }
1185
+ bytes.set(comment, 46 + entry.nameBytes.length + extraBytes);
1186
+ return bytes;
1187
+ }
1188
+ function encodeZipEndRecords(count, directorySize, directoryOffset, zip64, comment = new Uint8Array()) {
1189
+ for (const value of [count, directorySize, directoryOffset, directoryOffset + directorySize])
1190
+ validateUint64(value);
1191
+ if (comment.length > 65535) throw new RangeError("ZIP archive comment exceeds 65535 bytes");
1192
+ if (!zip64 && (count > 0xffffn || directorySize >= ZIP32_SENTINEL || directoryOffset >= ZIP32_SENTINEL))
1193
+ throw new RangeError("ZIP32 end record capacity exceeded");
1194
+ const bytes = new Uint8Array((zip64 ? 98 : 22) + comment.length);
1195
+ const view = new DataView(bytes.buffer);
1196
+ if (zip64) {
1197
+ view.setUint32(0, 101075792, true);
1198
+ view.setBigUint64(4, 44n, true);
1199
+ view.setUint16(12, 45, true);
1200
+ view.setUint16(14, 45, true);
1201
+ view.setBigUint64(24, count, true);
1202
+ view.setBigUint64(32, count, true);
1203
+ view.setBigUint64(40, directorySize, true);
1204
+ view.setBigUint64(48, directoryOffset, true);
1205
+ view.setUint32(56, 117853008, true);
1206
+ view.setBigUint64(64, directoryOffset + directorySize, true);
1207
+ view.setUint32(72, 1, true);
1208
+ }
1209
+ const endOffset = zip64 ? 76 : 0;
1210
+ view.setUint32(endOffset, 101010256, true);
1211
+ view.setUint16(endOffset + 8, zip64 ? 65535 : Number(count), true);
1212
+ view.setUint16(endOffset + 10, zip64 ? 65535 : Number(count), true);
1213
+ view.setUint32(endOffset + 12, zip64 ? Number(ZIP32_SENTINEL) : Number(directorySize), true);
1214
+ view.setUint32(endOffset + 16, zip64 ? Number(ZIP32_SENTINEL) : Number(directoryOffset), true);
1215
+ view.setUint16(endOffset + 20, comment.length, true);
1216
+ bytes.set(comment, endOffset + 22);
1217
+ return bytes;
1218
+ }
1219
+ function encodeZipTimestamp(date) {
1220
+ if (!(date instanceof Date) || !Number.isFinite(date.getTime()) || date.getUTCFullYear() < 1980 || date.getUTCFullYear() > 2107)
1221
+ throw new RangeError("ZIP timestamp must be a valid UTC date in 1980\u20132107");
1222
+ const time = date.getUTCHours() << 11 | date.getUTCMinutes() << 5 | Math.floor(date.getUTCSeconds() / 2);
1223
+ const day = date.getUTCFullYear() - 1980 << 9 | date.getUTCMonth() + 1 << 5 | date.getUTCDate();
1224
+ return (day << 16 | time) >>> 0;
1225
+ }
1226
+ function getZipVersion(entry) {
1227
+ return entry.zip64 ? 45 : entry.method === 8 || entry.flags & 8 ? 20 : 10;
1228
+ }
1229
+ function validateHeaderEntry(entry) {
1230
+ var _a;
1231
+ if (!entry.nameBytes.length || entry.nameBytes.length > 65535 || (((_a = entry.commentBytes) == null ? void 0 : _a.length) ?? 0) > 65535)
1232
+ throw new RangeError("ZIP name/comment exceeds header capacity");
1233
+ for (const value of [entry.size, entry.compressedSize, entry.localHeaderOffset])
1234
+ validateUint64(value);
1235
+ if (!entry.zip64 && [entry.size, entry.compressedSize, entry.localHeaderOffset].some(
1236
+ (value) => value >= ZIP32_SENTINEL
1237
+ ))
1238
+ throw new RangeError("ZIP32 entry capacity exceeded");
1239
+ }
1240
+ function validateUint64(value) {
1241
+ if (typeof value !== "bigint" || value < 0n || value > 0xffffffffffffffffn)
1242
+ throw new RangeError("ZIP64 unsigned integer capacity exceeded");
1243
+ }
1244
+ var ZIP32_SENTINEL;
1245
+ var init_zip_serialization = __esm({
1246
+ "src/zip/lib/zip-serialization.ts"() {
1247
+ "use strict";
1248
+ ZIP32_SENTINEL = 0xffffffffn;
1249
+ }
1250
+ });
1251
+
1252
+ // src/zip/zip-archive.ts
1253
+ async function openZipArchive(input, options = {}) {
1254
+ return await ZipArchive.open(input, options);
1255
+ }
1256
+ function normalizeZipInput(input) {
1257
+ if (input instanceof ArrayBuffer) return new BlobFile(input);
1258
+ if (ArrayBuffer.isView(input))
1259
+ return new BlobFile(
1260
+ new Blob([new Uint8Array(input.buffer, input.byteOffset, input.byteLength).slice()])
1261
+ );
1262
+ if (input instanceof Blob) return new BlobFile(input);
1263
+ return input;
1264
+ }
1265
+ function minimumBigInt(left, right) {
1266
+ return left < right ? left : right;
1267
+ }
1268
+ var DEFAULT_OPTIONS, ZipArchive;
1269
+ var init_zip_archive = __esm({
1270
+ "src/zip/zip-archive.ts"() {
1271
+ "use strict";
1272
+ init_loader_utils();
1273
+ init_deflate_decompressor();
1274
+ init_src();
1275
+ init_zip_entry_metadata();
1276
+ init_zip_serialization();
1277
+ DEFAULT_OPTIONS = {
1278
+ maxArchiveBytes: 1024n ** 4n,
1279
+ maxDirectoryBytes: 32 * 1024 * 1024,
1280
+ maxEntries: 1e5,
1281
+ maxReadBytes: 1024 * 1024,
1282
+ maxCompressedBytes: 64n * 1024n * 1024n,
1283
+ maxDecodedBytes: 64n * 1024n * 1024n,
1284
+ chunkBytes: 64 * 1024
1285
+ };
1286
+ ZipArchive = class _ZipArchive {
1287
+ /** Archive byte length, without losing ZIP64 precision. */
1288
+ size;
1289
+ /** Archive comment, decoded using legacy ZIP CP437. */
1290
+ comment;
1291
+ /** Shared file limits captured at open time. */
1292
+ limits;
1293
+ /** Owned random-access transport. */
1294
+ file;
1295
+ /** File lifetime, including in-flight operations. */
1296
+ controller = new AbortController();
1297
+ /** Initialization/caller cancellation combined with close. */
1298
+ signal;
1299
+ /** Validated directory boundary. */
1300
+ directory;
1301
+ /** A single directory-index promise shared by concurrent lookups. */
1302
+ directoryPromise;
1303
+ /** Local-header validation shared by repeated path reads. */
1304
+ entriesByOffset = /* @__PURE__ */ new Map();
1305
+ /** Central-validated named lookups share their local-header work. */
1306
+ entriesByPath = /* @__PURE__ */ new Map();
1307
+ /** Next local-header boundary for central-validated, nonoverlapping payloads. */
1308
+ nextOffsets = /* @__PURE__ */ new Map();
1309
+ /** Only entries issued by this archive can be used for reads. */
1310
+ issuedEntries = /* @__PURE__ */ new WeakSet();
1311
+ /** Idempotent file cleanup, including open failure. */
1312
+ closePromise;
1313
+ /** Captures the owned transport and validates independent limits. */
1314
+ constructor(file, size, options) {
1315
+ this.file = file;
1316
+ this.size = size;
1317
+ this.comment = "";
1318
+ this.limits = {
1319
+ maxArchiveBytes: options.maxArchiveBytes ?? DEFAULT_OPTIONS.maxArchiveBytes,
1320
+ maxDirectoryBytes: options.maxDirectoryBytes ?? DEFAULT_OPTIONS.maxDirectoryBytes,
1321
+ maxEntries: options.maxEntries ?? DEFAULT_OPTIONS.maxEntries,
1322
+ maxReadBytes: options.maxReadBytes ?? DEFAULT_OPTIONS.maxReadBytes,
1323
+ maxCompressedBytes: options.maxCompressedBytes ?? DEFAULT_OPTIONS.maxCompressedBytes,
1324
+ maxDecodedBytes: options.maxDecodedBytes ?? DEFAULT_OPTIONS.maxDecodedBytes,
1325
+ chunkBytes: options.chunkBytes ?? DEFAULT_OPTIONS.chunkBytes
1326
+ };
1327
+ for (const [name, value] of Object.entries(this.limits)) {
1328
+ const bigintLimit = ["maxArchiveBytes", "maxCompressedBytes", "maxDecodedBytes"].includes(
1329
+ name
1330
+ );
1331
+ if (bigintLimit ? typeof value !== "bigint" || value < 0n : typeof value !== "number" || !Number.isSafeInteger(value) || value < 1)
1332
+ throw new RangeError(`Invalid ZIP ${name} limit`);
1333
+ }
1334
+ this.signal = options.signal ? AbortSignal.any([this.controller.signal, options.signal]) : this.controller.signal;
1335
+ }
1336
+ /** Initializes directory bounds without scanning entries or reading their payloads. */
1337
+ static async open(input, options = {}) {
1338
+ var _a;
1339
+ const file = normalizeZipInput(input);
1340
+ let archive;
1341
+ try {
1342
+ const advertisedSize = file.bigsize;
1343
+ const status = advertisedSize === void 0 || advertisedSize === 0n ? await ((_a = file.stat) == null ? void 0 : _a.call(file)) : void 0;
1344
+ const reportedBigsize = (status == null ? void 0 : status.bigsize) ?? file.bigsize;
1345
+ const size = reportedBigsize !== void 0 && reportedBigsize !== 0n ? reportedBigsize : BigInt((status == null ? void 0 : status.size) || file.size);
1346
+ archive = new _ZipArchive(file, size, options);
1347
+ archive.signal.throwIfAborted();
1348
+ if (size < 22n || size > archive.limits.maxArchiveBytes)
1349
+ throw new RangeError("ZIP archive size limit or minimum header size");
1350
+ archive.directory = await archive.readDirectoryLocation();
1351
+ Object.defineProperty(archive, "comment", { value: archive.directory.comment });
1352
+ return archive;
1353
+ } catch (error) {
1354
+ if (archive) await archive.close();
1355
+ else await file.close();
1356
+ throw error;
1357
+ }
1358
+ }
1359
+ /**
1360
+ * Appends one STORE entry through validated container metadata and the native serializer.
1361
+ * Internal composition operation: callers own the writable file and discard it on write failure.
1362
+ * Existing payload offsets, central metadata and archive comments are retained.
1363
+ */
1364
+ static async appendEntry(file, path, data, options = {}) {
1365
+ const archive = await _ZipArchive.open(file, options);
1366
+ try {
1367
+ validateZipPath(path);
1368
+ if (archive.directory.offset > BigInt(Number.MAX_SAFE_INTEGER))
1369
+ throw new RangeError("ZIP append transport offset exceeds safe integer range");
1370
+ if (await archive.getEntry(path)) throw new Error("ZIP entry already exists");
1371
+ for await (const _entry of archive.entries()) {
1372
+ }
1373
+ const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
1374
+ if (path.endsWith("/") && bytes.length)
1375
+ throw new Error("ZIP directory payload must be empty");
1376
+ const entry = {
1377
+ nameBytes: encodeUtf8Text(path),
1378
+ date: /* @__PURE__ */ new Date("1980-01-01T00:00:00Z"),
1379
+ flags: 2048,
1380
+ method: 0,
1381
+ crc32: 0,
1382
+ size: BigInt(bytes.length),
1383
+ compressedSize: BigInt(bytes.length),
1384
+ localHeaderOffset: archive.directory.offset,
1385
+ zip64: archive.directory.offset >= 0xffffffffn || bytes.length >= 4294967295
1386
+ };
1387
+ let local = encodeZipLocalHeader(entry);
1388
+ let central = encodeZipCentralHeader(entry);
1389
+ const directoryBytes = archive.directory.size + BigInt(central.length);
1390
+ const directoryOffset = archive.directory.offset + BigInt(local.length + bytes.length);
1391
+ const count = archive.directory.count + 1n;
1392
+ const comment = new Uint8Array(
1393
+ await archive.readExact(
1394
+ archive.size - BigInt(archive.comment.length),
1395
+ archive.comment.length
1396
+ )
1397
+ );
1398
+ const footer = encodeZipEndRecords(
1399
+ count,
1400
+ directoryBytes,
1401
+ directoryOffset,
1402
+ directoryOffset + directoryBytes > 0x7fffffffn || count >= 0xffffn,
1403
+ comment
1404
+ );
1405
+ if (count > BigInt(archive.limits.maxEntries) || directoryBytes > BigInt(archive.limits.maxDirectoryBytes) || directoryOffset + directoryBytes + BigInt(footer.length) > archive.limits.maxArchiveBytes)
1406
+ throw new RangeError("ZIP append metadata/archive limit exceeded");
1407
+ entry.crc32 = calculateZipChecksum(bytes);
1408
+ local = encodeZipLocalHeader(entry);
1409
+ central = encodeZipCentralHeader(entry);
1410
+ const directory = new Uint8Array(
1411
+ await archive.readExact(archive.directory.offset, Number(archive.directory.size))
1412
+ );
1413
+ archive.signal.throwIfAborted();
1414
+ await file.truncate(Number(archive.directory.offset));
1415
+ for (const chunk of [local, bytes, directory, central, footer]) {
1416
+ archive.signal.throwIfAborted();
1417
+ await file.append(chunk);
1418
+ }
1419
+ archive.signal.throwIfAborted();
1420
+ } finally {
1421
+ await archive.close();
1422
+ }
1423
+ }
1424
+ /** Enumerates validated entries in central-directory order; metadata is indexed once. */
1425
+ async *entries() {
1426
+ for (const path of (await this.getDirectory()).keys()) yield await this.getEntry(path);
1427
+ }
1428
+ /**
1429
+ * Reads the final central entry using at most one maximum-sized header from the directory tail.
1430
+ * Ambiguous header signatures in comments fall back to the cached directory. This supports
1431
+ * final-index discovery without scanning a large directory in the normal indexed profile.
1432
+ */
1433
+ async getLastEntry() {
1434
+ this.signal.throwIfAborted();
1435
+ if (!this.directory.count) return void 0;
1436
+ const length = Number(minimumBigInt(this.directory.size, 46n + 3n * 65535n));
1437
+ const bytes = new Uint8Array(
1438
+ await this.readExact(this.directory.offset + this.directory.size - BigInt(length), length)
1439
+ );
1440
+ const view = new DataView(bytes.buffer);
1441
+ const positions = [];
1442
+ for (let position = 0; position + 46 <= length; position++) {
1443
+ if (view.getUint32(position, true) !== 33639248) continue;
1444
+ const end = position + 46 + view.getUint16(position + 28, true) + view.getUint16(position + 30, true) + view.getUint16(position + 32, true);
1445
+ if (end === length) positions.push(position);
1446
+ }
1447
+ if (positions.length !== 1) {
1448
+ const headers = [...(await this.getDirectory()).values()];
1449
+ return await this.getEntry(headers[headers.length - 1].path);
1450
+ }
1451
+ const metadata3 = decodeZipHeader(bytes.subarray(positions[0]), true);
1452
+ return await this.getValidatedEntry(metadata3.localHeaderOffset, metadata3);
1453
+ }
1454
+ /** Looks up a canonical path; returns undefined when the entry is absent. */
1455
+ async getEntry(path) {
1456
+ this.signal.throwIfAborted();
1457
+ const metadata3 = (await this.getDirectory()).get(path);
1458
+ if (!metadata3) return void 0;
1459
+ let promise = this.entriesByPath.get(path);
1460
+ if (!promise) {
1461
+ promise = this.getValidatedEntry(metadata3.localHeaderOffset, metadata3).catch((error) => {
1462
+ this.entriesByPath.delete(path);
1463
+ throw error;
1464
+ });
1465
+ this.entriesByPath.set(path, promise);
1466
+ }
1467
+ return await promise;
1468
+ }
1469
+ /**
1470
+ * Validates a populated local header at an index-provided offset without a directory scan.
1471
+ * Descriptor entries fall back to the shared directory because their local sizes may be zero.
1472
+ * Direct access validates local layout/bounds; central consistency requires named lookup.
1473
+ */
1474
+ async getEntryAt(localHeaderOffset) {
1475
+ this.signal.throwIfAborted();
1476
+ const existing = this.entriesByOffset.get(localHeaderOffset);
1477
+ if (existing) return await existing;
1478
+ const metadata3 = await this.readLocalHeader(localHeaderOffset);
1479
+ if (metadata3.header.flags & 8) {
1480
+ for (const header of (await this.getDirectory()).values())
1481
+ if (header.localHeaderOffset === localHeaderOffset)
1482
+ return await this.getEntry(header.path);
1483
+ throw new Error("Invalid ZIP archive: indexed offset missing from directory");
1484
+ }
1485
+ return await this.getValidatedEntry(localHeaderOffset, void 0, metadata3);
1486
+ }
1487
+ /** Reads one complete entry and verifies its decoded size and CRC-32. */
1488
+ async read(entryOrPath, options = {}) {
1489
+ const signal = this.getReadSignal(options);
1490
+ signal.throwIfAborted();
1491
+ const entry = await this.resolveEntry(entryOrPath);
1492
+ signal.throwIfAborted();
1493
+ this.checkEntryBudget(entry);
1494
+ if (entry.size > BigInt(Number.MAX_SAFE_INTEGER))
1495
+ throw new RangeError("ZIP allocation is not safely representable");
1496
+ const output = new Uint8Array(Number(entry.size));
1497
+ let offset = 0;
1498
+ for await (const chunk of this.readInBatches(entry, options)) {
1499
+ output.set(chunk, offset);
1500
+ offset += chunk.byteLength;
1501
+ }
1502
+ return output.buffer;
1503
+ }
1504
+ /** Streams decoded chunks with backpressure; consuming through completion verifies CRC-32. */
1505
+ async *readInBatches(entryOrPath, options = {}) {
1506
+ const signal = this.getReadSignal(options);
1507
+ signal.throwIfAborted();
1508
+ const entry = await this.resolveEntry(entryOrPath);
1509
+ signal.throwIfAborted();
1510
+ this.checkEntryBudget(entry);
1511
+ let decodedBytes = 0n;
1512
+ let checksum = 0;
1513
+ const hash = new CRC32Hash({
1514
+ crypto: {
1515
+ onEnd: (result) => {
1516
+ checksum = Number.parseInt(result.hash, 16);
1517
+ }
1518
+ }
1519
+ });
1520
+ const compressed = this.readPayloadChunks(entry, signal);
1521
+ const decoded = entry.compression === "store" ? compressed : new DeflateDecompressor({ raw: true }).decompressBatches(compressed);
1522
+ for await (const chunk of hash.hashBatches(decoded, "hex")) {
1523
+ signal.throwIfAborted();
1524
+ decodedBytes += BigInt(chunk.byteLength);
1525
+ if (decodedBytes > entry.size || decodedBytes > this.limits.maxDecodedBytes)
1526
+ throw new RangeError("ZIP decoded entry size limit exceeded");
1527
+ yield new Uint8Array(chunk);
1528
+ }
1529
+ signal.throwIfAborted();
1530
+ if (decodedBytes !== entry.size) throw new Error("Invalid ZIP archive: decoded size mismatch");
1531
+ if (checksum !== entry.crc32) throw new Error("Invalid ZIP archive: CRC-32 mismatch");
1532
+ }
1533
+ /** Reads only a STORE byte range. Partial reads cannot verify a whole-entry CRC. */
1534
+ async readRange(entryOrPath, options) {
1535
+ const signal = this.getReadSignal(options);
1536
+ signal.throwIfAborted();
1537
+ const entry = await this.resolveEntry(entryOrPath);
1538
+ if (entry.compression !== "store") throw new Error("ZIP ranges require STORE entries");
1539
+ if (options.start < 0n || options.end < options.start || options.end > entry.size || options.end - options.start > BigInt(this.limits.maxReadBytes))
1540
+ throw new RangeError("ZIP byte-range limit exceeded");
1541
+ return await this.readExact(
1542
+ entry.dataOffset + options.start,
1543
+ Number(options.end - options.start),
1544
+ signal
1545
+ );
1546
+ }
1547
+ /** Cancels reads and closes the owned transport exactly once; all subsequent reads reject. */
1548
+ close() {
1549
+ this.controller.abort(new Error("ZIP archive is closed"));
1550
+ this.closePromise ||= this.file.close();
1551
+ return this.closePromise;
1552
+ }
1553
+ /** Resolves a named entry or rejects metadata not issued by this archive. */
1554
+ async resolveEntry(entryOrPath) {
1555
+ this.signal.throwIfAborted();
1556
+ const entry = typeof entryOrPath === "string" ? await this.getEntry(entryOrPath) : entryOrPath;
1557
+ if (!entry || !this.issuedEntries.has(entry))
1558
+ throw new Error("ZIP entry not found or belongs to another archive");
1559
+ return entry;
1560
+ }
1561
+ /** Combines per-read cancellation with the owned lifetime. */
1562
+ getReadSignal(options) {
1563
+ return options.signal ? AbortSignal.any([this.signal, options.signal]) : this.signal;
1564
+ }
1565
+ /** Checks whole-entry consumption before allocation or decompression. */
1566
+ checkEntryBudget(entry) {
1567
+ if (entry.size > this.limits.maxDecodedBytes || entry.compressedSize > this.limits.maxCompressedBytes)
1568
+ throw new RangeError("ZIP entry compressed/decoded byte limit exceeded");
1569
+ }
1570
+ /** Yields compressed bytes without retaining a complete entry. */
1571
+ async *readPayloadChunks(entry, signal) {
1572
+ const chunkBytes = Math.min(this.limits.chunkBytes, this.limits.maxReadBytes);
1573
+ for (let offset = 0n; offset < entry.compressedSize; offset += BigInt(chunkBytes)) {
1574
+ const length = Number(minimumBigInt(BigInt(chunkBytes), entry.compressedSize - offset));
1575
+ yield await this.readExact(entry.dataOffset + offset, length, signal);
1576
+ }
1577
+ }
1578
+ /** Performs exact, bounded physical reads and rejects truncated transports. */
1579
+ async readExact(offset, length, signal = this.signal) {
1580
+ signal.throwIfAborted();
1581
+ if (offset < 0n || !Number.isSafeInteger(length) || length < 0 || offset + BigInt(length) > this.size)
1582
+ throw new Error("Invalid ZIP archive: read outside file");
1583
+ const output = new Uint8Array(length);
1584
+ for (let copied = 0; copied < length; ) {
1585
+ const readBytes = Math.min(length - copied, this.limits.maxReadBytes);
1586
+ const bytes = await this.file.read(offset + BigInt(copied), readBytes, signal);
1587
+ signal.throwIfAborted();
1588
+ if (bytes.byteLength !== readBytes)
1589
+ throw new Error("Invalid ZIP archive: truncated file read");
1590
+ output.set(new Uint8Array(bytes), copied);
1591
+ copied += readBytes;
1592
+ }
1593
+ return output.buffer;
1594
+ }
1595
+ /** Finds an EOCD whose complete comment ends at EOF, not a signature embedded in the comment. */
1596
+ async readDirectoryLocation() {
1597
+ const magic = new DataView(await this.readExact(0n, 4)).getUint32(0, true);
1598
+ if (magic !== 67324752 && magic !== 101010256 && magic !== 101075792)
1599
+ throw new Error("Unsupported ZIP prefix or archive format");
1600
+ const tailLength = Number(minimumBigInt(this.size, 65557n));
1601
+ const tailStart = this.size - BigInt(tailLength);
1602
+ const tail = new DataView(await this.readExact(tailStart, tailLength));
1603
+ let position = -1;
1604
+ for (let candidate = tailLength - 22; candidate >= 0; candidate--) {
1605
+ if (tail.getUint32(candidate, true) !== 101010256 || candidate + 22 + tail.getUint16(candidate + 20, true) !== tailLength)
1606
+ continue;
1607
+ if (position < 0) position = candidate;
1608
+ const emptyDirectoryAtEnd = tail.getUint32(candidate + 12, true) === 0 && BigInt(tail.getUint32(candidate + 16, true)) === tailStart + BigInt(candidate);
1609
+ if (tail.getUint16(candidate + 10, true) !== 0 || emptyDirectoryAtEnd || magic === 101075792) {
1610
+ position = candidate;
1611
+ break;
1612
+ }
1613
+ }
1614
+ if (position < 0) throw new Error("Invalid ZIP archive: end record not found");
1615
+ const disk = tail.getUint16(position + 4, true);
1616
+ const directoryDisk = tail.getUint16(position + 6, true);
1617
+ if (disk !== 0 && disk !== 65535 || directoryDisk !== 0 && directoryDisk !== 65535)
1618
+ throw new Error("Unsupported split ZIP archive");
1619
+ const onDisk = BigInt(tail.getUint16(position + 8, true));
1620
+ let count = BigInt(tail.getUint16(position + 10, true));
1621
+ let size = BigInt(tail.getUint32(position + 12, true));
1622
+ let offset = BigInt(tail.getUint32(position + 16, true));
1623
+ let footerOffset = tailStart + BigInt(position);
1624
+ let zip64 = false;
1625
+ if (footerOffset >= 20n) {
1626
+ const locator = new DataView(await this.readExact(footerOffset - 20n, 20));
1627
+ const locatorInsideDirectory = size !== 0xffffffffn && offset !== 0xffffffffn && offset + size > footerOffset - 20n;
1628
+ if (locator.getUint32(0, true) === 117853008 && !locatorInsideDirectory) {
1629
+ zip64 = true;
1630
+ if (locator.getUint32(4, true) || locator.getUint32(16, true) !== 1)
1631
+ throw new Error("Unsupported split ZIP64 archive");
1632
+ const zip64Offset = locator.getBigUint64(8, true);
1633
+ const record = new DataView(await this.readExact(zip64Offset, 56));
1634
+ if (record.getUint32(0, true) !== 101075792 || record.getBigUint64(4, true) < 44n || zip64Offset + 12n + record.getBigUint64(4, true) !== footerOffset - 20n || record.getUint32(16, true) || record.getUint32(20, true) || record.getBigUint64(24, true) !== record.getBigUint64(32, true))
1635
+ throw new Error("Invalid ZIP64 end record");
1636
+ const zip64Count = record.getBigUint64(32, true);
1637
+ const zip64Size = record.getBigUint64(40, true);
1638
+ const zip64DirectoryOffset = record.getBigUint64(48, true);
1639
+ if (onDisk !== 0xffffn && onDisk !== zip64Count || count !== 0xffffn && count !== zip64Count || size !== 0xffffffffn && size !== zip64Size || offset !== 0xffffffffn && offset !== zip64DirectoryOffset)
1640
+ throw new Error("Invalid ZIP64 legacy end values");
1641
+ count = zip64Count;
1642
+ size = zip64Size;
1643
+ offset = zip64DirectoryOffset;
1644
+ footerOffset = zip64Offset;
1645
+ } else if (size === 0xffffffffn || offset === 0xffffffffn)
1646
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
1647
+ } else if (size === 0xffffffffn || offset === 0xffffffffn)
1648
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
1649
+ if (!zip64) {
1650
+ if (disk === 65535 || directoryDisk === 65535)
1651
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
1652
+ if (onDisk !== count) throw new Error("Invalid ZIP archive: inconsistent entry counts");
1653
+ }
1654
+ if (count > BigInt(this.limits.maxEntries) || size > BigInt(this.limits.maxDirectoryBytes))
1655
+ throw new RangeError("ZIP directory entry/byte limit exceeded");
1656
+ if (offset + size > footerOffset || size < count * 46n || count === 0n !== (size === 0n))
1657
+ throw new Error("Invalid ZIP archive: directory outside bounds");
1658
+ if (count && new DataView(await this.readExact(offset, 4)).getUint32(0, true) !== 33639248)
1659
+ throw new Error("Invalid ZIP archive: directory signature missing");
1660
+ const comment = decodeZipText(new Uint8Array(tail.buffer, position + 22), false);
1661
+ return { count, size, offset, comment };
1662
+ }
1663
+ /** Indexes central metadata once, without eagerly reading every local header. */
1664
+ getDirectory() {
1665
+ this.signal.throwIfAborted();
1666
+ this.directoryPromise ||= this.readDirectory().catch((error) => {
1667
+ this.directoryPromise = void 0;
1668
+ this.nextOffsets.clear();
1669
+ throw error;
1670
+ });
1671
+ return this.directoryPromise;
1672
+ }
1673
+ /** Parses exact directory records, including comments and Unicode/ZIP64 extras. */
1674
+ async readDirectory() {
1675
+ const bytes = new Uint8Array(
1676
+ await this.readExact(this.directory.offset, Number(this.directory.size))
1677
+ );
1678
+ const view = new DataView(bytes.buffer);
1679
+ const entries = /* @__PURE__ */ new Map();
1680
+ const offsets = /* @__PURE__ */ new Set();
1681
+ let position = 0;
1682
+ for (let index = 0n; index < this.directory.count; index++) {
1683
+ if (position + 46 > bytes.byteLength)
1684
+ throw new Error("Invalid ZIP archive: truncated directory");
1685
+ const length = 46 + view.getUint16(position + 28, true) + view.getUint16(position + 30, true) + view.getUint16(position + 32, true);
1686
+ const header = decodeZipHeader(bytes.subarray(position, position + length), true);
1687
+ if (header.localHeaderOffset + 30n > this.directory.offset)
1688
+ throw new Error("Invalid ZIP archive: local header outside data region");
1689
+ if (entries.has(header.path) || offsets.has(header.localHeaderOffset))
1690
+ throw new Error("Invalid ZIP archive: duplicate path or local-header offset");
1691
+ entries.set(header.path, header);
1692
+ offsets.add(header.localHeaderOffset);
1693
+ position += length;
1694
+ }
1695
+ const sortedOffsets = [...offsets].sort(
1696
+ (left, right) => left < right ? -1 : left > right ? 1 : 0
1697
+ );
1698
+ sortedOffsets.forEach(
1699
+ (offset, index) => this.nextOffsets.set(offset, sortedOffsets[index + 1] ?? this.directory.offset)
1700
+ );
1701
+ if (position !== bytes.byteLength)
1702
+ throw new Error("Invalid ZIP archive: directory length mismatch");
1703
+ return entries;
1704
+ }
1705
+ /** Reads local metadata without inspecting unrelated payloads. */
1706
+ async readLocalHeader(offset) {
1707
+ if (offset < 0n || offset + 30n > this.directory.offset)
1708
+ throw new Error("Invalid ZIP archive: local header outside data region");
1709
+ const fixed = new DataView(await this.readExact(offset, 30));
1710
+ const length = 30 + fixed.getUint16(26, true) + fixed.getUint16(28, true);
1711
+ if (offset + BigInt(length) > this.directory.offset)
1712
+ throw new Error("Invalid ZIP archive: local metadata overlaps directory");
1713
+ const bytes = new Uint8Array(length);
1714
+ bytes.set(new Uint8Array(fixed.buffer));
1715
+ bytes.set(new Uint8Array(await this.readExact(offset + 30n, length - 30)), 30);
1716
+ const header = decodeZipHeader(bytes, false);
1717
+ return { header, dataOffset: offset + BigInt(length) };
1718
+ }
1719
+ /** Shares local validation; a later named lookup additionally verifies central metadata. */
1720
+ async getValidatedEntry(offset, central, localMetadata) {
1721
+ if (central) return await this.validateEntry(offset, central);
1722
+ let entry = this.entriesByOffset.get(offset);
1723
+ if (!entry) {
1724
+ entry = this.validateEntry(offset, void 0, localMetadata).catch((error) => {
1725
+ this.entriesByOffset.delete(offset);
1726
+ throw error;
1727
+ });
1728
+ this.entriesByOffset.set(offset, entry);
1729
+ }
1730
+ return await entry;
1731
+ }
1732
+ /** Validates local/central identity, payload bounds and signed or unsigned descriptors. */
1733
+ async validateEntry(offset, central, localMetadata) {
1734
+ const { header: local, dataOffset } = localMetadata ?? await this.readLocalHeader(offset);
1735
+ const metadata3 = central || local;
1736
+ const descriptor = Boolean(local.flags & 8);
1737
+ if (central && (central.flags !== local.flags || central.method !== local.method || central.nameBytes.length !== local.nameBytes.length || central.nameBytes.some((value, index) => value !== local.nameBytes[index]) || !descriptor && (central.crc32 !== local.crc32 || central.size !== local.size || central.compressedSize !== local.compressedSize)))
1738
+ throw new Error("Invalid ZIP archive: local/central metadata mismatch");
1739
+ if (metadata3.method === 0 && metadata3.size !== metadata3.compressedSize)
1740
+ throw new Error("Invalid ZIP archive: STORE sizes mismatch");
1741
+ if (central && descriptor && (local.crc32 !== 0 && local.crc32 !== central.crc32 || local.size !== 0n && local.size !== central.size || local.compressedSize !== 0n && local.compressedSize !== central.compressedSize))
1742
+ throw new Error("Invalid ZIP archive: descriptor local/central metadata mismatch");
1743
+ const payloadEnd = dataOffset + metadata3.compressedSize;
1744
+ const entryEnd = central ? this.nextOffsets.get(offset) ?? this.directory.offset : this.directory.offset;
1745
+ if (payloadEnd > entryEnd) throw new Error("Invalid ZIP archive: payload overlaps directory");
1746
+ if (descriptor)
1747
+ await this.validateDescriptor(
1748
+ payloadEnd,
1749
+ metadata3,
1750
+ local.zip64 || Boolean(central == null ? void 0 : central.zip64),
1751
+ entryEnd
1752
+ );
1753
+ const entry = Object.freeze({
1754
+ path: metadata3.path,
1755
+ directory: metadata3.path.endsWith("/"),
1756
+ compression: metadata3.method === 0 ? "store" : "deflate",
1757
+ size: metadata3.size,
1758
+ compressedSize: metadata3.compressedSize,
1759
+ crc32: metadata3.crc32,
1760
+ localHeaderOffset: offset,
1761
+ dataOffset,
1762
+ comment: (central == null ? void 0 : central.comment) || ""
1763
+ });
1764
+ this.issuedEntries.add(entry);
1765
+ return entry;
1766
+ }
1767
+ /** Resolves the optional descriptor signature using the expected CRC and sizes. */
1768
+ async validateDescriptor(offset, metadata3, zip64, entryEnd) {
1769
+ const length = Number(minimumBigInt(24n, entryEnd - offset));
1770
+ const bytes = new DataView(await this.readExact(offset, length));
1771
+ for (const wide of zip64 ? [true, false] : [false, true]) {
1772
+ if (!wide && (metadata3.size > 0xffffffffn || metadata3.compressedSize > 0xffffffffn)) continue;
1773
+ const descriptorLength = wide ? 20 : 12;
1774
+ for (const prefix of [4, 0]) {
1775
+ if (length < prefix + descriptorLength || prefix && bytes.getUint32(0, true) !== 134695760)
1776
+ continue;
1777
+ const compressed = wide ? bytes.getBigUint64(prefix + 4, true) : BigInt(bytes.getUint32(prefix + 4, true));
1778
+ const decoded = wide ? bytes.getBigUint64(prefix + 12, true) : BigInt(bytes.getUint32(prefix + 8, true));
1779
+ if (bytes.getUint32(prefix, true) === metadata3.crc32 && compressed === metadata3.compressedSize && decoded === metadata3.size)
1780
+ return;
1781
+ }
1782
+ }
1783
+ throw new Error("Invalid ZIP archive: data descriptor mismatch");
1784
+ }
1785
+ };
1786
+ }
1787
+ });
1788
+
1789
+ // src/zip/zip-loader.ts
1790
+ var zip_loader_exports = {};
1791
+ __export(zip_loader_exports, {
1792
+ ZipLoaderWithParser: () => ZipLoaderWithParser
1793
+ });
1794
+ async function parseZip(input, options = {}) {
1795
+ var _a;
1796
+ const maximum = ((_a = options.zip) == null ? void 0 : _a.maxTotalDecodedBytes) ?? ZipLoader.options.zip.maxTotalDecodedBytes;
1797
+ if (typeof maximum !== "bigint" || maximum < 0n)
1798
+ throw new RangeError("Invalid ZIP total decoded-byte limit");
1799
+ const archive = await openZipArchive(input, options.zip);
1800
+ try {
1801
+ const entries = [];
1802
+ let totalBytes = 0n;
1803
+ for await (const entry of archive.entries()) {
1804
+ if (entry.directory) continue;
1805
+ totalBytes += entry.size;
1806
+ if (totalBytes > maximum) throw new RangeError("ZIP total decoded-byte limit exceeded");
1807
+ entries.push(entry);
1808
+ }
1809
+ const files = /* @__PURE__ */ Object.create(null);
1810
+ for (const entry of entries) files[entry.path] = await archive.read(entry);
1811
+ return files;
1812
+ } finally {
1813
+ await archive.close();
1814
+ }
1815
+ }
1816
+ var _preload, metadata, ZipLoaderWithParser;
1817
+ var init_zip_loader = __esm({
1818
+ "src/zip/zip-loader.ts"() {
1819
+ "use strict";
1820
+ init_zip_loader_types();
1821
+ init_zip_archive();
1822
+ ({ preload: _preload, ...metadata } = ZipLoader);
1823
+ ZipLoaderWithParser = {
1824
+ ...metadata,
1825
+ parse: parseZip
1826
+ };
1827
+ }
1828
+ });
1829
+
1830
+ // dist/zip/zip-loader.js
1831
+ var zip_loader_exports2 = {};
1832
+ __export(zip_loader_exports2, {
1833
+ ZipLoaderWithParser: () => ZipLoaderWithParser2
1834
+ });
1835
+ module.exports = __toCommonJS(zip_loader_exports2);
1836
+
1837
+ // dist/zip/zip-format.js
1838
+ var ZipFormat = {
1839
+ name: "Zip Archive",
1840
+ id: "zip",
1841
+ module: "archives",
1842
+ encoding: "zip",
1843
+ format: "zip",
1844
+ extensions: ["zip"],
1845
+ mimeTypes: ["application/zip"],
1846
+ category: "archive",
1847
+ binary: true,
1848
+ tests: ["PK"]
1849
+ };
1850
+
1851
+ // dist/zip/zip-loader-types.js
1852
+ var VERSION2 = true ? "5.0.0-alpha.14" : "latest";
1853
+ var ZipLoader2 = {
1854
+ ...ZipFormat,
1855
+ version: VERSION2,
1856
+ dataType: null,
1857
+ batchType: null,
1858
+ options: { zip: { maxTotalDecodedBytes: 64n * 1024n * 1024n } },
1859
+ /** Loads the parser implementation through its installed package subpath. */
1860
+ async preload() {
1861
+ const { ZipLoaderWithParser: ZipLoaderWithParser3 } = await Promise.resolve().then(() => (init_zip_loader(), zip_loader_exports));
1862
+ return ZipLoaderWithParser3;
1863
+ }
1864
+ };
1865
+
1866
+ // dist/zip/zip-archive.js
1867
+ init_loader_utils();
1868
+ init_deflate_decompressor();
1869
+ init_src();
1870
+
1871
+ // dist/zip/lib/zip-entry-metadata.js
1872
+ init_src();
1873
+
1874
+ // dist/zip/lib/zip64-extra-field.js
1875
+ var ZIP64_EXTRA_FIELD_ID2 = 1;
1876
+ function parseZip64ExtraField2(extraField, expectedFields) {
1877
+ const values = {};
1878
+ if (expectedFields.length === 0) {
1879
+ return values;
1880
+ }
1881
+ const expectedPayloadLength = expectedFields.reduce((totalByteLength, field) => totalByteLength + field.byteLength, 0);
1882
+ let recordOffset = 0;
1883
+ while (recordOffset < extraField.byteLength) {
1884
+ if (recordOffset + 4 > extraField.byteLength) {
1885
+ throw new Error("Invalid ZIP archive: truncated extra-field record header while reading ZIP64 data");
1886
+ }
1887
+ const headerId = extraField.getUint16(recordOffset, true);
1888
+ const payloadLength = extraField.getUint16(recordOffset + 2, true);
1889
+ const payloadOffset = recordOffset + 4;
1890
+ const nextRecordOffset = payloadOffset + payloadLength;
1891
+ if (nextRecordOffset > extraField.byteLength) {
1892
+ throw new Error("Invalid ZIP archive: truncated extra-field record payload while reading ZIP64 data");
1893
+ }
1894
+ if (headerId === ZIP64_EXTRA_FIELD_ID2) {
1895
+ if (payloadLength !== expectedPayloadLength) {
1896
+ throw new Error("Invalid ZIP archive: ZIP64 extended information has an unexpected payload size");
1897
+ }
1898
+ let fieldOffset = payloadOffset;
1899
+ for (const field of expectedFields) {
1900
+ values[field.name] = field.byteLength === 8 ? extraField.getBigUint64(fieldOffset, true) : BigInt(extraField.getUint32(fieldOffset, true));
1901
+ fieldOffset += field.byteLength;
1902
+ }
1903
+ return values;
1904
+ }
1905
+ recordOffset = nextRecordOffset;
1906
+ }
1907
+ throw new Error("Invalid ZIP archive: required ZIP64 extended information is missing");
1908
+ }
1909
+
1910
+ // dist/zip/lib/zip-entry-metadata.js
1911
+ var CP437_HIGH2 = "\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";
1912
+ function decodeZipHeader2(bytes, central) {
1913
+ const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1914
+ const fixedBytes = central ? 46 : 30;
1915
+ if (bytes.byteLength < fixedBytes || header.getUint32(0, true) !== (central ? 33639248 : 67324752))
1916
+ throw new Error("Invalid ZIP archive: missing entry header");
1917
+ const nameLength = header.getUint16(central ? 28 : 26, true);
1918
+ const extraLength = header.getUint16(central ? 30 : 28, true);
1919
+ const commentLength = central ? header.getUint16(32, true) : 0;
1920
+ if (bytes.byteLength !== fixedBytes + nameLength + extraLength + commentLength)
1921
+ throw new Error("Invalid ZIP archive: truncated entry metadata");
1922
+ const flags = header.getUint16(central ? 8 : 6, true);
1923
+ const method = header.getUint16(central ? 10 : 8, true);
1924
+ if (flags & (1 | 64 | 8192))
1925
+ throw new Error("Unsupported ZIP encryption");
1926
+ if (flags & ~(8 | 2048 | (method === 8 ? 6 : 0)))
1927
+ throw new Error("Unsupported ZIP flags");
1928
+ if (method !== 0 && method !== 8)
1929
+ throw new Error(`Unsupported ZIP compression method: ${method}`);
1930
+ let compressedSize = BigInt(header.getUint32(central ? 20 : 18, true));
1931
+ let size = BigInt(header.getUint32(central ? 24 : 22, true));
1932
+ let localHeaderOffset = central ? BigInt(header.getUint32(42, true)) : 0n;
1933
+ let disk = central ? BigInt(header.getUint16(34, true)) : 0n;
1934
+ let zip64 = compressedSize === 0xffffffffn || size === 0xffffffffn;
1935
+ const fields = [];
1936
+ if (central) {
1937
+ if (size === 0xffffffffn)
1938
+ fields.push({ name: "size", byteLength: 8 });
1939
+ if (compressedSize === 0xffffffffn)
1940
+ fields.push({ name: "compressedSize", byteLength: 8 });
1941
+ if (localHeaderOffset === 0xffffffffn)
1942
+ fields.push({ name: "localHeaderOffset", byteLength: 8 });
1943
+ if (disk === 0xffffn)
1944
+ fields.push({ name: "disk", byteLength: 4 });
1945
+ } else if (zip64)
1946
+ fields.push({ name: "size", byteLength: 8 }, { name: "compressedSize", byteLength: 8 });
1947
+ const extraBytes = bytes.subarray(fixedBytes + nameLength, fixedBytes + nameLength + extraLength);
1948
+ const extra = new DataView(extraBytes.buffer, extraBytes.byteOffset, extraBytes.byteLength);
1949
+ const extraValues = parseZip64ExtraField2(extra, fields);
1950
+ if (size === 0xffffffffn)
1951
+ size = extraValues.size;
1952
+ if (compressedSize === 0xffffffffn)
1953
+ compressedSize = extraValues.compressedSize;
1954
+ if (localHeaderOffset === 0xffffffffn)
1955
+ localHeaderOffset = extraValues.localHeaderOffset;
1956
+ if (disk === 0xffffn)
1957
+ disk = extraValues.disk;
1958
+ if (disk !== 0n)
1959
+ throw new Error("Unsupported split ZIP archive");
1960
+ const nameBytes = bytes.subarray(fixedBytes, fixedBytes + nameLength);
1961
+ let path = decodeZipText2(nameBytes, Boolean(flags & 2048));
1962
+ const commentBytes = bytes.subarray(fixedBytes + nameLength + extraLength);
1963
+ let comment = decodeZipText2(commentBytes, Boolean(flags & 2048));
1964
+ for (let offset = 0; offset < extra.byteLength; ) {
1965
+ if (offset + 4 > extra.byteLength)
1966
+ throw new Error("Invalid ZIP archive: truncated extra field");
1967
+ const identifier = extra.getUint16(offset, true);
1968
+ const length = extra.getUint16(offset + 2, true);
1969
+ if (offset + 4 + length > extra.byteLength)
1970
+ throw new Error("Invalid ZIP archive: truncated extra field");
1971
+ if (!central && flags & 8 && identifier === 1) {
1972
+ if (length >= 16)
1973
+ zip64 = true;
1974
+ }
1975
+ if (identifier === 28789 || identifier === 25461) {
1976
+ const original = identifier === 28789 ? nameBytes : commentBytes;
1977
+ if (length < 5)
1978
+ throw new Error("Invalid ZIP archive: truncated Unicode extra field");
1979
+ if (extra.getUint8(offset + 4) === 1 && extra.getUint32(offset + 5, true) === calculateZipChecksum2(original)) {
1980
+ const text = decodeZipText2(extraBytes.subarray(offset + 9, offset + 4 + length), true);
1981
+ if (identifier === 28789)
1982
+ path = text;
1983
+ else
1984
+ comment = text;
1985
+ }
1986
+ }
1987
+ offset += 4 + length;
1988
+ }
1989
+ validateZipPath2(path);
1990
+ return {
1991
+ path,
1992
+ nameBytes,
1993
+ flags,
1994
+ method,
1995
+ crc32: header.getUint32(central ? 16 : 14, true),
1996
+ compressedSize,
1997
+ size,
1998
+ localHeaderOffset,
1999
+ comment,
2000
+ zip64
2001
+ };
2002
+ }
2003
+ function decodeZipText2(bytes, utf8) {
2004
+ if (utf8)
2005
+ return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
2006
+ return Array.from(bytes, (value) => value < 128 ? String.fromCharCode(value) : CP437_HIGH2[value - 128]).join("");
2007
+ }
2008
+ function validateZipPath2(path) {
2009
+ const segments = path.endsWith("/") ? path.slice(0, -1).split("/") : path.split("/");
2010
+ if (!path || path.includes("\\") || path.includes("\0") || /^[A-Za-z]:/.test(path) || segments.some((segment) => !segment || segment === "." || segment === ".."))
2011
+ throw new Error("Invalid ZIP archive: noncanonical relative path");
2012
+ }
2013
+ function calculateZipChecksum2(bytes) {
2014
+ return Number.parseInt(new CRC32Hash().hashSync(bytes.slice().buffer, "hex"), 16);
2015
+ }
2016
+ function encodeUtf8Text2(value) {
2017
+ const bytes = new TextEncoder().encode(value);
2018
+ if (new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes) !== value)
2019
+ throw new TypeError("ZIP names and entry comments must be well-formed Unicode");
2020
+ return bytes;
2021
+ }
2022
+
2023
+ // dist/zip/lib/zip-serialization.js
2024
+ var ZIP32_SENTINEL2 = 0xffffffffn;
2025
+ function encodeZipLocalHeader2(entry) {
2026
+ validateHeaderEntry2(entry);
2027
+ const bytes = new Uint8Array(30 + entry.nameBytes.length + (entry.zip64 ? 20 : 0));
2028
+ const view = new DataView(bytes.buffer);
2029
+ view.setUint32(0, 67324752, true);
2030
+ view.setUint16(4, getZipVersion2(entry), true);
2031
+ view.setUint16(6, entry.flags, true);
2032
+ view.setUint16(8, entry.method, true);
2033
+ view.setUint32(10, encodeZipTimestamp2(entry.date), true);
2034
+ const descriptor = Boolean(entry.flags & 8);
2035
+ view.setUint32(14, descriptor ? 0 : entry.crc32, true);
2036
+ view.setUint32(18, entry.zip64 ? Number(ZIP32_SENTINEL2) : descriptor ? 0 : Number(entry.compressedSize), true);
2037
+ view.setUint32(22, entry.zip64 ? Number(ZIP32_SENTINEL2) : descriptor ? 0 : Number(entry.size), true);
2038
+ view.setUint16(26, entry.nameBytes.length, true);
2039
+ view.setUint16(28, entry.zip64 ? 20 : 0, true);
2040
+ bytes.set(entry.nameBytes, 30);
2041
+ if (entry.zip64) {
2042
+ const extraOffset = 30 + entry.nameBytes.length;
2043
+ view.setUint16(extraOffset, 1, true);
2044
+ view.setUint16(extraOffset + 2, 16, true);
2045
+ view.setBigUint64(extraOffset + 4, descriptor ? 0n : entry.size, true);
2046
+ view.setBigUint64(extraOffset + 12, descriptor ? 0n : entry.compressedSize, true);
2047
+ }
2048
+ return bytes;
2049
+ }
2050
+ function encodeZipCentralHeader2(entry) {
2051
+ validateHeaderEntry2(entry);
2052
+ const comment = entry.commentBytes ?? new Uint8Array();
2053
+ const extraBytes = entry.zip64 ? 28 : 0;
2054
+ const bytes = new Uint8Array(46 + entry.nameBytes.length + extraBytes + comment.length);
2055
+ const view = new DataView(bytes.buffer);
2056
+ view.setUint32(0, 33639248, true);
2057
+ view.setUint16(4, entry.zip64 ? 45 : 20, true);
2058
+ view.setUint16(6, getZipVersion2(entry), true);
2059
+ view.setUint16(8, entry.flags, true);
2060
+ view.setUint16(10, entry.method, true);
2061
+ view.setUint32(12, encodeZipTimestamp2(entry.date), true);
2062
+ view.setUint32(16, entry.crc32, true);
2063
+ view.setUint32(20, entry.zip64 ? Number(ZIP32_SENTINEL2) : Number(entry.compressedSize), true);
2064
+ view.setUint32(24, entry.zip64 ? Number(ZIP32_SENTINEL2) : Number(entry.size), true);
2065
+ view.setUint16(28, entry.nameBytes.length, true);
2066
+ view.setUint16(30, extraBytes, true);
2067
+ view.setUint16(32, comment.length, true);
2068
+ view.setUint32(38, entry.directory ? 16 : 0, true);
2069
+ view.setUint32(42, entry.zip64 ? Number(ZIP32_SENTINEL2) : Number(entry.localHeaderOffset), true);
2070
+ bytes.set(entry.nameBytes, 46);
2071
+ if (entry.zip64) {
2072
+ const extraOffset = 46 + entry.nameBytes.length;
2073
+ view.setUint16(extraOffset, 1, true);
2074
+ view.setUint16(extraOffset + 2, 24, true);
2075
+ view.setBigUint64(extraOffset + 4, entry.size, true);
2076
+ view.setBigUint64(extraOffset + 12, entry.compressedSize, true);
2077
+ view.setBigUint64(extraOffset + 20, entry.localHeaderOffset, true);
2078
+ }
2079
+ bytes.set(comment, 46 + entry.nameBytes.length + extraBytes);
2080
+ return bytes;
2081
+ }
2082
+ function encodeZipEndRecords2(count, directorySize, directoryOffset, zip64, comment = new Uint8Array()) {
2083
+ for (const value of [count, directorySize, directoryOffset, directoryOffset + directorySize])
2084
+ validateUint642(value);
2085
+ if (comment.length > 65535)
2086
+ throw new RangeError("ZIP archive comment exceeds 65535 bytes");
2087
+ if (!zip64 && (count > 0xffffn || directorySize >= ZIP32_SENTINEL2 || directoryOffset >= ZIP32_SENTINEL2))
2088
+ throw new RangeError("ZIP32 end record capacity exceeded");
2089
+ const bytes = new Uint8Array((zip64 ? 98 : 22) + comment.length);
2090
+ const view = new DataView(bytes.buffer);
2091
+ if (zip64) {
2092
+ view.setUint32(0, 101075792, true);
2093
+ view.setBigUint64(4, 44n, true);
2094
+ view.setUint16(12, 45, true);
2095
+ view.setUint16(14, 45, true);
2096
+ view.setBigUint64(24, count, true);
2097
+ view.setBigUint64(32, count, true);
2098
+ view.setBigUint64(40, directorySize, true);
2099
+ view.setBigUint64(48, directoryOffset, true);
2100
+ view.setUint32(56, 117853008, true);
2101
+ view.setBigUint64(64, directoryOffset + directorySize, true);
2102
+ view.setUint32(72, 1, true);
2103
+ }
2104
+ const endOffset = zip64 ? 76 : 0;
2105
+ view.setUint32(endOffset, 101010256, true);
2106
+ view.setUint16(endOffset + 8, zip64 ? 65535 : Number(count), true);
2107
+ view.setUint16(endOffset + 10, zip64 ? 65535 : Number(count), true);
2108
+ view.setUint32(endOffset + 12, zip64 ? Number(ZIP32_SENTINEL2) : Number(directorySize), true);
2109
+ view.setUint32(endOffset + 16, zip64 ? Number(ZIP32_SENTINEL2) : Number(directoryOffset), true);
2110
+ view.setUint16(endOffset + 20, comment.length, true);
2111
+ bytes.set(comment, endOffset + 22);
2112
+ return bytes;
2113
+ }
2114
+ function encodeZipTimestamp2(date) {
2115
+ if (!(date instanceof Date) || !Number.isFinite(date.getTime()) || date.getUTCFullYear() < 1980 || date.getUTCFullYear() > 2107)
2116
+ throw new RangeError("ZIP timestamp must be a valid UTC date in 1980\u20132107");
2117
+ const time = date.getUTCHours() << 11 | date.getUTCMinutes() << 5 | Math.floor(date.getUTCSeconds() / 2);
2118
+ const day = date.getUTCFullYear() - 1980 << 9 | date.getUTCMonth() + 1 << 5 | date.getUTCDate();
2119
+ return (day << 16 | time) >>> 0;
2120
+ }
2121
+ function getZipVersion2(entry) {
2122
+ return entry.zip64 ? 45 : entry.method === 8 || entry.flags & 8 ? 20 : 10;
2123
+ }
2124
+ function validateHeaderEntry2(entry) {
2125
+ var _a;
2126
+ if (!entry.nameBytes.length || entry.nameBytes.length > 65535 || (((_a = entry.commentBytes) == null ? void 0 : _a.length) ?? 0) > 65535)
2127
+ throw new RangeError("ZIP name/comment exceeds header capacity");
2128
+ for (const value of [entry.size, entry.compressedSize, entry.localHeaderOffset])
2129
+ validateUint642(value);
2130
+ if (!entry.zip64 && [entry.size, entry.compressedSize, entry.localHeaderOffset].some((value) => value >= ZIP32_SENTINEL2))
2131
+ throw new RangeError("ZIP32 entry capacity exceeded");
2132
+ }
2133
+ function validateUint642(value) {
2134
+ if (typeof value !== "bigint" || value < 0n || value > 0xffffffffffffffffn)
2135
+ throw new RangeError("ZIP64 unsigned integer capacity exceeded");
2136
+ }
2137
+
2138
+ // dist/zip/zip-archive.js
2139
+ var DEFAULT_OPTIONS2 = {
2140
+ maxArchiveBytes: 1024n ** 4n,
2141
+ maxDirectoryBytes: 32 * 1024 * 1024,
2142
+ maxEntries: 1e5,
2143
+ maxReadBytes: 1024 * 1024,
2144
+ maxCompressedBytes: 64n * 1024n * 1024n,
2145
+ maxDecodedBytes: 64n * 1024n * 1024n,
2146
+ chunkBytes: 64 * 1024
2147
+ };
2148
+ var ZipArchive2 = class _ZipArchive {
2149
+ /** Archive byte length, without losing ZIP64 precision. */
2150
+ size;
2151
+ /** Archive comment, decoded using legacy ZIP CP437. */
2152
+ comment;
2153
+ /** Shared file limits captured at open time. */
2154
+ limits;
2155
+ /** Owned random-access transport. */
2156
+ file;
2157
+ /** File lifetime, including in-flight operations. */
2158
+ controller = new AbortController();
2159
+ /** Initialization/caller cancellation combined with close. */
2160
+ signal;
2161
+ /** Validated directory boundary. */
2162
+ directory;
2163
+ /** A single directory-index promise shared by concurrent lookups. */
2164
+ directoryPromise;
2165
+ /** Local-header validation shared by repeated path reads. */
2166
+ entriesByOffset = /* @__PURE__ */ new Map();
2167
+ /** Central-validated named lookups share their local-header work. */
2168
+ entriesByPath = /* @__PURE__ */ new Map();
2169
+ /** Next local-header boundary for central-validated, nonoverlapping payloads. */
2170
+ nextOffsets = /* @__PURE__ */ new Map();
2171
+ /** Only entries issued by this archive can be used for reads. */
2172
+ issuedEntries = /* @__PURE__ */ new WeakSet();
2173
+ /** Idempotent file cleanup, including open failure. */
2174
+ closePromise;
2175
+ /** Captures the owned transport and validates independent limits. */
2176
+ constructor(file, size, options) {
2177
+ this.file = file;
2178
+ this.size = size;
2179
+ this.comment = "";
2180
+ this.limits = {
2181
+ maxArchiveBytes: options.maxArchiveBytes ?? DEFAULT_OPTIONS2.maxArchiveBytes,
2182
+ maxDirectoryBytes: options.maxDirectoryBytes ?? DEFAULT_OPTIONS2.maxDirectoryBytes,
2183
+ maxEntries: options.maxEntries ?? DEFAULT_OPTIONS2.maxEntries,
2184
+ maxReadBytes: options.maxReadBytes ?? DEFAULT_OPTIONS2.maxReadBytes,
2185
+ maxCompressedBytes: options.maxCompressedBytes ?? DEFAULT_OPTIONS2.maxCompressedBytes,
2186
+ maxDecodedBytes: options.maxDecodedBytes ?? DEFAULT_OPTIONS2.maxDecodedBytes,
2187
+ chunkBytes: options.chunkBytes ?? DEFAULT_OPTIONS2.chunkBytes
2188
+ };
2189
+ for (const [name, value] of Object.entries(this.limits)) {
2190
+ const bigintLimit = ["maxArchiveBytes", "maxCompressedBytes", "maxDecodedBytes"].includes(name);
2191
+ if (bigintLimit ? typeof value !== "bigint" || value < 0n : typeof value !== "number" || !Number.isSafeInteger(value) || value < 1)
2192
+ throw new RangeError(`Invalid ZIP ${name} limit`);
2193
+ }
2194
+ this.signal = options.signal ? AbortSignal.any([this.controller.signal, options.signal]) : this.controller.signal;
2195
+ }
2196
+ /** Initializes directory bounds without scanning entries or reading their payloads. */
2197
+ static async open(input, options = {}) {
2198
+ var _a;
2199
+ const file = normalizeZipInput2(input);
2200
+ let archive;
2201
+ try {
2202
+ const advertisedSize = file.bigsize;
2203
+ const status = advertisedSize === void 0 || advertisedSize === 0n ? await ((_a = file.stat) == null ? void 0 : _a.call(file)) : void 0;
2204
+ const reportedBigsize = (status == null ? void 0 : status.bigsize) ?? file.bigsize;
2205
+ const size = reportedBigsize !== void 0 && reportedBigsize !== 0n ? reportedBigsize : BigInt((status == null ? void 0 : status.size) || file.size);
2206
+ archive = new _ZipArchive(file, size, options);
2207
+ archive.signal.throwIfAborted();
2208
+ if (size < 22n || size > archive.limits.maxArchiveBytes)
2209
+ throw new RangeError("ZIP archive size limit or minimum header size");
2210
+ archive.directory = await archive.readDirectoryLocation();
2211
+ Object.defineProperty(archive, "comment", { value: archive.directory.comment });
2212
+ return archive;
2213
+ } catch (error) {
2214
+ if (archive)
2215
+ await archive.close();
2216
+ else
2217
+ await file.close();
2218
+ throw error;
2219
+ }
2220
+ }
2221
+ /**
2222
+ * Appends one STORE entry through validated container metadata and the native serializer.
2223
+ * Internal composition operation: callers own the writable file and discard it on write failure.
2224
+ * Existing payload offsets, central metadata and archive comments are retained.
2225
+ */
2226
+ static async appendEntry(file, path, data, options = {}) {
2227
+ const archive = await _ZipArchive.open(file, options);
2228
+ try {
2229
+ validateZipPath2(path);
2230
+ if (archive.directory.offset > BigInt(Number.MAX_SAFE_INTEGER))
2231
+ throw new RangeError("ZIP append transport offset exceeds safe integer range");
2232
+ if (await archive.getEntry(path))
2233
+ throw new Error("ZIP entry already exists");
2234
+ for await (const _entry of archive.entries()) {
2235
+ }
2236
+ const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
2237
+ if (path.endsWith("/") && bytes.length)
2238
+ throw new Error("ZIP directory payload must be empty");
2239
+ const entry = {
2240
+ nameBytes: encodeUtf8Text2(path),
2241
+ date: /* @__PURE__ */ new Date("1980-01-01T00:00:00Z"),
2242
+ flags: 2048,
2243
+ method: 0,
2244
+ crc32: 0,
2245
+ size: BigInt(bytes.length),
2246
+ compressedSize: BigInt(bytes.length),
2247
+ localHeaderOffset: archive.directory.offset,
2248
+ zip64: archive.directory.offset >= 0xffffffffn || bytes.length >= 4294967295
2249
+ };
2250
+ let local = encodeZipLocalHeader2(entry);
2251
+ let central = encodeZipCentralHeader2(entry);
2252
+ const directoryBytes = archive.directory.size + BigInt(central.length);
2253
+ const directoryOffset = archive.directory.offset + BigInt(local.length + bytes.length);
2254
+ const count = archive.directory.count + 1n;
2255
+ const comment = new Uint8Array(await archive.readExact(archive.size - BigInt(archive.comment.length), archive.comment.length));
2256
+ const footer = encodeZipEndRecords2(count, directoryBytes, directoryOffset, directoryOffset + directoryBytes > 0x7fffffffn || count >= 0xffffn, comment);
2257
+ if (count > BigInt(archive.limits.maxEntries) || directoryBytes > BigInt(archive.limits.maxDirectoryBytes) || directoryOffset + directoryBytes + BigInt(footer.length) > archive.limits.maxArchiveBytes)
2258
+ throw new RangeError("ZIP append metadata/archive limit exceeded");
2259
+ entry.crc32 = calculateZipChecksum2(bytes);
2260
+ local = encodeZipLocalHeader2(entry);
2261
+ central = encodeZipCentralHeader2(entry);
2262
+ const directory = new Uint8Array(await archive.readExact(archive.directory.offset, Number(archive.directory.size)));
2263
+ archive.signal.throwIfAborted();
2264
+ await file.truncate(Number(archive.directory.offset));
2265
+ for (const chunk of [local, bytes, directory, central, footer]) {
2266
+ archive.signal.throwIfAborted();
2267
+ await file.append(chunk);
2268
+ }
2269
+ archive.signal.throwIfAborted();
2270
+ } finally {
2271
+ await archive.close();
2272
+ }
2273
+ }
2274
+ /** Enumerates validated entries in central-directory order; metadata is indexed once. */
2275
+ async *entries() {
2276
+ for (const path of (await this.getDirectory()).keys())
2277
+ yield await this.getEntry(path);
2278
+ }
2279
+ /**
2280
+ * Reads the final central entry using at most one maximum-sized header from the directory tail.
2281
+ * Ambiguous header signatures in comments fall back to the cached directory. This supports
2282
+ * final-index discovery without scanning a large directory in the normal indexed profile.
2283
+ */
2284
+ async getLastEntry() {
2285
+ this.signal.throwIfAborted();
2286
+ if (!this.directory.count)
2287
+ return void 0;
2288
+ const length = Number(minimumBigInt2(this.directory.size, 46n + 3n * 65535n));
2289
+ const bytes = new Uint8Array(await this.readExact(this.directory.offset + this.directory.size - BigInt(length), length));
2290
+ const view = new DataView(bytes.buffer);
2291
+ const positions = [];
2292
+ for (let position = 0; position + 46 <= length; position++) {
2293
+ if (view.getUint32(position, true) !== 33639248)
2294
+ continue;
2295
+ const end = position + 46 + view.getUint16(position + 28, true) + view.getUint16(position + 30, true) + view.getUint16(position + 32, true);
2296
+ if (end === length)
2297
+ positions.push(position);
2298
+ }
2299
+ if (positions.length !== 1) {
2300
+ const headers = [...(await this.getDirectory()).values()];
2301
+ return await this.getEntry(headers[headers.length - 1].path);
2302
+ }
2303
+ const metadata3 = decodeZipHeader2(bytes.subarray(positions[0]), true);
2304
+ return await this.getValidatedEntry(metadata3.localHeaderOffset, metadata3);
2305
+ }
2306
+ /** Looks up a canonical path; returns undefined when the entry is absent. */
2307
+ async getEntry(path) {
2308
+ this.signal.throwIfAborted();
2309
+ const metadata3 = (await this.getDirectory()).get(path);
2310
+ if (!metadata3)
2311
+ return void 0;
2312
+ let promise = this.entriesByPath.get(path);
2313
+ if (!promise) {
2314
+ promise = this.getValidatedEntry(metadata3.localHeaderOffset, metadata3).catch((error) => {
2315
+ this.entriesByPath.delete(path);
2316
+ throw error;
2317
+ });
2318
+ this.entriesByPath.set(path, promise);
2319
+ }
2320
+ return await promise;
2321
+ }
2322
+ /**
2323
+ * Validates a populated local header at an index-provided offset without a directory scan.
2324
+ * Descriptor entries fall back to the shared directory because their local sizes may be zero.
2325
+ * Direct access validates local layout/bounds; central consistency requires named lookup.
2326
+ */
2327
+ async getEntryAt(localHeaderOffset) {
2328
+ this.signal.throwIfAborted();
2329
+ const existing = this.entriesByOffset.get(localHeaderOffset);
2330
+ if (existing)
2331
+ return await existing;
2332
+ const metadata3 = await this.readLocalHeader(localHeaderOffset);
2333
+ if (metadata3.header.flags & 8) {
2334
+ for (const header of (await this.getDirectory()).values())
2335
+ if (header.localHeaderOffset === localHeaderOffset)
2336
+ return await this.getEntry(header.path);
2337
+ throw new Error("Invalid ZIP archive: indexed offset missing from directory");
2338
+ }
2339
+ return await this.getValidatedEntry(localHeaderOffset, void 0, metadata3);
2340
+ }
2341
+ /** Reads one complete entry and verifies its decoded size and CRC-32. */
2342
+ async read(entryOrPath, options = {}) {
2343
+ const signal = this.getReadSignal(options);
2344
+ signal.throwIfAborted();
2345
+ const entry = await this.resolveEntry(entryOrPath);
2346
+ signal.throwIfAborted();
2347
+ this.checkEntryBudget(entry);
2348
+ if (entry.size > BigInt(Number.MAX_SAFE_INTEGER))
2349
+ throw new RangeError("ZIP allocation is not safely representable");
2350
+ const output = new Uint8Array(Number(entry.size));
2351
+ let offset = 0;
2352
+ for await (const chunk of this.readInBatches(entry, options)) {
2353
+ output.set(chunk, offset);
2354
+ offset += chunk.byteLength;
2355
+ }
2356
+ return output.buffer;
2357
+ }
2358
+ /** Streams decoded chunks with backpressure; consuming through completion verifies CRC-32. */
2359
+ async *readInBatches(entryOrPath, options = {}) {
2360
+ const signal = this.getReadSignal(options);
2361
+ signal.throwIfAborted();
2362
+ const entry = await this.resolveEntry(entryOrPath);
2363
+ signal.throwIfAborted();
2364
+ this.checkEntryBudget(entry);
2365
+ let decodedBytes = 0n;
2366
+ let checksum = 0;
2367
+ const hash = new CRC32Hash({
2368
+ crypto: {
2369
+ onEnd: (result) => {
2370
+ checksum = Number.parseInt(result.hash, 16);
2371
+ }
2372
+ }
2373
+ });
2374
+ const compressed = this.readPayloadChunks(entry, signal);
2375
+ const decoded = entry.compression === "store" ? compressed : new DeflateDecompressor({ raw: true }).decompressBatches(compressed);
2376
+ for await (const chunk of hash.hashBatches(decoded, "hex")) {
2377
+ signal.throwIfAborted();
2378
+ decodedBytes += BigInt(chunk.byteLength);
2379
+ if (decodedBytes > entry.size || decodedBytes > this.limits.maxDecodedBytes)
2380
+ throw new RangeError("ZIP decoded entry size limit exceeded");
2381
+ yield new Uint8Array(chunk);
2382
+ }
2383
+ signal.throwIfAborted();
2384
+ if (decodedBytes !== entry.size)
2385
+ throw new Error("Invalid ZIP archive: decoded size mismatch");
2386
+ if (checksum !== entry.crc32)
2387
+ throw new Error("Invalid ZIP archive: CRC-32 mismatch");
2388
+ }
2389
+ /** Reads only a STORE byte range. Partial reads cannot verify a whole-entry CRC. */
2390
+ async readRange(entryOrPath, options) {
2391
+ const signal = this.getReadSignal(options);
2392
+ signal.throwIfAborted();
2393
+ const entry = await this.resolveEntry(entryOrPath);
2394
+ if (entry.compression !== "store")
2395
+ throw new Error("ZIP ranges require STORE entries");
2396
+ if (options.start < 0n || options.end < options.start || options.end > entry.size || options.end - options.start > BigInt(this.limits.maxReadBytes))
2397
+ throw new RangeError("ZIP byte-range limit exceeded");
2398
+ return await this.readExact(entry.dataOffset + options.start, Number(options.end - options.start), signal);
2399
+ }
2400
+ /** Cancels reads and closes the owned transport exactly once; all subsequent reads reject. */
2401
+ close() {
2402
+ this.controller.abort(new Error("ZIP archive is closed"));
2403
+ this.closePromise ||= this.file.close();
2404
+ return this.closePromise;
2405
+ }
2406
+ /** Resolves a named entry or rejects metadata not issued by this archive. */
2407
+ async resolveEntry(entryOrPath) {
2408
+ this.signal.throwIfAborted();
2409
+ const entry = typeof entryOrPath === "string" ? await this.getEntry(entryOrPath) : entryOrPath;
2410
+ if (!entry || !this.issuedEntries.has(entry))
2411
+ throw new Error("ZIP entry not found or belongs to another archive");
2412
+ return entry;
2413
+ }
2414
+ /** Combines per-read cancellation with the owned lifetime. */
2415
+ getReadSignal(options) {
2416
+ return options.signal ? AbortSignal.any([this.signal, options.signal]) : this.signal;
2417
+ }
2418
+ /** Checks whole-entry consumption before allocation or decompression. */
2419
+ checkEntryBudget(entry) {
2420
+ if (entry.size > this.limits.maxDecodedBytes || entry.compressedSize > this.limits.maxCompressedBytes)
2421
+ throw new RangeError("ZIP entry compressed/decoded byte limit exceeded");
2422
+ }
2423
+ /** Yields compressed bytes without retaining a complete entry. */
2424
+ async *readPayloadChunks(entry, signal) {
2425
+ const chunkBytes = Math.min(this.limits.chunkBytes, this.limits.maxReadBytes);
2426
+ for (let offset = 0n; offset < entry.compressedSize; offset += BigInt(chunkBytes)) {
2427
+ const length = Number(minimumBigInt2(BigInt(chunkBytes), entry.compressedSize - offset));
2428
+ yield await this.readExact(entry.dataOffset + offset, length, signal);
2429
+ }
2430
+ }
2431
+ /** Performs exact, bounded physical reads and rejects truncated transports. */
2432
+ async readExact(offset, length, signal = this.signal) {
2433
+ signal.throwIfAborted();
2434
+ if (offset < 0n || !Number.isSafeInteger(length) || length < 0 || offset + BigInt(length) > this.size)
2435
+ throw new Error("Invalid ZIP archive: read outside file");
2436
+ const output = new Uint8Array(length);
2437
+ for (let copied = 0; copied < length; ) {
2438
+ const readBytes = Math.min(length - copied, this.limits.maxReadBytes);
2439
+ const bytes = await this.file.read(offset + BigInt(copied), readBytes, signal);
2440
+ signal.throwIfAborted();
2441
+ if (bytes.byteLength !== readBytes)
2442
+ throw new Error("Invalid ZIP archive: truncated file read");
2443
+ output.set(new Uint8Array(bytes), copied);
2444
+ copied += readBytes;
2445
+ }
2446
+ return output.buffer;
2447
+ }
2448
+ /** Finds an EOCD whose complete comment ends at EOF, not a signature embedded in the comment. */
2449
+ async readDirectoryLocation() {
2450
+ const magic = new DataView(await this.readExact(0n, 4)).getUint32(0, true);
2451
+ if (magic !== 67324752 && magic !== 101010256 && magic !== 101075792)
2452
+ throw new Error("Unsupported ZIP prefix or archive format");
2453
+ const tailLength = Number(minimumBigInt2(this.size, 65557n));
2454
+ const tailStart = this.size - BigInt(tailLength);
2455
+ const tail = new DataView(await this.readExact(tailStart, tailLength));
2456
+ let position = -1;
2457
+ for (let candidate = tailLength - 22; candidate >= 0; candidate--) {
2458
+ if (tail.getUint32(candidate, true) !== 101010256 || candidate + 22 + tail.getUint16(candidate + 20, true) !== tailLength)
2459
+ continue;
2460
+ if (position < 0)
2461
+ position = candidate;
2462
+ const emptyDirectoryAtEnd = tail.getUint32(candidate + 12, true) === 0 && BigInt(tail.getUint32(candidate + 16, true)) === tailStart + BigInt(candidate);
2463
+ if (tail.getUint16(candidate + 10, true) !== 0 || emptyDirectoryAtEnd || magic === 101075792) {
2464
+ position = candidate;
2465
+ break;
2466
+ }
2467
+ }
2468
+ if (position < 0)
2469
+ throw new Error("Invalid ZIP archive: end record not found");
2470
+ const disk = tail.getUint16(position + 4, true);
2471
+ const directoryDisk = tail.getUint16(position + 6, true);
2472
+ if (disk !== 0 && disk !== 65535 || directoryDisk !== 0 && directoryDisk !== 65535)
2473
+ throw new Error("Unsupported split ZIP archive");
2474
+ const onDisk = BigInt(tail.getUint16(position + 8, true));
2475
+ let count = BigInt(tail.getUint16(position + 10, true));
2476
+ let size = BigInt(tail.getUint32(position + 12, true));
2477
+ let offset = BigInt(tail.getUint32(position + 16, true));
2478
+ let footerOffset = tailStart + BigInt(position);
2479
+ let zip64 = false;
2480
+ if (footerOffset >= 20n) {
2481
+ const locator = new DataView(await this.readExact(footerOffset - 20n, 20));
2482
+ const locatorInsideDirectory = size !== 0xffffffffn && offset !== 0xffffffffn && offset + size > footerOffset - 20n;
2483
+ if (locator.getUint32(0, true) === 117853008 && !locatorInsideDirectory) {
2484
+ zip64 = true;
2485
+ if (locator.getUint32(4, true) || locator.getUint32(16, true) !== 1)
2486
+ throw new Error("Unsupported split ZIP64 archive");
2487
+ const zip64Offset = locator.getBigUint64(8, true);
2488
+ const record = new DataView(await this.readExact(zip64Offset, 56));
2489
+ if (record.getUint32(0, true) !== 101075792 || record.getBigUint64(4, true) < 44n || zip64Offset + 12n + record.getBigUint64(4, true) !== footerOffset - 20n || record.getUint32(16, true) || record.getUint32(20, true) || record.getBigUint64(24, true) !== record.getBigUint64(32, true))
2490
+ throw new Error("Invalid ZIP64 end record");
2491
+ const zip64Count = record.getBigUint64(32, true);
2492
+ const zip64Size = record.getBigUint64(40, true);
2493
+ const zip64DirectoryOffset = record.getBigUint64(48, true);
2494
+ if (onDisk !== 0xffffn && onDisk !== zip64Count || count !== 0xffffn && count !== zip64Count || size !== 0xffffffffn && size !== zip64Size || offset !== 0xffffffffn && offset !== zip64DirectoryOffset)
2495
+ throw new Error("Invalid ZIP64 legacy end values");
2496
+ count = zip64Count;
2497
+ size = zip64Size;
2498
+ offset = zip64DirectoryOffset;
2499
+ footerOffset = zip64Offset;
2500
+ } else if (size === 0xffffffffn || offset === 0xffffffffn)
2501
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
2502
+ } else if (size === 0xffffffffn || offset === 0xffffffffn)
2503
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
2504
+ if (!zip64) {
2505
+ if (disk === 65535 || directoryDisk === 65535)
2506
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
2507
+ if (onDisk !== count)
2508
+ throw new Error("Invalid ZIP archive: inconsistent entry counts");
2509
+ }
2510
+ if (count > BigInt(this.limits.maxEntries) || size > BigInt(this.limits.maxDirectoryBytes))
2511
+ throw new RangeError("ZIP directory entry/byte limit exceeded");
2512
+ if (offset + size > footerOffset || size < count * 46n || count === 0n !== (size === 0n))
2513
+ throw new Error("Invalid ZIP archive: directory outside bounds");
2514
+ if (count && new DataView(await this.readExact(offset, 4)).getUint32(0, true) !== 33639248)
2515
+ throw new Error("Invalid ZIP archive: directory signature missing");
2516
+ const comment = decodeZipText2(new Uint8Array(tail.buffer, position + 22), false);
2517
+ return { count, size, offset, comment };
2518
+ }
2519
+ /** Indexes central metadata once, without eagerly reading every local header. */
2520
+ getDirectory() {
2521
+ this.signal.throwIfAborted();
2522
+ this.directoryPromise ||= this.readDirectory().catch((error) => {
2523
+ this.directoryPromise = void 0;
2524
+ this.nextOffsets.clear();
2525
+ throw error;
2526
+ });
2527
+ return this.directoryPromise;
2528
+ }
2529
+ /** Parses exact directory records, including comments and Unicode/ZIP64 extras. */
2530
+ async readDirectory() {
2531
+ const bytes = new Uint8Array(await this.readExact(this.directory.offset, Number(this.directory.size)));
2532
+ const view = new DataView(bytes.buffer);
2533
+ const entries = /* @__PURE__ */ new Map();
2534
+ const offsets = /* @__PURE__ */ new Set();
2535
+ let position = 0;
2536
+ for (let index = 0n; index < this.directory.count; index++) {
2537
+ if (position + 46 > bytes.byteLength)
2538
+ throw new Error("Invalid ZIP archive: truncated directory");
2539
+ const length = 46 + view.getUint16(position + 28, true) + view.getUint16(position + 30, true) + view.getUint16(position + 32, true);
2540
+ const header = decodeZipHeader2(bytes.subarray(position, position + length), true);
2541
+ if (header.localHeaderOffset + 30n > this.directory.offset)
2542
+ throw new Error("Invalid ZIP archive: local header outside data region");
2543
+ if (entries.has(header.path) || offsets.has(header.localHeaderOffset))
2544
+ throw new Error("Invalid ZIP archive: duplicate path or local-header offset");
2545
+ entries.set(header.path, header);
2546
+ offsets.add(header.localHeaderOffset);
2547
+ position += length;
2548
+ }
2549
+ const sortedOffsets = [...offsets].sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
2550
+ sortedOffsets.forEach((offset, index) => this.nextOffsets.set(offset, sortedOffsets[index + 1] ?? this.directory.offset));
2551
+ if (position !== bytes.byteLength)
2552
+ throw new Error("Invalid ZIP archive: directory length mismatch");
2553
+ return entries;
2554
+ }
2555
+ /** Reads local metadata without inspecting unrelated payloads. */
2556
+ async readLocalHeader(offset) {
2557
+ if (offset < 0n || offset + 30n > this.directory.offset)
2558
+ throw new Error("Invalid ZIP archive: local header outside data region");
2559
+ const fixed = new DataView(await this.readExact(offset, 30));
2560
+ const length = 30 + fixed.getUint16(26, true) + fixed.getUint16(28, true);
2561
+ if (offset + BigInt(length) > this.directory.offset)
2562
+ throw new Error("Invalid ZIP archive: local metadata overlaps directory");
2563
+ const bytes = new Uint8Array(length);
2564
+ bytes.set(new Uint8Array(fixed.buffer));
2565
+ bytes.set(new Uint8Array(await this.readExact(offset + 30n, length - 30)), 30);
2566
+ const header = decodeZipHeader2(bytes, false);
2567
+ return { header, dataOffset: offset + BigInt(length) };
2568
+ }
2569
+ /** Shares local validation; a later named lookup additionally verifies central metadata. */
2570
+ async getValidatedEntry(offset, central, localMetadata) {
2571
+ if (central)
2572
+ return await this.validateEntry(offset, central);
2573
+ let entry = this.entriesByOffset.get(offset);
2574
+ if (!entry) {
2575
+ entry = this.validateEntry(offset, void 0, localMetadata).catch((error) => {
2576
+ this.entriesByOffset.delete(offset);
2577
+ throw error;
2578
+ });
2579
+ this.entriesByOffset.set(offset, entry);
2580
+ }
2581
+ return await entry;
2582
+ }
2583
+ /** Validates local/central identity, payload bounds and signed or unsigned descriptors. */
2584
+ async validateEntry(offset, central, localMetadata) {
2585
+ const { header: local, dataOffset } = localMetadata ?? await this.readLocalHeader(offset);
2586
+ const metadata3 = central || local;
2587
+ const descriptor = Boolean(local.flags & 8);
2588
+ if (central && (central.flags !== local.flags || central.method !== local.method || central.nameBytes.length !== local.nameBytes.length || central.nameBytes.some((value, index) => value !== local.nameBytes[index]) || !descriptor && (central.crc32 !== local.crc32 || central.size !== local.size || central.compressedSize !== local.compressedSize)))
2589
+ throw new Error("Invalid ZIP archive: local/central metadata mismatch");
2590
+ if (metadata3.method === 0 && metadata3.size !== metadata3.compressedSize)
2591
+ throw new Error("Invalid ZIP archive: STORE sizes mismatch");
2592
+ if (central && descriptor && (local.crc32 !== 0 && local.crc32 !== central.crc32 || local.size !== 0n && local.size !== central.size || local.compressedSize !== 0n && local.compressedSize !== central.compressedSize))
2593
+ throw new Error("Invalid ZIP archive: descriptor local/central metadata mismatch");
2594
+ const payloadEnd = dataOffset + metadata3.compressedSize;
2595
+ const entryEnd = central ? this.nextOffsets.get(offset) ?? this.directory.offset : this.directory.offset;
2596
+ if (payloadEnd > entryEnd)
2597
+ throw new Error("Invalid ZIP archive: payload overlaps directory");
2598
+ if (descriptor)
2599
+ await this.validateDescriptor(payloadEnd, metadata3, local.zip64 || Boolean(central == null ? void 0 : central.zip64), entryEnd);
2600
+ const entry = Object.freeze({
2601
+ path: metadata3.path,
2602
+ directory: metadata3.path.endsWith("/"),
2603
+ compression: metadata3.method === 0 ? "store" : "deflate",
2604
+ size: metadata3.size,
2605
+ compressedSize: metadata3.compressedSize,
2606
+ crc32: metadata3.crc32,
2607
+ localHeaderOffset: offset,
2608
+ dataOffset,
2609
+ comment: (central == null ? void 0 : central.comment) || ""
2610
+ });
2611
+ this.issuedEntries.add(entry);
2612
+ return entry;
2613
+ }
2614
+ /** Resolves the optional descriptor signature using the expected CRC and sizes. */
2615
+ async validateDescriptor(offset, metadata3, zip64, entryEnd) {
2616
+ const length = Number(minimumBigInt2(24n, entryEnd - offset));
2617
+ const bytes = new DataView(await this.readExact(offset, length));
2618
+ for (const wide of zip64 ? [true, false] : [false, true]) {
2619
+ if (!wide && (metadata3.size > 0xffffffffn || metadata3.compressedSize > 0xffffffffn))
2620
+ continue;
2621
+ const descriptorLength = wide ? 20 : 12;
2622
+ for (const prefix of [4, 0]) {
2623
+ if (length < prefix + descriptorLength || prefix && bytes.getUint32(0, true) !== 134695760)
2624
+ continue;
2625
+ const compressed = wide ? bytes.getBigUint64(prefix + 4, true) : BigInt(bytes.getUint32(prefix + 4, true));
2626
+ const decoded = wide ? bytes.getBigUint64(prefix + 12, true) : BigInt(bytes.getUint32(prefix + 8, true));
2627
+ if (bytes.getUint32(prefix, true) === metadata3.crc32 && compressed === metadata3.compressedSize && decoded === metadata3.size)
2628
+ return;
2629
+ }
2630
+ }
2631
+ throw new Error("Invalid ZIP archive: data descriptor mismatch");
2632
+ }
2633
+ };
2634
+ async function openZipArchive2(input, options = {}) {
2635
+ return await ZipArchive2.open(input, options);
2636
+ }
2637
+ function normalizeZipInput2(input) {
2638
+ if (input instanceof ArrayBuffer)
2639
+ return new BlobFile(input);
2640
+ if (ArrayBuffer.isView(input))
2641
+ return new BlobFile(new Blob([new Uint8Array(input.buffer, input.byteOffset, input.byteLength).slice()]));
2642
+ if (input instanceof Blob)
2643
+ return new BlobFile(input);
2644
+ return input;
2645
+ }
2646
+ function minimumBigInt2(left, right) {
2647
+ return left < right ? left : right;
2648
+ }
2649
+
2650
+ // dist/zip/zip-loader.js
2651
+ var { preload: _preload2, ...metadata2 } = ZipLoader2;
2652
+ var ZipLoaderWithParser2 = {
2653
+ ...metadata2,
2654
+ parse: parseZip2
2655
+ };
2656
+ async function parseZip2(input, options = {}) {
2657
+ var _a;
2658
+ const maximum = ((_a = options.zip) == null ? void 0 : _a.maxTotalDecodedBytes) ?? ZipLoader2.options.zip.maxTotalDecodedBytes;
2659
+ if (typeof maximum !== "bigint" || maximum < 0n)
2660
+ throw new RangeError("Invalid ZIP total decoded-byte limit");
2661
+ const archive = await openZipArchive2(input, options.zip);
2662
+ try {
2663
+ const entries = [];
2664
+ let totalBytes = 0n;
2665
+ for await (const entry of archive.entries()) {
2666
+ if (entry.directory)
2667
+ continue;
2668
+ totalBytes += entry.size;
2669
+ if (totalBytes > maximum)
2670
+ throw new RangeError("ZIP total decoded-byte limit exceeded");
2671
+ entries.push(entry);
2672
+ }
2673
+ const files = /* @__PURE__ */ Object.create(null);
2674
+ for (const entry of entries)
2675
+ files[entry.path] = await archive.read(entry);
2676
+ return files;
2677
+ } finally {
2678
+ await archive.close();
2679
+ }
2680
+ }
2681
+ //# sourceMappingURL=zip-loader.cjs.map