Contents ======== - [Introduction](#introduction) - [Usage](#usage) # Introduction This is a Base64 encoding library as described in [RFC4648](https://www.rfc-editor.org/rfc/rfc4648). This library encodes and decodes random data into ASCII characters using an appropriate Base64 library. It is designed to leverage the abstractions in Rust's std library in order to be generic over io streams. That is to say, you can read from anything implementing **Read** and write the encoded or decoded output to anything which implements **Write**. # Usage Add the crate to your `Cargo.toml` file. ```Toml # Cargo.toml [dependencies] b64 = { git = "https://git.hitchhiker-linux.org/jeang3nie/b64_rs.git" } ``` ## Encoding Encoding 'Hello, World!' into a new `String`, wrapping at 76 characters and using the default alphabet. ``` use { std::io::Read, b64::Encoder, }; fn main() { let mut encoder = Encoder::new("Hello, World!".as_bytes(), vec![], None, Some(76)); encoder.encode().unwrap(); assert_eq!(encoder.output(), b"SGVsbG8sIFdvcmxkIQ==\n"); } ``` ## Decoding ``` use { std::io::Read, b64::Decoder, }; fn main() { let mut decoder = Decoder::new("SGVsbG8sIFdvcmxkIQ==".as_bytes(), vec![], None, false); assert_eq!(decoder.decode().unwrap(), b"Hello, World!"); } ```