Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add decodeFromStream for symmetry with encodeToStream #62

Closed
sschuberth opened this issue Oct 18, 2023 · 2 comments
Closed

Please add decodeFromStream for symmetry with encodeToStream #62

sschuberth opened this issue Oct 18, 2023 · 2 comments
Labels
wontfix This will not be worked on

Comments

@sschuberth
Copy link

That would ease reading from files on the JVM a bit 😉

@Peanuuutz
Copy link
Owner

Short answer: Won't fix. Please use inputStream.reader() with decodeFromNativeReader. By the way, we plan to deprecate encodeToStream in favor of encodeToNativeWriter in the next release.

Long answer: Actually that was a thing before, but was abandoned. Note that, the parser is based on character stream, not byte stream, and InputStream is a byte stream. While it is possible to achieve this with inputStream.bufferedReader(), we don't want to break the symmetry with other implementations either, which simply use x.buffered(). We've noticed that the offical Json format does copy InputStreamReader to support Json.decodeFromStream, which is not ideal in respect to no repetition. We don't want to pollute user's disk further with another copy of InputStreamReader when it is easy enough to use decodeFromNativeReader, so we don't plan to support InputStream directly. encodeToStream, on the other hand, just happens to be doable without a lot of paste work, but still hurts performance because it allocates a byte array each time even a single character goes into the file, so we don't recommend it either.

@Peanuuutz Peanuuutz added the wontfix This will not be worked on label Oct 18, 2023
@Peanuuutz Peanuuutz pinned this issue Oct 18, 2023
@sschuberth
Copy link
Author

We've noticed that the offical Json format does copy InputStreamReader to support Json.decodeFromStream

Yeah, that's where I'm coming from, and what I'm used to.

Thanks for the elaborate answer, makes sense now!

@sschuberth sschuberth closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants