aboutsummaryrefslogtreecommitdiff
path: root/src/bytes/reader.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2016-03-31 16:05:23 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2016-04-07 18:58:01 +0000
commite88f89028a55acf9c8b76b7f6ca284c3f9eb4cbd (patch)
treef33797b9e2ff352667f489fa04e04fad7f2b0d05 /src/bytes/reader.go
parente6f36f0cd5b45b9ce7809a34c45aeb66a5ca64a4 (diff)
downloadgo-e88f89028a55acf9c8b76b7f6ca284c3f9eb4cbd.tar.xz
bytes, string: add Reset method to Reader
Currently, there is no easy allocation-free way to turn a []byte or string into an io.Reader. Thus, we add a Reset method to bytes.Reader and strings.Reader to allow the reuse of these Readers with another []byte or string. This is consistent with the fact that many standard library io.Readers already support a Reset method of some type: bufio.Reader flate.Reader gzip.Reader zlib.Reader debug/dwarf.LineReader bytes.Buffer crypto/rc4.Cipher Fixes #15033 Change-Id: I456fd1af77af6ef0b4ac6228b058ac1458ff3d19 Reviewed-on: https://go-review.googlesource.com/21386 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/bytes/reader.go')
-rw-r--r--src/bytes/reader.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/bytes/reader.go b/src/bytes/reader.go
index 5941ebdab4..7aa30578b3 100644
--- a/src/bytes/reader.go
+++ b/src/bytes/reader.go
@@ -146,5 +146,8 @@ func (r *Reader) WriteTo(w io.Writer) (n int64, err error) {
return
}
+// Reset resets the Reader to be reading from b.
+func (r *Reader) Reset(b []byte) { *r = Reader{b, 0, -1} }
+
// NewReader returns a new Reader reading from b.
func NewReader(b []byte) *Reader { return &Reader{b, 0, -1} }