#zbase32 #base32 #encode #decode #python

z-base-32

z-base-32: human-oriented base-32 encoding

4 releases

0.1.3 Nov 21, 2023
0.1.2 Aug 25, 2021
0.1.1 Aug 25, 2021
0.1.0 Aug 19, 2021

#250 in Encoding

Download history 109/week @ 2023-11-04 121/week @ 2023-11-11 178/week @ 2023-11-18 326/week @ 2023-11-25 221/week @ 2023-12-02 496/week @ 2023-12-09 408/week @ 2023-12-16 298/week @ 2023-12-23 588/week @ 2023-12-30 677/week @ 2024-01-06 532/week @ 2024-01-13 577/week @ 2024-01-20 511/week @ 2024-01-27 495/week @ 2024-02-03 686/week @ 2024-02-10 852/week @ 2024-02-17

2,696 downloads per month
Used in 24 crates (3 directly)

MIT license

9KB
139 lines

z-base-32

ci

The z-base-32 is a human oriented base32 encoding.

API

The library exposes two functions with following signatures and error type:

pub fn encode(input: &[u8]) -> String;

pub fn decode(input: &str) -> Result<Vec<u8>, DecodeError>;

pub struct DecodeError;

Example

use zbase32::{encode, decode};

fn main() {
    assert_eq!(encode(b"foo"), "c3zs6".to_string());
    assert_eq!(Ok(b"foo"), decode("c3zs6".to_string()));
    assert_eq!(decode(&encode(b"foo")).unwrap(), b"foo")
}

Python

Building

This crate can be compiled with feature flag python in which case it produces Python bindings. To build a Python wheels use maturin:

maturin build

API

def encode(input: bytes) -> str:

def decode(input: str) -> bytes:

class DecodeError(Exception):

Example

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)

References

Dependencies

~0–7MB
~12K SLoC