circbuf

package module
v0.0.0-...-5111143 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2019 License: MIT Imports: 1 Imported by: 844

README

circbuf

This repository provides the circbuf package. This provides a Buffer object which is a circular (or ring) buffer. It has a fixed size, but can be written to infinitely. Only the last size bytes are ever retained. The buffer implements the io.Writer interface.

Documentation

Full documentation can be found on Godoc

Usage

The circbuf package is very easy to use:

buf, _ := NewBuffer(6)
buf.Write([]byte("hello world"))

if string(buf.Bytes()) != " world" {
    panic("should only have last 6 bytes!")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer implements a circular buffer. It is a fixed size, and new writes overwrite older data, such that for a buffer of size N, for any amount of writes, only the last N bytes are retained.

func NewBuffer

func NewBuffer(size int64) (*Buffer, error)

NewBuffer creates a new buffer of a given size. The size must be greater than 0.

func (*Buffer) Bytes

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

Bytes provides a slice of the bytes written. This slice should not be written to.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the buffer so it has no content.

func (*Buffer) Size

func (b *Buffer) Size() int64

Size returns the size of the buffer

func (*Buffer) String

func (b *Buffer) String() string

String returns the contents of the buffer as a string

func (*Buffer) TotalWritten

func (b *Buffer) TotalWritten() int64

TotalWritten provides the total number of bytes written

func (*Buffer) Write

func (b *Buffer) Write(buf []byte) (int, error)

Write writes up to len(buf) bytes to the internal ring, overriding older data if necessary.

Jump to

Keyboard shortcuts

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