Python binary object reader/writer
Project description
Byter
Python reader/writer for binary objects
Installation
pip install -U byter
Usage Example
with open("/path/to/binary/file", "rb") as data:
has_data = read_bool(data)
year = read_short(data)
month = read_short(data)
width = read_float(data)
height = read_float(data)
text = read_string(data, 70)
array = read_array(data, 3, 'unsigned_short')
print("has_data:", has_data)
print("year:", year)
print("month:", month)
print("width:", width)
print("height:", height)
print("text:": text)
print("array:", array)
>> has_data: True
year: 2019
month: 9
width: 1280.0
height: 1024.0
text: "Hello World!"
array: [13, 4, 16]
Types allowed to read/write
| C Type | Python type | Size in bytes |
|---|---|---|
| char | string of length 1 | 1 |
| signed char | integer | 1 |
| unsigned char | integer | 1 |
| bool | boolean | 1 |
| short | integer | 2 |
| unsigned short | integer | 2 |
| int | integer | 4 |
| unsigned int | integer | 4 |
| long | integer | 4 |
| unsigned long | integer | 4 |
| long long | integer | 8 |
| unsigned long long | integer | 8 |
| float | float | 4 |
| double | float | 8 |
| char[] | string |
Methodes allowed
For each C type from the table in the previous section, there is a read_ and a write_ function that performs a reading/writing of a specified number of bytes from the binary object. For example,
a = read_unsigned_long(data)
will read 4 consequent bytes from the binary source data.
However, to read an array of chars (string) the method is
s = read_string(data, s_len)
It is also possible to read an array of bytes using the following method:
arr = read_array(data, size, 'unsigned_short')
This will read a sequence of length size of unsigned ints, size * 2 bytes in total (short type is of 2 bytes).
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file byter-0.0.2.tar.gz.
File metadata
- Download URL: byter-0.0.2.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4331d01f175ba399110f1efcfd4f09bf341c768b5ae9128de88ccb5506ff5a44
|
|
| MD5 |
b6ba2b79bf763cdb81ceab6fbfc626fd
|
|
| BLAKE2b-256 |
5d76ec9a6acc63f7c37a98966bb13fc566e56ce933fd15020569951c944f03d3
|
File details
Details for the file byter-0.0.2-py3-none-any.whl.
File metadata
- Download URL: byter-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e351bedfc60d4c2072b6680adc759fc3c4be088d5072f513cd4f75c39741fcd
|
|
| MD5 |
ed1eedac10289ccca7498f19cf850bda
|
|
| BLAKE2b-256 |
946f1402d7d432a1d0d3ca77e2bbdc00ba625442ce7f08516b1448fa527aa4ac
|