bx.misc.binary_file module

Wrappers for doing binary IO on file-like objects

exception bx.misc.binary_file.BadMagicNumber

Bases: OSError

class bx.misc.binary_file.BinaryFileReader(file, magic=None, is_little_endian=False)

Bases: object

Wrapper for doing binary reads on any file like object.

Currently this is not heavily optimized (it uses the struct module to unpack)

read(byte_count=1)
read_and_unpack(format, byte_count=None)

Read enough bytes to unpack according to format and return the tuple of unpacked values.

read_c_string()

Read a zero terminated (C style) string

read_float()
read_raw_array(dtype, size)
read_uint16()
read_uint32()
read_uint64()
read_uint8()
seek(pos, whence=0)
skip(count)
tell()
unpack(format, buffer, byte_count=None)
class bx.misc.binary_file.BinaryFileWriter(file, magic=None, is_little_endian=False)

Bases: object

Wrapper for doing binary writes on any file like object.

Currently this is not heavily optimized (it uses the struct module to unpack)

pack(format, buffer)
pack_and_write(format, value)

Read enough bytes to unpack according to format and return the tuple of unpacked values.

seek(pos, whence=0)
skip(count)
tell()
write(value)
write_c_string(value)

Read a zero terminated (C style) string

write_raw_array(value)
write_uint16(value)
write_uint32(value)
write_uint64(value)
write_uint8(value)
bx.misc.binary_file.bytesify(s)