Datasets:
Download scripts/verify_checksums.py from Kevynf/llm-graph-poisoning-data: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/datasets/Kevynf/llm-graph-poisoning-data/resolve/main/scripts/verify_checksums.py
- Command line
-
hf download hf://datasets/Kevynf/llm-graph-poisoning-data/scripts/verify_checksums.py
-
curl -L -o verify_checksums.py https://huggingface.co/datasets/Kevynf/llm-graph-poisoning-data/resolve/main/scripts/verify_checksums.py
1.44 kB
| #!/usr/bin/env python3 | |
| """Verify a dataset export against metadata/checksums.sha256.""" | |
| from __future__ import annotations | |
| import argparse | |
| import hashlib | |
| from pathlib import Path | |
| def sha256(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as handle: | |
| for chunk in iter(lambda: handle.read(1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument( | |
| "root", | |
| nargs="?", | |
| type=Path, | |
| default=Path(__file__).resolve().parent.parent, | |
| help="Dataset repository root (default: parent of this script).", | |
| ) | |
| args = parser.parse_args() | |
| root = args.root.resolve() | |
| checksum_file = root / "metadata" / "checksums.sha256" | |
| failures: list[str] = [] | |
| checked = 0 | |
| for line in checksum_file.read_text(encoding="utf-8").splitlines(): | |
| if not line.strip(): | |
| continue | |
| expected, relative = line.split(" ", 1) | |
| path = root / Path(relative) | |
| if not path.is_file(): | |
| failures.append(f"missing: {relative}") | |
| elif sha256(path) != expected: | |
| failures.append(f"checksum mismatch: {relative}") | |
| checked += 1 | |
| if failures: | |
| raise SystemExit("\n".join(failures)) | |
| print(f"Verified {checked} files under {root}") | |
| if __name__ == "__main__": | |
| main() | |