Documentation
¶
Overview ¶
Package ring provides an efficient ring buffer for bytes.
Index ¶
- Variables
- type Buffer
- func (b *Buffer) Free() int
- func (b *Buffer) Read(buffer []byte) (int, error)
- func (b *Buffer) ReadByte() (byte, error)
- func (b *Buffer) ReadNFrom(reader io.Reader, n int) (int, error)
- func (b *Buffer) Reset()
- func (b *Buffer) Size() int
- func (b *Buffer) Used() int
- func (b *Buffer) Write(data []byte) (int, error)
- func (b *Buffer) WriteByte(value byte) error
- func (b *Buffer) WriteTo(writer io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBufferFull is the error returned by Buffer if a storage operation // can't be completed due to a lack of space in the buffer. ErrBufferFull = errors.New("buffer full") )
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a fixed-size ring buffer for storing bytes. Its behavior is designed to match that of bytes.Buffer as closely as possible. The zero value for Buffer is a buffer with zero capacity.
func NewBuffer ¶
NewBuffer creates a new ring buffer with the specified size. If size is less than or equal to 0, then a buffer with zero capacity is created.
func (*Buffer) ReadNFrom ¶
ReadNFrom is similar to using io.ReaderFrom.ReadFrom with io.LimitedReader, but it is designed to support a limited-capacity buffer, which can't reliably detect EOF without potentially wasting data from the stream. In particular, Buffer can't reliably detect the case that EOF is reached right as its storage is filled because io.Reader is not required to return io.EOF until the next call, and most implementations (including io.LimitedReader) will only return io.EOF on a subsequent call. Moreover, io.Reader isn't required to return an EOF indication on a zero-length read, so even a follow-up zero-length read can't be used to reliably detect EOF. As such, this method provides a more explicit definition of the number of bytes to read, and it will return io.EOF if encountered, unless it occurs simultaneously with request completion.