Skip to content
Snippets Groups Projects
Commit 0fc6af87 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Add the length to the data returned

Since we compute it anyway, better return it along with the result
parent 97b0d9f8
No related branches found
No related tags found
No related merge requests found
......@@ -125,7 +125,9 @@ def hash_path(path, algorithms=ALGORITHMS, chunk_cb=None):
"""
length = os.path.getsize(path)
with open(path, 'rb') as fobj:
return hash_file(fobj, length, algorithms, chunk_cb)
hash = hash_file(fobj, length, algorithms, chunk_cb)
hash['length'] = length
return hash
def hash_data(data, algorithms=ALGORITHMS):
......
......@@ -207,6 +207,7 @@ class GitHashFromScratch(GitHashWalkArborescenceTree):
os.path.join(self.tmp_root_path, b'sample-folder/empty-folder'): [], # noqa
os.path.join(self.tmp_root_path, b'sample-folder/bar/barfoo'): [{ # noqa
'type': git.GitType.BLOB, # noqa
'length': 72,
'sha256': b'=\xb5\xae\x16\x80U\xbc\xd9:M\x08(]\xc9\x9f\xfe\xe2\x883\x03\xb2?\xac^\xab\x85\x02s\xa8\xeaUF', # noqa
'name': b'another-quote.org', # noqa
'path': os.path.join(self.tmp_root_path, b'sample-folder/bar/barfoo/another-quote.org'), # noqa
......
......@@ -92,6 +92,7 @@ class Hashutil(unittest.TestCase):
f.close()
hashes = hashutil.hash_path(f.name)
self.checksums['length'] = len(self.data)
self.assertEquals(self.checksums, hashes)
@istest
......
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