From 651e1d3f273170d864a85b6c1aef75da1783a9de Mon Sep 17 00:00:00 2001 From: Sunshine Date: Fri, 16 Oct 2026 17:08:11 -0400 Subject: [PATCH] add crates.io and docs.rs badges, and a comparison with data-url --- README.md | 35 ++++++++++++++++++++++++++++++----- src/lib.rs | 6 ++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4fedd2a..cd772fa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ -[![dataurl build status on GNU/Linux](https://github.com/Y2Z/dataurl/workflows/GNU%2FLinux/badge.svg)](https://github.com/Y2Z/dataurl/actions?query=workflow%3AGNU%2FLinux) -[![dataurl build status on macOS](https://github.com/Y2Z/dataurl/workflows/macOS/badge.svg)](https://github.com/Y2Z/dataurl/actions?query=workflow%3AmacOS) -[![dataurl build status on Windows](https://github.com/Y2Z/dataurl/workflows/Windows/badge.svg)](https://github.com/Y2Z/dataurl/actions?query=workflow%3AWindows) +[![dataurl on crates.io](https://img.shields.io/crates/v/dataurl.svg)](https://crates.io/crates/dataurl) +[![dataurl documentation on docs.rs](https://docs.rs/dataurl/badge.svg)](https://docs.rs/dataurl) +[![dataurl build status on GNU/Linux](https://github.com/Y2Z/dataurl/actions/workflows/build_gnu_linux.yml/badge.svg)](https://github.com/Y2Z/dataurl/actions/workflows/build_gnu_linux.yml) +[![dataurl build status on macOS](https://github.com/Y2Z/dataurl/actions/workflows/build_macos.yml/badge.svg)](https://github.com/Y2Z/dataurl/actions/workflows/build_macos.yml) +[![dataurl build status on Windows](https://github.com/Y2Z/dataurl/actions/workflows/build_windows.yml/badge.svg)](https://github.com/Y2Z/dataurl/actions/workflows/build_windows.yml) # dataurl @@ -161,8 +163,31 @@ assert_eq!(extension_for_media_type("image/svg+xml"), Some("svg")); assert_eq!(extension_for_media_type("application/javascript"), Some("js")); ``` -If all you need is parsing, [data-url](https://crates.io/crates/data-url) (from the Servo project) is another spec-compliant option; -dataurl also generates data URLs (picking the shortest encoding if asked to), handles charsets, detects media types, and comes with a CLI tool. +The full API is documented on [docs.rs](https://docs.rs/dataurl). + +### Comparison with data-url + +[data-url](https://crates.io/crates/data-url), from the Servo project (it lives in the [rust-url](https://github.com/servo/rust-url) repository), +is the other spec-compliant data URL crate. Both follow the WHATWG Fetch Standard and pass the Web Platform Tests, but they're built for different jobs: + +| | dataurl | data-url | +|----------------------------------------------|-----------------------------------------------|-------------------------------------------| +| Parsing (WHATWG Fetch Standard) | Yes | Yes | +| Generating data URLs | Yes: percent-encoding, base64, or shortest | No | +| Changing media type, charset, fragment, data | Yes | No | +| Decoding text using the charset | Yes (encoding_rs) | No, bytes only | +| Media type detection | Yes (infer, plus file extensions) | No | +| MIME type parser | Yes | Yes | +| Forgiving-base64 decoder on its own | No | Yes | +| Decoding | Into a `Vec` | Into a `Vec`, or streamed to a callback without copying the input | +| `no_std` | No | Yes (with `alloc`) | +| Dependencies | encoding_rs, infer | None | +| Minimum Rust version | 1.74 | 1.51 | +| CLI tool | Yes | No | +| License | CC0 (public domain) | MIT or Apache-2.0 | + +If you only need to read data URLs, especially in `no_std` code, or you already use the [url](https://crates.io/crates/url) crate, data-url is the leaner choice. +If you need to create or modify data URLs, work with text in other charsets, or figure out what kind of file the data is, that's what dataurl is for. --------------------------------------------------- diff --git a/src/lib.rs b/src/lib.rs index 44d7018..fa66727 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,13 @@ //! # Ok::<(), dataurl::Error>(()) //! ``` //! +//! If you only need to read data URLs, especially in `no_std` code, the [data-url] crate +//! from the Servo project is a leaner alternative; this crate is for creating and modifying them, +//! decoding text in other charsets, and detecting media types +//! (see the [comparison](https://github.com/Y2Z/dataurl#comparison-with-data-url)). +//! //! [data: URL processor]: https://fetch.spec.whatwg.org/#data-url-processor +//! [data-url]: https://crates.io/crates/data-url mod base64; mod detect;