This commit is contained in:
Lukian LEIZOUR 2023-01-29 00:57:47 +01:00
parent a15c733e45
commit 2a5130cbda
2838 changed files with 288613 additions and 0 deletions

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

@ -0,0 +1,48 @@
import type {FileTypeResult} from './core.js';
/**
Detect the file type of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
@example
```
import {fileTypeFromStream} from 'file-type';
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
const response = await fetch(url);
const fileType = await fileTypeFromStream(response.body);
console.log(fileType);
//=> {ext: 'jpg', mime: 'image/jpeg'}
```
*/
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,
supportedExtensions,
supportedMimeTypes,
type FileTypeResult,
type FileExtension,
type MimeType,
} from './core.js';

51
node_modules/file-type/browser.js generated vendored Normal file
View file

@ -0,0 +1,51 @@
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);
});
}
export async function fileTypeFromStream(stream) {
const readableWebToNodeStream = new ReadableWebToNodeStream(stream);
const fileType = await coreFileTypeFromStream(readableWebToNodeStream);
await readableWebToNodeStream.close();
return fileType;
}
export async function fileTypeFromBlob(blob) {
const buffer = await blobToArrayBuffer(blob);
return fileTypeFromBuffer(Buffer.from(buffer));
}
export {
fileTypeFromTokenizer,
fileTypeFromBuffer,
fileTypeStream,
} from './core.js';

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

