Commit 891682c8 authored by Alan Donovan's avatar Alan Donovan

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/145577Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: 's avatarRob Pike <r@golang.org>
parent 2e9f0817
...@@ -187,6 +187,8 @@ func (b *Reader) Discard(n int) (discarded int, err error) { ...@@ -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, // The bytes are taken from at most one Read on the underlying Reader,
// hence n may be less than len(p). // hence n may be less than len(p).
// At EOF, the count will be zero and err will be io.EOF. // 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) { func (b *Reader) Read(p []byte) (n int, err error) {
n = len(p) n = len(p)
if n == 0 { if n == 0 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment