Documentation ¶
Overview ¶
Package circular provides a buffer with circular semantics.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("reader is closed")
ErrClosed is raised on read from closed Reader.
var ErrOutOfSync = errors.New("buffer overrun, read position overwritten")
ErrOutOfSync is raised when reader got too much out of sync with the writer.
var ErrSeekBeforeStart = errors.New("seek before start")
ErrSeekBeforeStart is raised when seek goes beyond start of the file.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer implements circular buffer which supports single writer and multiple readers each with its own offset.
func NewBuffer ¶
func NewBuffer(opts ...OptionFunc) (*Buffer, error)
NewBuffer creates new Buffer with specified options.
func (*Buffer) GetReader ¶
GetReader returns Reader object which implements io.ReadCloser, io.Seeker.
Reader starts at the most distant position in the past available and goes to the current write position.
func (*Buffer) GetStreamingReader ¶
func (buf *Buffer) GetStreamingReader() *StreamingReader
GetStreamingReader returns StreamingReader object which implements io.ReadCloser, io.Seeker.
StreamingReader starts at the most distant position in the past available.
type OptionFunc ¶
OptionFunc allows setting Buffer options.
func WithInitialCapacity ¶
func WithInitialCapacity(cap int) OptionFunc
WithInitialCapacity sets initial buffer capacity.
func WithMaxCapacity ¶
func WithMaxCapacity(cap int) OptionFunc
WithMaxCapacity sets maximum buffer capacity.
func WithSafetyGap ¶
func WithSafetyGap(gap int) OptionFunc
WithSafetyGap sets safety gap between readers and writers to avoid buffer overrun for the reader.
Reader initial position is set to be as far as possible in the buffer history, but next concurrent write might overwrite read position, and safety gap helps to prevent it. With safety gap, maximum available bytes to read are: MaxCapacity-SafetyGap.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader implements seekable reader with local position in the Buffer which reads from the fixed part of the buffer.
Reader is not safe to be used with concurrent Read/Seek operations.
type StreamingReader ¶
type StreamingReader struct {
// contains filtered or unexported fields
}
StreamingReader implements seekable reader with local position in the Buffer.
StreamingReader is not safe to be used with concurrent Read/Seek operations.
StreamingReader blocks for new data once it exhausts contents of the buffer.