aboutsummaryrefslogtreecommitdiff
path: root/src/bufio/bufio.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2017-11-01 19:00:05 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2017-11-02 17:17:44 +0000
commit6128ff84f1106af4944f50f74070566e87f2cb35 (patch)
tree19f4190f9b21681e268988d41a475a9eef01904b /src/bufio/bufio.go
parent2da1446bb11cdfaac1f86d7c2134c36487dd2d66 (diff)
downloadgo-6128ff84f1106af4944f50f74070566e87f2cb35.tar.xz
bufio: add Reader.Size and Writer.Size accessors
Fixes #21343 Change-Id: I3582fced902592fe12bfa29acf7b40b6e5e554a7 Reviewed-on: https://go-review.googlesource.com/75150 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/bufio/bufio.go')
-rw-r--r--src/bufio/bufio.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/bufio/bufio.go b/src/bufio/bufio.go
index da94a2503f..ad9c9f5ddf 100644
--- a/src/bufio/bufio.go
+++ b/src/bufio/bufio.go
@@ -62,6 +62,9 @@ func NewReader(rd io.Reader) *Reader {
return NewReaderSize(rd, defaultBufSize)
}
+// Size returns the size of the underlying buffer in bytes.
+func (r *Reader) Size() int { return len(r.buf) }
+
// Reset discards any buffered data, resets all state, and switches
// the buffered reader to read from r.
func (b *Reader) Reset(r io.Reader) {
@@ -548,6 +551,9 @@ func NewWriter(w io.Writer) *Writer {
return NewWriterSize(w, defaultBufSize)
}
+// Size returns the size of the underlying buffer in bytes.
+func (b *Writer) Size() int { return len(b.buf) }
+
// Reset discards any unflushed buffered data, clears any error, and
// resets b to write its output to w.
func (b *Writer) Reset(w io.Writer) {