package sbuf
import "git.wntrmute.dev/kyle/goutils/sbuf"
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.
Index ¶
- 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
Types ¶
type Buffer ¶
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 ¶
NewBuffer creates a new buffer with the specified capacity.
func NewBufferFrom ¶
NewBufferFrom creates a new buffer from the byte slice passed in. The original data will be wiped.
func (*Buffer) Bytes ¶
Bytes returns the bytes currently in the buffer, and closes itself.
func (*Buffer) Cap ¶
Cap returns the capacity of the buffer.
func (*Buffer) Close ¶
func (buf *Buffer) Close()
Close destroys and zeroises the buffer. The buffer will be re-opened on the next write.
func (*Buffer) Len ¶
Len returns the length of the buffer.
func (*Buffer) Read ¶
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 (*Buffer) ReadByte ¶
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 (*Buffer) Write ¶
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 (*Buffer) WriteByte ¶
WriteByte adds the byte c to the buffer, growing the buffer as needed.
Source Files ¶
sbuf.go
- Version
- v1.7.7 (latest)
- Published
- Jun 15, 2024
- Platform
- linux/amd64
- Imports
- 1 packages
- Last checked
- 4 days ago –
Tools for package owners.