Add Iterator.StringReader() #359
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
Iterator.StringReader()
to allow consumers to stream a JSON string without copying to unnecessary buffers.I fully expect this PR to probably be at least initially rejected, since I have provided neither a reliable means, nor documentation with sufficiently scary warnings, to avoid letting the consumer fail to read the full string, which in turn obviously ruins the state of the Iterator/Decoder.
However, I do think it's a decent starting point toward letting consumers avoid large buffer use in the case that an interesting and streamable large blob happens to be a JSON string in the bytestream. I do think it's at least in the spirit of this library, or I wouldn't be posting a PR at all.
I do also intend to add proper commentary and docs eventually, but it may take me some time to get to it, so if anybody were interested in taking a stab first, I'd be very grateful to hear that in the rejection message for this request :-)
For now, I'm using this in a personal project, and ensuring that I
io.Reader.Read(...)
through the entire JSON string by being explicit about that, but I thought I'd share this rather than keep it to myself, as it seems to be helpful. Please let me know if an example of how this has proved useful would perhaps lean folks in the direction of including this after all.