module-develop-kit 1.1.0 → 1.2.1

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 (45) hide show
  1. package/dist/commonjs-virtual-dir/browser.js +5 -2
  2. package/dist/commonjs-virtual-dir/browser2.js +4 -0
  3. package/dist/commonjs-virtual-dir/index2.js +5 -3
  4. package/dist/commonjs-virtual-dir/index3.js +3 -5
  5. package/dist/commonjs-virtual-dir/index4.js +2 -4
  6. package/dist/commonjs-virtual-dir/index5.js +2 -2
  7. package/dist/commonjs-virtual-dir/index6.js +2 -2
  8. package/dist/commonjs-virtual-dir/index7.js +4 -0
  9. package/dist/commonjs-virtual-dir/index8.js +4 -0
  10. package/dist/main.d.ts +140 -29
  11. package/dist/main.js +34 -22
  12. package/dist/src/outside-call/utils.js +1 -1
  13. package/dist/src/shield/crypto/sm4.js +1 -1
  14. package/dist/src/shield/file-detection.js +143 -0
  15. package/dist/vendor/@borewit/text-codec/lib/index.js +181 -0
  16. package/dist/vendor/@tokenizer/inflate/lib/GzipHandler.js +21 -0
  17. package/dist/vendor/@tokenizer/inflate/lib/ZipHandler.js +156 -0
  18. package/dist/vendor/@tokenizer/inflate/lib/ZipToken.js +71 -0
  19. package/dist/vendor/base64-js/index.js +1 -1
  20. package/dist/vendor/debug/src/browser.js +1 -1
  21. package/dist/vendor/file-type/source/detectors/asf.js +74 -0
  22. package/dist/vendor/file-type/source/detectors/ebml.js +61 -0
  23. package/dist/vendor/file-type/source/detectors/png.js +64 -0
  24. package/dist/vendor/file-type/source/detectors/zip.js +344 -0
  25. package/dist/vendor/file-type/source/index.js +1135 -0
  26. package/dist/vendor/file-type/source/parser.js +49 -0
  27. package/dist/vendor/file-type/source/supported.js +372 -0
  28. package/dist/vendor/file-type/source/tokens.js +40 -0
  29. package/dist/vendor/ieee754/index.js +30 -0
  30. package/dist/vendor/jsbn/index.js +1 -1
  31. package/dist/vendor/sdp-transform/lib/index.js +1 -1
  32. package/dist/vendor/strtok3/lib/AbstractTokenizer.js +92 -0
  33. package/dist/vendor/strtok3/lib/BlobTokenizer.js +48 -0
  34. package/dist/vendor/strtok3/lib/BufferTokenizer.js +47 -0
  35. package/dist/vendor/strtok3/lib/ReadStreamTokenizer.js +91 -0
  36. package/dist/vendor/strtok3/lib/core.js +22 -0
  37. package/dist/vendor/strtok3/lib/stream/AbstractStreamReader.js +51 -0
  38. package/dist/vendor/strtok3/lib/stream/Errors.js +16 -0
  39. package/dist/vendor/strtok3/lib/stream/WebStreamByobReader.js +18 -0
  40. package/dist/vendor/strtok3/lib/stream/WebStreamDefaultReader.js +45 -0
  41. package/dist/vendor/strtok3/lib/stream/WebStreamReader.js +15 -0
  42. package/dist/vendor/strtok3/lib/stream/WebStreamReaderFactory.js +15 -0
  43. package/dist/vendor/token-types/lib/index.js +81 -0
  44. package/dist/vendor/uint8array-extras/index.js +45 -0
  45. package/package.json +2 -1
