eerimoq / bincopy

Mangling of various file formats that conveys binary information (Motorola S-Record, Intel HEX, TI-TXT, Verilog VMEM, ELF and binary files).
MIT License
109 stars 38 forks source link

Change behaviour of `as_binary` when data is not present? #31

Open martinjthompson opened 1 year ago

martinjthompson commented 1 year ago

For my use-case it would be useful for as_binary to raise an Exception if I ask for data which is not contained in the files I have added.

At the moment, if padding is None, it is converted to a default of 0xFF . I would request the following (which admittedly changes the API):

make the default parameters more explicit:

def as_binary(self,
                  minimum_address=None,
                  maximum_address=None,
                  padding=0xFF):

and then alter the behaviour of padding==None to raise a RuntimeException if there is any data requested which does not 'exist'. Would this be acceptable?

eerimoq commented 1 year ago

Maybe add another argument?

def as_binary(self,
              minimum_address=None,
              maximum_address=None,
              padding=None,
              data_must_exist=False):
martinjthompson commented 1 year ago

Oh, yes, that could work :) I'll try and pull a PR together...