diff --git a/bincopy.py b/bincopy.py index a254133..3e2803f 100755 --- a/bincopy.py +++ b/bincopy.py @@ -351,13 +351,8 @@ class Segment: """ - class Chunk(namedtuple("Chunk", ["address", "data"])): + _Chunk = namedtuple("Chunk", ["address", "data"]) - def __len___(self): - return len(self.data) - - _Chunk = Chunk - def __init__(self, minimum_address, maximum_address, data, word_size_bytes): self.minimum_address = minimum_address self.maximum_address = maximum_address @@ -389,16 +384,20 @@ def chunks(self, size=32, alignment=1): if chunk_offset != 0: first_chunk_size = (alignment - chunk_offset) - yield self.Chunk(address // self._word_size_bytes, - data[:first_chunk_size]) + yield Segment(address // self._word_size_bytes, + (address + size) // self._word_size_bytes, + data[:first_chunk_size], + self._word_size_bytes) address += (first_chunk_size // self._word_size_bytes) data = data[first_chunk_size:] else: first_chunk_size = 0 for offset in range(0, len(data), size): - yield self.Chunk((address + offset) // self._word_size_bytes, - data[offset:offset + size]) + yield Segment((address + offset) // self._word_size_bytes, + (address + offset + size) // self._word_size_bytes, + data[offset:offset + size], + self._word_size_bytes) def add_data(self, minimum_address, maximum_address, data, overwrite): """Add given data to this segment. The added data must be adjacent to