Skip to content
/ dataurl Public

๐ŸŒ CLI tool and Rust crate for parsing and serializing data URLs

License

Notifications You must be signed in to change notification settings

Y2Z/dataurl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

54 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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


Usage (CLI)

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

Flags and options

  • -b: Encode data using base64
  • -c: Use custom charset
  • -d: Attempt to parse input, output resulting data
  • -f: Append fragment
  • -i: Specify file to read data from (use - for STDIN)
  • -o: Provide file to write output to (use - for STDOUT)
  • -t: Adjust media type

Usage (crate)

use dataurl::DataUrl;

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

assert_eq!(data_url.media_type(), "text/plain".to_string());
assert_eq!(data_url.media_type_no_default(), None);
assert_eq!(data_url.charset(), "US-ASCII".to_string());
assert_eq!(data_url.charset_no_default(), None);
assert!(!data_url.is_base64_encoded());
assert_eq!(data_url.data(), [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]);
assert_eq!(data_url.fragment(), None);
assert_eq!(data_url.to_string(), "data:,Hello%2C%20World%21");
assert_eq!(data_url.text(), "Hello, World!");

Installation

Using Cargo

cargo install dataurl
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.


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.