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
diff --git a/src/lib/io/bytebuffer.go b/src/lib/io/bytebuffer.go
index c862818..921ddb1 100644
--- a/src/lib/io/bytebuffer.go
+++ b/src/lib/io/bytebuffer.go
@@ -42,13 +42,17 @@
// 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