How-to¶
Basic actions¶
The following methods are defined in the base class MultiPartBuffer
and are available with all hexformat
classes.
Load an existing file¶
Methods are provided to read the data from already opened file handles (or compatibles) or by providing the file name only.
A new instance can be directly created from using fromfh()
and fromfile()
.
These methods will use the default format and call from<formatname>fh()
and from<formatname>file()
respectively.
All classes support reading from binary files using frombinfh()
and frombinfile()
Additional content can be read to an exising instance using loadfh()
and loadfile()
.
These methods will use the default format and call load<formatname>fh()
and load<formatname>file()
respectively.
All classes support reading from binary files using loadbinfh()
and loadbinfile()
Create new instance from binary file¶
- classmethod MultiPartBuffer.frombinfh(fh, address=0, size=-1, offset=0)[source]
- classmethod MultiPartBuffer.frombinfile(filename, address=0, size=-1, offset=0)[source]
Example:
from hexformat.srecord import SRecord
srec = SRecord.frombinfile("somefile.bin")
with open("somefile.bin", "rb") as fh:
srec2 = SRecord.frombinfh(fh)
Load (more) content from a binary file¶
- MultiPartBuffer.loadbinfh(fh, address=0, size=-1, offset=0)[source]
- MultiPartBuffer.loadbinfile(filename, address=0, size=-1, offset=0)[source]
Example:
from hexformat.srecord import SRecord
srec = SRecord()
srec.loadbinfile("somefile.bin")
with open("somefile.bin", "rb") as fh:
srec = SRecord.loadbinfh(fh)
Create new instance from hex file¶
These methods are using the standard format of the class as long no other is specified using the fformat argument.
- classmethod MultiPartBuffer.fromfh(fh, fformat=None, *args, **kvargs)[source]
- classmethod MultiPartBuffer.fromfile(filename, fformat=None, *args, **kvargs)[source]
Example:
from hexformat.srecord import SRecord
srec = SRecord.fromfile("somefile.bin")
with open("somefile.bin", "rb") as fh:
srec2 = SRecord.fromfh(fh)
Load (more) content from a hex file¶
These methods are using the standard format of the class as long no other is specified using the fformat argument.
- MultiPartBuffer.loadfh(fh, fformat=None, *args, **kvargs)[source]
- MultiPartBuffer.loadfile(filename, fformat=None, *args, **kvargs)[source]
Example:
from hexformat.srecord import SRecord
srec = SRecord()
srec.loadfile("somefile.bin")
with open("somefile.bin", "rb") as fh:
srec = SRecord.loadfh(fh)