Files
alexopus-ComfyUI-Image-Saver/utils.py
T

27 lines
789 B
Python

import os
import hashlib
def get_sha256(file_path):
file_no_ext = os.path.splitext(file_path)[0]
hash_file = file_no_ext + ".sha256"
if os.path.exists(hash_file):
try:
with open(hash_file, "r") as f:
return f.read().strip()
except OSError as e:
print(f"comfy-image-saver: Error reading existing hash file: {e}")
sha256_hash = hashlib.sha256()
with open(file_path, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
try:
with open(hash_file, "w") as f:
f.write(sha256_hash.hexdigest())
except OSError as e:
print(f"comfy-image-saver: Error writing hash to {hash_file}: {e}")
return sha256_hash.hexdigest()