forked from sindresorhus/file-type
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test-d.ts
More file actions
41 lines (36 loc) · 1.56 KB
/
index.test-d.ts
File metadata and controls
41 lines (36 loc) · 1.56 KB
1
2
3
4
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
import {createReadStream} from 'node:fs';
import {Readable} from 'node:stream';
import {ReadableStream as NodeReadableStream} from 'node:stream/web';
import {expectType} from 'tsd';
import {fromFile} from 'strtok3';
import {
type FileTypeResult as FileTypeResultBrowser,
} from './core.js';
import {
fileTypeFromBlob,
fileTypeFromBuffer,
fileTypeFromFile,
fileTypeFromStream,
fileTypeStream,
type FileTypeResult,
type ReadableStreamWithFileType,
FileTypeParser,
} from './index.js';
// `fileTypeStream`: accepts options merged from StreamOptions & FileTypeOptions
(async () => {
const stream = createReadStream('myFile');
expectType<ReadableStreamWithFileType>(await fileTypeStream(stream, {sampleSize: 256, customDetectors: []}));
})();
// `FileTypeParser`: tests generic input types and mixed options
(async () => {
const fileTypeParser = new FileTypeParser({customDetectors: []});
const nodeStream = new Readable();
const webStream = new ReadableStream<Uint8Array>();
const nodeWebStream = new NodeReadableStream<Uint8Array>();
expectType<FileTypeResult | undefined>(await fileTypeParser.fromStream(nodeStream));
expectType<FileTypeResult | undefined>(await fileTypeParser.fromStream(webStream));
expectType<FileTypeResult | undefined>(await fileTypeParser.fromStream(nodeWebStream));
expectType<ReadableStreamWithFileType>(await fileTypeParser.toDetectionStream(nodeStream, {sampleSize: 256, customDetectors: []}));
})();
// Test that Blob overload returns browser-specific result
expectType<Promise<FileTypeResultBrowser | undefined>>(fileTypeFromBlob(new Blob([])));