file-type-mime is a JavaScript utility designed to identify the MIME type and file extension of a given file by analyzing its binary content, typically provided as an `ArrayBuffer`. It is currently at version 0.4.7, indicating a pre-1.0 release. While specific release cadence isn't detailed, pre-1.0 versions often imply that the API might still be subject to minor breaking changes between minor versions as the library matures. This library supports a range of common file types including various image formats (BMP, GIF, JPEG, PNG, HEIC, TIFF), documents (PDF, DOCX, XLSX, PPTX, ODT), and archives (ZIP, GZ, RAR), with an optional `extra` flag to detect generic `json` and `txt` types. Its key differentiators include its lightweight nature and its focus on direct buffer analysis without external dependencies, making it suitable for both Node.js environments and browser-based file upload scenarios where direct file content analysis is required.
npm install file-type-mimeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `file-type-mime` in a Node.js environment to parse the MIME type from a file's `ArrayBuffer`, including an example of using the `extra` option for generic text detection.
Always pin to exact versions (e.g., `"file-type-mime": "0.4.7"`) and review release notes carefully before upgrading minor versions.
When working with Node.js `Buffer`s, access their underlying `ArrayBuffer` via `.buffer` property: `parse(nodeBuffer.buffer)`.
If expecting JSON or plain text files, ensure your call to `parse` includes the `extra` option: `parse(buffer, { extra: true })`.Always check the return value of `parse` for `undefined` before attempting to access properties like `result.mime` or `result.ext`: `const result = parse(buffer); if (result) { /* use result */ } else { /* handle unknown type */ }`.Use a named import for `parse`: `import { parse } from 'file-type-mime';`Access the `ArrayBuffer` from the Node.js `Buffer` using `.buffer`: `parse(myNodeBuffer.buffer)`.
Add a null check for the result: `const result = parse(buffer); if (result) { console.log(result.mime); }`No dependency data recorded yet.