Spaces:
Sleeping
Sleeping
Download src/uploader/hash_utils.py from jrrribeiro/BirdNET-Uploader-App: direct link, hf CLI and curl.
- Browser
- Download file 698 Bytes
-
https://huggingface.co/spaces/jrrribeiro/BirdNET-Uploader-App/resolve/main/src/uploader/hash_utils.py
- Command line
-
hf download hf://spaces/jrrribeiro/BirdNET-Uploader-App/src/uploader/hash_utils.py
-
curl -L -o hash_utils.py https://huggingface.co/spaces/jrrribeiro/BirdNET-Uploader-App/resolve/main/src/uploader/hash_utils.py
698 Bytes
| from __future__ import annotations | |
| import hashlib | |
| from pathlib import Path | |
| def compute_file_hash(path: str | Path, *, chunk_size: int = 1024 * 1024) -> str: | |
| """Compute a streaming SHA-256 hash for a file.""" | |
| digest = hashlib.sha256() | |
| file_path = Path(path) | |
| with file_path.open("rb") as handle: | |
| for chunk in iter(lambda: handle.read(chunk_size), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def verify_file_integrity(path: str | Path, expected_hash: str, *, chunk_size: int = 1024 * 1024) -> bool: | |
| """Return True when a file's SHA-256 matches the expected hash.""" | |
| return compute_file_hash(path, chunk_size=chunk_size) == expected_hash | |