import "github.com/kisom/sbuf"
NB: the canonical version of this is contained in the goutils repository.
Package sbuf implements a byte buffer that can be wiped. The
underlying byte slice is wiped on read before being declaimed, and
when the buffer is closed, its storage is zeroised. It is meant to be
a drop-in replacement
for bytes.Buffer
.
- type Buffer
- func NewBuffer(n int) *Buffer
- func NewBufferFrom(p []byte) *Buffer
- func (buf *Buffer) Bytes() []byte
- func (buf *Buffer) Cap() int
- func (buf *Buffer) Close()
- func (buf *Buffer) Len() int
- func (buf *Buffer) Read(p []byte) (int, error)
- func (buf *Buffer) ReadByte() (byte, error)
- func (buf *Buffer) Write(p []byte) (int, error)
- func (buf *Buffer) WriteByte(c byte) error
type Buffer struct {
// contains filtered or unexported fields
}
A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use.
func NewBuffer(n int) *Buffer
NewBuffer creates a new buffer with the specified capacity.
func NewBufferFrom(p []byte) *Buffer
NewBufferFrom creates a new buffer from the byte slice passed in. The original data will be wiped.
func (buf *Buffer) Bytes() []byte
Bytes returns the bytes currently in the buffer, and closes itself.
func (buf *Buffer) Cap() int
Cap returns the capacity of the buffer.
func (buf *Buffer) Close()
Close destroys and zeroises the buffer. The buffer will be re-opened on the next write.
func (buf *Buffer) Len() int
Len returns the length of the buffer.
func (buf *Buffer) Read(p []byte) (int, error)
Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
func (buf *Buffer) ReadByte() (byte, error)
ReadByte reads the next byte from the buffer. If the buffer has no data to return, err is io.EOF; otherwise it is nil.
func (buf *Buffer) Write(p []byte) (int, error)
Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil.
func (buf *Buffer) WriteByte(c byte) error
WriteByte adds the byte c to the buffer, growing the buffer as needed.
Generated by godoc2md