From 8ed8026434603cfbabb4d34b0064bd19da507603 Mon Sep 17 00:00:00 2001 From: Douglas Jacobsen Date: Tue, 29 Oct 2024 20:18:12 -0600 Subject: [PATCH] Update file hashing to read blocks instead of whole file --- lib/ramble/ramble/util/hashing.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ramble/ramble/util/hashing.py b/lib/ramble/ramble/util/hashing.py index 304e94825..7d867acac 100644 --- a/lib/ramble/ramble/util/hashing.py +++ b/lib/ramble/ramble/util/hashing.py @@ -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):