Skip to content

balena-os/circbuf

 
 

Repository files navigation

circbuf

About this fork: This is a fork from https://github.com/armon/circbuf including the following performance optimizations:

  • Add methods to efficiently read and write a single byte at a time.
  • Avoid allocating memory on Bytes() (at the expense of having a second, pre-allocated buffer)
  • Add a faster code path for buffers whose size is a power-of-two.

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!")
}

About

Golang circular (ring) buffer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%