Skip to content

Commit 13cb130

Browse files
committed
case-insensitive hash compare
1 parent 96cf0ce commit 13cb130

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

modules/util.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
281281
def compare_sha256(file_path: str, hash_prefix: str) -> bool:
282282
"""Check if the SHA256 hash of the file matches the given prefix."""
283283
import hashlib
284-
sha256 = hashlib.sha256()
285-
with open(file_path, 'rb') as f:
286-
for chunk in iter(lambda: f.read(4096), b''):
287-
sha256.update(chunk)
288-
return sha256.hexdigest().startswith(hash_prefix)
284+
hash_sha256 = hashlib.sha256()
285+
blksize = 1024 * 1024
286+
287+
with open(file_path, "rb") as f:
288+
for chunk in iter(lambda: f.read(blksize), b""):
289+
hash_sha256.update(chunk)
290+
return hash_sha256.hexdigest().startswith(hash_prefix.strip().lower())

0 commit comments

Comments
 (0)