The z-base-32
is a human oriented base32 encoding.
The library exposes two functions with following signatures and error type:
```rs pub fn encode(input: &[u8]) -> String;
pub fn decode(input: &str) -> Result
pub struct DecodeError; ```
```rs use zbase32::{encode, decode};
fn main() { asserteq!(encode(b"foo"), "c3zs6".tostring()); asserteq!(Ok(b"foo"), decode("c3zs6".tostring())); assert_eq!(decode(&encode(b"foo")).unwrap(), b"foo") } ```
This crate can be compiled with feature flag python
in which case it produces python bindings. To build a Python wheels use maturin
:
console
maturin build --cargo-extra-args="--features python"
```py def encode(input: bytes) -> str:
def decode(input: str) -> bytes:
class DecodeError(Exception): ```
```py import zbase32
assert zbase32.encode(b'foo') == 'c3zs6'
assert zbase32.decode('c3zs6') == b'foo'
try: zbase32.decode('invalid@char') except zbase32.DecodeError as e: print(e) ```