Skip to content

Commit

Permalink
[core] Allow calling UploadContext.collect_data multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
prokoma committed Dec 1, 2024
1 parent 1d3fabd commit edaa767
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions uf2tool/models/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def get_offset(self, part: str, offs: int) -> Optional[int]:
return None
return start + offs

def rewind(self) -> None:
self.seq = 0

def read_next(self, scheme: OTAScheme) -> Optional[Tuple[str, int, bytes]]:
"""
Read next available data block for the specified OTA scheme.
Expand Down Expand Up @@ -152,6 +155,10 @@ def collect_data(self, scheme: OTAScheme) -> Optional[Dict[int, BytesIO]]:
if not self.board_name:
raise ValueError("This UF2 is not readable, since no board name is present")

# rewind to the beginning of the UF2 so collect_data can be called
# multiple times
self.rewind()

out: Dict[int, BytesIO] = {}
while True:
ret = self.read_next(scheme)
Expand Down

0 comments on commit edaa767

Please sign in to comment.