ReMe/reme/utils/files/jsonl_zst.py
jinliyl 54fa3381d7
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
refactor(core): reorganize the ReMe runtime and shared helpers (#769)
* refactor(core): reorganize the ReMe runtime and shared helpers

* test(status): import the base component from its canonical module

* test: remove redundant unit checks

* refactor(core): use canonical runtime imports and shared CLI discovery

Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service.

* fix(cli): honor caller config when service replay is incomplete

Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
2026-11-20 22:06:46 +08:00

38 lines
1.2 KiB
Python

"""Tiny JSONL-over-zstd helpers."""
import io
import os
from collections.abc import Iterable, Iterator
from pathlib import Path
from uuid import uuid4
import zstandard as zstd
def read_jsonl_zst(path: str | Path, encoding: str = "utf-8") -> Iterator[str]:
"""Read JSONL-over-zstd lines from a file."""
path = Path(path)
if not path.exists():
return
with path.open("rb") as raw:
with zstd.ZstdDecompressor().stream_reader(raw) as reader:
text = io.TextIOWrapper(reader, encoding=encoding)
yield from text
def write_jsonl_zst(path: str | Path, lines: Iterable[str], encoding: str = "utf-8") -> Path:
"""Write JSONL-over-zstd lines to a file."""
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
tmp = path.with_name(f".{path.name}.{uuid4().hex}.tmp")
with tmp.open("wb") as raw:
with zstd.ZstdCompressor(level=3).stream_writer(raw) as writer:
text = io.TextIOWrapper(writer, encoding=encoding)
for line in lines:
text.write(line)
if not line.endswith("\n"):
text.write("\n")
text.flush()
text.detach()
os.replace(tmp, path)
return path