jsonxray 0.1.1 — fix reading from a pipe
Fixed
Reading from a pipe profiled nothing at all.
cat data.jsonl | jsonxray - # 0.1.0: "stdin contained no JSON records"…for input that was perfectly good. The README documents zcat events.jsonl.gz | jsonxray -, so this was a documented path that silently did nothing.
Why
Format sniffing reads a chunk to decide between JSONL and a JSON array, then tried to rewind the stream. I had assumed a pipe refuses to seek. It does not — it lies:
| a real pipe answers | |
|---|---|
seekable() |
True |
seek(0) |
succeeds, raises nothing |
tell() |
0 |
the next read() |
"" — the data is gone |
Every indicator says the rewind worked. There is nothing you can ask the stream to detect it, so the fix is to stop asking: the peeked text is now always pushed back in front of the stream rather than rewound. Correct on every input, and it costs one branch per read until the head is consumed.
The part worth repeating
The suite already had four non-seekable-input tests and they all passed, because the test double refused to seek honestly. The double was better behaved than reality, so it covered a failure mode that does not occur and missed the one that does.
0.1.1 adds a second double that lies exactly the way stdin does. With the old implementation restored, three of the new tests fail. 152 tests total.
pip install --upgrade jsonxrayFull documentation: https://github.com/CAOShurong/jsonxray