case-insensitive hash compare
Linter / ruff (push) Has been cancelled
Linter / eslint (push) Has been cancelled
Tests / tests on CPU with empty model (push) Has been cancelled

This commit is contained in:
w-e-w
2024-10-18 06:20:49 +09:00
parent 96cf0ce564
commit 13cb130930
+7 -5
View File
@@ -281,8 +281,10 @@ def load_file_from_url(
def compare_sha256(file_path: str, hash_prefix: str) -> bool:
"""Check if the SHA256 hash of the file matches the given prefix."""
import hashlib
sha256 = hashlib.sha256()
with open(file_path, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b''):
sha256.update(chunk)
return sha256.hexdigest().startswith(hash_prefix)
hash_sha256 = hashlib.sha256()
blksize = 1024 * 1024
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(blksize), b""):
hash_sha256.update(chunk)
return hash_sha256.hexdigest().startswith(hash_prefix.strip().lower())