file-type 20.1.0 → 20.3.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/core.d.ts +20 -5
- package/core.js +9 -0
- package/package.json +12 -5
- package/readme.md +21 -7
- package/supported.js +2 -0
package/core.d.ts
CHANGED
|
@@ -116,13 +116,28 @@ export declare function fileTypeFromBlob(blob: Blob): Promise<FileTypeResult | u
|
|
|
116
116
|
/**
|
|
117
117
|
A custom file type detector.
|
|
118
118
|
|
|
119
|
+
Custom file type detectors are plugins designed to extend the default detection capabilities.
|
|
120
|
+
They allow support for uncommon file types, non-binary formats, or customized detection behavior.
|
|
121
|
+
|
|
122
|
+
Detectors can be added via the constructor options or by modifying `FileTypeParser#detectors` directly.
|
|
123
|
+
Detectors provided through the constructor are executed before the default ones.
|
|
124
|
+
|
|
119
125
|
Detectors can be added via the constructor options or by directly modifying `FileTypeParser#detectors`.
|
|
120
126
|
|
|
121
|
-
|
|
127
|
+
### Example adding a detector
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
import {FileTypeParser} from 'file-type';
|
|
131
|
+
import {detectXml} from '@file-type/xml';
|
|
132
|
+
|
|
133
|
+
const parser = new FileTypeParser({customDetectors: [detectXml]});
|
|
134
|
+
const fileType = await parser.fromFile('sample.kml');
|
|
135
|
+
console.log(fileType);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Available-third party file-type detectors
|
|
122
139
|
|
|
123
|
-
|
|
124
|
-
- Introducing new `FileTypeResult` entries.
|
|
125
|
-
- Modifying the detection behavior of existing `FileTypeResult` types.
|
|
140
|
+
- [@file-type/xml](https://github.com/Borewit/file-type-xml): Detects common XML file types, such as GLM, KML, MusicXML, RSS, SVG, and XHTML
|
|
126
141
|
|
|
127
142
|
### Detector execution flow
|
|
128
143
|
|
|
@@ -131,7 +146,7 @@ If a detector returns `undefined`, the following rules apply:
|
|
|
131
146
|
1. **No Tokenizer Interaction**: If the detector does not modify the tokenizer's position, the next detector in the sequence is executed.
|
|
132
147
|
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.
|
|
133
148
|
|
|
134
|
-
### Example
|
|
149
|
+
### Example writing a custom detector
|
|
135
150
|
|
|
136
151
|
Below is an example of a custom detector array. This can be passed to the `FileTypeParser` via the `fileTypeOptions` argument.
|
|
137
152
|
|
package/core.js
CHANGED
|
@@ -1021,6 +1021,15 @@ export class FileTypeParser {
|
|
|
1021
1021
|
};
|
|
1022
1022
|
}
|
|
1023
1023
|
|
|
1024
|
+
if (this.checkString('.RMF')) {
|
|
1025
|
+
return {
|
|
1026
|
+
ext: 'rm',
|
|
1027
|
+
mime: 'application/vnd.rn-realmedia',
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// -- 5-byte signatures --
|
|
1032
|
+
|
|
1024
1033
|
if (this.checkString('DRACO')) {
|
|
1025
1034
|
return {
|
|
1026
1035
|
ext: 'drc',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.3.0",
|
|
4
4
|
"description": "Detect the file type of a file, stream, or data",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -15,16 +15,22 @@
|
|
|
15
15
|
".": {
|
|
16
16
|
"node": {
|
|
17
17
|
"types": "./index.d.ts",
|
|
18
|
-
"import": "./index.js"
|
|
18
|
+
"import": "./index.js",
|
|
19
|
+
"module-sync": "./index.js"
|
|
19
20
|
},
|
|
20
21
|
"default": {
|
|
21
22
|
"types": "./core.d.ts",
|
|
22
|
-
"import": "./core.js"
|
|
23
|
+
"import": "./core.js",
|
|
24
|
+
"module-sync": "./core.js"
|
|
23
25
|
}
|
|
24
26
|
},
|
|
25
27
|
"./core": {
|
|
26
28
|
"types": "./core.d.ts",
|
|
27
|
-
"
|
|
29
|
+
"default": "./core.js"
|
|
30
|
+
},
|
|
31
|
+
"./node": {
|
|
32
|
+
"types": "./index.d.ts",
|
|
33
|
+
"default": "./index.js"
|
|
28
34
|
}
|
|
29
35
|
},
|
|
30
36
|
"sideEffects": false,
|
|
@@ -234,7 +240,8 @@
|
|
|
234
240
|
"dotm",
|
|
235
241
|
"potm",
|
|
236
242
|
"pptm",
|
|
237
|
-
"jar"
|
|
243
|
+
"jar",
|
|
244
|
+
"rm"
|
|
238
245
|
],
|
|
239
246
|
"dependencies": {
|
|
240
247
|
"@tokenizer/inflate": "^0.2.6",
|
package/readme.md
CHANGED
|
@@ -343,15 +343,28 @@ Returns a `Set<string>` of supported MIME types.
|
|
|
343
343
|
|
|
344
344
|
## Custom detectors
|
|
345
345
|
|
|
346
|
-
|
|
346
|
+
Custom file type detectors are plugins designed to extend the default detection capabilities.
|
|
347
|
+
They allow support for uncommon file types, non-binary formats, or customized detection behavior.
|
|
348
|
+
|
|
349
|
+
Detectors can be added via the constructor options or by modifying `FileTypeParser#detectors` directly.
|
|
350
|
+
Detectors provided through the constructor are executed before the default ones.
|
|
347
351
|
|
|
348
352
|
Detectors can be added via the constructor options or by directly modifying `FileTypeParser#detectors`.
|
|
349
353
|
|
|
350
|
-
|
|
354
|
+
### Example adding a detector
|
|
355
|
+
|
|
356
|
+
```js
|
|
357
|
+
import {FileTypeParser} from 'file-type';
|
|
358
|
+
import {detectXml} from '@file-type/xml';
|
|
359
|
+
|
|
360
|
+
const parser = new FileTypeParser({customDetectors: [detectXml]});
|
|
361
|
+
const fileType = await parser.fromFile('sample.kml');
|
|
362
|
+
console.log(fileType);
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Available third-party file-type detectors
|
|
351
366
|
|
|
352
|
-
|
|
353
|
-
- Introducing new `FileTypeResult` entries.
|
|
354
|
-
- Modifying the detection behavior of existing `FileTypeResult` types.
|
|
367
|
+
- [@file-type/xml](https://github.com/Borewit/file-type-xml): Detects common XML file types, such as GLM, KML, MusicXML, RSS, SVG, and XHTML
|
|
355
368
|
|
|
356
369
|
### Detector execution flow
|
|
357
370
|
|
|
@@ -360,7 +373,7 @@ If a detector returns `undefined`, the following rules apply:
|
|
|
360
373
|
1. **No Tokenizer Interaction**: If the detector does not modify the tokenizer's position, the next detector in the sequence is executed.
|
|
361
374
|
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.
|
|
362
375
|
|
|
363
|
-
###
|
|
376
|
+
### Writing your own custom detector
|
|
364
377
|
|
|
365
378
|
Below is an example of a custom detector array. This can be passed to the `FileTypeParser` via the `fileTypeOptions` argument.
|
|
366
379
|
|
|
@@ -552,6 +565,7 @@ abortController.abort(); // Abort file-type reading from the Blob stream.
|
|
|
552
565
|
- [`qcp`](https://en.wikipedia.org/wiki/QCP) - Tagged and chunked data
|
|
553
566
|
- [`raf`](https://en.wikipedia.org/wiki/Raw_image_format) - Fujifilm RAW image file
|
|
554
567
|
- [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format)) - Archive file
|
|
568
|
+
- [`rm`](https://en.wikipedia.org/wiki/RealMedia) - RealMedia
|
|
555
569
|
- [`rpm`](https://fileinfo.com/extension/rpm) - Red Hat Package Manager file
|
|
556
570
|
- [`rtf`](https://en.wikipedia.org/wiki/Rich_Text_Format) - Rich Text Format
|
|
557
571
|
- [`rw2`](https://en.wikipedia.org/wiki/Raw_image_format) - Panasonic RAW image file
|
|
@@ -597,7 +611,7 @@ The following file types will not be accepted:
|
|
|
597
611
|
- `.ppt` - Microsoft PowerPoint97-2003 Document
|
|
598
612
|
- `.msi` - Microsoft Windows Installer
|
|
599
613
|
- `.csv` - [Reason.](https://github.com/sindresorhus/file-type/issues/264#issuecomment-568439196)
|
|
600
|
-
- `.svg` -
|
|
614
|
+
- `.svg` - Supported by [third-party detector](#available-third-party-file-type-detectors).
|
|
601
615
|
|
|
602
616
|
#### tokenizer
|
|
603
617
|
|
package/supported.js
CHANGED
|
@@ -171,6 +171,7 @@ export const extensions = [
|
|
|
171
171
|
'potm',
|
|
172
172
|
'pptm',
|
|
173
173
|
'jar',
|
|
174
|
+
'rm',
|
|
174
175
|
];
|
|
175
176
|
|
|
176
177
|
export const mimeTypes = [
|
|
@@ -341,4 +342,5 @@ export const mimeTypes = [
|
|
|
341
342
|
'application/vnd.ms-powerpoint.template.macroEnabled.12',
|
|
342
343
|
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
|
|
343
344
|
'application/java-archive',
|
|
345
|
+
'application/vnd.rn-realmedia',
|
|
344
346
|
];
|