Install & Compatibility
Where this runs
tested against v1.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.030s · 17.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.026s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Base64IO
✓ from base64io import Base64IO
This quickstart demonstrates how to use `base64io.Base64IO` to stream encode and decode content. It creates dummy binary and Base64 files, then uses `Base64IO` to transform them, verifying the output. Note that `Base64IO` always expects and produces byte streams.
import base64io
import tempfile
import os
# Create dummy input files in a temporary directory
dummy_input_bin_content = b"Hello, base64io streaming!"
dummy_input_b64_content = b"SGVsbG8sIGJhc2U2NGlvIHN0cmVhbWluZyE=" # Base64 of the above
with tempfile.TemporaryDirectory() as tmpdir:
input_bin_path = os.path.join(tmpdir, 'input.bin')
input_b64_path = os.path.join(tmpdir, 'input.b64')
output_b64_path = os.path.join(tmpdir, 'output.b64')
output_bin_path = os.path.join(tmpdir, 'output.bin')
# Write dummy content to temporary files
with open(input_bin_path, 'wb') as f:
f.write(dummy_input_bin_content)
with open(input_b64_path, 'wb') as f:
f.write(dummy_input_b64_content)
print(f"Temporary directory: {tmpdir}")
# --- Encoding example ---
# Open original binary input, wrap with Base64IO for encoding
with open(input_bin_path, 'rb') as fin, base64io.Base64IO(fin, 'encode') as fenc:
# Write encoded content to output file
with open(output_b64_path, 'wb') as fout:
fout.write(fenc.read())
# Verify encoded output
with open(output_b64_path, 'rb') as f:
encoded_output = f.read()
print(f"Encoded content written to {output_b64_path}: {encoded_output}")
assert encoded_output == dummy_input_b64_content
# --- Decoding example ---
# Open Base64 encoded input, wrap with Base64IO for decoding
with open(input_b64_path, 'rb') as fin, base64io.Base64IO(fin, 'decode') as fdec:
# Write decoded content to output file
with open(output_bin_path, 'wb') as fout:
fout.write(fdec.read())
# Verify decoded output
with open(output_bin_path, 'rb') as f:
decoded_output = f.read()
print(f"Decoded content written to {output_bin_path}: {decoded_output}")
assert decoded_output == dummy_input_bin_content
print("Quickstart successful!")
Errors
Common errors & fixes
TypeError: a bytes-like object is required, not '_io.TextIOWrapper'
Attempting to initialize `base64io.Base64IO` with a file opened in text mode (`'r'` or `'w'`), but the library expects a binary stream.
fixEnsure the underlying file is opened in binary mode, e.g., `open('my_file.txt', 'rb')` for reading or `open('output.b64', 'wb')` for writing. AttributeError: 'str' object has no attribute 'read'
Passing a raw `str` or `bytes` object directly to the `base64io.Base64IO` constructor instead of a file-like object.
fixWrap the `str` (after encoding to bytes) or `bytes` object in an `io.BytesIO` object before passing it to `Base64IO`, or use the standard `base64` module for direct string/bytes operations.
ValueError: Non-base64 character found
When `Base64IO` is in decode mode, the underlying stream contains characters that are not part of the standard Base64 alphabet (A-Z, a-z, 0-9, +, /, =).
fixVerify that the input stream consists solely of valid Base64 characters. Pre-process the stream to remove any unexpected characters or padding if necessary.
Upgrade
Version history
1.0.3latest on PyPI · released Dec 10, 2018
Audit
Dependencies
No dependency data recorded yet.