a c-extension that implements a binary reader on top of bytes and bytearrays
Project description
binaryreader
binaryreader is a faster and more elegant alternative to struct
for parsing binary data in Python.
Example
from binaryreader import BinaryReader
data: bytes|bytearray
read_little_endian: bool = True
reader = BinaryReader(data, read_little_endian)
text = reader.readStringC()
Benchmark
TODO
Properties
endian: bool
[get,set] - endianness of the reader (True - little, False - big)position: int
[get,set] - position of the cursor within the datasize: int
[get] - size of underlying/passed objectobj: bytes|bytearray
[get] - underlying/passed object
Functions
Notes:
-
kwargs won't be accepted, only args are useable
-
all readArray functions accept a langth as optional argument
-
bytes can be read by using readUInt8Array
-
BinaryReader(data: bytes|bytearray, is_little_endian: bool)
-
.readBool(): bool
- reads a bool -
.readInt8(): int
- reads an int8 -
.readUInt8(): int
- reads an uint8 -
.readInt16(): int
- reads an int16 -
.readUInt16(): int
- reads an uint16 -
.readInt32(): int
- reads an int32 -
.readUInt32(): int
- reads an uint32 -
.readInt64(): int
- reads an int64 -
.readUInt64(): int
- reads an uint64 -
.readHalf(): float
- reads a half -
.readFloat(): float
- reads a float -
.readDouble(): float
- reads a double -
.readBoolArray(): [bool]
- reads a bool array -
.readInt8Array(): [int]
- reads a array of int8 -
.readUInt8Array(): bytearray
- reads a array of uint8 -
.readInt16Array(): [int]
- reads a array of int16 -
.readUInt16Array(): [int]
- reads a array of uint16 -
.readInt32Array(): [int]
- reads a array of int32 -
.readUInt32Array(): [int]
- reads a array of uint32 -
.readInt64Array(): [int]
- reads a array of int64 -
.readUInt64Array(): [int]
- reads a array of uint64 -
.readHalfArray(): [float]
- reads a array of half -
.readFloatArray(): [float]
- reads a array of float -
.readDoubleArray(): [float]
- reads a array of double -
.readStringC(): str
- reads a null terminated string -
.readStringCArray(): [str]
- reads an array of null terminated strings -
.readString(): str
- reads a string (if length is not passed as arg, read an int as length) -
.readStringArray(): [str]
- reads an array of strings -
.readStringAligned(): str
- same as readString but aligned to 4 bytes after reading the string -
.readStringAlignedArray(): [str]
- reads an array of aligned strings -
.align(align_by: int): int
- aligns the cursor to the given input and returns the position after the alignment -
.readVarInt(): int
- reads a varint -
.readLSB(): bytearray
- reads the lsb data of the given size (in bytes to read -> output length is 1/8 of that)
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
Built Distributions
Hashes for binaryreader-0.1.1-py3.9-macosx-11-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | a45e6c05cb1be67f8976cb689ffd5e0836307f42e75924040810a8ee83246d28 |
|
MD5 | a9a5f70b9221ac89e7b31d6b4ff7d559 |
|
BLAKE2b-256 | 016d30360dbcb5489cfb8e6b03d1459a978d275a3b4052fbd4e5d6a99c421cb9 |
Hashes for binaryreader-0.1.1-py3.7-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34ce207f292ab47ae36920fd890bbcfba3f42b6da0c7566081fe262b56d0ab43 |
|
MD5 | 9044c4805504d8068d666083f739c6d4 |
|
BLAKE2b-256 | 41b7bef04af3d62635f8fa5a1d18a26bd347f905c5050618ba5f4deb501507a9 |
Hashes for binaryreader-0.1.1-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ef22945b7429ce27b89eb896c6b11a256bdf14713396a15bfb6a9f316bdd5df |
|
MD5 | a86bdfb764c7a92e6ad929f16e6b5153 |
|
BLAKE2b-256 | 073f3c791fc3b94b2022f23172d90fc3d7b38049c02df81c341d82a846b8b0de |
Hashes for binaryreader-0.1.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f5afa5562ece1993a4c6aee9618ce46645238b4601132d0b7fd6acf3cad4f67 |
|
MD5 | 061f66a26d7e089ff4f87a6b287f97f8 |
|
BLAKE2b-256 | 8068cf5b9530c19557f17cdde1ac392eb781cc591390e3c132bf04852283f4a8 |