Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. mimemagic

mimemagic

GPL-2.0Gov2.0.0

A powerful Go library for MIME type detection using glob patterns, magic number signatures, XML namespaces, and tree magic.

GitHubGitHub
99 stars11 forks0 contributors

What is mimemagic?

mimemagic is a Go library for detecting MIME types of files using multiple methods like glob patterns, magic number signatures, XML namespaces, and tree magic. It solves the problem of accurately identifying file types by leveraging the XDG shared-mime-info database, ensuring reliable detection across various file formats.

Target Audience

Go developers building applications that require file type detection, such as web servers, file upload systems, or content management tools.

Value Proposition

Developers choose mimemagic for its comprehensive detection methods, high performance, and pure Go implementation without external dependencies, making it a robust and efficient alternative to native tools.

Overview

Powerful and versatile MIME sniffing package using pre-compiled glob patterns, magic number signatures, XML document namespaces, and tree magic for mounted volumes, generated from the XDG shared-mime-info database.

Use Cases

Best For

  • Detecting MIME types in file upload systems
  • Building web servers that need accurate content-type headers
  • Creating CLI tools for file analysis
  • Processing large volumes of files with performance constraints
  • Implementing cross-platform file type detection
  • Integrating MIME sniffing into Go applications without C dependencies

Not Ideal For

  • Projects requiring strict permissive licensing (e.g., MIT or Apache) without GPL dependencies
  • Applications that only need basic file extension matching and can forgo magic number detection
  • Environments where custom or frequently updated MIME databases are essential, and regenerating definitions is impractical

Pros & Cons

Pros

Comprehensive Detection Methods

Combines glob patterns, magic signatures, XML namespaces, and tree magic per the XDG specification, ensuring accurate identification across diverse file types, as detailed in the README with 1003 MIME types and 493 magic signature tests.

Blazing-Fast Performance

Benchmarks show average detection times of 13 μs for Match(), with even faster glob-based matching, making it suitable for high-throughput file processing applications, as verified in the provided benchmarks.txt.

Pure Go Implementation

Has no external dependencies or C library bindings, ensuring easy integration and cross-platform support without additional setup, highlighted in the features as 'all in native go'.

Rich MIME Database

Includes 1003 MIME types with descriptions, acronyms, aliases, extensions, and icons, providing detailed metadata for enhanced file analysis, as listed in the README's feature breakdown.

Cons

Licensing Complications

The main branch is GPL-2.0-or-later due to derived work from shared-mime-info, which may restrict use in proprietary projects; the MIT branch requires manual handling of a database file, adding redistribution hurdles.

Overhead for Simple Use Cases

For applications only needing file extension matching, the extensive detection methods and large database introduce unnecessary complexity and increased binary size, as it's designed for comprehensive sniffing.

Dependency on XDG Database

Relies on the shared-mime-info database, so updates or custom MIME types require regenerating definitions using the included XML parser, which adds setup steps and potential maintenance overhead.

Frequently Asked Questions

Quick Stats

Stars99
Forks11
Contributors0
Open Issues5
Last commit2 years ago
CreatedSince 2018

Tags

#glob-patterns#sniffing#go-library#cli-tool#mime#magic-numbers#mime-types#golang#cross-platform#detection#xml-namespaces#extension#go

Built With

G
Go

Included in

Go169.1k
Auto-fetched 7 hours ago

Related Projects

fzffzf

:cherry_blossom: A command-line fuzzy finder

Stars82,864
Forks2,863
Last commit1 day ago
divedive

A tool for exploring each layer in a docker image

Stars54,539
Forks1,998
Last commit8 months ago
HubHub

A command-line tool that makes git easier to use with GitHub.

Stars22,957
Forks2,221
Last commit2 years ago
lolo

💥 A Lodash-style Go library based on Go 1.18+ Generics (map, filter, contains, find...)

Stars21,429
Forks953
Last commit19 hours ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub