Skip to content

Commit

Permalink
io: document that ReadAtLeast and ReadFull can drop errors
Browse files Browse the repository at this point in the history
Add a note that if an error is returned after having read
at least the minimum no. of bytes, the error is set to nil.

Fixes golang#20477

Change-Id: I75ba5ee967be3ff80249e40d459da4afeeb53463
Reviewed-on: https://go-review.googlesource.com/102459
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
agnivade authored and bradfitz committed Mar 26, 2018
1 parent 68a1c9c commit 665af04
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func WriteString(w Writer, s string) (n int, err error) {
// ReadAtLeast returns ErrUnexpectedEOF.
// If min is greater than the length of buf, ReadAtLeast returns ErrShortBuffer.
// On return, n >= min if and only if err == nil.
// If r returns an error having read at least min bytes, the error is dropped.
func ReadAtLeast(r Reader, buf []byte, min int) (n int, err error) {
if len(buf) < min {
return 0, ErrShortBuffer
Expand All @@ -323,6 +324,7 @@ func ReadAtLeast(r Reader, buf []byte, min int) (n int, err error) {
// If an EOF happens after reading some but not all the bytes,
// ReadFull returns ErrUnexpectedEOF.
// On return, n == len(buf) if and only if err == nil.
// If r returns an error having read at least len(buf) bytes, the error is dropped.
func ReadFull(r Reader, buf []byte) (n int, err error) {
return ReadAtLeast(r, buf, len(buf))
}
Expand Down

0 comments on commit 665af04

Please sign in to comment.