@@ -0,0 +1,1135 @@
1
+ import { UINT32_BE as T, UINT16_BE as p, StringType as S, UINT16_LE as g, UINT32_LE as C } from "../../token-types/lib/index.js";
2
+ import { fromWebStream as z, fromBuffer as I, fromBlob as M } from "../../strtok3/lib/core.js";
3
+ import "../../@tokenizer/inflate/lib/ZipHandler.js";
4
+ import { GzipHandler as O } from "../../@tokenizer/inflate/lib/GzipHandler.js";
5
+ import { concatUint8Arrays as P } from "../../uint8array-extras/index.js";
6
+ import { stringToBytes as j, uint32SyncSafeToken as R, tarHeaderChecksumMatches as L } from "./tokens.js";
7
+ import { mimeTypes as N, extensions as U } from "./supported.js";
8
+ import { ParserHardLimitError as q, hasUnknownFileSize as l, checkBytes as h, safeIgnore as F, maximumUntrustedSkipSizeInBytes as b } from "./parser.js";
9
+ import { detectZip as G } from "./detectors/zip.js";
10
+ import { detectEbml as _ } from "./detectors/ebml.js";
11
+ import { detectPng as H } from "./detectors/png.js";
12
+ import { detectAsf as V } from "./detectors/asf.js";
13
+ import { EndOfStreamError as d } from "../../strtok3/lib/stream/Errors.js";
14
+ const k = 4100, W = k - 2, $ = b, K = 1, A = 100, w = b, X = 512, v = 256, Z = 1024 * 1024, B = b;
15
+ function J(n) {
16
+ return Number.isFinite(n) ? Math.max(1, Math.trunc(n)) : k;
17
+ }
18
+ function Q(n) {
19
+ return Number.isFinite(n) ? Math.max(0, Math.min(W, Math.trunc(n))) : 0;
20
+ }
21
+ function Y(n) {
22
+ return Number.isFinite(n) ? Math.max(0, n) : Number.MAX_SAFE_INTEGER;
23
+ }
24
+ function D(n) {
25
+ return import(n);
26
+ }
27
+ function ee(n) {
28
+ return n.pipeThrough(new TransformStream());
29
+ }
30
+ function E(n, e) {
31
+ return e === void 0 ? n.read() : (e.throwIfAborted(), Promise.race([
32
+ n.read(),
33
+ new Promise((t, i) => {
34
+ e.addEventListener("abort", () => {
35
+ i(e.reason), n.cancel(e.reason).catch(() => {
36
+ });
37
+ }, { once: !0 });
38
+ })
39
+ ]));
40
+ }
41
+ function te(n, e) {
42
+ const t = n.getReader();
43
+ let i = 0, r = !1, s = !1;
44
+ const c = async (x) => {
45
+ r || s || (s = !0, await t.cancel(x));
46
+ };
47
+ return new ReadableStream({
48
+ async pull(x) {
49
+ if (i >= e) {
50
+ x.close(), await c();
51
+ return;
52
+ }
53
+ const { done: f, value: a } = await t.read();
54
+ if (f || !a) {
55
+ r = !0, x.close();
56
+ return;
57
+ }
58
+ const u = e - i;
59
+ if (a.length > u) {
60
+ x.enqueue(a.subarray(0, u)), i += u, x.close(), await c();
61
+ return;
62
+ }
63
+ x.enqueue(a), i += a.length;
64
+ },
65
+ async cancel(x) {
66
+ await c(x);
67
+ }
68
+ });
69
+ }
70
+ async function le(n, e) {
71
+ return new y(e).fromStream(n);
72
+ }
73
+ class y {
74
+ constructor(e) {
75
+ const t = Q(e?.mpegOffsetTolerance);
76
+ this.options = {
77
+ ...e,
78
+ mpegOffsetTolerance: t
79
+ }, this.detectors = [
80
+ ...this.options.customDetectors ?? [],
81
+ { id: "core", detect: this.detectConfident },
82
+ { id: "core.imprecise", detect: this.detectImprecise }
83
+ ], this.tokenizerOptions = {
84
+ abortSignal: this.options.signal
85
+ }, this.gzipProbeDepth = 0;
86
+ }
87
+ getTokenizerOptions() {
88
+ return {
89
+ ...this.tokenizerOptions
90
+ };
91
+ }
92
+ createTokenizerFromWebStream(e) {
93
+ return z(ee(e), this.getTokenizerOptions());
94
+ }
95
+ async parseTokenizer(e, t = 0) {
96
+ this.detectionReentryCount = t;
97
+ const i = e.position;
98
+ for (const r of this.detectors) {
99
+ let s;
100
+ try {
101
+ s = await r.detect(e);
102
+ } catch (c) {
103
+ if (c instanceof d || c instanceof q)
104
+ return;
105
+ throw c;
106
+ }
107
+ if (s)
108
+ return s;
109
+ if (i !== e.position)
110
+ return;
111
+ }
112
+ }
113
+ async fromTokenizer(e) {
114
+ try {
115
+ return await this.parseTokenizer(e);
116
+ } finally {
117
+ await e.close();
118
+ }
119
+ }
120
+ async fromBuffer(e) {
121
+ if (!(e instanceof Uint8Array || e instanceof ArrayBuffer))
122
+ throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof e}\``);
123
+ const t = e instanceof Uint8Array ? e : new Uint8Array(e);
124
+ if (t?.length > 1)
125
+ return this.fromTokenizer(I(t, this.getTokenizerOptions()));
126
+ }
127
+ async fromBlob(e) {
128
+ this.options.signal?.throwIfAborted();
129
+ const t = M(e, this.getTokenizerOptions());
130
+ return this.fromTokenizer(t);
131
+ }
132
+ async fromStream(e) {
133
+ this.options.signal?.throwIfAborted();
134
+ const t = this.createTokenizerFromWebStream(e);
135
+ return this.fromTokenizer(t);
136
+ }
137
+ async fromFile(e) {
138
+ this.options.signal?.throwIfAborted();
139
+ const [{ default: t }, { FileTokenizer: i }] = await Promise.all([
140
+ D("node:fs/promises"),
141
+ D("strtok3")
142
+ ]), r = await t.open(e, t.constants.O_RDONLY | t.constants.O_NONBLOCK), s = await r.stat();
143
+ if (!s.isFile()) {
144
+ await r.close();
145
+ return;
146
+ }
147
+ const c = new i(r, {
148
+ ...this.getTokenizerOptions(),
149
+ fileInfo: { path: e, size: s.size }
150
+ });
151
+ return this.fromTokenizer(c);
152
+ }
153
+ async toDetectionStream(e, t) {
154
+ this.options.signal?.throwIfAborted();
155
+ const i = J(t?.sampleSize ?? k);
156
+ let r, s = !1;
157
+ const c = e.getReader(), x = [];
158
+ let f = 0;
159
+ try {
160
+ for (; f < i; ) {
161
+ const { value: m, done: o } = await E(c, this.options.signal);
162
+ if (o || !m) {
163
+ s = !0;
164
+ break;
165
+ }
166
+ x.push(m), f += m.length;
167
+ }
168
+ if (!s && f === i) {
169
+ const { value: m, done: o } = await E(c, this.options.signal);
170
+ o || !m ? s = !0 : (x.push(m), f += m.length);
171
+ }
172
+ } finally {
173
+ c.releaseLock();
174
+ }
175
+ if (f > 0) {
176
+ const m = x.length === 1 ? x[0] : P(x);
177
+ try {
178
+ r = await this.fromBuffer(m.subarray(0, i));
179
+ } catch (o) {
180
+ if (!(o instanceof d))
181
+ throw o;
182
+ r = void 0;
183
+ }
184
+ !s && r?.ext === "pages" && (r = {
185
+ ext: "zip",
186
+ mime: "application/zip"
187
+ });
188
+ }
189
+ const a = new TransformStream({
190
+ start(m) {
191
+ for (const o of x)
192
+ m.enqueue(o);
193
+ },
194
+ transform(m, o) {
195
+ o.enqueue(m);
196
+ }
197
+ }), u = e.pipeThrough(a);
198
+ return u.fileType = r, u;
199
+ }
200
+ async detectGzip(e) {
201
+ if (this.gzipProbeDepth >= K)
202
+ return {
203
+ ext: "gz",
204
+ mime: "application/gzip"
205
+ };
206
+ const t = new O(e), i = te(t.inflate(), $), r = l(e);
207
+ let s, c, x, f;
208
+ if (r) {
209
+ const a = new AbortController();
210
+ s = setTimeout(() => {
211
+ a.abort(new DOMException(`Operation timed out after ${A} ms`, "TimeoutError"));
212
+ }, A), c = this.options.signal === void 0 ? a.signal : AbortSignal.any([this.options.signal, a.signal]), x = new y({
213
+ ...this.options,
214
+ signal: c
215
+ }), x.gzipProbeDepth = this.gzipProbeDepth + 1;
216
+ } else
217
+ this.gzipProbeDepth++;
218
+ try {
219
+ f = await (x ?? this).fromStream(i);
220
+ } catch (a) {
221
+ if (a?.name === "AbortError" && c?.reason?.name !== "TimeoutError")
222
+ throw a;
223
+ } finally {
224
+ clearTimeout(s), r || this.gzipProbeDepth--;
225
+ }
226
+ return f?.ext === "tar" ? {
227
+ ext: "tar.gz",
228
+ mime: "application/gzip"
229
+ } : {
230
+ ext: "gz",
231
+ mime: "application/gzip"
232
+ };
233
+ }
234
+ check(e, t) {
235
+ return h(this.buffer, e, t);
236
+ }
237
+ checkString(e, t) {
238
+ return this.check(j(e, t?.encoding), t);
239
+ }
240
+ // Detections with a high degree of certainty in identifying the correct file type
241
+ detectConfident = async (e) => {
242
+ if (this.buffer = new Uint8Array(k), e.fileInfo.size === void 0 && (e.fileInfo.size = Number.MAX_SAFE_INTEGER), this.tokenizer = e, l(e) && (await e.peekBuffer(this.buffer, { length: 3, mayBeLess: !0 }), this.check([31, 139, 8])))
243
+ return this.detectGzip(e);
244
+ if (await e.peekBuffer(this.buffer, { length: 32, mayBeLess: !0 }), this.check([66, 77]))
245
+ return {
246
+ ext: "bmp",
247
+ mime: "image/bmp"
248
+ };
249
+ if (this.check([11, 119]))
250
+ return {
251
+ ext: "ac3",
252
+ mime: "audio/vnd.dolby.dd-raw"
253
+ };
254
+ if (this.check([120, 1]))
255
+ return {
256
+ ext: "dmg",
257
+ mime: "application/x-apple-diskimage"
258
+ };
259
+ if (this.check([77, 90]))
260
+ return {
261
+ ext: "exe",
262
+ mime: "application/x-msdownload"
263
+ };
264
+ if (this.check([37, 33]))
265
+ return await e.peekBuffer(this.buffer, { length: 24, mayBeLess: !0 }), this.checkString("PS-Adobe-", { offset: 2 }) && this.checkString(" EPSF-", { offset: 14 }) ? {
266
+ ext: "eps",
267
+ mime: "application/eps"
268
+ } : {
269
+ ext: "ps",
270
+ mime: "application/postscript"
271
+ };
272
+ if (this.check([31, 160]) || this.check([31, 157]))
273
+ return {
274
+ ext: "Z",
275
+ mime: "application/x-compress"
276
+ };
277
+ if (this.check([199, 113]))
278
+ return {
279
+ ext: "cpio",
280
+ mime: "application/x-cpio"
281
+ };
282
+ if (this.check([96, 234]))
283
+ return {
284
+ ext: "arj",
285
+ mime: "application/x-arj"
286
+ };
287
+ if (this.check([239, 187, 191]))
288
+ return this.detectionReentryCount >= v ? void 0 : (this.detectionReentryCount++, await this.tokenizer.ignore(3), this.detectConfident(e));
289
+ if (this.check([71, 73, 70]))
290
+ return {
291
+ ext: "gif",
292
+ mime: "image/gif"
293
+ };
294
+ if (this.check([73, 73, 188]))
295
+ return {
296
+ ext: "jxr",
297
+ mime: "image/vnd.ms-photo"
298
+ };
299
+ if (this.check([31, 139, 8]))
300
+ return this.detectGzip(e);
301
+ if (this.check([66, 90, 104]))
302
+ return {
303
+ ext: "bz2",
304
+ mime: "application/x-bzip2"
305
+ };
306
+ if (this.checkString("ID3")) {
307
+ await F(e, 6, {
308
+ maximumLength: 6,
309
+ reason: "ID3 header prefix"
310
+ });
311
+ const t = await e.readToken(R), i = l(e);
312
+ if (!Number.isFinite(t) || t < 0 || i && (t > w || e.position + t > w))
313
+ return;
314
+ if (e.position + t > e.fileInfo.size)
315
+ return i ? void 0 : {
316
+ ext: "mp3",
317
+ mime: "audio/mpeg"
318
+ };
319
+ try {
320
+ await F(e, t, {
321
+ maximumLength: i ? w : e.fileInfo.size,
322
+ reason: "ID3 payload"
323
+ });
324
+ } catch (r) {
325
+ if (r instanceof d)
326
+ return;
327
+ throw r;
328
+ }
329
+ return this.detectionReentryCount >= v ? void 0 : (this.detectionReentryCount++, this.parseTokenizer(e, this.detectionReentryCount));
330
+ }
331
+ if (this.checkString("MP+"))
332
+ return {
333
+ ext: "mpc",
334
+ mime: "audio/x-musepack"
335
+ };
336
+ if ((this.buffer[0] === 67 || this.buffer[0] === 70) && this.check([87, 83], { offset: 1 }))
337
+ return {
338
+ ext: "swf",
339
+ mime: "application/x-shockwave-flash"
340
+ };
341
+ if (this.check([255, 216, 255]))
342
+ return this.check([247], { offset: 3 }) ? {
343
+ ext: "jls",
344
+ mime: "image/jls"
345
+ } : {
346
+ ext: "jpg",
347
+ mime: "image/jpeg"
348
+ };
349
+ if (this.check([79, 98, 106, 1]))
350
+ return {
351
+ ext: "avro",
352
+ mime: "application/avro"
353
+ };
354
+ if (this.checkString("FLIF"))
355
+ return {
356
+ ext: "flif",
357
+ mime: "image/flif"
358
+ };
359
+ if (this.checkString("8BPS"))
360
+ return {
361
+ ext: "psd",
362
+ mime: "image/vnd.adobe.photoshop"
363
+ };
364
+ if (this.checkString("MPCK"))
365
+ return {
366
+ ext: "mpc",
367
+ mime: "audio/x-musepack"
368
+ };
369
+ if (this.checkString("FORM"))
370
+ return {
371
+ ext: "aif",
372
+ mime: "audio/aiff"
373
+ };
374
+ if (this.checkString("icns", { offset: 0 }))
375
+ return {
376
+ ext: "icns",
377
+ mime: "image/icns"
378
+ };
379
+ if (this.check([80, 75, 3, 4]))
380
+ return G(e);
381
+ if (this.checkString("OggS")) {
382
+ await e.ignore(28);
383
+ const t = new Uint8Array(8);
384
+ return await e.readBuffer(t), h(t, [79, 112, 117, 115, 72, 101, 97, 100]) ? {
385
+ ext: "opus",
386
+ mime: "audio/ogg; codecs=opus"
387
+ } : h(t, [128, 116, 104, 101, 111, 114, 97]) ? {
388
+ ext: "ogv",
389
+ mime: "video/ogg"
390
+ } : h(t, [1, 118, 105, 100, 101, 111, 0]) ? {
391
+ ext: "ogm",
392
+ mime: "video/ogg"
393
+ } : h(t, [127, 70, 76, 65, 67]) ? {
394
+ ext: "oga",
395
+ mime: "audio/ogg"
396
+ } : h(t, [83, 112, 101, 101, 120, 32, 32]) ? {
397
+ ext: "spx",
398
+ mime: "audio/ogg"
399
+ } : h(t, [1, 118, 111, 114, 98, 105, 115]) ? {
400
+ ext: "ogg",
401
+ mime: "audio/ogg"
402
+ } : {
403
+ ext: "ogx",
404
+ mime: "application/ogg"
405
+ };
406
+ }
407
+ if (this.check([80, 75]) && (this.buffer[2] === 3 || this.buffer[2] === 5 || this.buffer[2] === 7) && (this.buffer[3] === 4 || this.buffer[3] === 6 || this.buffer[3] === 8))
408
+ return {
409
+ ext: "zip",
410
+ mime: "application/zip"
411
+ };
412
+ if (this.checkString("MThd"))
413
+ return {
414
+ ext: "mid",
415
+ mime: "audio/midi"
416
+ };
417
+ if (this.checkString("wOFF") && (this.check([0, 1, 0, 0], { offset: 4 }) || this.checkString("OTTO", { offset: 4 })))
418
+ return {
419
+ ext: "woff",
420
+ mime: "font/woff"
421
+ };
422
+ if (this.checkString("wOF2") && (this.check([0, 1, 0, 0], { offset: 4 }) || this.checkString("OTTO", { offset: 4 })))
423
+ return {
424
+ ext: "woff2",
425
+ mime: "font/woff2"
426
+ };
427
+ if (this.check([212, 195, 178, 161]) || this.check([161, 178, 195, 212]))
428
+ return {
429
+ ext: "pcap",
430
+ mime: "application/vnd.tcpdump.pcap"
431
+ };
432
+ if (this.checkString("DSD "))
433
+ return {
434
+ ext: "dsf",
435
+ mime: "audio/x-dsf"
436
+ // Non-standard
437
+ };
438
+ if (this.checkString("LZIP"))
439
+ return {
440
+ ext: "lz",
441
+ mime: "application/lzip"
442
+ };
443
+ if (this.checkString("fLaC"))
444
+ return {
445
+ ext: "flac",
446
+ mime: "audio/flac"
447
+ };
448
+ if (this.check([66, 80, 71, 251]))
449
+ return {
450
+ ext: "bpg",
451
+ mime: "image/bpg"
452
+ };
453
+ if (this.checkString("wvpk"))
454
+ return {
455
+ ext: "wv",
456
+ mime: "audio/wavpack"
457
+ };
458
+ if (this.checkString("%PDF"))
459
+ return {
460
+ ext: "pdf",
461
+ mime: "application/pdf"
462
+ };
463
+ if (this.check([0, 97, 115, 109]))
464
+ return {
465
+ ext: "wasm",
466
+ mime: "application/wasm"
467
+ };
468
+ if (this.check([73, 73])) {
469
+ const t = await this.readTiffHeader(!1);
470
+ if (t)
471
+ return t;
472
+ }
473
+ if (this.check([77, 77])) {
474
+ const t = await this.readTiffHeader(!0);
475
+ if (t)
476
+ return t;
477
+ }
478
+ if (this.checkString("MAC "))
479
+ return {
480
+ ext: "ape",
481
+ mime: "audio/ape"
482
+ };
483
+ if (this.check([26, 69, 223, 163]))
484
+ return _(e);
485
+ if (this.checkString("SQLi"))
486
+ return {
487
+ ext: "sqlite",
488
+ mime: "application/x-sqlite3"
489
+ };
490
+ if (this.check([78, 69, 83, 26]))
491
+ return {
492
+ ext: "nes",
493
+ mime: "application/x-nintendo-nes-rom"
494
+ };
495
+ if (this.checkString("Cr24"))
496
+ return {
497
+ ext: "crx",
498
+ mime: "application/x-google-chrome-extension"
499
+ };
500
+ if (this.checkString("MSCF") || this.checkString("ISc("))
501
+ return {
502
+ ext: "cab",
503
+ mime: "application/vnd.ms-cab-compressed"
504
+ };
505
+ if (this.check([237, 171, 238, 219]))
506
+ return {
507
+ ext: "rpm",
508
+ mime: "application/x-rpm"
509
+ };
510
+ if (this.check([197, 208, 211, 198]))
511
+ return {
512
+ ext: "eps",
513
+ mime: "application/eps"
514
+ };
515
+ if (this.check([40, 181, 47, 253]))
516
+ return {
517
+ ext: "zst",
518
+ mime: "application/zstd"
519
+ };
520
+ if (this.check([127, 69, 76, 70]))
521
+ return {
522
+ ext: "elf",
523
+ mime: "application/x-elf"
524
+ };
525
+ if (this.check([33, 66, 68, 78]))
526
+ return {
527
+ ext: "pst",
528
+ mime: "application/vnd.ms-outlook"
529
+ };
530
+ if (this.checkString("PAR1") || this.checkString("PARE"))
531
+ return {
532
+ ext: "parquet",
533
+ mime: "application/vnd.apache.parquet"
534
+ };
535
+ if (this.checkString("ttcf"))
536
+ return {
537
+ ext: "ttc",
538
+ mime: "font/collection"
539
+ };
540
+ if (this.check([254, 237, 250, 206]) || this.check([254, 237, 250, 207]) || this.check([206, 250, 237, 254]) || this.check([207, 250, 237, 254]))
541
+ return {
542
+ ext: "macho",
543
+ mime: "application/x-mach-binary"
544
+ };
545
+ if (this.check([4, 34, 77, 24]))
546
+ return {
547
+ ext: "lz4",
548
+ mime: "application/x-lz4"
549
+ // Informal, used by freedesktop.org shared-mime-info
550
+ };
551
+ if (this.checkString("regf"))
552
+ return {
553
+ ext: "dat",
554
+ mime: "application/x-ft-windows-registry-hive"
555
+ };
556
+ if (this.checkString("$FL2") || this.checkString("$FL3"))
557
+ return {
558
+ ext: "sav",
559
+ mime: "application/x-spss-sav"
560
+ };
561
+ if (this.check([79, 84, 84, 79, 0]))
562
+ return {
563
+ ext: "otf",
564
+ mime: "font/otf"
565
+ };
566
+ if (this.checkString("#!AMR"))
567
+ return {
568
+ ext: "amr",
569
+ mime: "audio/amr"
570
+ };
571
+ if (this.checkString(String.raw`{\rtf`))
572
+ return {
573
+ ext: "rtf",
574
+ mime: "application/rtf"
575
+ };
576
+ if (this.check([70, 76, 86, 1]))
577
+ return {
578
+ ext: "flv",
579
+ mime: "video/x-flv"
580
+ };
581
+ if (this.checkString("IMPM"))
582
+ return {
583
+ ext: "it",
584
+ mime: "audio/x-it"
585
+ };
586
+ if (this.checkString("-lh0-", { offset: 2 }) || this.checkString("-lh1-", { offset: 2 }) || this.checkString("-lh2-", { offset: 2 }) || this.checkString("-lh3-", { offset: 2 }) || this.checkString("-lh4-", { offset: 2 }) || this.checkString("-lh5-", { offset: 2 }) || this.checkString("-lh6-", { offset: 2 }) || this.checkString("-lh7-", { offset: 2 }) || this.checkString("-lzs-", { offset: 2 }) || this.checkString("-lz4-", { offset: 2 }) || this.checkString("-lz5-", { offset: 2 }) || this.checkString("-lhd-", { offset: 2 }))
587
+ return {
588
+ ext: "lzh",
589
+ mime: "application/x-lzh-compressed"
590
+ };
591
+ if (this.check([0, 0, 1, 186])) {
592
+ if (this.check([33], { offset: 4, mask: [241] }))
593
+ return {
594
+ ext: "mpg",
595
+ // May also be .ps, .mpeg
596
+ mime: "video/MP1S"
597
+ };
598
+ if (this.check([68], { offset: 4, mask: [196] }))
599
+ return {
600
+ ext: "mpg",
601
+ // May also be .mpg, .m2p, .vob or .sub
602
+ mime: "video/MP2P"
603
+ };
604
+ }
605
+ if (this.checkString("ITSF"))
606
+ return {
607
+ ext: "chm",
608
+ mime: "application/vnd.ms-htmlhelp"
609
+ };
610
+ if (this.check([202, 254, 186, 190])) {
611
+ const t = T.get(this.buffer, 4), i = p.get(this.buffer, 6);
612
+ if (t > 0 && t <= 30)
613
+ return {
614
+ ext: "macho",
615
+ mime: "application/x-mach-binary"
616
+ };
617
+ if (i > 30)
618
+ return {
619
+ ext: "class",
620
+ mime: "application/java-vm"
621
+ };
622
+ }
623
+ if (this.checkString(".RMF"))
624
+ return {
625
+ ext: "rm",
626
+ mime: "application/vnd.rn-realmedia"
627
+ };
628
+ if (this.checkString("DRACO"))
629
+ return {
630
+ ext: "drc",
631
+ mime: "application/x-ft-draco"
632
+ };
633
+ if (this.check([253, 55, 122, 88, 90, 0]))
634
+ return {
635
+ ext: "xz",
636
+ mime: "application/x-xz"
637
+ };
638
+ if (this.checkString("<?xml "))
639
+ return {
640
+ ext: "xml",
641
+ mime: "application/xml"
642
+ };
643
+ if (this.check([55, 122, 188, 175, 39, 28]))
644
+ return {
645
+ ext: "7z",
646
+ mime: "application/x-7z-compressed"
647
+ };
648
+ if (this.check([82, 97, 114, 33, 26, 7]) && (this.buffer[6] === 0 || this.buffer[6] === 1))
649
+ return {
650
+ ext: "rar",
651
+ mime: "application/x-rar-compressed"
652
+ };
653
+ if (this.checkString("solid "))
654
+ return {
655
+ ext: "stl",
656
+ mime: "model/stl"
657
+ };
658
+ if (this.checkString("AC")) {
659
+ const t = new S(4, "latin1").get(this.buffer, 2);
660
+ if (new RegExp("^\\d+$", "v").test(t) && t >= 1e3 && t <= 1050)
661
+ return {
662
+ ext: "dwg",
663
+ mime: "image/vnd.dwg"
664
+ };
665
+ }
666
+ if (this.checkString("070707"))
667
+ return {
668
+ ext: "cpio",
669
+ mime: "application/x-cpio"
670
+ };
671
+ if (this.checkString("BLENDER"))
672
+ return {
673
+ ext: "blend",
674
+ mime: "application/x-blender"
675
+ };
676
+ if (this.checkString("!<arch>"))
677
+ return await e.ignore(8), await e.readToken(new S(13, "ascii")) === "debian-binary" ? {
678
+ ext: "deb",
679
+ mime: "application/x-deb"
680
+ } : {
681
+ ext: "ar",
682
+ mime: "application/x-unix-archive"
683
+ };
684
+ if (this.checkString("WEBVTT") && // One of LF, CR, tab, space, or end of file must follow "WEBVTT" per the spec (see `fixture/fixture-vtt-*.vtt` for examples). Note that `\0` is technically the null character (there is no such thing as an EOF character). However, checking for `\0` gives us the same result as checking for the end of the stream.
685
+ [`
686
+ `, "\r", " ", " ", "\0"].some((t) => this.checkString(t, { offset: 6 })))
687
+ return {
688
+ ext: "vtt",
689
+ mime: "text/vtt"
690
+ };
691
+ if (this.check([137, 80, 78, 71, 13, 10, 26, 10]))
692
+ return H(e);
693
+ if (this.check([65, 82, 82, 79, 87, 49, 0, 0]))
694
+ return {
695
+ ext: "arrow",
696
+ mime: "application/vnd.apache.arrow.file"
697
+ };
698
+ if (this.check([103, 108, 84, 70, 2, 0, 0, 0]))
699
+ return {
700
+ ext: "glb",
701
+ mime: "model/gltf-binary"
702
+ };
703
+ if (this.check([102, 114, 101, 101], { offset: 4 }) || this.check([109, 100, 97, 116], { offset: 4 }) || this.check([109, 111, 111, 118], { offset: 4 }) || this.check([119, 105, 100, 101], { offset: 4 }))
704
+ return {
705
+ ext: "mov",
706
+ mime: "video/quicktime"
707
+ };
708
+ if (this.check([73, 73, 82, 79, 8, 0, 0, 0, 24]))
709
+ return {
710
+ ext: "orf",
711
+ mime: "image/x-olympus-orf"
712
+ };
713
+ if (this.checkString("gimp xcf "))
714
+ return {
715
+ ext: "xcf",
716
+ mime: "image/x-xcf"
717
+ };
718
+ if (this.checkString("ftyp", { offset: 4 }) && (this.buffer[8] & 96) !== 0) {
719
+ const t = new S(4, "latin1").get(this.buffer, 8).replace("\0", " ").trim();
720
+ switch (t) {
721
+ case "avif":
722
+ case "avis":
723
+ return { ext: "avif", mime: "image/avif" };
724
+ case "mif1":
725
+ return { ext: "heic", mime: "image/heif" };
726
+ case "msf1":
727
+ return { ext: "heic", mime: "image/heif-sequence" };
728
+ case "heic":
729
+ case "heix":
730
+ return { ext: "heic", mime: "image/heic" };
731
+ case "hevc":
732
+ case "hevx":
733
+ return { ext: "heic", mime: "image/heic-sequence" };
734
+ case "qt":
735
+ return { ext: "mov", mime: "video/quicktime" };
736
+ case "M4V":
737
+ case "M4VH":
738
+ case "M4VP":
739
+ return { ext: "m4v", mime: "video/x-m4v" };
740
+ case "M4P":
741
+ return { ext: "m4p", mime: "video/mp4" };
742
+ case "M4B":
743
+ return { ext: "m4b", mime: "audio/mp4" };
744
+ case "M4A":
745
+ return { ext: "m4a", mime: "audio/x-m4a" };
746
+ case "F4V":
747
+ return { ext: "f4v", mime: "video/mp4" };
748
+ case "F4P":
749
+ return { ext: "f4p", mime: "video/mp4" };
750
+ case "F4A":
751
+ return { ext: "f4a", mime: "audio/mp4" };
752
+ case "F4B":
753
+ return { ext: "f4b", mime: "audio/mp4" };
754
+ case "crx":
755
+ return { ext: "cr3", mime: "image/x-canon-cr3" };
756
+ default:
757
+ return t.startsWith("3g") ? t.startsWith("3g2") ? { ext: "3g2", mime: "video/3gpp2" } : { ext: "3gp", mime: "video/3gpp" } : { ext: "mp4", mime: "video/mp4" };
758
+ }
759
+ }
760
+ if (this.checkString(`REGEDIT4\r
761
+ `))
762
+ return {
763
+ ext: "reg",
764
+ mime: "application/x-ms-regedit"
765
+ };
766
+ if (this.check([82, 73, 70, 70])) {
767
+ if (this.checkString("WEBP", { offset: 8 }))
768
+ return {
769
+ ext: "webp",
770
+ mime: "image/webp"
771
+ };
772
+ if (this.check([65, 86, 73], { offset: 8 }))
773
+ return {
774
+ ext: "avi",
775
+ mime: "video/vnd.avi"
776
+ };
777
+ if (this.check([87, 65, 86, 69], { offset: 8 }))
778
+ return {
779
+ ext: "wav",
780
+ mime: "audio/wav"
781
+ };
782
+ if (this.check([81, 76, 67, 77], { offset: 8 }))
783
+ return {
784
+ ext: "qcp",
785
+ mime: "audio/qcelp"
786
+ };
787
+ }
788
+ if (this.check([73, 73, 85, 0, 24, 0, 0, 0, 136, 231, 116, 216]))
789
+ return {
790
+ ext: "rw2",
791
+ mime: "image/x-panasonic-rw2"
792
+ };
793
+ if (this.check([48, 38, 178, 117, 142, 102, 207, 17, 166, 217]))
794
+ return V(e);
795
+ if (this.check([171, 75, 84, 88, 32, 49, 49, 187, 13, 10, 26, 10]))
796
+ return {
797
+ ext: "ktx",
798
+ mime: "image/ktx"
799
+ };
800
+ if ((this.check([126, 16, 4]) || this.check([126, 24, 4])) && this.check([48, 77, 73, 69], { offset: 4 }))
801
+ return {
802
+ ext: "mie",
803
+ mime: "application/x-mie"
804
+ };
805
+ if (this.check([39, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], { offset: 2 }))
806
+ return {
807
+ ext: "shp",
808
+ mime: "application/x-esri-shape"
809
+ };
810
+ if (this.check([255, 79, 255, 81]))
811
+ return {
812
+ ext: "j2c",
813
+ mime: "image/j2c"
814
+ };
815
+ if (this.check([0, 0, 0, 12, 106, 80, 32, 32, 13, 10, 135, 10]))
816
+ switch (await e.ignore(20), await e.readToken(new S(4, "ascii"))) {
817
+ case "jp2 ":
818
+ return {
819
+ ext: "jp2",
820
+ mime: "image/jp2"
821
+ };
822
+ case "jpx ":
823
+ return {
824
+ ext: "jpx",
825
+ mime: "image/jpx"
826
+ };
827
+ case "jpm ":
828
+ return {
829
+ ext: "jpm",
830
+ mime: "image/jpm"
831
+ };
832
+ case "mjp2":
833
+ return {
834
+ ext: "mj2",
835
+ mime: "image/mj2"
836
+ };
837
+ default:
838
+ return;
839
+ }
840
+ if (this.check([255, 10]) || this.check([0, 0, 0, 12, 74, 88, 76, 32, 13, 10, 135, 10]))
841
+ return {
842
+ ext: "jxl",
843
+ mime: "image/jxl"
844
+ };
845
+ if (this.check([254, 255]))
846
+ return this.checkString("<?xml ", { offset: 2, encoding: "utf-16be" }) ? {
847
+ ext: "xml",
848
+ mime: "application/xml"
849
+ } : void 0;
850
+ if (this.check([208, 207, 17, 224, 161, 177, 26, 225]))
851
+ return {
852
+ ext: "cfb",
853
+ mime: "application/x-cfb"
854
+ };
855
+ if (await e.peekBuffer(this.buffer, { length: Math.min(256, e.fileInfo.size), mayBeLess: !0 }), this.check([97, 99, 115, 112], { offset: 36 }))
856
+ return {
857
+ ext: "icc",
858
+ mime: "application/vnd.iccprofile"
859
+ };
860
+ if (this.checkString("**ACE", { offset: 7 }) && this.checkString("**", { offset: 12 }))
861
+ return {
862
+ ext: "ace",
863
+ mime: "application/x-ace-compressed"
864
+ };
865
+ if (this.checkString("BEGIN:")) {
866
+ if (this.checkString("VCARD", { offset: 6 }))
867
+ return {
868
+ ext: "vcf",
869
+ mime: "text/vcard"
870
+ };
871
+ if (this.checkString("VCALENDAR", { offset: 6 }))
872
+ return {
873
+ ext: "ics",
874
+ mime: "text/calendar"
875
+ };
876
+ }
877
+ if (this.checkString("FUJIFILMCCD-RAW"))
878
+ return {
879
+ ext: "raf",
880
+ mime: "image/x-fujifilm-raf"
881
+ };
882
+ if (this.checkString("Extended Module:"))
883
+ return {
884
+ ext: "xm",
885
+ mime: "audio/x-xm"
886
+ };
887
+ if (this.checkString("Creative Voice File"))
888
+ return {
889
+ ext: "voc",
890
+ mime: "audio/x-voc"
891
+ };
892
+ if (this.check([4, 0, 0, 0]) && this.buffer.length >= 16) {
893
+ const t = new DataView(this.buffer.buffer).getUint32(12, !0);
894
+ if (t > 12 && this.buffer.length >= t + 16)
895
+ try {
896
+ const i = new TextDecoder().decode(this.buffer.subarray(16, t + 16));
897
+ if (JSON.parse(i).files)
898
+ return {
899
+ ext: "asar",
900
+ mime: "application/x-asar"
901
+ };
902
+ } catch {
903
+ }
904
+ }
905
+ if (this.check([6, 14, 43, 52, 2, 5, 1, 1, 13, 1, 2, 1, 1, 2]))
906
+ return {
907
+ ext: "mxf",
908
+ mime: "application/mxf"
909
+ };
910
+ if (this.checkString("SCRM", { offset: 44 }))
911
+ return {
912
+ ext: "s3m",
913
+ mime: "audio/x-s3m"
914
+ };
915
+ if (this.check([71]) && this.check([71], { offset: 188 }))
916
+ return {
917
+ ext: "mts",
918
+ mime: "video/mp2t"
919
+ };
920
+ if (this.check([71], { offset: 4 }) && this.check([71], { offset: 196 }))
921
+ return {
922
+ ext: "mts",
923
+ mime: "video/mp2t"
924
+ };
925
+ if (this.check([66, 79, 79, 75, 77, 79, 66, 73], { offset: 60 }))
926
+ return {
927
+ ext: "mobi",
928
+ mime: "application/x-mobipocket-ebook"
929
+ };
930
+ if (this.check([68, 73, 67, 77], { offset: 128 }))
931
+ return {
932
+ ext: "dcm",
933
+ mime: "application/dicom"
934
+ };
935
+ if (this.check([76, 0, 0, 0, 1, 20, 2, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70]))
936
+ return {
937
+ ext: "lnk",
938
+ mime: "application/x-ms-shortcut"
939
+ // Informal, used by freedesktop.org shared-mime-info
940
+ };
941
+ if (this.check([98, 111, 111, 107, 0, 0, 0, 0, 109, 97, 114, 107, 0, 0, 0, 0]))
942
+ return {
943
+ ext: "alias",
944
+ mime: "application/x-ft-apple.alias"
945
+ };
946
+ if (this.checkString("Kaydara FBX Binary \0"))
947
+ return {
948
+ ext: "fbx",
949
+ mime: "application/x-ft-fbx"
950
+ };
951
+ if (this.check([76, 80], { offset: 34 }) && (this.check([0, 0, 1], { offset: 8 }) || this.check([1, 0, 2], { offset: 8 }) || this.check([2, 0, 2], { offset: 8 })))
952
+ return {
953
+ ext: "eot",
954
+ mime: "application/vnd.ms-fontobject"
955
+ };
956
+ if (this.check([6, 6, 237, 245, 216, 29, 70, 229, 189, 49, 239, 231, 254, 116, 183, 29]))
957
+ return {
958
+ ext: "indd",
959
+ mime: "application/x-indesign"
960
+ };
961
+ if (this.check([255, 255, 0, 0, 7, 0, 0, 0, 4, 0, 0, 0, 1, 0, 1, 0]) || this.check([0, 0, 255, 255, 0, 0, 0, 7, 0, 0, 0, 4, 0, 1, 0, 1]))
962
+ return {
963
+ ext: "jmp",
964
+ mime: "application/x-jmp-data"
965
+ };
966
+ if (await e.peekBuffer(this.buffer, { length: Math.min(512, e.fileInfo.size), mayBeLess: !0 }), this.checkString("ustar", { offset: 257 }) && (this.checkString("\0", { offset: 262 }) || this.checkString(" ", { offset: 262 })) || this.check([0, 0, 0, 0, 0, 0], { offset: 257 }) && L(this.buffer))
967
+ return {
968
+ ext: "tar",
969
+ mime: "application/x-tar"
970
+ };
971
+ if (this.check([255, 254])) {
972
+ const t = "utf-16le";
973
+ return this.checkString("<?xml ", { offset: 2, encoding: t }) ? {
974
+ ext: "xml",
975
+ mime: "application/xml"
976
+ } : this.check([255, 14], { offset: 2 }) && this.checkString("SketchUp Model", { offset: 4, encoding: t }) ? {
977
+ ext: "skp",
978
+ mime: "application/vnd.sketchup.skp"
979
+ } : this.checkString(`Windows Registry Editor Version 5.00\r
980
+ `, { offset: 2, encoding: t }) ? {
981
+ ext: "reg",
982
+ mime: "application/x-ms-regedit"
983
+ } : void 0;
984
+ }
985
+ if (this.checkString("-----BEGIN PGP MESSAGE-----"))
986
+ return {
987
+ ext: "pgp",
988
+ mime: "application/pgp-encrypted"
989
+ };
990
+ };
991
+ // Detections with limited supporting data, resulting in a higher likelihood of false positives
992
+ detectImprecise = async (e) => {
993
+ this.buffer = new Uint8Array(k);
994
+ const t = Y(e.fileInfo.size);
995
+ if (await e.peekBuffer(this.buffer, { length: Math.min(8, t), mayBeLess: !0 }), this.check([0, 0, 1, 186]) || this.check([0, 0, 1, 179]))
996
+ return {
997
+ ext: "mpg",
998
+ mime: "video/mpeg"
999
+ };
1000
+ if (this.check([0, 1, 0, 0, 0]))
1001
+ return {
1002
+ ext: "ttf",
1003
+ mime: "font/ttf"
1004
+ };
1005
+ if (this.check([0, 0, 1, 0]))
1006
+ return {
1007
+ ext: "ico",
1008
+ mime: "image/x-icon"
1009
+ };
1010
+ if (this.check([0, 0, 2, 0]))
1011
+ return {
1012
+ ext: "cur",
1013
+ mime: "image/x-icon"
1014
+ };
1015
+ if (await e.peekBuffer(this.buffer, { length: Math.min(2 + this.options.mpegOffsetTolerance, t), mayBeLess: !0 }), this.buffer.length >= 2 + this.options.mpegOffsetTolerance)
1016
+ for (let i = 0; i <= this.options.mpegOffsetTolerance; ++i) {
1017
+ const r = this.scanMpeg(i);
1018
+ if (r)
1019
+ return r;
1020
+ }
1021
+ };
1022
+ async readTiffTag(e) {
1023
+ const t = await this.tokenizer.readToken(e ? p : g);
1024
+ switch (await this.tokenizer.ignore(10), t) {
1025
+ case 50341:
1026
+ return {
1027
+ ext: "arw",
1028
+ mime: "image/x-sony-arw"
1029
+ };
1030
+ case 50706:
1031
+ return {
1032
+ ext: "dng",
1033
+ mime: "image/x-adobe-dng"
1034
+ };
1035
+ }
1036
+ }
1037
+ async readTiffIFD(e) {
1038
+ const t = await this.tokenizer.readToken(e ? p : g);
1039
+ if (!(t > X) && !(l(this.tokenizer) && 2 + t * 12 > B))
1040
+ for (let i = 0; i < t; ++i) {
1041
+ const r = await this.readTiffTag(e);
1042
+ if (r)
1043
+ return r;
1044
+ }
1045
+ }
1046
+ async readTiffHeader(e) {
1047
+ const t = {
1048
+ ext: "tif",
1049
+ mime: "image/tiff"
1050
+ }, i = (e ? p : g).get(this.buffer, 2), r = (e ? T : C).get(this.buffer, 4);
1051
+ if (i === 42) {
1052
+ if (r >= 6) {
1053
+ if (this.checkString("CR", { offset: 8 }))
1054
+ return {
1055
+ ext: "cr2",
1056
+ mime: "image/x-canon-cr2"
1057
+ };
1058
+ if (r >= 8) {
1059
+ const x = (e ? p : g).get(this.buffer, 8), f = (e ? p : g).get(this.buffer, 10);
1060
+ if (x === 28 && f === 254 || x === 31 && f === 11)
1061
+ return {
1062
+ ext: "nef",
1063
+ mime: "image/x-nikon-nef"
1064
+ };
1065
+ }
1066
+ }
1067
+ if (l(this.tokenizer) && r > Z)
1068
+ return t;
1069
+ const s = l(this.tokenizer) ? B : this.tokenizer.fileInfo.size;
1070
+ try {
1071
+ await F(this.tokenizer, r, {
1072
+ maximumLength: s,
1073
+ reason: "TIFF IFD offset"
1074
+ });
1075
+ } catch (x) {
1076
+ if (x instanceof d)
1077
+ return;
1078
+ throw x;
1079
+ }
1080
+ let c;
1081
+ try {
1082
+ c = await this.readTiffIFD(e);
1083
+ } catch (x) {
1084
+ if (x instanceof d)
1085
+ return;
1086
+ throw x;
1087
+ }
1088
+ return c ?? t;
1089
+ }
1090
+ if (i === 43)
1091
+ return t;
1092
+ }
1093
+ /**
1094
+ Scan check MPEG 1 or 2 Layer 3 header, or 'layer 0' for ADTS (MPEG sync-word 0xFFE).
1095
+
1096
+ @param offset - Offset to scan for sync-preamble.
1097
+ @returns {{ext: string, mime: string}}
1098
+ */
1099
+ scanMpeg(e) {
1100
+ if (this.check([255, 224], { offset: e, mask: [255, 224] })) {
1101
+ if (this.check([16], { offset: e + 1, mask: [22] }))
1102
+ return this.check([8], { offset: e + 1, mask: [8] }) ? {
1103
+ ext: "aac",
1104
+ mime: "audio/aac"
1105
+ } : {
1106
+ ext: "aac",
1107
+ mime: "audio/aac"
1108
+ };
1109
+ if (this.check([2], { offset: e + 1, mask: [6] }))
1110
+ return {
1111
+ ext: "mp3",
1112
+ mime: "audio/mpeg"
1113
+ };
1114
+ if (this.check([4], { offset: e + 1, mask: [6] }))
1115
+ return {
1116
+ ext: "mp2",
1117
+ mime: "audio/mpeg"
1118
+ };
1119
+ if (this.check([6], { offset: e + 1, mask: [6] }))
1120
+ return {
1121
+ ext: "mp1",
1122
+ mime: "audio/mpeg"
1123
+ };
1124
+ }
1125
+ }
1126
+ }
1127
+ const ge = new Set(U), de = new Set(N);
1128
+ export {
1129
+ y as FileTypeParser,
1130
+ le as fileTypeFromStream,
1131
+ J as normalizeSampleSize,
1132
+ k as reasonableDetectionSizeInBytes,
1133
+ ge as supportedExtensions,
1134
+ de as supportedMimeTypes
1135
+ };