forked from sindresorhus/file-type
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test-d.ts
25 lines (19 loc) · 993 Bytes
/
index.test-d.ts
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
import * as fs from 'fs';
import {expectType} from 'tsd';
import fileType = require('.');
import {FileTypeResult, FileType, ReadableStreamWithFileType} from '.';
expectType<FileTypeResult | undefined>(fileType(new Buffer([0xff, 0xd8, 0xff])));
expectType<FileTypeResult | undefined>(fileType(new Uint8Array([0xff, 0xd8, 0xff])));
expectType<FileTypeResult | undefined>(fileType(new ArrayBuffer(42)));
const result = fileType(new Buffer([0xff, 0xd8, 0xff]));
if (result !== undefined) {
expectType<FileType>(result.ext);
expectType<string>(result.mime);
}
expectType<number>(fileType.minimumBytes);
expectType<readonly fileType.FileType[]>(fileType.extensions);
expectType<readonly fileType.MimeType[]>(fileType.mimeTypes);
const readableStream = fs.createReadStream('file.png');
const streamWithFileType = fileType.stream(readableStream);
expectType<Promise<ReadableStreamWithFileType>>(streamWithFileType);
expectType<FileTypeResult | undefined>((await streamWithFileType).fileType);