]> Cypherpunks repositories - gostls13.git/commit
bufio: add Reader.Discard
authorBrad Fitzpatrick <bradfitz@golang.org>
Fri, 2 Jan 2015 18:02:15 +0000 (10:02 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 7 Jan 2015 06:37:57 +0000 (06:37 +0000)
commitee2ecc4552d8fd2b29be29aed1fe81dca0df60f9
tree1300cd6fabb2c8a89ef8ad554e40e567d8a3835e
parent5f179c7cef24c74627632ca1b9df8d5ea3912ace
bufio: add Reader.Discard

Reader.Discard is the complement to Peek. It discards the next n bytes
of input.

We already have Reader.Buffered to see how many bytes of data are
sitting available in memory, and Reader.Peek to get that that buffer
directly. But once you're done with the Peek'd data, you can't get rid
of it, other than Reading it.
Both Read and io.CopyN(ioutil.Discard, bufReader, N) are relatively
slow. People instead resort to multiple blind ReadByte calls, just to
advance the internal b.r variable.

I've wanted this previously, several people have asked for it in the
past on golang-nuts/dev, and somebody just asked me for it again in a
private email. There are a few places in the standard library we'd use
it too.

Change-Id: I85dfad47704a58bd42f6867adbc9e4e1792bc3b0
Reviewed-on: https://go-review.googlesource.com/2260
Reviewed-by: Russ Cox <rsc@golang.org>
src/bufio/bufio.go
src/bufio/bufio_test.go
src/net/http/transfer.go