Skip to main content

Base64File

An IO wrapper that but reads/writes binary data as base64 text, supporting concurrent reading and writing. Similar to GzipFile, it simulates most of the methods of a standard file object (with the exception of readline).

Usage

base64file.open()

  • Similar to gzip.open() or io.open()
import base64file

# to write text
with base64file.open('some-file.txt', 'rt', encoding='utf8') as f:
    f.write('1234567890')

# to write binary
with base64file.open('some-file.txt', 'rb') as f:
    f.write(b'\1\2\3\4\5')

base64file.Base64File

  • When opening a Base64File without specifying an underlying file, a filename must be provided, and the usual binary modes are supported: r, rb, w, wb, a, ab, x, and xb (optional + to enable concurrent reading/writing, e.g. wb+).
  • When opening a Base64File with a specified underlying file, the mode is inherited from the specified file (replacing text-mode with binary-mode). If a binary-mode file is provided, it is automatically wrapped with a TextIOWrapper.
from base64file import Base64File

# open a new/existing file for concurrent reading and writing
with Base64File('some-file.txt', 'w+') as b:
    b.write(b'\0\1\2\3\4')
    b.seek(0)
    b.write(b'\n')
    print(b.read(2))  # prints b'\1\2'

# wrap an existing file (in this example, open for reading)
with open('some-file.txt', 'r') as f:
    with Base64File(file_obj=f) as b:
        print(b.read(2))  # prints b'\n\1'
        print(b.read())  # prints b'\2\3\4'

# if you need to keep the file open, remember to close it
f = open('some-file.txt', 'w+')
b = Base64File(file_obj=f)
b.write(b'\0\1\2\3\4')
b.seek(0)
b.write(b'\n')
print(b.read(2))  # prints b'\1\2'
b.close()  # this is necessary, otherwise the final 1-2 bytes may not be written
f.close()

base64file.Base85File and base64file.Ascii85File

  • The same as base64file.Base64File, but instead uses b85encode() or a85encode()
  • Note that many implementations of base85 are actually Ascii85 (for example, CyberChef.io)
from base64file import Ascii85File
from base64file import Base85File

Metadata

Release files for base64file 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for base64file 0.0.12
File Size Uploaded
base64file-0.0.12.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for base64file 0.0.12
File Interpreter ABI Platform
base64file-0.0.12-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 21.2 kB

Release files / base64file-0.0.12.tar.gz

Download URL base64file-0.0.12.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3b6330870df9aecf875bd03f67b4412f359a8d11e4d1148502b73da5cd7f787a
BLAKE2b-256 checksum
How to use checksums
1c8bec0fbd5e5b53eb6073f2d9f828830945f1bd99a938bafbb41c64723b19fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release files / base64file-0.0.12-py2.py3-none-any.whl

Download URL base64file-0.0.12-py2.py3-none-any.whl
Size 10.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9f91956abc9902c9b7247562812620ebab2c569406d84563124454acc4aae74f
BLAKE2b-256 checksum
How to use checksums
74723da0521bb7f730dd225d5a713ff6db99aa6c5d3f1a416882a3253d7afd8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page