Hacker News new | ask | show | jobs
by BugsJustFindMe 1850 days ago
The only reason people care about newlines for a stream is because they've arbitrarily chosen to fetch bytes from the stream until the next newline sequence (readline instead of read). But you could just as easily look for a different sequence, like the ASCII record separator character which was invented exactly for this task, and then you wouldn't have to destructively strip newlines from your input.
2 comments

I'll switch from \n to \x1E when cat, head, text editors, etc. start supporting the latter as a synonym for the former.
We tell our customers our streaming API uses jsonlines for documentation purposes, but we actually just decode in a loop until EOF, and 400 at the first decode error. No separators necessary at all.