buffer

package module
v0.0.0-...-696176a Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: ISC Imports: 6 Imported by: 0

README

buffer

This package provides a circular buffer implementation backed by an MMAP'd file. It's purpose is to provide a simple interface for storing arbitrary records backed by a file which can handle failures and is suitable for concurrent access.

Specifically, this is a fork of ashishgandhi's buffer implementation which suits our needs more effectively. Namely, insertions into a full buffer do not overwrite existing records. Instead an error is returned to the caller forcing a decision on how to handle.

At this time, Cloudflare provides no guarantees about the stability of this package. Please use vendoring to maintain this dependency in your project.

Documentation

Overview

package buffer provides an mmap'd circular buffer

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotOpen = errors.New("Not open")
)

Functions

This section is empty.

Types

type Buffer

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

func New

func New(filename string, capacity int) (*Buffer, error)

New creates a new Buffer backed by the file given by filename. it's max capacity is set to the capacity given

func Open

func Open(filename string) (*Buffer, error)

Open will open an existing buffer, if the file does not exist an error is returned

func (*Buffer) Advise

func (b *Buffer) Advise() error

func (*Buffer) Close

func (b *Buffer) Close() (err error)

func (*Buffer) Insert

func (b *Buffer) Insert(data []byte) error

Insert inserts the data into the buffer Inserting data which will overflow the buffer fails Inserting does not overwrite any existing data inside the buffer if it would overwrite data, errOverwrite is returned

func (*Buffer) Peek

func (b *Buffer) Peek() ([]byte, error)

Peek reads the first record and returns it without removing it from the buffer.

func (*Buffer) Pop

func (b *Buffer) Pop() ([]byte, error)

Pop removes and returns the first record in the buffer

func (*Buffer) Size

func (b *Buffer) Size() int

func (*Buffer) Sync

func (b *Buffer) Sync() (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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