Skip to content

Commit

Permalink
Don't rescan the whole previous block
Browse files Browse the repository at this point in the history
  • Loading branch information
AT0myks committed Jun 28, 2023
1 parent dcca555 commit fbd8261
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pycramfs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def find_superblocks(
"""Return a list of dictionaries representing the
superblocks found in the file with their offset.
"""
count = 0
indexes: Set[int] = set()
result: List[StructAsDict] = []
if isinstance(file_or_bytes, (str, Path)):
Expand All @@ -80,14 +79,13 @@ def find_superblocks(
raise TypeError("argument must be a path or bytes")
with stream as f:
prev_block = b''
for next_block in iter(partial(f.read, size), b''):
for count, next_block in enumerate(iter(partial(f.read, size), b'')):
# We don't want to "cut" in the middle of a magic.
block = prev_block + next_block
index = block.find(MAGIC_BYTES)
if index != -1:
indexes.add(index + (count * size) - len(prev_block))
prev_block = next_block
count += 1
prev_block = next_block[-(len(MAGIC_BYTES) - 1) :]
for index in sorted(indexes):
f.seek(index)
super = Super.from_fd(f)
Expand Down

0 comments on commit fbd8261

Please sign in to comment.