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
This commit is contained in:
Russ Cox 2009-05-18 13:31:56 -07:00
parent 6b942c68cc
commit be869ba4d6
7 changed files with 269 additions and 210 deletions

View file

@ -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