A Go package for detecting MIME types and file extensions based on magic numbers, prioritizing common formats and supporting extension.
mimetype is a Go library for detecting MIME types and file extensions by analyzing file content magic numbers. It provides a reliable, system-independent alternative to ensure consistent file type identification across different platforms. The library uses a hierarchical detection system to efficiently handle nested formats like ZIP-based Office documents.
Go developers building applications that need reliable file type detection, such as web servers processing uploads, security scanners, or file management tools. It's particularly useful for those requiring cross-platform consistency without external C dependencies.
Developers choose mimetype for its pure Go implementation with no external dependencies, ensuring easy deployment and goroutine safety. Its hierarchical detection prioritizes correctness and efficiently handles container formats, offering a more accurate alternative to system-dependent methods.
A Go package for media type and file extension detection, based on magic numbers
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows users to add support for custom or new file formats via the Extend method, as shown in the package examples, enabling niche type detection.
Uses a tree structure to prioritize common formats and handle container files like ZIP for Office documents efficiently, minimizing read operations and improving accuracy.
Pure Go implementation without C bindings ensures easy deployment and cross-platform consistency, avoiding system library issues.
Goroutine-safe for multi-threaded applications, as stated in the features, making it suitable for use in web servers or concurrent processing tools.
Magic number detection can be slow, especially when SetLimit is increased for complex files like Office documents, leading to higher latency as noted in the FAQ and benchmarks.
Some file formats, such as Microsoft Office documents, may not be detected correctly without manual adjustment of detection limits, requiring user intervention as admitted in the FAQ.
Relies solely on content analysis and ignores file extensions or external metadata, which can be a drawback in contexts where such information is reliable or preferred.
mimetype is an open-source alternative to the following products:
libmagic is a library for file type identification that determines the MIME type of files by examining their contents and comparing against magic number patterns.
The file command is a standard Unix utility that determines the type of a file by examining its contents and structure, commonly used in shell scripting and system administration.