Skip to content

Request support for Byte size-based flushing #10

@valllabh

Description

@valllabh

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:

// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions