buffer

package module
v0.0.0-...-2ceb2ab Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: ISC Imports: 5 Imported by: 1

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

This section is empty.

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 (*Buffer) Advise

func (b *Buffer) Advise() 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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