Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matusf/z-base-32
z-base-32: human-oriented base-32 encoding
https://github.com/matusf/z-base-32
encoding python rust zbase32
Last synced: 1 day ago
JSON representation
z-base-32: human-oriented base-32 encoding
- Host: GitHub
- URL: https://github.com/matusf/z-base-32
- Owner: matusf
- License: mit
- Created: 2021-08-08T19:40:23.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-01-08T19:04:21.000Z (1 day ago)
- Last Synced: 2025-01-08T20:23:15.592Z (1 day ago)
- Topics: encoding, python, rust, zbase32
- Language: Rust
- Homepage:
- Size: 77.1 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# z-base-32
![ci](https://github.com/matusf/z-base-32/actions/workflows/ci.yml/badge.svg)
The `z-base-32` is a human-oriented base-32 encoding.
## Rust
### Crate
#### Installation
```sh
cargo add z-base-32
```#### API
The library exposes two functions with the following signatures and an error type:
```rs
pub fn encode(input: impl AsRef<[u8]>) -> String;pub fn decode(input: &str) -> Result, DecodeError>;
pub struct DecodeError;
```#### Example
```rs
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](https://github.com/matusf/z-base-32/releases/latest).
```console
cargo install --features cli z-base-32
```#### Example
```console
$ zbase32 -h
z-base-32: human-oriented base-32 encodingUsage: zbase32 [OPTIONS] [FILE]
Arguments:
[FILE] File to encode or decodeOptions:
-d, --decode Decode data
-w, --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](https://pypi.org/project/z-base-32/). Install it using the following command:
```console
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`](https://github.com/PyO3/maturin):
```console
maturin build
```### API
```py
def encode(input: bytes) -> str:def decode(input: str) -> bytes:
class DecodeError(Exception):
```### Example
```py
import zbase32assert zbase32.encode(b'foo') == 'c3zs6'
assert zbase32.decode('c3zs6') == b'foo'
try:
zbase32.decode('invalid@char')
except zbase32.DecodeError as e:
print(e)
```## References
-