A simple crate to look up a file extension for a mimetype.
It embeds part of the mime-db database, packed efficiently into around 20 KiB. There are no runtime dependencies, and it's no_std
-compatible.
```rust use mime2ext::mime2ext;
asserteq!(mime2ext("image/png"), Some("png")); asserteq!(mime2ext("application/octet-stream"), Some("bin")); asserteq!(mime2ext("text/html; charset=UTF-8"), Some("html")); asserteq!(mime2ext("nonexistent/mimetype"), None); assert_eq!(mime2ext("invalid-mimetype"), None); ```
mime
mime
's Mime
type is supported through its implementation of AsRef<str>
, without any dependency on the crate:
```rust use mime::{Mime, TEXT_PLAIN}; use mime2ext::mime2ext;
asserteq!(mime2ext(TEXTPLAIN), Some("txt")); let mime: Mime = "text/xml; charset=latin1".parse()?; assert_eq!(mime2ext(mime), Some("xml")); ```
mime2ext includes a fixed version of mime-db. A new version of mime2ext has to be released for each new version of mime-db.
The currently used mime-db version is 1.45.0.
Both mime2ext and mime-db are licensed under the MIT license. See LICENSE
and mime-db/LICENSE
.