This commit is contained in:
Lukian 2023-06-20 15:28:07 +02:00
parent 68f4b60012
commit 41ae7ff4bd
1010 changed files with 38622 additions and 17071 deletions

21
node_modules/file-type/browser.d.ts generated vendored
View file

@ -18,28 +18,9 @@ console.log(fileType);
*/
export declare function fileTypeFromStream(stream: ReadableStream): Promise<FileTypeResult | undefined>;
/**
Detect the file type of a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
__Note:__ This method is only available in the browser.
@example
```
import {fileTypeFromBlob} from 'file-type';
const blob = new Blob(['<?xml version="1.0" encoding="ISO-8859-1" ?>'], {
type: 'plain/text',
endings: 'native'
});
console.log(await fileTypeFromBlob(blob));
//=> {ext: 'txt', mime: 'plain/text'}
```
*/
export declare function fileTypeFromBlob(blob: Blob): Promise<FileTypeResult | undefined>;
export {
fileTypeFromBuffer,
fileTypeFromBlob,
supportedExtensions,
supportedMimeTypes,
type FileTypeResult,

38
node_modules/file-type/browser.js generated vendored
View file

@ -1,36 +1,5 @@
import {Buffer} from 'node:buffer';
import {ReadableWebToNodeStream} from 'readable-web-to-node-stream';
import {fileTypeFromBuffer, fileTypeFromStream as coreFileTypeFromStream} from './core.js';
/**
Convert Blobs to ArrayBuffer.
@param {Blob} blob - Web API Blob.
@returns {Promise<ArrayBuffer>}
*/
function blobToArrayBuffer(blob) {
if (blob.arrayBuffer) {
return blob.arrayBuffer();
}
// TODO: Remove when stop supporting older environments
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.addEventListener('loadend', event => {
resolve(event.target.result);
});
fileReader.addEventListener('error', event => {
reject(new Error(event.message));
});
fileReader.addEventListener('abort', event => {
reject(new Error(event.type));
});
fileReader.readAsArrayBuffer(blob);
});
}
import {fileTypeFromStream as coreFileTypeFromStream} from './core.js';
export async function fileTypeFromStream(stream) {
const readableWebToNodeStream = new ReadableWebToNodeStream(stream);
@ -39,11 +8,6 @@ export async function fileTypeFromStream(stream) {
return fileType;
}
export async function fileTypeFromBlob(blob) {
const buffer = await blobToArrayBuffer(blob);
return fileTypeFromBuffer(Buffer.from(buffer));
}
export {
fileTypeFromTokenizer,
fileTypeFromBuffer,

38
node_modules/file-type/core.d.ts generated vendored
View file

@ -83,6 +83,7 @@ export type FileExtension =
| 'xlsx'
| '3gp'
| '3g2'
| 'j2c'
| 'jp2'
| 'jpm'
| 'jpx'
@ -144,7 +145,14 @@ export type FileExtension =
| 'jls'
| 'pst'
| 'dwg'
| 'parquet';
| 'parquet'
| 'class'
| 'arj'
| 'cpio'
| 'ace'
| 'avro'
| 'icc'
; // eslint-disable-line semi-style
export type MimeType =
| 'image/jpeg'
@ -231,6 +239,7 @@ export type MimeType =
| 'video/mp2t'
| 'application/x-blender'
| 'image/bpg'
| 'image/j2c'
| 'image/jp2'
| 'image/jpx'
| 'image/jpm'
@ -284,7 +293,14 @@ export type MimeType =
| 'image/jls'
| 'application/vnd.ms-outlook'
| 'image/vnd.dwg'
| 'application/x-parquet';
| 'application/x-parquet'
| 'application/java-vm'
| 'application/x-arj'
| 'application/x-cpio'
| 'application/x-ace-compressed'
| 'application/avro'
| 'application/vnd.iccprofile'
; // eslint-disable-line semi-style
export type FileTypeResult = {
/**
@ -401,3 +417,21 @@ if (stream2.fileType?.mime === 'image/jpeg') {
```
*/
export function fileTypeStream(readableStream: ReadableStream, options?: StreamOptions): Promise<ReadableStreamWithFileType>;
/**
Detect the file type of a [`Blob`](https://nodejs.org/api/buffer.html#class-blob).
@example
```
import {fileTypeFromBlob} from 'file-type';
const blob = new Blob(['<?xml version="1.0" encoding="ISO-8859-1" ?>'], {
type: 'plain/text',
endings: 'native'
});
console.log(await fileTypeFromBlob(blob));
//=> {ext: 'txt', mime: 'plain/text'}
```
*/
export declare function fileTypeFromBlob(blob: Blob): Promise<FileTypeResult | undefined>;

91
node_modules/file-type/core.js generated vendored
View file

@ -33,6 +33,11 @@ export async function fileTypeFromBuffer(input) {
return fileTypeFromTokenizer(strtok3.fromBuffer(buffer));
}
export async function fileTypeFromBlob(blob) {
const buffer = await blob.arrayBuffer();
return fileTypeFromBuffer(new Uint8Array(buffer));
}
function _check(buffer, headers, options) {
options = {
offset: 0,
@ -144,6 +149,20 @@ class FileTypeParser {
};
}
if (this.check([0xC7, 0x71])) {
return {
ext: 'cpio',
mime: 'application/x-cpio',
};
}
if (this.check([0x60, 0xEA])) {
return {
ext: 'arj',
mime: 'application/x-arj',
};
}
// -- 3-byte signatures --
if (this.check([0xEF, 0xBB, 0xBF])) { // UTF-8-BOM
@ -230,6 +249,13 @@ class FileTypeParser {
};
}
if (this.check([0x4F, 0x62, 0x6A, 0x01])) {
return {
ext: 'avro',
mime: 'application/avro',
};
}
if (this.checkString('FLIF')) {
return {
ext: 'flif',
@ -611,17 +637,24 @@ class FileTypeParser {
}
if (this.checkString('%PDF')) {
await tokenizer.ignore(1350);
const maxBufferSize = 10 * 1024 * 1024;
const buffer = Buffer.alloc(Math.min(maxBufferSize, tokenizer.fileInfo.size));
await tokenizer.readBuffer(buffer, {mayBeLess: true});
try {
await tokenizer.ignore(1350);
const maxBufferSize = 10 * 1024 * 1024;
const buffer = Buffer.alloc(Math.min(maxBufferSize, tokenizer.fileInfo.size));
await tokenizer.readBuffer(buffer, {mayBeLess: true});
// Check if this is an Adobe Illustrator file
if (buffer.includes(Buffer.from('AIPrivateData'))) {
return {
ext: 'ai',
mime: 'application/postscript',
};
// Check if this is an Adobe Illustrator file
if (buffer.includes(Buffer.from('AIPrivateData'))) {
return {
ext: 'ai',
mime: 'application/postscript',
};
}
} catch (error) {
// Swallow end of stream error if file is too small for the Adobe AI check
if (!(error instanceof strtok3.EndOfStreamError)) {
throw error;
}
}
// Assume this is just a normal PDF
@ -905,6 +938,13 @@ class FileTypeParser {
};
}
if (this.check([0xCA, 0xFE, 0xBA, 0xBE])) {
return {
ext: 'class',
mime: 'application/java-vm',
};
}
// -- 6-byte signatures --
if (this.check([0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00])) {
@ -955,6 +995,13 @@ class FileTypeParser {
}
}
if (this.checkString('070707')) {
return {
ext: 'cpio',
mime: 'application/x-cpio',
};
}
// -- 7-byte signatures --
if (this.checkString('BLENDER')) {
@ -980,6 +1027,16 @@ class FileTypeParser {
};
}
if (this.checkString('**ACE', {offset: 7})) {
await tokenizer.peekBuffer(this.buffer, {length: 14, mayBeLess: true});
if (this.checkString('**', {offset: 12})) {
return {
ext: 'ace',
mime: 'application/x-ace-compressed',
};
}
}
// -- 8-byte signatures --
if (this.check([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])) {
@ -1151,6 +1208,13 @@ class FileTypeParser {
};
}
if (this.check([0xFF, 0x4F, 0xFF, 0x51])) {
return {
ext: 'j2c',
mime: 'image/j2c',
};
}
if (this.check([0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A])) {
// JPEG-2000 family
@ -1247,6 +1311,13 @@ class FileTypeParser {
// Increase sample size from 12 to 256.
await tokenizer.peekBuffer(this.buffer, {length: Math.min(256, tokenizer.fileInfo.size), mayBeLess: true});
if (this.check([0x61, 0x63, 0x73, 0x70], {offset: 36})) {
return {
ext: 'icc',
mime: 'application/vnd.iccprofile',
};
}
// -- 15-byte signatures --
if (this.checkString('BEGIN:')) {

19
node_modules/file-type/package.json generated vendored
View file

@ -1,6 +1,6 @@
{
"name": "file-type",
"version": "18.2.0",
"version": "18.5.0",
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
"license": "MIT",
"repository": "sindresorhus/file-type",
@ -132,6 +132,7 @@
"pptx",
"xlsx",
"3gp",
"j2c",
"jp2",
"jpm",
"jpx",
@ -197,7 +198,13 @@
"jls",
"pst",
"dwg",
"parquet"
"parquet",
"class",
"arj",
"cpio",
"ace",
"avro",
"icc"
],
"dependencies": {
"readable-web-to-node-stream": "^3.0.2",
@ -206,12 +213,12 @@
},
"devDependencies": {
"@tokenizer/token": "^0.3.0",
"@types/node": "^18.7.13",
"ava": "^5.1.0",
"@types/node": "^20.1.2",
"ava": "^5.2.0",
"commonmark": "^0.30.0",
"noop-stream": "^1.0.0",
"tsd": "^0.25.0",
"xo": "^0.53.1"
"tsd": "^0.28.1",
"xo": "^0.54.2"
},
"xo": {
"envs": [

39
node_modules/file-type/readme.md generated vendored
View file

@ -8,36 +8,6 @@ This package is for detecting binary-based file formats, not text-based formats
We accept contributions for commonly used modern file formats, not historical or obscure ones. Open an issue first for discussion.
<br>
---
<div align="center">
<p>
<p>
<sup>
<a href="https://github.com/sponsors/sindresorhus">My open source work is supported by the community</a>
</sup>
</p>
<sup>Special thanks to:</sup>
<br>
<br>
<a href="https://bit.io/?utm_campaign=github_repo&utm_medium=referral&utm_content=file-type&utm_source=github">
<div>
<img src="https://sindresorhus.com/assets/thanks/bitio-logo.svg" width="190" alt="bit.io">
</div>
<b>Instant, shareable cloud PostgreSQL database</b>
<div>
<sup>Import any dataset in seconds, share with anyone with a click, try without signing up</sup>
</div>
</a>
</p>
</div>
---
<br>
## Install
```sh
@ -198,8 +168,6 @@ A readable stream representing file data.
Detect the file type of a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
**Note:** This method is only available in the browser.
The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
Returns a `Promise` for an object with the detected file type and MIME type:
@ -346,6 +314,7 @@ Returns a `Set<string>` of supported MIME types.
- [`Z`](https://fileinfo.com/extension/z) - Unix Compressed File
- [`aac`](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) - Advanced Audio Coding
- [`ac3`](https://www.atsc.org/standard/a522012-digital-audio-compression-ac-3-e-ac-3-standard-12172012/) - ATSC A/52 Audio File
- [`ace`](https://en.wikipedia.org/wiki/ACE_(compressed_file_format)) - ACE archive
- [`ai`](https://en.wikipedia.org/wiki/Adobe_Illustrator_Artwork) - Adobe Illustrator Artwork
- [`aif`](https://en.wikipedia.org/wiki/Audio_Interchange_File_Format) - Audio Interchange file
- [`alias`](https://en.wikipedia.org/wiki/Alias_%28Mac_OS%29) - macOS Alias file
@ -353,12 +322,14 @@ Returns a `Set<string>` of supported MIME types.
- [`ape`](https://en.wikipedia.org/wiki/Monkey%27s_Audio) - Monkey's Audio
- [`apng`](https://en.wikipedia.org/wiki/APNG) - Animated Portable Network Graphics
- [`ar`](https://en.wikipedia.org/wiki/Ar_(Unix)) - Archive file
- [`arj`](https://en.wikipedia.org/wiki/ARJ) - Archive file
- [`arrow`](https://arrow.apache.org) - Columnar format for tables of data
- [`arw`](https://en.wikipedia.org/wiki/Raw_image_format#ARW) - Sony Alpha Raw image file
- [`asar`](https://github.com/electron/asar#format) - Archive format primarily used to enclose Electron applications
- [`asf`](https://en.wikipedia.org/wiki/Advanced_Systems_Format) - Advanced Systems Format
- [`avi`](https://en.wikipedia.org/wiki/Audio_Video_Interleave) - Audio Video Interleave file
- [`avif`](https://en.wikipedia.org/wiki/AV1#AV1_Image_File_Format_(AVIF)) - AV1 Image File Format
- [`avro`](https://en.wikipedia.org/wiki/Apache_Avro#Avro_Object_Container_File) - Object container file developed by Apache Avro
- [`blend`](https://wiki.blender.org/index.php/Dev:Source/Architecture/File_Format) - Blender project
- [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format) - Bitmap image file
- [`bpg`](https://bellard.org/bpg/) - Better Portable Graphics file
@ -366,6 +337,8 @@ Returns a `Set<string>` of supported MIME types.
- [`cab`](https://en.wikipedia.org/wiki/Cabinet_(file_format)) - Cabinet file
- [`cfb`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) - Compount File Binary Format
- [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help
- [`class`](https://en.wikipedia.org/wiki/Java_class_file) - Java class file
- [`cpio`](https://en.wikipedia.org/wiki/Cpio) - Cpio archive
- [`cr2`](https://fileinfo.com/extension/cr2) - Canon Raw image file (v2)
- [`cr3`](https://fileinfo.com/extension/cr3) - Canon Raw image file (v3)
- [`crx`](https://developer.chrome.com/extensions/crx) - Google Chrome extension
@ -393,11 +366,13 @@ Returns a `Set<string>` of supported MIME types.
- [`glb`](https://github.com/KhronosGroup/glTF) - GL Transmission Format
- [`gz`](https://en.wikipedia.org/wiki/Gzip) - Archive file
- [`heic`](https://nokiatech.github.io/heif/technical.html) - High Efficiency Image File Format
- [`icc`](https://en.wikipedia.org/wiki/ICC_profile) - ICC Profile
- [`icns`](https://en.wikipedia.org/wiki/Apple_Icon_Image_format) - Apple Icon image
- [`ico`](https://en.wikipedia.org/wiki/ICO_(file_format)) - Windows icon file
- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
- [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format) - Adobe InDesign document
- [`it`](https://wiki.openmpt.org/Manual:_Module_formats#The_Impulse_Tracker_format_.28.it.29) - Audio module format: Impulse Tracker
- [`j2c`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
- [`jls`](https://en.wikipedia.org/wiki/Lossless_JPEG#JPEG-LS) - Lossless/near-lossless compression standard for continuous-tone images
- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
- [`jpg`](https://en.wikipedia.org/wiki/JPEG) - Joint Photographic Experts Group image

14
node_modules/file-type/supported.js generated vendored
View file

@ -81,6 +81,7 @@ export const extensions = [
'xlsx',
'3gp',
'3g2',
'j2c',
'jp2',
'jpm',
'jpx',
@ -142,6 +143,12 @@ export const extensions = [
'pst',
'dwg',
'parquet',
'class',
'arj',
'cpio',
'ace',
'avro',
'icc',
];
export const mimeTypes = [
@ -228,6 +235,7 @@ export const mimeTypes = [
'video/mp2t',
'application/x-blender',
'image/bpg',
'image/j2c',
'image/jp2',
'image/jpx',
'image/jpm',
@ -283,4 +291,10 @@ export const mimeTypes = [
'application/vnd.ms-outlook',
'image/vnd.dwg',
'application/x-parquet',
'application/java-vm',
'application/x-arj',
'application/x-cpio',
'application/x-ace-compressed',
'application/avro',
'application/vnd.iccprofile',
];