json icon indicating copy to clipboard operation
json copied to clipboard

Should `byteReader.extend` account for empty reads?

Open mna opened this issue 1 year ago • 0 comments

Hello,

I'm looking to use something like the byteReader approach for one of my projects, and looking at it a bit more closely, I see that the json package considers a call of byteReader.extend that returns 0 as EOF (see the call in Scanner.Next, for example). The documentation of Scanner.Next mentions that "If the stream is at its end, or an error has occurred, Next returns a zero length []byte slice."

However, it is possible that the underlying io.Reader returns 0, nil as a call to Read, which indicates that no data is available but no error was encountered, in which case a number of retries should probably happen in byteReader.extend? I'm thinking something like what is done in bufio.Reader.fill.

It's possible that I'm missing something and the io.Reader in byteReader is always expected to be of a certain type that guarantees no empty reads (without error) or something like that.

Thanks, Martin

mna avatar Nov 24 '23 15:11 mna