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.2-py3.9-macosx-11-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d56ce7c1873a4ee751965e97e03e4a4ac5846e12b550a65ef23f1360cf681d7 |
|
MD5 | 6fec22dad4cf4de1daaf0903e19e415b |
|
BLAKE2b-256 | 3d4630ddf8109aec3b96da88a3bc7c530b5d28a22cc170bce793b16797ada9c4 |
Hashes for binaryreader-0.1.2-py3.7-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e372dfd9cf296fe6b9a40a1095702187ade26bb5a9fb8b58b7906ce7b636a2a |
|
MD5 | 5b4a0ac99d6f5f79bd91e4ab887843e1 |
|
BLAKE2b-256 | 112c9bb13ef5526575c017458716b892b01c57fd6bc4498dc8fa3ab8dc3cbc26 |
Hashes for binaryreader-0.1.2-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27dafebbb1b953a3c30f58640e03811150db12badba791511a6ebe3258588a50 |
|
MD5 | 4164ce62ad2e5831faf32f381a81a735 |
|
BLAKE2b-256 | eb85d098faa5189cd4a6bf406269824f86accc475f4f3d045b141fae5ffab735 |
Hashes for binaryreader-0.1.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2870c3cad7848bb8f2477d5c3ab5ae9b3d5434b8b892c62f45978df43c876c74 |
|
MD5 | e207707701a502335decb60a959f04f5 |
|
BLAKE2b-256 | 73942d014bea588a4e634eb7002dbf92ab27a3ca4b9ed0a71a8e8aa5ff363704 |