#base32 #encode-decode #decode #encode #python

bin+lib z-base-32

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

5 releases

0.1.4 Feb 27, 2024
0.1.3 Nov 21, 2023
0.1.2 Aug 25, 2021
0.1.1 Aug 25, 2021
0.1.0 Aug 19, 2021

#317 in Encoding

Download history 357/week @ 2023-12-18 298/week @ 2023-12-25 429/week @ 2024-01-01 635/week @ 2024-01-08 462/week @ 2024-01-15 543/week @ 2024-01-22 476/week @ 2024-01-29 519/week @ 2024-02-05 661/week @ 2024-02-12 823/week @ 2024-02-19 1209/week @ 2024-02-26 876/week @ 2024-03-04 472/week @ 2024-03-11 779/week @ 2024-03-18 383/week @ 2024-03-25 729/week @ 2024-04-01

2,441 downloads per month
Used in 26 crates (3 directly)

MIT license

15KB
217 lines

z-base-32

ci

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

Rust

Crate

Installation

cargo add z-base-32

API

The library exposes two functions with the following signatures and an 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")
}

CLI

This project also provides a CLI utility with a similar interface to the well-known base64 command.

Installation

To install z-base-32 CLI you can build it from source or download prebuild binary from releases.

cargo install --features cli z-base-32

Example

$ zbase32 -h
z-base-32: human-oriented base-32 encoding

Usage: zbase32 [OPTIONS] [FILE]

Arguments:
  [FILE]  File to encode or decode

Options:
  -d, --decode       Decode data
  -w, --wrap <WRAP>  Wrap encoded lines after COLS character [default: 76]
  -h, --help         Print help
  -V, --version      Print version

Python

Installation

The z-base-32 package is published at PyPI. Install it using the following command:

pip install z-base-32

Building

This crate can be compiled with the feature flag python in which case it produces Python bindings. To build 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–6.5MB
~19K SLoC