import sys
from pathlib import Path
from blake3 import blake3
def dirhash(path: Path) -> bytes:
if not path.is_dir():
return blake3(path.read_bytes()).digest()
hasher = blake3(derive_key_context="directory")
for child in sorted(path.iterdir(), key=lambda child: child.name):
hasher.update(child.name.encode("utf8"))
hasher.update(b"\xff")
hasher.update(dirhash(child)) return hasher.digest()
def main() -> None:
for arg in sys.argv[1:]:
print(f"{dirhash(Path(arg)).hex()} {arg}")
if __name__ == "__main__":
main()