mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Remove manual memory management in hashlib_hasher in favor of using Python's built-in buffering
This commit is contained in:
parent
e1c16c33a4
commit
119d26e102
@ -163,13 +163,11 @@ class ModelHash:
|
||||
"""
|
||||
|
||||
def hashlib_hasher(file_path: Path) -> str:
|
||||
"""Hashes a file using a hashlib algorithm. Uses `memoryview` to avoid reading the entire file into memory."""
|
||||
"""Hashes a file using a hashlib algorithm."""
|
||||
hasher = hashlib.new(algorithm)
|
||||
buffer = bytearray(128 * 1024)
|
||||
mv = memoryview(buffer)
|
||||
with open(file_path, "rb", buffering=0) as f:
|
||||
while n := f.readinto(mv):
|
||||
hasher.update(mv[:n])
|
||||
with open(file_path, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(128 * 1024), b""):
|
||||
hasher.update(chunk)
|
||||
return hasher.hexdigest()
|
||||
|
||||
return hashlib_hasher
|
||||
|
Loading…
Reference in New Issue
Block a user