Download examples/read_records.py from jh2525/StreamStop: direct link, hf CLI and curl.
- Browser
- Download file 703 Bytes
-
https://huggingface.co/datasets/jh2525/StreamStop/resolve/main/examples/read_records.py
- Command line
-
hf download hf://datasets/jh2525/StreamStop/examples/read_records.py
-
curl -L -o read_records.py https://huggingface.co/datasets/jh2525/StreamStop/resolve/main/examples/read_records.py
703 Bytes
| """Read compressed StreamStop JSONL records without extracting the full collection.""" | |
| from pathlib import Path | |
| import argparse | |
| import gzip | |
| import json | |
| import lzma | |
| def iter_records(path): | |
| path = Path(path) | |
| opener = lzma.open if path.suffix == ".xz" else gzip.open | |
| with opener(path, "rt", encoding="utf-8") as stream: | |
| for line in stream: | |
| if line.strip(): | |
| yield json.loads(line) | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("path", type=Path) | |
| args = parser.parse_args() | |
| row = next(iter_records(args.path)) | |
| print("Record fields:", ", ".join(sorted(row))) | |