file-type 16.5.0 → 17.0.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/browser.d.ts +22 -28
- package/browser.js +21 -19
- package/core.d.ts +362 -356
- package/core.js +1214 -1155
- package/index.d.ts +4 -17
- package/index.js +5 -24
- package/package.json +28 -16
- package/readme.md +143 -97
- package/supported.js +275 -278
- package/util.js +10 -12
package/core.d.ts
CHANGED
|
@@ -1,386 +1,392 @@
|
|
|
1
|
-
|
|
2
|
-
import {Readable as ReadableStream} from 'stream';
|
|
1
|
+
import {Readable as ReadableStream} from 'node:stream';
|
|
3
2
|
import {ITokenizer} from 'strtok3/lib/core';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
| 'vcf';
|
|
145
|
-
|
|
146
|
-
type MimeType =
|
|
147
|
-
| 'image/jpeg'
|
|
148
|
-
| 'image/png'
|
|
149
|
-
| 'image/gif'
|
|
150
|
-
| 'image/webp'
|
|
151
|
-
| 'image/flif'
|
|
152
|
-
| 'image/x-xcf'
|
|
153
|
-
| 'image/x-canon-cr2'
|
|
154
|
-
| 'image/x-canon-cr3'
|
|
155
|
-
| 'image/tiff'
|
|
156
|
-
| 'image/bmp'
|
|
157
|
-
| 'image/icns'
|
|
158
|
-
| 'image/vnd.ms-photo'
|
|
159
|
-
| 'image/vnd.adobe.photoshop'
|
|
160
|
-
| 'application/x-indesign'
|
|
161
|
-
| 'application/epub+zip'
|
|
162
|
-
| 'application/x-xpinstall'
|
|
163
|
-
| 'application/vnd.oasis.opendocument.text'
|
|
164
|
-
| 'application/vnd.oasis.opendocument.spreadsheet'
|
|
165
|
-
| 'application/vnd.oasis.opendocument.presentation'
|
|
166
|
-
| 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
167
|
-
| 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
|
168
|
-
| 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
169
|
-
| 'application/zip'
|
|
170
|
-
| 'application/x-tar'
|
|
171
|
-
| 'application/x-rar-compressed'
|
|
172
|
-
| 'application/gzip'
|
|
173
|
-
| 'application/x-bzip2'
|
|
174
|
-
| 'application/x-7z-compressed'
|
|
175
|
-
| 'application/x-apple-diskimage'
|
|
176
|
-
| 'video/mp4'
|
|
177
|
-
| 'audio/midi'
|
|
178
|
-
| 'video/x-matroska'
|
|
179
|
-
| 'video/webm'
|
|
180
|
-
| 'video/quicktime'
|
|
181
|
-
| 'video/vnd.avi'
|
|
182
|
-
| 'audio/vnd.wave'
|
|
183
|
-
| 'audio/qcelp'
|
|
184
|
-
| 'audio/x-ms-asf'
|
|
185
|
-
| 'video/x-ms-asf'
|
|
186
|
-
| 'application/vnd.ms-asf'
|
|
187
|
-
| 'video/mpeg'
|
|
188
|
-
| 'video/3gpp'
|
|
189
|
-
| 'audio/mpeg'
|
|
190
|
-
| 'audio/mp4' // RFC 4337
|
|
191
|
-
| 'audio/opus'
|
|
192
|
-
| 'video/ogg'
|
|
193
|
-
| 'audio/ogg'
|
|
194
|
-
| 'application/ogg'
|
|
195
|
-
| 'audio/x-flac'
|
|
196
|
-
| 'audio/ape'
|
|
197
|
-
| 'audio/wavpack'
|
|
198
|
-
| 'audio/amr'
|
|
199
|
-
| 'application/pdf'
|
|
200
|
-
| 'application/x-msdownload'
|
|
201
|
-
| 'application/x-shockwave-flash'
|
|
202
|
-
| 'application/rtf'
|
|
203
|
-
| 'application/wasm'
|
|
204
|
-
| 'font/woff'
|
|
205
|
-
| 'font/woff2'
|
|
206
|
-
| 'application/vnd.ms-fontobject'
|
|
207
|
-
| 'font/ttf'
|
|
208
|
-
| 'font/otf'
|
|
209
|
-
| 'image/x-icon'
|
|
210
|
-
| 'video/x-flv'
|
|
211
|
-
| 'application/postscript'
|
|
212
|
-
| 'application/eps'
|
|
213
|
-
| 'application/x-xz'
|
|
214
|
-
| 'application/x-sqlite3'
|
|
215
|
-
| 'application/x-nintendo-nes-rom'
|
|
216
|
-
| 'application/x-google-chrome-extension'
|
|
217
|
-
| 'application/vnd.ms-cab-compressed'
|
|
218
|
-
| 'application/x-deb'
|
|
219
|
-
| 'application/x-unix-archive'
|
|
220
|
-
| 'application/x-rpm'
|
|
221
|
-
| 'application/x-compress'
|
|
222
|
-
| 'application/x-lzip'
|
|
223
|
-
| 'application/x-cfb'
|
|
224
|
-
| 'application/x-mie'
|
|
225
|
-
| 'application/x-apache-arrow'
|
|
226
|
-
| 'application/mxf'
|
|
227
|
-
| 'video/mp2t'
|
|
228
|
-
| 'application/x-blender'
|
|
229
|
-
| 'image/bpg'
|
|
230
|
-
| 'image/jp2'
|
|
231
|
-
| 'image/jpx'
|
|
232
|
-
| 'image/jpm'
|
|
233
|
-
| 'image/mj2'
|
|
234
|
-
| 'audio/aiff'
|
|
235
|
-
| 'application/xml'
|
|
236
|
-
| 'application/x-mobipocket-ebook'
|
|
237
|
-
| 'image/heif'
|
|
238
|
-
| 'image/heif-sequence'
|
|
239
|
-
| 'image/heic'
|
|
240
|
-
| 'image/heic-sequence'
|
|
241
|
-
| 'image/ktx'
|
|
242
|
-
| 'application/dicom'
|
|
243
|
-
| 'audio/x-musepack'
|
|
244
|
-
| 'text/calendar'
|
|
245
|
-
| 'text/vcard'
|
|
246
|
-
| 'model/gltf-binary'
|
|
247
|
-
| 'application/vnd.tcpdump.pcap'
|
|
248
|
-
| 'audio/x-dsf' // Non-standard
|
|
249
|
-
| 'application/x.ms.shortcut' // Invented by us
|
|
250
|
-
| 'application/x.apple.alias' // Invented by us
|
|
251
|
-
| 'audio/x-voc'
|
|
252
|
-
| 'audio/vnd.dolby.dd-raw'
|
|
253
|
-
| 'audio/x-m4a'
|
|
254
|
-
| 'image/apng'
|
|
255
|
-
| 'image/x-olympus-orf'
|
|
256
|
-
| 'image/x-sony-arw'
|
|
257
|
-
| 'image/x-adobe-dng'
|
|
258
|
-
| 'image/x-nikon-nef'
|
|
259
|
-
| 'image/x-panasonic-rw2'
|
|
260
|
-
| 'image/x-fujifilm-raf'
|
|
261
|
-
| 'video/x-m4v'
|
|
262
|
-
| 'video/3gpp2'
|
|
263
|
-
| 'application/x-esri-shape'
|
|
264
|
-
| 'audio/aac'
|
|
265
|
-
| 'audio/x-it'
|
|
266
|
-
| 'audio/x-s3m'
|
|
267
|
-
| 'audio/x-xm'
|
|
268
|
-
| 'video/MP1S'
|
|
269
|
-
| 'video/MP2P'
|
|
270
|
-
| 'application/vnd.sketchup.skp'
|
|
271
|
-
| 'image/avif'
|
|
272
|
-
| 'application/x-lzh-compressed'
|
|
273
|
-
| 'application/pgp-encrypted'
|
|
274
|
-
| 'application/x-asar'
|
|
275
|
-
| 'model/stl'
|
|
276
|
-
| 'application/vnd.ms-htmlhelp'
|
|
277
|
-
| 'model/3mf'
|
|
278
|
-
| 'image/jxl'
|
|
279
|
-
| 'application/zstd';
|
|
280
|
-
|
|
281
|
-
interface FileTypeResult {
|
|
282
|
-
/**
|
|
283
|
-
One of the supported [file types](https://github.com/sindresorhus/file-type#supported-file-types).
|
|
284
|
-
*/
|
|
285
|
-
readonly ext: FileExtension;
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type).
|
|
289
|
-
*/
|
|
290
|
-
readonly mime: MimeType;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
type ReadableStreamWithFileType = ReadableStream & {
|
|
294
|
-
readonly fileType?: FileTypeResult;
|
|
295
|
-
};
|
|
4
|
+
export type FileExtension =
|
|
5
|
+
| 'jpg'
|
|
6
|
+
| 'png'
|
|
7
|
+
| 'apng'
|
|
8
|
+
| 'gif'
|
|
9
|
+
| 'webp'
|
|
10
|
+
| 'flif'
|
|
11
|
+
| 'xcf'
|
|
12
|
+
| 'cr2'
|
|
13
|
+
| 'cr3'
|
|
14
|
+
| 'orf'
|
|
15
|
+
| 'arw'
|
|
16
|
+
| 'dng'
|
|
17
|
+
| 'nef'
|
|
18
|
+
| 'rw2'
|
|
19
|
+
| 'raf'
|
|
20
|
+
| 'tif'
|
|
21
|
+
| 'bmp'
|
|
22
|
+
| 'icns'
|
|
23
|
+
| 'jxr'
|
|
24
|
+
| 'psd'
|
|
25
|
+
| 'indd'
|
|
26
|
+
| 'zip'
|
|
27
|
+
| 'tar'
|
|
28
|
+
| 'rar'
|
|
29
|
+
| 'gz'
|
|
30
|
+
| 'bz2'
|
|
31
|
+
| '7z'
|
|
32
|
+
| 'dmg'
|
|
33
|
+
| 'mp4'
|
|
34
|
+
| 'mid'
|
|
35
|
+
| 'mkv'
|
|
36
|
+
| 'webm'
|
|
37
|
+
| 'mov'
|
|
38
|
+
| 'avi'
|
|
39
|
+
| 'mpg'
|
|
40
|
+
| 'mp2'
|
|
41
|
+
| 'mp3'
|
|
42
|
+
| 'm4a'
|
|
43
|
+
| 'ogg'
|
|
44
|
+
| 'opus'
|
|
45
|
+
| 'flac'
|
|
46
|
+
| 'wav'
|
|
47
|
+
| 'qcp'
|
|
48
|
+
| 'amr'
|
|
49
|
+
| 'pdf'
|
|
50
|
+
| 'epub'
|
|
51
|
+
| 'mobi'
|
|
52
|
+
| 'exe'
|
|
53
|
+
| 'swf'
|
|
54
|
+
| 'rtf'
|
|
55
|
+
| 'woff'
|
|
56
|
+
| 'woff2'
|
|
57
|
+
| 'eot'
|
|
58
|
+
| 'ttf'
|
|
59
|
+
| 'otf'
|
|
60
|
+
| 'ico'
|
|
61
|
+
| 'flv'
|
|
62
|
+
| 'ps'
|
|
63
|
+
| 'xz'
|
|
64
|
+
| 'sqlite'
|
|
65
|
+
| 'nes'
|
|
66
|
+
| 'crx'
|
|
67
|
+
| 'xpi'
|
|
68
|
+
| 'cab'
|
|
69
|
+
| 'deb'
|
|
70
|
+
| 'ar'
|
|
71
|
+
| 'rpm'
|
|
72
|
+
| 'Z'
|
|
73
|
+
| 'lz'
|
|
74
|
+
| 'cfb'
|
|
75
|
+
| 'mxf'
|
|
76
|
+
| 'mts'
|
|
77
|
+
| 'wasm'
|
|
78
|
+
| 'blend'
|
|
79
|
+
| 'bpg'
|
|
80
|
+
| 'docx'
|
|
81
|
+
| 'pptx'
|
|
82
|
+
| 'xlsx'
|
|
83
|
+
| '3gp'
|
|
84
|
+
| '3g2'
|
|
85
|
+
| 'jp2'
|
|
86
|
+
| 'jpm'
|
|
87
|
+
| 'jpx'
|
|
88
|
+
| 'mj2'
|
|
89
|
+
| 'aif'
|
|
90
|
+
| 'odt'
|
|
91
|
+
| 'ods'
|
|
92
|
+
| 'odp'
|
|
93
|
+
| 'xml'
|
|
94
|
+
| 'heic'
|
|
95
|
+
| 'cur'
|
|
96
|
+
| 'ktx'
|
|
97
|
+
| 'ape'
|
|
98
|
+
| 'wv'
|
|
99
|
+
| 'asf'
|
|
100
|
+
| 'dcm'
|
|
101
|
+
| 'mpc'
|
|
102
|
+
| 'ics'
|
|
103
|
+
| 'glb'
|
|
104
|
+
| 'pcap'
|
|
105
|
+
| 'dsf'
|
|
106
|
+
| 'lnk'
|
|
107
|
+
| 'alias'
|
|
108
|
+
| 'voc'
|
|
109
|
+
| 'ac3'
|
|
110
|
+
| 'm4b'
|
|
111
|
+
| 'm4p'
|
|
112
|
+
| 'm4v'
|
|
113
|
+
| 'f4a'
|
|
114
|
+
| 'f4b'
|
|
115
|
+
| 'f4p'
|
|
116
|
+
| 'f4v'
|
|
117
|
+
| 'mie'
|
|
118
|
+
| 'ogv'
|
|
119
|
+
| 'ogm'
|
|
120
|
+
| 'oga'
|
|
121
|
+
| 'spx'
|
|
122
|
+
| 'ogx'
|
|
123
|
+
| 'arrow'
|
|
124
|
+
| 'shp'
|
|
125
|
+
| 'aac'
|
|
126
|
+
| 'mp1'
|
|
127
|
+
| 'it'
|
|
128
|
+
| 's3m'
|
|
129
|
+
| 'xm'
|
|
130
|
+
| 'ai'
|
|
131
|
+
| 'skp'
|
|
132
|
+
| 'avif'
|
|
133
|
+
| 'eps'
|
|
134
|
+
| 'lzh'
|
|
135
|
+
| 'pgp'
|
|
136
|
+
| 'asar'
|
|
137
|
+
| 'stl'
|
|
138
|
+
| 'chm'
|
|
139
|
+
| '3mf'
|
|
140
|
+
| 'zst'
|
|
141
|
+
| 'jxl'
|
|
142
|
+
| 'vcf';
|
|
296
143
|
|
|
144
|
+
export type MimeType =
|
|
145
|
+
| 'image/jpeg'
|
|
146
|
+
| 'image/png'
|
|
147
|
+
| 'image/gif'
|
|
148
|
+
| 'image/webp'
|
|
149
|
+
| 'image/flif'
|
|
150
|
+
| 'image/x-xcf'
|
|
151
|
+
| 'image/x-canon-cr2'
|
|
152
|
+
| 'image/x-canon-cr3'
|
|
153
|
+
| 'image/tiff'
|
|
154
|
+
| 'image/bmp'
|
|
155
|
+
| 'image/icns'
|
|
156
|
+
| 'image/vnd.ms-photo'
|
|
157
|
+
| 'image/vnd.adobe.photoshop'
|
|
158
|
+
| 'application/x-indesign'
|
|
159
|
+
| 'application/epub+zip'
|
|
160
|
+
| 'application/x-xpinstall'
|
|
161
|
+
| 'application/vnd.oasis.opendocument.text'
|
|
162
|
+
| 'application/vnd.oasis.opendocument.spreadsheet'
|
|
163
|
+
| 'application/vnd.oasis.opendocument.presentation'
|
|
164
|
+
| 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
165
|
+
| 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
|
166
|
+
| 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
167
|
+
| 'application/zip'
|
|
168
|
+
| 'application/x-tar'
|
|
169
|
+
| 'application/x-rar-compressed'
|
|
170
|
+
| 'application/gzip'
|
|
171
|
+
| 'application/x-bzip2'
|
|
172
|
+
| 'application/x-7z-compressed'
|
|
173
|
+
| 'application/x-apple-diskimage'
|
|
174
|
+
| 'video/mp4'
|
|
175
|
+
| 'audio/midi'
|
|
176
|
+
| 'video/x-matroska'
|
|
177
|
+
| 'video/webm'
|
|
178
|
+
| 'video/quicktime'
|
|
179
|
+
| 'video/vnd.avi'
|
|
180
|
+
| 'audio/vnd.wave'
|
|
181
|
+
| 'audio/qcelp'
|
|
182
|
+
| 'audio/x-ms-asf'
|
|
183
|
+
| 'video/x-ms-asf'
|
|
184
|
+
| 'application/vnd.ms-asf'
|
|
185
|
+
| 'video/mpeg'
|
|
186
|
+
| 'video/3gpp'
|
|
187
|
+
| 'audio/mpeg'
|
|
188
|
+
| 'audio/mp4' // RFC 4337
|
|
189
|
+
| 'audio/opus'
|
|
190
|
+
| 'video/ogg'
|
|
191
|
+
| 'audio/ogg'
|
|
192
|
+
| 'application/ogg'
|
|
193
|
+
| 'audio/x-flac'
|
|
194
|
+
| 'audio/ape'
|
|
195
|
+
| 'audio/wavpack'
|
|
196
|
+
| 'audio/amr'
|
|
197
|
+
| 'application/pdf'
|
|
198
|
+
| 'application/x-msdownload'
|
|
199
|
+
| 'application/x-shockwave-flash'
|
|
200
|
+
| 'application/rtf'
|
|
201
|
+
| 'application/wasm'
|
|
202
|
+
| 'font/woff'
|
|
203
|
+
| 'font/woff2'
|
|
204
|
+
| 'application/vnd.ms-fontobject'
|
|
205
|
+
| 'font/ttf'
|
|
206
|
+
| 'font/otf'
|
|
207
|
+
| 'image/x-icon'
|
|
208
|
+
| 'video/x-flv'
|
|
209
|
+
| 'application/postscript'
|
|
210
|
+
| 'application/eps'
|
|
211
|
+
| 'application/x-xz'
|
|
212
|
+
| 'application/x-sqlite3'
|
|
213
|
+
| 'application/x-nintendo-nes-rom'
|
|
214
|
+
| 'application/x-google-chrome-extension'
|
|
215
|
+
| 'application/vnd.ms-cab-compressed'
|
|
216
|
+
| 'application/x-deb'
|
|
217
|
+
| 'application/x-unix-archive'
|
|
218
|
+
| 'application/x-rpm'
|
|
219
|
+
| 'application/x-compress'
|
|
220
|
+
| 'application/x-lzip'
|
|
221
|
+
| 'application/x-cfb'
|
|
222
|
+
| 'application/x-mie'
|
|
223
|
+
| 'application/x-apache-arrow'
|
|
224
|
+
| 'application/mxf'
|
|
225
|
+
| 'video/mp2t'
|
|
226
|
+
| 'application/x-blender'
|
|
227
|
+
| 'image/bpg'
|
|
228
|
+
| 'image/jp2'
|
|
229
|
+
| 'image/jpx'
|
|
230
|
+
| 'image/jpm'
|
|
231
|
+
| 'image/mj2'
|
|
232
|
+
| 'audio/aiff'
|
|
233
|
+
| 'application/xml'
|
|
234
|
+
| 'application/x-mobipocket-ebook'
|
|
235
|
+
| 'image/heif'
|
|
236
|
+
| 'image/heif-sequence'
|
|
237
|
+
| 'image/heic'
|
|
238
|
+
| 'image/heic-sequence'
|
|
239
|
+
| 'image/ktx'
|
|
240
|
+
| 'application/dicom'
|
|
241
|
+
| 'audio/x-musepack'
|
|
242
|
+
| 'text/calendar'
|
|
243
|
+
| 'text/vcard'
|
|
244
|
+
| 'model/gltf-binary'
|
|
245
|
+
| 'application/vnd.tcpdump.pcap'
|
|
246
|
+
| 'audio/x-dsf' // Non-standard
|
|
247
|
+
| 'application/x.ms.shortcut' // Invented by us
|
|
248
|
+
| 'application/x.apple.alias' // Invented by us
|
|
249
|
+
| 'audio/x-voc'
|
|
250
|
+
| 'audio/vnd.dolby.dd-raw'
|
|
251
|
+
| 'audio/x-m4a'
|
|
252
|
+
| 'image/apng'
|
|
253
|
+
| 'image/x-olympus-orf'
|
|
254
|
+
| 'image/x-sony-arw'
|
|
255
|
+
| 'image/x-adobe-dng'
|
|
256
|
+
| 'image/x-nikon-nef'
|
|
257
|
+
| 'image/x-panasonic-rw2'
|
|
258
|
+
| 'image/x-fujifilm-raf'
|
|
259
|
+
| 'video/x-m4v'
|
|
260
|
+
| 'video/3gpp2'
|
|
261
|
+
| 'application/x-esri-shape'
|
|
262
|
+
| 'audio/aac'
|
|
263
|
+
| 'audio/x-it'
|
|
264
|
+
| 'audio/x-s3m'
|
|
265
|
+
| 'audio/x-xm'
|
|
266
|
+
| 'video/MP1S'
|
|
267
|
+
| 'video/MP2P'
|
|
268
|
+
| 'application/vnd.sketchup.skp'
|
|
269
|
+
| 'image/avif'
|
|
270
|
+
| 'application/x-lzh-compressed'
|
|
271
|
+
| 'application/pgp-encrypted'
|
|
272
|
+
| 'application/x-asar'
|
|
273
|
+
| 'model/stl'
|
|
274
|
+
| 'application/vnd.ms-htmlhelp'
|
|
275
|
+
| 'model/3mf'
|
|
276
|
+
| 'image/jxl'
|
|
277
|
+
| 'application/zstd';
|
|
278
|
+
|
|
279
|
+
export interface FileTypeResult {
|
|
297
280
|
/**
|
|
298
|
-
|
|
281
|
+
One of the supported [file types](https://github.com/sindresorhus/file-type#supported-file-types).
|
|
282
|
+
*/
|
|
283
|
+
readonly ext: FileExtension;
|
|
299
284
|
|
|
300
|
-
|
|
285
|
+
/**
|
|
286
|
+
The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type).
|
|
287
|
+
*/
|
|
288
|
+
readonly mime: MimeType;
|
|
289
|
+
}
|
|
301
290
|
|
|
302
|
-
|
|
291
|
+
export type ReadableStreamWithFileType = ReadableStream & {
|
|
292
|
+
readonly fileType?: FileTypeResult;
|
|
293
|
+
};
|
|
303
294
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
*/
|
|
307
|
-
function fromBuffer(buffer: Buffer | Uint8Array | ArrayBuffer): Promise<core.FileTypeResult | undefined>;
|
|
295
|
+
/**
|
|
296
|
+
Detect the file type of a `Buffer`, `Uint8Array`, or `ArrayBuffer`.
|
|
308
297
|
|
|
309
|
-
|
|
310
|
-
Detect the file type of a Node.js [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
|
|
298
|
+
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.
|
|
311
299
|
|
|
312
|
-
|
|
300
|
+
If file access is available, it is recommended to use `.fromFile()` instead.
|
|
313
301
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
302
|
+
@param buffer - An Uint8Array or Buffer representing file data. It works best if the buffer contains the entire file, it may work with a smaller portion as well.
|
|
303
|
+
@returns The detected file type and MIME type, or `undefined` when there is no match.
|
|
304
|
+
*/
|
|
305
|
+
export function fileTypeFromBuffer(buffer: Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
|
|
318
306
|
|
|
319
|
-
|
|
320
|
-
|
|
307
|
+
/**
|
|
308
|
+
Detect the file type of a Node.js [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
|
|
321
309
|
|
|
322
|
-
|
|
310
|
+
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.
|
|
323
311
|
|
|
324
|
-
|
|
312
|
+
@param stream - A readable stream representing file data.
|
|
313
|
+
@returns The detected file type and MIME type, or `undefined` when there is no match.
|
|
314
|
+
*/
|
|
315
|
+
export function fileTypeFromStream(stream: ReadableStream): Promise<FileTypeResult | undefined>;
|
|
325
316
|
|
|
326
|
-
|
|
317
|
+
/**
|
|
318
|
+
Detect the file type from an [`ITokenizer`](https://github.com/Borewit/strtok3#tokenizer) source.
|
|
327
319
|
|
|
328
|
-
|
|
329
|
-
import {makeTokenizer} = require('@tokenizer/http');
|
|
330
|
-
import FileType = require('file-type');
|
|
320
|
+
This method is used internally, but can also be used for a special "tokenizer" reader.
|
|
331
321
|
|
|
332
|
-
|
|
322
|
+
A tokenizer propagates the internal read functions, allowing alternative transport mechanisms, to access files, to be implemented and used.
|
|
333
323
|
|
|
334
|
-
|
|
335
|
-
const httpTokenizer = await makeTokenizer(audioTrackUrl);
|
|
336
|
-
const fileType = await FileType.fromTokenizer(httpTokenizer);
|
|
324
|
+
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 is able to *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.
|
|
337
325
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
```
|
|
326
|
+
```
|
|
327
|
+
import {makeTokenizer} from '@tokenizer/http';
|
|
328
|
+
import {fileTypeFromTokenizer} from 'file-type';
|
|
342
329
|
|
|
343
|
-
|
|
344
|
-
@returns The detected file type and MIME type, or `undefined` when there is no match.
|
|
345
|
-
*/
|
|
346
|
-
function fromTokenizer(tokenizer: ITokenizer): Promise<core.FileTypeResult | undefined>;
|
|
330
|
+
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';
|
|
347
331
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
*/
|
|
351
|
-
const extensions: Set<core.FileExtension>;
|
|
332
|
+
const httpTokenizer = await makeTokenizer(audioTrackUrl);
|
|
333
|
+
const fileType = await fileTypeFromTokenizer(httpTokenizer);
|
|
352
334
|
|
|
335
|
+
console.log(fileType);
|
|
336
|
+
//=> {ext: 'mp3', mime: 'audio/mpeg'}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
@param tokenizer - File source implementing the tokenizer interface.
|
|
340
|
+
@returns The detected file type and MIME type, or `undefined` when there is no match.
|
|
341
|
+
*/
|
|
342
|
+
export function fileTypeFromTokenizer(tokenizer: ITokenizer): Promise<FileTypeResult | undefined>;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
Supported file extensions.
|
|
346
|
+
*/
|
|
347
|
+
export const supportedExtensions: ReadonlySet<FileExtension>;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
Supported MIME types.
|
|
351
|
+
*/
|
|
352
|
+
export const supportedMimeTypes: ReadonlySet<MimeType>;
|
|
353
|
+
|
|
354
|
+
export interface StreamOptions {
|
|
353
355
|
/**
|
|
354
|
-
|
|
356
|
+
The default sample size in bytes.
|
|
357
|
+
|
|
358
|
+
@default 4100
|
|
355
359
|
*/
|
|
356
|
-
|
|
360
|
+
readonly sampleSize?: number;
|
|
361
|
+
}
|
|
357
362
|
|
|
358
|
-
|
|
359
|
-
|
|
363
|
+
/**
|
|
364
|
+
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 `FileType.fromFile()`.
|
|
360
365
|
|
|
361
|
-
|
|
362
|
-
|
|
366
|
+
This method can be handy to put in between a stream, but it comes with a price.
|
|
367
|
+
Internally `stream()` builds up a buffer of `sampleSize` bytes, used as a sample, to determine the file type.
|
|
368
|
+
The sample size impacts the file detection resolution.
|
|
369
|
+
A smaller sample size will result in lower probability of the best file type detection.
|
|
363
370
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
import * as fs from 'fs';
|
|
367
|
-
import * as crypto from 'crypto';
|
|
368
|
-
import fileType = require('file-type');
|
|
371
|
+
**Note:** This method is only available when using Node.js.
|
|
372
|
+
**Note:** Requires Node.js 14 or later.
|
|
369
373
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const decipher = crypto.createDecipheriv(alg, key, iv);
|
|
373
|
-
const stream = await fileType.stream(read.pipe(decipher));
|
|
374
|
+
@param readableStream - A [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) containing a file to examine.
|
|
375
|
+
@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 `FileType.fromFile()`.
|
|
374
376
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
+
@example
|
|
378
|
+
```
|
|
379
|
+
import got from 'got';
|
|
380
|
+
import {fileTypeStream} from 'file-type';
|
|
377
381
|
|
|
378
|
-
|
|
379
|
-
stream.pipe(write);
|
|
380
|
-
})();
|
|
381
|
-
```
|
|
382
|
-
*/
|
|
383
|
-
function stream(readableStream: ReadableStream): Promise<core.ReadableStreamWithFileType>
|
|
384
|
-
}
|
|
382
|
+
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
|
|
385
383
|
|
|
386
|
-
|
|
384
|
+
const stream1 = got.stream(url);
|
|
385
|
+
const stream2 = await fileTypeStream(stream1, {sampleSize: 1024});
|
|
386
|
+
|
|
387
|
+
if (stream2.fileType && stream2.fileType.mime === 'image/jpeg') {
|
|
388
|
+
// stream2 can be used to stream the JPEG image (from the very beginning of the stream)
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
*/
|
|
392
|
+
export function fileTypeStream(readableStream: ReadableStream, options?: StreamOptions): Promise<ReadableStreamWithFileType>;
|