oden/third-party/vendor/data-url
2024-03-08 11:03:01 -08:00
..
src Vendor things 2024-03-08 11:03:01 -08:00
tests Vendor things 2024-03-08 11:03:01 -08:00
.cargo-checksum.json Vendor things 2024-03-08 11:03:01 -08:00
Cargo.toml Vendor things 2024-03-08 11:03:01 -08:00
LICENSE-APACHE Vendor things 2024-03-08 11:03:01 -08:00
LICENSE-MIT Vendor things 2024-03-08 11:03:01 -08:00
README.md Vendor things 2024-03-08 11:03:01 -08: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());