fmedia

Crates.iofmedia
lib.rsfmedia
version0.2.0
sourcesrc
created_at2021-07-31 14:58:09.926551
updated_at2021-07-31 15:20:30.586479
descriptionGet file media type or suffix
homepage
repository
max_upload_size
id429708
size49,646
Liangcheng Juves (LcJuves)

documentation

README

fmedia

Get the media type from the file suffix

use fmedia::MediaType;

assert_eq!("image/png", MediaType::from_file_extension("png").unwrap());
assert_eq!(
    "image/jpeg",
    MediaType::from_file_extension("jpeg").unwrap()
);
assert_eq!(
    "image/svg+xml",
    MediaType::from_file_extension("svg").unwrap()
);
assert_eq!(
    "application/json",
    MediaType::from_file_extension("json").unwrap()
);

Get its suffix by file media type

Return one or more results

use fmedia::FileExtension;

assert_eq!(
    vec!["png"],
    FileExtension::from_media_type("image/png").unwrap()
);
assert_eq!(
    vec!["jpe", "jpeg", "jpg"],
    FileExtension::from_media_type("image/jpeg").unwrap()
);
assert_eq!(
    vec!["svg", "svgz"],
    FileExtension::from_media_type("image/svg+xml").unwrap()
);
assert_eq!(
    vec!["json"],
    FileExtension::from_media_type("application/json").unwrap()
);
Commit count: 0

cargo fmt