aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/bytes
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2012-01-21 21:31:21 -0800
committerRobert Griesemer <gri@golang.org>2012-01-21 21:31:21 -0800
commite17afa4d0cc19f4bbac5310fe7b97f3d051c1479 (patch)
treec91635e4a8d49d0087b01b9e4d376dea4a0d0867 /src/pkg/bytes
parentb0d2713b77f80986f688d18bd0df03ed56d6e7b5 (diff)
downloadgo-e17afa4d0cc19f4bbac5310fe7b97f3d051c1479.tar.xz
bytes.Buffer: remove dead code, complete documentation
R=r, dave, r CC=golang-dev https://golang.org/cl/5533086
Diffstat (limited to 'src/pkg/bytes')
-rw-r--r--src/pkg/bytes/buffer.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/pkg/bytes/buffer.go b/src/pkg/bytes/buffer.go
index 08f3f3b665..2c3eb6a596 100644
--- a/src/pkg/bytes/buffer.go
+++ b/src/pkg/bytes/buffer.go
@@ -103,20 +103,16 @@ func (b *Buffer) grow(n int) int {
func (b *Buffer) Write(p []byte) (n int, err error) {
b.lastRead = opInvalid
m := b.grow(len(p))
- if m < 0 {
- return 0, ErrTooLarge
- }
return copy(b.buf[m:], p), nil
}
// WriteString appends the contents of s to the buffer. The return
// value n is the length of s; err is always nil.
+// If the buffer becomes too large, WriteString will panic with
+// ErrTooLarge.
func (b *Buffer) WriteString(s string) (n int, err error) {
b.lastRead = opInvalid
m := b.grow(len(s))
- if m < 0 {
- return 0, ErrTooLarge
- }
return copy(b.buf[m:], s), nil
}
@@ -130,6 +126,8 @@ const MinRead = 512
// The return value n is the number of bytes read.
// Any error except io.EOF encountered during the read
// is also returned.
+// If the buffer becomes too large, ReadFrom will panic with
+// ErrTooLarge.
func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error) {
b.lastRead = opInvalid
// If buffer is empty, reset to recover space.
@@ -198,12 +196,11 @@ func (b *Buffer) WriteTo(w io.Writer) (n int64, err error) {
// WriteByte appends the byte c to the buffer.
// The returned error is always nil, but is included
// to match bufio.Writer's WriteByte.
+// If the buffer becomes too large, WriteByte will panic with
+// ErrTooLarge.
func (b *Buffer) WriteByte(c byte) error {
b.lastRead = opInvalid
m := b.grow(1)
- if m < 0 {
- return ErrTooLarge
- }
b.buf[m] = c
return nil
}
@@ -212,6 +209,8 @@ func (b *Buffer) WriteByte(c byte) error {
// code point r to the buffer, returning its length and
// an error, which is always nil but is included
// to match bufio.Writer's WriteRune.
+// If the buffer becomes too large, WriteRune will panic with
+// ErrTooLarge.
func (b *Buffer) WriteRune(r rune) (n int, err error) {
if r < utf8.RuneSelf {
b.WriteByte(byte(r))