Add: utils func to compute md5 hash of files
This commit is contained in:
parent
7fd888aae2
commit
f783d29202
1 changed files with 22 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue