MegaMimes
A lightweight C library for detecting file MIME types and metadata.
MegaMimes
MegaMimes is a lightweight, dependency-free C99 library for detecting MIME types and classifying file content across Linux, macOS, and Windows. It uses layered evidence—including magic signatures, container hints, and file extensions—to make reliable content-type decisions while also identifying whether content is text or binary and detecting its encoding. (GitHub)
The Challenge
File extensions alone are not always reliable indicators of what a file actually contains. Applications that process uploaded or untrusted files need a more robust way to determine file types, handle ambiguous content, and distinguish between strong and weak detection signals without introducing heavy dependencies.
The Solution
MegaMimes was designed as a small, portable library that analyzes files using multiple sources of evidence and combines them into a confidence-based result. The latest version adds ranked detection candidates, strict mode for security-oriented classification, suspicious-file indicators, configurable byte limits, and text encoding detection using UTF BOM and UTF-8 analysis. (GitHub)
The project also includes a C API and command-line utility, making the library useful both as an embedded component in C applications and as a standalone file-analysis tool. It is built with CMake and includes automated tests through CTest. (GitHub)
Outcome
The result is a compact, cross-platform file classification library that provides developers with detailed and explainable MIME detection rather than relying on a single signal. By combining multiple detection strategies with confidence scoring and strict-mode controls, MegaMimes provides a practical foundation for applications that need dependable file-type and content classification. (GitHub)