file-type 16.5.2 → 17.0.2
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 +22 -28
- package/browser.js +21 -19
- package/core.d.ts +362 -356
- package/core.js +1214 -1155
- package/index.d.ts +4 -17
- package/index.js +5 -24
- package/package.json +28 -16
- package/readme.md +113 -97
- package/supported.js +275 -278
- package/util.js +10 -12
package/browser.d.ts
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
import * as core from './core';
|
|
3
|
-
|
|
4
|
-
export type FileTypeResult = core.FileTypeResult;
|
|
5
|
-
export type FileExtension = core.FileExtension;
|
|
6
|
-
export type MimeType = core.MimeType;
|
|
1
|
+
import {FileTypeResult} from './core.js';
|
|
7
2
|
|
|
8
3
|
/**
|
|
9
4
|
Determine file type from a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
|
|
10
5
|
|
|
11
6
|
```
|
|
12
|
-
import
|
|
7
|
+
import {fileTypeFromStream} from 'file-type';
|
|
13
8
|
|
|
14
9
|
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const fileType = await FileType.fromStream(response.body);
|
|
11
|
+
const response = await fetch(url);
|
|
12
|
+
const fileType = await fileTypeFromStream(response.body);
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})();
|
|
14
|
+
console.log(fileType);
|
|
15
|
+
//=> {ext: 'jpg', mime: 'image/jpeg'}
|
|
23
16
|
```
|
|
24
17
|
*/
|
|
25
|
-
export declare function
|
|
18
|
+
export declare function fileTypeFromStream(stream: ReadableStream): Promise<FileTypeResult | undefined>;
|
|
26
19
|
|
|
27
20
|
/**
|
|
28
21
|
Determine file type from a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
|
|
29
22
|
|
|
30
23
|
```
|
|
31
|
-
import
|
|
24
|
+
import {fileTypeFromBlob} from 'file-type';
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
26
|
+
const blob = new Blob(['<?xml version="1.0" encoding="ISO-8859-1" ?>'], {
|
|
27
|
+
type: 'plain/text',
|
|
28
|
+
endings: 'native'
|
|
29
|
+
});
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})();
|
|
31
|
+
console.log(await fileTypeFromBlob(blob));
|
|
32
|
+
//=> {ext: 'txt', mime: 'plain/text'}
|
|
42
33
|
```
|
|
43
34
|
*/
|
|
44
|
-
export declare function
|
|
35
|
+
export declare function fileTypeFromBlob(blob: Blob): Promise<FileTypeResult | undefined>;
|
|
45
36
|
|
|
46
37
|
export {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
fileTypeFromBuffer,
|
|
39
|
+
supportedExtensions,
|
|
40
|
+
supportedMimeTypes,
|
|
41
|
+
FileTypeResult,
|
|
42
|
+
FileExtension,
|
|
43
|
+
MimeType,
|
|
44
|
+
} from './core.js';
|
package/browser.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
async function fromStream(stream) {
|
|
6
|
-
const readableWebToNodeStream = new ReadableWebToNodeStream(stream);
|
|
7
|
-
const fileType = await core.fromStream(readableWebToNodeStream);
|
|
8
|
-
await readableWebToNodeStream.close();
|
|
9
|
-
return fileType;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async function fromBlob(blob) {
|
|
13
|
-
const buffer = await blobToArrayBuffer(blob);
|
|
14
|
-
return core.fromBuffer(Buffer.from(buffer));
|
|
15
|
-
}
|
|
1
|
+
import {Buffer} from 'node:buffer';
|
|
2
|
+
import {ReadableWebToNodeStream} from 'readable-web-to-node-stream';
|
|
3
|
+
import {fileTypeFromBuffer, fileTypeFromStream as coreFileTypeFromStream} from './core.js';
|
|
16
4
|
|
|
17
5
|
/**
|
|
18
6
|
Convert Blobs to ArrayBuffer.
|
|
7
|
+
|
|
19
8
|
@param {Blob} blob - Web API Blob.
|
|
20
9
|
@returns {Promise<ArrayBuffer>}
|
|
21
10
|
*/
|
|
@@ -43,7 +32,20 @@ function blobToArrayBuffer(blob) {
|
|
|
43
32
|
});
|
|
44
33
|
}
|
|
45
34
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
export async function fileTypeFromStream(stream) {
|
|
36
|
+
const readableWebToNodeStream = new ReadableWebToNodeStream(stream);
|
|
37
|
+
const fileType = await coreFileTypeFromStream(readableWebToNodeStream);
|
|
38
|
+
await readableWebToNodeStream.close();
|
|
39
|
+
return fileType;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function fileTypeFromBlob(blob) {
|
|
43
|
+
const buffer = await blobToArrayBuffer(blob);
|
|
44
|
+
return fileTypeFromBuffer(Buffer.from(buffer));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
fileTypeFromTokenizer,
|
|
49
|
+
fileTypeFromBuffer,
|
|
50
|
+
fileTypeStream,
|
|
51
|
+
} from './core.js';
|