MimeDescription
Human-friendly MIME type descriptions for Elixir.
This library provides embedded MIME type descriptions sourced from the freedesktop.org shared-mime-info database. The data is compiled directly into the library at build time, so no runtime fetching is required.
Installation
Add mime_description to your list of dependencies in mix.exs:
def deps do
[
{:mime_description, "~> 0.1.0"}
]
endUsage
# Get description for a MIME type
MimeDescription.get("application/pdf")
#=> {:ok, "PDF document"}
MimeDescription.get("text/plain")
#=> {:ok, "plain text document"}
# Handle unknown types
MimeDescription.get("unknown/type")
#=> {:error, :not_found}
# Get with a default fallback
MimeDescription.get_with_default("unknown/type", "Unknown file")
#=> "Unknown file"
# Raise if not found
MimeDescription.get!("application/pdf")
#=> "PDF document"How It Works
Unlike runtime-based solutions, MimeDescription embeds the MIME type database directly into your compiled application. This means:
- No network requests at runtime
- No file I/O to read external databases
- Fast lookups from an in-memory Elixir map
- No dependencies on system MIME databases
The MIME data is sourced from the authoritative freedesktop.org shared-mime-info database and is automatically updated weekly via GitHub Actions.
Updating the MIME Database
The library includes a Mix task to update the embedded MIME data:
# Check for updates and regenerate if needed
mix mime_description.generate
# Force regeneration
mix mime_description.generate --forceThis task:
- Checks if the upstream database has changed (using ETags)
- Downloads the latest XML data if needed
- Parses and generates an Elixir module with the embedded data
- The generated module is compiled into your application
Automated Updates
The MIME database is automatically updated weekly via GitHub Actions. The workflow:
- Runs every Sunday at 02:00 UTC
- Checks for updates from freedesktop.org
- Regenerates the data module if changes are detected
- Commits the updates back to the repository
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details.
Credits
MIME type descriptions are sourced from the freedesktop.org shared-mime-info database.