7 releases (breaking)
0.6.0 | Oct 27, 2023 |
---|---|
0.5.0 | Oct 3, 2023 |
0.4.1 | Sep 29, 2023 |
0.4.0 | Apr 11, 2023 |
0.1.0 | Jan 14, 2023 |
#2449 in Encoding
Used in baze64-gui
25KB
517 lines
Baze64
The baze64 rust library & accompanying CLI
Usage
Library
Simply add
baze64 = "<VERSION>"
to your Cargo.toml
where <VERSION>
is the latest version of the crate. Alternatively,
run
cargo add baze64
for this to be done for you.
CLI
Run baze64 encode <STRING>
to encode a string or baze64 encode -f <FILE>
to
encode a file. Decode a base64 string by running
baze64 decode <STRING>
where <STRING>
is a base64 encoded string, adding -o <FILE>
to output to <FILE>
lib.rs
:
Encode & decode base64 to & from arbitrary byte sequences
All encoding & decoding is done via the Base64String
struct, using an alphabet implementing the Alphabet
trait
Examples
Encode & decode a string:
let text = "Some text".to_string();
let encoded = Base64String::<Standard>::encode(text.as_bytes());
let decoded = encoded.decode()?;
assert_eq!(text, String::from_utf8(decoded)?);
Encode & decode a file:
let mut file = File::open("path/to/file.ext")?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
let encoded = Base64String::<Standard>::encode(&buffer);
let bytes = encoded.decode()?;
assert_eq!(buffer, bytes);
Dependencies
~4–10MB
~107K SLoC