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