A helper for quickly determining the file type of a buffer.
This library is pure JavaScript, any can run in Node, the browser, or anywhere else JavaScript runs. This library is exported in CommonJS and ES Modules.
Compared to other libraries that iterate through multiple arrays to find the mime type, this helper detects mime type by looping through a single object.
- JPEG
- PNG
- GIF
- WEBP
- BMP
- TIFF
- AVIF
To install this library, use on of the following commands:
npm install -S mime-tree
yarn add mime-tree
import mimeFromBuffer from "mime-tree";
const image: Uint8Array = ...;
const mimeType = mimeFromBuffer(image);