basE91 implementation for Rust

CircleCI Documentation Current Version on crates.io MIT / Apache2 License

basE91 is an advanced method for encoding binary data as ASCII characters. It is similar to base64, but is more efficient. The overhead produced by basE91 depends on the input data. It amounts at most to 23% (versus 33% for base64) and can range down to 14%, which typically occurs on 0-byte blocks.

For more information see http://base91.sourceforge.net/

Joachim Henke's basE91 encoding implementation for Rust.

Also supports xml-friendly base91 implementation by r-lyeh, which supports quoting and is JSON, XML and TSV friendly.

Library features

Examples

Using helpers

```rust let source = "This is a random binary string";

let encodeasvec: Vec = base91::sliceencode(source.asbytes()); let decodeasvec: Vec = base91::slicedecode(&encodeas_vec);

asserteq!( "nX,<:WRT%yxtYQ:mbr4JB*H[LR/@Qj{o0aU=Z", String::fromutf8lossy(&encodeas_vec) );

asserteq!( "This is a random binary string", String::fromutf8lossy(&decodeas_vec) ); ```

Using Iterators

```rust let source = "This is a random binary string";

let asvec: Vec = base91::EncodeIterator::new(source.bytes()).collect(); let asstr: String = base91::EncodeIterator::new(source.bytes()).aschariter().collect();

asserteq!( "nX,<:WRT%yxtYQ:mbr4JB*H[LR/@Qj{o0aU=Z", String::fromutf8lossy(&asvec) );

asserteq!( "nX,<:WRT%yxtYQ:mbr4JB*H[LR/@Qj{o0aU=Z", asstr ); ```

Using Xml Friendly or another specific variation

Warning! If you disable the feature canonical and enable the feature xml-friendly, then base91::EncodeIterator and base91::DecodeIterator will silently use XmlFriendly variant. In turn, all the helper functions use the iterators internally (slice_encode and slice_decode).

```rust use base91::iter::{EncodeGenericIterator, DecodeGenericIterator}; use base91::codemap::XmlFriendly;

let source = "This is a random binary string";

let encodeasvec: Vec = EncodeGenericIterator::::new(source.bytes()).collect(); let decodeasvec: Vec = DecodeGenericIterator::::new(encodeasvec.iter().copied()).collect();

asserteq!( "nX,-:WRT%yxtYQ:mbr4JB*H[LR/@Qj{o0aU=Z", String::fromutf8lossy(&encodeas_vec) );

asserteq!( "This is a random binary string", String::fromutf8lossy(&decodeas_vec) ); ```

License

The current Rust implementation is provided under the dual MIT/Apache2 license.

Acknowledgement

The original basE91 has been developed by Joachim Henke, and is released as free software under the terms of the BSD license