Skip to content
Snippets Groups Projects
Verified Commit 0119f4c1 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

swh.model: Do multiple reads with a fixed chunk size

parent 34870256
No related branches found
Tags debian/upstream/4.2.0
No related merge requests found
......@@ -124,7 +124,10 @@ class Content(MerkleLeaf):
h = MultiHash(length=length)
chunks = []
with open(path, 'rb') as fobj:
for chunk in fobj:
while True:
chunk = fobj.read(HASH_BLOCK_SIZE)
if not chunk:
break
h.update(chunk)
chunks.append(chunk)
......
......@@ -117,9 +117,12 @@ class MultiHash:
ret.track_length = track_length
@classmethod
def from_file(cls, file, hash_names=DEFAULT_ALGORITHMS, length=None):
def from_file(cls, fobj, hash_names=DEFAULT_ALGORITHMS, length=None):
ret = cls(length=length, hash_names=hash_names)
for chunk in file:
while True:
chunk = fobj.read(HASH_BLOCK_SIZE)
if not chunk:
break
ret.update(chunk)
return ret
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment