diff options
Diffstat (limited to 'src/bytes/buffer.go')
| -rw-r--r-- | src/bytes/buffer.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go index ee83fd8b36..5ab58c78bb 100644 --- a/src/bytes/buffer.go +++ b/src/bytes/buffer.go @@ -53,6 +53,12 @@ const maxInt = int(^uint(0) >> 1) // so immediate changes to the slice will affect the result of future reads. func (b *Buffer) Bytes() []byte { return b.buf[b.off:] } +// AvailableBuffer returns an empty buffer with b.Available() capacity. +// This buffer is intended to be appended to and +// passed to an immediately succeeding Write call. +// The buffer is only valid until the next write operation on b. +func (b *Buffer) AvailableBuffer() []byte { return b.buf[len(b.buf):] } + // String returns the contents of the unread portion of the buffer // as a string. If the Buffer is a nil pointer, it returns "<nil>". // @@ -76,6 +82,9 @@ func (b *Buffer) Len() int { return len(b.buf) - b.off } // total space allocated for the buffer's data. func (b *Buffer) Cap() int { return cap(b.buf) } +// Available returns how many bytes are unused in the buffer. +func (b *Buffer) Available() int { return cap(b.buf) - len(b.buf) } + // Truncate discards all but the first n unread bytes from the buffer // but continues to use the same allocated storage. // It panics if n is negative or greater than the length of the buffer. |
