StreamStop / examples /read_records.py
jh2525's picture
Upload examples/read_records.py
52a5af7 verified
Raw History Blame Contribute Delete
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)))