Skip to content

Commit

Permalink
bufio: clarify io.EOF behavior of Reader.Read
Browse files Browse the repository at this point in the history
Fixes #52577

Change-Id: Idaff2604979f9a9c1c7d3140c8a5d218fcd27a56
Reviewed-on: https://go-review.googlesource.com/c/go/+/403594
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
  • Loading branch information
ianlancetaylor authored and gopherbot committed May 2, 2022
1 parent a887579 commit 99f1bf5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/bufio/bufio.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ func (b *Reader) Discard(n int) (discarded int, err error) {
// The bytes are taken from at most one Read on the underlying Reader,
// hence n may be less than len(p).
// To read exactly len(p) bytes, use io.ReadFull(b, p).
// At EOF, the count will be zero and err will be io.EOF.
// If the underlying Reader can return a non-zero count with io.EOF,

This comment has been minimized.

Copy link
@fadyanwar

fadyanwar Jul 30, 2022

Isn't this a bit confusing? How can the reader have both EOF and non-zero count in the same time?

This comment has been minimized.

Copy link
@ianlancetaylor

ianlancetaylor Jul 30, 2022

Author Member

We use Gerritt for code review. GitHub is a mirror, and very few people see comments on GitHub commits. If you want to comment on this change, please comment on https://go.dev/cl/403594 or https://go.dev/issue/52577. Thanks.

A non-zero count with EOF means that it read that many bytes, and that those bytes are the last bytes in the input.

// then this Read method can do so as well; see the [io.Reader] docs.
func (b *Reader) Read(p []byte) (n int, err error) {
n = len(p)
if n == 0 {
Expand Down

0 comments on commit 99f1bf5

Please sign in to comment.