mime-bytes 0.0.2

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.
@@ -0,0 +1,1217 @@
1
+ "use strict";
2
+ // Master registry of all supported file types with magic bytes, MIME types, and extensions
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.CONTENT_TYPE_MAPPINGS = exports.FILE_TYPES = void 0;
5
+ exports.getFileTypeByMagicBytes = getFileTypeByMagicBytes;
6
+ exports.getFileTypeByExtension = getFileTypeByExtension;
7
+ exports.getFileTypesByCategory = getFileTypesByCategory;
8
+ exports.getContentTypeByExtension = getContentTypeByExtension;
9
+ exports.detectCharset = detectCharset;
10
+ exports.getContentTypeForExtension = getContentTypeForExtension;
11
+ exports.FILE_TYPES = [
12
+ // Image Formats
13
+ {
14
+ name: "png",
15
+ magicBytes: ["0x89", "0x50", "0x4E", "0x47", "0x0D", "0x0A", "0x1A", "0x0A"],
16
+ mimeType: "image/png",
17
+ extensions: ["png", "apng"],
18
+ description: "Portable Network Graphics",
19
+ category: "image",
20
+ charset: "binary"
21
+ },
22
+ {
23
+ name: "jpeg",
24
+ magicBytes: ["0xFF", "0xD8", "0xFF"],
25
+ mimeType: "image/jpeg",
26
+ extensions: ["jpg", "jpeg", "jpe", "jif", "jfif"],
27
+ description: "JPEG image format",
28
+ category: "image"
29
+ },
30
+ {
31
+ name: "gif",
32
+ magicBytes: ["0x47", "0x49", "0x46", "0x38", "0x37", "0x61"],
33
+ mimeType: "image/gif",
34
+ extensions: ["gif"],
35
+ description: "Graphics Interchange Format (GIF87a)",
36
+ category: "image"
37
+ },
38
+ {
39
+ name: "gif89a",
40
+ magicBytes: ["0x47", "0x49", "0x46", "0x38", "0x39", "0x61"],
41
+ mimeType: "image/gif",
42
+ extensions: ["gif"],
43
+ description: "Graphics Interchange Format (GIF89a)",
44
+ category: "image"
45
+ },
46
+ {
47
+ name: "webp",
48
+ magicBytes: ["0x52", "0x49", "0x46", "0x46", "?", "?", "?", "?", "0x57", "0x45", "0x42", "0x50"],
49
+ mimeType: "image/webp",
50
+ extensions: ["webp"],
51
+ description: "WebP image format",
52
+ category: "image"
53
+ },
54
+ {
55
+ name: "qoi",
56
+ magicBytes: ["0x71", "0x6F", "0x69", "0x66"],
57
+ mimeType: "image/qoi",
58
+ extensions: ["qoi"],
59
+ description: "Quite OK Image Format",
60
+ category: "image"
61
+ },
62
+ // PCT (Apple PICT) - No reliable magic bytes, extension-based detection only
63
+ {
64
+ name: "pct",
65
+ magicBytes: [], // PCT files don't have consistent magic bytes
66
+ mimeType: "image/x-pict",
67
+ extensions: ["pct", "pic", "pict"],
68
+ description: "Apple PICT image format (legacy)",
69
+ category: "image"
70
+ },
71
+ // TGA (Truevision Targa) - No reliable magic bytes at offset 0
72
+ {
73
+ name: "tga",
74
+ magicBytes: [], // TGA files don't have magic bytes at the beginning
75
+ mimeType: "image/x-targa",
76
+ extensions: ["tga", "icb", "vda", "vst"],
77
+ description: "Truevision TGA image format",
78
+ category: "image"
79
+ },
80
+ {
81
+ name: "bmp",
82
+ magicBytes: ["0x42", "0x4D"],
83
+ mimeType: "image/bmp",
84
+ extensions: ["bmp"],
85
+ description: "Bitmap image format",
86
+ category: "image"
87
+ },
88
+ {
89
+ name: "ico",
90
+ magicBytes: ["0x00", "0x00", "0x01", "0x00"],
91
+ mimeType: "image/x-icon",
92
+ extensions: ["ico"],
93
+ description: "Icon format",
94
+ category: "image"
95
+ },
96
+ {
97
+ name: "tiff",
98
+ magicBytes: ["0x49", "0x49", "0x2A", "0x00"],
99
+ mimeType: "image/tiff",
100
+ extensions: ["tif", "tiff"],
101
+ description: "Tagged Image File Format (little-endian)",
102
+ category: "image"
103
+ },
104
+ {
105
+ name: "tiff-be",
106
+ magicBytes: ["0x4D", "0x4D", "0x00", "0x2A"],
107
+ mimeType: "image/tiff",
108
+ extensions: ["tif", "tiff"],
109
+ description: "Tagged Image File Format (big-endian)",
110
+ category: "image"
111
+ },
112
+ // Archive Formats
113
+ {
114
+ name: "zip",
115
+ magicBytes: ["0x50", "0x4B", "0x03", "0x04"],
116
+ mimeType: "application/zip",
117
+ extensions: ["zip", "aar", "apk", "docx", "epub", "ipa", "jar", "kmz", "maff", "msix", "odp", "ods", "odt", "pk3", "pk4", "pptx", "usdz", "vsdx", "xlsx", "xpi", "whl"],
118
+ description: "ZIP archive and related formats",
119
+ category: "archive"
120
+ },
121
+ {
122
+ name: "zip-empty",
123
+ magicBytes: ["0x50", "0x4B", "0x05", "0x06"],
124
+ mimeType: "application/zip",
125
+ extensions: ["zip"],
126
+ description: "Empty ZIP archive",
127
+ category: "archive"
128
+ },
129
+ {
130
+ name: "zip-spanned",
131
+ magicBytes: ["0x50", "0x4B", "0x07", "0x08"],
132
+ mimeType: "application/zip",
133
+ extensions: ["zip"],
134
+ description: "Spanned ZIP archive",
135
+ category: "archive"
136
+ },
137
+ {
138
+ name: "rar",
139
+ magicBytes: ["0x52", "0x61", "0x72", "0x21", "0x1A", "0x07", "0x00"],
140
+ mimeType: "application/x-rar-compressed",
141
+ extensions: ["rar"],
142
+ description: "RAR archive format",
143
+ category: "archive"
144
+ },
145
+ {
146
+ name: "rar5",
147
+ magicBytes: ["0x52", "0x61", "0x72", "0x21", "0x1A", "0x07", "0x01", "0x00"],
148
+ mimeType: "application/x-rar-compressed",
149
+ extensions: ["rar"],
150
+ description: "RAR5 archive format",
151
+ category: "archive"
152
+ },
153
+ {
154
+ name: "7z",
155
+ magicBytes: ["0x37", "0x7A", "0xBC", "0xAF", "0x27", "0x1C"],
156
+ mimeType: "application/x-7z-compressed",
157
+ extensions: ["7z"],
158
+ description: "7-Zip archive format",
159
+ category: "archive"
160
+ },
161
+ {
162
+ name: "tar",
163
+ magicBytes: ["0x75", "0x73", "0x74", "0x61", "0x72"],
164
+ mimeType: "application/x-tar",
165
+ extensions: ["tar"],
166
+ offset: 257,
167
+ description: "TAR archive",
168
+ category: "archive"
169
+ },
170
+ {
171
+ name: "gz",
172
+ magicBytes: ["0x1F", "0x8B"],
173
+ mimeType: "application/gzip",
174
+ extensions: ["gz", "gzip"],
175
+ description: "GZIP compressed file",
176
+ category: "archive"
177
+ },
178
+ {
179
+ name: "bz2",
180
+ magicBytes: ["0x42", "0x5A", "0x68"],
181
+ mimeType: "application/x-bzip2",
182
+ extensions: ["bz2"],
183
+ description: "BZIP2 compressed file",
184
+ category: "archive"
185
+ },
186
+ {
187
+ name: "xz",
188
+ magicBytes: ["0xFD", "0x37", "0x7A", "0x58", "0x5A", "0x00"],
189
+ mimeType: "application/x-xz",
190
+ extensions: ["xz"],
191
+ description: "XZ compressed file",
192
+ category: "archive"
193
+ },
194
+ // Document Formats
195
+ {
196
+ name: "pdf",
197
+ magicBytes: ["0x25", "0x50", "0x44", "0x46"],
198
+ mimeType: "application/pdf",
199
+ extensions: ["pdf"],
200
+ description: "Portable Document Format",
201
+ category: "document"
202
+ },
203
+ {
204
+ name: "ps",
205
+ magicBytes: ["0x25", "0x21", "0x50", "0x53"],
206
+ mimeType: "application/postscript",
207
+ extensions: ["ps"],
208
+ description: "PostScript document",
209
+ category: "document"
210
+ },
211
+ {
212
+ name: "eps",
213
+ magicBytes: ["0x25", "0x21", "0x50", "0x53", "0x2D", "0x41", "0x64", "0x6F", "0x62", "0x65"],
214
+ mimeType: "application/eps",
215
+ extensions: ["eps", "epsf"],
216
+ description: "Encapsulated PostScript",
217
+ category: "document"
218
+ },
219
+ {
220
+ name: "rtf",
221
+ magicBytes: ["0x7B", "0x5C", "0x72", "0x74", "0x66"],
222
+ mimeType: "application/rtf",
223
+ extensions: ["rtf"],
224
+ description: "Rich Text Format",
225
+ category: "document"
226
+ },
227
+ // Media Formats
228
+ {
229
+ name: "mp4",
230
+ magicBytes: ["0x66", "0x74", "0x79", "0x70"],
231
+ mimeType: "video/mp4",
232
+ extensions: ["mp4", "m4v", "m4p", "m4b", "f4v", "f4p", "f4b", "f4a"],
233
+ offset: 4,
234
+ description: "MP4 video format",
235
+ category: "video"
236
+ },
237
+ {
238
+ name: "3gp",
239
+ magicBytes: ["0x66", "0x74", "0x79", "0x70", "0x33", "0x67"],
240
+ mimeType: "video/3gpp",
241
+ extensions: ["3gp", "3g2"],
242
+ offset: 4,
243
+ description: "3GP video format",
244
+ category: "video"
245
+ },
246
+ {
247
+ name: "heic",
248
+ magicBytes: ["0x66", "0x74", "0x79", "0x70", "0x68", "0x65", "0x69", "0x63"],
249
+ mimeType: "image/heic",
250
+ extensions: ["heic"],
251
+ offset: 4,
252
+ description: "High Efficiency Image Container",
253
+ category: "image"
254
+ },
255
+ {
256
+ name: "heif",
257
+ magicBytes: ["0x66", "0x74", "0x79", "0x70", "0x6D", "0x69", "0x66", "0x31"],
258
+ mimeType: "image/heif",
259
+ extensions: ["heif"],
260
+ offset: 4,
261
+ description: "High Efficiency Image Format",
262
+ category: "image"
263
+ },
264
+ {
265
+ name: "mp3",
266
+ magicBytes: ["0x49", "0x44", "0x33"],
267
+ mimeType: "audio/mpeg",
268
+ extensions: ["mp3"],
269
+ description: "MP3 audio format",
270
+ category: "audio"
271
+ },
272
+ {
273
+ name: "mp3-sync",
274
+ magicBytes: ["0xFF", "0xFB"],
275
+ mimeType: "audio/mpeg",
276
+ extensions: ["mp3"],
277
+ description: "MP3 audio format (sync)",
278
+ category: "audio"
279
+ },
280
+ {
281
+ name: "flac",
282
+ magicBytes: ["0x66", "0x4C", "0x61", "0x43"],
283
+ mimeType: "audio/flac",
284
+ extensions: ["flac"],
285
+ description: "FLAC audio format",
286
+ category: "audio"
287
+ },
288
+ {
289
+ name: "wav",
290
+ magicBytes: ["0x52", "0x49", "0x46", "0x46", "?", "?", "?", "?", "0x57", "0x41", "0x56", "0x45"],
291
+ mimeType: "audio/wav",
292
+ extensions: ["wav"],
293
+ description: "WAV audio format",
294
+ category: "audio"
295
+ },
296
+ {
297
+ name: "ogg",
298
+ magicBytes: ["0x4F", "0x67", "0x67", "0x53"],
299
+ mimeType: "audio/ogg",
300
+ extensions: ["ogg", "oga", "ogv"],
301
+ description: "OGG container format",
302
+ category: "audio"
303
+ },
304
+ {
305
+ name: "avi",
306
+ magicBytes: ["0x52", "0x49", "0x46", "0x46", "?", "?", "?", "?", "0x41", "0x56", "0x49", "0x20"],
307
+ mimeType: "video/x-msvideo",
308
+ extensions: ["avi"],
309
+ description: "AVI video format",
310
+ category: "video"
311
+ },
312
+ {
313
+ name: "mkv",
314
+ magicBytes: ["0x1A", "0x45", "0xDF", "0xA3"],
315
+ mimeType: "video/x-matroska",
316
+ extensions: ["mkv", "mka", "mks", "mk3d", "webm"],
317
+ description: "Matroska video format",
318
+ category: "video"
319
+ },
320
+ {
321
+ name: "mov",
322
+ magicBytes: ["0x66", "0x74", "0x79", "0x70", "0x71", "0x74"],
323
+ mimeType: "video/quicktime",
324
+ extensions: ["mov"],
325
+ offset: 4,
326
+ description: "QuickTime video format",
327
+ category: "video"
328
+ },
329
+ // Executable Formats
330
+ {
331
+ name: "exe",
332
+ magicBytes: ["0x4D", "0x5A"],
333
+ mimeType: "application/x-msdownload",
334
+ extensions: ["exe", "dll", "mui", "sys", "scr", "cpl", "ocx", "ax", "iec", "ime", "rs", "tsp", "fon", "efi"],
335
+ description: "Windows PE executable",
336
+ category: "executable"
337
+ },
338
+ {
339
+ name: "elf",
340
+ magicBytes: ["0x7F", "0x45", "0x4C", "0x46"],
341
+ mimeType: "application/x-elf",
342
+ extensions: ["elf", "axf", "bin", "o", "out", "prx", "puff", "ko", "mod", "so"],
343
+ description: "ELF executable format",
344
+ category: "executable"
345
+ },
346
+ {
347
+ name: "macho-32",
348
+ magicBytes: ["0xFE", "0xED", "0xFA", "0xCE"],
349
+ mimeType: "application/x-mach-binary",
350
+ extensions: ["macho"],
351
+ description: "Mach-O 32-bit executable format",
352
+ category: "executable"
353
+ },
354
+ {
355
+ name: "macho-64",
356
+ magicBytes: ["0xFE", "0xED", "0xFA", "0xCF"],
357
+ mimeType: "application/x-mach-binary",
358
+ extensions: ["macho"],
359
+ description: "Mach-O 64-bit executable format",
360
+ category: "executable"
361
+ },
362
+ {
363
+ name: "macho-universal",
364
+ magicBytes: ["0xCA", "0xFE", "0xBA", "0xBE"],
365
+ mimeType: "application/x-mach-binary",
366
+ extensions: ["macho"],
367
+ description: "Mach-O universal binary",
368
+ category: "executable"
369
+ },
370
+ {
371
+ name: "class",
372
+ magicBytes: ["0xCA", "0xFE", "0xBA", "0xBE"],
373
+ mimeType: "application/java-vm",
374
+ extensions: ["class"],
375
+ description: "Java class file",
376
+ category: "executable"
377
+ },
378
+ {
379
+ name: "dex",
380
+ magicBytes: ["0x64", "0x65", "0x78", "0x0A", "0x30", "0x33", "0x35", "0x00"],
381
+ mimeType: "application/x-dex",
382
+ extensions: ["dex"],
383
+ description: "Dalvik Executable",
384
+ category: "executable"
385
+ },
386
+ {
387
+ name: "wasm",
388
+ magicBytes: ["0x00", "0x61", "0x73", "0x6D"],
389
+ mimeType: "application/wasm",
390
+ extensions: ["wasm"],
391
+ description: "WebAssembly binary format",
392
+ category: "executable"
393
+ },
394
+ // Font Formats
395
+ {
396
+ name: "ttf",
397
+ magicBytes: ["0x00", "0x01", "0x00", "0x00"],
398
+ mimeType: "font/ttf",
399
+ extensions: ["ttf"],
400
+ description: "TrueType font",
401
+ category: "font"
402
+ },
403
+ {
404
+ name: "otf",
405
+ magicBytes: ["0x4F", "0x54", "0x54", "0x4F"],
406
+ mimeType: "font/otf",
407
+ extensions: ["otf"],
408
+ description: "OpenType font",
409
+ category: "font"
410
+ },
411
+ {
412
+ name: "woff",
413
+ magicBytes: ["0x77", "0x4F", "0x46", "0x46"],
414
+ mimeType: "font/woff",
415
+ extensions: ["woff"],
416
+ description: "Web Open Font Format",
417
+ category: "font"
418
+ },
419
+ {
420
+ name: "woff2",
421
+ magicBytes: ["0x77", "0x4F", "0x46", "0x32"],
422
+ mimeType: "font/woff2",
423
+ extensions: ["woff2"],
424
+ description: "Web Open Font Format 2",
425
+ category: "font"
426
+ },
427
+ {
428
+ name: "eot",
429
+ magicBytes: ["0x4C", "0x50"],
430
+ mimeType: "application/vnd.ms-fontobject",
431
+ extensions: ["eot"],
432
+ offset: 34,
433
+ description: "Embedded OpenType font",
434
+ category: "font"
435
+ },
436
+ // Database Formats
437
+ {
438
+ name: "sqlite",
439
+ magicBytes: ["0x53", "0x51", "0x4C", "0x69", "0x74", "0x65", "0x20", "0x66", "0x6F", "0x72", "0x6D", "0x61", "0x74", "0x20", "0x33", "0x00"],
440
+ mimeType: "application/x-sqlite3",
441
+ extensions: ["sqlite", "sqlite3", "db", "db3"],
442
+ description: "SQLite database",
443
+ category: "database"
444
+ },
445
+ // Text Formats with BOM
446
+ {
447
+ name: "utf8",
448
+ magicBytes: ["0xEF", "0xBB", "0xBF"],
449
+ mimeType: "text/plain",
450
+ extensions: ["txt", "xml", "json", "csv", "md", "html", "css", "js", "ts", "py", "java", "c", "cpp", "h", "hpp", "sql", "yaml", "yml", "toml", "ini", "cfg", "conf", "log"],
451
+ description: "UTF-8 text with BOM",
452
+ category: "text",
453
+ charset: "utf-8"
454
+ },
455
+ {
456
+ name: "utf16le",
457
+ magicBytes: ["0xFF", "0xFE"],
458
+ mimeType: "text/plain",
459
+ extensions: ["txt", "xml", "json", "csv", "md", "html", "css", "js", "ts", "py", "java", "c", "cpp", "h", "hpp"],
460
+ description: "UTF-16 LE text with BOM",
461
+ category: "text"
462
+ },
463
+ {
464
+ name: "utf16be",
465
+ magicBytes: ["0xFE", "0xFF"],
466
+ mimeType: "text/plain",
467
+ extensions: ["txt", "xml", "json", "csv", "md", "html", "css", "js", "ts", "py", "java", "c", "cpp", "h", "hpp"],
468
+ description: "UTF-16 BE text with BOM",
469
+ category: "text"
470
+ },
471
+ {
472
+ name: "utf32le",
473
+ magicBytes: ["0xFF", "0xFE", "0x00", "0x00"],
474
+ mimeType: "text/plain",
475
+ extensions: ["txt", "xml", "json", "csv", "md", "html", "css", "js", "ts", "py", "java", "c", "cpp", "h", "hpp"],
476
+ description: "UTF-32 LE text with BOM",
477
+ category: "text"
478
+ },
479
+ {
480
+ name: "utf32be",
481
+ magicBytes: ["0x00", "0x00", "0xFE", "0xFF"],
482
+ mimeType: "text/plain",
483
+ extensions: ["txt", "xml", "json", "csv", "md", "html", "css", "js", "ts", "py", "java", "c", "cpp", "h", "hpp"],
484
+ description: "UTF-32 BE text with BOM",
485
+ category: "text"
486
+ },
487
+ // Other Formats
488
+ {
489
+ name: "xml",
490
+ magicBytes: ["0x3C", "0x3F", "0x78", "0x6D", "0x6C"],
491
+ mimeType: "application/xml",
492
+ extensions: ["xml"],
493
+ description: "XML document",
494
+ category: "text"
495
+ },
496
+ {
497
+ name: "swf",
498
+ magicBytes: ["0x43", "0x57", "0x53"],
499
+ mimeType: "application/x-shockwave-flash",
500
+ extensions: ["swf"],
501
+ description: "Shockwave Flash",
502
+ category: "other"
503
+ },
504
+ {
505
+ name: "swf-compressed",
506
+ magicBytes: ["0x46", "0x57", "0x53"],
507
+ mimeType: "application/x-shockwave-flash",
508
+ extensions: ["swf"],
509
+ description: "Shockwave Flash (compressed)",
510
+ category: "other"
511
+ },
512
+ {
513
+ name: "psd",
514
+ magicBytes: ["0x38", "0x42", "0x50", "0x53"],
515
+ mimeType: "image/vnd.adobe.photoshop",
516
+ extensions: ["psd"],
517
+ description: "Adobe Photoshop document",
518
+ category: "image"
519
+ },
520
+ {
521
+ name: "indd",
522
+ magicBytes: ["0x06", "0x06", "0xED", "0xF5", "0xD8", "0x1D", "0x46", "0xE5", "0xBD", "0x31", "0xEF", "0xE7", "0xFE", "0x74", "0xB7", "0x1D"],
523
+ mimeType: "application/x-indesign",
524
+ extensions: ["indd"],
525
+ description: "Adobe InDesign document",
526
+ category: "document"
527
+ },
528
+ // Additional Archive Formats
529
+ {
530
+ name: "cab",
531
+ magicBytes: ["0x4D", "0x53", "0x43", "0x46"],
532
+ mimeType: "application/vnd.ms-cab-compressed",
533
+ extensions: ["cab"],
534
+ description: "Microsoft Cabinet archive",
535
+ category: "archive",
536
+ charset: "binary"
537
+ },
538
+ {
539
+ name: "deb",
540
+ magicBytes: ["0x21", "0x3C", "0x61", "0x72", "0x63", "0x68", "0x3E"],
541
+ mimeType: "application/x-debian-package",
542
+ extensions: ["deb"],
543
+ description: "Debian package",
544
+ category: "archive",
545
+ charset: "binary"
546
+ },
547
+ {
548
+ name: "ar",
549
+ magicBytes: ["0x21", "0x3C", "0x61", "0x72", "0x63", "0x68", "0x3E"],
550
+ mimeType: "application/x-archive",
551
+ extensions: ["ar", "a"],
552
+ description: "Unix archive",
553
+ category: "archive",
554
+ charset: "binary"
555
+ },
556
+ {
557
+ name: "rpm",
558
+ magicBytes: ["0xED", "0xAB", "0xEE", "0xDB"],
559
+ mimeType: "application/x-rpm",
560
+ extensions: ["rpm"],
561
+ description: "Red Hat Package Manager",
562
+ category: "archive",
563
+ charset: "binary"
564
+ },
565
+ // Additional Audio Formats
566
+ {
567
+ name: "m4a",
568
+ magicBytes: ["0x66", "0x74", "0x79", "0x70", "0x4D", "0x34", "0x41"],
569
+ mimeType: "audio/mp4",
570
+ extensions: ["m4a"],
571
+ offset: 4,
572
+ description: "MPEG-4 Audio",
573
+ category: "audio",
574
+ charset: "binary"
575
+ },
576
+ {
577
+ name: "opus",
578
+ magicBytes: ["0x4F", "0x70", "0x75", "0x73", "0x48", "0x65", "0x61", "0x64"],
579
+ mimeType: "audio/opus",
580
+ extensions: ["opus"],
581
+ description: "Opus audio",
582
+ category: "audio",
583
+ charset: "binary"
584
+ },
585
+ {
586
+ name: "amr",
587
+ magicBytes: ["0x23", "0x21", "0x41", "0x4D", "0x52"],
588
+ mimeType: "audio/amr",
589
+ extensions: ["amr"],
590
+ description: "Adaptive Multi-Rate audio",
591
+ category: "audio",
592
+ charset: "binary"
593
+ },
594
+ {
595
+ name: "spx",
596
+ magicBytes: ["0x53", "0x70", "0x65", "0x65", "0x78", "0x20", "0x20", "0x20"],
597
+ mimeType: "audio/speex",
598
+ extensions: ["spx"],
599
+ description: "Speex audio",
600
+ category: "audio",
601
+ charset: "binary"
602
+ },
603
+ // Additional Video Formats
604
+ {
605
+ name: "webm",
606
+ magicBytes: ["0x1A", "0x45", "0xDF", "0xA3"],
607
+ mimeType: "video/webm",
608
+ extensions: ["webm"],
609
+ description: "WebM video",
610
+ category: "video",
611
+ charset: "binary"
612
+ },
613
+ {
614
+ name: "mp2t",
615
+ magicBytes: ["0x47"],
616
+ mimeType: "video/mp2t",
617
+ extensions: ["ts", "mts", "m2ts"],
618
+ description: "MPEG Transport Stream",
619
+ category: "video",
620
+ charset: "binary"
621
+ },
622
+ // AutoCAD DWG - Multiple versions with different signatures
623
+ {
624
+ name: "dwg",
625
+ magicBytes: ["0x41", "0x43", "0x31", "0x2E", "0x32"], // AC1.2
626
+ mimeType: "application/acad",
627
+ extensions: ["dwg"],
628
+ description: "AutoCAD Drawing (R1.2)",
629
+ category: "cad",
630
+ charset: "binary"
631
+ },
632
+ {
633
+ name: "dwg",
634
+ magicBytes: ["0x41", "0x43", "0x31", "0x2E", "0x34", "0x30"], // AC1.40
635
+ mimeType: "application/acad",
636
+ extensions: ["dwg"],
637
+ description: "AutoCAD Drawing (R1.40)",
638
+ category: "cad",
639
+ charset: "binary"
640
+ },
641
+ {
642
+ name: "dwg",
643
+ magicBytes: ["0x41", "0x43", "0x31", "0x2E", "0x35", "0x30"], // AC1.50
644
+ mimeType: "application/acad",
645
+ extensions: ["dwg"],
646
+ description: "AutoCAD Drawing (R1.50)",
647
+ category: "cad",
648
+ charset: "binary"
649
+ },
650
+ {
651
+ name: "dwg",
652
+ magicBytes: ["0x41", "0x43", "0x32", "0x2E", "0x30", "0x30"], // AC2.00
653
+ mimeType: "application/acad",
654
+ extensions: ["dwg"],
655
+ description: "AutoCAD Drawing (R2.00)",
656
+ category: "cad",
657
+ charset: "binary"
658
+ },
659
+ {
660
+ name: "dwg",
661
+ magicBytes: ["0x41", "0x43", "0x32", "0x2E", "0x31", "0x30"], // AC2.10
662
+ mimeType: "application/acad",
663
+ extensions: ["dwg"],
664
+ description: "AutoCAD Drawing (R2.10)",
665
+ category: "cad",
666
+ charset: "binary"
667
+ },
668
+ {
669
+ name: "dwg",
670
+ magicBytes: ["0x41", "0x43", "0x32", "0x2E", "0x32", "0x31"], // AC2.21
671
+ mimeType: "application/acad",
672
+ extensions: ["dwg"],
673
+ description: "AutoCAD Drawing (R2.21)",
674
+ category: "cad",
675
+ charset: "binary"
676
+ },
677
+ {
678
+ name: "dwg",
679
+ magicBytes: ["0x41", "0x43", "0x32", "0x2E", "0x32", "0x32"], // AC2.22
680
+ mimeType: "application/acad",
681
+ extensions: ["dwg"],
682
+ description: "AutoCAD Drawing (R2.22)",
683
+ category: "cad",
684
+ charset: "binary"
685
+ },
686
+ {
687
+ name: "dwg",
688
+ magicBytes: ["0x41", "0x43", "0x32", "0x2E", "0x35", "0x30"], // AC2.50
689
+ mimeType: "application/acad",
690
+ extensions: ["dwg"],
691
+ description: "AutoCAD Drawing (R2.50)",
692
+ category: "cad",
693
+ charset: "binary"
694
+ },
695
+ {
696
+ name: "dwg",
697
+ magicBytes: ["0x41", "0x43", "0x32", "0x2E", "0x36", "0x30"], // AC2.60
698
+ mimeType: "application/acad",
699
+ extensions: ["dwg"],
700
+ description: "AutoCAD Drawing (R2.60)",
701
+ category: "cad",
702
+ charset: "binary"
703
+ },
704
+ {
705
+ name: "dwg",
706
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x30", "0x31"], // AC1001
707
+ mimeType: "application/acad",
708
+ extensions: ["dwg"],
709
+ description: "AutoCAD Drawing (R9)",
710
+ category: "cad",
711
+ charset: "binary"
712
+ },
713
+ {
714
+ name: "dwg",
715
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x30", "0x32"], // AC1002
716
+ mimeType: "application/acad",
717
+ extensions: ["dwg"],
718
+ description: "AutoCAD Drawing (R10)",
719
+ category: "cad",
720
+ charset: "binary"
721
+ },
722
+ {
723
+ name: "dwg",
724
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x30", "0x33"], // AC1003
725
+ mimeType: "application/acad",
726
+ extensions: ["dwg"],
727
+ description: "AutoCAD Drawing (R11)",
728
+ category: "cad",
729
+ charset: "binary"
730
+ },
731
+ {
732
+ name: "dwg",
733
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x30", "0x34"], // AC1004
734
+ mimeType: "application/acad",
735
+ extensions: ["dwg"],
736
+ description: "AutoCAD Drawing (R12)",
737
+ category: "cad",
738
+ charset: "binary"
739
+ },
740
+ {
741
+ name: "dwg",
742
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x31", "0x32"], // AC1012
743
+ mimeType: "application/acad",
744
+ extensions: ["dwg"],
745
+ description: "AutoCAD Drawing (R13)",
746
+ category: "cad",
747
+ charset: "binary"
748
+ },
749
+ {
750
+ name: "dwg",
751
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x31", "0x34"], // AC1014
752
+ mimeType: "application/acad",
753
+ extensions: ["dwg"],
754
+ description: "AutoCAD Drawing (R14)",
755
+ category: "cad",
756
+ charset: "binary"
757
+ },
758
+ {
759
+ name: "dwg",
760
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x31", "0x35"], // AC1015
761
+ mimeType: "application/acad",
762
+ extensions: ["dwg"],
763
+ description: "AutoCAD Drawing (2000)",
764
+ category: "cad",
765
+ charset: "binary"
766
+ },
767
+ {
768
+ name: "dwg",
769
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x31", "0x38"], // AC1018
770
+ mimeType: "application/acad",
771
+ extensions: ["dwg"],
772
+ description: "AutoCAD Drawing (2004)",
773
+ category: "cad",
774
+ charset: "binary"
775
+ },
776
+ {
777
+ name: "dwg",
778
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x32", "0x31"], // AC1021
779
+ mimeType: "application/acad",
780
+ extensions: ["dwg"],
781
+ description: "AutoCAD Drawing (2007)",
782
+ category: "cad",
783
+ charset: "binary"
784
+ },
785
+ {
786
+ name: "dwg",
787
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x32", "0x34"], // AC1024
788
+ mimeType: "application/acad",
789
+ extensions: ["dwg"],
790
+ description: "AutoCAD Drawing (2010)",
791
+ category: "cad",
792
+ charset: "binary"
793
+ },
794
+ {
795
+ name: "dwg",
796
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x32", "0x37"], // AC1027
797
+ mimeType: "application/acad",
798
+ extensions: ["dwg"],
799
+ description: "AutoCAD Drawing (2013)",
800
+ category: "cad",
801
+ charset: "binary"
802
+ },
803
+ {
804
+ name: "dwg",
805
+ magicBytes: ["0x41", "0x43", "0x31", "0x30", "0x33", "0x32"], // AC1032
806
+ mimeType: "application/acad",
807
+ extensions: ["dwg"],
808
+ description: "AutoCAD Drawing (2018)",
809
+ category: "cad",
810
+ charset: "binary"
811
+ },
812
+ // Enhanced Metafile (EMF)
813
+ {
814
+ name: "emf",
815
+ magicBytes: ["0x01", "0x00", "0x00", "0x00"],
816
+ mimeType: "image/emf",
817
+ extensions: ["emf"],
818
+ description: "Enhanced Metafile",
819
+ category: "image",
820
+ charset: "binary"
821
+ },
822
+ {
823
+ name: "mpg",
824
+ magicBytes: ["0x00", "0x00", "0x01", "0xBA"],
825
+ mimeType: "video/mpeg",
826
+ extensions: ["mpg", "mpeg"],
827
+ description: "MPEG video",
828
+ category: "video",
829
+ charset: "binary"
830
+ },
831
+ {
832
+ name: "mp2",
833
+ magicBytes: ["0x00", "0x00", "0x01", "0xB3"],
834
+ mimeType: "video/mpeg",
835
+ extensions: ["mp2", "m2v"],
836
+ description: "MPEG-2 video",
837
+ category: "video",
838
+ charset: "binary"
839
+ },
840
+ {
841
+ name: "flv",
842
+ magicBytes: ["0x46", "0x4C", "0x56"],
843
+ mimeType: "video/x-flv",
844
+ extensions: ["flv"],
845
+ description: "Flash Video",
846
+ category: "video",
847
+ charset: "binary"
848
+ },
849
+ // Additional Font Formats
850
+ {
851
+ name: "ttc",
852
+ magicBytes: ["0x74", "0x74", "0x63", "0x66"],
853
+ mimeType: "font/collection",
854
+ extensions: ["ttc"],
855
+ description: "TrueType font collection",
856
+ category: "font",
857
+ charset: "binary"
858
+ },
859
+ // Office Document Formats (ZIP-based)
860
+ {
861
+ name: "docx",
862
+ magicBytes: ["0x50", "0x4B", "0x03", "0x04"],
863
+ mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
864
+ extensions: ["docx"],
865
+ description: "Microsoft Word document",
866
+ category: "document",
867
+ charset: "binary",
868
+ contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
869
+ },
870
+ {
871
+ name: "xlsx",
872
+ magicBytes: ["0x50", "0x4B", "0x03", "0x04"],
873
+ mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
874
+ extensions: ["xlsx"],
875
+ description: "Microsoft Excel spreadsheet",
876
+ category: "document",
877
+ charset: "binary",
878
+ contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
879
+ },
880
+ {
881
+ name: "pptx",
882
+ magicBytes: ["0x50", "0x4B", "0x03", "0x04"],
883
+ mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
884
+ extensions: ["pptx"],
885
+ description: "Microsoft PowerPoint presentation",
886
+ category: "document",
887
+ charset: "binary",
888
+ contentType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
889
+ }
890
+ ];
891
+ exports.CONTENT_TYPE_MAPPINGS = [
892
+ // TypeScript files (charset-dependent)
893
+ [['ts'], 'text/x-typescript', 'utf-8'],
894
+ [['ts'], 'video/mp2t', 'binary'],
895
+ [['tsx'], 'text/x-typescript', 'utf-8'],
896
+ // Office Open XML formats (detected as application/zip but have specific content types)
897
+ [['docx'], 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'binary'],
898
+ [['xlsx'], 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'binary'],
899
+ [['pptx'], 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'binary'],
900
+ // Other ZIP-based formats
901
+ [['epub'], 'application/epub+zip', 'binary'],
902
+ [['jar'], 'application/java-archive', 'binary'],
903
+ [['apk'], 'application/vnd.android.package-archive', 'binary'],
904
+ [['xpi'], 'application/x-xpinstall', 'binary'],
905
+ // Font files
906
+ [['ttf'], 'font/ttf'],
907
+ [['otf'], 'font/otf'],
908
+ [['woff'], 'font/woff'],
909
+ [['woff2'], 'font/woff2'],
910
+ [['eot'], 'application/vnd.ms-fontobject'],
911
+ [['svg'], 'image/svg+xml'],
912
+ // OpenDocument formats
913
+ [['ods'], 'application/vnd.oasis.opendocument.spreadsheet'],
914
+ [['odt'], 'application/vnd.oasis.opendocument.text'],
915
+ [['odp'], 'application/vnd.oasis.opendocument.presentation'],
916
+ [['odg'], 'application/vnd.oasis.opendocument.graphics'],
917
+ // CAD formats
918
+ [['dxf'], 'image/vnd.dxf', 'ascii'], // DXF is typically text-based
919
+ [['dxf'], 'image/vnd.dxf', 'utf-8'], // Modern DXF files might be UTF-8
920
+ [['emf'], 'image/emf', 'binary'],
921
+ // Archive formats
922
+ [['zip'], 'application/zip'],
923
+ [['rar'], 'application/x-rar-compressed'],
924
+ [['7z'], 'application/x-7z-compressed'],
925
+ [['tar'], 'application/x-tar'],
926
+ [['gz', 'gzip'], 'application/gzip'],
927
+ [['bz2'], 'application/x-bzip2'],
928
+ [['xz'], 'application/x-xz'],
929
+ [['Z'], 'application/x-compress'],
930
+ [['lz'], 'application/x-lzip'],
931
+ [['lzh'], 'application/x-lzh-compressed'],
932
+ [['zst'], 'application/zstd'],
933
+ [['cab'], 'application/vnd.ms-cab-compressed'],
934
+ [['deb'], 'application/x-deb'],
935
+ [['ar'], 'application/x-unix-archive'],
936
+ [['rpm'], 'application/x-rpm'],
937
+ [['cpio'], 'application/x-cpio'],
938
+ [['arj'], 'application/x-arj'],
939
+ [['ace'], 'application/x-ace-compressed'],
940
+ [['asar'], 'application/x-asar'],
941
+ [['tar.gz'], 'application/gzip'],
942
+ // Image formats
943
+ [['jpg'], 'image/jpeg'],
944
+ [['png'], 'image/png'],
945
+ [['apng'], 'image/apng'],
946
+ [['gif'], 'image/gif'],
947
+ [['webp'], 'image/webp'],
948
+ [['flif'], 'image/flif'],
949
+ [['xcf'], 'image/x-xcf'],
950
+ [['cr2'], 'image/x-canon-cr2'],
951
+ [['cr3'], 'image/x-canon-cr3'],
952
+ [['orf'], 'image/x-olympus-orf'],
953
+ [['arw'], 'image/x-sony-arw'],
954
+ [['dng'], 'image/x-adobe-dng'],
955
+ [['nef'], 'image/x-nikon-nef'],
956
+ [['rw2'], 'image/x-panasonic-rw2'],
957
+ [['raf'], 'image/x-fujifilm-raf'],
958
+ [['tif'], 'image/tiff'],
959
+ [['bmp'], 'image/bmp'],
960
+ [['icns'], 'image/icns'],
961
+ [['jxr'], 'image/vnd.ms-photo'],
962
+ [['psd'], 'image/vnd.adobe.photoshop'],
963
+ [['ico'], 'image/x-icon'],
964
+ [['cur'], 'image/x-icon'],
965
+ [['bpg'], 'image/bpg'],
966
+ [['j2c'], 'image/j2c'],
967
+ [['jp2'], 'image/jp2'],
968
+ [['jpm'], 'image/jpm'],
969
+ [['jpx'], 'image/jpx'],
970
+ [['mj2'], 'image/mj2'],
971
+ [['heic'], 'image/heic'],
972
+ [['heif'], 'image/heif'],
973
+ [['avif'], 'image/avif'],
974
+ [['jxl'], 'image/jxl'],
975
+ [['jls'], 'image/jls'],
976
+ [['ktx'], 'image/ktx'],
977
+ [['dwg'], 'application/acad', 'binary'],
978
+ // Video formats
979
+ [['mp4'], 'video/mp4'],
980
+ [['mkv'], 'video/matroska'],
981
+ [['webm'], 'video/webm'],
982
+ [['mov'], 'video/quicktime'],
983
+ [['avi'], 'video/vnd.avi'],
984
+ [['mpg'], 'video/mpeg'],
985
+ [['mp2'], 'video/mpeg'],
986
+ [['mp1'], 'video/MP1S'],
987
+ [['mts'], 'video/mp2t'],
988
+ [['m2ts'], 'video/mp2t'],
989
+ [['3gp'], 'video/3gpp'],
990
+ [['3g2'], 'video/3gpp2'],
991
+ [['flv'], 'video/x-flv'],
992
+ [['m4v'], 'video/x-m4v'],
993
+ [['f4v'], 'video/x-m4v'],
994
+ [['ogv'], 'video/ogg'],
995
+ [['asf'], 'video/x-ms-asf'],
996
+ // Audio formats
997
+ [['mp3'], 'audio/mpeg'],
998
+ [['m4a'], 'audio/x-m4a'],
999
+ [['m4p'], 'audio/mp4'],
1000
+ [['m4b'], 'audio/mp4'],
1001
+ [['f4a'], 'audio/mp4'],
1002
+ [['f4b'], 'audio/mp4'],
1003
+ [['oga'], 'audio/ogg'],
1004
+ [['ogg'], 'audio/ogg'],
1005
+ [['opus'], 'audio/ogg; codecs=opus'],
1006
+ [['flac'], 'audio/flac'],
1007
+ [['wav'], 'audio/wav'],
1008
+ [['spx'], 'audio/ogg'],
1009
+ [['amr'], 'audio/amr'],
1010
+ [['mid'], 'audio/midi'],
1011
+ [['aif'], 'audio/aiff'],
1012
+ [['aiff'], 'audio/aiff'],
1013
+ [['qcp'], 'audio/qcelp'],
1014
+ [['ape'], 'audio/ape'],
1015
+ [['wv'], 'audio/wavpack'],
1016
+ [['mpc'], 'audio/x-musepack'],
1017
+ [['voc'], 'audio/x-voc'],
1018
+ [['ac3'], 'audio/vnd.dolby.dd-raw'],
1019
+ [['aac'], 'audio/aac'],
1020
+ [['it'], 'audio/x-it'],
1021
+ [['s3m'], 'audio/x-s3m'],
1022
+ [['xm'], 'audio/x-xm'],
1023
+ [['dsf'], 'audio/x-dsf'],
1024
+ // Document formats
1025
+ [['pdf'], 'application/pdf'],
1026
+ [['rtf'], 'application/rtf'],
1027
+ [['ps'], 'application/postscript'],
1028
+ [['eps'], 'application/eps'],
1029
+ [['indd'], 'application/x-indesign'],
1030
+ // Text formats
1031
+ [['xml'], 'application/xml'],
1032
+ [['ics'], 'text/calendar'],
1033
+ [['vcf'], 'text/vcard'],
1034
+ [['vtt'], 'text/vtt'],
1035
+ // Font formats (additional)
1036
+ [['ttc'], 'font/collection'],
1037
+ // Model/3D formats
1038
+ [['glb'], 'model/gltf-binary'],
1039
+ [['stl'], 'model/stl'],
1040
+ [['3mf'], 'model/3mf'],
1041
+ [['fbx'], 'application/x-autodesk.fbx'],
1042
+ [['blend'], 'application/x-blender'],
1043
+ [['skp'], 'application/vnd.sketchup.skp'],
1044
+ // Microsoft Office formats (additional)
1045
+ [['docm'], 'application/vnd.ms-word.document.macroenabled.12'],
1046
+ [['dotm'], 'application/vnd.ms-word.template.macroenabled.12'],
1047
+ [['dotx'], 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'],
1048
+ [['xlsm'], 'application/vnd.ms-excel.sheet.macroenabled.12'],
1049
+ [['xltm'], 'application/vnd.ms-excel.template.macroenabled.12'],
1050
+ [['xltx'], 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'],
1051
+ [['pptm'], 'application/vnd.ms-powerpoint.presentation.macroenabled.12'],
1052
+ [['potm'], 'application/vnd.ms-powerpoint.template.macroenabled.12'],
1053
+ [['potx'], 'application/vnd.openxmlformats-officedocument.presentationml.template'],
1054
+ [['ppsm'], 'application/vnd.ms-powerpoint.slideshow.macroenabled.12'],
1055
+ [['ppsx'], 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'],
1056
+ [['vsdx'], 'application/vnd.visio'],
1057
+ [['pst'], 'application/vnd.ms-outlook'],
1058
+ // OpenDocument templates
1059
+ [['ott'], 'application/vnd.oasis.opendocument.text-template'],
1060
+ [['ots'], 'application/vnd.oasis.opendocument.spreadsheet-template'],
1061
+ [['otp'], 'application/vnd.oasis.opendocument.presentation-template'],
1062
+ [['otg'], 'application/vnd.oasis.opendocument.graphics-template'],
1063
+ // Executable/Binary formats
1064
+ [['exe'], 'application/x-msdownload'],
1065
+ [['elf'], 'application/x-elf'],
1066
+ [['macho'], 'application/x-mach-binary'],
1067
+ [['class'], 'application/java-vm'],
1068
+ [['swf'], 'application/x-shockwave-flash'],
1069
+ [['wasm'], 'application/wasm'],
1070
+ [['crx'], 'application/x-google-chrome-extension'],
1071
+ // Database formats
1072
+ [['sqlite'], 'application/x-sqlite3'],
1073
+ // Data formats
1074
+ [['arrow'], 'application/vnd.apache.arrow.file'],
1075
+ [['parquet'], 'application/vnd.apache.parquet'],
1076
+ [['avro'], 'application/avro'],
1077
+ // Disk/System formats
1078
+ [['dmg'], 'application/x-apple-diskimage'],
1079
+ [['reg'], 'application/x-ms-regedit'],
1080
+ [['dat'], 'application/x-ft-windows-registry-hive'],
1081
+ // E-book formats
1082
+ [['mobi'], 'application/x-mobipocket-ebook'],
1083
+ [['chm'], 'application/vnd.ms-htmlhelp'],
1084
+ // Miscellaneous formats
1085
+ [['cfb'], 'application/x-cfb'],
1086
+ [['mxf'], 'application/mxf'],
1087
+ [['mie'], 'application/x-mie'],
1088
+ [['nes'], 'application/x-nintendo-nes-rom'],
1089
+ [['pcap'], 'application/vnd.tcpdump.pcap'],
1090
+ [['shp'], 'application/x-esri-shape'],
1091
+ [['pgp'], 'application/pgp-encrypted'],
1092
+ [['icc'], 'application/vnd.iccprofile'],
1093
+ [['dcm'], 'application/dicom'],
1094
+ [['rm'], 'application/vnd.rn-realmedia'],
1095
+ [['ogm'], 'application/ogg'],
1096
+ [['ogx'], 'application/ogg'],
1097
+ // Programming and markup languages
1098
+ [['less'], 'text/x-less', 'utf-8'],
1099
+ [['md'], 'text/markdown', 'utf-8'],
1100
+ [['scss'], 'text/x-scss', 'utf-8'],
1101
+ [['sh'], 'application/x-sh', 'utf-8'],
1102
+ [['sql'], 'application/sql', 'utf-8'],
1103
+ [['yaml'], 'application/x-yaml', 'utf-8'],
1104
+ [['yml'], 'application/x-yaml', 'utf-8'],
1105
+ [['jsx'], 'text/jsx', 'utf-8'],
1106
+ [['js'], 'application/javascript', 'utf-8'],
1107
+ [['json'], 'application/json', 'utf-8'],
1108
+ [['html'], 'text/html', 'utf-8'],
1109
+ [['htm'], 'text/html', 'utf-8'],
1110
+ [['css'], 'text/css', 'utf-8'],
1111
+ [['txt'], 'text/plain', 'utf-8'],
1112
+ [['csv'], 'text/csv', 'utf-8'],
1113
+ [['tsv'], 'text/tab-separated-values', 'utf-8'],
1114
+ // Legacy image formats
1115
+ [['pct'], 'image/x-pict'],
1116
+ [['tga'], 'image/x-targa']
1117
+ ];
1118
+ // Utility functions for working with the registry
1119
+ function getFileTypeByMagicBytes(magicBytes, offset = 0) {
1120
+ return exports.FILE_TYPES.find(type => {
1121
+ // Skip file types with no magic bytes (extension-only detection)
1122
+ if (!type.magicBytes || type.magicBytes.length === 0)
1123
+ return false;
1124
+ if (type.offset !== undefined && type.offset !== offset)
1125
+ return false;
1126
+ // Convert magic bytes to hex string for comparison
1127
+ const typeSignature = type.magicBytes.map(b => b.replace(/0x/i, '')).join('').toLowerCase();
1128
+ const inputSignature = magicBytes.toLowerCase();
1129
+ // Handle wildcards in signatures
1130
+ return matchSignatureWithWildcards(typeSignature, inputSignature);
1131
+ }) || null;
1132
+ }
1133
+ function getFileTypeByExtension(extension) {
1134
+ const cleanExt = extension.toLowerCase().replace(/^\./, '');
1135
+ return exports.FILE_TYPES.filter(type => type.extensions.some(ext => ext.toLowerCase() === cleanExt));
1136
+ }
1137
+ function getFileTypesByCategory(category) {
1138
+ return exports.FILE_TYPES.filter(type => type.category === category);
1139
+ }
1140
+ // Helper function to match signatures with wildcards
1141
+ function matchSignatureWithWildcards(pattern, input) {
1142
+ if (pattern === input)
1143
+ return true;
1144
+ // Handle wildcards (?) in the pattern
1145
+ const regexPattern = pattern.replace(/\?/g, '[0-9a-f]{2}');
1146
+ const regex = new RegExp(`^${regexPattern}`, 'i');
1147
+ return regex.test(input);
1148
+ }
1149
+ // Helper function to find content type by extension
1150
+ function getContentTypeByExtension(extension) {
1151
+ const cleanExt = extension.toLowerCase().replace(/^\./, '');
1152
+ for (const mapping of exports.CONTENT_TYPE_MAPPINGS) {
1153
+ if (mapping[0].includes(cleanExt)) {
1154
+ return mapping[1];
1155
+ }
1156
+ }
1157
+ return null;
1158
+ }
1159
+ // Charset detection logic - derived from bytes automatically
1160
+ function detectCharset(buffer) {
1161
+ // Step 1: Check for BOM (Byte Order Mark) patterns
1162
+ const hex = buffer.slice(0, 4).toString('hex');
1163
+ if (hex.startsWith('efbbbf'))
1164
+ return 'utf-8';
1165
+ if (hex.startsWith('fffe'))
1166
+ return 'utf-16le';
1167
+ if (hex.startsWith('feff'))
1168
+ return 'utf-16be';
1169
+ if (hex.startsWith('0000feff'))
1170
+ return 'utf-32be';
1171
+ if (hex.startsWith('fffe0000'))
1172
+ return 'utf-32le';
1173
+ // Step 2: Check for binary characteristics
1174
+ const sample = buffer.slice(0, Math.min(buffer.length, 1024)); // Check first 1KB
1175
+ let nullCount = 0;
1176
+ let controlCount = 0;
1177
+ for (let i = 0; i < sample.length; i++) {
1178
+ const byte = sample[i];
1179
+ if (byte === 0)
1180
+ nullCount++;
1181
+ // Count control characters except tab, newline, carriage return
1182
+ if (byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
1183
+ controlCount++;
1184
+ }
1185
+ }
1186
+ const nullRatio = nullCount / sample.length;
1187
+ const controlRatio = controlCount / sample.length;
1188
+ // If more than 10% null bytes or control characters, likely binary
1189
+ if (nullRatio > 0.1 || controlRatio > 0.1) {
1190
+ return 'binary';
1191
+ }
1192
+ // Step 3: Try to decode as UTF-8 to validate
1193
+ try {
1194
+ // Use TextDecoder with fatal flag to validate UTF-8
1195
+ new TextDecoder('utf-8', { fatal: true }).decode(sample);
1196
+ return 'utf-8';
1197
+ }
1198
+ catch {
1199
+ // If UTF-8 decoding fails, it might be a legacy encoding
1200
+ // Return 'ascii' as a conservative guess (could also return 'unknown')
1201
+ return 'ascii';
1202
+ }
1203
+ }
1204
+ function getContentTypeForExtension(extension, charset) {
1205
+ // Normalize extension
1206
+ const ext = extension.toLowerCase().replace(/^\./, '');
1207
+ // If charset is provided, look for exact matches first
1208
+ if (charset) {
1209
+ const exactMatch = exports.CONTENT_TYPE_MAPPINGS.find(mapping => mapping[0].includes(ext) && mapping[2] === charset);
1210
+ if (exactMatch) {
1211
+ return exactMatch[1];
1212
+ }
1213
+ }
1214
+ // Fall back to mappings without charset requirements
1215
+ const generalMatch = exports.CONTENT_TYPE_MAPPINGS.find(mapping => mapping[0].includes(ext) && mapping.length === 2);
1216
+ return generalMatch ? generalMatch[1] : null;
1217
+ }