Crate data_url

Source
Expand description

Processing of data: URLs 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!(url.mime_type().matches("text", "plain"));
assert_eq!(url.mime_type().get_parameter("charset"), Some("US-ASCII"));
assert_eq!(body, b"Hello World!");
assert!(fragment.is_none());

Modulesยง

forgiving_base64
https://infra.spec.whatwg.org/#forgiving-base64-decode
mime

Macrosยง

require ๐Ÿ”’

Structsยง

DataUrl
FragmentIdentifier
The URLโ€™s fragment identifier (after #)

Enumsยง

DataUrlError

Functionsยง

decode_with_base64 ๐Ÿ”’
decode_without_base64() composed with https://infra.spec.whatwg.org/#isomorphic-decode composed with https://infra.spec.whatwg.org/#forgiving-base64-decode.
decode_without_base64 ๐Ÿ”’
This is https://url.spec.whatwg.org/#string-percent-decode while also:
find_comma_before_fragment ๐Ÿ”’
parse_header ๐Ÿ”’
percent_encode ๐Ÿ”’
pretend_parse_data_url ๐Ÿ”’
Similar to https://url.spec.whatwg.org/#concept-basic-url-parser followed by https://url.spec.whatwg.org/#concept-url-serializer
remove_base64_suffix ๐Ÿ”’
None: no base64 suffix