GithubHelp home page GithubHelp logo

base91's Introduction

basE91 implementation for Rust

GitHub Actions 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

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

let encode_as_vec: Vec<u8> = base91::slice_encode(source.as_bytes());
let decode_as_vec: Vec<u8> = base91::slice_decode(&encode_as_vec);

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

assert_eq!(
    "This is a random binary string",
    String::from_utf8_lossy(&decode_as_vec)
);

Using Iterators

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

let as_vec: Vec<u8> = base91::EncodeIterator::new(source.bytes()).collect();
let as_str: String = base91::EncodeIterator::new(source.bytes()).as_char_iter().collect();

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

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

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).

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

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

let encode_as_vec: Vec<u8> = EncodeGenericIterator::<XmlFriendly, _>::new(source.bytes()).collect();
let decode_as_vec: Vec<u8> = DecodeGenericIterator::<XmlFriendly, _>::new(encode_as_vec.iter().copied()).collect();

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

assert_eq!(
    "This is a random binary string",
    String::from_utf8_lossy(&decode_as_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

base91's People

Contributors

dnsl48 avatar mominul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

base91's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.