aboutsummaryrefslogtreecommitdiff
path: root/src/lib/io/bytebuffer.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-05-18 13:31:56 -0700
committerRuss Cox <rsc@golang.org>2009-05-18 13:31:56 -0700
commitbe869ba4d66ad7028ea84ee380072a23ec54c469 (patch)
tree488ca34092c88b7b28ad44f1cc49493fc5c9842a /src/lib/io/bytebuffer.go
parent6b942c68cc5f25ee6b3fe113fe9707a23a974aaa (diff)
downloadgo-be869ba4d66ad7028ea84ee380072a23ec54c469.tar.xz
add io.ByteReader.
add testing/iotest package. make bufio return error on short write. R=r DELTA=423 (208 added, 154 deleted, 61 changed) OCL=28997 CL=28999
Diffstat (limited to 'src/lib/io/bytebuffer.go')
-rw-r--r--src/lib/io/bytebuffer.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/lib/io/bytebuffer.go b/src/lib/io/bytebuffer.go
index c862818fd7..921ddb17ae 100644
--- a/src/lib/io/bytebuffer.go
+++ b/src/lib/io/bytebuffer.go
@@ -42,13 +42,17 @@ func (b *ByteBuffer) Len() int {
// Truncate discards all but the first n unread bytes from the buffer.
// It is an error to call b.Truncate(n) with n > b.Len().
func (b *ByteBuffer) Truncate(n int) {
+ if n == 0 {
+ // Reuse buffer space.
+ b.off = 0;
+ }
b.buf = b.buf[0 : b.off + n];
}
// Reset resets the buffer so it has no content.
// b.Reset() is the same as b.Truncate(0).
func (b *ByteBuffer) Reset() {
- b.buf = b.buf[0 : b.off];
+ b.Truncate(0);
}
// Write appends the contents of p to the buffer. The return