Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSizeExceeded is returned when a write would exceed the 100MB limit. ErrSizeExceeded = errors.New("maximum buffer size exceeded") // ErrWriteAfterRead is returned when attempting to write after reading has started. ErrWriteAfterRead = errors.New("cannot write after read has started") )
var ErrBufferFull = errors.New("buffer is full")
ErrBufferFull is returned when the RAM chunk cannot accept more data.
Functions ¶
This section is empty.
Types ¶
type SmartBuffer ¶
type SmartBuffer struct {
// contains filtered or unexported fields
}
SmartBuffer stores data in RAM up to 5MB, then automatically overflows to a temporary file on disk. It enforces a 100MB maximum size limit and supports streaming via io.Reader. The buffer transitions from write mode to read mode on the first Read() call. After reading starts, writes are no longer allowed.
func (*SmartBuffer) Close ¶
func (b *SmartBuffer) Close() error
Close cleans up resources by closing and removing the temporary file if one was created.
func (*SmartBuffer) Read ¶
func (b *SmartBuffer) Read(p []byte) (n int, err error)
Read implements io.Reader. On the first call, it finalizes the buffer by flushing any remaining RAM data to the file (if file exists) and seeks to the beginning. Subsequent calls stream data from either RAM (if < 5MB total) or the temp file. Returns io.EOF when all data has been read.
func (*SmartBuffer) Size ¶
func (b *SmartBuffer) Size() int64
Size returns the total number of bytes written to the buffer.
func (*SmartBuffer) Write ¶
func (b *SmartBuffer) Write(data []byte) (int, error)
Write implements io.Writer. It buffers data in RAM up to 5MB, then automatically flushes to a temporary file. Returns ErrSizeExceeded if the total size would exceed 100MB. Returns ErrWriteAfterRead if called after reading has started.