file-type 18.0.0 → 18.1.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 +4 -4
- package/core.d.ts +14 -8
- package/core.js +34 -9
- package/index.d.ts +1 -2
- package/package.json +11 -6
- package/readme.md +8 -8
- package/supported.js +6 -0
package/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {FileTypeResult} from './core.js';
|
|
1
|
+
import type {FileTypeResult} from './core.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
Detect the file type of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
|
|
@@ -42,7 +42,7 @@ export {
|
|
|
42
42
|
fileTypeFromBuffer,
|
|
43
43
|
supportedExtensions,
|
|
44
44
|
supportedMimeTypes,
|
|
45
|
-
FileTypeResult,
|
|
46
|
-
FileExtension,
|
|
47
|
-
MimeType,
|
|
45
|
+
type FileTypeResult,
|
|
46
|
+
type FileExtension,
|
|
47
|
+
type MimeType,
|
|
48
48
|
} from './core.js';
|
package/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {Readable as ReadableStream} from 'node:stream';
|
|
2
|
-
import {ITokenizer} from 'strtok3';
|
|
1
|
+
import type {Readable as ReadableStream} from 'node:stream';
|
|
2
|
+
import type {ITokenizer} from 'strtok3';
|
|
3
3
|
|
|
4
4
|
export type FileExtension =
|
|
5
5
|
| 'jpg'
|
|
@@ -140,7 +140,10 @@ export type FileExtension =
|
|
|
140
140
|
| '3mf'
|
|
141
141
|
| 'zst'
|
|
142
142
|
| 'jxl'
|
|
143
|
-
| 'vcf'
|
|
143
|
+
| 'vcf'
|
|
144
|
+
| 'jls'
|
|
145
|
+
| 'pst'
|
|
146
|
+
| 'dwg';
|
|
144
147
|
|
|
145
148
|
export type MimeType =
|
|
146
149
|
| 'image/jpeg'
|
|
@@ -276,9 +279,12 @@ export type MimeType =
|
|
|
276
279
|
| 'application/vnd.ms-htmlhelp'
|
|
277
280
|
| 'model/3mf'
|
|
278
281
|
| 'image/jxl'
|
|
279
|
-
| 'application/zstd'
|
|
282
|
+
| 'application/zstd'
|
|
283
|
+
| 'image/jls'
|
|
284
|
+
| 'application/vnd.ms-outlook'
|
|
285
|
+
| 'image/vnd.dwg';
|
|
280
286
|
|
|
281
|
-
export
|
|
287
|
+
export type FileTypeResult = {
|
|
282
288
|
/**
|
|
283
289
|
One of the supported [file types](https://github.com/sindresorhus/file-type#supported-file-types).
|
|
284
290
|
*/
|
|
@@ -288,7 +294,7 @@ export interface FileTypeResult {
|
|
|
288
294
|
The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type).
|
|
289
295
|
*/
|
|
290
296
|
readonly mime: MimeType;
|
|
291
|
-
}
|
|
297
|
+
};
|
|
292
298
|
|
|
293
299
|
export type ReadableStreamWithFileType = ReadableStream & {
|
|
294
300
|
readonly fileType?: FileTypeResult;
|
|
@@ -354,14 +360,14 @@ Supported MIME types.
|
|
|
354
360
|
*/
|
|
355
361
|
export const supportedMimeTypes: ReadonlySet<MimeType>;
|
|
356
362
|
|
|
357
|
-
export
|
|
363
|
+
export type StreamOptions = {
|
|
358
364
|
/**
|
|
359
365
|
The default sample size in bytes.
|
|
360
366
|
|
|
361
367
|
@default 4100
|
|
362
368
|
*/
|
|
363
369
|
readonly sampleSize?: number;
|
|
364
|
-
}
|
|
370
|
+
};
|
|
365
371
|
|
|
366
372
|
/**
|
|
367
373
|
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()`.
|
package/core.js
CHANGED
|
@@ -159,13 +159,6 @@ class FileTypeParser {
|
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
if (this.check([0xFF, 0xD8, 0xFF])) {
|
|
163
|
-
return {
|
|
164
|
-
ext: 'jpg',
|
|
165
|
-
mime: 'image/jpeg',
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
162
|
if (this.check([0x49, 0x49, 0xBC])) {
|
|
170
163
|
return {
|
|
171
164
|
ext: 'jxr',
|
|
@@ -222,6 +215,21 @@ class FileTypeParser {
|
|
|
222
215
|
|
|
223
216
|
// -- 4-byte signatures --
|
|
224
217
|
|
|
218
|
+
// Requires a sample size of 4 bytes
|
|
219
|
+
if (this.check([0xFF, 0xD8, 0xFF])) {
|
|
220
|
+
if (this.check([0xF7], {offset: 3})) { // JPG7/SOF55, indicating a ISO/IEC 14495 / JPEG-LS file
|
|
221
|
+
return {
|
|
222
|
+
ext: 'jls',
|
|
223
|
+
mime: 'image/jls',
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
ext: 'jpg',
|
|
229
|
+
mime: 'image/jpeg',
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
225
233
|
if (this.checkString('FLIF')) {
|
|
226
234
|
return {
|
|
227
235
|
ext: 'flif',
|
|
@@ -800,6 +808,13 @@ class FileTypeParser {
|
|
|
800
808
|
};
|
|
801
809
|
}
|
|
802
810
|
|
|
811
|
+
if (this.check([0x21, 0x42, 0x44, 0x4E])) {
|
|
812
|
+
return {
|
|
813
|
+
ext: 'pst',
|
|
814
|
+
mime: 'application/vnd.ms-outlook',
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
|
|
803
818
|
// -- 5-byte signatures --
|
|
804
819
|
|
|
805
820
|
if (this.check([0x4F, 0x54, 0x54, 0x4F, 0x00])) {
|
|
@@ -923,6 +938,16 @@ class FileTypeParser {
|
|
|
923
938
|
};
|
|
924
939
|
}
|
|
925
940
|
|
|
941
|
+
if (this.checkString('AC')) {
|
|
942
|
+
const version = this.buffer.toString('binary', 2, 6);
|
|
943
|
+
if (version.match('^d*') && version >= 1000 && version <= 1050) {
|
|
944
|
+
return {
|
|
945
|
+
ext: 'dwg',
|
|
946
|
+
mime: 'image/vnd.dwg',
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
926
951
|
// -- 7-byte signatures --
|
|
927
952
|
|
|
928
953
|
if (this.checkString('BLENDER')) {
|
|
@@ -1483,8 +1508,8 @@ class FileTypeParser {
|
|
|
1483
1508
|
}
|
|
1484
1509
|
|
|
1485
1510
|
await this.tokenizer.ignore(ifdOffset);
|
|
1486
|
-
const fileType = await this.readTiffIFD(
|
|
1487
|
-
return fileType
|
|
1511
|
+
const fileType = await this.readTiffIFD(bigEndian);
|
|
1512
|
+
return fileType ?? {
|
|
1488
1513
|
ext: 'tif',
|
|
1489
1514
|
mime: 'image/tiff',
|
|
1490
1515
|
};
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.1.0",
|
|
4
4
|
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -193,7 +193,10 @@
|
|
|
193
193
|
"3mf",
|
|
194
194
|
"zst",
|
|
195
195
|
"jxl",
|
|
196
|
-
"vcf"
|
|
196
|
+
"vcf",
|
|
197
|
+
"jls",
|
|
198
|
+
"pst",
|
|
199
|
+
"dwg"
|
|
197
200
|
],
|
|
198
201
|
"dependencies": {
|
|
199
202
|
"readable-web-to-node-stream": "^3.0.2",
|
|
@@ -203,11 +206,11 @@
|
|
|
203
206
|
"devDependencies": {
|
|
204
207
|
"@tokenizer/token": "^0.3.0",
|
|
205
208
|
"@types/node": "^18.7.13",
|
|
206
|
-
"ava": "^
|
|
209
|
+
"ava": "^5.1.0",
|
|
207
210
|
"commonmark": "^0.30.0",
|
|
208
211
|
"noop-stream": "^1.0.0",
|
|
209
|
-
"tsd": "^0.
|
|
210
|
-
"xo": "^0.
|
|
212
|
+
"tsd": "^0.25.0",
|
|
213
|
+
"xo": "^0.53.1"
|
|
211
214
|
},
|
|
212
215
|
"xo": {
|
|
213
216
|
"envs": [
|
|
@@ -219,7 +222,9 @@
|
|
|
219
222
|
"no-await-in-loop": "warn",
|
|
220
223
|
"no-bitwise": "off",
|
|
221
224
|
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
222
|
-
"unicorn/text-encoding-identifier-case": "off"
|
|
225
|
+
"unicorn/text-encoding-identifier-case": "off",
|
|
226
|
+
"unicorn/switch-case-braces": "off",
|
|
227
|
+
"unicorn/prefer-top-level-await": "off"
|
|
223
228
|
}
|
|
224
229
|
},
|
|
225
230
|
"ava": {
|
package/readme.md
CHANGED
|
@@ -376,6 +376,7 @@ Returns a `Set<string>` of supported MIME types.
|
|
|
376
376
|
- [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Adobe Digital Negative image file
|
|
377
377
|
- [`docx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Word
|
|
378
378
|
- [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)
|
|
379
|
+
- [`dwg`](https://en.wikipedia.org/wiki/.dwg) - Autodesk CAD file
|
|
379
380
|
- [`elf`](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) - Unix Executable and Linkable Format
|
|
380
381
|
- [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType) - Embedded OpenType font
|
|
381
382
|
- [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript
|
|
@@ -397,6 +398,7 @@ Returns a `Set<string>` of supported MIME types.
|
|
|
397
398
|
- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
|
|
398
399
|
- [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format) - Adobe InDesign document
|
|
399
400
|
- [`it`](https://wiki.openmpt.org/Manual:_Module_formats#The_Impulse_Tracker_format_.28.it.29) - Audio module format: Impulse Tracker
|
|
401
|
+
- [`jls`](https://en.wikipedia.org/wiki/Lossless_JPEG#JPEG-LS) - Lossless/near-lossless compression standard for continuous-tone images
|
|
400
402
|
- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
|
|
401
403
|
- [`jpg`](https://en.wikipedia.org/wiki/JPEG) - Joint Photographic Experts Group image
|
|
402
404
|
- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
|
|
@@ -410,7 +412,7 @@ Returns a `Set<string>` of supported MIME types.
|
|
|
410
412
|
- [`m4a`](https://en.wikipedia.org/wiki/M4A) - Audio-only MPEG-4 files
|
|
411
413
|
- [`m4b`](https://en.wikipedia.org/wiki/M4B) - Audiobook and podcast MPEG-4 files, which also contain metadata including chapter markers, images, and hyperlinks
|
|
412
414
|
- [`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
|
|
413
|
-
- [`m4v`](https://en.wikipedia.org/wiki/M4V) -
|
|
415
|
+
- [`m4v`](https://en.wikipedia.org/wiki/M4V) - Video container format developed by Apple, which is very similar to the MP4 format
|
|
414
416
|
- [`mid`](https://en.wikipedia.org/wiki/MIDI) - Musical Instrument Digital Interface file
|
|
415
417
|
- [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Dedicated meta information format which supports storage of binary as well as textual meta information
|
|
416
418
|
- [`mj2`](https://en.wikipedia.org/wiki/Motion_JPEG_2000) - Motion JPEG 2000
|
|
@@ -445,6 +447,7 @@ Returns a `Set<string>` of supported MIME types.
|
|
|
445
447
|
- [`pptx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Powerpoint
|
|
446
448
|
- [`ps`](https://en.wikipedia.org/wiki/Postscript) - Postscript
|
|
447
449
|
- [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format) - Adobe Photoshop document
|
|
450
|
+
- [`pst`](https://en.wikipedia.org/wiki/Personal_Storage_Table) - Personal Storage Table file
|
|
448
451
|
- [`qcp`](https://en.wikipedia.org/wiki/QCP) - Tagged and chunked data
|
|
449
452
|
- [`raf`](https://en.wikipedia.org/wiki/Raw_image_format) - Fujifilm RAW image file
|
|
450
453
|
- [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format)) - Archive file
|
|
@@ -490,12 +493,6 @@ The following file types will not be accepted:
|
|
|
490
493
|
- `.csv` - [Reason.](https://github.com/sindresorhus/file-type/issues/264#issuecomment-568439196)
|
|
491
494
|
- `.svg` - Detecting it requires a full-blown parser. Check out [`is-svg`](https://github.com/sindresorhus/is-svg) for something that mostly works.
|
|
492
495
|
|
|
493
|
-
## file-type for enterprise
|
|
494
|
-
|
|
495
|
-
Available as part of the Tidelift Subscription.
|
|
496
|
-
|
|
497
|
-
The maintainers of file-type and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-file-type?utm_source=npm-file-type&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
|
498
|
-
|
|
499
496
|
## Related
|
|
500
497
|
|
|
501
498
|
- [file-type-cli](https://github.com/sindresorhus/file-type-cli) - CLI for this module
|
|
@@ -503,6 +500,9 @@ The maintainers of file-type and thousands of other packages are working with Ti
|
|
|
503
500
|
## Maintainers
|
|
504
501
|
|
|
505
502
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
503
|
+
- [Borewit](https://github.com/Borewit)
|
|
504
|
+
|
|
505
|
+
**Former**
|
|
506
|
+
|
|
506
507
|
- [Mikael Finstad](https://github.com/mifi)
|
|
507
508
|
- [Ben Brook](https://github.com/bencmbrook)
|
|
508
|
-
- [Borewit](https://github.com/Borewit)
|
package/supported.js
CHANGED
|
@@ -138,6 +138,9 @@ export const extensions = [
|
|
|
138
138
|
'zst',
|
|
139
139
|
'jxl',
|
|
140
140
|
'vcf',
|
|
141
|
+
'jls',
|
|
142
|
+
'pst',
|
|
143
|
+
'dwg',
|
|
141
144
|
];
|
|
142
145
|
|
|
143
146
|
export const mimeTypes = [
|
|
@@ -275,4 +278,7 @@ export const mimeTypes = [
|
|
|
275
278
|
'model/3mf',
|
|
276
279
|
'image/jxl',
|
|
277
280
|
'application/zstd',
|
|
281
|
+
'image/jls',
|
|
282
|
+
'application/vnd.ms-outlook',
|
|
283
|
+
'image/vnd.dwg',
|
|
278
284
|
];
|