aboutsummaryrefslogtreecommitdiff
path: root/src/strings/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/strings/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/strings/reader.go')
-rw-r--r--src/strings/reader.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/strings/reader.go b/src/strings/reader.go
index 248e55245c..737873c099 100644
--- a/src/strings/reader.go
+++ b/src/strings/reader.go
@@ -145,6 +145,9 @@ func (r *Reader) WriteTo(w io.Writer) (n int64, err error) {
return
}
+// Reset resets the Reader to be reading from s.
+func (r *Reader) Reset(s string) { *r = Reader{s, 0, -1} }
+
// NewReader returns a new Reader reading from s.
// It is similar to bytes.NewBufferString but more efficient and read-only.
func NewReader(s string) *Reader { return &Reader{s, 0, -1} }