ringio

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package ringio implements a ring-buffer that is an io.Reader and an io.Writer with fixed-size semantics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounded

type Bounded struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Bounded is an io.Reader and io.Writer that allows writing as many bytes as are given for the capacity before it has to be drained by reading from it.

It is able to safely read and write in parallel, protected by a Mutex.

func New

func New(cap uint, overwrite bool) *Bounded

New returns a bounded ring buffer of the given capacity. If overwrite is true, a full ring buffer will discard unread bytes and overwrite them upon writes.

If overwrite is false, writing more bytes than there is space in the buffer will fail with ErrFull and no bytes will be written.

func (*Bounded) Bytes

func (b *Bounded) Bytes() []byte

Bytes consumes all readable data on the ring buffer and returns a newly-allocated byte slice containing all readable bytes.

func (*Bounded) Read

func (b *Bounded) Read(p []byte) (n int, err error)

func (*Bounded) Reset

func (b *Bounded) Reset()

Reset throws away all data on the ring buffer.

func (*Bounded) String

func (b *Bounded) String() string

String consumes all readable data on the ring buffer and returns it as a string.

func (*Bounded) Write

func (b *Bounded) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL