9 releases (5 breaking)

0.6.2 Jul 28, 2019
0.6.1 Jul 23, 2019
0.5.1 Jul 23, 2019
0.4.0 Jul 22, 2019
0.1.0 Jul 19, 2019

#2235 in Encoding

Download history 1430/week @ 2024-03-13 1688/week @ 2024-03-20 1810/week @ 2024-03-27 1593/week @ 2024-04-03 1721/week @ 2024-04-10 2181/week @ 2024-04-17 1871/week @ 2024-04-24 1457/week @ 2024-05-01 1315/week @ 2024-05-08 1295/week @ 2024-05-15 1868/week @ 2024-05-22 1025/week @ 2024-05-29 1171/week @ 2024-06-05 1063/week @ 2024-06-12 1441/week @ 2024-06-19 1532/week @ 2024-06-26

5,380 downloads per month
Used in 11 crates (6 directly)

MIT/Apache

165KB
3K SLoC

radix64

Docs build status

Fast and easy base64 encoding and decoding.

Usage

Encode and decode with the standard alphabet

use radix64::STD;
let encoded = STD.encode("my message");
let decoded = STD.decode(&encoded).unwrap();
assert_eq!("my message".as_bytes(), &decoded);

Encode and decode with the url safe alphabet

use radix64::URL_SAFE;
let encoded = URL_SAFE.encode("my message");
let decoded = URL_SAFE.decode(&encoded).unwrap();
assert_eq!("my message".as_bytes(), &decoded);

Encode multiple messages reusing the same allocated buffer for each message.

use radix64::STD;
let mut buf = Vec::new();
let encoded = STD.encode_with_buffer("my message", &buf);
let encoded = STD.encode_with_buffer("my second message", &buf);

Decode multiple messages reusing the same allocated buffer for each message.

use radix64::STD;
let mut buf = Vec::new();
let decoded = STD.decode_with_buffer("AABB", &buf);
let decoded = STD.decode_with_buffer("AA==", &buf);

Define and use a custom alphabet

use radix64::ConfigBuilder;
let my_cfg =
    ConfigBuilder::with_alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#&")
        .no_padding()
        .build()
        .unwrap();
let encoded = my_cfg.encode("my message");
let decoded = my_cfg.decode(&encoded).unwrap();

Performance

The standard alphabets (STD, URL_SAFE, and CRYPT) along with the NO_PAD variants all have an AVX2 optimized encoder and decoder. This provides a huge performance boost if running on an AVX2 enabled CPU. A runtime check will be performed by default to see if AVX2 is available. If you specify compiling for an AVX2 enabled platform the runtime check will be avoided. If you want to avoid using the AVX2 implementation you can disable the "simd" feature when compiling the crate.

See a sample of benchmark runs here

Dependencies