Add: utils func to compute md5 hash of files

This commit is contained in:
Aroy-Art 2025-02-25 11:07:25 +01:00
parent 7fd888aae2
commit f783d29202
Signed by: Aroy
GPG key ID: 583642324A1D2070

View file

@ -1,3 +1,4 @@
import hashlib
from blake3 import blake3
from blurhash import encode
@ -51,6 +52,27 @@ def compute_string_hash_blake3(string, logger=None):
return compute_blake3_hash(string, is_file=False, logger=logger)
def compute_md5_hash(file_path):
"""
Compute the MD5 hash of a file.
Args:
file_path (str): Path to the file.
Returns:
str: MD5 hash of the file.
"""
try:
hash_md5 = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
except Exception as e:
tqdm.write(f"Error computing MD5 hash: {e}")
return None
def compute_blur_hash(image_path, components_x=4, components_y=4, logger=None):
"""
Compute the BlurHash of an image.