From 891682c8250e53e62d5ffe027d5ab63d21f6cd5c Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 29 Oct 2018 13:49:32 -0400 Subject: [PATCH] bufio: suggest io.ReadFull at (*Reader).Read Many times when using bufio.Reader I imagine, incorrectly, that it implements the retry loop itself, being a high-level buffered wrapper around, say, a file descriptor prone to short reads. This comment would have saved me much time. Change-Id: I34c790e0d7c1515430a76d02ce4739b586a36ba7 Reviewed-on: https://go-review.googlesource.com/c/145577 Reviewed-by: Ian Lance Taylor Reviewed-by: Rob Pike --- src/bufio/bufio.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bufio/bufio.go b/src/bufio/bufio.go index 8d162b34a0..e498dfea1e 100644 --- a/src/bufio/bufio.go +++ b/src/bufio/bufio.go @@ -187,6 +187,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). // At EOF, the count will be zero and err will be io.EOF. +// +// To read exactly len(p) bytes, use io.ReadFull(b, p). func (b *Reader) Read(p []byte) (n int, err error) { n = len(p) if n == 0 { -- 2.50.0