file-type 19.4.0 → 19.5.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 +4 -2
- package/core.js +14 -2
- package/index.d.ts +2 -1
- package/index.js +2 -2
- package/package.json +4 -3
- package/readme.md +1 -0
- package/supported.js +2 -0
package/core.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ Typings for primary entry point, Node.js specific typings can be found in index.
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type {ReadableStream as WebReadableStream} from 'node:stream/web';
|
|
6
|
-
import type {ITokenizer} from 'strtok3';
|
|
6
|
+
import type {ITokenizer, AnyWebByteStream} from 'strtok3';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
Either the Node.js ReadableStream or the `lib.dom.d.ts` ReadableStream.
|
|
@@ -165,6 +165,7 @@ export type FileExtension =
|
|
|
165
165
|
| 'icc'
|
|
166
166
|
| 'fbx'
|
|
167
167
|
| 'vsdx'
|
|
168
|
+
| 'vtt'
|
|
168
169
|
; // eslint-disable-line semi-style
|
|
169
170
|
|
|
170
171
|
export type MimeType =
|
|
@@ -270,6 +271,7 @@ export type MimeType =
|
|
|
270
271
|
| 'audio/x-musepack'
|
|
271
272
|
| 'text/calendar'
|
|
272
273
|
| 'text/vcard'
|
|
274
|
+
| 'text/vtt'
|
|
273
275
|
| 'model/gltf-binary'
|
|
274
276
|
| 'application/vnd.tcpdump.pcap'
|
|
275
277
|
| 'audio/x-dsf' // Non-standard
|
|
@@ -350,7 +352,7 @@ The file type is detected by checking the [magic number](https://en.wikipedia.or
|
|
|
350
352
|
@param stream - A [web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) streaming a file to examine.
|
|
351
353
|
@returns A `Promise` for an object with the detected file type, or `undefined` when there is no match.
|
|
352
354
|
*/
|
|
353
|
-
export function fileTypeFromStream(stream:
|
|
355
|
+
export function fileTypeFromStream(stream: AnyWebByteStream): Promise<FileTypeResult | undefined>;
|
|
354
356
|
|
|
355
357
|
/**
|
|
356
358
|
Detect the file type from an [`ITokenizer`](https://github.com/Borewit/strtok3#tokenizer) source.
|
package/core.js
CHANGED
|
@@ -51,8 +51,8 @@ export async function fileTypeFromTokenizer(tokenizer) {
|
|
|
51
51
|
return new FileTypeParser().fromTokenizer(tokenizer);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export async function fileTypeStream(webStream) {
|
|
55
|
-
return new FileTypeParser().toDetectionStream(webStream);
|
|
54
|
+
export async function fileTypeStream(webStream, options) {
|
|
55
|
+
return new FileTypeParser(options).toDetectionStream(webStream, options);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export class FileTypeParser {
|
|
@@ -1139,6 +1139,18 @@ export class FileTypeParser {
|
|
|
1139
1139
|
}
|
|
1140
1140
|
}
|
|
1141
1141
|
|
|
1142
|
+
if (
|
|
1143
|
+
this.checkString('WEBVTT')
|
|
1144
|
+
&& (
|
|
1145
|
+
// One of LF, CR, tab, space, or end of file must follow "WEBVTT" per the spec (see `fixture/fixture-vtt-*.vtt` for examples). Note that `\0` is technically the null character (there is no such thing as an EOF character). However, checking for `\0` gives us the same result as checking for the end of the stream.
|
|
1146
|
+
(['\n', '\r', '\t', ' ', '\0'].some(char7 => this.checkString(char7, {offset: 6}))))
|
|
1147
|
+
) {
|
|
1148
|
+
return {
|
|
1149
|
+
ext: 'vtt',
|
|
1150
|
+
mime: 'text/vtt',
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1142
1154
|
// -- 8-byte signatures --
|
|
1143
1155
|
|
|
1144
1156
|
if (this.check([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])) {
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ Typings for Node.js specific entry point.
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type {Readable as NodeReadableStream} from 'node:stream';
|
|
6
|
+
import type {AnyWebByteStream} from 'strtok3';
|
|
6
7
|
import type {FileTypeResult, StreamOptions, AnyWebReadableStream, Detector, AnyWebReadableByteStreamWithFileType} from './core.js';
|
|
7
8
|
import {FileTypeParser} from './core.js';
|
|
8
9
|
|
|
@@ -85,6 +86,6 @@ if (stream2.fileType?.mime === 'image/jpeg') {
|
|
|
85
86
|
```
|
|
86
87
|
*/
|
|
87
88
|
export function fileTypeStream(readableStream: NodeReadableStream, options?: StreamOptions): Promise<ReadableStreamWithFileType>;
|
|
88
|
-
export function fileTypeStream(webStream:
|
|
89
|
+
export function fileTypeStream(webStream: AnyWebByteStream, options?: StreamOptions): Promise<AnyWebReadableByteStreamWithFileType>;
|
|
89
90
|
|
|
90
91
|
export * from './core.js';
|
package/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Node.js specific entry point.
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {ReadableStream as WebReadableStream} from 'node:stream/web';
|
|
6
|
-
import {pipeline, PassThrough} from 'node:stream';
|
|
6
|
+
import {pipeline, PassThrough, Readable} from 'node:stream';
|
|
7
7
|
import * as strtok3 from 'strtok3';
|
|
8
8
|
import {FileTypeParser, reasonableDetectionSizeInBytes} from './core.js';
|
|
9
9
|
|
|
@@ -27,7 +27,7 @@ export class NodeFileTypeParser extends FileTypeParser {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
async toDetectionStream(readableStream, options = {}) {
|
|
30
|
-
if (readableStream instanceof
|
|
30
|
+
if (!(readableStream instanceof Readable)) {
|
|
31
31
|
return super.toDetectionStream(readableStream, options);
|
|
32
32
|
}
|
|
33
33
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.5.0",
|
|
4
4
|
"description": "Detect the file type of a file, stream, or data",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -215,11 +215,12 @@
|
|
|
215
215
|
"avro",
|
|
216
216
|
"icc",
|
|
217
217
|
"fbx",
|
|
218
|
-
"vsdx"
|
|
218
|
+
"vsdx",
|
|
219
|
+
"vtt"
|
|
219
220
|
],
|
|
220
221
|
"dependencies": {
|
|
221
222
|
"get-stream": "^9.0.1",
|
|
222
|
-
"strtok3": "^8.
|
|
223
|
+
"strtok3": "^8.1.0",
|
|
223
224
|
"token-types": "^6.0.0",
|
|
224
225
|
"uint8array-extras": "^1.3.0"
|
|
225
226
|
},
|
package/readme.md
CHANGED
|
@@ -507,6 +507,7 @@ console.log(fileType);
|
|
|
507
507
|
- [`vcf`](https://en.wikipedia.org/wiki/VCard) - vCard
|
|
508
508
|
- [`voc`](https://wiki.multimedia.cx/index.php/Creative_Voice) - Creative Voice File
|
|
509
509
|
- [`vsdx`](https://en.wikipedia.org/wiki/Microsoft_Visio) - Microsoft Visio File
|
|
510
|
+
- [`vtt`](https://en.wikipedia.org/wiki/WebVTT) - WebVTT File (for video captions)
|
|
510
511
|
- [`wasm`](https://en.wikipedia.org/wiki/WebAssembly) - WebAssembly intermediate compiled format
|
|
511
512
|
- [`wav`](https://en.wikipedia.org/wiki/WAV) - Waveform Audio file
|
|
512
513
|
- [`webm`](https://en.wikipedia.org/wiki/WebM) - Web video file
|
package/supported.js
CHANGED
|
@@ -152,6 +152,7 @@ export const extensions = [
|
|
|
152
152
|
'icc',
|
|
153
153
|
'fbx',
|
|
154
154
|
'vsdx',
|
|
155
|
+
'vtt',
|
|
155
156
|
];
|
|
156
157
|
|
|
157
158
|
export const mimeTypes = [
|
|
@@ -257,6 +258,7 @@ export const mimeTypes = [
|
|
|
257
258
|
'audio/x-musepack',
|
|
258
259
|
'text/calendar',
|
|
259
260
|
'text/vcard',
|
|
261
|
+
'text/vtt',
|
|
260
262
|
'model/gltf-binary',
|
|
261
263
|
'application/vnd.tcpdump.pcap',
|
|
262
264
|
'audio/x-dsf', // Non-standard
|