globocom / globocom/go-buffer

Request support for Byte size-based flushing

Open
#10 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
28
Forks
8
PR merge metrics
No merged PRs in 30d

Description

### Feature Request

**Description:**

I would like to request support for byte size-based flushing in the `buffer` package. Currently, the package supports flushing based on a timeout or when the buffer is full based on the number of items. However, there are use cases where it's essential to flush the buffer when it reaches a certain byte size limit.

**Use Case:**

Imagine a scenario where we're buffering log entries to be written to the buffer and sent to a remote server. It's important to flush the buffer when it reaches a certain size to avoid memory overflows or to ensure that log entries are sent in manageable chunks.

**Proposed Solution:**

I suggest adding a new configuration option to the `Options` struct to specify a byte size limit. When this limit is reached, the buffer should automatically trigger a flush. Users should be able to set this byte size limit when creating a new `Buffer` instance.

**Example:**

```go
// Create a new buffer with byte size-based flushing.
buffer := buffer.New(buffer.WithByteSizeLimit(1024)) // Flush when the buffer reaches 1 KB.

// Push data into the buffer.
buffer.Push([]byte("Some log entry"))

// The buffer will automatically flush when it reaches 1 KB in size.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.