Detect binary file types from buffers, streams, or files by checking magic numbers.
file-type is a Node.js library that detects the type of binary files by checking their magic numbers—the unique byte sequences at the start of a file. It returns the file extension and MIME type, helping developers validate and process files accurately without relying on file extensions or metadata. The library supports a wide range of formats, from images and audio to archives and documents.
Node.js developers building applications that handle file uploads, media processing, or data validation, such as content management systems, file servers, or security tools.
Developers choose file-type for its reliability in detecting binary formats via magic numbers, extensive support for modern file types, and flexible API that works with buffers, streams, and files. Its ESM-first design and extensibility through custom detectors make it a robust choice for production environments.
Detect the file type of a file, stream, or data
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Detects file types by analyzing binary signatures (magic numbers), ensuring high reliability for over 200 supported formats like PNG, MP3, and PDF, as outlined in the comprehensive format list.
Works with buffers, file paths, streams, blobs, and tokenizers, offering APIs like fileTypeFromStream and fileTypeFromBlob for diverse data access methods in Node.js and web environments.
Supports custom detectors through options like customDetectors, allowing integration of third-party plugins for non-binary formats or specialized needs, with examples provided for XML and PDF detection.
Recognizes a wide range of modern file types including AVIF, WebP, and JXL, with ongoing contributions for commonly used formats, making it suitable for contemporary media processing.
Requires ESM-compatible projects, forcing CommonJS users to configure tools like Webpack or use workarounds like load-esm, adding complexity for legacy setups as noted in the install section.
Exclusively focuses on binary-based detection, leaving text-based formats unsupported natively and relying on custom detectors for basics like CSV or SVG, which the README explicitly states.
Provides no guarantees on file validity or security; the README warns it's a hint only and recommends external measures like size limits and timeouts for untrusted files, limiting out-of-the-box robustness.