Skip to main content

Python binary object reader/writer

Project description

Byter

Python reader/writer for binary objects

Usage Example

with open(fpath, "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, size, 'unsigned_short')

print("has_data:", has_data)
print("year:", year)
print("month:", month)
print("width:", width)
print("height:", height)
print("text": text)
print("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 * 4 bytes in total.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

byter-0.0.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

byter-0.0.1-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file byter-0.0.1.tar.gz.

File metadata

  • Download URL: byter-0.0.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for byter-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9de8fc8e6eb163049bc1988e7f26df882ec94420c5010d1147c4a12f2508be01
MD5 55958369c150d5c7d66c709975af224b
BLAKE2b-256 b1a091e2bf17ae5642c10f5d6a73a549596bb6e6e04f0c546aad8136fa9a7c46

See more details on using hashes here.

File details

Details for the file byter-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: byter-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for byter-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2cf23f793f0252dbd6fa77efe7b776e477d86e5f9165e59f42c24e889c42fa6
MD5 3141c5a429f7e469f0343fb6bfdca67f
BLAKE2b-256 d38013d353b4db1b51e4ba14d846dd04b6c780b673b251db0ca84cdb2d453387

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page