10 releases

Uses old Rust 2015

0.1.53 Aug 16, 2024
0.1.52 Feb 21, 2022
0.1.51 Nov 9, 2021
0.1.4 May 31, 2021
0.1.2 Mar 3, 2021

#155 in Filesystem

Download history 1316/week @ 2024-08-07 1469/week @ 2024-08-14 1442/week @ 2024-08-21 1588/week @ 2024-08-28 1881/week @ 2024-09-04 1870/week @ 2024-09-11 1679/week @ 2024-09-18 2048/week @ 2024-09-25 1699/week @ 2024-10-02 1917/week @ 2024-10-09 2196/week @ 2024-10-16 1297/week @ 2024-10-23 1750/week @ 2024-10-30 1637/week @ 2024-11-06 1974/week @ 2024-11-13 1657/week @ 2024-11-20

7,294 downloads per month
Used in 17 crates (5 directly)

MIT license

28KB
188 lines

mime2ext

Crates.io API reference MSRV CI

A simple compact crate to look up a file extension for a mime type.

It embeds part of the mime-db database, packed efficiently into around 20 KiB. There are no dependencies, and it's no_std-compatible.

Example

use mime2ext::mime2ext;

assert_eq!(mime2ext("image/png"), Some("png"));
assert_eq!(mime2ext("application/octet-stream"), Some("bin"));
assert_eq!(mime2ext("text/html; charset=UTF-8"), Some("html"));
assert_eq!(mime2ext("nonexistent/mimetype"), None);
assert_eq!(mime2ext("invalid-mimetype"), None);

Interoperability with mime

mime's Mime type is supported through its implementation of AsRef<str>, without any dependency on the crate:

use mime::{Mime, TEXT_PLAIN};
use mime2ext::mime2ext;

assert_eq!(mime2ext(TEXT_PLAIN), Some("txt"));
let mime: Mime = "text/xml; charset=latin1".parse()?;
assert_eq!(mime2ext(&mime), Some("xml"));

Versioning

mime2ext includes a static version of mime-db. A new version of mime2ext has to be released for each new version of mime-db.

mime2ext's version number tracks that of mime-db. mime2ext version 0.1.49 corresponds to mime-db version 1.49.0.

See CHANGELOG.md for differences between versions, including relevant changes to mime-db.

License

Both mime2ext and mime-db are licensed under the MIT license. See LICENSE and mime-db/LICENSE.

See also

  • mime_guess, which mainly converts in the opposite direction. It can also convert mime types to extensions but often suggests rarely-used extensions, like jpe for image/jpeg.

No runtime deps