@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,4614 @@
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: ZipLoaderWithParser2 } = await Promise.resolve().then(() => (init_zip_loader(), zip_loader_exports));
74
+ return ZipLoaderWithParser2;
75
+ }
76
+ };
77
+ }
78
+ });
79
+
80
+ // ../core/src/loader-utils/lib/env-utils/globals.ts
81
+ var globals, self_, window_, global_, document_, isBrowser, matches, nodeVersion;
82
+ var init_globals = __esm({
83
+ "../core/src/loader-utils/lib/env-utils/globals.ts"() {
84
+ "use strict";
85
+ globals = {
86
+ self: typeof self !== "undefined" && self,
87
+ window: typeof window !== "undefined" && window,
88
+ global: typeof global !== "undefined" && global,
89
+ document: typeof document !== "undefined" && document
90
+ };
91
+ self_ = globals.self || globals.window || globals.global || {};
92
+ window_ = globals.window || globals.self || globals.global || {};
93
+ global_ = globals.global || globals.self || globals.window || {};
94
+ document_ = globals.document || {};
95
+ isBrowser = // @ts-ignore process does not exist on browser
96
+ Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
97
+ matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
98
+ nodeVersion = matches && parseFloat(matches[1]) || 0;
99
+ }
100
+ });
101
+
102
+ // ../core/src/loader-utils/lib/javascript-utils/is-type.ts
103
+ var isSharedArrayBuffer;
104
+ var init_is_type = __esm({
105
+ "../core/src/loader-utils/lib/javascript-utils/is-type.ts"() {
106
+ "use strict";
107
+ isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
108
+ }
109
+ });
110
+
111
+ // ../core/src/loader-utils/lib/module-utils/js-module-utils.ts
112
+ function registerJSModules(modules) {
113
+ globalThis.loaders ||= {};
114
+ globalThis.loaders.modules ||= {};
115
+ Object.assign(globalThis.loaders.modules, modules);
116
+ }
117
+ var init_js_module_utils = __esm({
118
+ "../core/src/loader-utils/lib/module-utils/js-module-utils.ts"() {
119
+ "use strict";
120
+ }
121
+ });
122
+
123
+ // ../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts
124
+ function concatenateArrayBuffers(...sources) {
125
+ return concatenateArrayBuffersFromArray(sources);
126
+ }
127
+ function concatenateArrayBuffersFromArray(sources) {
128
+ const sourceArrays = sources.map(
129
+ (source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
130
+ );
131
+ const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
132
+ const result = new Uint8Array(byteLength);
133
+ let offset = 0;
134
+ for (const sourceArray of sourceArrays) {
135
+ result.set(sourceArray, offset);
136
+ offset += sourceArray.byteLength;
137
+ }
138
+ return result.buffer;
139
+ }
140
+ var init_array_buffer_utils = __esm({
141
+ "../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts"() {
142
+ "use strict";
143
+ }
144
+ });
145
+
146
+ // ../core/src/loader-utils/lib/iterators/async-iteration.ts
147
+ async function concatenateArrayBuffersAsync(asyncIterator) {
148
+ const arrayBuffers = [];
149
+ for await (const chunk of asyncIterator) {
150
+ arrayBuffers.push(copyToArrayBuffer(chunk));
151
+ }
152
+ return concatenateArrayBuffers(...arrayBuffers);
153
+ }
154
+ function copyToArrayBuffer(chunk) {
155
+ if (chunk instanceof ArrayBuffer) {
156
+ return chunk;
157
+ }
158
+ if (ArrayBuffer.isView(chunk)) {
159
+ const { buffer, byteOffset, byteLength } = chunk;
160
+ return copyFromBuffer(buffer, byteOffset, byteLength);
161
+ }
162
+ return copyFromBuffer(chunk);
163
+ }
164
+ function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
165
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
166
+ const copy = new Uint8Array(view.length);
167
+ copy.set(view);
168
+ return copy.buffer;
169
+ }
170
+ var init_async_iteration = __esm({
171
+ "../core/src/loader-utils/lib/iterators/async-iteration.ts"() {
172
+ "use strict";
173
+ init_array_buffer_utils();
174
+ }
175
+ });
176
+
177
+ // ../core/src/loader-utils/lib/path-utils/get-cwd.ts
178
+ function getCWD() {
179
+ var _a;
180
+ if (typeof process !== "undefined" && typeof process.cwd !== "undefined") {
181
+ return process.cwd();
182
+ }
183
+ const pathname = (_a = globalThis.location) == null ? void 0 : _a.pathname;
184
+ return (pathname == null ? void 0 : pathname.slice(0, pathname.lastIndexOf("/") + 1)) || "";
185
+ }
186
+ var init_get_cwd = __esm({
187
+ "../core/src/loader-utils/lib/path-utils/get-cwd.ts"() {
188
+ "use strict";
189
+ }
190
+ });
191
+
192
+ // ../core/src/loader-utils/lib/path-utils/path.ts
193
+ var path_exports = {};
194
+ __export(path_exports, {
195
+ dirname: () => dirname,
196
+ filename: () => filename,
197
+ join: () => join,
198
+ resolve: () => resolve
199
+ });
200
+ function filename(url) {
201
+ const slashIndex = url ? url.lastIndexOf("/") : -1;
202
+ return slashIndex >= 0 ? url.substr(slashIndex + 1) : url;
203
+ }
204
+ function dirname(url) {
205
+ const slashIndex = url ? url.lastIndexOf("/") : -1;
206
+ return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
207
+ }
208
+ function join(...parts) {
209
+ const separator = "/";
210
+ parts = parts.map((part, index) => {
211
+ if (index) {
212
+ part = part.replace(new RegExp(`^${separator}`), "");
213
+ }
214
+ if (index !== parts.length - 1) {
215
+ part = part.replace(new RegExp(`${separator}$`), "");
216
+ }
217
+ return part;
218
+ });
219
+ return parts.join(separator);
220
+ }
221
+ function resolve(...components) {
222
+ const paths = [];
223
+ for (let _i = 0; _i < components.length; _i++) {
224
+ paths[_i] = components[_i];
225
+ }
226
+ let resolvedPath = "";
227
+ let resolvedAbsolute = false;
228
+ let cwd;
229
+ for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
230
+ let path;
231
+ if (i >= 0) {
232
+ path = paths[i];
233
+ } else {
234
+ if (cwd === void 0) {
235
+ cwd = getCWD();
236
+ }
237
+ path = cwd;
238
+ }
239
+ if (path.length === 0) {
240
+ continue;
241
+ }
242
+ resolvedPath = `${path}/${resolvedPath}`;
243
+ resolvedAbsolute = path.charCodeAt(0) === SLASH;
244
+ }
245
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
246
+ if (resolvedAbsolute) {
247
+ return `/${resolvedPath}`;
248
+ } else if (resolvedPath.length > 0) {
249
+ return resolvedPath;
250
+ }
251
+ return ".";
252
+ }
253
+ function normalizeStringPosix(path, allowAboveRoot) {
254
+ let res = "";
255
+ let lastSlash = -1;
256
+ let dots = 0;
257
+ let code;
258
+ let isAboveRoot = false;
259
+ for (let i = 0; i <= path.length; ++i) {
260
+ if (i < path.length) {
261
+ code = path.charCodeAt(i);
262
+ } else if (code === SLASH) {
263
+ break;
264
+ } else {
265
+ code = SLASH;
266
+ }
267
+ if (code === SLASH) {
268
+ if (lastSlash === i - 1 || dots === 1) {
269
+ } else if (lastSlash !== i - 1 && dots === 2) {
270
+ if (res.length < 2 || !isAboveRoot || res.charCodeAt(res.length - 1) !== DOT || res.charCodeAt(res.length - 2) !== DOT) {
271
+ if (res.length > 2) {
272
+ const start = res.length - 1;
273
+ let j = start;
274
+ for (; j >= 0; --j) {
275
+ if (res.charCodeAt(j) === SLASH) {
276
+ break;
277
+ }
278
+ }
279
+ if (j !== start) {
280
+ res = j === -1 ? "" : res.slice(0, j);
281
+ lastSlash = i;
282
+ dots = 0;
283
+ isAboveRoot = false;
284
+ continue;
285
+ }
286
+ } else if (res.length === 2 || res.length === 1) {
287
+ res = "";
288
+ lastSlash = i;
289
+ dots = 0;
290
+ isAboveRoot = false;
291
+ continue;
292
+ }
293
+ }
294
+ if (allowAboveRoot) {
295
+ if (res.length > 0) {
296
+ res += "/..";
297
+ } else {
298
+ res = "..";
299
+ }
300
+ isAboveRoot = true;
301
+ }
302
+ } else {
303
+ const slice = path.slice(lastSlash + 1, i);
304
+ if (res.length > 0) {
305
+ res += `/${slice}`;
306
+ } else {
307
+ res = slice;
308
+ }
309
+ isAboveRoot = false;
310
+ }
311
+ lastSlash = i;
312
+ dots = 0;
313
+ } else if (code === DOT && dots !== -1) {
314
+ ++dots;
315
+ } else {
316
+ dots = -1;
317
+ }
318
+ }
319
+ return res;
320
+ }
321
+ var SLASH, DOT;
322
+ var init_path = __esm({
323
+ "../core/src/loader-utils/lib/path-utils/path.ts"() {
324
+ "use strict";
325
+ init_get_cwd();
326
+ SLASH = 47;
327
+ DOT = 46;
328
+ }
329
+ });
330
+
331
+ // ../core/src/loader-utils/lib/node/buffer.browser.ts
332
+ function toArrayBuffer(buffer) {
333
+ return buffer;
334
+ }
335
+ var init_buffer_browser = __esm({
336
+ "../core/src/loader-utils/lib/node/buffer.browser.ts"() {
337
+ "use strict";
338
+ }
339
+ });
340
+
341
+ // ../core/src/loader-utils/lib/binary-utils/memory-conversion-utils.ts
342
+ function isBuffer(value) {
343
+ return value && typeof value === "object" && value.isBuffer;
344
+ }
345
+ function toArrayBuffer2(data) {
346
+ if (isBuffer(data)) {
347
+ return toArrayBuffer(data);
348
+ }
349
+ if (data instanceof ArrayBuffer) {
350
+ return data;
351
+ }
352
+ if (isSharedArrayBuffer(data)) {
353
+ return copyToArrayBuffer2(data);
354
+ }
355
+ if (ArrayBuffer.isView(data)) {
356
+ const buffer = data.buffer;
357
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
358
+ return buffer;
359
+ }
360
+ return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
361
+ }
362
+ if (typeof data === "string") {
363
+ const text = data;
364
+ const uint8Array = new TextEncoder().encode(text);
365
+ return uint8Array.buffer;
366
+ }
367
+ if (data && typeof data === "object" && data._toArrayBuffer) {
368
+ return data._toArrayBuffer();
369
+ }
370
+ throw new Error("toArrayBuffer");
371
+ }
372
+ function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
373
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
374
+ const copy = new Uint8Array(view.length);
375
+ copy.set(view);
376
+ return copy.buffer;
377
+ }
378
+ var init_memory_conversion_utils = __esm({
379
+ "../core/src/loader-utils/lib/binary-utils/memory-conversion-utils.ts"() {
380
+ "use strict";
381
+ init_is_type();
382
+ init_buffer_browser();
383
+ }
384
+ });
385
+
386
+ // ../core/src/loader-utils/lib/files/blob-file.ts
387
+ var BlobFile;
388
+ var init_blob_file = __esm({
389
+ "../core/src/loader-utils/lib/files/blob-file.ts"() {
390
+ "use strict";
391
+ BlobFile = class {
392
+ handle;
393
+ size;
394
+ bigsize;
395
+ url;
396
+ constructor(blob) {
397
+ this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
398
+ this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
399
+ this.bigsize = BigInt(this.size);
400
+ this.url = blob instanceof File ? blob.name : "";
401
+ }
402
+ async close() {
403
+ }
404
+ async stat() {
405
+ return {
406
+ size: this.handle.size,
407
+ bigsize: BigInt(this.handle.size),
408
+ isDirectory: false
409
+ };
410
+ }
411
+ async read(start, length, signal) {
412
+ if (signal == null ? void 0 : signal.aborted) {
413
+ throw new Error("Request aborted");
414
+ }
415
+ const arrayBuffer = await this.handle.slice(Number(start), Number(start) + Number(length)).arrayBuffer();
416
+ if (signal == null ? void 0 : signal.aborted) {
417
+ throw new Error("Request aborted");
418
+ }
419
+ return arrayBuffer;
420
+ }
421
+ };
422
+ }
423
+ });
424
+
425
+ // ../core/src/loader-utils/lib/files/node-file-facade.ts
426
+ var NOT_IMPLEMENTED, NodeFileFacade;
427
+ var init_node_file_facade = __esm({
428
+ "../core/src/loader-utils/lib/files/node-file-facade.ts"() {
429
+ "use strict";
430
+ init_globals();
431
+ NOT_IMPLEMENTED = new Error("Not implemented");
432
+ NodeFileFacade = class {
433
+ handle;
434
+ size = 0;
435
+ bigsize = 0n;
436
+ url = "";
437
+ constructor(url, flags, mode) {
438
+ var _a;
439
+ if ((_a = globalThis.loaders) == null ? void 0 : _a.NodeFile) {
440
+ return new globalThis.loaders.NodeFile(url, flags, mode);
441
+ }
442
+ if (isBrowser) {
443
+ throw new Error("Can't instantiate NodeFile in browser.");
444
+ }
445
+ throw new Error(
446
+ "Can't instantiate NodeFile. Make sure to import @loaders.gl/core/polyfills first."
447
+ );
448
+ }
449
+ /** Read data */
450
+ async read(start, length) {
451
+ throw NOT_IMPLEMENTED;
452
+ }
453
+ /** Write to file. The number of bytes written will be returned */
454
+ async write(arrayBuffer, offset, length) {
455
+ throw NOT_IMPLEMENTED;
456
+ }
457
+ /** Get information about file */
458
+ async stat() {
459
+ throw NOT_IMPLEMENTED;
460
+ }
461
+ /** Truncates the file descriptor. Only available on NodeFile. */
462
+ async truncate(length) {
463
+ throw NOT_IMPLEMENTED;
464
+ }
465
+ /** Append data to a file. Only available on NodeFile. */
466
+ async append(data) {
467
+ throw NOT_IMPLEMENTED;
468
+ }
469
+ /** Close the file */
470
+ async close() {
471
+ }
472
+ };
473
+ }
474
+ });
475
+
476
+ // ../core/src/loader-utils/lib/filesystems/node-filesystem-facade.ts
477
+ var NOT_IMPLEMENTED2, NodeFileSystemFacade;
478
+ var init_node_filesystem_facade = __esm({
479
+ "../core/src/loader-utils/lib/filesystems/node-filesystem-facade.ts"() {
480
+ "use strict";
481
+ init_globals();
482
+ NOT_IMPLEMENTED2 = new Error("Not implemented");
483
+ NodeFileSystemFacade = class {
484
+ // implements FileSystem
485
+ constructor(options) {
486
+ var _a;
487
+ if ((_a = globalThis.loaders) == null ? void 0 : _a.NodeFileSystem) {
488
+ return new globalThis.loaders.NodeFileSystem(options);
489
+ }
490
+ if (isBrowser) {
491
+ throw new Error("Can't instantiate NodeFileSystem in browser.");
492
+ }
493
+ throw new Error(
494
+ "Can't instantiate NodeFileSystem. Make sure to import @loaders.gl/core/polyfills first."
495
+ );
496
+ }
497
+ // DUMMY IMPLEMENTATION, not used (constructor returns a real NodeFileSystem instance)
498
+ // implements RandomAccessReadFileSystem
499
+ readable = true;
500
+ writable = true;
501
+ async openReadableFile(path, flags) {
502
+ throw NOT_IMPLEMENTED2;
503
+ }
504
+ // implements RandomAccessWriteFileSystem
505
+ async openWritableFile(path, flags, mode) {
506
+ throw NOT_IMPLEMENTED2;
507
+ }
508
+ // Implements file system
509
+ async readdir(dirname2 = ".", options) {
510
+ throw NOT_IMPLEMENTED2;
511
+ }
512
+ async stat(path, options) {
513
+ throw NOT_IMPLEMENTED2;
514
+ }
515
+ async unlink(path) {
516
+ throw NOT_IMPLEMENTED2;
517
+ }
518
+ async fetch(path, options) {
519
+ throw NOT_IMPLEMENTED2;
520
+ }
521
+ };
522
+ }
523
+ });
524
+
525
+ // ../core/src/loader-utils/index.ts
526
+ var init_loader_utils = __esm({
527
+ "../core/src/loader-utils/index.ts"() {
528
+ "use strict";
529
+ init_globals();
530
+ init_js_module_utils();
531
+ init_array_buffer_utils();
532
+ init_async_iteration();
533
+ init_memory_conversion_utils();
534
+ init_path();
535
+ init_blob_file();
536
+ init_node_file_facade();
537
+ init_node_filesystem_facade();
538
+ }
539
+ });
540
+
541
+ // ../compression/src/lib/compression.ts
542
+ var CompressionTransform, Compressor, Decompressor;
543
+ var init_compression = __esm({
544
+ "../compression/src/lib/compression.ts"() {
545
+ "use strict";
546
+ init_loader_utils();
547
+ CompressionTransform = class {
548
+ /** Preloads any dynamic libraries. May enable sync functions */
549
+ async preload(modules = {}) {
550
+ registerJSModules(modules);
551
+ return void 0;
552
+ }
553
+ // HELPERS
554
+ concatenate(asyncIterator) {
555
+ return concatenateArrayBuffersAsync(asyncIterator);
556
+ }
557
+ improveError(error) {
558
+ if (!error.message.includes(this.name)) {
559
+ error.message = `${this.name} ${error.message}`;
560
+ }
561
+ return error;
562
+ }
563
+ };
564
+ Compressor = class extends CompressionTransform {
565
+ constructor(options) {
566
+ super();
567
+ this.compressBatches = this.compressBatches.bind(this);
568
+ }
569
+ /** Asynchronously compresses data. */
570
+ async compress(input) {
571
+ await this.preload();
572
+ return this.compressSync(input);
573
+ }
574
+ /** Synchronously compresses data. */
575
+ compressSync(input) {
576
+ throw new Error(`${this.name}: sync compression not supported`);
577
+ }
578
+ /** Compresses batches. */
579
+ async *compressBatches(asyncIterator) {
580
+ const input = await this.concatenate(asyncIterator);
581
+ yield this.compress(input);
582
+ }
583
+ };
584
+ Decompressor = class extends CompressionTransform {
585
+ constructor(options) {
586
+ super();
587
+ this.decompressBatches = this.decompressBatches.bind(this);
588
+ }
589
+ /** Asynchronously decompresses data. */
590
+ async decompress(input, size) {
591
+ await this.preload();
592
+ return this.decompressSync(input, size);
593
+ }
594
+ /** Synchronously decompresses data. */
595
+ decompressSync(input, size) {
596
+ throw new Error(`${this.name}: sync decompression not supported`);
597
+ }
598
+ /** Decompresses batches. */
599
+ async *decompressBatches(asyncIterator) {
600
+ const input = await this.concatenate(asyncIterator);
601
+ yield this.decompress(input);
602
+ }
603
+ };
604
+ }
605
+ });
606
+
607
+ // ../compression/src/lib/compress-utils-compression.ts
608
+ async function* transformBatches(stream, inputBatches, maximumOutputByteLength = Number.POSITIVE_INFINITY) {
609
+ let outputByteLength = 0;
610
+ try {
611
+ for await (const input of inputBatches) {
612
+ const output2 = stream.write(new Uint8Array(input));
613
+ if (output2.byteLength > maximumOutputByteLength - outputByteLength)
614
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
615
+ outputByteLength += output2.byteLength;
616
+ if (output2.byteLength > 0) yield copyArrayBuffer(output2);
617
+ }
618
+ const output = stream.finish();
619
+ if (output.byteLength > maximumOutputByteLength - outputByteLength)
620
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
621
+ if (output.byteLength > 0) yield copyArrayBuffer(output);
622
+ } finally {
623
+ stream.destroy();
624
+ }
625
+ }
626
+ function copyArrayBuffer(bytes) {
627
+ return bytes.slice().buffer;
628
+ }
629
+ function getDecompressOptions(options, size) {
630
+ const decodeOptions = {
631
+ ...options.compressUtils,
632
+ ...size === void 0 ? {} : { expectedSize: size }
633
+ };
634
+ const capacity = decodeOptions.expectedSize;
635
+ const maximum = getMaximumOutputByteLength(options);
636
+ if (capacity !== void 0 && (!Number.isSafeInteger(capacity) || capacity < 0 || capacity > maximum)) {
637
+ throw new RangeError("expectedSize exceeds the configured output capacity limit");
638
+ }
639
+ return decodeOptions;
640
+ }
641
+ function getMaximumOutputByteLength(options) {
642
+ const maximum = options.maxOutputByteLength ?? 512 * 1024 * 1024;
643
+ if (!Number.isSafeInteger(maximum) || maximum < 0 || maximum > 2147483647)
644
+ throw new RangeError("Invalid maxOutputByteLength");
645
+ return maximum;
646
+ }
647
+ function copyDecompressedOutput(bytes, options) {
648
+ if (bytes.byteLength > getMaximumOutputByteLength(options))
649
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
650
+ return copyArrayBuffer(bytes);
651
+ }
652
+ var CompressUtilsCompressor, CompressUtilsDecompressor;
653
+ var init_compress_utils_compression = __esm({
654
+ "../compression/src/lib/compress-utils-compression.ts"() {
655
+ "use strict";
656
+ init_compression();
657
+ CompressUtilsCompressor = class extends Compressor {
658
+ name;
659
+ extensions;
660
+ contentEncodings;
661
+ isSupported = true;
662
+ options;
663
+ loadModule;
664
+ /** Module initialized for synchronous operations. */
665
+ module = null;
666
+ /** Shared import and WASM initialization for concurrent callers. */
667
+ modulePromise = null;
668
+ /** Creates a format-specific compress-utils encoder. */
669
+ constructor(metadata2, loadModule, options = {}) {
670
+ super(options);
671
+ this.name = metadata2.name;
672
+ this.extensions = metadata2.extensions || [];
673
+ this.contentEncodings = metadata2.contentEncodings || [];
674
+ this.loadModule = loadModule;
675
+ this.options = options;
676
+ }
677
+ /** Imports and initializes the codec without loading the opposite direction. */
678
+ async preload(modules = {}) {
679
+ await super.preload(modules);
680
+ this.modulePromise ||= this.loadModule().then(async (module2) => {
681
+ var _a;
682
+ await ((_a = module2.preload) == null ? void 0 : _a.call(module2));
683
+ this.module = module2;
684
+ });
685
+ try {
686
+ await this.modulePromise;
687
+ } catch (error) {
688
+ this.modulePromise = null;
689
+ throw error;
690
+ }
691
+ }
692
+ /** Runs synchronously after preload has initialized the WASM codec. */
693
+ compressSync(input) {
694
+ var _a;
695
+ if (!((_a = this.module) == null ? void 0 : _a.compressSync))
696
+ throw new Error(`${this.name}: call preload() before compressSync()`);
697
+ return copyArrayBuffer(
698
+ this.module.compressSync(new Uint8Array(input), this.options.compressUtils)
699
+ );
700
+ }
701
+ /** Compresses one buffer with the selected compress-utils encoder. */
702
+ async compress(input) {
703
+ await this.preload();
704
+ const module2 = this.module;
705
+ const output = await module2.compress(new Uint8Array(input), this.options.compressUtils);
706
+ return copyArrayBuffer(output);
707
+ }
708
+ /** Incrementally compresses input batches with compress-utils. */
709
+ async *compressBatches(inputBatches) {
710
+ await this.preload();
711
+ const module2 = this.module;
712
+ if (!module2.createCompressStream) {
713
+ yield await this.compress(await this.concatenate(inputBatches));
714
+ return;
715
+ }
716
+ const stream = await module2.createCompressStream(this.options.compressUtils);
717
+ yield* transformBatches(stream, inputBatches);
718
+ }
719
+ };
720
+ CompressUtilsDecompressor = class extends Decompressor {
721
+ name;
722
+ extensions;
723
+ contentEncodings;
724
+ isSupported = true;
725
+ options;
726
+ loadModule;
727
+ /** Module initialized for synchronous operations. */
728
+ module = null;
729
+ /** Shared import and WASM initialization for concurrent callers. */
730
+ modulePromise = null;
731
+ /** Creates a format-specific compress-utils decoder. */
732
+ constructor(metadata2, loadModule, options = {}) {
733
+ super(options);
734
+ this.name = metadata2.name;
735
+ this.extensions = metadata2.extensions || [];
736
+ this.contentEncodings = metadata2.contentEncodings || [];
737
+ this.loadModule = loadModule;
738
+ this.options = options;
739
+ }
740
+ /** Imports and initializes the codec without loading the opposite direction. */
741
+ async preload(modules = {}) {
742
+ await super.preload(modules);
743
+ this.modulePromise ||= this.loadModule().then(async (module2) => {
744
+ var _a;
745
+ await ((_a = module2.preload) == null ? void 0 : _a.call(module2));
746
+ this.module = module2;
747
+ });
748
+ try {
749
+ await this.modulePromise;
750
+ } catch (error) {
751
+ this.modulePromise = null;
752
+ throw error;
753
+ }
754
+ }
755
+ /** Runs synchronously after preload has initialized the WASM codec. */
756
+ decompressSync(input, size) {
757
+ var _a;
758
+ if (!((_a = this.module) == null ? void 0 : _a.decompressSync))
759
+ throw new Error(`${this.name}: call preload() before decompressSync()`);
760
+ return copyDecompressedOutput(
761
+ this.module.decompressSync(new Uint8Array(input), getDecompressOptions(this.options, size)),
762
+ this.options
763
+ );
764
+ }
765
+ /** Decompresses one buffer with the selected compress-utils decoder. */
766
+ async decompress(input, size) {
767
+ const decodeOptions = getDecompressOptions(this.options, size);
768
+ await this.preload();
769
+ const module2 = this.module;
770
+ const output = await module2.decompress(new Uint8Array(input), decodeOptions);
771
+ return copyDecompressedOutput(output, this.options);
772
+ }
773
+ /** Incrementally decompresses input batches with compress-utils. */
774
+ async *decompressBatches(inputBatches) {
775
+ await this.preload();
776
+ const module2 = this.module;
777
+ if (!module2.createDecompressStream) {
778
+ yield await this.decompress(await this.concatenate(inputBatches));
779
+ return;
780
+ }
781
+ const maximum = getMaximumOutputByteLength(this.options);
782
+ const stream = await module2.createDecompressStream();
783
+ yield* transformBatches(stream, inputBatches, maximum);
784
+ }
785
+ };
786
+ }
787
+ });
788
+
789
+ // ../compression/src/deflate-decompressor-compress-utils.ts
790
+ var DeflateCompressUtilsDecompressor;
791
+ var init_deflate_decompressor_compress_utils = __esm({
792
+ "../compression/src/deflate-decompressor-compress-utils.ts"() {
793
+ "use strict";
794
+ init_compress_utils_compression();
795
+ DeflateCompressUtilsDecompressor = class extends CompressUtilsDecompressor {
796
+ constructor(options = {}) {
797
+ super(
798
+ { name: "deflate", contentEncodings: ["deflate"] },
799
+ () => options.raw ? import("compress-utils/deflate/decompress") : import("compress-utils/zlib/decompress"),
800
+ options
801
+ );
802
+ }
803
+ };
804
+ }
805
+ });
806
+
807
+ // ../compression/src/lib/decompression-stream.ts
808
+ async function decompressWithNativeDecompressionStream(input, format) {
809
+ const outputBatches = decompressBatchesWithNativeDecompressionStream([input], format);
810
+ return outputBatches ? await concatenateNativeDecompressionBatches(outputBatches) : null;
811
+ }
812
+ function decompressBatchesWithNativeDecompressionStream(inputBatches, format) {
813
+ const decompressionStream = createNativeDecompressionStream(format);
814
+ return decompressionStream ? transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) : null;
815
+ }
816
+ function createNativeDecompressionStream(format) {
817
+ var _a, _b;
818
+ if (typeof globalThis.DecompressionStream === "undefined") {
819
+ return null;
820
+ }
821
+ if (((_b = (_a = globalThis.process) == null ? void 0 : _a.release) == null ? void 0 : _b.name) === "node" && typeof globalThis.Buffer === "undefined") {
822
+ return null;
823
+ }
824
+ try {
825
+ const DecompressionStreamConstructor = globalThis.DecompressionStream;
826
+ return new DecompressionStreamConstructor(format);
827
+ } catch (error) {
828
+ if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
829
+ return null;
830
+ }
831
+ throw error;
832
+ }
833
+ }
834
+ async function* transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) {
835
+ const writer = decompressionStream.writable.getWriter();
836
+ const reader = decompressionStream.readable.getReader();
837
+ const writePromise = writeBatchesToNativeDecompressionStream(inputBatches, writer);
838
+ writePromise.catch(() => {
839
+ });
840
+ let outputCompleted = false;
841
+ try {
842
+ while (true) {
843
+ const { done, value } = await reader.read();
844
+ if (done) {
845
+ outputCompleted = true;
846
+ break;
847
+ }
848
+ yield copyExactArrayBuffer(value);
849
+ }
850
+ await writePromise;
851
+ } finally {
852
+ if (!outputCompleted) {
853
+ await reader.cancel().catch(() => {
854
+ });
855
+ await writer.abort().catch(() => {
856
+ });
857
+ await writePromise.catch(() => {
858
+ });
859
+ }
860
+ reader.releaseLock();
861
+ }
862
+ }
863
+ async function concatenateNativeDecompressionBatches(outputBatches) {
864
+ const batches = [];
865
+ let byteLength = 0;
866
+ for await (const outputBatch of outputBatches) {
867
+ const bytes = new Uint8Array(outputBatch);
868
+ batches.push(bytes);
869
+ byteLength += bytes.byteLength;
870
+ }
871
+ const output = new Uint8Array(byteLength);
872
+ let byteOffset = 0;
873
+ for (const batch of batches) {
874
+ output.set(batch, byteOffset);
875
+ byteOffset += batch.byteLength;
876
+ }
877
+ return output.buffer;
878
+ }
879
+ function copyExactArrayBuffer(value) {
880
+ return new Uint8Array(value).buffer;
881
+ }
882
+ async function writeBatchesToNativeDecompressionStream(inputBatches, writer) {
883
+ try {
884
+ for await (const inputBatch of inputBatches) {
885
+ await writer.write(new Uint8Array(inputBatch));
886
+ }
887
+ await writer.close();
888
+ } catch (error) {
889
+ await writer.abort(error).catch(() => {
890
+ });
891
+ throw error;
892
+ }
893
+ }
894
+ var init_decompression_stream = __esm({
895
+ "../compression/src/lib/decompression-stream.ts"() {
896
+ "use strict";
897
+ }
898
+ });
899
+
900
+ // ../compression/src/deflate-decompressor.ts
901
+ var DeflateDecompressor;
902
+ var init_deflate_decompressor = __esm({
903
+ "../compression/src/deflate-decompressor.ts"() {
904
+ "use strict";
905
+ init_deflate_decompressor_compress_utils();
906
+ init_decompression_stream();
907
+ DeflateDecompressor = class extends DeflateCompressUtilsDecompressor {
908
+ /** Decompresses with native streams when available, otherwise lazily initializes WASM. */
909
+ async decompress(input, size) {
910
+ if (this.options.useNative !== false) {
911
+ const output = await decompressWithNativeDecompressionStream(
912
+ input,
913
+ this.options.raw ? "deflate-raw" : "deflate"
914
+ );
915
+ if (output) return output;
916
+ }
917
+ return super.decompress(input, size);
918
+ }
919
+ /** Streams native batches when available, otherwise uses the WASM stream. */
920
+ async *decompressBatches(inputBatches) {
921
+ if (this.options.useNative !== false) {
922
+ const output = decompressBatchesWithNativeDecompressionStream(
923
+ inputBatches,
924
+ this.options.raw ? "deflate-raw" : "deflate"
925
+ );
926
+ if (output) {
927
+ yield* output;
928
+ return;
929
+ }
930
+ }
931
+ yield* super.decompressBatches(inputBatches);
932
+ }
933
+ };
934
+ }
935
+ });
936
+
937
+ // ../crypto/src/lib/hash.ts
938
+ var Hash;
939
+ var init_hash = __esm({
940
+ "../crypto/src/lib/hash.ts"() {
941
+ "use strict";
942
+ init_loader_utils();
943
+ Hash = class {
944
+ constructor(options = {}) {
945
+ this.hashBatches = this.hashBatches.bind(this);
946
+ }
947
+ async preload() {
948
+ return;
949
+ }
950
+ async *hashBatches(asyncIterator, encoding = "base64") {
951
+ var _a, _b;
952
+ const arrayBuffers = [];
953
+ for await (const arrayBuffer of asyncIterator) {
954
+ arrayBuffers.push(arrayBuffer);
955
+ yield arrayBuffer;
956
+ }
957
+ const output = await this.concatenate(arrayBuffers);
958
+ const hash = await this.hash(output, encoding);
959
+ (_b = (_a = this.options.crypto) == null ? void 0 : _a.onEnd) == null ? void 0 : _b.call(_a, { hash });
960
+ }
961
+ // HELPERS
962
+ async concatenate(asyncIterator) {
963
+ return await concatenateArrayBuffersAsync(asyncIterator);
964
+ }
965
+ };
966
+ }
967
+ });
968
+
969
+ // ../crypto/src/lib/algorithms/crc32.ts
970
+ function getCRC32Table() {
971
+ return CRC32TAB;
972
+ }
973
+ var CRC32, CRC32TAB;
974
+ var init_crc32 = __esm({
975
+ "../crypto/src/lib/algorithms/crc32.ts"() {
976
+ "use strict";
977
+ CRC32 = class {
978
+ crc;
979
+ constructor() {
980
+ this.crc = ~0;
981
+ }
982
+ update(arrayBuffer) {
983
+ const CRC32_TABLE = getCRC32Table();
984
+ const byteArray = new Uint8Array(arrayBuffer);
985
+ for (let i = 0; i < byteArray.byteLength; i++) {
986
+ this.crc = this.crc >>> 8 ^ CRC32_TABLE[(this.crc ^ byteArray[i]) & 255];
987
+ }
988
+ return this;
989
+ }
990
+ finalize() {
991
+ this.crc = (this.crc ^ -1) >>> 0;
992
+ return this.crc;
993
+ }
994
+ };
995
+ CRC32TAB = Uint32Array.of(
996
+ 0,
997
+ 1996959894,
998
+ 3993919788,
999
+ 2567524794,
1000
+ 124634137,
1001
+ 1886057615,
1002
+ 3915621685,
1003
+ 2657392035,
1004
+ 249268274,
1005
+ 2044508324,
1006
+ 3772115230,
1007
+ 2547177864,
1008
+ 162941995,
1009
+ 2125561021,
1010
+ 3887607047,
1011
+ 2428444049,
1012
+ 498536548,
1013
+ 1789927666,
1014
+ 4089016648,
1015
+ 2227061214,
1016
+ 450548861,
1017
+ 1843258603,
1018
+ 4107580753,
1019
+ 2211677639,
1020
+ 325883990,
1021
+ 1684777152,
1022
+ 4251122042,
1023
+ 2321926636,
1024
+ 335633487,
1025
+ 1661365465,
1026
+ 4195302755,
1027
+ 2366115317,
1028
+ 997073096,
1029
+ 1281953886,
1030
+ 3579855332,
1031
+ 2724688242,
1032
+ 1006888145,
1033
+ 1258607687,
1034
+ 3524101629,
1035
+ 2768942443,
1036
+ 901097722,
1037
+ 1119000684,
1038
+ 3686517206,
1039
+ 2898065728,
1040
+ 853044451,
1041
+ 1172266101,
1042
+ 3705015759,
1043
+ 2882616665,
1044
+ 651767980,
1045
+ 1373503546,
1046
+ 3369554304,
1047
+ 3218104598,
1048
+ 565507253,
1049
+ 1454621731,
1050
+ 3485111705,
1051
+ 3099436303,
1052
+ 671266974,
1053
+ 1594198024,
1054
+ 3322730930,
1055
+ 2970347812,
1056
+ 795835527,
1057
+ 1483230225,
1058
+ 3244367275,
1059
+ 3060149565,
1060
+ 1994146192,
1061
+ 31158534,
1062
+ 2563907772,
1063
+ 4023717930,
1064
+ 1907459465,
1065
+ 112637215,
1066
+ 2680153253,
1067
+ 3904427059,
1068
+ 2013776290,
1069
+ 251722036,
1070
+ 2517215374,
1071
+ 3775830040,
1072
+ 2137656763,
1073
+ 141376813,
1074
+ 2439277719,
1075
+ 3865271297,
1076
+ 1802195444,
1077
+ 476864866,
1078
+ 2238001368,
1079
+ 4066508878,
1080
+ 1812370925,
1081
+ 453092731,
1082
+ 2181625025,
1083
+ 4111451223,
1084
+ 1706088902,
1085
+ 314042704,
1086
+ 2344532202,
1087
+ 4240017532,
1088
+ 1658658271,
1089
+ 366619977,
1090
+ 2362670323,
1091
+ 4224994405,
1092
+ 1303535960,
1093
+ 984961486,
1094
+ 2747007092,
1095
+ 3569037538,
1096
+ 1256170817,
1097
+ 1037604311,
1098
+ 2765210733,
1099
+ 3554079995,
1100
+ 1131014506,
1101
+ 879679996,
1102
+ 2909243462,
1103
+ 3663771856,
1104
+ 1141124467,
1105
+ 855842277,
1106
+ 2852801631,
1107
+ 3708648649,
1108
+ 1342533948,
1109
+ 654459306,
1110
+ 3188396048,
1111
+ 3373015174,
1112
+ 1466479909,
1113
+ 544179635,
1114
+ 3110523913,
1115
+ 3462522015,
1116
+ 1591671054,
1117
+ 702138776,
1118
+ 2966460450,
1119
+ 3352799412,
1120
+ 1504918807,
1121
+ 783551873,
1122
+ 3082640443,
1123
+ 3233442989,
1124
+ 3988292384,
1125
+ 2596254646,
1126
+ 62317068,
1127
+ 1957810842,
1128
+ 3939845945,
1129
+ 2647816111,
1130
+ 81470997,
1131
+ 1943803523,
1132
+ 3814918930,
1133
+ 2489596804,
1134
+ 225274430,
1135
+ 2053790376,
1136
+ 3826175755,
1137
+ 2466906013,
1138
+ 167816743,
1139
+ 2097651377,
1140
+ 4027552580,
1141
+ 2265490386,
1142
+ 503444072,
1143
+ 1762050814,
1144
+ 4150417245,
1145
+ 2154129355,
1146
+ 426522225,
1147
+ 1852507879,
1148
+ 4275313526,
1149
+ 2312317920,
1150
+ 282753626,
1151
+ 1742555852,
1152
+ 4189708143,
1153
+ 2394877945,
1154
+ 397917763,
1155
+ 1622183637,
1156
+ 3604390888,
1157
+ 2714866558,
1158
+ 953729732,
1159
+ 1340076626,
1160
+ 3518719985,
1161
+ 2797360999,
1162
+ 1068828381,
1163
+ 1219638859,
1164
+ 3624741850,
1165
+ 2936675148,
1166
+ 906185462,
1167
+ 1090812512,
1168
+ 3747672003,
1169
+ 2825379669,
1170
+ 829329135,
1171
+ 1181335161,
1172
+ 3412177804,
1173
+ 3160834842,
1174
+ 628085408,
1175
+ 1382605366,
1176
+ 3423369109,
1177
+ 3138078467,
1178
+ 570562233,
1179
+ 1426400815,
1180
+ 3317316542,
1181
+ 2998733608,
1182
+ 733239954,
1183
+ 1555261956,
1184
+ 3268935591,
1185
+ 3050360625,
1186
+ 752459403,
1187
+ 1541320221,
1188
+ 2607071920,
1189
+ 3965973030,
1190
+ 1969922972,
1191
+ 40735498,
1192
+ 2617837225,
1193
+ 3943577151,
1194
+ 1913087877,
1195
+ 83908371,
1196
+ 2512341634,
1197
+ 3803740692,
1198
+ 2075208622,
1199
+ 213261112,
1200
+ 2463272603,
1201
+ 3855990285,
1202
+ 2094854071,
1203
+ 198958881,
1204
+ 2262029012,
1205
+ 4057260610,
1206
+ 1759359992,
1207
+ 534414190,
1208
+ 2176718541,
1209
+ 4139329115,
1210
+ 1873836001,
1211
+ 414664567,
1212
+ 2282248934,
1213
+ 4279200368,
1214
+ 1711684554,
1215
+ 285281116,
1216
+ 2405801727,
1217
+ 4167216745,
1218
+ 1634467795,
1219
+ 376229701,
1220
+ 2685067896,
1221
+ 3608007406,
1222
+ 1308918612,
1223
+ 956543938,
1224
+ 2808555105,
1225
+ 3495958263,
1226
+ 1231636301,
1227
+ 1047427035,
1228
+ 2932959818,
1229
+ 3654703836,
1230
+ 1088359270,
1231
+ 936918e3,
1232
+ 2847714899,
1233
+ 3736837829,
1234
+ 1202900863,
1235
+ 817233897,
1236
+ 3183342108,
1237
+ 3401237130,
1238
+ 1404277552,
1239
+ 615818150,
1240
+ 3134207493,
1241
+ 3453421203,
1242
+ 1423857449,
1243
+ 601450431,
1244
+ 3009837614,
1245
+ 3294710456,
1246
+ 1567103746,
1247
+ 711928724,
1248
+ 3020668471,
1249
+ 3272380065,
1250
+ 1510334235,
1251
+ 755167117
1252
+ );
1253
+ }
1254
+ });
1255
+
1256
+ // ../crypto/src/lib/utils/base64-utils.ts
1257
+ function asciiToBase64(string) {
1258
+ string = `${string}`;
1259
+ for (let i = 0; i < string.length; i++) {
1260
+ if (string.charCodeAt(i) > 255) {
1261
+ return null;
1262
+ }
1263
+ }
1264
+ let out = "";
1265
+ for (let i = 0; i < string.length; i += 3) {
1266
+ const groupsOfSix = [void 0, void 0, void 0, void 0];
1267
+ groupsOfSix[0] = string.charCodeAt(i) >> 2;
1268
+ groupsOfSix[1] = (string.charCodeAt(i) & 3) << 4;
1269
+ if (string.length > i + 1) {
1270
+ groupsOfSix[1] |= string.charCodeAt(i + 1) >> 4;
1271
+ groupsOfSix[2] = (string.charCodeAt(i + 1) & 15) << 2;
1272
+ }
1273
+ if (string.length > i + 2) {
1274
+ groupsOfSix[2] |= string.charCodeAt(i + 2) >> 6;
1275
+ groupsOfSix[3] = string.charCodeAt(i + 2) & 63;
1276
+ }
1277
+ for (let j = 0; j < groupsOfSix.length; j++) {
1278
+ if (typeof groupsOfSix[j] === "undefined") {
1279
+ out += "=";
1280
+ } else {
1281
+ out += btoaLookup(groupsOfSix[j]);
1282
+ }
1283
+ }
1284
+ }
1285
+ return out;
1286
+ }
1287
+ function btoaLookup(idx) {
1288
+ if (idx < 26) {
1289
+ return String.fromCharCode(idx + "A".charCodeAt(0));
1290
+ }
1291
+ if (idx < 52) {
1292
+ return String.fromCharCode(idx - 26 + "a".charCodeAt(0));
1293
+ }
1294
+ if (idx < 62) {
1295
+ return String.fromCharCode(idx - 52 + "0".charCodeAt(0));
1296
+ }
1297
+ if (idx === 62) {
1298
+ return "+";
1299
+ }
1300
+ if (idx === 63) {
1301
+ return "/";
1302
+ }
1303
+ return void 0;
1304
+ }
1305
+ var init_base64_utils = __esm({
1306
+ "../crypto/src/lib/utils/base64-utils.ts"() {
1307
+ "use strict";
1308
+ }
1309
+ });
1310
+
1311
+ // ../crypto/src/lib/utils/digest-utils.ts
1312
+ function encodeNumber(number, encoding) {
1313
+ switch (encoding) {
1314
+ case "hex":
1315
+ return convertNumberToHex(number);
1316
+ case "base64":
1317
+ return convertHexToBase64(convertNumberToHex(number));
1318
+ default:
1319
+ throw new Error(encoding);
1320
+ }
1321
+ }
1322
+ function encodeHex(hex, encoding) {
1323
+ switch (encoding) {
1324
+ case "hex":
1325
+ return hex;
1326
+ case "base64":
1327
+ return convertHexToBase64(hex);
1328
+ default:
1329
+ throw new Error(encoding);
1330
+ }
1331
+ }
1332
+ function convertHexToBase64(hexstring) {
1333
+ if (hexstring.length % 2 !== 0) {
1334
+ hexstring = `0${hexstring}`;
1335
+ }
1336
+ const matches2 = hexstring.match(/\w{2}/g) || [];
1337
+ const string = matches2.map((a) => String.fromCharCode(parseInt(a, 16))).join("");
1338
+ return asciiToBase64(string) || "";
1339
+ }
1340
+ function convertNumberToHex(cipher) {
1341
+ const hexString = cipher.toString(16);
1342
+ return hexString === "0" ? `0${hexString}` : hexString;
1343
+ }
1344
+ var init_digest_utils = __esm({
1345
+ "../crypto/src/lib/utils/digest-utils.ts"() {
1346
+ "use strict";
1347
+ init_base64_utils();
1348
+ }
1349
+ });
1350
+
1351
+ // ../crypto/src/lib/crc32-hash.ts
1352
+ var CRC32Hash;
1353
+ var init_crc32_hash = __esm({
1354
+ "../crypto/src/lib/crc32-hash.ts"() {
1355
+ "use strict";
1356
+ init_hash();
1357
+ init_crc32();
1358
+ init_digest_utils();
1359
+ CRC32Hash = class extends Hash {
1360
+ name = "crc32";
1361
+ options;
1362
+ constructor(options = {}) {
1363
+ super();
1364
+ this.options = { crypto: {}, ...options };
1365
+ this.hashBatches = this.hashBatches.bind(this);
1366
+ }
1367
+ /**
1368
+ * Atomic hash calculation
1369
+ * @returns base64 encoded hash
1370
+ */
1371
+ async hash(input, encoding) {
1372
+ return this.hashSync(input, encoding);
1373
+ }
1374
+ hashSync(input, encoding) {
1375
+ const hash = new CRC32();
1376
+ hash.update(input);
1377
+ const digest = hash.finalize();
1378
+ return encodeNumber(digest, encoding);
1379
+ }
1380
+ async *hashBatches(asyncIterator, encoding = "base64") {
1381
+ var _a, _b;
1382
+ const hash = new CRC32();
1383
+ for await (const chunk of asyncIterator) {
1384
+ hash.update(chunk);
1385
+ yield chunk;
1386
+ }
1387
+ const digest = hash.finalize();
1388
+ (_b = (_a = this.options.crypto) == null ? void 0 : _a.onEnd) == null ? void 0 : _b.call(_a, { hash: encodeNumber(digest, encoding) });
1389
+ }
1390
+ };
1391
+ }
1392
+ });
1393
+
1394
+ // ../crypto/src/lib/algorithms/md5-wasm.ts
1395
+ async function md5WASM(data) {
1396
+ const input = normalizeInput(data);
1397
+ if (!input) {
1398
+ throw new TypeError(parmTypeErrStr);
1399
+ }
1400
+ if (!wasm || input.length <= bounder) {
1401
+ return makeMD5JS()(input);
1402
+ }
1403
+ if (input.length > upperLimit) {
1404
+ throw new Error(tooBigErrStr);
1405
+ }
1406
+ const memory = new WebAssembly.Memory({
1407
+ initial: input.length > 32e6 ? input.length > 64e6 ? input.length > 128e6 ? 4096 : 2048 : 1024 : 512
1408
+ });
1409
+ const memoryView = new Uint32Array(memory.buffer);
1410
+ const { instance } = await WebAssembly.instantiate(wasm, {
1411
+ imports: { mem: memory, log: console.log }
1412
+ });
1413
+ return makeMD5WA()(input, instance.exports, memoryView);
1414
+ }
1415
+ function calculateMD5Sync(data) {
1416
+ const input = normalizeInput(data);
1417
+ if (!input) {
1418
+ throw new TypeError(parmTypeErrStr);
1419
+ }
1420
+ return makeMD5JS()(input);
1421
+ }
1422
+ function makeMD5WA() {
1423
+ var _loop, loops;
1424
+ var getA, setA, getB, setB, getC, setC, getD, setD, _getX, _setX, memView;
1425
+ var md5WA = function(message) {
1426
+ var m00, m01, m02, m03, m04, m05, m06, m07, m08, m09, m10, m11, m12, m13, m14, m15, aa, bb, cc, dd, m, _k;
1427
+ var _qwerty = (/* @__PURE__ */ new Date()).getTime();
1428
+ var _md5Used = 0;
1429
+ var a = 1732584193, b = -271733879, c = -1732584194, d = 271733878, i = 0, l = message.length * 8, len;
1430
+ len = bytesToWordsNewer(message, memView);
1431
+ memView[l >>> 5] |= 128 << l % 32;
1432
+ memView[(l + 64 >>> 9 << 4) + 14] = l;
1433
+ len = (l + 64 >>> 9 << 4) + 15;
1434
+ m = memView;
1435
+ while (i < len) {
1436
+ if (len > i + bounder) {
1437
+ setA(a);
1438
+ setB(b);
1439
+ setC(c);
1440
+ setD(d);
1441
+ loops(biteSize);
1442
+ i = i + biteSize * 16;
1443
+ a = getA();
1444
+ b = getB();
1445
+ c = getC();
1446
+ d = getD();
1447
+ _md5Used++;
1448
+ } else {
1449
+ aa = a;
1450
+ bb = b;
1451
+ cc = c;
1452
+ dd = d;
1453
+ m00 = m[i + 0] >>> 0;
1454
+ m01 = m[i + 1] >>> 0;
1455
+ m02 = m[i + 2] >>> 0;
1456
+ m03 = m[i + 3] >>> 0;
1457
+ m04 = m[i + 4] >>> 0;
1458
+ m05 = m[i + 5] >>> 0;
1459
+ m06 = m[i + 6] >>> 0;
1460
+ m07 = m[i + 7] >>> 0;
1461
+ m08 = m[i + 8] >>> 0;
1462
+ m09 = m[i + 9] >>> 0;
1463
+ m10 = m[i + 10] >>> 0;
1464
+ m11 = m[i + 11] >>> 0;
1465
+ m12 = m[i + 12] >>> 0;
1466
+ m13 = m[i + 13] >>> 0;
1467
+ m14 = m[i + 14] >>> 0;
1468
+ m15 = m[i + 15] >>> 0;
1469
+ a = ____(7, 25, a + (b & c | ~b & d) + m00 - 680876936) + b;
1470
+ d = ____(12, 20, d + (a & b | ~a & c) + m01 - 389564586) + a;
1471
+ c = ____(17, 15, c + (d & a | ~d & b) + m02 + 606105819) + d;
1472
+ b = ____(22, 10, b + (c & d | ~c & a) + m03 - 1044525330) + c;
1473
+ a = ____(7, 25, a + (b & c | ~b & d) + m04 - 176418897) + b;
1474
+ d = ____(12, 20, d + (a & b | ~a & c) + m05 + 1200080426) + a;
1475
+ c = ____(17, 15, c + (d & a | ~d & b) + m06 - 1473231341) + d;
1476
+ b = ____(22, 10, b + (c & d | ~c & a) + m07 - 45705983) + c;
1477
+ a = ____(7, 25, a + (b & c | ~b & d) + m08 + 1770035416) + b;
1478
+ d = ____(12, 20, d + (a & b | ~a & c) + m09 - 1958414417) + a;
1479
+ c = ____(17, 15, c + (d & a | ~d & b) + m10 - 42063) + d;
1480
+ b = ____(22, 10, b + (c & d | ~c & a) + m11 - 1990404162) + c;
1481
+ a = ____(7, 25, a + (b & c | ~b & d) + m12 + 1804603682) + b;
1482
+ d = ____(12, 20, d + (a & b | ~a & c) + m13 - 40341101) + a;
1483
+ c = ____(17, 15, c + (d & a | ~d & b) + m14 - 1502002290) + d;
1484
+ b = ____(22, 10, b + (c & d | ~c & a) + m15 + 1236535329) + c;
1485
+ a = ____(5, 27, a + (b & d | c & ~d) + m01 - 165796510) + b;
1486
+ d = ____(9, 23, d + (a & c | b & ~c) + m06 - 1069501632) + a;
1487
+ c = ____(14, 18, c + (d & b | a & ~b) + m11 + 643717713) + d;
1488
+ b = ____(20, 12, b + (c & a | d & ~a) + m00 - 373897302) + c;
1489
+ a = ____(5, 27, a + (b & d | c & ~d) + m05 - 701558691) + b;
1490
+ d = ____(9, 23, d + (a & c | b & ~c) + m10 + 38016083) + a;
1491
+ c = ____(14, 18, c + (d & b | a & ~b) + m15 - 660478335) + d;
1492
+ b = ____(20, 12, b + (c & a | d & ~a) + m04 - 405537848) + c;
1493
+ a = ____(5, 27, a + (b & d | c & ~d) + m09 + 568446438) + b;
1494
+ d = ____(9, 23, d + (a & c | b & ~c) + m14 - 1019803690) + a;
1495
+ c = ____(14, 18, c + (d & b | a & ~b) + m03 - 187363961) + d;
1496
+ b = ____(20, 12, b + (c & a | d & ~a) + m08 + 1163531501) + c;
1497
+ a = ____(5, 27, a + (b & d | c & ~d) + m13 - 1444681467) + b;
1498
+ d = ____(9, 23, d + (a & c | b & ~c) + m02 - 51403784) + a;
1499
+ c = ____(14, 18, c + (d & b | a & ~b) + m07 + 1735328473) + d;
1500
+ b = ____(20, 12, b + (c & a | d & ~a) + m12 - 1926607734) + c;
1501
+ a = ____(4, 28, a + (b ^ c ^ d) + m05 - 378558) + b;
1502
+ d = ____(11, 21, d + (a ^ b ^ c) + m08 - 2022574463) + a;
1503
+ c = ____(16, 16, c + (d ^ a ^ b) + m11 + 1839030562) + d;
1504
+ b = ____(23, 9, b + (c ^ d ^ a) + m14 - 35309556) + c;
1505
+ a = ____(4, 28, a + (b ^ c ^ d) + m01 - 1530992060) + b;
1506
+ d = ____(11, 21, d + (a ^ b ^ c) + m04 + 1272893353) + a;
1507
+ c = ____(16, 16, c + (d ^ a ^ b) + m07 - 155497632) + d;
1508
+ b = ____(23, 9, b + (c ^ d ^ a) + m10 - 1094730640) + c;
1509
+ a = ____(4, 28, a + (b ^ c ^ d) + m13 + 681279174) + b;
1510
+ d = ____(11, 21, d + (a ^ b ^ c) + m00 - 358537222) + a;
1511
+ c = ____(16, 16, c + (d ^ a ^ b) + m03 - 722521979) + d;
1512
+ b = ____(23, 9, b + (c ^ d ^ a) + m06 + 76029189) + c;
1513
+ a = ____(4, 28, a + (b ^ c ^ d) + m09 - 640364487) + b;
1514
+ d = ____(11, 21, d + (a ^ b ^ c) + m12 - 421815835) + a;
1515
+ c = ____(16, 16, c + (d ^ a ^ b) + m15 + 530742520) + d;
1516
+ b = ____(23, 9, b + (c ^ d ^ a) + m02 - 995338651) + c;
1517
+ a = ____(6, 26, a + (c ^ (b | ~d)) + m00 - 198630844) + b;
1518
+ d = ____(10, 22, d + (b ^ (a | ~c)) + m07 + 1126891415) + a;
1519
+ c = ____(15, 17, c + (a ^ (d | ~b)) + m14 - 1416354905) + d;
1520
+ b = ____(21, 11, b + (d ^ (c | ~a)) + m05 - 57434055) + c;
1521
+ a = ____(6, 26, a + (c ^ (b | ~d)) + m12 + 1700485571) + b;
1522
+ d = ____(10, 22, d + (b ^ (a | ~c)) + m03 - 1894986606) + a;
1523
+ c = ____(15, 17, c + (a ^ (d | ~b)) + m10 - 1051523) + d;
1524
+ b = ____(21, 11, b + (d ^ (c | ~a)) + m01 - 2054922799) + c;
1525
+ a = ____(6, 26, a + (c ^ (b | ~d)) + m08 + 1873313359) + b;
1526
+ d = ____(10, 22, d + (b ^ (a | ~c)) + m15 - 30611744) + a;
1527
+ c = ____(15, 17, c + (a ^ (d | ~b)) + m06 - 1560198380) + d;
1528
+ b = ____(21, 11, b + (d ^ (c | ~a)) + m13 + 1309151649) + c;
1529
+ a = ____(6, 26, a + (c ^ (b | ~d)) + m04 - 145523070) + b;
1530
+ d = ____(10, 22, d + (b ^ (a | ~c)) + m11 - 1120210379) + a;
1531
+ c = ____(15, 17, c + (a ^ (d | ~b)) + m02 + 718787259) + d;
1532
+ b = ____(21, 11, b + (d ^ (c | ~a)) + m09 - 343485551) + c;
1533
+ i = i + 16;
1534
+ a = a + aa >>> 0;
1535
+ b = b + bb >>> 0;
1536
+ c = c + cc >>> 0;
1537
+ d = d + dd >>> 0;
1538
+ }
1539
+ }
1540
+ return crypt.endian([a, b, c, d]);
1541
+ function ____(s, t, n) {
1542
+ return n << s | n >>> t;
1543
+ }
1544
+ function bytesToWordsNewer(bytes, words) {
1545
+ var i2 = -1, l2 = Math.floor((bytes.length - 1) / 4), j = 0, b0, b1, b2, b3;
1546
+ while (l2 - 8 > i2++) {
1547
+ j = i2 << 2;
1548
+ words[i2] = bytes[j + 0] | bytes[j + 1] << 8 | bytes[j + 2] << 16 | bytes[j + 3] << 24;
1549
+ }
1550
+ i2--;
1551
+ while (l2 > i2++) {
1552
+ j = i2 << 2;
1553
+ b0 = typeof bytes[j + 0] === "undefined" ? 0 : bytes[j + 0];
1554
+ b1 = typeof bytes[j + 1] === "undefined" ? 0 : bytes[j + 1];
1555
+ b2 = typeof bytes[j + 2] === "undefined" ? 0 : bytes[j + 2];
1556
+ b3 = typeof bytes[j + 3] === "undefined" ? 0 : bytes[j + 3];
1557
+ words[i2] = b0 | b1 << 8 | b2 << 16 | b3 << 24;
1558
+ }
1559
+ return l2 + 1;
1560
+ }
1561
+ };
1562
+ return function(message, exports, mView, options) {
1563
+ var digestbytes;
1564
+ loops = exports.loops;
1565
+ _loop = exports.loop;
1566
+ getA = exports.getA;
1567
+ getB = exports.getB;
1568
+ getC = exports.getC;
1569
+ getD = exports.getD;
1570
+ _getX = exports.getX;
1571
+ setA = exports.setA;
1572
+ setB = exports.setB;
1573
+ setC = exports.setC;
1574
+ setD = exports.setD;
1575
+ _setX = exports.setX;
1576
+ memView = mView;
1577
+ digestbytes = crypt.wordsToBytes(md5WA(message));
1578
+ return options && options.asBytes ? digestbytes : crypt.bytesconvertNumberToHex(digestbytes);
1579
+ };
1580
+ }
1581
+ function makeMD5JS() {
1582
+ var md5JS = function(message, options) {
1583
+ var m00, m01, m02, m03, m04, m05, m06, m07, m08, m09, m10, m11, m12, m13, m14, m15, aa, bb, cc, dd, m;
1584
+ var _qwerty = (/* @__PURE__ */ new Date()).getTime();
1585
+ var a = 1732584193, b = -271733879, c = -1732584194, d = 271733878, l = message.length * 8;
1586
+ m = crypt.bytesToWords(message);
1587
+ for (var j = 0; j < m.length; j++) {
1588
+ m[j] = (m[j] << 8 | m[j] >>> 24) & 16711935 | (m[j] << 24 | m[j] >>> 8) & 4278255360;
1589
+ }
1590
+ m[l >>> 5] |= 128 << l % 32;
1591
+ m[(l + 64 >>> 9 << 4) + 14] = l;
1592
+ for (var i = 0; i < m.length; i += 16) {
1593
+ aa = a;
1594
+ bb = b;
1595
+ cc = c;
1596
+ dd = d;
1597
+ m00 = m[i + 0] >>> 0;
1598
+ m01 = m[i + 1] >>> 0;
1599
+ m02 = m[i + 2] >>> 0;
1600
+ m03 = m[i + 3] >>> 0;
1601
+ m04 = m[i + 4] >>> 0;
1602
+ m05 = m[i + 5] >>> 0;
1603
+ m06 = m[i + 6] >>> 0;
1604
+ m07 = m[i + 7] >>> 0;
1605
+ m08 = m[i + 8] >>> 0;
1606
+ m09 = m[i + 9] >>> 0;
1607
+ m10 = m[i + 10] >>> 0;
1608
+ m11 = m[i + 11] >>> 0;
1609
+ m12 = m[i + 12] >>> 0;
1610
+ m13 = m[i + 13] >>> 0;
1611
+ m14 = m[i + 14] >>> 0;
1612
+ m15 = m[i + 15] >>> 0;
1613
+ a = ____(7, 25, a + (b & c | ~b & d) + m00 - 680876936) + b;
1614
+ d = ____(12, 20, d + (a & b | ~a & c) + m01 - 389564586) + a;
1615
+ c = ____(17, 15, c + (d & a | ~d & b) + m02 + 606105819) + d;
1616
+ b = ____(22, 10, b + (c & d | ~c & a) + m03 - 1044525330) + c;
1617
+ a = ____(7, 25, a + (b & c | ~b & d) + m04 - 176418897) + b;
1618
+ d = ____(12, 20, d + (a & b | ~a & c) + m05 + 1200080426) + a;
1619
+ c = ____(17, 15, c + (d & a | ~d & b) + m06 - 1473231341) + d;
1620
+ b = ____(22, 10, b + (c & d | ~c & a) + m07 - 45705983) + c;
1621
+ a = ____(7, 25, a + (b & c | ~b & d) + m08 + 1770035416) + b;
1622
+ d = ____(12, 20, d + (a & b | ~a & c) + m09 - 1958414417) + a;
1623
+ c = ____(17, 15, c + (d & a | ~d & b) + m10 - 42063) + d;
1624
+ b = ____(22, 10, b + (c & d | ~c & a) + m11 - 1990404162) + c;
1625
+ a = ____(7, 25, a + (b & c | ~b & d) + m12 + 1804603682) + b;
1626
+ d = ____(12, 20, d + (a & b | ~a & c) + m13 - 40341101) + a;
1627
+ c = ____(17, 15, c + (d & a | ~d & b) + m14 - 1502002290) + d;
1628
+ b = ____(22, 10, b + (c & d | ~c & a) + m15 + 1236535329) + c;
1629
+ a = ____(5, 27, a + (b & d | c & ~d) + m01 - 165796510) + b;
1630
+ d = ____(9, 23, d + (a & c | b & ~c) + m06 - 1069501632) + a;
1631
+ c = ____(14, 18, c + (d & b | a & ~b) + m11 + 643717713) + d;
1632
+ b = ____(20, 12, b + (c & a | d & ~a) + m00 - 373897302) + c;
1633
+ a = ____(5, 27, a + (b & d | c & ~d) + m05 - 701558691) + b;
1634
+ d = ____(9, 23, d + (a & c | b & ~c) + m10 + 38016083) + a;
1635
+ c = ____(14, 18, c + (d & b | a & ~b) + m15 - 660478335) + d;
1636
+ b = ____(20, 12, b + (c & a | d & ~a) + m04 - 405537848) + c;
1637
+ a = ____(5, 27, a + (b & d | c & ~d) + m09 + 568446438) + b;
1638
+ d = ____(9, 23, d + (a & c | b & ~c) + m14 - 1019803690) + a;
1639
+ c = ____(14, 18, c + (d & b | a & ~b) + m03 - 187363961) + d;
1640
+ b = ____(20, 12, b + (c & a | d & ~a) + m08 + 1163531501) + c;
1641
+ a = ____(5, 27, a + (b & d | c & ~d) + m13 - 1444681467) + b;
1642
+ d = ____(9, 23, d + (a & c | b & ~c) + m02 - 51403784) + a;
1643
+ c = ____(14, 18, c + (d & b | a & ~b) + m07 + 1735328473) + d;
1644
+ b = ____(20, 12, b + (c & a | d & ~a) + m12 - 1926607734) + c;
1645
+ a = ____(4, 28, a + (b ^ c ^ d) + m05 - 378558) + b;
1646
+ d = ____(11, 21, d + (a ^ b ^ c) + m08 - 2022574463) + a;
1647
+ c = ____(16, 16, c + (d ^ a ^ b) + m11 + 1839030562) + d;
1648
+ b = ____(23, 9, b + (c ^ d ^ a) + m14 - 35309556) + c;
1649
+ a = ____(4, 28, a + (b ^ c ^ d) + m01 - 1530992060) + b;
1650
+ d = ____(11, 21, d + (a ^ b ^ c) + m04 + 1272893353) + a;
1651
+ c = ____(16, 16, c + (d ^ a ^ b) + m07 - 155497632) + d;
1652
+ b = ____(23, 9, b + (c ^ d ^ a) + m10 - 1094730640) + c;
1653
+ a = ____(4, 28, a + (b ^ c ^ d) + m13 + 681279174) + b;
1654
+ d = ____(11, 21, d + (a ^ b ^ c) + m00 - 358537222) + a;
1655
+ c = ____(16, 16, c + (d ^ a ^ b) + m03 - 722521979) + d;
1656
+ b = ____(23, 9, b + (c ^ d ^ a) + m06 + 76029189) + c;
1657
+ a = ____(4, 28, a + (b ^ c ^ d) + m09 - 640364487) + b;
1658
+ d = ____(11, 21, d + (a ^ b ^ c) + m12 - 421815835) + a;
1659
+ c = ____(16, 16, c + (d ^ a ^ b) + m15 + 530742520) + d;
1660
+ b = ____(23, 9, b + (c ^ d ^ a) + m02 - 995338651) + c;
1661
+ a = ____(6, 26, a + (c ^ (b | ~d)) + m00 - 198630844) + b;
1662
+ d = ____(10, 22, d + (b ^ (a | ~c)) + m07 + 1126891415) + a;
1663
+ c = ____(15, 17, c + (a ^ (d | ~b)) + m14 - 1416354905) + d;
1664
+ b = ____(21, 11, b + (d ^ (c | ~a)) + m05 - 57434055) + c;
1665
+ a = ____(6, 26, a + (c ^ (b | ~d)) + m12 + 1700485571) + b;
1666
+ d = ____(10, 22, d + (b ^ (a | ~c)) + m03 - 1894986606) + a;
1667
+ c = ____(15, 17, c + (a ^ (d | ~b)) + m10 - 1051523) + d;
1668
+ b = ____(21, 11, b + (d ^ (c | ~a)) + m01 - 2054922799) + c;
1669
+ a = ____(6, 26, a + (c ^ (b | ~d)) + m08 + 1873313359) + b;
1670
+ d = ____(10, 22, d + (b ^ (a | ~c)) + m15 - 30611744) + a;
1671
+ c = ____(15, 17, c + (a ^ (d | ~b)) + m06 - 1560198380) + d;
1672
+ b = ____(21, 11, b + (d ^ (c | ~a)) + m13 + 1309151649) + c;
1673
+ a = ____(6, 26, a + (c ^ (b | ~d)) + m04 - 145523070) + b;
1674
+ d = ____(10, 22, d + (b ^ (a | ~c)) + m11 - 1120210379) + a;
1675
+ c = ____(15, 17, c + (a ^ (d | ~b)) + m02 + 718787259) + d;
1676
+ b = ____(21, 11, b + (d ^ (c | ~a)) + m09 - 343485551) + c;
1677
+ a = a + aa >>> 0;
1678
+ b = b + bb >>> 0;
1679
+ c = c + cc >>> 0;
1680
+ d = d + dd >>> 0;
1681
+ }
1682
+ return crypt.endian([a, b, c, d]);
1683
+ function ____(s, t, n) {
1684
+ return n << s | n >>> t;
1685
+ }
1686
+ };
1687
+ return function(message, options) {
1688
+ var digestbytes = crypt.wordsToBytes(md5JS(message, options)), result = options && options.asBytes ? digestbytes : crypt.bytesconvertNumberToHex(digestbytes);
1689
+ return result;
1690
+ };
1691
+ }
1692
+ function decodeBase64Safely(str) {
1693
+ try {
1694
+ return decodeBase64ToUint8Array(str);
1695
+ } catch (_error) {
1696
+ return null;
1697
+ }
1698
+ }
1699
+ function decodeBase64ToUint8Array(base64) {
1700
+ var sanitized = base64.replace(/-/g, "+").replace(/_/g, "/");
1701
+ if (typeof atob === "function") {
1702
+ return binaryStringToUint8Array(atob(sanitized));
1703
+ }
1704
+ return decodeBase64WithoutAtob(sanitized);
1705
+ }
1706
+ function decodeBase64WithoutAtob(base64) {
1707
+ var paddingLength = base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0, byteLength = base64.length * 3 / 4 - paddingLength, bytes = new Uint8Array(byteLength), byteIndex = 0, i = 0, enc1, enc2, enc3, enc4;
1708
+ while (i < base64.length) {
1709
+ enc1 = BASE64_LOOKUP.indexOf(base64.charAt(i++));
1710
+ enc2 = BASE64_LOOKUP.indexOf(base64.charAt(i++));
1711
+ enc3 = BASE64_LOOKUP.indexOf(base64.charAt(i++));
1712
+ enc4 = BASE64_LOOKUP.indexOf(base64.charAt(i++));
1713
+ if (enc1 < 0 || enc2 < 0 || enc3 < 0 || enc4 < 0) {
1714
+ throw new TypeError("Invalid base64 input");
1715
+ }
1716
+ bytes[byteIndex++] = enc1 << 2 | enc2 >> 4;
1717
+ if (enc3 < 64 && byteIndex < byteLength) {
1718
+ bytes[byteIndex++] = (enc2 & 15) << 4 | enc3 >> 2;
1719
+ }
1720
+ if (enc4 < 64 && byteIndex < byteLength) {
1721
+ bytes[byteIndex++] = (enc3 & 3) << 6 | enc4;
1722
+ }
1723
+ }
1724
+ return bytes;
1725
+ }
1726
+ function binaryStringToUint8Array(str) {
1727
+ var length = str.length, view = new Uint8Array(length), i = 0;
1728
+ while (i < length) {
1729
+ view[i] = str.charCodeAt(i);
1730
+ i++;
1731
+ }
1732
+ return view;
1733
+ }
1734
+ function normalizeInput(data) {
1735
+ if (data instanceof Uint8Array) {
1736
+ return data;
1737
+ }
1738
+ if (typeof ArrayBuffer !== "undefined" && data instanceof ArrayBuffer) {
1739
+ return new Uint8Array(data);
1740
+ }
1741
+ if (data && typeof data === "object" && ArrayBuffer.isView(data)) {
1742
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
1743
+ }
1744
+ if (typeof data === "string") {
1745
+ return new TextEncoder().encode(data);
1746
+ }
1747
+ return null;
1748
+ }
1749
+ function makeCrypt() {
1750
+ var _base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1751
+ return {
1752
+ rotl: function(n, b) {
1753
+ return n << b | n >>> 32 - b;
1754
+ },
1755
+ endian: function(n) {
1756
+ if (n.constructor === Number) {
1757
+ return crypt.rotl(n, 8) & 16711935 | crypt.rotl(n, 24) & 4278255360;
1758
+ }
1759
+ for (var i = 0; i < n.length; i++) n[i] = crypt.endian(n[i]);
1760
+ return n;
1761
+ },
1762
+ bytesToWords: function(bytes) {
1763
+ for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
1764
+ words[b >>> 5] |= bytes[i] << 24 - b % 32;
1765
+ return words;
1766
+ },
1767
+ wordsToBytes: function(words) {
1768
+ for (var bytes = [], b = 0; b < words.length * 32; b += 8)
1769
+ bytes.push(words[b >>> 5] >>> 24 - b % 32 & 255);
1770
+ return bytes;
1771
+ },
1772
+ bytesconvertNumberToHex: function(bytes) {
1773
+ for (var hex = [], i = 0; i < bytes.length; i++) {
1774
+ hex.push((bytes[i] >>> 4).toString(16));
1775
+ hex.push((bytes[i] & 15).toString(16));
1776
+ }
1777
+ return hex.join("");
1778
+ }
1779
+ };
1780
+ }
1781
+ var BASE64_LOOKUP, wasmB64Bytes, wasm, crypt, biteSize, bounder, upperLimit, parmTypeErrStr, tooBigErrStr;
1782
+ var init_md5_wasm = __esm({
1783
+ "../crypto/src/lib/algorithms/md5-wasm.ts"() {
1784
+ "use strict";
1785
+ BASE64_LOOKUP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
1786
+ wasmB64Bytes = decodeBase64Safely(
1787
+ "AGFzbQEAAAABDANgAX8AYAAAYAABfwIeAgdpbXBvcnRzA2xvZwAAB2ltcG9ydHMDbWVtAgABAzIxAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEAAAAAAAAAAAAAAAAAAAAAAgICAgIAAAAAAAaYARt/AUGBxpS6Bgt/AUGJ17b+fgt/AUH+uevFeQt/AUH2qMmBAQt/AUEAC38BQQALfwFBAAt/AUEAC38BQQALfwFBAAt/AUEAC38BQQALfwFBAAt/AUEAC38BQQALfwFBAAt/AUEAC38BQQALfwFBAAt/AUEAC38BQQALfwFBAAt/AUEAC38BQQALfwFBAAt/AUEAC38BQQALB7oCJQhvbmVGdWxsQQAYCG9uZUZ1bGxCABkIb25lRnVsbEMAGghvbmVGdWxsRAAbBWxvb3BzAAEEbG9vcAACBXByaW1lAAMFbG9vcEEABAZsb29wQTEABQZsb29wQTIABgZsb29wQTMABwZsb29wQTQACAVsb29wQgAJBmxvb3BCMQAKBmxvb3BCMgALBmxvb3BCMwAMBmxvb3BCNAANBWxvb3BDAA4GbG9vcEMxAA8GbG9vcEMyABAGbG9vcEMzABEGbG9vcEM0ABIFbG9vcEQAEwZsb29wRDEAFAZsb29wRDIAFQZsb29wRDMAFgZsb29wRDQAFwRnZXRBACgEZ2V0QgApBGdldEMAKgRnZXREACsEZ2V0WAAsBHNldEEALQRzZXRCAC4Ec2V0QwAvBHNldEQAMARzZXRYADEKzA0xWwEBf0EAJAggAEEGdCEBAkADQCMIIAFGDQEjACQEIwEkBSMCJAYjAyQHEAIjBCMAaiQAIwUjAWokASMGIwJqJAIjByMDaiQDIwhBwABqJAgMAAsLIwgjGmokGgsTACMIIxpqJAkQAxAEEAkQDhATC6IBAEEAIwlqKAIAJApBBCMJaigCACQLQQgjCWooAgAkDEEMIwlqKAIAJA1BECMJaigCACQOQRQjCWooAgAkD0EYIwlqKAIAJBBBHCMJaigCACQRQSAjCWooAgAkEkEkIwlqKAIAJBNBKCMJaigCACQUQSwjCWooAgAkFUEwIwlqKAIAJBZBNCMJaigCACQXQTgjCWooAgAkGEE8IwlqKAIAJBkLCgAQBRAGEAcQCAsuAEH4yKq7fSMKahAYQdbunsZ+IwtqEBtB2+GBoQIjDGoQGkHunfeNfCMNahAZCy0AQa+f8Kt/Iw5qEBhBqoyfvAQjD2oQG0GTjMHBeiMQahAaQYGqmmojEWoQGQssAEHYsYLMBiMSahAYQa/vk9p4IxNqEBtBsbd9IxRqEBpBvq/zyngjFWoQGQstAEGiosDcBiMWahAYQZPj4WwjF2oQG0GOh+WzeiMYahAaQaGQ0M0EIxlqEBkLCgAQChALEAwQDQsuAEHiyviwfyMLahAcQcDmgoJ8IxBqEB9B0bT5sgIjFWoQHkGqj9vNfiMKahAdCy0AQd2gvLF9Iw9qEBxB06iQEiMUahAfQYHNh8V9IxlqEB5ByPfPvn4jDmoQHQsuAEHmm4ePAiMTahAcQdaP3Jl8IxhqEB9Bh5vUpn8jDWoQHkHtqeiqBCMSahAdCy0AQYXSj896IxdqEBxB+Me+ZyMMahAfQdmFvLsGIxFqEB5Bipmp6XgjFmoQHQsKABAPEBAQERASCysAQcLyaCMPahAgQYHtx7t4IxJqECNBosL17AYjFWoQIkGM8JRvIxhqECELLgBBxNT7pXojC2oQIEGpn/veBCMOahAjQeCW7bV/IxFqECJB8Pj+9XsjFGoQIQstAEHG/e3EAiMXahAgQfrPhNV+IwpqECNBheG8p30jDWoQIkGFuqAkIxBqECELLgBBuaDTzn0jE2oQIEHls+62fiMWahAjQfj5if0BIxlqECJB5ayxpXwjDGoQIQsKABAUEBUQFhAXCy0AQcTEpKF/IwpqECRBl/+rmQQjEWoQJ0Gnx9DceiMYahAmQbnAzmQjD2oQJQstAEHDs+2qBiMWahAkQZKZs/h4Iw1qECdB/ei/fyMUahAmQdG7kax4IwtqECULLQBBz/yh/QYjEmoQJEHgzbNxIxlqECdBlIaFmHojEGoQJkGho6DwBCMXahAlCy4AQYL9zbp/Iw5qECRBteTr6XsjFWoQJ0G7pd/WAiMMahAmQZGnm9x+IxNqECULKAEBf0F/IwFzIwNxIwEjAnFyIwBqIABqIgFBB3QgAUEZdnIjAWokAAsoAQF/QX8jAnMjAHEjAiMDcXIjAWogAGoiAUEWdCABQQp2ciMCaiQBCygBAX9BfyMDcyMBcSMDIwBxciMCaiAAaiIBQRF0IAFBD3ZyIwNqJAILKAEBf0F/IwBzIwJxIwAjAXFyIwNqIABqIgFBDHQgAUEUdnIjAGokAwsoAQF/IwJBfyMDc3EjASMDcXIjAGogAGoiAUEFdCABQRt2ciMBaiQACygBAX8jA0F/IwBzcSMCIwBxciMBaiAAaiIBQRR0IAFBDHZyIwJqJAELKAEBfyMAQX8jAXNxIwMjAXFyIwJqIABqIgFBDnQgAUESdnIjA2okAgsoAQF/IwFBfyMCc3EjACMCcXIjA2ogAGoiAUEJdCABQRd2ciMAaiQDCyIBAX8jASMCcyMDcyMAaiAAaiIBQQR0IAFBHHZyIwFqJAALIgEBfyMCIwNzIwBzIwFqIABqIgFBF3QgAUEJdnIjAmokAQsiAQF/IwMjAHMjAXMjAmogAGoiAUEQdCABQRB2ciMDaiQCCyIBAX8jACMBcyMCcyMDaiAAaiIBQQt0IAFBFXZyIwBqJAMLJQEBf0F/IwNzIwFyIwJzIwBqIABqIgFBBnQgAUEadnIjAWokAAslAQF/QX8jAHMjAnIjA3MjAWogAGoiAUEVdCABQQt2ciMCaiQBCyUBAX9BfyMBcyMDciMAcyMCaiAAaiIBQQ90IAFBEXZyIwNqJAILJQEBf0F/IwJzIwByIwFzIwNqIABqIgFBCnQgAUEWdnIjAGokAwsEACMACwQAIwELBAAjAgsEACMDCwQAIxoLBgAgACQACwYAIAAkAQsGACAAJAILBgAgACQDCwYAIAAkGgsA6gQEbmFtZQGSAzIAA2xvZwEFbG9vcHMCBGxvb3ADBXByaW1lBAVsb29wQQUGbG9vcEExBgZsb29wQTIHBmxvb3BBMwgGbG9vcEE0CQVsb29wQgoGbG9vcEIxCwZsb29wQjIMBmxvb3BCMw0GbG9vcEI0DgVsb29wQw8GbG9vcEMxEAZsb29wQzIRBmxvb3BDMxIGbG9vcEM0EwVsb29wRBQGbG9vcEQxFQZsb29wRDIWBmxvb3BEMxcGbG9vcEQ0GAhvbmVGdWxsQRkIb25lRnVsbEIaCG9uZUZ1bGxDGwhvbmVGdWxsRBwIdHdvRnVsbEEdCHR3b0Z1bGxCHgh0d29GdWxsQx8IdHdvRnVsbEQgCHRyZUZ1bGxBIQh0cmVGdWxsQiIIdHJlRnVsbEMjCHRyZUZ1bGxEJAhxdWFGdWxsQSUIcXVhRnVsbEImCHF1YUZ1bGxDJwhxdWFGdWxsRCgEZ2V0QSkEZ2V0QioEZ2V0QysEZ2V0RCwEZ2V0WC0Ec2V0QS4Ec2V0Qi8Ec2V0QzAEc2V0RDEEc2V0WALNATIAAQAAAQIAAAEIbnVtbG9vcHMCAAMABAAFAAYABwAIAAkACgALAAwADQAOAA8AEAARABIAEwAUABUAFgAXABgCAAABAW4ZAgAAAQFuGgIAAAEBbhsCAAABAW4cAgAAAQFuHQIAAAEBbh4CAAABAW4fAgAAAQFuIAIAAAEBbiECAAABAW4iAgAAAQFuIwIAAAEBbiQCAAABAW4lAgAAAQFuJgIAAAEBbicCAAABAW4oACkAKgArACwALQEAAC4BAAAvAQAAMAEAADEBAAA="
1788
+ );
1789
+ wasm = typeof WebAssembly !== "undefined" && wasmB64Bytes ? wasmB64Bytes.buffer : false;
1790
+ crypt = makeCrypt();
1791
+ biteSize = 240 * 16 * 16;
1792
+ bounder = Math.floor(biteSize * 16 * 1.066666667);
1793
+ upperLimit = 268435456 - 65536;
1794
+ parmTypeErrStr = "Parameter must be ArrayBuffer, ArrayBufferView or string";
1795
+ tooBigErrStr = "Parameter exceeds max size of 255.9 Mbytes";
1796
+ if (!wasm) {
1797
+ }
1798
+ }
1799
+ });
1800
+
1801
+ // ../crypto/src/lib/md5-hash.ts
1802
+ var MD5Hash;
1803
+ var init_md5_hash = __esm({
1804
+ "../crypto/src/lib/md5-hash.ts"() {
1805
+ "use strict";
1806
+ init_hash();
1807
+ init_md5_wasm();
1808
+ init_digest_utils();
1809
+ MD5Hash = class extends Hash {
1810
+ /** Identifies the digest algorithm. */
1811
+ name = "md5";
1812
+ /** Hash configuration. */
1813
+ options;
1814
+ /** Creates an MD5 hash calculator. */
1815
+ constructor(options = {}) {
1816
+ super();
1817
+ this.options = options;
1818
+ }
1819
+ /**
1820
+ * Atomic hash calculation
1821
+ * @returns Hash in the requested encoding
1822
+ */
1823
+ async hash(input, encoding) {
1824
+ const hex = await md5WASM(input);
1825
+ return encodeHex(hex, encoding);
1826
+ }
1827
+ /** Calculates a digest synchronously without WebAssembly initialization. */
1828
+ hashSync(input, encoding) {
1829
+ return encodeHex(calculateMD5Sync(input), encoding);
1830
+ }
1831
+ };
1832
+ }
1833
+ });
1834
+
1835
+ // ../crypto/src/index.ts
1836
+ var init_src = __esm({
1837
+ "../crypto/src/index.ts"() {
1838
+ "use strict";
1839
+ init_crc32_hash();
1840
+ init_md5_hash();
1841
+ }
1842
+ });
1843
+
1844
+ // src/zip/lib/zip64-extra-field.ts
1845
+ function parseZip64ExtraField(extraField, expectedFields) {
1846
+ const values = {};
1847
+ if (expectedFields.length === 0) {
1848
+ return values;
1849
+ }
1850
+ const expectedPayloadLength = expectedFields.reduce(
1851
+ (totalByteLength, field) => totalByteLength + field.byteLength,
1852
+ 0
1853
+ );
1854
+ let recordOffset = 0;
1855
+ while (recordOffset < extraField.byteLength) {
1856
+ if (recordOffset + 4 > extraField.byteLength) {
1857
+ throw new Error(
1858
+ "Invalid ZIP archive: truncated extra-field record header while reading ZIP64 data"
1859
+ );
1860
+ }
1861
+ const headerId = extraField.getUint16(recordOffset, true);
1862
+ const payloadLength = extraField.getUint16(recordOffset + 2, true);
1863
+ const payloadOffset = recordOffset + 4;
1864
+ const nextRecordOffset = payloadOffset + payloadLength;
1865
+ if (nextRecordOffset > extraField.byteLength) {
1866
+ throw new Error(
1867
+ "Invalid ZIP archive: truncated extra-field record payload while reading ZIP64 data"
1868
+ );
1869
+ }
1870
+ if (headerId === ZIP64_EXTRA_FIELD_ID) {
1871
+ if (payloadLength !== expectedPayloadLength) {
1872
+ throw new Error(
1873
+ "Invalid ZIP archive: ZIP64 extended information has an unexpected payload size"
1874
+ );
1875
+ }
1876
+ let fieldOffset = payloadOffset;
1877
+ for (const field of expectedFields) {
1878
+ values[field.name] = field.byteLength === 8 ? extraField.getBigUint64(fieldOffset, true) : BigInt(extraField.getUint32(fieldOffset, true));
1879
+ fieldOffset += field.byteLength;
1880
+ }
1881
+ return values;
1882
+ }
1883
+ recordOffset = nextRecordOffset;
1884
+ }
1885
+ throw new Error("Invalid ZIP archive: required ZIP64 extended information is missing");
1886
+ }
1887
+ var ZIP64_EXTRA_FIELD_ID;
1888
+ var init_zip64_extra_field = __esm({
1889
+ "src/zip/lib/zip64-extra-field.ts"() {
1890
+ "use strict";
1891
+ ZIP64_EXTRA_FIELD_ID = 1;
1892
+ }
1893
+ });
1894
+
1895
+ // src/zip/lib/zip-entry-metadata.ts
1896
+ function decodeZipHeader(bytes, central) {
1897
+ const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1898
+ const fixedBytes = central ? 46 : 30;
1899
+ if (bytes.byteLength < fixedBytes || header.getUint32(0, true) !== (central ? 33639248 : 67324752))
1900
+ throw new Error("Invalid ZIP archive: missing entry header");
1901
+ const nameLength = header.getUint16(central ? 28 : 26, true);
1902
+ const extraLength = header.getUint16(central ? 30 : 28, true);
1903
+ const commentLength = central ? header.getUint16(32, true) : 0;
1904
+ if (bytes.byteLength !== fixedBytes + nameLength + extraLength + commentLength)
1905
+ throw new Error("Invalid ZIP archive: truncated entry metadata");
1906
+ const flags = header.getUint16(central ? 8 : 6, true);
1907
+ const method = header.getUint16(central ? 10 : 8, true);
1908
+ if (flags & (1 | 64 | 8192)) throw new Error("Unsupported ZIP encryption");
1909
+ if (flags & ~(8 | 2048 | (method === 8 ? 6 : 0))) throw new Error("Unsupported ZIP flags");
1910
+ if (method !== 0 && method !== 8)
1911
+ throw new Error(`Unsupported ZIP compression method: ${method}`);
1912
+ let compressedSize = BigInt(header.getUint32(central ? 20 : 18, true));
1913
+ let size = BigInt(header.getUint32(central ? 24 : 22, true));
1914
+ let localHeaderOffset = central ? BigInt(header.getUint32(42, true)) : 0n;
1915
+ let disk = central ? BigInt(header.getUint16(34, true)) : 0n;
1916
+ let zip64 = compressedSize === 0xffffffffn || size === 0xffffffffn;
1917
+ const fields = [];
1918
+ if (central) {
1919
+ if (size === 0xffffffffn) fields.push({ name: "size", byteLength: 8 });
1920
+ if (compressedSize === 0xffffffffn) fields.push({ name: "compressedSize", byteLength: 8 });
1921
+ if (localHeaderOffset === 0xffffffffn) fields.push({ name: "localHeaderOffset", byteLength: 8 });
1922
+ if (disk === 0xffffn) fields.push({ name: "disk", byteLength: 4 });
1923
+ } else if (zip64)
1924
+ fields.push({ name: "size", byteLength: 8 }, { name: "compressedSize", byteLength: 8 });
1925
+ const extraBytes = bytes.subarray(fixedBytes + nameLength, fixedBytes + nameLength + extraLength);
1926
+ const extra = new DataView(extraBytes.buffer, extraBytes.byteOffset, extraBytes.byteLength);
1927
+ const extraValues = parseZip64ExtraField(extra, fields);
1928
+ if (size === 0xffffffffn) size = extraValues.size;
1929
+ if (compressedSize === 0xffffffffn) compressedSize = extraValues.compressedSize;
1930
+ if (localHeaderOffset === 0xffffffffn) localHeaderOffset = extraValues.localHeaderOffset;
1931
+ if (disk === 0xffffn) disk = extraValues.disk;
1932
+ if (disk !== 0n) throw new Error("Unsupported split ZIP archive");
1933
+ const nameBytes = bytes.subarray(fixedBytes, fixedBytes + nameLength);
1934
+ let path = decodeZipText(nameBytes, Boolean(flags & 2048));
1935
+ const commentBytes = bytes.subarray(fixedBytes + nameLength + extraLength);
1936
+ let comment = decodeZipText(commentBytes, Boolean(flags & 2048));
1937
+ for (let offset = 0; offset < extra.byteLength; ) {
1938
+ if (offset + 4 > extra.byteLength)
1939
+ throw new Error("Invalid ZIP archive: truncated extra field");
1940
+ const identifier = extra.getUint16(offset, true);
1941
+ const length = extra.getUint16(offset + 2, true);
1942
+ if (offset + 4 + length > extra.byteLength)
1943
+ throw new Error("Invalid ZIP archive: truncated extra field");
1944
+ if (!central && flags & 8 && identifier === 1) {
1945
+ if (length >= 16) zip64 = true;
1946
+ }
1947
+ if (identifier === 28789 || identifier === 25461) {
1948
+ const original = identifier === 28789 ? nameBytes : commentBytes;
1949
+ if (length < 5) throw new Error("Invalid ZIP archive: truncated Unicode extra field");
1950
+ if (extra.getUint8(offset + 4) === 1 && extra.getUint32(offset + 5, true) === calculateZipChecksum(original)) {
1951
+ const text = decodeZipText(extraBytes.subarray(offset + 9, offset + 4 + length), true);
1952
+ if (identifier === 28789) path = text;
1953
+ else comment = text;
1954
+ }
1955
+ }
1956
+ offset += 4 + length;
1957
+ }
1958
+ validateZipPath(path);
1959
+ return {
1960
+ path,
1961
+ nameBytes,
1962
+ flags,
1963
+ method,
1964
+ crc32: header.getUint32(central ? 16 : 14, true),
1965
+ compressedSize,
1966
+ size,
1967
+ localHeaderOffset,
1968
+ comment,
1969
+ zip64
1970
+ };
1971
+ }
1972
+ function decodeZipText(bytes, utf8) {
1973
+ if (utf8) return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
1974
+ return Array.from(
1975
+ bytes,
1976
+ (value) => value < 128 ? String.fromCharCode(value) : CP437_HIGH[value - 128]
1977
+ ).join("");
1978
+ }
1979
+ function validateZipPath(path) {
1980
+ const segments = path.endsWith("/") ? path.slice(0, -1).split("/") : path.split("/");
1981
+ if (!path || path.includes("\\") || path.includes("\0") || /^[A-Za-z]:/.test(path) || segments.some((segment) => !segment || segment === "." || segment === ".."))
1982
+ throw new Error("Invalid ZIP archive: noncanonical relative path");
1983
+ }
1984
+ function calculateZipChecksum(bytes) {
1985
+ return Number.parseInt(new CRC32Hash().hashSync(bytes.slice().buffer, "hex"), 16);
1986
+ }
1987
+ function encodeUtf8Text(value) {
1988
+ const bytes = new TextEncoder().encode(value);
1989
+ if (new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes) !== value)
1990
+ throw new TypeError("ZIP names and entry comments must be well-formed Unicode");
1991
+ return bytes;
1992
+ }
1993
+ var CP437_HIGH;
1994
+ var init_zip_entry_metadata = __esm({
1995
+ "src/zip/lib/zip-entry-metadata.ts"() {
1996
+ "use strict";
1997
+ init_src();
1998
+ init_zip64_extra_field();
1999
+ 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";
2000
+ }
2001
+ });
2002
+
2003
+ // src/zip/lib/zip-serialization.ts
2004
+ function encodeZipLocalHeader(entry) {
2005
+ validateHeaderEntry(entry);
2006
+ const bytes = new Uint8Array(30 + entry.nameBytes.length + (entry.zip64 ? 20 : 0));
2007
+ const view = new DataView(bytes.buffer);
2008
+ view.setUint32(0, 67324752, true);
2009
+ view.setUint16(4, getZipVersion(entry), true);
2010
+ view.setUint16(6, entry.flags, true);
2011
+ view.setUint16(8, entry.method, true);
2012
+ view.setUint32(10, encodeZipTimestamp(entry.date), true);
2013
+ const descriptor = Boolean(entry.flags & 8);
2014
+ view.setUint32(14, descriptor ? 0 : entry.crc32, true);
2015
+ view.setUint32(
2016
+ 18,
2017
+ entry.zip64 ? Number(ZIP32_SENTINEL) : descriptor ? 0 : Number(entry.compressedSize),
2018
+ true
2019
+ );
2020
+ view.setUint32(
2021
+ 22,
2022
+ entry.zip64 ? Number(ZIP32_SENTINEL) : descriptor ? 0 : Number(entry.size),
2023
+ true
2024
+ );
2025
+ view.setUint16(26, entry.nameBytes.length, true);
2026
+ view.setUint16(28, entry.zip64 ? 20 : 0, true);
2027
+ bytes.set(entry.nameBytes, 30);
2028
+ if (entry.zip64) {
2029
+ const extraOffset = 30 + entry.nameBytes.length;
2030
+ view.setUint16(extraOffset, 1, true);
2031
+ view.setUint16(extraOffset + 2, 16, true);
2032
+ view.setBigUint64(extraOffset + 4, descriptor ? 0n : entry.size, true);
2033
+ view.setBigUint64(extraOffset + 12, descriptor ? 0n : entry.compressedSize, true);
2034
+ }
2035
+ return bytes;
2036
+ }
2037
+ function encodeZipCentralHeader(entry) {
2038
+ validateHeaderEntry(entry);
2039
+ const comment = entry.commentBytes ?? new Uint8Array();
2040
+ const extraBytes = entry.zip64 ? 28 : 0;
2041
+ const bytes = new Uint8Array(46 + entry.nameBytes.length + extraBytes + comment.length);
2042
+ const view = new DataView(bytes.buffer);
2043
+ view.setUint32(0, 33639248, true);
2044
+ view.setUint16(4, entry.zip64 ? 45 : 20, true);
2045
+ view.setUint16(6, getZipVersion(entry), true);
2046
+ view.setUint16(8, entry.flags, true);
2047
+ view.setUint16(10, entry.method, true);
2048
+ view.setUint32(12, encodeZipTimestamp(entry.date), true);
2049
+ view.setUint32(16, entry.crc32, true);
2050
+ view.setUint32(20, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.compressedSize), true);
2051
+ view.setUint32(24, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.size), true);
2052
+ view.setUint16(28, entry.nameBytes.length, true);
2053
+ view.setUint16(30, extraBytes, true);
2054
+ view.setUint16(32, comment.length, true);
2055
+ view.setUint32(38, entry.directory ? 16 : 0, true);
2056
+ view.setUint32(42, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.localHeaderOffset), true);
2057
+ bytes.set(entry.nameBytes, 46);
2058
+ if (entry.zip64) {
2059
+ const extraOffset = 46 + entry.nameBytes.length;
2060
+ view.setUint16(extraOffset, 1, true);
2061
+ view.setUint16(extraOffset + 2, 24, true);
2062
+ view.setBigUint64(extraOffset + 4, entry.size, true);
2063
+ view.setBigUint64(extraOffset + 12, entry.compressedSize, true);
2064
+ view.setBigUint64(extraOffset + 20, entry.localHeaderOffset, true);
2065
+ }
2066
+ bytes.set(comment, 46 + entry.nameBytes.length + extraBytes);
2067
+ return bytes;
2068
+ }
2069
+ function encodeZipEndRecords(count, directorySize, directoryOffset, zip64, comment = new Uint8Array()) {
2070
+ for (const value of [count, directorySize, directoryOffset, directoryOffset + directorySize])
2071
+ validateUint64(value);
2072
+ if (comment.length > 65535) throw new RangeError("ZIP archive comment exceeds 65535 bytes");
2073
+ if (!zip64 && (count > 0xffffn || directorySize >= ZIP32_SENTINEL || directoryOffset >= ZIP32_SENTINEL))
2074
+ throw new RangeError("ZIP32 end record capacity exceeded");
2075
+ const bytes = new Uint8Array((zip64 ? 98 : 22) + comment.length);
2076
+ const view = new DataView(bytes.buffer);
2077
+ if (zip64) {
2078
+ view.setUint32(0, 101075792, true);
2079
+ view.setBigUint64(4, 44n, true);
2080
+ view.setUint16(12, 45, true);
2081
+ view.setUint16(14, 45, true);
2082
+ view.setBigUint64(24, count, true);
2083
+ view.setBigUint64(32, count, true);
2084
+ view.setBigUint64(40, directorySize, true);
2085
+ view.setBigUint64(48, directoryOffset, true);
2086
+ view.setUint32(56, 117853008, true);
2087
+ view.setBigUint64(64, directoryOffset + directorySize, true);
2088
+ view.setUint32(72, 1, true);
2089
+ }
2090
+ const endOffset = zip64 ? 76 : 0;
2091
+ view.setUint32(endOffset, 101010256, true);
2092
+ view.setUint16(endOffset + 8, zip64 ? 65535 : Number(count), true);
2093
+ view.setUint16(endOffset + 10, zip64 ? 65535 : Number(count), true);
2094
+ view.setUint32(endOffset + 12, zip64 ? Number(ZIP32_SENTINEL) : Number(directorySize), true);
2095
+ view.setUint32(endOffset + 16, zip64 ? Number(ZIP32_SENTINEL) : Number(directoryOffset), true);
2096
+ view.setUint16(endOffset + 20, comment.length, true);
2097
+ bytes.set(comment, endOffset + 22);
2098
+ return bytes;
2099
+ }
2100
+ function encodeZipTimestamp(date) {
2101
+ if (!(date instanceof Date) || !Number.isFinite(date.getTime()) || date.getUTCFullYear() < 1980 || date.getUTCFullYear() > 2107)
2102
+ throw new RangeError("ZIP timestamp must be a valid UTC date in 1980\u20132107");
2103
+ const time = date.getUTCHours() << 11 | date.getUTCMinutes() << 5 | Math.floor(date.getUTCSeconds() / 2);
2104
+ const day = date.getUTCFullYear() - 1980 << 9 | date.getUTCMonth() + 1 << 5 | date.getUTCDate();
2105
+ return (day << 16 | time) >>> 0;
2106
+ }
2107
+ function getZipVersion(entry) {
2108
+ return entry.zip64 ? 45 : entry.method === 8 || entry.flags & 8 ? 20 : 10;
2109
+ }
2110
+ function validateHeaderEntry(entry) {
2111
+ var _a;
2112
+ if (!entry.nameBytes.length || entry.nameBytes.length > 65535 || (((_a = entry.commentBytes) == null ? void 0 : _a.length) ?? 0) > 65535)
2113
+ throw new RangeError("ZIP name/comment exceeds header capacity");
2114
+ for (const value of [entry.size, entry.compressedSize, entry.localHeaderOffset])
2115
+ validateUint64(value);
2116
+ if (!entry.zip64 && [entry.size, entry.compressedSize, entry.localHeaderOffset].some(
2117
+ (value) => value >= ZIP32_SENTINEL
2118
+ ))
2119
+ throw new RangeError("ZIP32 entry capacity exceeded");
2120
+ }
2121
+ function validateUint64(value) {
2122
+ if (typeof value !== "bigint" || value < 0n || value > 0xffffffffffffffffn)
2123
+ throw new RangeError("ZIP64 unsigned integer capacity exceeded");
2124
+ }
2125
+ var ZIP32_SENTINEL;
2126
+ var init_zip_serialization = __esm({
2127
+ "src/zip/lib/zip-serialization.ts"() {
2128
+ "use strict";
2129
+ ZIP32_SENTINEL = 0xffffffffn;
2130
+ }
2131
+ });
2132
+
2133
+ // src/zip/zip-archive.ts
2134
+ async function openZipArchive(input, options = {}) {
2135
+ return await ZipArchive.open(input, options);
2136
+ }
2137
+ function normalizeZipInput(input) {
2138
+ if (input instanceof ArrayBuffer) return new BlobFile(input);
2139
+ if (ArrayBuffer.isView(input))
2140
+ return new BlobFile(
2141
+ new Blob([new Uint8Array(input.buffer, input.byteOffset, input.byteLength).slice()])
2142
+ );
2143
+ if (input instanceof Blob) return new BlobFile(input);
2144
+ return input;
2145
+ }
2146
+ function minimumBigInt(left, right) {
2147
+ return left < right ? left : right;
2148
+ }
2149
+ var DEFAULT_OPTIONS, ZipArchive;
2150
+ var init_zip_archive = __esm({
2151
+ "src/zip/zip-archive.ts"() {
2152
+ "use strict";
2153
+ init_loader_utils();
2154
+ init_deflate_decompressor();
2155
+ init_src();
2156
+ init_zip_entry_metadata();
2157
+ init_zip_serialization();
2158
+ DEFAULT_OPTIONS = {
2159
+ maxArchiveBytes: 1024n ** 4n,
2160
+ maxDirectoryBytes: 32 * 1024 * 1024,
2161
+ maxEntries: 1e5,
2162
+ maxReadBytes: 1024 * 1024,
2163
+ maxCompressedBytes: 64n * 1024n * 1024n,
2164
+ maxDecodedBytes: 64n * 1024n * 1024n,
2165
+ chunkBytes: 64 * 1024
2166
+ };
2167
+ ZipArchive = class _ZipArchive {
2168
+ /** Archive byte length, without losing ZIP64 precision. */
2169
+ size;
2170
+ /** Archive comment, decoded using legacy ZIP CP437. */
2171
+ comment;
2172
+ /** Shared file limits captured at open time. */
2173
+ limits;
2174
+ /** Owned random-access transport. */
2175
+ file;
2176
+ /** File lifetime, including in-flight operations. */
2177
+ controller = new AbortController();
2178
+ /** Initialization/caller cancellation combined with close. */
2179
+ signal;
2180
+ /** Validated directory boundary. */
2181
+ directory;
2182
+ /** A single directory-index promise shared by concurrent lookups. */
2183
+ directoryPromise;
2184
+ /** Local-header validation shared by repeated path reads. */
2185
+ entriesByOffset = /* @__PURE__ */ new Map();
2186
+ /** Central-validated named lookups share their local-header work. */
2187
+ entriesByPath = /* @__PURE__ */ new Map();
2188
+ /** Next local-header boundary for central-validated, nonoverlapping payloads. */
2189
+ nextOffsets = /* @__PURE__ */ new Map();
2190
+ /** Only entries issued by this archive can be used for reads. */
2191
+ issuedEntries = /* @__PURE__ */ new WeakSet();
2192
+ /** Idempotent file cleanup, including open failure. */
2193
+ closePromise;
2194
+ /** Captures the owned transport and validates independent limits. */
2195
+ constructor(file, size, options) {
2196
+ this.file = file;
2197
+ this.size = size;
2198
+ this.comment = "";
2199
+ this.limits = {
2200
+ maxArchiveBytes: options.maxArchiveBytes ?? DEFAULT_OPTIONS.maxArchiveBytes,
2201
+ maxDirectoryBytes: options.maxDirectoryBytes ?? DEFAULT_OPTIONS.maxDirectoryBytes,
2202
+ maxEntries: options.maxEntries ?? DEFAULT_OPTIONS.maxEntries,
2203
+ maxReadBytes: options.maxReadBytes ?? DEFAULT_OPTIONS.maxReadBytes,
2204
+ maxCompressedBytes: options.maxCompressedBytes ?? DEFAULT_OPTIONS.maxCompressedBytes,
2205
+ maxDecodedBytes: options.maxDecodedBytes ?? DEFAULT_OPTIONS.maxDecodedBytes,
2206
+ chunkBytes: options.chunkBytes ?? DEFAULT_OPTIONS.chunkBytes
2207
+ };
2208
+ for (const [name, value] of Object.entries(this.limits)) {
2209
+ const bigintLimit = ["maxArchiveBytes", "maxCompressedBytes", "maxDecodedBytes"].includes(
2210
+ name
2211
+ );
2212
+ if (bigintLimit ? typeof value !== "bigint" || value < 0n : typeof value !== "number" || !Number.isSafeInteger(value) || value < 1)
2213
+ throw new RangeError(`Invalid ZIP ${name} limit`);
2214
+ }
2215
+ this.signal = options.signal ? AbortSignal.any([this.controller.signal, options.signal]) : this.controller.signal;
2216
+ }
2217
+ /** Initializes directory bounds without scanning entries or reading their payloads. */
2218
+ static async open(input, options = {}) {
2219
+ var _a;
2220
+ const file = normalizeZipInput(input);
2221
+ let archive;
2222
+ try {
2223
+ const advertisedSize = file.bigsize;
2224
+ const status = advertisedSize === void 0 || advertisedSize === 0n ? await ((_a = file.stat) == null ? void 0 : _a.call(file)) : void 0;
2225
+ const reportedBigsize = (status == null ? void 0 : status.bigsize) ?? file.bigsize;
2226
+ const size = reportedBigsize !== void 0 && reportedBigsize !== 0n ? reportedBigsize : BigInt((status == null ? void 0 : status.size) || file.size);
2227
+ archive = new _ZipArchive(file, size, options);
2228
+ archive.signal.throwIfAborted();
2229
+ if (size < 22n || size > archive.limits.maxArchiveBytes)
2230
+ throw new RangeError("ZIP archive size limit or minimum header size");
2231
+ archive.directory = await archive.readDirectoryLocation();
2232
+ Object.defineProperty(archive, "comment", { value: archive.directory.comment });
2233
+ return archive;
2234
+ } catch (error) {
2235
+ if (archive) await archive.close();
2236
+ else await file.close();
2237
+ throw error;
2238
+ }
2239
+ }
2240
+ /**
2241
+ * Appends one STORE entry through validated container metadata and the native serializer.
2242
+ * Internal composition operation: callers own the writable file and discard it on write failure.
2243
+ * Existing payload offsets, central metadata and archive comments are retained.
2244
+ */
2245
+ static async appendEntry(file, path, data, options = {}) {
2246
+ const archive = await _ZipArchive.open(file, options);
2247
+ try {
2248
+ validateZipPath(path);
2249
+ if (archive.directory.offset > BigInt(Number.MAX_SAFE_INTEGER))
2250
+ throw new RangeError("ZIP append transport offset exceeds safe integer range");
2251
+ if (await archive.getEntry(path)) throw new Error("ZIP entry already exists");
2252
+ for await (const _entry of archive.entries()) {
2253
+ }
2254
+ const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
2255
+ if (path.endsWith("/") && bytes.length)
2256
+ throw new Error("ZIP directory payload must be empty");
2257
+ const entry = {
2258
+ nameBytes: encodeUtf8Text(path),
2259
+ date: /* @__PURE__ */ new Date("1980-01-01T00:00:00Z"),
2260
+ flags: 2048,
2261
+ method: 0,
2262
+ crc32: 0,
2263
+ size: BigInt(bytes.length),
2264
+ compressedSize: BigInt(bytes.length),
2265
+ localHeaderOffset: archive.directory.offset,
2266
+ zip64: archive.directory.offset >= 0xffffffffn || bytes.length >= 4294967295
2267
+ };
2268
+ let local = encodeZipLocalHeader(entry);
2269
+ let central = encodeZipCentralHeader(entry);
2270
+ const directoryBytes = archive.directory.size + BigInt(central.length);
2271
+ const directoryOffset = archive.directory.offset + BigInt(local.length + bytes.length);
2272
+ const count = archive.directory.count + 1n;
2273
+ const comment = new Uint8Array(
2274
+ await archive.readExact(
2275
+ archive.size - BigInt(archive.comment.length),
2276
+ archive.comment.length
2277
+ )
2278
+ );
2279
+ const footer = encodeZipEndRecords(
2280
+ count,
2281
+ directoryBytes,
2282
+ directoryOffset,
2283
+ directoryOffset + directoryBytes > 0x7fffffffn || count >= 0xffffn,
2284
+ comment
2285
+ );
2286
+ if (count > BigInt(archive.limits.maxEntries) || directoryBytes > BigInt(archive.limits.maxDirectoryBytes) || directoryOffset + directoryBytes + BigInt(footer.length) > archive.limits.maxArchiveBytes)
2287
+ throw new RangeError("ZIP append metadata/archive limit exceeded");
2288
+ entry.crc32 = calculateZipChecksum(bytes);
2289
+ local = encodeZipLocalHeader(entry);
2290
+ central = encodeZipCentralHeader(entry);
2291
+ const directory = new Uint8Array(
2292
+ await archive.readExact(archive.directory.offset, Number(archive.directory.size))
2293
+ );
2294
+ archive.signal.throwIfAborted();
2295
+ await file.truncate(Number(archive.directory.offset));
2296
+ for (const chunk of [local, bytes, directory, central, footer]) {
2297
+ archive.signal.throwIfAborted();
2298
+ await file.append(chunk);
2299
+ }
2300
+ archive.signal.throwIfAborted();
2301
+ } finally {
2302
+ await archive.close();
2303
+ }
2304
+ }
2305
+ /** Enumerates validated entries in central-directory order; metadata is indexed once. */
2306
+ async *entries() {
2307
+ for (const path of (await this.getDirectory()).keys()) yield await this.getEntry(path);
2308
+ }
2309
+ /**
2310
+ * Reads the final central entry using at most one maximum-sized header from the directory tail.
2311
+ * Ambiguous header signatures in comments fall back to the cached directory. This supports
2312
+ * final-index discovery without scanning a large directory in the normal indexed profile.
2313
+ */
2314
+ async getLastEntry() {
2315
+ this.signal.throwIfAborted();
2316
+ if (!this.directory.count) return void 0;
2317
+ const length = Number(minimumBigInt(this.directory.size, 46n + 3n * 65535n));
2318
+ const bytes = new Uint8Array(
2319
+ await this.readExact(this.directory.offset + this.directory.size - BigInt(length), length)
2320
+ );
2321
+ const view = new DataView(bytes.buffer);
2322
+ const positions = [];
2323
+ for (let position = 0; position + 46 <= length; position++) {
2324
+ if (view.getUint32(position, true) !== 33639248) continue;
2325
+ const end = position + 46 + view.getUint16(position + 28, true) + view.getUint16(position + 30, true) + view.getUint16(position + 32, true);
2326
+ if (end === length) positions.push(position);
2327
+ }
2328
+ if (positions.length !== 1) {
2329
+ const headers = [...(await this.getDirectory()).values()];
2330
+ return await this.getEntry(headers[headers.length - 1].path);
2331
+ }
2332
+ const metadata2 = decodeZipHeader(bytes.subarray(positions[0]), true);
2333
+ return await this.getValidatedEntry(metadata2.localHeaderOffset, metadata2);
2334
+ }
2335
+ /** Looks up a canonical path; returns undefined when the entry is absent. */
2336
+ async getEntry(path) {
2337
+ this.signal.throwIfAborted();
2338
+ const metadata2 = (await this.getDirectory()).get(path);
2339
+ if (!metadata2) return void 0;
2340
+ let promise = this.entriesByPath.get(path);
2341
+ if (!promise) {
2342
+ promise = this.getValidatedEntry(metadata2.localHeaderOffset, metadata2).catch((error) => {
2343
+ this.entriesByPath.delete(path);
2344
+ throw error;
2345
+ });
2346
+ this.entriesByPath.set(path, promise);
2347
+ }
2348
+ return await promise;
2349
+ }
2350
+ /**
2351
+ * Validates a populated local header at an index-provided offset without a directory scan.
2352
+ * Descriptor entries fall back to the shared directory because their local sizes may be zero.
2353
+ * Direct access validates local layout/bounds; central consistency requires named lookup.
2354
+ */
2355
+ async getEntryAt(localHeaderOffset) {
2356
+ this.signal.throwIfAborted();
2357
+ const existing = this.entriesByOffset.get(localHeaderOffset);
2358
+ if (existing) return await existing;
2359
+ const metadata2 = await this.readLocalHeader(localHeaderOffset);
2360
+ if (metadata2.header.flags & 8) {
2361
+ for (const header of (await this.getDirectory()).values())
2362
+ if (header.localHeaderOffset === localHeaderOffset)
2363
+ return await this.getEntry(header.path);
2364
+ throw new Error("Invalid ZIP archive: indexed offset missing from directory");
2365
+ }
2366
+ return await this.getValidatedEntry(localHeaderOffset, void 0, metadata2);
2367
+ }
2368
+ /** Reads one complete entry and verifies its decoded size and CRC-32. */
2369
+ async read(entryOrPath, options = {}) {
2370
+ const signal = this.getReadSignal(options);
2371
+ signal.throwIfAborted();
2372
+ const entry = await this.resolveEntry(entryOrPath);
2373
+ signal.throwIfAborted();
2374
+ this.checkEntryBudget(entry);
2375
+ if (entry.size > BigInt(Number.MAX_SAFE_INTEGER))
2376
+ throw new RangeError("ZIP allocation is not safely representable");
2377
+ const output = new Uint8Array(Number(entry.size));
2378
+ let offset = 0;
2379
+ for await (const chunk of this.readInBatches(entry, options)) {
2380
+ output.set(chunk, offset);
2381
+ offset += chunk.byteLength;
2382
+ }
2383
+ return output.buffer;
2384
+ }
2385
+ /** Streams decoded chunks with backpressure; consuming through completion verifies CRC-32. */
2386
+ async *readInBatches(entryOrPath, options = {}) {
2387
+ const signal = this.getReadSignal(options);
2388
+ signal.throwIfAborted();
2389
+ const entry = await this.resolveEntry(entryOrPath);
2390
+ signal.throwIfAborted();
2391
+ this.checkEntryBudget(entry);
2392
+ let decodedBytes = 0n;
2393
+ let checksum = 0;
2394
+ const hash = new CRC32Hash({
2395
+ crypto: {
2396
+ onEnd: (result) => {
2397
+ checksum = Number.parseInt(result.hash, 16);
2398
+ }
2399
+ }
2400
+ });
2401
+ const compressed = this.readPayloadChunks(entry, signal);
2402
+ const decoded = entry.compression === "store" ? compressed : new DeflateDecompressor({ raw: true }).decompressBatches(compressed);
2403
+ for await (const chunk of hash.hashBatches(decoded, "hex")) {
2404
+ signal.throwIfAborted();
2405
+ decodedBytes += BigInt(chunk.byteLength);
2406
+ if (decodedBytes > entry.size || decodedBytes > this.limits.maxDecodedBytes)
2407
+ throw new RangeError("ZIP decoded entry size limit exceeded");
2408
+ yield new Uint8Array(chunk);
2409
+ }
2410
+ signal.throwIfAborted();
2411
+ if (decodedBytes !== entry.size) throw new Error("Invalid ZIP archive: decoded size mismatch");
2412
+ if (checksum !== entry.crc32) throw new Error("Invalid ZIP archive: CRC-32 mismatch");
2413
+ }
2414
+ /** Reads only a STORE byte range. Partial reads cannot verify a whole-entry CRC. */
2415
+ async readRange(entryOrPath, options) {
2416
+ const signal = this.getReadSignal(options);
2417
+ signal.throwIfAborted();
2418
+ const entry = await this.resolveEntry(entryOrPath);
2419
+ if (entry.compression !== "store") throw new Error("ZIP ranges require STORE entries");
2420
+ if (options.start < 0n || options.end < options.start || options.end > entry.size || options.end - options.start > BigInt(this.limits.maxReadBytes))
2421
+ throw new RangeError("ZIP byte-range limit exceeded");
2422
+ return await this.readExact(
2423
+ entry.dataOffset + options.start,
2424
+ Number(options.end - options.start),
2425
+ signal
2426
+ );
2427
+ }
2428
+ /** Cancels reads and closes the owned transport exactly once; all subsequent reads reject. */
2429
+ close() {
2430
+ this.controller.abort(new Error("ZIP archive is closed"));
2431
+ this.closePromise ||= this.file.close();
2432
+ return this.closePromise;
2433
+ }
2434
+ /** Resolves a named entry or rejects metadata not issued by this archive. */
2435
+ async resolveEntry(entryOrPath) {
2436
+ this.signal.throwIfAborted();
2437
+ const entry = typeof entryOrPath === "string" ? await this.getEntry(entryOrPath) : entryOrPath;
2438
+ if (!entry || !this.issuedEntries.has(entry))
2439
+ throw new Error("ZIP entry not found or belongs to another archive");
2440
+ return entry;
2441
+ }
2442
+ /** Combines per-read cancellation with the owned lifetime. */
2443
+ getReadSignal(options) {
2444
+ return options.signal ? AbortSignal.any([this.signal, options.signal]) : this.signal;
2445
+ }
2446
+ /** Checks whole-entry consumption before allocation or decompression. */
2447
+ checkEntryBudget(entry) {
2448
+ if (entry.size > this.limits.maxDecodedBytes || entry.compressedSize > this.limits.maxCompressedBytes)
2449
+ throw new RangeError("ZIP entry compressed/decoded byte limit exceeded");
2450
+ }
2451
+ /** Yields compressed bytes without retaining a complete entry. */
2452
+ async *readPayloadChunks(entry, signal) {
2453
+ const chunkBytes = Math.min(this.limits.chunkBytes, this.limits.maxReadBytes);
2454
+ for (let offset = 0n; offset < entry.compressedSize; offset += BigInt(chunkBytes)) {
2455
+ const length = Number(minimumBigInt(BigInt(chunkBytes), entry.compressedSize - offset));
2456
+ yield await this.readExact(entry.dataOffset + offset, length, signal);
2457
+ }
2458
+ }
2459
+ /** Performs exact, bounded physical reads and rejects truncated transports. */
2460
+ async readExact(offset, length, signal = this.signal) {
2461
+ signal.throwIfAborted();
2462
+ if (offset < 0n || !Number.isSafeInteger(length) || length < 0 || offset + BigInt(length) > this.size)
2463
+ throw new Error("Invalid ZIP archive: read outside file");
2464
+ const output = new Uint8Array(length);
2465
+ for (let copied = 0; copied < length; ) {
2466
+ const readBytes = Math.min(length - copied, this.limits.maxReadBytes);
2467
+ const bytes = await this.file.read(offset + BigInt(copied), readBytes, signal);
2468
+ signal.throwIfAborted();
2469
+ if (bytes.byteLength !== readBytes)
2470
+ throw new Error("Invalid ZIP archive: truncated file read");
2471
+ output.set(new Uint8Array(bytes), copied);
2472
+ copied += readBytes;
2473
+ }
2474
+ return output.buffer;
2475
+ }
2476
+ /** Finds an EOCD whose complete comment ends at EOF, not a signature embedded in the comment. */
2477
+ async readDirectoryLocation() {
2478
+ const magic = new DataView(await this.readExact(0n, 4)).getUint32(0, true);
2479
+ if (magic !== 67324752 && magic !== 101010256 && magic !== 101075792)
2480
+ throw new Error("Unsupported ZIP prefix or archive format");
2481
+ const tailLength = Number(minimumBigInt(this.size, 65557n));
2482
+ const tailStart = this.size - BigInt(tailLength);
2483
+ const tail = new DataView(await this.readExact(tailStart, tailLength));
2484
+ let position = -1;
2485
+ for (let candidate = tailLength - 22; candidate >= 0; candidate--) {
2486
+ if (tail.getUint32(candidate, true) !== 101010256 || candidate + 22 + tail.getUint16(candidate + 20, true) !== tailLength)
2487
+ continue;
2488
+ if (position < 0) position = candidate;
2489
+ const emptyDirectoryAtEnd = tail.getUint32(candidate + 12, true) === 0 && BigInt(tail.getUint32(candidate + 16, true)) === tailStart + BigInt(candidate);
2490
+ if (tail.getUint16(candidate + 10, true) !== 0 || emptyDirectoryAtEnd || magic === 101075792) {
2491
+ position = candidate;
2492
+ break;
2493
+ }
2494
+ }
2495
+ if (position < 0) throw new Error("Invalid ZIP archive: end record not found");
2496
+ const disk = tail.getUint16(position + 4, true);
2497
+ const directoryDisk = tail.getUint16(position + 6, true);
2498
+ if (disk !== 0 && disk !== 65535 || directoryDisk !== 0 && directoryDisk !== 65535)
2499
+ throw new Error("Unsupported split ZIP archive");
2500
+ const onDisk = BigInt(tail.getUint16(position + 8, true));
2501
+ let count = BigInt(tail.getUint16(position + 10, true));
2502
+ let size = BigInt(tail.getUint32(position + 12, true));
2503
+ let offset = BigInt(tail.getUint32(position + 16, true));
2504
+ let footerOffset = tailStart + BigInt(position);
2505
+ let zip64 = false;
2506
+ if (footerOffset >= 20n) {
2507
+ const locator = new DataView(await this.readExact(footerOffset - 20n, 20));
2508
+ const locatorInsideDirectory = size !== 0xffffffffn && offset !== 0xffffffffn && offset + size > footerOffset - 20n;
2509
+ if (locator.getUint32(0, true) === 117853008 && !locatorInsideDirectory) {
2510
+ zip64 = true;
2511
+ if (locator.getUint32(4, true) || locator.getUint32(16, true) !== 1)
2512
+ throw new Error("Unsupported split ZIP64 archive");
2513
+ const zip64Offset = locator.getBigUint64(8, true);
2514
+ const record = new DataView(await this.readExact(zip64Offset, 56));
2515
+ 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))
2516
+ throw new Error("Invalid ZIP64 end record");
2517
+ const zip64Count = record.getBigUint64(32, true);
2518
+ const zip64Size = record.getBigUint64(40, true);
2519
+ const zip64DirectoryOffset = record.getBigUint64(48, true);
2520
+ if (onDisk !== 0xffffn && onDisk !== zip64Count || count !== 0xffffn && count !== zip64Count || size !== 0xffffffffn && size !== zip64Size || offset !== 0xffffffffn && offset !== zip64DirectoryOffset)
2521
+ throw new Error("Invalid ZIP64 legacy end values");
2522
+ count = zip64Count;
2523
+ size = zip64Size;
2524
+ offset = zip64DirectoryOffset;
2525
+ footerOffset = zip64Offset;
2526
+ } else if (size === 0xffffffffn || offset === 0xffffffffn)
2527
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
2528
+ } else if (size === 0xffffffffn || offset === 0xffffffffn)
2529
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
2530
+ if (!zip64) {
2531
+ if (disk === 65535 || directoryDisk === 65535)
2532
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
2533
+ if (onDisk !== count) throw new Error("Invalid ZIP archive: inconsistent entry counts");
2534
+ }
2535
+ if (count > BigInt(this.limits.maxEntries) || size > BigInt(this.limits.maxDirectoryBytes))
2536
+ throw new RangeError("ZIP directory entry/byte limit exceeded");
2537
+ if (offset + size > footerOffset || size < count * 46n || count === 0n !== (size === 0n))
2538
+ throw new Error("Invalid ZIP archive: directory outside bounds");
2539
+ if (count && new DataView(await this.readExact(offset, 4)).getUint32(0, true) !== 33639248)
2540
+ throw new Error("Invalid ZIP archive: directory signature missing");
2541
+ const comment = decodeZipText(new Uint8Array(tail.buffer, position + 22), false);
2542
+ return { count, size, offset, comment };
2543
+ }
2544
+ /** Indexes central metadata once, without eagerly reading every local header. */
2545
+ getDirectory() {
2546
+ this.signal.throwIfAborted();
2547
+ this.directoryPromise ||= this.readDirectory().catch((error) => {
2548
+ this.directoryPromise = void 0;
2549
+ this.nextOffsets.clear();
2550
+ throw error;
2551
+ });
2552
+ return this.directoryPromise;
2553
+ }
2554
+ /** Parses exact directory records, including comments and Unicode/ZIP64 extras. */
2555
+ async readDirectory() {
2556
+ const bytes = new Uint8Array(
2557
+ await this.readExact(this.directory.offset, Number(this.directory.size))
2558
+ );
2559
+ const view = new DataView(bytes.buffer);
2560
+ const entries = /* @__PURE__ */ new Map();
2561
+ const offsets = /* @__PURE__ */ new Set();
2562
+ let position = 0;
2563
+ for (let index = 0n; index < this.directory.count; index++) {
2564
+ if (position + 46 > bytes.byteLength)
2565
+ throw new Error("Invalid ZIP archive: truncated directory");
2566
+ const length = 46 + view.getUint16(position + 28, true) + view.getUint16(position + 30, true) + view.getUint16(position + 32, true);
2567
+ const header = decodeZipHeader(bytes.subarray(position, position + length), true);
2568
+ if (header.localHeaderOffset + 30n > this.directory.offset)
2569
+ throw new Error("Invalid ZIP archive: local header outside data region");
2570
+ if (entries.has(header.path) || offsets.has(header.localHeaderOffset))
2571
+ throw new Error("Invalid ZIP archive: duplicate path or local-header offset");
2572
+ entries.set(header.path, header);
2573
+ offsets.add(header.localHeaderOffset);
2574
+ position += length;
2575
+ }
2576
+ const sortedOffsets = [...offsets].sort(
2577
+ (left, right) => left < right ? -1 : left > right ? 1 : 0
2578
+ );
2579
+ sortedOffsets.forEach(
2580
+ (offset, index) => this.nextOffsets.set(offset, sortedOffsets[index + 1] ?? this.directory.offset)
2581
+ );
2582
+ if (position !== bytes.byteLength)
2583
+ throw new Error("Invalid ZIP archive: directory length mismatch");
2584
+ return entries;
2585
+ }
2586
+ /** Reads local metadata without inspecting unrelated payloads. */
2587
+ async readLocalHeader(offset) {
2588
+ if (offset < 0n || offset + 30n > this.directory.offset)
2589
+ throw new Error("Invalid ZIP archive: local header outside data region");
2590
+ const fixed = new DataView(await this.readExact(offset, 30));
2591
+ const length = 30 + fixed.getUint16(26, true) + fixed.getUint16(28, true);
2592
+ if (offset + BigInt(length) > this.directory.offset)
2593
+ throw new Error("Invalid ZIP archive: local metadata overlaps directory");
2594
+ const bytes = new Uint8Array(length);
2595
+ bytes.set(new Uint8Array(fixed.buffer));
2596
+ bytes.set(new Uint8Array(await this.readExact(offset + 30n, length - 30)), 30);
2597
+ const header = decodeZipHeader(bytes, false);
2598
+ return { header, dataOffset: offset + BigInt(length) };
2599
+ }
2600
+ /** Shares local validation; a later named lookup additionally verifies central metadata. */
2601
+ async getValidatedEntry(offset, central, localMetadata) {
2602
+ if (central) return await this.validateEntry(offset, central);
2603
+ let entry = this.entriesByOffset.get(offset);
2604
+ if (!entry) {
2605
+ entry = this.validateEntry(offset, void 0, localMetadata).catch((error) => {
2606
+ this.entriesByOffset.delete(offset);
2607
+ throw error;
2608
+ });
2609
+ this.entriesByOffset.set(offset, entry);
2610
+ }
2611
+ return await entry;
2612
+ }
2613
+ /** Validates local/central identity, payload bounds and signed or unsigned descriptors. */
2614
+ async validateEntry(offset, central, localMetadata) {
2615
+ const { header: local, dataOffset } = localMetadata ?? await this.readLocalHeader(offset);
2616
+ const metadata2 = central || local;
2617
+ const descriptor = Boolean(local.flags & 8);
2618
+ 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)))
2619
+ throw new Error("Invalid ZIP archive: local/central metadata mismatch");
2620
+ if (metadata2.method === 0 && metadata2.size !== metadata2.compressedSize)
2621
+ throw new Error("Invalid ZIP archive: STORE sizes mismatch");
2622
+ if (central && descriptor && (local.crc32 !== 0 && local.crc32 !== central.crc32 || local.size !== 0n && local.size !== central.size || local.compressedSize !== 0n && local.compressedSize !== central.compressedSize))
2623
+ throw new Error("Invalid ZIP archive: descriptor local/central metadata mismatch");
2624
+ const payloadEnd = dataOffset + metadata2.compressedSize;
2625
+ const entryEnd = central ? this.nextOffsets.get(offset) ?? this.directory.offset : this.directory.offset;
2626
+ if (payloadEnd > entryEnd) throw new Error("Invalid ZIP archive: payload overlaps directory");
2627
+ if (descriptor)
2628
+ await this.validateDescriptor(
2629
+ payloadEnd,
2630
+ metadata2,
2631
+ local.zip64 || Boolean(central == null ? void 0 : central.zip64),
2632
+ entryEnd
2633
+ );
2634
+ const entry = Object.freeze({
2635
+ path: metadata2.path,
2636
+ directory: metadata2.path.endsWith("/"),
2637
+ compression: metadata2.method === 0 ? "store" : "deflate",
2638
+ size: metadata2.size,
2639
+ compressedSize: metadata2.compressedSize,
2640
+ crc32: metadata2.crc32,
2641
+ localHeaderOffset: offset,
2642
+ dataOffset,
2643
+ comment: (central == null ? void 0 : central.comment) || ""
2644
+ });
2645
+ this.issuedEntries.add(entry);
2646
+ return entry;
2647
+ }
2648
+ /** Resolves the optional descriptor signature using the expected CRC and sizes. */
2649
+ async validateDescriptor(offset, metadata2, zip64, entryEnd) {
2650
+ const length = Number(minimumBigInt(24n, entryEnd - offset));
2651
+ const bytes = new DataView(await this.readExact(offset, length));
2652
+ for (const wide of zip64 ? [true, false] : [false, true]) {
2653
+ if (!wide && (metadata2.size > 0xffffffffn || metadata2.compressedSize > 0xffffffffn)) continue;
2654
+ const descriptorLength = wide ? 20 : 12;
2655
+ for (const prefix of [4, 0]) {
2656
+ if (length < prefix + descriptorLength || prefix && bytes.getUint32(0, true) !== 134695760)
2657
+ continue;
2658
+ const compressed = wide ? bytes.getBigUint64(prefix + 4, true) : BigInt(bytes.getUint32(prefix + 4, true));
2659
+ const decoded = wide ? bytes.getBigUint64(prefix + 12, true) : BigInt(bytes.getUint32(prefix + 8, true));
2660
+ if (bytes.getUint32(prefix, true) === metadata2.crc32 && compressed === metadata2.compressedSize && decoded === metadata2.size)
2661
+ return;
2662
+ }
2663
+ }
2664
+ throw new Error("Invalid ZIP archive: data descriptor mismatch");
2665
+ }
2666
+ };
2667
+ }
2668
+ });
2669
+
2670
+ // src/zip/zip-loader.ts
2671
+ var zip_loader_exports = {};
2672
+ __export(zip_loader_exports, {
2673
+ ZipLoaderWithParser: () => ZipLoaderWithParser
2674
+ });
2675
+ async function parseZip(input, options = {}) {
2676
+ var _a;
2677
+ const maximum = ((_a = options.zip) == null ? void 0 : _a.maxTotalDecodedBytes) ?? ZipLoader.options.zip.maxTotalDecodedBytes;
2678
+ if (typeof maximum !== "bigint" || maximum < 0n)
2679
+ throw new RangeError("Invalid ZIP total decoded-byte limit");
2680
+ const archive = await openZipArchive(input, options.zip);
2681
+ try {
2682
+ const entries = [];
2683
+ let totalBytes = 0n;
2684
+ for await (const entry of archive.entries()) {
2685
+ if (entry.directory) continue;
2686
+ totalBytes += entry.size;
2687
+ if (totalBytes > maximum) throw new RangeError("ZIP total decoded-byte limit exceeded");
2688
+ entries.push(entry);
2689
+ }
2690
+ const files = /* @__PURE__ */ Object.create(null);
2691
+ for (const entry of entries) files[entry.path] = await archive.read(entry);
2692
+ return files;
2693
+ } finally {
2694
+ await archive.close();
2695
+ }
2696
+ }
2697
+ var _preload, metadata, ZipLoaderWithParser;
2698
+ var init_zip_loader = __esm({
2699
+ "src/zip/zip-loader.ts"() {
2700
+ "use strict";
2701
+ init_zip_loader_types();
2702
+ init_zip_archive();
2703
+ ({ preload: _preload, ...metadata } = ZipLoader);
2704
+ ZipLoaderWithParser = {
2705
+ ...metadata,
2706
+ parse: parseZip
2707
+ };
2708
+ }
2709
+ });
2710
+
2711
+ // dist/zip/index.js
2712
+ var index_exports = {};
2713
+ __export(index_exports, {
2714
+ IndexedArchive: () => IndexedArchive,
2715
+ ZipArchive: () => ZipArchive2,
2716
+ ZipFileSystem: () => ZipFileSystem,
2717
+ ZipFormat: () => ZipFormat,
2718
+ ZipLoader: () => ZipLoader2,
2719
+ ZipWriter: () => ZipWriter,
2720
+ addOneFile: () => addOneFile,
2721
+ composeHashFile: () => composeHashFile,
2722
+ createZip: () => createZip,
2723
+ encodeIndexedZip: () => encodeIndexedZip,
2724
+ encodeZip: () => encodeZip,
2725
+ encodeZipInBatches: () => encodeZipInBatches,
2726
+ openZipArchive: () => openZipArchive2,
2727
+ parseHashTable: () => parseHashTable
2728
+ });
2729
+ module.exports = __toCommonJS(index_exports);
2730
+
2731
+ // dist/zip/zip-format.js
2732
+ var ZipFormat = {
2733
+ name: "Zip Archive",
2734
+ id: "zip",
2735
+ module: "archives",
2736
+ encoding: "zip",
2737
+ format: "zip",
2738
+ extensions: ["zip"],
2739
+ mimeTypes: ["application/zip"],
2740
+ category: "archive",
2741
+ binary: true,
2742
+ tests: ["PK"]
2743
+ };
2744
+
2745
+ // dist/zip/zip-loader-types.js
2746
+ var VERSION2 = true ? "5.0.0-alpha.14" : "latest";
2747
+ var ZipLoader2 = {
2748
+ ...ZipFormat,
2749
+ version: VERSION2,
2750
+ dataType: null,
2751
+ batchType: null,
2752
+ options: { zip: { maxTotalDecodedBytes: 64n * 1024n * 1024n } },
2753
+ /** Loads the parser implementation through its installed package subpath. */
2754
+ async preload() {
2755
+ const { ZipLoaderWithParser: ZipLoaderWithParser2 } = await Promise.resolve().then(() => (init_zip_loader(), zip_loader_exports));
2756
+ return ZipLoaderWithParser2;
2757
+ }
2758
+ };
2759
+
2760
+ // ../compression/src/deflate-compressor-compress-utils.ts
2761
+ init_compress_utils_compression();
2762
+ var DeflateCompressUtilsCompressor = class extends CompressUtilsCompressor {
2763
+ constructor(options = {}) {
2764
+ super(
2765
+ { name: "deflate", contentEncodings: ["deflate"] },
2766
+ () => options.raw ? import("compress-utils/deflate/compress") : import("compress-utils/zlib/compress"),
2767
+ options
2768
+ );
2769
+ }
2770
+ };
2771
+
2772
+ // ../compression/src/lib/compression-stream.ts
2773
+ async function compressWithNativeCompressionStream(input, format) {
2774
+ const outputBatches = compressBatchesWithNativeCompressionStream([input], format);
2775
+ return outputBatches ? await concatenateBatches(outputBatches) : null;
2776
+ }
2777
+ function compressBatchesWithNativeCompressionStream(inputBatches, format) {
2778
+ const compressionStream = createNativeCompressionStream(format);
2779
+ return compressionStream ? transformBatches2(inputBatches, compressionStream) : null;
2780
+ }
2781
+ function createNativeCompressionStream(format) {
2782
+ if (typeof globalThis.CompressionStream === "undefined") {
2783
+ return null;
2784
+ }
2785
+ try {
2786
+ const CompressionStreamConstructor = globalThis.CompressionStream;
2787
+ return new CompressionStreamConstructor(format);
2788
+ } catch (error) {
2789
+ if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
2790
+ return null;
2791
+ }
2792
+ throw error;
2793
+ }
2794
+ }
2795
+ async function* transformBatches2(inputBatches, compressionStream) {
2796
+ const writer = compressionStream.writable.getWriter();
2797
+ const reader = compressionStream.readable.getReader();
2798
+ const writePromise = writeBatches(inputBatches, writer);
2799
+ writePromise.catch(() => {
2800
+ });
2801
+ let outputCompleted = false;
2802
+ try {
2803
+ while (true) {
2804
+ const { done, value } = await reader.read();
2805
+ if (done) {
2806
+ outputCompleted = true;
2807
+ break;
2808
+ }
2809
+ yield new Uint8Array(value).buffer;
2810
+ }
2811
+ await writePromise;
2812
+ } finally {
2813
+ if (!outputCompleted) {
2814
+ await reader.cancel().catch(() => {
2815
+ });
2816
+ await writer.abort().catch(() => {
2817
+ });
2818
+ await writePromise.catch(() => {
2819
+ });
2820
+ }
2821
+ reader.releaseLock();
2822
+ }
2823
+ }
2824
+ async function writeBatches(inputBatches, writer) {
2825
+ try {
2826
+ for await (const inputBatch of inputBatches) {
2827
+ await writer.write(new Uint8Array(inputBatch));
2828
+ }
2829
+ await writer.close();
2830
+ } catch (error) {
2831
+ await writer.abort(error).catch(() => {
2832
+ });
2833
+ throw error;
2834
+ }
2835
+ }
2836
+ async function concatenateBatches(batches) {
2837
+ const output = [];
2838
+ let byteLength = 0;
2839
+ for await (const batch of batches) {
2840
+ const bytes = new Uint8Array(batch);
2841
+ output.push(bytes);
2842
+ byteLength += bytes.byteLength;
2843
+ }
2844
+ const result = new Uint8Array(byteLength);
2845
+ let offset = 0;
2846
+ for (const batch of output) {
2847
+ result.set(batch, offset);
2848
+ offset += batch.byteLength;
2849
+ }
2850
+ return result.buffer;
2851
+ }
2852
+
2853
+ // ../compression/src/deflate-compressor.ts
2854
+ var DeflateCompressor = class extends DeflateCompressUtilsCompressor {
2855
+ /** Compresses with native streams when available, otherwise lazily initializes WASM. */
2856
+ async compress(input) {
2857
+ if (this.options.useNative !== false && !this.options.raw) {
2858
+ const output = await compressWithNativeCompressionStream(input, "deflate");
2859
+ if (output) return output;
2860
+ }
2861
+ return super.compress(input);
2862
+ }
2863
+ /** Streams native batches when available, otherwise uses the WASM stream. */
2864
+ async *compressBatches(inputBatches) {
2865
+ if (this.options.useNative !== false && !this.options.raw) {
2866
+ const output = compressBatchesWithNativeCompressionStream(inputBatches, "deflate");
2867
+ if (output) {
2868
+ yield* output;
2869
+ return;
2870
+ }
2871
+ }
2872
+ yield* super.compressBatches(inputBatches);
2873
+ }
2874
+ };
2875
+
2876
+ // dist/zip/zip-encode.js
2877
+ init_src();
2878
+
2879
+ // dist/zip/lib/zip-entry-metadata.js
2880
+ init_src();
2881
+
2882
+ // dist/zip/lib/zip64-extra-field.js
2883
+ var ZIP64_EXTRA_FIELD_ID2 = 1;
2884
+ function parseZip64ExtraField2(extraField, expectedFields) {
2885
+ const values = {};
2886
+ if (expectedFields.length === 0) {
2887
+ return values;
2888
+ }
2889
+ const expectedPayloadLength = expectedFields.reduce((totalByteLength, field) => totalByteLength + field.byteLength, 0);
2890
+ let recordOffset = 0;
2891
+ while (recordOffset < extraField.byteLength) {
2892
+ if (recordOffset + 4 > extraField.byteLength) {
2893
+ throw new Error("Invalid ZIP archive: truncated extra-field record header while reading ZIP64 data");
2894
+ }
2895
+ const headerId = extraField.getUint16(recordOffset, true);
2896
+ const payloadLength = extraField.getUint16(recordOffset + 2, true);
2897
+ const payloadOffset = recordOffset + 4;
2898
+ const nextRecordOffset = payloadOffset + payloadLength;
2899
+ if (nextRecordOffset > extraField.byteLength) {
2900
+ throw new Error("Invalid ZIP archive: truncated extra-field record payload while reading ZIP64 data");
2901
+ }
2902
+ if (headerId === ZIP64_EXTRA_FIELD_ID2) {
2903
+ if (payloadLength !== expectedPayloadLength) {
2904
+ throw new Error("Invalid ZIP archive: ZIP64 extended information has an unexpected payload size");
2905
+ }
2906
+ let fieldOffset = payloadOffset;
2907
+ for (const field of expectedFields) {
2908
+ values[field.name] = field.byteLength === 8 ? extraField.getBigUint64(fieldOffset, true) : BigInt(extraField.getUint32(fieldOffset, true));
2909
+ fieldOffset += field.byteLength;
2910
+ }
2911
+ return values;
2912
+ }
2913
+ recordOffset = nextRecordOffset;
2914
+ }
2915
+ throw new Error("Invalid ZIP archive: required ZIP64 extended information is missing");
2916
+ }
2917
+
2918
+ // dist/zip/lib/zip-entry-metadata.js
2919
+ 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";
2920
+ function decodeZipHeader2(bytes, central) {
2921
+ const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
2922
+ const fixedBytes = central ? 46 : 30;
2923
+ if (bytes.byteLength < fixedBytes || header.getUint32(0, true) !== (central ? 33639248 : 67324752))
2924
+ throw new Error("Invalid ZIP archive: missing entry header");
2925
+ const nameLength = header.getUint16(central ? 28 : 26, true);
2926
+ const extraLength = header.getUint16(central ? 30 : 28, true);
2927
+ const commentLength = central ? header.getUint16(32, true) : 0;
2928
+ if (bytes.byteLength !== fixedBytes + nameLength + extraLength + commentLength)
2929
+ throw new Error("Invalid ZIP archive: truncated entry metadata");
2930
+ const flags = header.getUint16(central ? 8 : 6, true);
2931
+ const method = header.getUint16(central ? 10 : 8, true);
2932
+ if (flags & (1 | 64 | 8192))
2933
+ throw new Error("Unsupported ZIP encryption");
2934
+ if (flags & ~(8 | 2048 | (method === 8 ? 6 : 0)))
2935
+ throw new Error("Unsupported ZIP flags");
2936
+ if (method !== 0 && method !== 8)
2937
+ throw new Error(`Unsupported ZIP compression method: ${method}`);
2938
+ let compressedSize = BigInt(header.getUint32(central ? 20 : 18, true));
2939
+ let size = BigInt(header.getUint32(central ? 24 : 22, true));
2940
+ let localHeaderOffset = central ? BigInt(header.getUint32(42, true)) : 0n;
2941
+ let disk = central ? BigInt(header.getUint16(34, true)) : 0n;
2942
+ let zip64 = compressedSize === 0xffffffffn || size === 0xffffffffn;
2943
+ const fields = [];
2944
+ if (central) {
2945
+ if (size === 0xffffffffn)
2946
+ fields.push({ name: "size", byteLength: 8 });
2947
+ if (compressedSize === 0xffffffffn)
2948
+ fields.push({ name: "compressedSize", byteLength: 8 });
2949
+ if (localHeaderOffset === 0xffffffffn)
2950
+ fields.push({ name: "localHeaderOffset", byteLength: 8 });
2951
+ if (disk === 0xffffn)
2952
+ fields.push({ name: "disk", byteLength: 4 });
2953
+ } else if (zip64)
2954
+ fields.push({ name: "size", byteLength: 8 }, { name: "compressedSize", byteLength: 8 });
2955
+ const extraBytes = bytes.subarray(fixedBytes + nameLength, fixedBytes + nameLength + extraLength);
2956
+ const extra = new DataView(extraBytes.buffer, extraBytes.byteOffset, extraBytes.byteLength);
2957
+ const extraValues = parseZip64ExtraField2(extra, fields);
2958
+ if (size === 0xffffffffn)
2959
+ size = extraValues.size;
2960
+ if (compressedSize === 0xffffffffn)
2961
+ compressedSize = extraValues.compressedSize;
2962
+ if (localHeaderOffset === 0xffffffffn)
2963
+ localHeaderOffset = extraValues.localHeaderOffset;
2964
+ if (disk === 0xffffn)
2965
+ disk = extraValues.disk;
2966
+ if (disk !== 0n)
2967
+ throw new Error("Unsupported split ZIP archive");
2968
+ const nameBytes = bytes.subarray(fixedBytes, fixedBytes + nameLength);
2969
+ let path = decodeZipText2(nameBytes, Boolean(flags & 2048));
2970
+ const commentBytes = bytes.subarray(fixedBytes + nameLength + extraLength);
2971
+ let comment = decodeZipText2(commentBytes, Boolean(flags & 2048));
2972
+ for (let offset = 0; offset < extra.byteLength; ) {
2973
+ if (offset + 4 > extra.byteLength)
2974
+ throw new Error("Invalid ZIP archive: truncated extra field");
2975
+ const identifier = extra.getUint16(offset, true);
2976
+ const length = extra.getUint16(offset + 2, true);
2977
+ if (offset + 4 + length > extra.byteLength)
2978
+ throw new Error("Invalid ZIP archive: truncated extra field");
2979
+ if (!central && flags & 8 && identifier === 1) {
2980
+ if (length >= 16)
2981
+ zip64 = true;
2982
+ }
2983
+ if (identifier === 28789 || identifier === 25461) {
2984
+ const original = identifier === 28789 ? nameBytes : commentBytes;
2985
+ if (length < 5)
2986
+ throw new Error("Invalid ZIP archive: truncated Unicode extra field");
2987
+ if (extra.getUint8(offset + 4) === 1 && extra.getUint32(offset + 5, true) === calculateZipChecksum2(original)) {
2988
+ const text = decodeZipText2(extraBytes.subarray(offset + 9, offset + 4 + length), true);
2989
+ if (identifier === 28789)
2990
+ path = text;
2991
+ else
2992
+ comment = text;
2993
+ }
2994
+ }
2995
+ offset += 4 + length;
2996
+ }
2997
+ validateZipPath2(path);
2998
+ return {
2999
+ path,
3000
+ nameBytes,
3001
+ flags,
3002
+ method,
3003
+ crc32: header.getUint32(central ? 16 : 14, true),
3004
+ compressedSize,
3005
+ size,
3006
+ localHeaderOffset,
3007
+ comment,
3008
+ zip64
3009
+ };
3010
+ }
3011
+ function decodeZipText2(bytes, utf8) {
3012
+ if (utf8)
3013
+ return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
3014
+ return Array.from(bytes, (value) => value < 128 ? String.fromCharCode(value) : CP437_HIGH2[value - 128]).join("");
3015
+ }
3016
+ function validateZipPath2(path) {
3017
+ const segments = path.endsWith("/") ? path.slice(0, -1).split("/") : path.split("/");
3018
+ if (!path || path.includes("\\") || path.includes("\0") || /^[A-Za-z]:/.test(path) || segments.some((segment) => !segment || segment === "." || segment === ".."))
3019
+ throw new Error("Invalid ZIP archive: noncanonical relative path");
3020
+ }
3021
+ function calculateZipChecksum2(bytes) {
3022
+ return Number.parseInt(new CRC32Hash().hashSync(bytes.slice().buffer, "hex"), 16);
3023
+ }
3024
+ function encodeUtf8Text2(value) {
3025
+ const bytes = new TextEncoder().encode(value);
3026
+ if (new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes) !== value)
3027
+ throw new TypeError("ZIP names and entry comments must be well-formed Unicode");
3028
+ return bytes;
3029
+ }
3030
+
3031
+ // dist/zip/lib/zip-serialization.js
3032
+ var ZIP32_SENTINEL2 = 0xffffffffn;
3033
+ function encodeZipLocalHeader2(entry) {
3034
+ validateHeaderEntry2(entry);
3035
+ const bytes = new Uint8Array(30 + entry.nameBytes.length + (entry.zip64 ? 20 : 0));
3036
+ const view = new DataView(bytes.buffer);
3037
+ view.setUint32(0, 67324752, true);
3038
+ view.setUint16(4, getZipVersion2(entry), true);
3039
+ view.setUint16(6, entry.flags, true);
3040
+ view.setUint16(8, entry.method, true);
3041
+ view.setUint32(10, encodeZipTimestamp2(entry.date), true);
3042
+ const descriptor = Boolean(entry.flags & 8);
3043
+ view.setUint32(14, descriptor ? 0 : entry.crc32, true);
3044
+ view.setUint32(18, entry.zip64 ? Number(ZIP32_SENTINEL2) : descriptor ? 0 : Number(entry.compressedSize), true);
3045
+ view.setUint32(22, entry.zip64 ? Number(ZIP32_SENTINEL2) : descriptor ? 0 : Number(entry.size), true);
3046
+ view.setUint16(26, entry.nameBytes.length, true);
3047
+ view.setUint16(28, entry.zip64 ? 20 : 0, true);
3048
+ bytes.set(entry.nameBytes, 30);
3049
+ if (entry.zip64) {
3050
+ const extraOffset = 30 + entry.nameBytes.length;
3051
+ view.setUint16(extraOffset, 1, true);
3052
+ view.setUint16(extraOffset + 2, 16, true);
3053
+ view.setBigUint64(extraOffset + 4, descriptor ? 0n : entry.size, true);
3054
+ view.setBigUint64(extraOffset + 12, descriptor ? 0n : entry.compressedSize, true);
3055
+ }
3056
+ return bytes;
3057
+ }
3058
+ function encodeZipCentralHeader2(entry) {
3059
+ validateHeaderEntry2(entry);
3060
+ const comment = entry.commentBytes ?? new Uint8Array();
3061
+ const extraBytes = entry.zip64 ? 28 : 0;
3062
+ const bytes = new Uint8Array(46 + entry.nameBytes.length + extraBytes + comment.length);
3063
+ const view = new DataView(bytes.buffer);
3064
+ view.setUint32(0, 33639248, true);
3065
+ view.setUint16(4, entry.zip64 ? 45 : 20, true);
3066
+ view.setUint16(6, getZipVersion2(entry), true);
3067
+ view.setUint16(8, entry.flags, true);
3068
+ view.setUint16(10, entry.method, true);
3069
+ view.setUint32(12, encodeZipTimestamp2(entry.date), true);
3070
+ view.setUint32(16, entry.crc32, true);
3071
+ view.setUint32(20, entry.zip64 ? Number(ZIP32_SENTINEL2) : Number(entry.compressedSize), true);
3072
+ view.setUint32(24, entry.zip64 ? Number(ZIP32_SENTINEL2) : Number(entry.size), true);
3073
+ view.setUint16(28, entry.nameBytes.length, true);
3074
+ view.setUint16(30, extraBytes, true);
3075
+ view.setUint16(32, comment.length, true);
3076
+ view.setUint32(38, entry.directory ? 16 : 0, true);
3077
+ view.setUint32(42, entry.zip64 ? Number(ZIP32_SENTINEL2) : Number(entry.localHeaderOffset), true);
3078
+ bytes.set(entry.nameBytes, 46);
3079
+ if (entry.zip64) {
3080
+ const extraOffset = 46 + entry.nameBytes.length;
3081
+ view.setUint16(extraOffset, 1, true);
3082
+ view.setUint16(extraOffset + 2, 24, true);
3083
+ view.setBigUint64(extraOffset + 4, entry.size, true);
3084
+ view.setBigUint64(extraOffset + 12, entry.compressedSize, true);
3085
+ view.setBigUint64(extraOffset + 20, entry.localHeaderOffset, true);
3086
+ }
3087
+ bytes.set(comment, 46 + entry.nameBytes.length + extraBytes);
3088
+ return bytes;
3089
+ }
3090
+ function encodeZipDescriptor(entry) {
3091
+ validateHeaderEntry2(entry);
3092
+ const bytes = new Uint8Array(entry.zip64 ? 24 : 16);
3093
+ const view = new DataView(bytes.buffer);
3094
+ view.setUint32(0, 134695760, true);
3095
+ view.setUint32(4, entry.crc32, true);
3096
+ if (entry.zip64) {
3097
+ view.setBigUint64(8, entry.compressedSize, true);
3098
+ view.setBigUint64(16, entry.size, true);
3099
+ } else {
3100
+ view.setUint32(8, Number(entry.compressedSize), true);
3101
+ view.setUint32(12, Number(entry.size), true);
3102
+ }
3103
+ return bytes;
3104
+ }
3105
+ function encodeZipEndRecords2(count, directorySize, directoryOffset, zip64, comment = new Uint8Array()) {
3106
+ for (const value of [count, directorySize, directoryOffset, directoryOffset + directorySize])
3107
+ validateUint642(value);
3108
+ if (comment.length > 65535)
3109
+ throw new RangeError("ZIP archive comment exceeds 65535 bytes");
3110
+ if (!zip64 && (count > 0xffffn || directorySize >= ZIP32_SENTINEL2 || directoryOffset >= ZIP32_SENTINEL2))
3111
+ throw new RangeError("ZIP32 end record capacity exceeded");
3112
+ const bytes = new Uint8Array((zip64 ? 98 : 22) + comment.length);
3113
+ const view = new DataView(bytes.buffer);
3114
+ if (zip64) {
3115
+ view.setUint32(0, 101075792, true);
3116
+ view.setBigUint64(4, 44n, true);
3117
+ view.setUint16(12, 45, true);
3118
+ view.setUint16(14, 45, true);
3119
+ view.setBigUint64(24, count, true);
3120
+ view.setBigUint64(32, count, true);
3121
+ view.setBigUint64(40, directorySize, true);
3122
+ view.setBigUint64(48, directoryOffset, true);
3123
+ view.setUint32(56, 117853008, true);
3124
+ view.setBigUint64(64, directoryOffset + directorySize, true);
3125
+ view.setUint32(72, 1, true);
3126
+ }
3127
+ const endOffset = zip64 ? 76 : 0;
3128
+ view.setUint32(endOffset, 101010256, true);
3129
+ view.setUint16(endOffset + 8, zip64 ? 65535 : Number(count), true);
3130
+ view.setUint16(endOffset + 10, zip64 ? 65535 : Number(count), true);
3131
+ view.setUint32(endOffset + 12, zip64 ? Number(ZIP32_SENTINEL2) : Number(directorySize), true);
3132
+ view.setUint32(endOffset + 16, zip64 ? Number(ZIP32_SENTINEL2) : Number(directoryOffset), true);
3133
+ view.setUint16(endOffset + 20, comment.length, true);
3134
+ bytes.set(comment, endOffset + 22);
3135
+ return bytes;
3136
+ }
3137
+ function encodeZipTimestamp2(date) {
3138
+ if (!(date instanceof Date) || !Number.isFinite(date.getTime()) || date.getUTCFullYear() < 1980 || date.getUTCFullYear() > 2107)
3139
+ throw new RangeError("ZIP timestamp must be a valid UTC date in 1980\u20132107");
3140
+ const time = date.getUTCHours() << 11 | date.getUTCMinutes() << 5 | Math.floor(date.getUTCSeconds() / 2);
3141
+ const day = date.getUTCFullYear() - 1980 << 9 | date.getUTCMonth() + 1 << 5 | date.getUTCDate();
3142
+ return (day << 16 | time) >>> 0;
3143
+ }
3144
+ function getZipVersion2(entry) {
3145
+ return entry.zip64 ? 45 : entry.method === 8 || entry.flags & 8 ? 20 : 10;
3146
+ }
3147
+ function validateHeaderEntry2(entry) {
3148
+ var _a;
3149
+ if (!entry.nameBytes.length || entry.nameBytes.length > 65535 || (((_a = entry.commentBytes) == null ? void 0 : _a.length) ?? 0) > 65535)
3150
+ throw new RangeError("ZIP name/comment exceeds header capacity");
3151
+ for (const value of [entry.size, entry.compressedSize, entry.localHeaderOffset])
3152
+ validateUint642(value);
3153
+ if (!entry.zip64 && [entry.size, entry.compressedSize, entry.localHeaderOffset].some((value) => value >= ZIP32_SENTINEL2))
3154
+ throw new RangeError("ZIP32 entry capacity exceeded");
3155
+ }
3156
+ function validateUint642(value) {
3157
+ if (typeof value !== "bigint" || value < 0n || value > 0xffffffffffffffffn)
3158
+ throw new RangeError("ZIP64 unsigned integer capacity exceeded");
3159
+ }
3160
+
3161
+ // dist/zip/zip-encode.js
3162
+ var DEFAULT_OPTIONS2 = {
3163
+ compression: "store",
3164
+ zip64: "auto",
3165
+ maxArchiveBytes: 1024n ** 4n,
3166
+ maxEntryBytes: 1024n ** 4n,
3167
+ maxDirectoryBytes: 32 * 1024 * 1024,
3168
+ maxEntries: 1e5,
3169
+ chunkBytes: 64 * 1024
3170
+ };
3171
+ async function encodeZip(files, options = {}) {
3172
+ const chunks = [];
3173
+ let size = 0;
3174
+ for await (const chunk of encodeZipInBatches(files, options)) {
3175
+ if (size + chunk.length > 4294967295)
3176
+ throw new RangeError("ZIP buffer capacity exceeded; use encodeZipInBatches");
3177
+ chunks.push(chunk);
3178
+ size += chunk.length;
3179
+ }
3180
+ const output = new Uint8Array(size);
3181
+ let offset = 0;
3182
+ for (const chunk of chunks) {
3183
+ output.set(chunk, offset);
3184
+ offset += chunk.length;
3185
+ }
3186
+ return output.buffer;
3187
+ }
3188
+ async function* encodeZipInBatches(files, options = {}) {
3189
+ const settings = {
3190
+ compression: options.compression ?? DEFAULT_OPTIONS2.compression,
3191
+ zip64: options.zip64 ?? DEFAULT_OPTIONS2.zip64,
3192
+ maxArchiveBytes: options.maxArchiveBytes ?? DEFAULT_OPTIONS2.maxArchiveBytes,
3193
+ maxEntryBytes: options.maxEntryBytes ?? DEFAULT_OPTIONS2.maxEntryBytes,
3194
+ maxDirectoryBytes: options.maxDirectoryBytes ?? DEFAULT_OPTIONS2.maxDirectoryBytes,
3195
+ maxEntries: options.maxEntries ?? DEFAULT_OPTIONS2.maxEntries,
3196
+ chunkBytes: options.chunkBytes ?? DEFAULT_OPTIONS2.chunkBytes
3197
+ };
3198
+ validateSettings(settings);
3199
+ const signal = options.signal;
3200
+ signal == null ? void 0 : signal.throwIfAborted();
3201
+ const comment = encodeArchiveComment(options.comment ?? "");
3202
+ const date = options.date ?? /* @__PURE__ */ new Date("1980-01-01T00:00:00Z");
3203
+ encodeZipTimestamp2(date);
3204
+ const paths = Object.keys(files).sort();
3205
+ if (paths.length > settings.maxEntries)
3206
+ throw new RangeError("ZIP entry count limit exceeded");
3207
+ if (settings.zip64 === "never" && paths.length > 65535)
3208
+ throw new RangeError("ZIP32 entry count capacity exceeded");
3209
+ let minimumDirectoryBytes = 0;
3210
+ const entries = paths.map((path) => {
3211
+ var _a;
3212
+ validateZipPath2(path);
3213
+ const value = files[path];
3214
+ const entry = value && typeof value === "object" && "data" in value ? value : { data: value };
3215
+ const size = getSourceSize(entry.data);
3216
+ const directory2 = path.endsWith("/");
3217
+ const compression = entry.compression ?? settings.compression;
3218
+ if (compression !== "store" && compression !== "deflate")
3219
+ throw new TypeError("Unsupported ZIP compression");
3220
+ if (size !== void 0 && (size > settings.maxEntryBytes || directory2 && size !== 0n))
3221
+ throw new RangeError("ZIP entry byte limit or nonempty directory");
3222
+ if (path.length > 65535 || (((_a = entry.comment) == null ? void 0 : _a.length) ?? 0) > 65535)
3223
+ throw new RangeError("ZIP name/comment exceeds header capacity");
3224
+ if (entry.comment !== void 0 && typeof entry.comment !== "string")
3225
+ throw new TypeError("ZIP entry comment must be a string");
3226
+ const nameBytes = encodeUtf8Text2(path);
3227
+ const commentBytes = encodeUtf8Text2(entry.comment ?? "");
3228
+ encodeZipTimestamp2(entry.date ?? date);
3229
+ const timestamp = new Date((entry.date ?? date).getTime());
3230
+ const zip642 = settings.zip64 === "always" || settings.zip64 === "auto" && (size === void 0 || size >= 0xffffffffn || !directory2 && compression === "deflate");
3231
+ const header = {
3232
+ nameBytes,
3233
+ commentBytes,
3234
+ date: timestamp,
3235
+ method: directory2 || compression === "store" ? 0 : 8,
3236
+ flags: 2056,
3237
+ crc32: 0,
3238
+ size: size ?? 0n,
3239
+ compressedSize: 0n,
3240
+ localHeaderOffset: 0n,
3241
+ zip64: zip642,
3242
+ directory: directory2
3243
+ };
3244
+ encodeZipCentralHeader2(header);
3245
+ minimumDirectoryBytes += 46 + nameBytes.length + commentBytes.length + (zip642 ? 28 : 0);
3246
+ if (minimumDirectoryBytes > settings.maxDirectoryBytes)
3247
+ throw new RangeError("ZIP directory byte limit exceeded");
3248
+ return { source: entry.data, size, header };
3249
+ });
3250
+ let outputBytes = 0n;
3251
+ let directoryBytes = 0;
3252
+ let usedZip64 = settings.zip64 === "always";
3253
+ const directory = [];
3254
+ function* emit(bytes) {
3255
+ for (let offset = 0; offset < bytes.length; offset += settings.chunkBytes) {
3256
+ signal == null ? void 0 : signal.throwIfAborted();
3257
+ const chunk = bytes.slice(offset, offset + settings.chunkBytes);
3258
+ if (outputBytes + BigInt(chunk.length) > settings.maxArchiveBytes)
3259
+ throw new RangeError("ZIP archive output byte limit exceeded");
3260
+ outputBytes += BigInt(chunk.length);
3261
+ yield chunk;
3262
+ signal == null ? void 0 : signal.throwIfAborted();
3263
+ }
3264
+ }
3265
+ for (const entry of entries) {
3266
+ signal == null ? void 0 : signal.throwIfAborted();
3267
+ const zip642 = entry.header.zip64 || settings.zip64 === "auto" && outputBytes >= 0xffffffffn;
3268
+ const header = { ...entry.header, localHeaderOffset: outputBytes, zip64: zip642 };
3269
+ usedZip64 ||= zip642;
3270
+ yield* emit(encodeZipLocalHeader2(header));
3271
+ let size = 0n;
3272
+ let compressedSize = 0n;
3273
+ let checksum = 0;
3274
+ async function* measuredInput() {
3275
+ for await (const block of readSource(entry.source, settings.chunkBytes, signal)) {
3276
+ size += BigInt(block.byteLength);
3277
+ if (size > settings.maxEntryBytes || header.directory && size !== 0n)
3278
+ throw new RangeError("ZIP entry byte limit or nonempty directory");
3279
+ if (!zip642 && size >= 0xffffffffn)
3280
+ throw new RangeError("ZIP32 entry capacity exceeded");
3281
+ yield block;
3282
+ }
3283
+ if (entry.size !== void 0 && size !== entry.size)
3284
+ throw new TypeError("ZIP source size changed during encoding");
3285
+ }
3286
+ const hash = new CRC32Hash({
3287
+ crypto: {
3288
+ /** Captures the CRC after all decoded input bytes have been consumed. */
3289
+ onEnd: (result) => {
3290
+ checksum = Number.parseInt(result.hash, 16);
3291
+ }
3292
+ }
3293
+ });
3294
+ const input = hash.hashBatches(measuredInput(), "hex");
3295
+ const payload = header.method === 8 ? new DeflateCompressor({ raw: true }).compressBatches(input) : input;
3296
+ for await (const block of payload) {
3297
+ signal == null ? void 0 : signal.throwIfAborted();
3298
+ compressedSize += BigInt(block.byteLength);
3299
+ if (!zip642 && compressedSize >= 0xffffffffn)
3300
+ throw new RangeError("ZIP32 compressed entry capacity exceeded");
3301
+ yield* emit(new Uint8Array(block));
3302
+ }
3303
+ const finalHeader = { ...header, size, compressedSize, crc32: checksum };
3304
+ yield* emit(encodeZipDescriptor(finalHeader));
3305
+ const centralHeader = encodeZipCentralHeader2(finalHeader);
3306
+ directoryBytes += centralHeader.length;
3307
+ if (directoryBytes > settings.maxDirectoryBytes)
3308
+ throw new RangeError("ZIP directory byte limit exceeded");
3309
+ directory.push(centralHeader);
3310
+ }
3311
+ const directoryOffset = outputBytes;
3312
+ const zip64 = usedZip64 || settings.zip64 === "auto" && (paths.length >= 65535 || directoryBytes >= 4294967295 || directoryOffset >= 0xffffffffn);
3313
+ const footer = encodeZipEndRecords2(BigInt(paths.length), BigInt(directoryBytes), directoryOffset, zip64, comment);
3314
+ for (const header of directory)
3315
+ yield* emit(header);
3316
+ yield* emit(footer);
3317
+ }
3318
+ function validateSettings(settings) {
3319
+ if (settings.compression !== "store" && settings.compression !== "deflate")
3320
+ throw new TypeError("Unsupported ZIP compression");
3321
+ if (!["auto", "always", "never"].includes(settings.zip64))
3322
+ throw new TypeError("Invalid ZIP64 policy");
3323
+ for (const [name, value] of Object.entries(settings)) {
3324
+ if (name === "compression" || name === "zip64")
3325
+ continue;
3326
+ const bigintLimit = name === "maxArchiveBytes" || name === "maxEntryBytes";
3327
+ if (bigintLimit ? typeof value !== "bigint" || value < 0n : typeof value !== "number" || !Number.isSafeInteger(value) || value < 1)
3328
+ throw new RangeError(`Invalid ZIP ${name} limit`);
3329
+ }
3330
+ }
3331
+ function getSourceSize(source) {
3332
+ if (source instanceof ArrayBuffer || ArrayBuffer.isView(source))
3333
+ return BigInt(source.byteLength);
3334
+ if (source instanceof Blob)
3335
+ return BigInt(Object.getOwnPropertyDescriptor(Blob.prototype, "size").get.call(source));
3336
+ if (!source || typeof source !== "object" || !(source instanceof ReadableStream) && !(Symbol.asyncIterator in source) && !(Symbol.iterator in source))
3337
+ throw new TypeError("ZIP source must be bytes, a Blob or a byte stream");
3338
+ return void 0;
3339
+ }
3340
+ async function* readSource(source, chunkBytes, signal) {
3341
+ if (source instanceof Blob) {
3342
+ const size = Number(getSourceSize(source));
3343
+ for (let offset = 0; offset < size; offset += chunkBytes) {
3344
+ signal == null ? void 0 : signal.throwIfAborted();
3345
+ const blob = Blob.prototype.slice.call(source, offset, Math.min(size, offset + chunkBytes));
3346
+ const block = await awaitWithSignal(Blob.prototype.arrayBuffer.call(blob), signal);
3347
+ signal == null ? void 0 : signal.throwIfAborted();
3348
+ if (block.byteLength !== Math.min(chunkBytes, size - offset))
3349
+ throw new TypeError("ZIP Blob returned a truncated block");
3350
+ yield block;
3351
+ }
3352
+ return;
3353
+ }
3354
+ if (source instanceof ArrayBuffer || ArrayBuffer.isView(source)) {
3355
+ yield* splitByteChunk(source, chunkBytes, signal);
3356
+ return;
3357
+ }
3358
+ const reader = source instanceof ReadableStream ? source.getReader() : void 0;
3359
+ const iterator = reader ? void 0 : Symbol.asyncIterator in source ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
3360
+ let done = false;
3361
+ try {
3362
+ while (!done) {
3363
+ signal == null ? void 0 : signal.throwIfAborted();
3364
+ const result = await awaitWithSignal(reader ? reader.read() : Promise.resolve(iterator.next()), signal);
3365
+ done = Boolean(result.done);
3366
+ if (!done)
3367
+ yield* splitByteChunk(result.value, chunkBytes, signal);
3368
+ }
3369
+ } finally {
3370
+ if (reader) {
3371
+ if (!done)
3372
+ void reader.cancel(signal == null ? void 0 : signal.reason).catch(() => {
3373
+ });
3374
+ reader.releaseLock();
3375
+ } else if (!done && (iterator == null ? void 0 : iterator.return)) {
3376
+ void Promise.resolve().then(() => iterator.return()).catch(() => {
3377
+ });
3378
+ }
3379
+ }
3380
+ }
3381
+ function* splitByteChunk(chunk, chunkBytes, signal) {
3382
+ if (!(chunk instanceof ArrayBuffer) && !ArrayBuffer.isView(chunk))
3383
+ throw new TypeError("ZIP stream chunks must be binary");
3384
+ const bytes = chunk instanceof ArrayBuffer ? new Uint8Array(chunk) : new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
3385
+ const length = bytes.length;
3386
+ for (let offset = 0; offset < length; offset += chunkBytes) {
3387
+ signal == null ? void 0 : signal.throwIfAborted();
3388
+ if (bytes.byteLength !== length)
3389
+ throw new TypeError("ZIP source size changed during encoding");
3390
+ yield bytes.slice(offset, offset + chunkBytes).buffer;
3391
+ }
3392
+ }
3393
+ function awaitWithSignal(promise, signal) {
3394
+ if (!signal)
3395
+ return promise;
3396
+ return new Promise((resolve2, reject) => {
3397
+ const finish = (settle) => {
3398
+ signal.removeEventListener("abort", abort);
3399
+ settle();
3400
+ };
3401
+ const abort = () => finish(() => reject(signal.reason));
3402
+ signal.addEventListener("abort", abort, { once: true });
3403
+ promise.then((value) => finish(() => resolve2(value)), (error) => finish(() => reject(error)));
3404
+ if (signal.aborted)
3405
+ abort();
3406
+ });
3407
+ }
3408
+ function encodeArchiveComment(comment) {
3409
+ if (typeof comment !== "string")
3410
+ throw new TypeError("ZIP archive comment must be a string");
3411
+ const codepoints = [...comment];
3412
+ if (codepoints.length > 65535)
3413
+ throw new RangeError("ZIP archive comment exceeds 65535 bytes");
3414
+ const alphabet = decodeZipText2(Uint8Array.from({ length: 256 }, (_, index) => index), false);
3415
+ const bytes = new Uint8Array(codepoints.length);
3416
+ codepoints.forEach((character, index) => {
3417
+ const position = alphabet.indexOf(character);
3418
+ if (position < 0)
3419
+ throw new TypeError("ZIP archive comment is not representable in CP437");
3420
+ bytes[index] = position;
3421
+ });
3422
+ return bytes;
3423
+ }
3424
+
3425
+ // dist/zip/zip-writer.js
3426
+ var VERSION3 = true ? "5.0.0-alpha.14" : "latest";
3427
+ var ZipWriter = {
3428
+ ...ZipFormat,
3429
+ version: VERSION3,
3430
+ options: { zip: { createFolders: false } },
3431
+ encode: encodeZipFiles
3432
+ };
3433
+ async function encodeZipFiles(input, options = {}) {
3434
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3435
+ (_b = (_a = options.zip) == null ? void 0 : _a.signal) == null ? void 0 : _b.throwIfAborted();
3436
+ if ("jszip" in options)
3437
+ throw new TypeError("jszip options were removed; use typed zip options");
3438
+ const files = /* @__PURE__ */ Object.create(null);
3439
+ const maximum = ((_c = options.zip) == null ? void 0 : _c.maxEntries) ?? 1e5;
3440
+ if (!Number.isSafeInteger(maximum) || maximum < 1)
3441
+ throw new RangeError("Invalid ZIP entry limit");
3442
+ let count = 0;
3443
+ const addFile2 = (path, data) => {
3444
+ if (!Object.hasOwn(files, path) && ++count > maximum)
3445
+ throw new RangeError("ZIP entry limit exceeded");
3446
+ files[path] = data;
3447
+ };
3448
+ for (const [path, data] of Object.entries(input)) {
3449
+ if (path.endsWith("/") || ((_d = options.zip) == null ? void 0 : _d.createFolders)) {
3450
+ let offset = path.indexOf("/");
3451
+ while (offset !== -1) {
3452
+ const directory = path.slice(0, offset + 1);
3453
+ if (!Object.hasOwn(input, directory))
3454
+ addFile2(directory, new Uint8Array(0));
3455
+ offset = path.indexOf("/", offset + 1);
3456
+ }
3457
+ }
3458
+ addFile2(path, typeof data === "string" ? new TextEncoder().encode(data) : data);
3459
+ }
3460
+ (_f = (_e = options.zip) == null ? void 0 : _e.onUpdate) == null ? void 0 : _f.call(_e, { percent: 0 });
3461
+ const bytes = await encodeZip(files, options.zip);
3462
+ (_h = (_g = options.zip) == null ? void 0 : _g.onUpdate) == null ? void 0 : _h.call(_g, { percent: 100 });
3463
+ return bytes;
3464
+ }
3465
+
3466
+ // dist/zip/indexed-zip-writer.js
3467
+ init_src();
3468
+ var RESOURCE_CHUNK_BYTES = 64 * 1024;
3469
+ async function encodeIndexedZip(files, options) {
3470
+ const layout = prepareArchiveLayout(files, options);
3471
+ if (layout.archiveBytes > 4294967295)
3472
+ throw new RangeError("Indexed ZIP buffer capacity exceeded; use encodeIndexedZipInBatches");
3473
+ const archive = new Uint8Array(layout.archiveBytes);
3474
+ let offset = 0;
3475
+ for await (const chunk of encodeArchiveChunks(layout)) {
3476
+ archive.set(chunk, offset);
3477
+ offset += chunk.byteLength;
3478
+ }
3479
+ return archive.buffer;
3480
+ }
3481
+ function prepareArchiveLayout(files, options) {
3482
+ const { maxArchiveBytes, indexPath, lowercasePaths = false, signal, zip64: policy = "auto", zip64Threshold = 4294967294, maxEntries = 1e5, maxDirectoryBytes = 32 * 1024 * 1024 } = options;
3483
+ if (!["auto", "always", "never"].includes(policy) || !Number.isSafeInteger(zip64Threshold) || zip64Threshold < 0 || !Number.isSafeInteger(maxEntries) || maxEntries < 1 || !Number.isSafeInteger(maxDirectoryBytes) || maxDirectoryBytes < 1)
3484
+ throw new RangeError("Invalid indexed ZIP policy or metadata limit");
3485
+ signal == null ? void 0 : signal.throwIfAborted();
3486
+ validatePath(indexPath);
3487
+ if (/^\d+$/.test(indexPath)) {
3488
+ throw new TypeError("Indexed ZIP index path must be nonnumeric to remain the final entry");
3489
+ }
3490
+ if (!Number.isSafeInteger(maxArchiveBytes) || maxArchiveBytes < 0) {
3491
+ throw new RangeError("Indexed ZIP archive byte limit must be a non-negative safe integer");
3492
+ }
3493
+ const paths = Object.keys(Object.fromEntries(Object.keys(files).sort().map((path) => [path, true])));
3494
+ if (paths.length + 1 > maxEntries)
3495
+ throw new RangeError("Indexed ZIP entry limit exceeded");
3496
+ const canonicalPaths = paths.map((path) => lowercasePaths ? path.toLowerCase() : path);
3497
+ if (new Set(canonicalPaths).size !== paths.length) {
3498
+ throw new TypeError("Indexed ZIP contains duplicate canonical paths");
3499
+ }
3500
+ const resources = paths.map((path) => {
3501
+ validatePath(path);
3502
+ if ((lowercasePaths ? path.toLowerCase() : path) === (lowercasePaths ? indexPath.toLowerCase() : indexPath)) {
3503
+ throw new TypeError("Indexed ZIP resource uses the reserved index path");
3504
+ }
3505
+ const data = files[path];
3506
+ const byteLength = data instanceof ArrayBuffer ? Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get.call(data) : Object.getOwnPropertyDescriptor(Blob.prototype, "size").get.call(data);
3507
+ return { path, data, byteLength };
3508
+ });
3509
+ const zip32Bytes = resources.reduce((total, resource) => total + 76 + 2 * resource.path.length + resource.byteLength, 22 + 76 + 2 * indexPath.length + 24 * resources.length);
3510
+ const requiresZip64 = zip32Bytes > Math.min(zip64Threshold, 4294967294) || resources.length + 1 >= 65535;
3511
+ if (policy === "never" && requiresZip64)
3512
+ throw new RangeError("Indexed ZIP requires ZIP64");
3513
+ const zip64 = policy === "always" || requiresZip64;
3514
+ const archiveBytes = zip32Bytes + (zip64 ? 48 * (resources.length + 1) + 76 : 0);
3515
+ const directoryBytes = resources.reduce((total, resource) => total + 46 + resource.path.length, 46 + indexPath.length) + (zip64 ? 28 * (resources.length + 1) : 0);
3516
+ if (directoryBytes > maxDirectoryBytes)
3517
+ throw new RangeError("Indexed ZIP directory byte limit exceeded");
3518
+ if (!Number.isSafeInteger(archiveBytes) || archiveBytes > maxArchiveBytes)
3519
+ throw new RangeError("Indexed ZIP archive exceeds the configured byte limit");
3520
+ return { resources, archiveBytes, indexPath, lowercasePaths, signal, zip64 };
3521
+ }
3522
+ async function* encodeArchiveChunks(layout) {
3523
+ const { resources, archiveBytes, indexPath, lowercasePaths, signal, zip64 } = layout;
3524
+ const entries = [];
3525
+ const centralHeaders = [];
3526
+ const hash = new MD5Hash();
3527
+ const digests = /* @__PURE__ */ new Set();
3528
+ let localHeaderOffset = 0;
3529
+ for (const resource of resources) {
3530
+ signal == null ? void 0 : signal.throwIfAborted();
3531
+ const checksum = await checksumResource(resource, signal);
3532
+ signal == null ? void 0 : signal.throwIfAborted();
3533
+ const digest = await hash.hash(new TextEncoder().encode(lowercasePaths ? resource.path.toLowerCase() : resource.path).buffer, "hex");
3534
+ if (digests.has(digest))
3535
+ throw new Error("Indexed ZIP contains duplicate MD5 hashes");
3536
+ digests.add(digest);
3537
+ const entry = new DataView(new ArrayBuffer(24));
3538
+ for (let index = 0; index < 16; index++) {
3539
+ entry.setUint8(index, Number.parseInt(digest.slice(index * 2, index * 2 + 2), 16));
3540
+ }
3541
+ entry.setBigUint64(16, BigInt(localHeaderOffset), true);
3542
+ entries.push(entry);
3543
+ signal == null ? void 0 : signal.throwIfAborted();
3544
+ assertResourceSize(resource);
3545
+ const headers = await encodeEntryHeaders(resource.path, resource.byteLength, checksum, localHeaderOffset, zip64);
3546
+ signal == null ? void 0 : signal.throwIfAborted();
3547
+ assertResourceSize(resource);
3548
+ centralHeaders.push(headers.centralHeader);
3549
+ localHeaderOffset += headers.localHeader.byteLength + resource.byteLength;
3550
+ yield headers.localHeader;
3551
+ for await (const block of readResourceBlocks(resource, signal))
3552
+ yield new Uint8Array(block);
3553
+ }
3554
+ entries.sort(compareIndexEntries);
3555
+ const indexData = new Uint8Array(24 * entries.length);
3556
+ entries.forEach((entry, index) => indexData.set(new Uint8Array(entry.buffer), index * 24));
3557
+ signal == null ? void 0 : signal.throwIfAborted();
3558
+ const indexResource = { data: indexData.buffer, byteLength: indexData.byteLength };
3559
+ const indexChecksum = await checksumResource(indexResource, signal);
3560
+ const indexHeaders = await encodeEntryHeaders(indexPath, indexData.byteLength, indexChecksum, localHeaderOffset, zip64);
3561
+ signal == null ? void 0 : signal.throwIfAborted();
3562
+ centralHeaders.push(indexHeaders.centralHeader);
3563
+ const centralDirectoryOffset = localHeaderOffset + indexHeaders.localHeader.byteLength + indexData.byteLength;
3564
+ yield indexHeaders.localHeader;
3565
+ for await (const block of readResourceBlocks(indexResource, signal))
3566
+ yield new Uint8Array(block);
3567
+ for (const centralHeader of centralHeaders) {
3568
+ signal == null ? void 0 : signal.throwIfAborted();
3569
+ yield centralHeader;
3570
+ }
3571
+ signal == null ? void 0 : signal.throwIfAborted();
3572
+ yield encodeZipEndRecords2(BigInt(resources.length + 1), BigInt(archiveBytes - (zip64 ? 98 : 22) - centralDirectoryOffset), BigInt(centralDirectoryOffset), zip64);
3573
+ signal == null ? void 0 : signal.throwIfAborted();
3574
+ }
3575
+ async function* readResourceBlocks(resource, signal) {
3576
+ signal == null ? void 0 : signal.throwIfAborted();
3577
+ assertResourceSize(resource);
3578
+ for (let offset = 0; offset < resource.byteLength; offset += RESOURCE_CHUNK_BYTES) {
3579
+ signal == null ? void 0 : signal.throwIfAborted();
3580
+ assertResourceSize(resource);
3581
+ const end = Math.min(offset + RESOURCE_CHUNK_BYTES, resource.byteLength);
3582
+ const block = resource.data instanceof ArrayBuffer ? ArrayBuffer.prototype.slice.call(resource.data, offset, end) : await Blob.prototype.arrayBuffer.call(Blob.prototype.slice.call(resource.data, offset, end));
3583
+ signal == null ? void 0 : signal.throwIfAborted();
3584
+ if (block.byteLength !== end - offset) {
3585
+ throw new TypeError("Indexed ZIP resource size changed during packaging");
3586
+ }
3587
+ yield block;
3588
+ }
3589
+ signal == null ? void 0 : signal.throwIfAborted();
3590
+ }
3591
+ function assertResourceSize(resource) {
3592
+ if (resource.data instanceof ArrayBuffer && resource.data.byteLength !== resource.byteLength) {
3593
+ throw new TypeError("Indexed ZIP resource size changed during packaging");
3594
+ }
3595
+ }
3596
+ async function checksumResource(resource, signal) {
3597
+ let checksum = 0;
3598
+ const hash = new CRC32Hash({
3599
+ crypto: {
3600
+ /** Captures the final checksum after all input blocks have been consumed. */
3601
+ onEnd: (result) => {
3602
+ checksum = Number.parseInt(result.hash, 16);
3603
+ }
3604
+ }
3605
+ });
3606
+ for await (const _block of hash.hashBatches(readResourceBlocks(resource, signal), "hex")) {
3607
+ signal == null ? void 0 : signal.throwIfAborted();
3608
+ }
3609
+ return checksum;
3610
+ }
3611
+ async function encodeEntryHeaders(path, byteLength, checksum, localHeaderOffset, zip64) {
3612
+ const entry = {
3613
+ nameBytes: new TextEncoder().encode(path),
3614
+ date: /* @__PURE__ */ new Date("1980-01-01T00:00:00Z"),
3615
+ method: 0,
3616
+ flags: 0,
3617
+ crc32: checksum,
3618
+ size: BigInt(byteLength),
3619
+ compressedSize: BigInt(byteLength),
3620
+ localHeaderOffset: BigInt(localHeaderOffset),
3621
+ zip64
3622
+ };
3623
+ return { localHeader: encodeZipLocalHeader2(entry), centralHeader: encodeZipCentralHeader2(entry) };
3624
+ }
3625
+ function compareIndexEntries(left, right) {
3626
+ for (const offset of [0, 8]) {
3627
+ const leftValue = left.getBigUint64(offset, true);
3628
+ const rightValue = right.getBigUint64(offset, true);
3629
+ if (leftValue !== rightValue)
3630
+ return leftValue < rightValue ? -1 : 1;
3631
+ }
3632
+ return 0;
3633
+ }
3634
+ function validatePath(path) {
3635
+ if (path.length > 65535 || /[^\x20-\x7e]/.test(path) || path.includes("\\") || path.split("/").some((segment) => !segment || segment === "." || segment === "..")) {
3636
+ throw new TypeError("Indexed ZIP requires canonical relative ASCII paths");
3637
+ }
3638
+ }
3639
+
3640
+ // dist/zip/lib/zip-composition.js
3641
+ init_loader_utils();
3642
+ init_src();
3643
+
3644
+ // dist/zip/zip-archive.js
3645
+ init_loader_utils();
3646
+ init_deflate_decompressor();
3647
+ init_src();
3648
+ var DEFAULT_OPTIONS3 = {
3649
+ maxArchiveBytes: 1024n ** 4n,
3650
+ maxDirectoryBytes: 32 * 1024 * 1024,
3651
+ maxEntries: 1e5,
3652
+ maxReadBytes: 1024 * 1024,
3653
+ maxCompressedBytes: 64n * 1024n * 1024n,
3654
+ maxDecodedBytes: 64n * 1024n * 1024n,
3655
+ chunkBytes: 64 * 1024
3656
+ };
3657
+ var ZipArchive2 = class _ZipArchive {
3658
+ /** Archive byte length, without losing ZIP64 precision. */
3659
+ size;
3660
+ /** Archive comment, decoded using legacy ZIP CP437. */
3661
+ comment;
3662
+ /** Shared file limits captured at open time. */
3663
+ limits;
3664
+ /** Owned random-access transport. */
3665
+ file;
3666
+ /** File lifetime, including in-flight operations. */
3667
+ controller = new AbortController();
3668
+ /** Initialization/caller cancellation combined with close. */
3669
+ signal;
3670
+ /** Validated directory boundary. */
3671
+ directory;
3672
+ /** A single directory-index promise shared by concurrent lookups. */
3673
+ directoryPromise;
3674
+ /** Local-header validation shared by repeated path reads. */
3675
+ entriesByOffset = /* @__PURE__ */ new Map();
3676
+ /** Central-validated named lookups share their local-header work. */
3677
+ entriesByPath = /* @__PURE__ */ new Map();
3678
+ /** Next local-header boundary for central-validated, nonoverlapping payloads. */
3679
+ nextOffsets = /* @__PURE__ */ new Map();
3680
+ /** Only entries issued by this archive can be used for reads. */
3681
+ issuedEntries = /* @__PURE__ */ new WeakSet();
3682
+ /** Idempotent file cleanup, including open failure. */
3683
+ closePromise;
3684
+ /** Captures the owned transport and validates independent limits. */
3685
+ constructor(file, size, options) {
3686
+ this.file = file;
3687
+ this.size = size;
3688
+ this.comment = "";
3689
+ this.limits = {
3690
+ maxArchiveBytes: options.maxArchiveBytes ?? DEFAULT_OPTIONS3.maxArchiveBytes,
3691
+ maxDirectoryBytes: options.maxDirectoryBytes ?? DEFAULT_OPTIONS3.maxDirectoryBytes,
3692
+ maxEntries: options.maxEntries ?? DEFAULT_OPTIONS3.maxEntries,
3693
+ maxReadBytes: options.maxReadBytes ?? DEFAULT_OPTIONS3.maxReadBytes,
3694
+ maxCompressedBytes: options.maxCompressedBytes ?? DEFAULT_OPTIONS3.maxCompressedBytes,
3695
+ maxDecodedBytes: options.maxDecodedBytes ?? DEFAULT_OPTIONS3.maxDecodedBytes,
3696
+ chunkBytes: options.chunkBytes ?? DEFAULT_OPTIONS3.chunkBytes
3697
+ };
3698
+ for (const [name, value] of Object.entries(this.limits)) {
3699
+ const bigintLimit = ["maxArchiveBytes", "maxCompressedBytes", "maxDecodedBytes"].includes(name);
3700
+ if (bigintLimit ? typeof value !== "bigint" || value < 0n : typeof value !== "number" || !Number.isSafeInteger(value) || value < 1)
3701
+ throw new RangeError(`Invalid ZIP ${name} limit`);
3702
+ }
3703
+ this.signal = options.signal ? AbortSignal.any([this.controller.signal, options.signal]) : this.controller.signal;
3704
+ }
3705
+ /** Initializes directory bounds without scanning entries or reading their payloads. */
3706
+ static async open(input, options = {}) {
3707
+ var _a;
3708
+ const file = normalizeZipInput2(input);
3709
+ let archive;
3710
+ try {
3711
+ const advertisedSize = file.bigsize;
3712
+ const status = advertisedSize === void 0 || advertisedSize === 0n ? await ((_a = file.stat) == null ? void 0 : _a.call(file)) : void 0;
3713
+ const reportedBigsize = (status == null ? void 0 : status.bigsize) ?? file.bigsize;
3714
+ const size = reportedBigsize !== void 0 && reportedBigsize !== 0n ? reportedBigsize : BigInt((status == null ? void 0 : status.size) || file.size);
3715
+ archive = new _ZipArchive(file, size, options);
3716
+ archive.signal.throwIfAborted();
3717
+ if (size < 22n || size > archive.limits.maxArchiveBytes)
3718
+ throw new RangeError("ZIP archive size limit or minimum header size");
3719
+ archive.directory = await archive.readDirectoryLocation();
3720
+ Object.defineProperty(archive, "comment", { value: archive.directory.comment });
3721
+ return archive;
3722
+ } catch (error) {
3723
+ if (archive)
3724
+ await archive.close();
3725
+ else
3726
+ await file.close();
3727
+ throw error;
3728
+ }
3729
+ }
3730
+ /**
3731
+ * Appends one STORE entry through validated container metadata and the native serializer.
3732
+ * Internal composition operation: callers own the writable file and discard it on write failure.
3733
+ * Existing payload offsets, central metadata and archive comments are retained.
3734
+ */
3735
+ static async appendEntry(file, path, data, options = {}) {
3736
+ const archive = await _ZipArchive.open(file, options);
3737
+ try {
3738
+ validateZipPath2(path);
3739
+ if (archive.directory.offset > BigInt(Number.MAX_SAFE_INTEGER))
3740
+ throw new RangeError("ZIP append transport offset exceeds safe integer range");
3741
+ if (await archive.getEntry(path))
3742
+ throw new Error("ZIP entry already exists");
3743
+ for await (const _entry of archive.entries()) {
3744
+ }
3745
+ const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
3746
+ if (path.endsWith("/") && bytes.length)
3747
+ throw new Error("ZIP directory payload must be empty");
3748
+ const entry = {
3749
+ nameBytes: encodeUtf8Text2(path),
3750
+ date: /* @__PURE__ */ new Date("1980-01-01T00:00:00Z"),
3751
+ flags: 2048,
3752
+ method: 0,
3753
+ crc32: 0,
3754
+ size: BigInt(bytes.length),
3755
+ compressedSize: BigInt(bytes.length),
3756
+ localHeaderOffset: archive.directory.offset,
3757
+ zip64: archive.directory.offset >= 0xffffffffn || bytes.length >= 4294967295
3758
+ };
3759
+ let local = encodeZipLocalHeader2(entry);
3760
+ let central = encodeZipCentralHeader2(entry);
3761
+ const directoryBytes = archive.directory.size + BigInt(central.length);
3762
+ const directoryOffset = archive.directory.offset + BigInt(local.length + bytes.length);
3763
+ const count = archive.directory.count + 1n;
3764
+ const comment = new Uint8Array(await archive.readExact(archive.size - BigInt(archive.comment.length), archive.comment.length));
3765
+ const footer = encodeZipEndRecords2(count, directoryBytes, directoryOffset, directoryOffset + directoryBytes > 0x7fffffffn || count >= 0xffffn, comment);
3766
+ if (count > BigInt(archive.limits.maxEntries) || directoryBytes > BigInt(archive.limits.maxDirectoryBytes) || directoryOffset + directoryBytes + BigInt(footer.length) > archive.limits.maxArchiveBytes)
3767
+ throw new RangeError("ZIP append metadata/archive limit exceeded");
3768
+ entry.crc32 = calculateZipChecksum2(bytes);
3769
+ local = encodeZipLocalHeader2(entry);
3770
+ central = encodeZipCentralHeader2(entry);
3771
+ const directory = new Uint8Array(await archive.readExact(archive.directory.offset, Number(archive.directory.size)));
3772
+ archive.signal.throwIfAborted();
3773
+ await file.truncate(Number(archive.directory.offset));
3774
+ for (const chunk of [local, bytes, directory, central, footer]) {
3775
+ archive.signal.throwIfAborted();
3776
+ await file.append(chunk);
3777
+ }
3778
+ archive.signal.throwIfAborted();
3779
+ } finally {
3780
+ await archive.close();
3781
+ }
3782
+ }
3783
+ /** Enumerates validated entries in central-directory order; metadata is indexed once. */
3784
+ async *entries() {
3785
+ for (const path of (await this.getDirectory()).keys())
3786
+ yield await this.getEntry(path);
3787
+ }
3788
+ /**
3789
+ * Reads the final central entry using at most one maximum-sized header from the directory tail.
3790
+ * Ambiguous header signatures in comments fall back to the cached directory. This supports
3791
+ * final-index discovery without scanning a large directory in the normal indexed profile.
3792
+ */
3793
+ async getLastEntry() {
3794
+ this.signal.throwIfAborted();
3795
+ if (!this.directory.count)
3796
+ return void 0;
3797
+ const length = Number(minimumBigInt2(this.directory.size, 46n + 3n * 65535n));
3798
+ const bytes = new Uint8Array(await this.readExact(this.directory.offset + this.directory.size - BigInt(length), length));
3799
+ const view = new DataView(bytes.buffer);
3800
+ const positions = [];
3801
+ for (let position = 0; position + 46 <= length; position++) {
3802
+ if (view.getUint32(position, true) !== 33639248)
3803
+ continue;
3804
+ const end = position + 46 + view.getUint16(position + 28, true) + view.getUint16(position + 30, true) + view.getUint16(position + 32, true);
3805
+ if (end === length)
3806
+ positions.push(position);
3807
+ }
3808
+ if (positions.length !== 1) {
3809
+ const headers = [...(await this.getDirectory()).values()];
3810
+ return await this.getEntry(headers[headers.length - 1].path);
3811
+ }
3812
+ const metadata2 = decodeZipHeader2(bytes.subarray(positions[0]), true);
3813
+ return await this.getValidatedEntry(metadata2.localHeaderOffset, metadata2);
3814
+ }
3815
+ /** Looks up a canonical path; returns undefined when the entry is absent. */
3816
+ async getEntry(path) {
3817
+ this.signal.throwIfAborted();
3818
+ const metadata2 = (await this.getDirectory()).get(path);
3819
+ if (!metadata2)
3820
+ return void 0;
3821
+ let promise = this.entriesByPath.get(path);
3822
+ if (!promise) {
3823
+ promise = this.getValidatedEntry(metadata2.localHeaderOffset, metadata2).catch((error) => {
3824
+ this.entriesByPath.delete(path);
3825
+ throw error;
3826
+ });
3827
+ this.entriesByPath.set(path, promise);
3828
+ }
3829
+ return await promise;
3830
+ }
3831
+ /**
3832
+ * Validates a populated local header at an index-provided offset without a directory scan.
3833
+ * Descriptor entries fall back to the shared directory because their local sizes may be zero.
3834
+ * Direct access validates local layout/bounds; central consistency requires named lookup.
3835
+ */
3836
+ async getEntryAt(localHeaderOffset) {
3837
+ this.signal.throwIfAborted();
3838
+ const existing = this.entriesByOffset.get(localHeaderOffset);
3839
+ if (existing)
3840
+ return await existing;
3841
+ const metadata2 = await this.readLocalHeader(localHeaderOffset);
3842
+ if (metadata2.header.flags & 8) {
3843
+ for (const header of (await this.getDirectory()).values())
3844
+ if (header.localHeaderOffset === localHeaderOffset)
3845
+ return await this.getEntry(header.path);
3846
+ throw new Error("Invalid ZIP archive: indexed offset missing from directory");
3847
+ }
3848
+ return await this.getValidatedEntry(localHeaderOffset, void 0, metadata2);
3849
+ }
3850
+ /** Reads one complete entry and verifies its decoded size and CRC-32. */
3851
+ async read(entryOrPath, options = {}) {
3852
+ const signal = this.getReadSignal(options);
3853
+ signal.throwIfAborted();
3854
+ const entry = await this.resolveEntry(entryOrPath);
3855
+ signal.throwIfAborted();
3856
+ this.checkEntryBudget(entry);
3857
+ if (entry.size > BigInt(Number.MAX_SAFE_INTEGER))
3858
+ throw new RangeError("ZIP allocation is not safely representable");
3859
+ const output = new Uint8Array(Number(entry.size));
3860
+ let offset = 0;
3861
+ for await (const chunk of this.readInBatches(entry, options)) {
3862
+ output.set(chunk, offset);
3863
+ offset += chunk.byteLength;
3864
+ }
3865
+ return output.buffer;
3866
+ }
3867
+ /** Streams decoded chunks with backpressure; consuming through completion verifies CRC-32. */
3868
+ async *readInBatches(entryOrPath, options = {}) {
3869
+ const signal = this.getReadSignal(options);
3870
+ signal.throwIfAborted();
3871
+ const entry = await this.resolveEntry(entryOrPath);
3872
+ signal.throwIfAborted();
3873
+ this.checkEntryBudget(entry);
3874
+ let decodedBytes = 0n;
3875
+ let checksum = 0;
3876
+ const hash = new CRC32Hash({
3877
+ crypto: {
3878
+ onEnd: (result) => {
3879
+ checksum = Number.parseInt(result.hash, 16);
3880
+ }
3881
+ }
3882
+ });
3883
+ const compressed = this.readPayloadChunks(entry, signal);
3884
+ const decoded = entry.compression === "store" ? compressed : new DeflateDecompressor({ raw: true }).decompressBatches(compressed);
3885
+ for await (const chunk of hash.hashBatches(decoded, "hex")) {
3886
+ signal.throwIfAborted();
3887
+ decodedBytes += BigInt(chunk.byteLength);
3888
+ if (decodedBytes > entry.size || decodedBytes > this.limits.maxDecodedBytes)
3889
+ throw new RangeError("ZIP decoded entry size limit exceeded");
3890
+ yield new Uint8Array(chunk);
3891
+ }
3892
+ signal.throwIfAborted();
3893
+ if (decodedBytes !== entry.size)
3894
+ throw new Error("Invalid ZIP archive: decoded size mismatch");
3895
+ if (checksum !== entry.crc32)
3896
+ throw new Error("Invalid ZIP archive: CRC-32 mismatch");
3897
+ }
3898
+ /** Reads only a STORE byte range. Partial reads cannot verify a whole-entry CRC. */
3899
+ async readRange(entryOrPath, options) {
3900
+ const signal = this.getReadSignal(options);
3901
+ signal.throwIfAborted();
3902
+ const entry = await this.resolveEntry(entryOrPath);
3903
+ if (entry.compression !== "store")
3904
+ throw new Error("ZIP ranges require STORE entries");
3905
+ if (options.start < 0n || options.end < options.start || options.end > entry.size || options.end - options.start > BigInt(this.limits.maxReadBytes))
3906
+ throw new RangeError("ZIP byte-range limit exceeded");
3907
+ return await this.readExact(entry.dataOffset + options.start, Number(options.end - options.start), signal);
3908
+ }
3909
+ /** Cancels reads and closes the owned transport exactly once; all subsequent reads reject. */
3910
+ close() {
3911
+ this.controller.abort(new Error("ZIP archive is closed"));
3912
+ this.closePromise ||= this.file.close();
3913
+ return this.closePromise;
3914
+ }
3915
+ /** Resolves a named entry or rejects metadata not issued by this archive. */
3916
+ async resolveEntry(entryOrPath) {
3917
+ this.signal.throwIfAborted();
3918
+ const entry = typeof entryOrPath === "string" ? await this.getEntry(entryOrPath) : entryOrPath;
3919
+ if (!entry || !this.issuedEntries.has(entry))
3920
+ throw new Error("ZIP entry not found or belongs to another archive");
3921
+ return entry;
3922
+ }
3923
+ /** Combines per-read cancellation with the owned lifetime. */
3924
+ getReadSignal(options) {
3925
+ return options.signal ? AbortSignal.any([this.signal, options.signal]) : this.signal;
3926
+ }
3927
+ /** Checks whole-entry consumption before allocation or decompression. */
3928
+ checkEntryBudget(entry) {
3929
+ if (entry.size > this.limits.maxDecodedBytes || entry.compressedSize > this.limits.maxCompressedBytes)
3930
+ throw new RangeError("ZIP entry compressed/decoded byte limit exceeded");
3931
+ }
3932
+ /** Yields compressed bytes without retaining a complete entry. */
3933
+ async *readPayloadChunks(entry, signal) {
3934
+ const chunkBytes = Math.min(this.limits.chunkBytes, this.limits.maxReadBytes);
3935
+ for (let offset = 0n; offset < entry.compressedSize; offset += BigInt(chunkBytes)) {
3936
+ const length = Number(minimumBigInt2(BigInt(chunkBytes), entry.compressedSize - offset));
3937
+ yield await this.readExact(entry.dataOffset + offset, length, signal);
3938
+ }
3939
+ }
3940
+ /** Performs exact, bounded physical reads and rejects truncated transports. */
3941
+ async readExact(offset, length, signal = this.signal) {
3942
+ signal.throwIfAborted();
3943
+ if (offset < 0n || !Number.isSafeInteger(length) || length < 0 || offset + BigInt(length) > this.size)
3944
+ throw new Error("Invalid ZIP archive: read outside file");
3945
+ const output = new Uint8Array(length);
3946
+ for (let copied = 0; copied < length; ) {
3947
+ const readBytes = Math.min(length - copied, this.limits.maxReadBytes);
3948
+ const bytes = await this.file.read(offset + BigInt(copied), readBytes, signal);
3949
+ signal.throwIfAborted();
3950
+ if (bytes.byteLength !== readBytes)
3951
+ throw new Error("Invalid ZIP archive: truncated file read");
3952
+ output.set(new Uint8Array(bytes), copied);
3953
+ copied += readBytes;
3954
+ }
3955
+ return output.buffer;
3956
+ }
3957
+ /** Finds an EOCD whose complete comment ends at EOF, not a signature embedded in the comment. */
3958
+ async readDirectoryLocation() {
3959
+ const magic = new DataView(await this.readExact(0n, 4)).getUint32(0, true);
3960
+ if (magic !== 67324752 && magic !== 101010256 && magic !== 101075792)
3961
+ throw new Error("Unsupported ZIP prefix or archive format");
3962
+ const tailLength = Number(minimumBigInt2(this.size, 65557n));
3963
+ const tailStart = this.size - BigInt(tailLength);
3964
+ const tail = new DataView(await this.readExact(tailStart, tailLength));
3965
+ let position = -1;
3966
+ for (let candidate = tailLength - 22; candidate >= 0; candidate--) {
3967
+ if (tail.getUint32(candidate, true) !== 101010256 || candidate + 22 + tail.getUint16(candidate + 20, true) !== tailLength)
3968
+ continue;
3969
+ if (position < 0)
3970
+ position = candidate;
3971
+ const emptyDirectoryAtEnd = tail.getUint32(candidate + 12, true) === 0 && BigInt(tail.getUint32(candidate + 16, true)) === tailStart + BigInt(candidate);
3972
+ if (tail.getUint16(candidate + 10, true) !== 0 || emptyDirectoryAtEnd || magic === 101075792) {
3973
+ position = candidate;
3974
+ break;
3975
+ }
3976
+ }
3977
+ if (position < 0)
3978
+ throw new Error("Invalid ZIP archive: end record not found");
3979
+ const disk = tail.getUint16(position + 4, true);
3980
+ const directoryDisk = tail.getUint16(position + 6, true);
3981
+ if (disk !== 0 && disk !== 65535 || directoryDisk !== 0 && directoryDisk !== 65535)
3982
+ throw new Error("Unsupported split ZIP archive");
3983
+ const onDisk = BigInt(tail.getUint16(position + 8, true));
3984
+ let count = BigInt(tail.getUint16(position + 10, true));
3985
+ let size = BigInt(tail.getUint32(position + 12, true));
3986
+ let offset = BigInt(tail.getUint32(position + 16, true));
3987
+ let footerOffset = tailStart + BigInt(position);
3988
+ let zip64 = false;
3989
+ if (footerOffset >= 20n) {
3990
+ const locator = new DataView(await this.readExact(footerOffset - 20n, 20));
3991
+ const locatorInsideDirectory = size !== 0xffffffffn && offset !== 0xffffffffn && offset + size > footerOffset - 20n;
3992
+ if (locator.getUint32(0, true) === 117853008 && !locatorInsideDirectory) {
3993
+ zip64 = true;
3994
+ if (locator.getUint32(4, true) || locator.getUint32(16, true) !== 1)
3995
+ throw new Error("Unsupported split ZIP64 archive");
3996
+ const zip64Offset = locator.getBigUint64(8, true);
3997
+ const record = new DataView(await this.readExact(zip64Offset, 56));
3998
+ 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))
3999
+ throw new Error("Invalid ZIP64 end record");
4000
+ const zip64Count = record.getBigUint64(32, true);
4001
+ const zip64Size = record.getBigUint64(40, true);
4002
+ const zip64DirectoryOffset = record.getBigUint64(48, true);
4003
+ if (onDisk !== 0xffffn && onDisk !== zip64Count || count !== 0xffffn && count !== zip64Count || size !== 0xffffffffn && size !== zip64Size || offset !== 0xffffffffn && offset !== zip64DirectoryOffset)
4004
+ throw new Error("Invalid ZIP64 legacy end values");
4005
+ count = zip64Count;
4006
+ size = zip64Size;
4007
+ offset = zip64DirectoryOffset;
4008
+ footerOffset = zip64Offset;
4009
+ } else if (size === 0xffffffffn || offset === 0xffffffffn)
4010
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
4011
+ } else if (size === 0xffffffffn || offset === 0xffffffffn)
4012
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
4013
+ if (!zip64) {
4014
+ if (disk === 65535 || directoryDisk === 65535)
4015
+ throw new Error("Invalid ZIP archive: ZIP64 locator missing");
4016
+ if (onDisk !== count)
4017
+ throw new Error("Invalid ZIP archive: inconsistent entry counts");
4018
+ }
4019
+ if (count > BigInt(this.limits.maxEntries) || size > BigInt(this.limits.maxDirectoryBytes))
4020
+ throw new RangeError("ZIP directory entry/byte limit exceeded");
4021
+ if (offset + size > footerOffset || size < count * 46n || count === 0n !== (size === 0n))
4022
+ throw new Error("Invalid ZIP archive: directory outside bounds");
4023
+ if (count && new DataView(await this.readExact(offset, 4)).getUint32(0, true) !== 33639248)
4024
+ throw new Error("Invalid ZIP archive: directory signature missing");
4025
+ const comment = decodeZipText2(new Uint8Array(tail.buffer, position + 22), false);
4026
+ return { count, size, offset, comment };
4027
+ }
4028
+ /** Indexes central metadata once, without eagerly reading every local header. */
4029
+ getDirectory() {
4030
+ this.signal.throwIfAborted();
4031
+ this.directoryPromise ||= this.readDirectory().catch((error) => {
4032
+ this.directoryPromise = void 0;
4033
+ this.nextOffsets.clear();
4034
+ throw error;
4035
+ });
4036
+ return this.directoryPromise;
4037
+ }
4038
+ /** Parses exact directory records, including comments and Unicode/ZIP64 extras. */
4039
+ async readDirectory() {
4040
+ const bytes = new Uint8Array(await this.readExact(this.directory.offset, Number(this.directory.size)));
4041
+ const view = new DataView(bytes.buffer);
4042
+ const entries = /* @__PURE__ */ new Map();
4043
+ const offsets = /* @__PURE__ */ new Set();
4044
+ let position = 0;
4045
+ for (let index = 0n; index < this.directory.count; index++) {
4046
+ if (position + 46 > bytes.byteLength)
4047
+ throw new Error("Invalid ZIP archive: truncated directory");
4048
+ const length = 46 + view.getUint16(position + 28, true) + view.getUint16(position + 30, true) + view.getUint16(position + 32, true);
4049
+ const header = decodeZipHeader2(bytes.subarray(position, position + length), true);
4050
+ if (header.localHeaderOffset + 30n > this.directory.offset)
4051
+ throw new Error("Invalid ZIP archive: local header outside data region");
4052
+ if (entries.has(header.path) || offsets.has(header.localHeaderOffset))
4053
+ throw new Error("Invalid ZIP archive: duplicate path or local-header offset");
4054
+ entries.set(header.path, header);
4055
+ offsets.add(header.localHeaderOffset);
4056
+ position += length;
4057
+ }
4058
+ const sortedOffsets = [...offsets].sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
4059
+ sortedOffsets.forEach((offset, index) => this.nextOffsets.set(offset, sortedOffsets[index + 1] ?? this.directory.offset));
4060
+ if (position !== bytes.byteLength)
4061
+ throw new Error("Invalid ZIP archive: directory length mismatch");
4062
+ return entries;
4063
+ }
4064
+ /** Reads local metadata without inspecting unrelated payloads. */
4065
+ async readLocalHeader(offset) {
4066
+ if (offset < 0n || offset + 30n > this.directory.offset)
4067
+ throw new Error("Invalid ZIP archive: local header outside data region");
4068
+ const fixed = new DataView(await this.readExact(offset, 30));
4069
+ const length = 30 + fixed.getUint16(26, true) + fixed.getUint16(28, true);
4070
+ if (offset + BigInt(length) > this.directory.offset)
4071
+ throw new Error("Invalid ZIP archive: local metadata overlaps directory");
4072
+ const bytes = new Uint8Array(length);
4073
+ bytes.set(new Uint8Array(fixed.buffer));
4074
+ bytes.set(new Uint8Array(await this.readExact(offset + 30n, length - 30)), 30);
4075
+ const header = decodeZipHeader2(bytes, false);
4076
+ return { header, dataOffset: offset + BigInt(length) };
4077
+ }
4078
+ /** Shares local validation; a later named lookup additionally verifies central metadata. */
4079
+ async getValidatedEntry(offset, central, localMetadata) {
4080
+ if (central)
4081
+ return await this.validateEntry(offset, central);
4082
+ let entry = this.entriesByOffset.get(offset);
4083
+ if (!entry) {
4084
+ entry = this.validateEntry(offset, void 0, localMetadata).catch((error) => {
4085
+ this.entriesByOffset.delete(offset);
4086
+ throw error;
4087
+ });
4088
+ this.entriesByOffset.set(offset, entry);
4089
+ }
4090
+ return await entry;
4091
+ }
4092
+ /** Validates local/central identity, payload bounds and signed or unsigned descriptors. */
4093
+ async validateEntry(offset, central, localMetadata) {
4094
+ const { header: local, dataOffset } = localMetadata ?? await this.readLocalHeader(offset);
4095
+ const metadata2 = central || local;
4096
+ const descriptor = Boolean(local.flags & 8);
4097
+ 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)))
4098
+ throw new Error("Invalid ZIP archive: local/central metadata mismatch");
4099
+ if (metadata2.method === 0 && metadata2.size !== metadata2.compressedSize)
4100
+ throw new Error("Invalid ZIP archive: STORE sizes mismatch");
4101
+ if (central && descriptor && (local.crc32 !== 0 && local.crc32 !== central.crc32 || local.size !== 0n && local.size !== central.size || local.compressedSize !== 0n && local.compressedSize !== central.compressedSize))
4102
+ throw new Error("Invalid ZIP archive: descriptor local/central metadata mismatch");
4103
+ const payloadEnd = dataOffset + metadata2.compressedSize;
4104
+ const entryEnd = central ? this.nextOffsets.get(offset) ?? this.directory.offset : this.directory.offset;
4105
+ if (payloadEnd > entryEnd)
4106
+ throw new Error("Invalid ZIP archive: payload overlaps directory");
4107
+ if (descriptor)
4108
+ await this.validateDescriptor(payloadEnd, metadata2, local.zip64 || Boolean(central == null ? void 0 : central.zip64), entryEnd);
4109
+ const entry = Object.freeze({
4110
+ path: metadata2.path,
4111
+ directory: metadata2.path.endsWith("/"),
4112
+ compression: metadata2.method === 0 ? "store" : "deflate",
4113
+ size: metadata2.size,
4114
+ compressedSize: metadata2.compressedSize,
4115
+ crc32: metadata2.crc32,
4116
+ localHeaderOffset: offset,
4117
+ dataOffset,
4118
+ comment: (central == null ? void 0 : central.comment) || ""
4119
+ });
4120
+ this.issuedEntries.add(entry);
4121
+ return entry;
4122
+ }
4123
+ /** Resolves the optional descriptor signature using the expected CRC and sizes. */
4124
+ async validateDescriptor(offset, metadata2, zip64, entryEnd) {
4125
+ const length = Number(minimumBigInt2(24n, entryEnd - offset));
4126
+ const bytes = new DataView(await this.readExact(offset, length));
4127
+ for (const wide of zip64 ? [true, false] : [false, true]) {
4128
+ if (!wide && (metadata2.size > 0xffffffffn || metadata2.compressedSize > 0xffffffffn))
4129
+ continue;
4130
+ const descriptorLength = wide ? 20 : 12;
4131
+ for (const prefix of [4, 0]) {
4132
+ if (length < prefix + descriptorLength || prefix && bytes.getUint32(0, true) !== 134695760)
4133
+ continue;
4134
+ const compressed = wide ? bytes.getBigUint64(prefix + 4, true) : BigInt(bytes.getUint32(prefix + 4, true));
4135
+ const decoded = wide ? bytes.getBigUint64(prefix + 12, true) : BigInt(bytes.getUint32(prefix + 8, true));
4136
+ if (bytes.getUint32(prefix, true) === metadata2.crc32 && compressed === metadata2.compressedSize && decoded === metadata2.size)
4137
+ return;
4138
+ }
4139
+ }
4140
+ throw new Error("Invalid ZIP archive: data descriptor mismatch");
4141
+ }
4142
+ };
4143
+ async function openZipArchive2(input, options = {}) {
4144
+ return await ZipArchive2.open(input, options);
4145
+ }
4146
+ function normalizeZipInput2(input) {
4147
+ if (input instanceof ArrayBuffer)
4148
+ return new BlobFile(input);
4149
+ if (ArrayBuffer.isView(input))
4150
+ return new BlobFile(new Blob([new Uint8Array(input.buffer, input.byteOffset, input.byteLength).slice()]));
4151
+ if (input instanceof Blob)
4152
+ return new BlobFile(input);
4153
+ return input;
4154
+ }
4155
+ function minimumBigInt2(left, right) {
4156
+ return left < right ? left : right;
4157
+ }
4158
+
4159
+ // dist/zip/lib/zip-composition.js
4160
+ async function generateFileHeaders(fileName, file, offset) {
4161
+ validateZipPath2(fileName);
4162
+ const header = {
4163
+ nameBytes: encodeUtf8Text2(fileName),
4164
+ date: /* @__PURE__ */ new Date("1980-01-01T00:00:00Z"),
4165
+ flags: 2048,
4166
+ method: 0,
4167
+ crc32: Number.parseInt(await new CRC32Hash().hash(file, "hex"), 16),
4168
+ size: BigInt(file.byteLength),
4169
+ compressedSize: BigInt(file.byteLength),
4170
+ localHeaderOffset: offset,
4171
+ zip64: offset >= 0xffffffffn || file.byteLength >= 4294967295
4172
+ };
4173
+ return [
4174
+ new Uint8Array(concatenateArrayBuffers(encodeZipLocalHeader2(header), file)),
4175
+ encodeZipCentralHeader2(header)
4176
+ ];
4177
+ }
4178
+ async function addOneFile(zipUrl, file, fileName, options = {}) {
4179
+ await ZipArchive2.appendEntry(new NodeFileFacade(zipUrl, "a+"), fileName, file, options);
4180
+ }
4181
+ async function createZip(inputPath, outputPath, createAdditionalData, options = {}) {
4182
+ var _a, _b;
4183
+ const state = {
4184
+ maxArchiveBytes: options.maxArchiveBytes ?? 1024n ** 4n,
4185
+ maxEntries: options.maxEntries ?? 1e5,
4186
+ maxDirectoryBytes: options.maxDirectoryBytes ?? 32 * 1024 * 1024,
4187
+ signal: options.signal,
4188
+ directoryBytes: 0
4189
+ };
4190
+ if (typeof state.maxArchiveBytes !== "bigint" || state.maxArchiveBytes < 0n || !Number.isSafeInteger(state.maxEntries) || state.maxEntries < 1 || !Number.isSafeInteger(state.maxDirectoryBytes) || state.maxDirectoryBytes < 1)
4191
+ throw new RangeError("Invalid ZIP composition limits");
4192
+ if (state.maxArchiveBytes < 22n)
4193
+ throw new RangeError("ZIP composition archive limit exceeded");
4194
+ (_a = state.signal) == null ? void 0 : _a.throwIfAborted();
4195
+ const fileIterator = getFileIterator(inputPath);
4196
+ const resFile = new NodeFileFacade(outputPath, "w");
4197
+ const fileList = [];
4198
+ const cdArray = [];
4199
+ try {
4200
+ for await (const file of fileIterator) {
4201
+ await addFile(file, resFile, cdArray, state, fileList);
4202
+ }
4203
+ if (createAdditionalData) {
4204
+ const additionaldata = await createAdditionalData(fileList);
4205
+ await addFile(additionaldata, resFile, cdArray, state);
4206
+ }
4207
+ (_b = state.signal) == null ? void 0 : _b.throwIfAborted();
4208
+ const cdOffset = (await resFile.stat()).bigsize;
4209
+ const cd = concatenateArrayBuffers(...cdArray);
4210
+ await resFile.append(new Uint8Array(cd));
4211
+ const eoCDStart = (await resFile.stat()).bigsize;
4212
+ await resFile.append(new Uint8Array(encodeZipEndRecords2(BigInt(cdArray.length), BigInt(cd.byteLength), cdOffset, eoCDStart > 0x7fffffffn || cdArray.length >= 65535)));
4213
+ } finally {
4214
+ await resFile.close();
4215
+ }
4216
+ }
4217
+ async function addFile(file, resFile, cdArray, state, fileList) {
4218
+ var _a, _b;
4219
+ (_a = state.signal) == null ? void 0 : _a.throwIfAborted();
4220
+ const size = (await resFile.stat()).bigsize;
4221
+ fileList == null ? void 0 : fileList.push({ fileName: file.path, localHeaderOffset: size });
4222
+ const [localPart, cdHeaderPart] = await generateFileHeaders(file.path, file.file, size);
4223
+ const directoryBytes = state.directoryBytes + cdHeaderPart.byteLength;
4224
+ const directoryOffset = size + BigInt(localPart.byteLength);
4225
+ const count = cdArray.length + 1;
4226
+ const footer = encodeZipEndRecords2(BigInt(count), BigInt(directoryBytes), directoryOffset, directoryOffset + BigInt(directoryBytes) > 0x7fffffffn || count >= 65535);
4227
+ if (count > state.maxEntries || directoryBytes > state.maxDirectoryBytes || directoryOffset + BigInt(directoryBytes + footer.length) > state.maxArchiveBytes)
4228
+ throw new RangeError("ZIP composition metadata/archive limit exceeded");
4229
+ (_b = state.signal) == null ? void 0 : _b.throwIfAborted();
4230
+ await resFile.append(localPart);
4231
+ state.directoryBytes = directoryBytes;
4232
+ cdArray.push(toArrayBuffer2(cdHeaderPart));
4233
+ }
4234
+ function getFileIterator(inputPath) {
4235
+ async function* iterable() {
4236
+ const fileList = await getAllFiles(inputPath);
4237
+ for (const filePath of fileList) {
4238
+ const provider = new NodeFileFacade(path_exports.join(inputPath, filePath), "r");
4239
+ try {
4240
+ const { bigsize } = await provider.stat();
4241
+ const file = await provider.read(0, Number(bigsize));
4242
+ yield { path: filePath, file };
4243
+ } finally {
4244
+ await provider.close();
4245
+ }
4246
+ }
4247
+ }
4248
+ return iterable();
4249
+ }
4250
+ async function getAllFiles(basePath, subfolder = "", fsPassed) {
4251
+ const fs = fsPassed ? fsPassed : new NodeFileSystemFacade({});
4252
+ const files = await fs.readdir(pathJoin(basePath, subfolder));
4253
+ const arrayOfFiles = [];
4254
+ for (const file of files) {
4255
+ const fullPath = pathJoin(basePath, subfolder, file);
4256
+ if ((await fs.stat(fullPath)).isDirectory) {
4257
+ const files2 = await getAllFiles(basePath, pathJoin(subfolder, file));
4258
+ arrayOfFiles.push(...files2);
4259
+ } else {
4260
+ arrayOfFiles.push(pathJoin(subfolder, file));
4261
+ }
4262
+ }
4263
+ return arrayOfFiles;
4264
+ }
4265
+ function pathJoin(...paths) {
4266
+ const resPaths = paths.filter((val) => val.length);
4267
+ return path_exports.join(...resPaths);
4268
+ }
4269
+
4270
+ // dist/zip/filesystems/IndexedArchive.js
4271
+ init_src();
4272
+
4273
+ // dist/zip/hash-file-utility.js
4274
+ init_src();
4275
+ init_loader_utils();
4276
+ function parseHashTable(arrayBuffer) {
4277
+ if (arrayBuffer.byteLength % 24)
4278
+ throw new Error("Invalid ZIP index length");
4279
+ const dataView = new DataView(arrayBuffer);
4280
+ const hashMap = {};
4281
+ for (let i = 0; i < arrayBuffer.byteLength; i = i + 24) {
4282
+ const offset = dataView.getBigUint64(i + 16, true);
4283
+ const hash = bufferToHex(arrayBuffer, i, 16);
4284
+ if (hash in hashMap)
4285
+ throw new Error("Duplicate ZIP index hash");
4286
+ hashMap[hash] = offset;
4287
+ }
4288
+ return hashMap;
4289
+ }
4290
+ function bufferToHex(buffer, start, length) {
4291
+ return [...new Uint8Array(buffer, start, length)].map((x) => x.toString(16).padStart(2, "0")).join("");
4292
+ }
4293
+ async function composeHashFile(zipCDIterator) {
4294
+ const md5Hash = new MD5Hash();
4295
+ const textEncoder = new TextEncoder();
4296
+ const hashArray = [];
4297
+ for await (const cdHeader of zipCDIterator) {
4298
+ let filename2 = ("path" in cdHeader ? cdHeader.path : cdHeader.fileName).split("\\").join("/");
4299
+ if (filename2 !== "3dSceneLayer.json.gz") {
4300
+ filename2 = filename2.toLowerCase();
4301
+ }
4302
+ const arrayBuffer = textEncoder.encode(filename2).buffer;
4303
+ const md5 = await md5Hash.hash(arrayBuffer, "hex");
4304
+ hashArray.push(concatenateArrayBuffers(hexStringToBuffer(md5), bigintToBuffer(cdHeader.localHeaderOffset)));
4305
+ }
4306
+ const bufferArray = hashArray.sort(compareHashes);
4307
+ return concatenateArrayBuffersFromArray(bufferArray);
4308
+ }
4309
+ function compareHashes(arrA, arrB) {
4310
+ const a = new BigUint64Array(arrA);
4311
+ const b = new BigUint64Array(arrB);
4312
+ return Number(a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]);
4313
+ }
4314
+ function hexStringToBuffer(str) {
4315
+ var _a;
4316
+ const byteArray = (_a = str.match(/../g)) == null ? void 0 : _a.map((h) => parseInt(h, 16));
4317
+ return new Uint8Array(byteArray ?? new Array(16)).buffer;
4318
+ }
4319
+ function bigintToBuffer(n) {
4320
+ return new BigUint64Array([n]).buffer;
4321
+ }
4322
+
4323
+ // dist/zip/filesystems/IndexedArchive.js
4324
+ var IndexedArchive = class {
4325
+ options;
4326
+ /** Owned random-access archive source. */
4327
+ file;
4328
+ /** Optional resource URL prefix. */
4329
+ fileName;
4330
+ /** Format-provided path hashes, or a directory-derived fallback. */
4331
+ hashTable;
4332
+ /** Cancellation for metadata initialization and indexed reads. */
4333
+ controller = new AbortController();
4334
+ /** Shared lazy ZIP reader and directory cache. */
4335
+ readerPromise;
4336
+ /** Idempotent release even when no reader has been opened. */
4337
+ closePromise;
4338
+ /** Captures the source and an optional already-loaded format index. */
4339
+ constructor(file, hashTable, fileName, options = {}) {
4340
+ this.options = options;
4341
+ this.file = file;
4342
+ this.hashTable = hashTable;
4343
+ this.fileName = fileName;
4344
+ }
4345
+ /**
4346
+ * Loads a final index when present, otherwise hashes validated directory entries.
4347
+ * The format supplies the reserved name and fallback path-case policy. Returns true for an index.
4348
+ */
4349
+ async initializeIndex(indexPath, lowercasePaths = false) {
4350
+ const reader = await this.getZipArchive();
4351
+ const last = await reader.getLastEntry();
4352
+ if ((last == null ? void 0 : last.path) === indexPath) {
4353
+ this.hashTable = parseHashTable(await reader.read(last));
4354
+ return true;
4355
+ }
4356
+ const hash = new MD5Hash();
4357
+ const table = /* @__PURE__ */ Object.create(null);
4358
+ for await (const entry of reader.entries()) {
4359
+ const path = lowercasePaths ? entry.path.toLowerCase() : entry.path;
4360
+ const digest = await hash.hash(new TextEncoder().encode(path).buffer, "hex");
4361
+ if (digest in table)
4362
+ throw new Error("Duplicate ZIP index path hash");
4363
+ table[digest] = entry.localHeaderOffset;
4364
+ }
4365
+ this.hashTable = table;
4366
+ return false;
4367
+ }
4368
+ /** Closes the reader/transport exactly once and rejects subsequent resource reads. */
4369
+ async close() {
4370
+ this.controller.abort(new Error("ZIP archive is closed"));
4371
+ this.closePromise ||= this.readerPromise ? this.readerPromise.then((reader) => reader.close(), () => {
4372
+ }) : this.file.close();
4373
+ await this.closePromise;
4374
+ }
4375
+ /** Reads and verifies a complete ZIP entry, retaining direct indexed local-header access. */
4376
+ async readZipEntry(path) {
4377
+ const reader = await this.getZipArchive();
4378
+ let entry;
4379
+ if (this.hashTable) {
4380
+ const digest = await new MD5Hash().hash(new TextEncoder().encode(path).buffer, "hex");
4381
+ const offset = this.hashTable[digest];
4382
+ if (offset === void 0)
4383
+ return void 0;
4384
+ entry = await reader.getEntryAt(offset);
4385
+ if (entry.path.toLowerCase() !== path.toLowerCase())
4386
+ throw new Error("ZIP index path mismatch");
4387
+ } else
4388
+ entry = await reader.getEntry(path);
4389
+ return entry ? await reader.read(entry) : void 0;
4390
+ }
4391
+ /** Compatibility helper for adapters with no path index. */
4392
+ async getFileWithoutHash(path) {
4393
+ const data = await this.readZipEntry(path);
4394
+ if (!data)
4395
+ throw new Error(`No such file in the archive: ${path}`);
4396
+ return data;
4397
+ }
4398
+ /** Initializes container metadata once without reading unrelated payloads. */
4399
+ async getZipArchive() {
4400
+ if (this.closePromise)
4401
+ throw new Error("ZIP archive is closed");
4402
+ this.readerPromise ||= openZipArchive2(this.file, {
4403
+ ...this.options,
4404
+ signal: this.options.signal ? AbortSignal.any([this.controller.signal, this.options.signal]) : this.controller.signal
4405
+ });
4406
+ return await this.readerPromise;
4407
+ }
4408
+ };
4409
+
4410
+ // dist/zip/filesystems/zip-filesystem.js
4411
+ init_loader_utils();
4412
+ var ZipFileSystem = class {
4413
+ options;
4414
+ /** Owned random-access transport. */
4415
+ file;
4416
+ /** Optional archive name used in response URLs. */
4417
+ fileName;
4418
+ /** Optional format adapter retaining resource aliases and content-level decoding. */
4419
+ archive;
4420
+ /** Shared reader initialization, performed once when first needed. */
4421
+ readerPromise;
4422
+ /** Cancellation for opening and all reads during the filesystem lifetime. */
4423
+ controller = new AbortController();
4424
+ /** Caller cancellation combined with filesystem destruction. */
4425
+ signal;
4426
+ /** Idempotent transport release. */
4427
+ destroyPromise;
4428
+ /** Opens portable bytes, a random-access file, a format adapter, or a Node file path lazily. */
4429
+ constructor(file, options = {}) {
4430
+ this.options = options;
4431
+ this.signal = options.signal ? AbortSignal.any([this.controller.signal, options.signal]) : this.controller.signal;
4432
+ this.archive = file instanceof IndexedArchive ? file : null;
4433
+ if (typeof file === "string") {
4434
+ if (isBrowser)
4435
+ throw new Error("ZipFileSystem cannot open file paths in browser environments");
4436
+ this.fileName = file;
4437
+ this.file = new NodeFileFacade(file);
4438
+ } else if (file instanceof IndexedArchive) {
4439
+ this.file = file.file;
4440
+ this.fileName = file.fileName;
4441
+ } else if (file instanceof Blob || file instanceof ArrayBuffer) {
4442
+ this.file = new BlobFile(file);
4443
+ } else if (ArrayBuffer.isView(file)) {
4444
+ this.file = new BlobFile(Uint8Array.from(new Uint8Array(file.buffer, file.byteOffset, file.byteLength)).buffer);
4445
+ } else {
4446
+ this.file = file;
4447
+ }
4448
+ }
4449
+ /** Cancels pending reads and closes the owned file once; later operations reject. */
4450
+ destroy() {
4451
+ this.controller.abort(new Error("ZIP filesystem is closed"));
4452
+ this.destroyPromise ||= this.archive ? this.archive.close() : this.readerPromise ? this.readerPromise.then((reader) => reader.close(), () => {
4453
+ }) : this.file.close();
4454
+ return this.destroyPromise;
4455
+ }
4456
+ /** Lists validated archive paths in central-directory order, including directory entries. */
4457
+ async readdir() {
4458
+ const reader = await this.getReader();
4459
+ const paths = [];
4460
+ for await (const entry of reader.entries())
4461
+ paths.push(entry.path);
4462
+ return paths;
4463
+ }
4464
+ /** Returns validated metadata; rejects sizes that cannot be represented safely as a number. */
4465
+ async stat(filename2) {
4466
+ const entry = await this.getEntry(filename2);
4467
+ if (entry.size > BigInt(Number.MAX_SAFE_INTEGER))
4468
+ throw new RangeError("ZIP FileSystem size is not safely representable");
4469
+ return { ...entry, size: Number(entry.size), uncompressedSize: entry.size };
4470
+ }
4471
+ /**
4472
+ * Fetches a confined resource. Complete streams verify CRC when consumed through completion.
4473
+ * Single STORE ranges return 206 or 416; compressed and format-decoded ranges reject.
4474
+ */
4475
+ async fetch(filename2, options = {}) {
4476
+ var _a, _b, _c, _d;
4477
+ this.signal.throwIfAborted();
4478
+ (_a = options.signal) == null ? void 0 : _a.throwIfAborted();
4479
+ if (options.method && options.method.toUpperCase() !== "GET")
4480
+ throw new Error("ZIP filesystem only supports GET");
4481
+ let path;
4482
+ const range = new Headers(options.headers).get("range");
4483
+ let response;
4484
+ if (this.archive) {
4485
+ path = this.resolveResourcePath(filename2);
4486
+ if (range !== null)
4487
+ throw new Error("ZIP ranges are unavailable through format resource adapters");
4488
+ response = new Response(await this.archive.getFile(path, "http"));
4489
+ this.signal.throwIfAborted();
4490
+ (_b = options.signal) == null ? void 0 : _b.throwIfAborted();
4491
+ } else {
4492
+ const reader = await this.getReader();
4493
+ (_c = options.signal) == null ? void 0 : _c.throwIfAborted();
4494
+ const entry = await this.getEntry(filename2);
4495
+ (_d = options.signal) == null ? void 0 : _d.throwIfAborted();
4496
+ path = entry.path;
4497
+ const headers = new Headers({
4498
+ "Accept-Ranges": entry.compression === "store" ? "bytes" : "none",
4499
+ "Content-Length": String(entry.size)
4500
+ });
4501
+ if (range !== null) {
4502
+ if (entry.compression !== "store")
4503
+ throw new Error("ZIP ranges require STORE entries");
4504
+ const bounds = parseByteRange(range, entry.size);
4505
+ if (!bounds) {
4506
+ headers.set("Content-Range", `bytes */${entry.size}`);
4507
+ headers.set("Content-Length", "0");
4508
+ response = new Response(null, { status: 416, headers });
4509
+ } else {
4510
+ const bytes = await reader.readRange(entry, {
4511
+ ...bounds,
4512
+ signal: options.signal || void 0
4513
+ });
4514
+ headers.set("Content-Range", `bytes ${bounds.start}-${bounds.end - 1n}/${entry.size}`);
4515
+ headers.set("Content-Length", String(bounds.end - bounds.start));
4516
+ response = new Response(bytes, { status: 206, headers });
4517
+ }
4518
+ } else {
4519
+ const iterator = reader.readInBatches(entry, { signal: options.signal || void 0 })[Symbol.asyncIterator]();
4520
+ const stream = new ReadableStream({
4521
+ async pull(controller) {
4522
+ try {
4523
+ const chunk = await iterator.next();
4524
+ if (chunk.done)
4525
+ controller.close();
4526
+ else
4527
+ controller.enqueue(chunk.value);
4528
+ } catch (error) {
4529
+ controller.error(error);
4530
+ }
4531
+ },
4532
+ async cancel() {
4533
+ var _a2;
4534
+ await ((_a2 = iterator.return) == null ? void 0 : _a2.call(iterator));
4535
+ }
4536
+ }, { highWaterMark: 0 });
4537
+ response = new Response(stream, { headers });
4538
+ }
4539
+ }
4540
+ Object.defineProperty(response, "url", {
4541
+ value: this.getResourceUrl(path)
4542
+ });
4543
+ return response;
4544
+ }
4545
+ /** Resolves resources once, allowing parents inside the archive but rejecting root escapes. */
4546
+ resolveResourcePath(filename2, decodeUri = false) {
4547
+ var _a;
4548
+ const archivePath = filename2.startsWith("./") ? filename2.slice(2) : filename2;
4549
+ const archiveName = (_a = this.fileName) == null ? void 0 : _a.replace(/^\.\//, "");
4550
+ if (archiveName && (archivePath === archiveName || archivePath.startsWith(`${archiveName}/`))) {
4551
+ filename2 = archivePath.slice(archiveName.length).replace(/^\//, "");
4552
+ decodeUri = true;
4553
+ }
4554
+ decodeUri ||= filename2.startsWith("/") || filename2.startsWith("./");
4555
+ if (/^[a-z][a-z\d+.-]*:/i.test(filename2) || filename2.startsWith("//"))
4556
+ throw new Error("ZIP resource must stay inside the archive");
4557
+ const decoded = decodeUri ? decodeURIComponent(filename2.split(/[?#]/, 1)[0]) : filename2;
4558
+ if (decoded.includes("\\") || decoded.includes("\0") || decoded.startsWith("//") || /^[a-z][a-z\d+.-]*:/i.test(decoded))
4559
+ throw new Error("ZIP resource must stay inside the archive");
4560
+ const segments = [];
4561
+ for (const segment of decoded.split("/")) {
4562
+ if (!segment || segment === ".")
4563
+ continue;
4564
+ if (segment === "..") {
4565
+ if (!segments.length)
4566
+ throw new Error("ZIP resource escapes the archive");
4567
+ segments.pop();
4568
+ } else
4569
+ segments.push(segment);
4570
+ }
4571
+ return segments.join("/") + (decoded.endsWith("/") && segments.length ? "/" : "");
4572
+ }
4573
+ /** Creates a qualified URL that cannot be confused with a canonical literal archive path. */
4574
+ getResourceUrl(path) {
4575
+ const prefix = this.fileName && !/^(?:\/|[a-z][a-z\d+.-]*:)/i.test(this.fileName) ? `./${this.fileName.replace(/^\.\//, "")}` : this.fileName || "";
4576
+ return `${prefix}/${path.split("/").map(encodeURIComponent).join("/")}`;
4577
+ }
4578
+ /** Shares the directory cache and lifetime with every filesystem lookup. */
4579
+ async getReader() {
4580
+ this.signal.throwIfAborted();
4581
+ if (this.archive)
4582
+ return await this.archive.getZipArchive();
4583
+ this.readerPromise ||= openZipArchive2(this.file, {
4584
+ ...this.options,
4585
+ signal: this.signal
4586
+ });
4587
+ return await this.readerPromise;
4588
+ }
4589
+ /** Resolves one validated entry and reports absent resources explicitly. */
4590
+ async getEntry(path) {
4591
+ const reader = await this.getReader();
4592
+ const entry = await reader.getEntry(path) || await reader.getEntry(this.resolveResourcePath(path, true));
4593
+ if (!entry)
4594
+ throw new Error(`File has not been found in the zip archive: ${path}`);
4595
+ return entry;
4596
+ }
4597
+ };
4598
+ function parseByteRange(value, size) {
4599
+ const match = /^bytes=(\d*)-(\d*)$/i.exec(value.trim());
4600
+ if (!match || !match[1] && !match[2] || size === 0n)
4601
+ return void 0;
4602
+ if (!match[1]) {
4603
+ const suffix = BigInt(match[2]);
4604
+ if (!suffix)
4605
+ return void 0;
4606
+ return { start: suffix < size ? size - suffix : 0n, end: size };
4607
+ }
4608
+ const start = BigInt(match[1]);
4609
+ const last = match[2] ? BigInt(match[2]) : size - 1n;
4610
+ if (start >= size || last < start)
4611
+ return void 0;
4612
+ return { start, end: last < size ? last + 1n : size };
4613
+ }
4614
+ //# sourceMappingURL=index.cjs.map