Just like io.ReadFull, encoding/binary.Read will return io.EOF if the given reader returns EOF before any bytes are read, but will return io.ErrUnexpectedEOF if some (but not all) of the bytes are read before encountering EOF (binary.Read just calls io.ReadFull under the hood). IMO, this behavior should be documented so that a) callers know about it and, b) callers can rely on the behavior not changing in the future (whereas, currently, a change in this behavior wouldn't break the documented API).
This concern was originally raised here on golang-nuts.
Version: 1.4.2
OS/Arch: linux/amd64
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
encoding/binary.Read should document use of io.EOF vs io.ErrUnexpectedEOF
encoding/binary: Read should document use of io.EOF vs io.ErrUnexpectedEOF
Aug 4, 2015
Just like io.ReadFull, encoding/binary.Read will return io.EOF if the given reader returns EOF before any bytes are read, but will return io.ErrUnexpectedEOF if some (but not all) of the bytes are read before encountering EOF (binary.Read just calls io.ReadFull under the hood). IMO, this behavior should be documented so that a) callers know about it and, b) callers can rely on the behavior not changing in the future (whereas, currently, a change in this behavior wouldn't break the documented API).
This concern was originally raised here on golang-nuts.
The text was updated successfully, but these errors were encountered: