A BinaryReader class for Python 3.6+.
Instanciate a BinaryReader class:
from binreader import BinaryReader
with open("example.bin", "rb") as f:
reader = BinaryReader(f)
print(reader.read_int()) # Reads an int32, returns a Python intThe following read methods are available:
read_bool()->boolread_byte()->intread_ubyte()->intread_int16()->intread_uint16()->intread_int32()->intread_uint32()->intread_int64()->intread_uint64()->intread_int()->int(alias ofread_int32())read_uint()->int(alias ofread_uint32())read_float()->floatread_double()->float
The following string read methods are available:
read_cstring()->bytes: Reads a null-terminated string.read_string(size: int=None)->str: Reads and decodes a string of sizesize. IfsizeisNone, expects a null terminator.
The following utility methods are available:
align(): Seeks forward to align the buffer's handle position on a multiple of 4 bytes.read(*args): Callsread(*args)on the buffer.seek(*args): Callsseek(*args)on the buffer.tell(): Returns the buffer's handle position.read_struct(format): Read a struct from the buffer, returning a tuple of that struct. Size is automatically calculated. Endianness defaults to the reader's endianness, but may be overridden.
This project is licensed under the MIT license. The full license text is available in the LICENSE file.