Base2048

0.1.3 · active · verified Fri Apr 17

`base2048` is a Python library that provides efficient binary encoding and decoding using the Base2048 scheme, implemented as a Rust extension for performance. It offers simple functions to convert bytes to Base2048 strings and vice-versa. The current version is 0.1.3, and it functions as a stable utility library with infrequent updates, focusing on its core encoding capabilities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to encode `bytes` to a Base2048 string and decode it back. It also shows the necessary steps to handle text (Unicode) by explicitly converting it to bytes before encoding and back to a string after decoding.

from base2048 import encode, decode

original_bytes = b"Hello, Base2048 encoding!"

# Encode bytes to a Base2048 string
encoded_string = encode(original_bytes)
print(f"Original bytes: {original_bytes!r}")
print(f"Encoded string: {encoded_string!r}")

# Decode Base2048 string back to bytes
decoded_bytes = decode(encoded_string)
print(f"Decoded bytes:  {decoded_bytes!r}")

assert original_bytes == decoded_bytes

# Example with text that needs explicit encoding/decoding
text = "こんにちは, Base2048!"
text_bytes = text.encode('utf-8')
encoded_text_string = encode(text_bytes)
print(f"\nOriginal text: {text!r}")
print(f"Encoded text string: {encoded_text_string!r}")

decoded_text_bytes = decode(encoded_text_string)
decoded_text = decoded_text_bytes.decode('utf-8')
print(f"Decoded text: {decoded_text!r}")
assert text == decoded_text

view raw JSON →