Repository navigation
What's new
Overwrite mode (SetOverwrite(true)) now behaves like a traditional circular buffer for writes that do not fit: the buffer keeps the last Capacity() bytes and the write is reported as fully accepted. A blocking overwrite write no longer waits for a reader, for writes of any size. Nothing else changes.
Breaking changes
-
A non-blocking
Writethat does not fit no longer returnsErrTooMuchDataToWritewithn < len(p), and no longer leaves the head of the write in the buffer. It now returnsn == len(p), err == niland keeps the tail, matching blocking mode (#40).rb := ringbuffer.New(4).SetOverwrite(true) rb.Write([]byte("abcdef")) // before: n=4, ErrTooMuchDataToWrite, buffer "abcd" // now: n=6, nil, buffer "cdef"
Callers that used
nor that error to detect dropped data should checkrb.Length()/rb.Bytes()instead. -
TryWritein overwrite mode keeps the tail too, so it no longer differs fromWrite.
Fixes
- A blocking overwrite
Writelarger than the buffer no longer waits for a reader: no more deadlock when nothing is reading, and no more hang instead of returning (by @bardrop, #39). - An overwrite write larger than the buffer is now trimmed to the bytes that survive before copying, instead of copying the whole write and overwriting it chunk by chunk.
Docs
SetOverwrite,SetBlocking,WriteandErrTooMuchDataToWritedocument the overwrite-mode behaviour, and the README gained an "Overwrite mode" section.
Compatibility
- Non-overwrite mode is untouched:
ErrTooMuchDataToWrite,ErrIsFulland the blocking semantics are unchanged. ReadFromstill waits for a reader when the buffer is full in overwrite mode; unchanged in this release.