#command-line #web #data #url #parser #command-line-tool #cli

bin+lib dataurl

CLI tool and Rust crate for parsing and generating data URLs

4 releases

0.1.2 Oct 30, 2021
0.1.1 Oct 23, 2021
0.1.0 Oct 22, 2021
0.0.1 Oct 18, 2021

#2779 in Parser implementations

Download history 126/week @ 2024-07-25 166/week @ 2024-08-01 102/week @ 2024-08-08 86/week @ 2024-08-15 73/week @ 2024-08-22 107/week @ 2024-08-29 91/week @ 2024-09-05 76/week @ 2024-09-12 98/week @ 2024-09-19 137/week @ 2024-09-26 97/week @ 2024-10-03 132/week @ 2024-10-10 97/week @ 2024-10-17 73/week @ 2024-10-24 220/week @ 2024-10-31 207/week @ 2024-11-07

615 downloads per month
Used in 3 crates (via cargo-cog)

CC0 license

22KB
471 lines

dataurl build status on GNU/Linux dataurl build status on macOS dataurl build status on Windows

dataurl

CLI tool / Rust crate for converting files and text into data URLs and back


Installation

Using Cargo

cargo install dataurl

Using containers

docker build -t Y2Z/dataurl .
sudo install -b dist/run-in-container.sh /usr/local/bin/dataurl

From source

git clone https://github.com/Y2Z/dataurl.git
cd dataurl
make install

Using pre-built binaries (Windows, ARM-based devices, etc)

Every release contains pre-built binaries for Windows, GNU/Linux, as well as platforms with non-standart CPU architecture.


Usage (CLI)

dataurl "some text"
dataurl -d 'data:text/html,text<a id%3D"b">ok</a>?a=v#f' > index.html
dataurl -i picture.png
cat file.txt | dataurl -i -
cat file.png | dataurl

Usage (crate)

use dataurl::DataUrl;

let data_url: DataUrl = DataUrl::parse("data:,Hello,%20World!")?;

assert_eq!(data_url.get_media_type(), "text/plain".to_string());
assert_eq!(data_url.get_media_type_no_default(), None);
assert_eq!(data_url.get_charset(), "US-ASCII".to_string());
assert_eq!(data_url.get_charset_no_default(), None);
assert!(!data_url.get_is_base64_encoded());
assert_eq!(data_url.get_data(), [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]);
assert_eq!(data_url.get_fragment(), None);
assert_eq!(data_url.to_string(), "data:,Hello%2C%20World%21");
assert_eq!(data_url.get_text(), "Hello, World!");

Flags and options

  • -b: Encode data using base64

  • -d: Attempt to parse input, output resulting data

  • -c: Use custom charset

  • -f: Append fragment

  • -i: Specify file to read data from (use - for STDIN)

  • -t: Adjust media type


References


License

To the extent possible under law, the author(s) have dedicated all copyright related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

Dependencies

~8.5MB
~205K SLoC