@ -0,0 +1,403 @@
import type {Readable as ReadableStream} from 'node:stream';
import type {ITokenizer} from 'strtok3';
export type FileExtension =
| 'jpg'
| 'png'
| 'apng'
| 'gif'
| 'webp'
| 'flif'
| 'xcf'
| 'cr2'
| 'cr3'
| 'orf'
| 'arw'
| 'dng'
| 'nef'
| 'rw2'
| 'raf'
| 'tif'
| 'bmp'
| 'icns'
| 'jxr'
| 'psd'
| 'indd'
| 'zip'
| 'tar'
| 'rar'
| 'gz'
| 'bz2'
| '7z'
| 'dmg'
| 'mp4'
| 'mid'
| 'mkv'
| 'webm'
| 'mov'
| 'avi'
| 'mpg'
| 'mp2'
| 'mp3'
| 'm4a'
| 'ogg'
| 'opus'
| 'flac'
| 'wav'
| 'qcp'
| 'amr'
| 'pdf'
| 'epub'
| 'mobi'
| 'elf'
| 'exe'
| 'swf'
| 'rtf'
| 'woff'
| 'woff2'
| 'eot'
| 'ttf'
| 'otf'
| 'ico'
| 'flv'
| 'ps'
| 'xz'
| 'sqlite'
| 'nes'
| 'crx'
| 'xpi'
| 'cab'
| 'deb'
| 'ar'
| 'rpm'
| 'Z'
| 'lz'
| 'cfb'
| 'mxf'
| 'mts'
| 'wasm'
| 'blend'
| 'bpg'
| 'docx'
| 'pptx'
| 'xlsx'
| '3gp'
| '3g2'
| 'jp2'
| 'jpm'
| 'jpx'
| 'mj2'
| 'aif'
| 'odt'
| 'ods'
| 'odp'
| 'xml'
| 'heic'
| 'cur'
| 'ktx'
| 'ape'
| 'wv'
| 'asf'
| 'dcm'
| 'mpc'
| 'ics'
| 'glb'
| 'pcap'
| 'dsf'
| 'lnk'
| 'alias'
| 'voc'
| 'ac3'
| 'm4b'
| 'm4p'
| 'm4v'
| 'f4a'
| 'f4b'
| 'f4p'
| 'f4v'
| 'mie'
| 'ogv'
| 'ogm'
| 'oga'
| 'spx'
| 'ogx'
| 'arrow'
| 'shp'
| 'aac'
| 'mp1'
| 'it'
| 's3m'
| 'xm'
| 'ai'
| 'skp'
| 'avif'
| 'eps'
| 'lzh'
| 'pgp'
| 'asar'
| 'stl'
| 'chm'
| '3mf'
| 'zst'
| 'jxl'
| 'vcf'
| 'jls'
| 'pst'
| 'dwg'
| 'parquet';
export type MimeType =
| 'image/jpeg'
| 'image/png'
| 'image/gif'
| 'image/webp'
| 'image/flif'
| 'image/x-xcf'
| 'image/x-canon-cr2'
| 'image/x-canon-cr3'
| 'image/tiff'
| 'image/bmp'
| 'image/icns'
| 'image/vnd.ms-photo'
| 'image/vnd.adobe.photoshop'
| 'application/x-indesign'
| 'application/epub+zip'
| 'application/x-xpinstall'
| 'application/vnd.oasis.opendocument.text'
| 'application/vnd.oasis.opendocument.spreadsheet'
| 'application/vnd.oasis.opendocument.presentation'
| 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
| 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
| 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
| 'application/zip'
| 'application/x-tar'
| 'application/x-rar-compressed'
| 'application/gzip'
| 'application/x-bzip2'
| 'application/x-7z-compressed'
| 'application/x-apple-diskimage'
| 'video/mp4'
| 'audio/midi'
| 'video/x-matroska'
| 'video/webm'
| 'video/quicktime'
| 'video/vnd.avi'
| 'audio/vnd.wave'
| 'audio/qcelp'
| 'audio/x-ms-asf'
| 'video/x-ms-asf'
| 'application/vnd.ms-asf'
| 'video/mpeg'
| 'video/3gpp'
| 'audio/mpeg'
| 'audio/mp4' // RFC 4337
| 'audio/opus'
| 'video/ogg'
| 'audio/ogg'
| 'application/ogg'
| 'audio/x-flac'
| 'audio/ape'
| 'audio/wavpack'
| 'audio/amr'
| 'application/pdf'
| 'application/x-elf'
| 'application/x-msdownload'
| 'application/x-shockwave-flash'
| 'application/rtf'
| 'application/wasm'
| 'font/woff'
| 'font/woff2'
| 'application/vnd.ms-fontobject'
| 'font/ttf'
| 'font/otf'
| 'image/x-icon'
| 'video/x-flv'
| 'application/postscript'
| 'application/eps'
| 'application/x-xz'
| 'application/x-sqlite3'
| 'application/x-nintendo-nes-rom'
| 'application/x-google-chrome-extension'
| 'application/vnd.ms-cab-compressed'
| 'application/x-deb'
| 'application/x-unix-archive'
| 'application/x-rpm'
| 'application/x-compress'
| 'application/x-lzip'
| 'application/x-cfb'
| 'application/x-mie'
| 'application/x-apache-arrow'
| 'application/mxf'
| 'video/mp2t'
| 'application/x-blender'
| 'image/bpg'
| 'image/jp2'
| 'image/jpx'
| 'image/jpm'
| 'image/mj2'
| 'audio/aiff'
| 'application/xml'
| 'application/x-mobipocket-ebook'
| 'image/heif'
| 'image/heif-sequence'
| 'image/heic'
| 'image/heic-sequence'
| 'image/ktx'
| 'application/dicom'
| 'audio/x-musepack'
| 'text/calendar'
| 'text/vcard'
| 'model/gltf-binary'
| 'application/vnd.tcpdump.pcap'
| 'audio/x-dsf' // Non-standard
| 'application/x.ms.shortcut' // Invented by us
| 'application/x.apple.alias' // Invented by us
| 'audio/x-voc'
| 'audio/vnd.dolby.dd-raw'
| 'audio/x-m4a'
| 'image/apng'
| 'image/x-olympus-orf'
| 'image/x-sony-arw'
| 'image/x-adobe-dng'
| 'image/x-nikon-nef'
| 'image/x-panasonic-rw2'
| 'image/x-fujifilm-raf'
| 'video/x-m4v'
| 'video/3gpp2'
| 'application/x-esri-shape'
| 'audio/aac'
| 'audio/x-it'
| 'audio/x-s3m'
| 'audio/x-xm'
| 'video/MP1S'
| 'video/MP2P'
| 'application/vnd.sketchup.skp'
| 'image/avif'
| 'application/x-lzh-compressed'
| 'application/pgp-encrypted'
| 'application/x-asar'
| 'model/stl'
| 'application/vnd.ms-htmlhelp'
| 'model/3mf'
| 'image/jxl'
| 'application/zstd'
| 'image/jls'
| 'application/vnd.ms-outlook'
| 'image/vnd.dwg'
| 'application/x-parquet';
export type FileTypeResult = {
/**
One of the supported [file types](https://github.com/sindresorhus/file-type#supported-file-types).
*/
readonly ext: FileExtension;
/**
The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type).
*/
readonly mime: MimeType;
};
export type ReadableStreamWithFileType = ReadableStream & {
readonly fileType?: FileTypeResult;
};
/**
Detect the file type of a `Buffer`, `Uint8Array`, or `ArrayBuffer`.
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.
If file access is available, it is recommended to use `.fromFile()` instead.
@param buffer - An Uint8Array or Buffer representing file data. It works best if the buffer contains the entire file, it may work with a smaller portion as well.
@returns The detected file type and MIME type, or `undefined` when there is no match.
*/
export function fileTypeFromBuffer(buffer: Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
/**
Detect the file type of a Node.js [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
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.
@param stream - A readable stream representing file data.
@returns The detected file type and MIME type, or `undefined` when there is no match.
*/
export function fileTypeFromStream(stream: ReadableStream): Promise<FileTypeResult | undefined>;
/**
Detect the file type from an [`ITokenizer`](https://github.com/Borewit/strtok3#tokenizer) source.
This method is used internally, but can also be used for a special "tokenizer" reader.
A tokenizer propagates the internal read functions, allowing alternative transport mechanisms, to access files, to be implemented and used.
@param tokenizer - File source implementing the tokenizer interface.
@returns The detected file type and MIME type, or `undefined` when there is no match.
An example is [`@tokenizer/http`](https://github.com/Borewit/tokenizer-http), which requests data using [HTTP-range-requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests). A difference with a conventional stream and the [*tokenizer*](https://github.com/Borewit/strtok3#tokenizer), is that it is able to *ignore* (seek, fast-forward) in the stream. For example, you may only need and read the first 6 bytes, and the last 128 bytes, which may be an advantage in case reading the entire file would take longer.
@example
```
import {makeTokenizer} from '@tokenizer/http';
import {fileTypeFromTokenizer} from 'file-type';
const audioTrackUrl = 'https://test-audio.netlify.com/Various%20Artists%20-%202009%20-%20netBloc%20Vol%2024_%20tiuqottigeloot%20%5BMP3-V2%5D/01%20-%20Diablo%20Swing%20Orchestra%20-%20Heroines.mp3';
const httpTokenizer = await makeTokenizer(audioTrackUrl);
const fileType = await fileTypeFromTokenizer(httpTokenizer);
console.log(fileType);
//=> {ext: 'mp3', mime: 'audio/mpeg'}
```
*/
export function fileTypeFromTokenizer(tokenizer: ITokenizer): Promise<FileTypeResult | undefined>;
/**
Supported file extensions.
*/
export const supportedExtensions: ReadonlySet<FileExtension>;
/**
Supported MIME types.
*/
export const supportedMimeTypes: ReadonlySet<MimeType>;
export type StreamOptions = {
/**
The default sample size in bytes.
@default 4100
*/
readonly sampleSize?: number;
};
/**
Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
This method can be handy to put in between a stream, but it comes with a price.
Internally `stream()` builds up a buffer of `sampleSize` bytes, used as a sample, to determine the file type.
The sample size impacts the file detection resolution.
A smaller sample size will result in lower probability of the best file type detection.
**Note:** This method is only available when using Node.js.
**Note:** Requires Node.js 14 or later.
@param readableStream - A [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) containing a file to examine.
@returns A `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
@example
```
import got from 'got';
import {fileTypeStream} from 'file-type';
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
const stream1 = got.stream(url);
const stream2 = await fileTypeStream(stream1, {sampleSize: 1024});
if (stream2.fileType?.mime === 'image/jpeg') {
// stream2 can be used to stream the JPEG image (from the very beginning of the stream)
}
```
*/
export function fileTypeStream(readableStream: ReadableStream, options?: StreamOptions): Promise<ReadableStreamWithFileType>;

1570
node_modules/file-type/core.js generated vendored Normal file

File diff suppressed because it is too large Load diff

13
node_modules/file-type/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,13 @@
import type {FileTypeResult} from './core.js';
/**
Detect the file type of a file path.
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.
@param path - The file path to parse.
@returns The detected file type and MIME type or `undefined` when there is no match.
*/
export function fileTypeFromFile(path: string): Promise<FileTypeResult | undefined>;
export * from './core.js';

13
node_modules/file-type/index.js generated vendored Normal file
View file

@ -0,0 +1,13 @@
import * as strtok3 from 'strtok3';
import {fileTypeFromTokenizer} from './core.js';
export async function fileTypeFromFile(path) {
const tokenizer = await strtok3.fromFile(path);
try {
return await fileTypeFromTokenizer(tokenizer);
} finally {
await tokenizer.close();
}
}
export * from './core.js';

9
node_modules/file-type/license generated vendored Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

234
node_modules/file-type/package.json generated vendored Normal file
View file

@ -0,0 +1,234 @@
{
"name": "file-type",
"version": "18.2.0",
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
"license": "MIT",
"repository": "sindresorhus/file-type",
"funding": "https://github.com/sindresorhus/file-type?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": {
".": {
"node": "./index.js",
"default": "./browser.js"
},
"./core": "./core.js"
},
"engines": {
"node": ">=14.16"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts",
"browser.js",
"browser.d.ts",
"core.js",
"core.d.ts",
"supported.js",
"util.js"
],
"keywords": [
"mime",
"file",
"type",
"magic",
"archive",
"image",
"img",
"pic",
"picture",
"flash",
"photo",
"video",
"detect",
"check",
"is",
"exif",
"elf",
"exe",
"binary",
"buffer",
"uint8array",
"jpg",
"png",
"apng",
"gif",
"webp",
"flif",
"xcf",
"cr2",
"cr3",
"orf",
"arw",
"dng",
"nef",
"rw2",
"raf",
"tif",
"bmp",
"icns",
"jxr",
"psd",
"indd",
"zip",
"tar",
"rar",
"gz",
"bz2",
"7z",
"dmg",
"mp4",
"mid",
"mkv",
"webm",
"mov",
"avi",
"mpg",
"mp2",
"mp3",
"m4a",
"ogg",
"opus",
"flac",
"wav",
"amr",
"pdf",
"epub",
"mobi",
"swf",
"rtf",
"woff",
"woff2",
"eot",
"ttf",
"otf",
"ico",
"flv",
"ps",
"xz",
"sqlite",
"xpi",
"cab",
"deb",
"ar",
"rpm",
"Z",
"lz",
"cfb",
"mxf",
"mts",
"wasm",
"webassembly",
"blend",
"bpg",
"docx",
"pptx",
"xlsx",
"3gp",
"jp2",
"jpm",
"jpx",
"mj2",
"aif",
"odt",
"ods",
"odp",
"xml",
"heic",
"ics",
"glb",
"pcap",
"dsf",
"lnk",
"alias",
"voc",
"ac3",
"3g2",
"m4b",
"m4p",
"m4v",
"f4a",
"f4b",
"f4p",
"f4v",
"mie",
"qcp",
"asf",
"ogv",
"ogm",
"oga",
"spx",
"ogx",
"ape",
"wv",
"cur",
"nes",
"crx",
"ktx",
"dcm",
"mpc",
"arrow",
"shp",
"aac",
"mp1",
"it",
"s3m",
"xm",
"ai",
"skp",
"avif",
"eps",
"lzh",
"pgp",
"asar",
"stl",
"chm",
"3mf",
"zst",
"jxl",
"vcf",
"jls",
"pst",
"dwg",
"parquet"
],
"dependencies": {
"readable-web-to-node-stream": "^3.0.2",
"strtok3": "^7.0.0",
"token-types": "^5.0.1"
},
"devDependencies": {
"@tokenizer/token": "^0.3.0",
"@types/node": "^18.7.13",
"ava": "^5.1.0",
"commonmark": "^0.30.0",
"noop-stream": "^1.0.0",
"tsd": "^0.25.0",
"xo": "^0.53.1"
},
"xo": {
"envs": [
"node",
"browser"
],
"rules": {
"no-inner-declarations": "warn",
"no-await-in-loop": "warn",
"no-bitwise": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"unicorn/text-encoding-identifier-case": "off",
"unicorn/switch-case-braces": "off",
"unicorn/prefer-top-level-await": "off"
}
},
"ava": {
"serial": true
}
}

509
node_modules/file-type/readme.md generated vendored Normal file
View file

@ -0,0 +1,509 @@
# file-type
> Detect the file type of a Buffer/Uint8Array/ArrayBuffer
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.
This package is for detecting binary-based file formats, not text-based formats like `.txt`, `.csv`, `.svg`, etc.
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
npm install file-type
```
**This package is a ESM package. Your project needs to be ESM too. [Read more](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).**
If you use it with Webpack, you need the latest Webpack version and ensure you configure it correctly for ESM.
## Usage
#### Node.js
Determine file type from a file:
```js
import {fileTypeFromFile} from 'file-type';
console.log(await fileTypeFromFile('Unicorn.png'));
//=> {ext: 'png', mime: 'image/png'}
```
Determine file type from a Buffer, which may be a portion of the beginning of a file:
```js
import {fileTypeFromBuffer} from 'file-type';
import {readChunk} from 'read-chunk';
const buffer = await readChunk('Unicorn.png', {length: 4100});
console.log(await fileTypeFromBuffer(buffer));
//=> {ext: 'png', mime: 'image/png'}
```
Determine file type from a stream:
```js
import fs from 'node:fs';
import {fileTypeFromStream} from 'file-type';
const stream = fs.createReadStream('Unicorn.mp4');
console.log(await fileTypeFromStream(stream));
//=> {ext: 'mp4', mime: 'video/mp4'}
```
The stream method can also be used to read from a remote location:
```js
import got from 'got';
import {fileTypeFromStream} from 'file-type';
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
const stream = got.stream(url);
console.log(await fileTypeFromStream(stream));
//=> {ext: 'jpg', mime: 'image/jpeg'}
```
Another stream example:
```js
import stream from 'node:stream';
import fs from 'node:fs';
import crypto from 'node:crypto';
import {fileTypeStream} from 'file-type';
const read = fs.createReadStream('encrypted.enc');
const decipher = crypto.createDecipheriv(alg, key, iv);
const streamWithFileType = await fileTypeStream(stream.pipeline(read, decipher));
console.log(streamWithFileType.fileType);
//=> {ext: 'mov', mime: 'video/quicktime'}
const write = fs.createWriteStream(`decrypted.${streamWithFileType.fileType.ext}`);
streamWithFileType.pipe(write);
```
#### Browser
```js
import {fileTypeFromStream} from 'file-type';
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
const response = await fetch(url);
const fileType = await fileTypeFromStream(response.body);
console.log(fileType);
//=> {ext: 'jpg', mime: 'image/jpeg'}
```
## API
### fileTypeFromBuffer(buffer)
Detect the file type of a `Buffer`, `Uint8Array`, or `ArrayBuffer`.
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.
If file access is available, it is recommended to use `fileTypeFromFile()` instead.
Returns a `Promise` for an object with the detected file type and MIME type:
- `ext` - One of the [supported file types](#supported-file-types)
- `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
Or `undefined` when there is no match.
#### buffer
Type: `Buffer | Uint8Array | ArrayBuffer`
A buffer representing file data. It works best if the buffer contains the entire file, it may work with a smaller portion as well.
### fileTypeFromFile(filePath)
Detect the file type of a file path.
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:
- `ext` - One of the [supported file types](#supported-file-types)
- `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
Or `undefined` when there is no match.
#### filePath
Type: `string`
The file path to parse.
### fileTypeFromStream(stream)
Detect the file type of a Node.js [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
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:
- `ext` - One of the [supported file types](#supported-file-types)
- `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
Or `undefined` when there is no match.
#### stream
Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)
A readable stream representing file data.
### fileTypeFromBlob(blob)
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:
- `ext` - One of the [supported file types](#supported-file-types)
- `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
Or `undefined` when there is no match.
```js
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'}
```
### fileTypeFromTokenizer(tokenizer)
Detect the file type from an `ITokenizer` source.
This method is used internally, but can also be used for a special "tokenizer" reader.
A tokenizer propagates the internal read functions, allowing alternative transport mechanisms, to access files, to be implemented and used.
Returns a `Promise` for an object with the detected file type and MIME type:
- `ext` - One of the [supported file types](#supported-file-types)
- `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)
Or `undefined` when there is no match.
An example is [`@tokenizer/http`](https://github.com/Borewit/tokenizer-http), which requests data using [HTTP-range-requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests). A difference with a conventional stream and the [*tokenizer*](https://github.com/Borewit/strtok3#tokenizer), is that it can *ignore* (seek, fast-forward) in the stream. For example, you may only need and read the first 6 bytes, and the last 128 bytes, which may be an advantage in case reading the entire file would take longer.
```js
import {makeTokenizer} from '@tokenizer/http';
import {fileTypeFromTokenizer} from 'file-type';
const audioTrackUrl = 'https://test-audio.netlify.com/Various%20Artists%20-%202009%20-%20netBloc%20Vol%2024_%20tiuqottigeloot%20%5BMP3-V2%5D/01%20-%20Diablo%20Swing%20Orchestra%20-%20Heroines.mp3';
const httpTokenizer = await makeTokenizer(audioTrackUrl);
const fileType = await fileTypeFromTokenizer(httpTokenizer);
console.log(fileType);
//=> {ext: 'mp3', mime: 'audio/mpeg'}
```
Or use [`@tokenizer/s3`](https://github.com/Borewit/tokenizer-s3) to determine the file type of a file stored on [Amazon S3](https://aws.amazon.com/s3):
```js
import S3 from 'aws-sdk/clients/s3';
import {makeTokenizer} from '@tokenizer/s3';
import {fileTypeFromTokenizer} from 'file-type';
// Initialize the S3 client
const s3 = new S3();
// Initialize the S3 tokenizer.
const s3Tokenizer = await makeTokenizer(s3, {
Bucket: 'affectlab',
Key: '1min_35sec.mp4'
});
// Figure out what kind of file it is.
const fileType = await fileTypeFromTokenizer(s3Tokenizer);
console.log(fileType);
```
Note that only the minimum amount of data required to determine the file type is read (okay, just a bit extra to prevent too many fragmented reads).
#### tokenizer
Type: [`ITokenizer`](https://github.com/Borewit/strtok3#tokenizer)
A file source implementing the [tokenizer interface](https://github.com/Borewit/strtok3#tokenizer).
### fileTypeStream(readableStream, options?)
Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
This method can be handy to put in between a stream, but it comes with a price.
Internally `stream()` builds up a buffer of `sampleSize` bytes, used as a sample, to determine the file type.
The sample size impacts the file detection resolution.
A smaller sample size will result in lower probability of the best file type detection.
**Note:** This method is only available when using Node.js.
**Note:** Requires Node.js 14 or later.
#### readableStream
Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)
#### options
Type: `object`
##### sampleSize
Type: `number`\
Default: `4100`
The sample size in bytes.
#### Example
```js
import got from 'got';
import {fileTypeStream} from 'file-type';
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
const stream1 = got.stream(url);
const stream2 = await fileTypeStream(stream1, {sampleSize: 1024});
if (stream2.fileType?.mime === 'image/jpeg') {
// stream2 can be used to stream the JPEG image (from the very beginning of the stream)
}
```
#### readableStream
Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)
The input stream.
### supportedExtensions
Returns a `Set<string>` of supported file extensions.
### supportedMimeTypes
Returns a `Set<string>` of supported MIME types.
## Supported file types
- [`3g2`](https://en.wikipedia.org/wiki/3GP_and_3G2#3G2) - Multimedia container format defined by the 3GPP2 for 3G CDMA2000 multimedia services
- [`3gp`](https://en.wikipedia.org/wiki/3GP_and_3G2#3GP) - Multimedia container format defined by the Third Generation Partnership Project (3GPP) for 3G UMTS multimedia services
- [`3mf`](https://en.wikipedia.org/wiki/3D_Manufacturing_Format) - 3D Manufacturing Format
- [`7z`](https://en.wikipedia.org/wiki/7z) - 7-Zip archive
- [`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
- [`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
- [`amr`](https://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec) - Adaptive Multi-Rate audio codec
- [`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
- [`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
- [`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
- [`bz2`](https://en.wikipedia.org/wiki/Bzip2) - Archive file
- [`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
- [`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
- [`cur`](https://en.wikipedia.org/wiki/ICO_(file_format)) - Icon file
- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File
- [`deb`](https://en.wikipedia.org/wiki/Deb_(file_format)) - Debian package
- [`dmg`](https://en.wikipedia.org/wiki/Apple_Disk_Image) - Apple Disk Image
- [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Adobe Digital Negative image file
- [`docx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Word
- [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)
- [`dwg`](https://en.wikipedia.org/wiki/.dwg) - Autodesk CAD file
- [`elf`](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) - Unix Executable and Linkable Format
- [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType) - Embedded OpenType font
- [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript
- [`epub`](https://en.wikipedia.org/wiki/EPUB) - E-book file
- [`exe`](https://en.wikipedia.org/wiki/.exe) - Executable file
- [`f4a`](https://en.wikipedia.org/wiki/Flash_Video) - Audio-only ISO base media file format used by Adobe Flash Player
- [`f4b`](https://en.wikipedia.org/wiki/Flash_Video) - Audiobook and podcast ISO base media file format used by Adobe Flash Player
- [`f4p`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format protected by Adobe Access DRM used by Adobe Flash Player
- [`f4v`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format used by Adobe Flash Player
- [`flac`](https://en.wikipedia.org/wiki/FLAC) - Free Lossless Audio Codec
- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format) - Free Lossless Image Format
- [`flv`](https://en.wikipedia.org/wiki/Flash_Video) - Flash video
- [`gif`](https://en.wikipedia.org/wiki/GIF) - Graphics Interchange Format
- [`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
- [`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
- [`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
- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
- [`jpx`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
- [`jxl`](https://en.wikipedia.org/wiki/JPEG_XL) - JPEG XL image format
- [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR) - Joint Photographic Experts Group extended range
- [`ktx`](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) - OpenGL and OpenGL ES textures
- [`lnk`](https://en.wikipedia.org/wiki/Shortcut_%28computing%29#Microsoft_Windows) - Microsoft Windows file shortcut
- [`lz`](https://en.wikipedia.org/wiki/Lzip) - Arhive file
- [`lzh`](https://en.wikipedia.org/wiki/LHA_(file_format)) - LZH archive
- [`m4a`](https://en.wikipedia.org/wiki/M4A) - Audio-only MPEG-4 files
- [`m4b`](https://en.wikipedia.org/wiki/M4B) - Audiobook and podcast MPEG-4 files, which also contain metadata including chapter markers, images, and hyperlinks
- [`m4p`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 files with audio streams encrypted by FairPlay Digital Rights Management as were sold through the iTunes Store
- [`m4v`](https://en.wikipedia.org/wiki/M4V) - Video container format developed by Apple, which is very similar to the MP4 format
- [`mid`](https://en.wikipedia.org/wiki/MIDI) - Musical Instrument Digital Interface file
- [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Dedicated meta information format which supports storage of binary as well as textual meta information
- [`mj2`](https://en.wikipedia.org/wiki/Motion_JPEG_2000) - Motion JPEG 2000
- [`mkv`](https://en.wikipedia.org/wiki/Matroska) - Matroska video file
- [`mobi`](https://en.wikipedia.org/wiki/Mobipocket) - Mobipocket
- [`mov`](https://en.wikipedia.org/wiki/QuickTime_File_Format) - QuickTime video file
- [`mp1`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_I) - MPEG-1 Audio Layer I
- [`mp2`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_II) - MPEG-1 Audio Layer II
- [`mp3`](https://en.wikipedia.org/wiki/MP3) - Audio file
- [`mp4`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 Part 14 video file
- [`mpc`](https://en.wikipedia.org/wiki/Musepack) - Musepack (SV7 & SV8)
- [`mpg`](https://en.wikipedia.org/wiki/MPEG-1) - MPEG-1 file
- [`mts`](https://en.wikipedia.org/wiki/.m2ts) - MPEG-2 Transport Stream, both raw and Blu-ray Disc Audio-Video (BDAV) versions
- [`mxf`](https://en.wikipedia.org/wiki/Material_Exchange_Format) - Material Exchange Format
- [`nef`](https://www.nikonusa.com/en/learn-and-explore/a/products-and-innovation/nikon-electronic-format-nef.html) - Nikon Electronic Format image file
- [`nes`](https://fileinfo.com/extension/nes) - Nintendo NES ROM
- [`odp`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for presentations
- [`ods`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for spreadsheets
- [`odt`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for word processing
- [`oga`](https://en.wikipedia.org/wiki/Ogg) - Audio file
- [`ogg`](https://en.wikipedia.org/wiki/Ogg) - Audio file
- [`ogm`](https://en.wikipedia.org/wiki/Ogg) - Audio file
- [`ogv`](https://en.wikipedia.org/wiki/Ogg) - Audio file
- [`ogx`](https://en.wikipedia.org/wiki/Ogg) - Audio file
- [`opus`](https://en.wikipedia.org/wiki/Opus_(audio_format)) - Audio file
- [`orf`](https://en.wikipedia.org/wiki/ORF_format) - Olympus Raw image file
- [`otf`](https://en.wikipedia.org/wiki/OpenType) - OpenType font
- [`parquet`](https://en.wikipedia.org/wiki/Apache_Parquet) - Apache Parquet
- [`pcap`](https://wiki.wireshark.org/Development/LibpcapFileFormat) - Libpcap File Format
- [`pdf`](https://en.wikipedia.org/wiki/Portable_Document_Format) - Portable Document Format
- [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - Pretty Good Privacy
- [`png`](https://en.wikipedia.org/wiki/Portable_Network_Graphics) - Portable Network Graphics
- [`pptx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Powerpoint
- [`ps`](https://en.wikipedia.org/wiki/Postscript) - Postscript
- [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format) - Adobe Photoshop document
- [`pst`](https://en.wikipedia.org/wiki/Personal_Storage_Table) - Personal Storage Table file
- [`qcp`](https://en.wikipedia.org/wiki/QCP) - Tagged and chunked data
- [`raf`](https://en.wikipedia.org/wiki/Raw_image_format) - Fujifilm RAW image file
- [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format)) - Archive file
- [`rpm`](https://fileinfo.com/extension/rpm) - Red Hat Package Manager file
- [`rtf`](https://en.wikipedia.org/wiki/Rich_Text_Format) - Rich Text Format
- [`rw2`](https://en.wikipedia.org/wiki/Raw_image_format) - Panasonic RAW image file
- [`s3m`](https://wiki.openmpt.org/Manual:_Module_formats#The_ScreamTracker_3_format_.28.s3m.29) - Audio module format: ScreamTracker 3
- [`shp`](https://en.wikipedia.org/wiki/Shapefile) - Geospatial vector data format
- [`skp`](https://en.wikipedia.org/wiki/SketchUp) - SketchUp
- [`spx`](https://en.wikipedia.org/wiki/Ogg) - Audio file
- [`sqlite`](https://www.sqlite.org/fileformat2.html) - SQLite file
- [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Standard Tesselated Geometry File Format (ASCII only)
- [`swf`](https://en.wikipedia.org/wiki/SWF) - Adobe Flash Player file
- [`tar`](https://en.wikipedia.org/wiki/Tar_(computing)#File_format) - Tarball archive file
- [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format) - Tagged Image file
- [`ttf`](https://en.wikipedia.org/wiki/TrueType) - TrueType font
- [`vcf`](https://en.wikipedia.org/wiki/VCard) - vCard
- [`voc`](https://wiki.multimedia.cx/index.php/Creative_Voice) - Creative Voice File
- [`wasm`](https://en.wikipedia.org/wiki/WebAssembly) - WebAssembly intermediate compiled format
- [`wav`](https://en.wikipedia.org/wiki/WAV) - Waveform Audio file
- [`webm`](https://en.wikipedia.org/wiki/WebM) - Web video file
- [`webp`](https://en.wikipedia.org/wiki/WebP) - Web Picture format
- [`woff`](https://en.wikipedia.org/wiki/Web_Open_Font_Format) - Web Open Font Format
- [`woff2`](https://en.wikipedia.org/wiki/Web_Open_Font_Format) - Web Open Font Format
- [`wv`](https://en.wikipedia.org/wiki/WavPack) - WavPack
- [`xcf`](https://en.wikipedia.org/wiki/XCF_(file_format)) - eXperimental Computing Facility
- [`xlsx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Excel
- [`xm`](https://wiki.openmpt.org/Manual:_Module_formats#The_FastTracker_2_format_.28.xm.29) - Audio module format: FastTracker 2
- [`xml`](https://en.wikipedia.org/wiki/XML) - eXtensible Markup Language
- [`xpi`](https://en.wikipedia.org/wiki/XPInstall) - XPInstall file
- [`xz`](https://en.wikipedia.org/wiki/Xz) - Compressed file
- [`zip`](https://en.wikipedia.org/wiki/Zip_(file_format)) - Archive file
- [`zst`](https://en.wikipedia.org/wiki/Zstandard) - Archive file
*Pull requests are welcome for additional commonly used file types.*
The following file types will not be accepted:
- [MS-CFB: Microsoft Compound File Binary File Format based formats](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cfb/53989ce4-7b05-4f8d-829b-d08d6148375b), too old and difficult to parse:
- `.doc` - Microsoft Word 97-2003 Document
- `.xls` - Microsoft Excel 97-2003 Document
- `.ppt` - Microsoft PowerPoint97-2003 Document
- `.msi` - Microsoft Windows Installer
- `.csv` - [Reason.](https://github.com/sindresorhus/file-type/issues/264#issuecomment-568439196)
- `.svg` - Detecting it requires a full-blown parser. Check out [`is-svg`](https://github.com/sindresorhus/is-svg) for something that mostly works.
## Related
- [file-type-cli](https://github.com/sindresorhus/file-type-cli) - CLI for this module
## Maintainers
- [Sindre Sorhus](https://github.com/sindresorhus)
- [Borewit](https://github.com/Borewit)
**Former**
- [Mikael Finstad](https://github.com/mifi)
- [Ben Brook](https://github.com/bencmbrook)

286
node_modules/file-type/supported.js generated vendored Normal file
View file

@ -0,0 +1,286 @@
export const extensions = [
'jpg',
'png',
'apng',
'gif',
'webp',
'flif',
'xcf',
'cr2',
'cr3',
'orf',
'arw',
'dng',
'nef',
'rw2',
'raf',
'tif',
'bmp',
'icns',
'jxr',
'psd',
'indd',
'zip',
'tar',
'rar',
'gz',
'bz2',
'7z',
'dmg',
'mp4',
'mid',
'mkv',
'webm',
'mov',
'avi',
'mpg',
'mp2',
'mp3',
'm4a',
'oga',
'ogg',
'ogv',
'opus',
'flac',
'wav',
'spx',
'amr',
'pdf',
'epub',
'elf',
'exe',
'swf',
'rtf',
'wasm',
'woff',
'woff2',
'eot',
'ttf',
'otf',
'ico',
'flv',
'ps',
'xz',
'sqlite',
'nes',
'crx',
'xpi',
'cab',
'deb',
'ar',
'rpm',
'Z',
'lz',
'cfb',
'mxf',
'mts',
'blend',
'bpg',
'docx',
'pptx',
'xlsx',
'3gp',
'3g2',
'jp2',
'jpm',
'jpx',
'mj2',
'aif',
'qcp',
'odt',
'ods',
'odp',
'xml',
'mobi',
'heic',
'cur',
'ktx',
'ape',
'wv',
'dcm',
'ics',
'glb',
'pcap',
'dsf',
'lnk',
'alias',
'voc',
'ac3',
'm4v',
'm4p',
'm4b',
'f4v',
'f4p',
'f4b',
'f4a',
'mie',
'asf',
'ogm',
'ogx',
'mpc',
'arrow',
'shp',
'aac',
'mp1',
'it',
's3m',
'xm',
'ai',
'skp',
'avif',
'eps',
'lzh',
'pgp',
'asar',
'stl',
'chm',
'3mf',
'zst',
'jxl',
'vcf',
'jls',
'pst',
'dwg',
'parquet',
];
export const mimeTypes = [
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
'image/flif',
'image/x-xcf',
'image/x-canon-cr2',
'image/x-canon-cr3',
'image/tiff',
'image/bmp',
'image/vnd.ms-photo',
'image/vnd.adobe.photoshop',
'application/x-indesign',
'application/epub+zip',
'application/x-xpinstall',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.presentation',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/zip',
'application/x-tar',
'application/x-rar-compressed',
'application/gzip',
'application/x-bzip2',
'application/x-7z-compressed',
'application/x-apple-diskimage',
'application/x-apache-arrow',
'video/mp4',
'audio/midi',
'video/x-matroska',
'video/webm',
'video/quicktime',
'video/vnd.avi',
'audio/vnd.wave',
'audio/qcelp',
'audio/x-ms-asf',
'video/x-ms-asf',
'application/vnd.ms-asf',
'video/mpeg',
'video/3gpp',
'audio/mpeg',
'audio/mp4', // RFC 4337
'audio/opus',
'video/ogg',
'audio/ogg',
'application/ogg',
'audio/x-flac',
'audio/ape',
'audio/wavpack',
'audio/amr',
'application/pdf',
'application/x-elf',
'application/x-msdownload',
'application/x-shockwave-flash',
'application/rtf',
'application/wasm',
'font/woff',
'font/woff2',
'application/vnd.ms-fontobject',
'font/ttf',
'font/otf',
'image/x-icon',
'video/x-flv',
'application/postscript',
'application/eps',
'application/x-xz',
'application/x-sqlite3',
'application/x-nintendo-nes-rom',
'application/x-google-chrome-extension',
'application/vnd.ms-cab-compressed',
'application/x-deb',
'application/x-unix-archive',
'application/x-rpm',
'application/x-compress',
'application/x-lzip',
'application/x-cfb',
'application/x-mie',
'application/mxf',
'video/mp2t',
'application/x-blender',
'image/bpg',
'image/jp2',
'image/jpx',
'image/jpm',
'image/mj2',
'audio/aiff',
'application/xml',
'application/x-mobipocket-ebook',
'image/heif',
'image/heif-sequence',
'image/heic',
'image/heic-sequence',
'image/icns',
'image/ktx',
'application/dicom',
'audio/x-musepack',
'text/calendar',
'text/vcard',
'model/gltf-binary',
'application/vnd.tcpdump.pcap',
'audio/x-dsf', // Non-standard
'application/x.ms.shortcut', // Invented by us
'application/x.apple.alias', // Invented by us
'audio/x-voc',
'audio/vnd.dolby.dd-raw',
'audio/x-m4a',
'image/apng',
'image/x-olympus-orf',
'image/x-sony-arw',
'image/x-adobe-dng',
'image/x-nikon-nef',
'image/x-panasonic-rw2',
'image/x-fujifilm-raf',
'video/x-m4v',
'video/3gpp2',
'application/x-esri-shape',
'audio/aac',
'audio/x-it',
'audio/x-s3m',
'audio/x-xm',
'video/MP1S',
'video/MP2P',
'application/vnd.sketchup.skp',
'image/avif',
'application/x-lzh-compressed',
'application/pgp-encrypted',
'application/x-asar',
'model/stl',
'application/vnd.ms-htmlhelp',
'model/3mf',
'image/jxl',
'application/zstd',
'image/jls',
'application/vnd.ms-outlook',
'image/vnd.dwg',
'application/x-parquet',
];

38
node_modules/file-type/util.js generated vendored Normal file
View file

@ -0,0 +1,38 @@
export function stringToBytes(string) {
return [...string].map(character => character.charCodeAt(0)); // eslint-disable-line unicorn/prefer-code-point
}
/**
Checks whether the TAR checksum is valid.
@param {Buffer} buffer - The TAR header `[offset ... offset + 512]`.
@param {number} offset - TAR header offset.
@returns {boolean} `true` if the TAR checksum is valid, otherwise `false`.
*/
export function tarHeaderChecksumMatches(buffer, offset = 0) {
const readSum = Number.parseInt(buffer.toString('utf8', 148, 154).replace(/\0.*$/, '').trim(), 8); // Read sum in header
if (Number.isNaN(readSum)) {
return false;
}
let sum = 8 * 0x20; // Initialize signed bit sum
for (let index = offset; index < offset + 148; index++) {
sum += buffer[index];
}
for (let index = offset + 156; index < offset + 512; index++) {
sum += buffer[index];
}
return readSum === sum;
}
/**
ID3 UINT32 sync-safe tokenizer token.
28 bits (representing up to 256MB) integer, the msb is 0 to avoid "false syncsignals".
*/
export const uint32SyncSafeToken = {
get: (buffer, offset) => (buffer[offset + 3] & 0x7F) | ((buffer[offset + 2]) << 7) | ((buffer[offset + 1]) << 14) | ((buffer[offset]) << 21),
len: 4,
};