rust-url/data-url
2022-08-16 11:02:12 -07:00
..
src Remove dependency on third-party matches crate 2022-02-16 13:46:34 -07:00
tests Align mime type parser to spec 2022-01-31 16:46:18 +01:00
Cargo.toml Update the minimum rust-version to 1.51 to fix a build break on the 1.45 CI pipeline due to an update of dependencies that now require the cargo resolver feature to be stablized. 2022-08-16 11:02:12 -07:00
LICENSE-APACHE Add metadata for the data-url crate 2018-02-02 10:19:39 +01:00
LICENSE-MIT Add metadata for the data-url crate 2018-02-02 10:19:39 +01:00
README.md Fix data-url README 2018-02-02 10:42:54 +01:00

data-url

crates.io docs.rs

Processing of data: URLs in Rust according to the Fetch Standard: https://fetch.spec.whatwg.org/#data-urls but starting from a string rather than a parsed URL to avoid extra copies.

use data_url::{DataUrl, mime};

let url = DataUrl::process("data:,Hello%20World!").unwrap();
let (body, fragment) = url.decode_to_vec().unwrap();

assert_eq!(url.mime_type().type_, "text");
assert_eq!(url.mime_type().subtype, "plain");
assert_eq!(url.mime_type().get_parameter("charset"), Some("US-ASCII"));
assert_eq!(body, b"Hello World!");
assert!(fragment.is_none());