@depup/file-type 21.3.0-depup.0

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.
package/readme.md ADDED
@@ -0,0 +1,662 @@
1
+ <h1 align="center" title="file-type">
2
+ <img src="media/logo.jpg" alt="file-type logo">
3
+ </h1>
4
+
5
+ > Detect the file type of a file, stream, or data
6
+
7
+ The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
8
+
9
+ This package is for detecting binary-based file formats, not text-based formats like `.txt`, `.csv`, `.svg`, etc.
10
+
11
+ We accept contributions for commonly used modern file formats, not historical or obscure ones. Open an issue first for discussion.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install file-type
17
+ ```
18
+
19
+ **This package is an ESM package. Your project needs to be ESM too. [Read more](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). For TypeScript + CommonJS, see [`load-esm`](https://github.com/Borewit/load-esm).**
20
+
21
+ If you use it with Webpack, you need the latest Webpack version and ensure you configure it correctly for ESM.
22
+
23
+ File type detection is based on binary signatures (magic numbers) and should be treated as a best-effort hint, not a guarantee.
24
+
25
+ ## Usage
26
+
27
+ ### Node.js
28
+
29
+ Determine file type from a file:
30
+
31
+ ```js
32
+ import {fileTypeFromFile} from 'file-type';
33
+
34
+ console.log(await fileTypeFromFile('Unicorn.png'));
35
+ //=> {ext: 'png', mime: 'image/png'}
36
+ ```
37
+
38
+ Determine file type from a Uint8Array/ArrayBuffer, which may be a portion of the beginning of a file:
39
+
40
+ ```js
41
+ import {fileTypeFromBuffer} from 'file-type';
42
+ import {readChunk} from 'read-chunk';
43
+
44
+ const buffer = await readChunk('Unicorn.png', {length: 4100});
45
+
46
+ console.log(await fileTypeFromBuffer(buffer));
47
+ //=> {ext: 'png', mime: 'image/png'}
48
+ ```
49
+
50
+ Determine file type from a stream:
51
+
52
+ ```js
53
+ import fs from 'node:fs';
54
+ import {fileTypeFromStream} from 'file-type';
55
+
56
+ const stream = fs.createReadStream('Unicorn.mp4');
57
+
58
+ console.log(await fileTypeFromStream(stream));
59
+ //=> {ext: 'mp4', mime: 'video/mp4'}
60
+ ```
61
+
62
+ The stream method can also be used to read from a remote location:
63
+
64
+ ```js
65
+ import got from 'got';
66
+ import {fileTypeFromStream} from 'file-type';
67
+
68
+ const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
69
+
70
+ const stream = got.stream(url);
71
+
72
+ console.log(await fileTypeFromStream(stream));
73
+ //=> {ext: 'jpg', mime: 'image/jpeg'}
74
+ ```
75
+
76
+ Another stream example:
77
+
78
+ ```js
79
+ import stream from 'node:stream';
80
+ import fs from 'node:fs';
81
+ import crypto from 'node:crypto';
82
+ import {fileTypeStream} from 'file-type';
83
+
84
+ const read = fs.createReadStream('encrypted.enc');
85
+ const decipher = crypto.createDecipheriv(alg, key, iv);
86
+
87
+ const streamWithFileType = await fileTypeStream(stream.pipeline(read, decipher));
88
+
89
+ console.log(streamWithFileType.fileType);
90
+ //=> {ext: 'mov', mime: 'video/quicktime'}
91
+
92
+ const write = fs.createWriteStream(`decrypted.${streamWithFileType.fileType.ext}`);
93
+ streamWithFileType.pipe(write);
94
+ ```
95
+
96
+ ### Browser
97
+
98
+ ```js
99
+ import {fileTypeFromStream} from 'file-type';
100
+
101
+ const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
102
+
103
+ const response = await fetch(url);
104
+ const fileType = await fileTypeFromStream(response.body);
105
+
106
+ console.log(fileType);
107
+ //=> {ext: 'jpg', mime: 'image/jpeg'}
108
+ ```
109
+
110
+ ## API
111
+
112
+ ### fileTypeFromBuffer(buffer, options)
113
+
114
+ Detect the file type of a `Uint8Array`, or `ArrayBuffer`.
115
+
116
+ The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
117
+
118
+ If file access is available, it is recommended to use `fileTypeFromFile()` instead.
119
+
120
+ Returns a `Promise` for an object with the detected file type:
121
+
122
+ - `ext` - One of the [supported file types](#supported-file-types)
123
+ - `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
124
+
125
+ Or `undefined` when there is no match.
126
+
127
+ #### buffer
128
+
129
+ Type: `Uint8Array | ArrayBuffer`
130
+
131
+ A buffer representing file data. It works best if the buffer contains the entire file. It may work with a smaller portion as well.
132
+
133
+ ### fileTypeFromFile(filePath, options)
134
+
135
+ Detect the file type of a file path.
136
+
137
+ This is for Node.js only.
138
+
139
+ To read from a [`File`](https://developer.mozilla.org/docs/Web/API/File), see [`fileTypeFromBlob()`](#filetypefromblobblob-options).
140
+
141
+ The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
142
+
143
+ Returns a `Promise` for an object with the detected file type:
144
+
145
+ - `ext` - One of the [supported file types](#supported-file-types)
146
+ - `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
147
+
148
+ Or `undefined` when there is no match.
149
+
150
+ #### filePath
151
+
152
+ Type: `string`
153
+
154
+ The file path to parse.
155
+
156
+ ### fileTypeFromStream(stream)
157
+
158
+ Detect the file type of a [web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
159
+
160
+ If the engine is Node.js, this may also be a [Node.js `stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable).
161
+
162
+ Direct support for Node.js streams will be dropped in the future, when Node.js streams can be converted to Web streams (see [`toWeb()`](https://nodejs.org/api/stream.html#streamreadabletowebstreamreadable-options)).
163
+
164
+ The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
165
+
166
+ Returns a `Promise` for an object with the detected file type:
167
+
168
+ - `ext` - One of the [supported file types](#supported-file-types)
169
+ - `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
170
+
171
+ Or `undefined` when there is no match.
172
+
173
+ #### stream
174
+
175
+ Type: [Web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) or [Node.js `stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)
176
+
177
+ A readable stream representing file data.
178
+
179
+ ### fileTypeFromBlob(blob, options)
180
+
181
+ Detect the file type of a [`Blob`](https://developer.mozilla.org/docs/Web/API/Blob),
182
+
183
+ > [!TIP]
184
+ > A [`File` object](https://developer.mozilla.org/docs/Web/API/File) is a `Blob` and can be passed in here.
185
+
186
+ It will **stream** the underlying Blob.
187
+
188
+ The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the blob.
189
+
190
+ Returns a `Promise` for an object with the detected file type:
191
+
192
+ - `ext` - One of the [supported file types](#supported-file-types)
193
+ - `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
194
+
195
+ Or `undefined` when there is no match.
196
+
197
+ ```js
198
+ import {fileTypeFromBlob} from 'file-type';
199
+
200
+ const blob = new Blob(['<?xml version="1.0" encoding="ISO-8859-1" ?>'], {
201
+ type: 'text/plain',
202
+ endings: 'native'
203
+ });
204
+
205
+ console.log(await fileTypeFromBlob(blob));
206
+ //=> {ext: 'txt', mime: 'text/plain'}
207
+ ```
208
+
209
+ #### blob
210
+
211
+ Type: [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
212
+
213
+ ### fileTypeFromTokenizer(tokenizer, options)
214
+
215
+ Detect the file type from an `ITokenizer` source.
216
+
217
+ This method is used internally, but can also be used for a special "tokenizer" reader.
218
+
219
+ A tokenizer propagates the internal read functions, allowing alternative transport mechanisms, to access files, to be implemented and used.
220
+
221
+ Returns a `Promise` for an object with the detected file type:
222
+
223
+ - `ext` - One of the [supported file types](#supported-file-types)
224
+ - `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
225
+
226
+ Or `undefined` when there is no match.
227
+
228
+ An example is [`@tokenizer/http`](https://github.com/Borewit/tokenizer-http), which requests data using [HTTP-range-requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests). A difference with a conventional stream and the [*tokenizer*](https://github.com/Borewit/strtok3#tokenizer), is that it can *ignore* (seek, fast-forward) in the stream. For example, you may only need and read the first 6 bytes, and the last 128 bytes, which may be an advantage in case reading the entire file would take longer.
229
+
230
+ ```js
231
+ import {makeTokenizer} from '@tokenizer/http';
232
+ import {fileTypeFromTokenizer} from 'file-type';
233
+
234
+ const audioTrackUrl = 'https://test-audio.netlify.com/Various%20Artists%20-%202009%20-%20netBloc%20Vol%2024_%20tiuqottigeloot%20%5BMP3-V2%5D/01%20-%20Diablo%20Swing%20Orchestra%20-%20Heroines.mp3';
235
+
236
+ const httpTokenizer = await makeTokenizer(audioTrackUrl);
237
+ const fileType = await fileTypeFromTokenizer(httpTokenizer);
238
+
239
+ console.log(fileType);
240
+ //=> {ext: 'mp3', mime: 'audio/mpeg'}
241
+ ```
242
+
243
+ Or use [`@tokenizer/s3`](https://github.com/Borewit/tokenizer-s3) to determine the file type of a file stored on [Amazon S3](https://aws.amazon.com/s3):
244
+
245
+ ```js
246
+ import {S3Client} from '@aws-sdk/client-s3';
247
+ import {makeChunkedTokenizerFromS3} from '@tokenizer/s3';
248
+ import {fileTypeFromTokenizer} from 'file-type';
249
+
250
+ // Initialize the S3 client
251
+ // Initialize S3 client
252
+ const s3 = new S3Client();
253
+
254
+ // Initialize the S3 tokenizer.
255
+ const s3Tokenizer = await makeChunkedTokenizerFromS3(s3, {
256
+ Bucket: 'affectlab',
257
+ Key: '1min_35sec.mp4'
258
+ });
259
+
260
+ // Figure out what kind of file it is.
261
+ const fileType = await fileTypeFromTokenizer(s3Tokenizer);
262
+ console.log(fileType);
263
+ ```
264
+
265
+ Note that only the minimum amount of data required to determine the file type is read (okay, just a bit extra to prevent too many fragmented reads).
266
+
267
+ #### tokenizer
268
+
269
+ Type: [`ITokenizer`](https://github.com/Borewit/strtok3#tokenizer)
270
+
271
+ A file source implementing the [tokenizer interface](https://github.com/Borewit/strtok3#tokenizer).
272
+
273
+ ### fileTypeStream(webStream, options?)
274
+
275
+ Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
276
+
277
+ This method can be handy to put in between a stream, but it comes with a price.
278
+ Internally `stream()` builds up a buffer of `sampleSize` bytes, used as a sample, to determine the file type.
279
+ The sample size impacts the file detection resolution.
280
+ A smaller sample size will result in lower probability of the best file type detection.
281
+
282
+ **Note:** When using Node.js, a `stream.Readable` may be provided as well.
283
+
284
+ #### readableStream
285
+
286
+ Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)
287
+
288
+ #### options
289
+
290
+ Type: `object`
291
+
292
+ Supports the following options in addition to the [general options](#options):
293
+
294
+ ##### sampleSize
295
+
296
+ Type: `number`\
297
+ Default: `4100`
298
+
299
+ The sample size in bytes.
300
+
301
+ #### Example
302
+
303
+ ```js
304
+ import got from 'got';
305
+ import {fileTypeStream} from 'file-type';
306
+
307
+ const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
308
+
309
+ const stream1 = got.stream(url);
310
+ const stream2 = await fileTypeStream(stream1, {sampleSize: 1024});
311
+
312
+ if (stream2.fileType?.mime === 'image/jpeg') {
313
+ // stream2 can be used to stream the JPEG image (from the very beginning of the stream)
314
+ }
315
+ ```
316
+
317
+ #### readableStream
318
+
319
+ Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)
320
+
321
+ The input stream.
322
+
323
+ ### supportedExtensions
324
+
325
+ Returns a `Set<string>` of supported file extensions.
326
+
327
+ ### supportedMimeTypes
328
+
329
+ Returns a `Set<string>` of supported MIME types.
330
+
331
+ ### Options
332
+
333
+ #### customDetectors
334
+
335
+ Array of custom file type detectors to run before default detectors.
336
+
337
+ For example:
338
+
339
+ ```js
340
+ import {fileTypeFromFile} from 'file-type';
341
+ import {detectXml} from '@file-type/xml';
342
+
343
+ const fileType = await fileTypeFromFile('sample.kml', {customDetectors: [detectXml]});
344
+ console.log(fileType);
345
+ ```
346
+
347
+ #### mpegOffsetTolerance
348
+
349
+ Default: `0`
350
+
351
+ Specifies the byte tolerance for locating the first MPEG audio frame (e.g. `.mp1`, `.mp2`, `.mp3`, `.aac`).
352
+
353
+ Allows detection to handle slight sync offsets between the expected and actual frame start. Common in malformed or incorrectly muxed files, which, while technically invalid, do occur in the wild.
354
+
355
+ A tolerance of 10 bytes covers most cases.
356
+
357
+ ## Custom detectors
358
+
359
+ Custom file type detectors are plugins designed to extend the default detection capabilities.
360
+ They allow support for uncommon file types, non-binary formats, or customized detection behavior.
361
+
362
+ Detectors can be added via the constructor options or by modifying `FileTypeParser#detectors` directly.
363
+ Detectors provided through the constructor are executed before the default ones.
364
+
365
+ Detectors can be added via the constructor options or by directly modifying `FileTypeParser#detectors`.
366
+
367
+ ### Example adding a detector
368
+
369
+ For example:
370
+
371
+ ```js
372
+ import {FileTypeParser} from 'file-type';
373
+ import {detectXml} from '@file-type/xml';
374
+
375
+ const parser = new FileTypeParser({customDetectors: [detectXml]});
376
+ const fileType = await parser.fromFile('sample.kml');
377
+ console.log(fileType);
378
+ ```
379
+
380
+ ### Available third-party file-type detectors
381
+
382
+ - [@file-type/av](https://github.com/Borewit/file-type-av): Improves detection of audio and video file formats, with accurate differentiation between the two
383
+ - [@file-type/pdf](https://github.com/Borewit/file-type-pdf): Detects PDF based file types, such as Adobe Illustrator
384
+ - [@file-type/xml](https://github.com/Borewit/file-type-xml): Detects common XML file types, such as GLM, KML, MusicXML, RSS, SVG, and XHTML
385
+
386
+ ### Detector execution flow
387
+
388
+ If a detector returns `undefined`, the following rules apply:
389
+
390
+ 1. **No Tokenizer Interaction**: If the detector does not modify the tokenizer's position, the next detector in the sequence is executed.
391
+ 2. **Tokenizer Interaction**: If the detector modifies the tokenizer's position (`tokenizer.position` is advanced), no further detectors are executed. In this case, the file type remains `undefined`, as subsequent detectors cannot evaluate the content. This is an exceptional scenario, as it prevents any other detectors from determining the file type.
392
+
393
+ ### Writing your own custom detector
394
+
395
+ Below is an example of a custom detector array. This can be passed to the `FileTypeParser` via the `fileTypeOptions` argument.
396
+
397
+ ```js
398
+ import {FileTypeParser} from 'file-type';
399
+
400
+ const unicornDetector = {
401
+ id: 'unicorn', // May be used to recognize the detector in the detector list
402
+ async detect(tokenizer) {
403
+ const unicornHeader = [85, 78, 73, 67, 79, 82, 78]; // "UNICORN" in ASCII decimal
404
+
405
+ const buffer = new Uint8Array(unicornHeader.length);
406
+ await tokenizer.peekBuffer(buffer, {length: unicornHeader.length, mayBeLess: true});
407
+ if (unicornHeader.every((value, index) => value === buffer[index])) {
408
+ return {ext: 'unicorn', mime: 'application/unicorn'};
409
+ }
410
+
411
+ return undefined;
412
+ }
413
+ }
414
+
415
+ const buffer = new Uint8Array([85, 78, 73, 67, 79, 82, 78]);
416
+ const parser = new FileTypeParser({customDetectors: [unicornDetector]});
417
+ const fileType = await parser.fromBuffer(buffer);
418
+ console.log(fileType); // {ext: 'unicorn', mime: 'application/unicorn'}
419
+ ```
420
+
421
+ ```ts
422
+ /**
423
+ @param tokenizer - The [tokenizer](https://github.com/Borewit/strtok3#tokenizer) used to read file content.
424
+ @param fileType - The file type detected by standard or previous custom detectors, or `undefined` if no match is found.
425
+ @returns The detected file type, or `undefined` if no match is found.
426
+ */
427
+ export type Detector = (tokenizer: ITokenizer, fileType?: FileTypeResult) => Promise<FileTypeResult | undefined>;
428
+ ```
429
+
430
+ ## Abort signal
431
+
432
+ Some async operations can be aborted by passing an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to the `FileTypeParser` constructor.
433
+
434
+ ```js
435
+ import {FileTypeParser} from 'file-type';
436
+
437
+ const abortController = new AbortController()
438
+
439
+ const parser = new FileTypeParser({abortSignal: abortController.signal});
440
+
441
+ const promise = parser.fromStream(blob.stream());
442
+
443
+ abortController.abort(); // Abort file-type reading from the Blob stream.
444
+ ```
445
+
446
+ ## Supported file types
447
+
448
+ - [`3g2`](https://en.wikipedia.org/wiki/3GP_and_3G2#3G2) - Multimedia container format defined by the 3GPP2 for 3G CDMA2000 multimedia services
449
+ - [`3gp`](https://en.wikipedia.org/wiki/3GP_and_3G2#3GP) - Multimedia container format defined by the Third Generation Partnership Project (3GPP) for 3G UMTS multimedia services
450
+ - [`3mf`](https://en.wikipedia.org/wiki/3D_Manufacturing_Format) - 3D Manufacturing Format
451
+ - [`7z`](https://en.wikipedia.org/wiki/7z) - 7-Zip archive
452
+ - [`Z`](https://fileinfo.com/extension/z) - Unix Compressed File
453
+ - [`aac`](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) - Advanced Audio Coding
454
+ - [`ac3`](https://www.atsc.org/standard/a522012-digital-audio-compression-ac-3-e-ac-3-standard-12172012/) - ATSC A/52 Audio File
455
+ - [`ace`](https://en.wikipedia.org/wiki/ACE_(compressed_file_format)) - ACE archive
456
+ - [`aif`](https://en.wikipedia.org/wiki/Audio_Interchange_File_Format) - Audio Interchange file
457
+ - [`alias`](https://en.wikipedia.org/wiki/Alias_%28Mac_OS%29) - macOS Alias file
458
+ - [`amr`](https://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec) - Adaptive Multi-Rate audio codec
459
+ - [`ape`](https://en.wikipedia.org/wiki/Monkey%27s_Audio) - Monkey's Audio
460
+ - [`apk`](https://en.wikipedia.org/wiki/Apk_(file_format)) - Android package format
461
+ - [`apng`](https://en.wikipedia.org/wiki/APNG) - Animated Portable Network Graphics
462
+ - [`ar`](https://en.wikipedia.org/wiki/Ar_(Unix)) - Archive file
463
+ - [`arj`](https://en.wikipedia.org/wiki/ARJ) - Archive file
464
+ - [`arrow`](https://arrow.apache.org) - Columnar format for tables of data
465
+ - [`arw`](https://en.wikipedia.org/wiki/Raw_image_format#ARW) - Sony Alpha Raw image file
466
+ - [`asar`](https://github.com/electron/asar#format) - Archive format primarily used to enclose Electron applications
467
+ - [`asf`](https://en.wikipedia.org/wiki/Advanced_Systems_Format) - Advanced Systems Format
468
+ - [`avi`](https://en.wikipedia.org/wiki/Audio_Video_Interleave) - Audio Video Interleave file
469
+ - [`avif`](https://en.wikipedia.org/wiki/AV1#AV1_Image_File_Format_(AVIF)) - AV1 Image File Format
470
+ - [`avro`](https://en.wikipedia.org/wiki/Apache_Avro#Avro_Object_Container_File) - Object container file developed by Apache Avro
471
+ - [`blend`](https://wiki.blender.org/index.php/Dev:Source/Architecture/File_Format) - Blender project
472
+ - [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format) - Bitmap image file
473
+ - [`bpg`](https://bellard.org/bpg/) - Better Portable Graphics file
474
+ - [`bz2`](https://en.wikipedia.org/wiki/Bzip2) - Archive file
475
+ - [`cab`](https://en.wikipedia.org/wiki/Cabinet_(file_format)) - Cabinet file
476
+ - [`cfb`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) - Compound File Binary Format
477
+ - [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help
478
+ - [`class`](https://en.wikipedia.org/wiki/Java_class_file) - Java class file
479
+ - [`cpio`](https://en.wikipedia.org/wiki/Cpio) - Cpio archive
480
+ - [`cr2`](https://fileinfo.com/extension/cr2) - Canon Raw image file (v2)
481
+ - [`cr3`](https://fileinfo.com/extension/cr3) - Canon Raw image file (v3)
482
+ - [`crx`](https://developer.chrome.com/extensions/crx) - Google Chrome extension
483
+ - [`cur`](https://en.wikipedia.org/wiki/ICO_(file_format)) - Icon file
484
+ - [`dat`](https://en.wikipedia.org/wiki/Windows_Registry) - Windows registry hive file
485
+ - [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File
486
+ - [`deb`](https://en.wikipedia.org/wiki/Deb_(file_format)) - Debian package
487
+ - [`dmg`](https://en.wikipedia.org/wiki/Apple_Disk_Image) - Apple Disk Image
488
+ - [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Adobe Digital Negative image file
489
+ - [`docm`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft Word macro-enabled document
490
+ - [`docx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Word document
491
+ - [`dotm`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft Word macro-enabled template
492
+ - [`dotx`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft Word template
493
+ - [`drc`](https://en.wikipedia.org/wiki/Zstandard) - Google's Draco 3D Data Compression
494
+ - [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)
495
+ - [`dwg`](https://en.wikipedia.org/wiki/.dwg) - Autodesk CAD file
496
+ - [`elf`](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) - Unix Executable and Linkable Format
497
+ - [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType) - Embedded OpenType font
498
+ - [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript
499
+ - [`epub`](https://en.wikipedia.org/wiki/EPUB) - E-book file
500
+ - [`exe`](https://en.wikipedia.org/wiki/.exe) - Executable file
501
+ - [`f4a`](https://en.wikipedia.org/wiki/Flash_Video) - Audio-only ISO base media file format used by Adobe Flash Player
502
+ - [`f4b`](https://en.wikipedia.org/wiki/Flash_Video) - Audiobook and podcast ISO base media file format used by Adobe Flash Player
503
+ - [`f4p`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format protected by Adobe Access DRM used by Adobe Flash Player
504
+ - [`f4v`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format used by Adobe Flash Player
505
+ - [`fbx`](https://en.wikipedia.org/wiki/FBX) - Filmbox is a proprietary file format used to provide interoperability between digital content creation apps.
506
+ - [`flac`](https://en.wikipedia.org/wiki/FLAC) - Free Lossless Audio Codec
507
+ - [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format) - Free Lossless Image Format
508
+ - [`flv`](https://en.wikipedia.org/wiki/Flash_Video) - Flash video
509
+ - [`gif`](https://en.wikipedia.org/wiki/GIF) - Graphics Interchange Format
510
+ - [`glb`](https://github.com/KhronosGroup/glTF) - GL Transmission Format
511
+ - [`gz`](https://en.wikipedia.org/wiki/Gzip) - Archive file
512
+ - [`heic`](https://nokiatech.github.io/heif/technical.html) - High Efficiency Image File Format
513
+ - [`icc`](https://en.wikipedia.org/wiki/ICC_profile) - ICC Profile
514
+ - [`icns`](https://en.wikipedia.org/wiki/Apple_Icon_Image_format) - Apple Icon image
515
+ - [`ico`](https://en.wikipedia.org/wiki/ICO_(file_format)) - Windows icon file
516
+ - [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
517
+ - [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format) - Adobe InDesign document
518
+ - [`it`](https://wiki.openmpt.org/Manual:_Module_formats#The_Impulse_Tracker_format_.28.it.29) - Audio module format: Impulse Tracker
519
+ - [`j2c`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
520
+ - [`jar`](https://en.wikipedia.org/wiki/JAR_(file_format)) - Java archive
521
+ - [`jls`](https://en.wikipedia.org/wiki/Lossless_JPEG#JPEG-LS) - Lossless/near-lossless compression standard for continuous-tone images
522
+ - [`jmp`](https://en.wikipedia.org/wiki/JMP_(statistical_software)) - JMP data file format by SAS Institute
523
+ - [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
524
+ - [`jpg`](https://en.wikipedia.org/wiki/JPEG) - Joint Photographic Experts Group image
525
+ - [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
526
+ - [`jpx`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
527
+ - [`jxl`](https://en.wikipedia.org/wiki/JPEG_XL) - JPEG XL image format
528
+ - [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR) - Joint Photographic Experts Group extended range
529
+ - [`ktx`](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) - OpenGL and OpenGL ES textures
530
+ - [`lnk`](https://en.wikipedia.org/wiki/Shortcut_%28computing%29#Microsoft_Windows) - Microsoft Windows file shortcut
531
+ - [`lz`](https://en.wikipedia.org/wiki/Lzip) - Archive file
532
+ - [`lz4`](https://en.wikipedia.org/wiki/LZ4_(compression_algorithm)) - Compressed archive created by one of a variety of LZ4 compression utilities
533
+ - [`lzh`](https://en.wikipedia.org/wiki/LHA_(file_format)) - LZH archive
534
+ - [`m4a`](https://en.wikipedia.org/wiki/M4A) - Audio-only MPEG-4 files
535
+ - [`m4b`](https://en.wikipedia.org/wiki/M4B) - Audiobook and podcast MPEG-4 files, which also contain metadata including chapter markers, images, and hyperlinks
536
+ - [`m4p`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 files with audio streams encrypted by FairPlay Digital Rights Management as were sold through the iTunes Store
537
+ - [`m4v`](https://en.wikipedia.org/wiki/M4V) - Video container format developed by Apple, which is very similar to the MP4 format
538
+ - [`macho`](https://en.wikipedia.org/wiki/Mach-O) - Mach-O binary format
539
+ - [`mid`](https://en.wikipedia.org/wiki/MIDI) - Musical Instrument Digital Interface file
540
+ - [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Dedicated meta information format which supports storage of binary as well as textual meta information
541
+ - [`mj2`](https://en.wikipedia.org/wiki/Motion_JPEG_2000) - Motion JPEG 2000
542
+ - [`mkv`](https://en.wikipedia.org/wiki/Matroska) - Matroska video file
543
+ - [`mobi`](https://en.wikipedia.org/wiki/Mobipocket) - Mobipocket
544
+ - [`mov`](https://en.wikipedia.org/wiki/QuickTime_File_Format) - QuickTime video file
545
+ - [`mp1`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_I) - MPEG-1 Audio Layer I
546
+ - [`mp2`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_II) - MPEG-1 Audio Layer II
547
+ - [`mp3`](https://en.wikipedia.org/wiki/MP3) - Audio file
548
+ - [`mp4`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 Part 14 video file
549
+ - [`mpc`](https://en.wikipedia.org/wiki/Musepack) - Musepack (SV7 & SV8)
550
+ - [`mpg`](https://en.wikipedia.org/wiki/MPEG-1) - MPEG-1 file
551
+ - [`mts`](https://en.wikipedia.org/wiki/.m2ts) - MPEG-2 Transport Stream, both raw and Blu-ray Disc Audio-Video (BDAV) versions
552
+ - [`mxf`](https://en.wikipedia.org/wiki/Material_Exchange_Format) - Material Exchange Format
553
+ - [`nef`](https://www.nikonusa.com/en/learn-and-explore/a/products-and-innovation/nikon-electronic-format-nef.html) - Nikon Electronic Format image file
554
+ - [`nes`](https://fileinfo.com/extension/nes) - Nintendo NES ROM
555
+ - [`odg`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for drawing
556
+ - [`odp`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for presentations
557
+ - [`ods`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for spreadsheets
558
+ - [`odt`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for word processing
559
+ - [`oga`](https://en.wikipedia.org/wiki/Ogg) - Audio file
560
+ - [`ogg`](https://en.wikipedia.org/wiki/Ogg) - Audio file
561
+ - [`ogm`](https://en.wikipedia.org/wiki/Ogg) - Audio file
562
+ - [`ogv`](https://en.wikipedia.org/wiki/Ogg) - Audio file
563
+ - [`ogx`](https://en.wikipedia.org/wiki/Ogg) - Audio file
564
+ - [`opus`](https://en.wikipedia.org/wiki/Opus_(audio_format)) - Audio file
565
+ - [`orf`](https://en.wikipedia.org/wiki/ORF_format) - Olympus Raw image file
566
+ - [`otf`](https://en.wikipedia.org/wiki/OpenType) - OpenType font
567
+ - [`otg`](https://en.wikipedia.org/wiki/OpenDocument_technical_specification#Templates) - OpenDocument template for drawing
568
+ - [`otp`](https://en.wikipedia.org/wiki/OpenDocument_technical_specification#Templates) - OpenDocument template for presentations
569
+ - [`ots`](https://en.wikipedia.org/wiki/OpenDocument_technical_specification#Templates) - OpenDocument template for spreadsheets
570
+ - [`ott`](https://en.wikipedia.org/wiki/OpenDocument_technical_specification#Templates) - OpenDocument template for word processing
571
+ - [`parquet`](https://en.wikipedia.org/wiki/Apache_Parquet) - Apache Parquet
572
+ - [`pcap`](https://wiki.wireshark.org/Development/LibpcapFileFormat) - Libpcap File Format
573
+ - [`pdf`](https://en.wikipedia.org/wiki/Portable_Document_Format) - Portable Document Format
574
+ - [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - Pretty Good Privacy
575
+ - [`png`](https://en.wikipedia.org/wiki/Portable_Network_Graphics) - Portable Network Graphics
576
+ - [`potm`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft PowerPoint macro-enabled template
577
+ - [`potx`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft PowerPoint template
578
+ - [`ppsm`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions#PowerPoint) - Office PowerPoint 2007 macro-enabled slide show
579
+ - [`ppsx`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions#PowerPoint) - Office PowerPoint 2007 slide show
580
+ - [`pptm`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft PowerPoint macro-enabled document
581
+ - [`pptx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft PowerPoint document
582
+ - [`ps`](https://en.wikipedia.org/wiki/Postscript) - Postscript
583
+ - [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format) - Adobe Photoshop document
584
+ - [`pst`](https://en.wikipedia.org/wiki/Personal_Storage_Table) - Personal Storage Table file
585
+ - [`qcp`](https://en.wikipedia.org/wiki/QCP) - Tagged and chunked data
586
+ - [`raf`](https://en.wikipedia.org/wiki/Raw_image_format) - Fujifilm RAW image file
587
+ - [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format)) - Archive file
588
+ - [`reg`](https://en.wikipedia.org/wiki/Windows_Registry) - Windows registry (entries) file format
589
+ - [`rm`](https://en.wikipedia.org/wiki/RealMedia) - RealMedia
590
+ - [`rpm`](https://fileinfo.com/extension/rpm) - Red Hat Package Manager file
591
+ - [`rtf`](https://en.wikipedia.org/wiki/Rich_Text_Format) - Rich Text Format
592
+ - [`rw2`](https://en.wikipedia.org/wiki/Raw_image_format) - Panasonic RAW image file
593
+ - [`s3m`](https://wiki.openmpt.org/Manual:_Module_formats#The_ScreamTracker_3_format_.28.s3m.29) - Audio module format: ScreamTracker 3
594
+ - [`sav`](https://en.wikipedia.org/wiki/SPSS) - SPSS Statistical Data File
595
+ - [`shp`](https://en.wikipedia.org/wiki/Shapefile) - Geospatial vector data format
596
+ - [`skp`](https://en.wikipedia.org/wiki/SketchUp) - SketchUp
597
+ - [`spx`](https://en.wikipedia.org/wiki/Ogg) - Audio file
598
+ - [`sqlite`](https://www.sqlite.org/fileformat2.html) - SQLite file
599
+ - [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Standard Tesselated Geometry File Format (ASCII only)
600
+ - [`swf`](https://en.wikipedia.org/wiki/SWF) - Adobe Flash Player file
601
+ - [`tar`](https://en.wikipedia.org/wiki/Tar_(computing)#File_format) - Tape archive or tarball
602
+ - [`tar.gz`](https://en.wikipedia.org/wiki/Gzip) - Gzipped tape archive (tarball)
603
+ - [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format) - Tagged Image file
604
+ - [`ttc`](https://en.wikipedia.org/wiki/TrueType#TrueType_Collection) - TrueType Collection font
605
+ - [`ttf`](https://en.wikipedia.org/wiki/TrueType) - TrueType font
606
+ - [`vcf`](https://en.wikipedia.org/wiki/VCard) - vCard
607
+ - [`voc`](https://wiki.multimedia.cx/index.php/Creative_Voice) - Creative Voice File
608
+ - [`vsdx`](https://en.wikipedia.org/wiki/Microsoft_Visio) - Microsoft Visio File
609
+ - [`vtt`](https://en.wikipedia.org/wiki/WebVTT) - WebVTT File (for video captions)
610
+ - [`wasm`](https://en.wikipedia.org/wiki/WebAssembly) - WebAssembly intermediate compiled format
611
+ - [`wav`](https://en.wikipedia.org/wiki/WAV) - Waveform Audio file
612
+ - [`webm`](https://en.wikipedia.org/wiki/WebM) - Web video file
613
+ - [`webp`](https://en.wikipedia.org/wiki/WebP) - Web Picture format
614
+ - [`woff`](https://en.wikipedia.org/wiki/Web_Open_Font_Format) - Web Open Font Format
615
+ - [`woff2`](https://en.wikipedia.org/wiki/Web_Open_Font_Format) - Web Open Font Format
616
+ - [`wv`](https://en.wikipedia.org/wiki/WavPack) - WavPack
617
+ - [`xcf`](https://en.wikipedia.org/wiki/XCF_(file_format)) - eXperimental Computing Facility
618
+ - [`xlsm`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft Excel macro-enabled document
619
+ - [`xlsx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Excel document
620
+ - [`xltm`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft Excel macro-enabled template
621
+ - [`xltx`](https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions) - Microsoft Excel template
622
+ - [`xm`](https://wiki.openmpt.org/Manual:_Module_formats#The_FastTracker_2_format_.28.xm.29) - Audio module format: FastTracker 2
623
+ - [`xml`](https://en.wikipedia.org/wiki/XML) - eXtensible Markup Language
624
+ - [`xpi`](https://en.wikipedia.org/wiki/XPInstall) - XPInstall file
625
+ - [`xz`](https://en.wikipedia.org/wiki/Xz) - Compressed file
626
+ - [`zip`](https://en.wikipedia.org/wiki/Zip_(file_format)) - Archive file
627
+ - [`zst`](https://en.wikipedia.org/wiki/Zstandard) - Archive file
628
+
629
+ *[Pull requests](.github/pull_request_template.md) are welcome for additional commonly used file types.*
630
+
631
+ The following file types will not be accepted:
632
+ - [MS-CFB: Microsoft Compound File Binary File Format based formats](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cfb/53989ce4-7b05-4f8d-829b-d08d6148375b), too old and difficult to parse:
633
+ - `.doc` - Microsoft Word 97-2003 Document
634
+ - `.xls` - Microsoft Excel 97-2003 Document
635
+ - `.ppt` - Microsoft PowerPoint97-2003 Document
636
+ - `.msi` - Microsoft Windows Installer
637
+ - `.csv` - [Reason.](https://github.com/sindresorhus/file-type/issues/264#issuecomment-568439196)
638
+ - `.svg` - Supported by [third-party detector](#available-third-party-file-type-detectors).
639
+
640
+ #### tokenizer
641
+
642
+ Type: [`ITokenizer`](https://github.com/Borewit/strtok3#tokenizer)
643
+
644
+ Usable as source of the examined file.
645
+
646
+ #### fileType
647
+
648
+ Type: `FileTypeResult`
649
+
650
+ An object having an `ext` (extension) and `mime` (mime type) property.
651
+
652
+ Detected by the standard detections or a previous custom detection. Undefined if no matching fileTypeResult could be found.
653
+
654
+ ## Related
655
+
656
+ - [file-type-cli](https://github.com/sindresorhus/file-type-cli) - CLI for this module
657
+ - [image-dimensions](https://github.com/sindresorhus/image-dimensions) - Get the dimensions of an image
658
+
659
+ ## Maintainers
660
+
661
+ - [Sindre Sorhus](https://github.com/sindresorhus)
662
+ - [Borewit](https://github.com/Borewit)