Fast, dependency-free Go package to infer binary file types by checking magic number signatures.
Filetype is a Go library for detecting file types and MIME types by analyzing magic number signatures in file headers. It solves the problem of unreliable file identification that depends on file extensions, which is crucial for security, data processing, and media handling applications.
Go developers building applications that require secure file upload validation, media processing pipelines, data analysis tools, or any system needing accurate file type detection independent of filenames.
Developers choose filetype for its zero dependencies, pure Go implementation, and optimized performance that only reads the first 262 bytes of a file. Its pluggable matcher system and comprehensive support for hundreds of file types across multiple categories provide both reliability and flexibility.
Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports hundreds of file types across images, videos, audio, archives, and documents, as listed in the README, ensuring broad detection capabilities for diverse applications.
Optimized to read only the first 262 bytes of a file, with benchmarks showing microsecond-level detection (e.g., 1083 ns/op for tar), making it efficient for large-scale processing.
Pure Go implementation with no C bindings, simplifying deployment and reducing compatibility issues, aligning with the library's philosophy of simplicity.
Offers a pluggable matcher system, demonstrated in the examples, allowing developers to add custom file type definitions for proprietary or niche formats.
Relies solely on magic numbers in the first 262 bytes, which may fail for files with corrupted headers, fragmented formats, or types that require deeper content analysis for accurate identification.
SVG detection is not included by default and requires importing the go-is-svg package, adding complexity for projects that frequently handle SVG files.
The API requires the file header to be loaded into memory, which can be inefficient for streaming applications or when processing extremely large files without buffering the entire content.