mime_map
Version, currently main branch1 version
- main branchlatestSep 1, 2026
github.com/shpeckman/mime_map
Crystal shard for mapping MIME types to file names and vice versa, dynamically generated from IANA registry data.
Installation
# Add this to your shard.yml
dependencies:
mime_map:
github: shpeckman/mime_map
branch: mainmain is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
>= 1.0.0- License
- MIT
- Author
- shpeckman
Dependencies
This version declares no dependencies.
README
mime_map
A blazing fast, lightweight Crystal shard for bidirectional mapping between file extensions and MIME/media types.
mime_map dynamically generates its mappings at installation time using the most up-to-date IANA registries (covering application, audio, font, image, message, model, multipart, text, and video) as well as the comprehensive Apache mime.types fallback list.
Installation
- Add the dependency to your
shard.yml:
dependencies:
mime_map:
github: shpeckman/mime_map
version: ~> 1.0.0
- Run
shards install
Note: The installation process uses a
postinstallhook to runmake, which fetches the latest MIME type data directly from IANA and Apache and compiles it into static Crystal Hash structures for O(1) performance.
Usage
require "mime_map"
MimeMap.media_type?("json")
MimeMap.media_type?("ZIP")
MimeMap.media_type?("foo")
MimeMap.media_type("csv")
MimeMap.media_type("unknown", "application/octet-stream")
MimeMap.name?("application/json")
MimeMap.extensions("image/jpeg")
MimeMap.from_ext(".png")
MimeMap.from_filename("/var/www/uploads/document.pdf")
MimeMap.from_filename("Makefile")
MimeMap.category?("png")
MimeMap.category?("archive.zip")
MimeMap.category?("invalid-ext")
MimeMap.category("document.pdf")
MimeMap.image?("png")
MimeMap.image?("photo.png")
MimeMap.image?("image/png")
MimeMap.image?("application/json")
MimeMap.audio?("mp3")
MimeMap.application?("document.pdf")
MimeMap.text?("text/html")
Available Category Checkers
The following category checking methods are automatically generated and backed by the MimeMap::Category enum:
MimeMap.application?(input)MimeMap.audio?(input)MimeMap.font?(input)MimeMap.image?(input)MimeMap.message?(input)MimeMap.model?(input)MimeMap.multipart?(input)MimeMap.text?(input)MimeMap.video?(input)
Contributing
- Fork it (https://github.com/shpeckman/mime_map/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
main- Seen
- Sep 1, 2026
- Crystal
>= 1.0.0- Indexed
- yes
Dependents
Repository
github.com/shpeckman/mime_map
Metadata
- Created
- Sep 17, 2026
- Updated
- Sep 27, 2026
- Synced
- Sep 27, 2026
- Versions
- 1