diff options
author | Scott Schwartz <scotts@golang.org> | 2009-06-19 16:29:30 -0700 |
---|---|---|
committer | Scott Schwartz <scotts@golang.org> | 2009-06-19 16:29:30 -0700 |
commit | 0ddac0c5ded6e6f018d8d2f253e9b2e9406b0596 (patch) | |
tree | 771c7776356289df00a53726ff1a2974fdd1fc15 /src/pkg/io/bytebuffer.go | |
parent | 9e2437e53f1c28550d51d34e323642074a730d12 (diff) | |
download | golang-0ddac0c5ded6e6f018d8d2f253e9b2e9406b0596.tar.gz |
Add ReadByte to bytebuffer
R=rsc
APPROVED=rsc
DELTA=24 (24 added, 0 deleted, 0 changed)
OCL=30459
CL=30540
Diffstat (limited to 'src/pkg/io/bytebuffer.go')
-rw-r--r-- | src/pkg/io/bytebuffer.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/pkg/io/bytebuffer.go b/src/pkg/io/bytebuffer.go index 921ddb17a..000c05352 100644 --- a/src/pkg/io/bytebuffer.go +++ b/src/pkg/io/bytebuffer.go @@ -102,6 +102,17 @@ func (b *ByteBuffer) Read(p []byte) (n int, err os.Error) { return n, nil } +// ReadByte reads and returns the next byte from the buffer. +// If no byte is available, it returns error ErrEOF. +func (b *ByteBuffer) ReadByte() (c byte, err os.Error) { + if b.off >= len(b.buf) { + return 0, ErrEOF; + } + c = b.buf[b.off]; + b.off++; + return c, nil; +} + // NewByteBufferFromArray creates and initializes a new ByteBuffer // with buf as its initial contents. func NewByteBufferFromArray(buf []byte) *ByteBuffer { |