minimime
A minimal MIME type detection library for Rust, ported from the Ruby minimime gem.
This library provides fast MIME type detection based on file extensions and content types, using embedded database files for efficient lookups without external dependencies.
Features
- Fast lookups: Uses embedded hash maps for O(1) MIME type detection
- No external dependencies: Database files are embedded at compile time
- Case insensitive: Handles file extensions in any case
- Binary detection: Identifies binary vs text file types
- Thread safe: Safe for concurrent use across multiple threads
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
Quick Start
use ;
// Look up by filename
if let Some = lookup_by_filename
// Look up by extension
if let Some = lookup_by_extension
// Look up by content type
if let Some = lookup_by_content_type
API Reference
lookup_by_filename(filename: &str) -> Option<Info>- Look up MIME type by filenamelookup_by_extension(extension: &str) -> Option<Info>- Look up MIME type by file extensionlookup_by_content_type(content_type: &str) -> Option<Info>- Look up by MIME content type
Each function returns an Info struct containing:
extension- File extension (without dot)content_type- MIME content typeencoding- Encoding typeis_binary()- Whether the file type is binary
Supported File Types
This library supports hundreds of file extensions and MIME types, including:
- Web formats: HTML, CSS, JS, JSON, XML
- Images: PNG, JPEG, GIF, SVG, WebP, BMP, ICO
- Documents: PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX
- Archives: ZIP, TAR, GZ, RAR, 7Z
- Media files: MP3, MP4, AVI, MOV, WAV, FLAC
- Programming: RS, PY, JS, TS, GO, C, CPP, H
- And many more...
Examples
Basic Usage
use lookup_by_filename;
Web Server Integration
use lookup_by_filename;
Performance
The library uses embedded hash maps for fast lookups, making it extremely efficient:
- Average case O(1) lookups with amortized performance
- No file system access required
- Thread-safe for concurrent usage
- Minimal memory footprint
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
- Ported from the Ruby minimime gem
- Inspired by the need for a fast, dependency-free MIME detection library in Rust