binary_reader v1.3
Changelog:
- Added an
encoding
parameter in the constructer which defaults to'utf-8'
. - Added context managers for
with
statement. See examples below.
The BinaryReader's buffer will get cleared after returning to the original context.
with BinaryReader() as br:
br.write_uint32(0)
The BinaryReader will seek_to
the given offset, and will return to the original position before the method was called after exiting the context.
# Position is pos
with br.seek_to(offset):
# Position is offset
br.read_uint32()
# Position is offset + 4
# Position is pos
You can also use as
to get a reference to the BinaryReader, if you prefer to use a different variable name inside the new context.
# Works the same way as in the previous example
with br.seek_to(offset, whence) as section:
section.read_uint32()