Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update file hashing to read blocks instead of whole file #732

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/ramble/ramble/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
import hashlib
import spack.util.spack_json as sjson

BLOCK_SIZE = 1024 * 1024


def hash_file(file_path):
file_hash = None
file_hash = hashlib.sha256()
with open(file_path, "rb") as f:
bytes = f.read()
file_hash = hashlib.sha256(bytes).hexdigest()
return file_hash
while True:
bytes = f.read(BLOCK_SIZE)
if not bytes:
break
file_hash.update(bytes)
return file_hash.hexdigest()


def hash_string(string):
Expand Down