import hashlib def hash_file(path, algorithm="sha256"): """Hash a file by streaming in 64KB chunks. Returns hex digest.""" if algorithm == "blake3": try: import blake3 h = blake3.blake3() except ImportError: raise ImportError("blake3 requested but not installed; pip install blake3") else: h = hashlib.new(algorithm) with open(path, "rb") as f: while chunk := f.read(65536): h.update(chunk) return h.hexdigest()