An IO wrapper that reads/writes binary data as base64 into a text file
Project description
Base64File
- like gzip.GzipFile, but writes out your binary data as base64 text
- and obviously the inverse, it reads base64 text files as binary data
- supports most modes
- the standard
wb
,rb
,ab
,xb
, with optional+
for concurrent reading/writing - the
b
is optional to specify
- the standard
Usage
from base64file import Base64File
# open a new/existing file
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 open file
with open('some-file.txt', 'w+') as f:
with Base64File(file_obj=f) 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'
# 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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
base64file-0.0.3.tar.gz
(8.3 kB
view hashes)
Built Distribution
Close
Hashes for base64file-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7646149c17247cee901ffcc829f3bb6d098cf77c233c8f8880a4511bed6a2084 |
|
MD5 | 020c7e44513c3a5311238db32f62616f |
|
BLAKE2b-256 | cdb28007235207867190cf2568c5bee16b83aafa949d55229f2f9da56fce7d95 |