bufferfile

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2025 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package bufferfile provides a FIFO implementation backed by a temporary file that supports concurrent reads and writes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FIFO

type FIFO struct {
	// contains filtered or unexported fields
}

FIFO is an io.ReadWriteCloser implementation that supports concurrent reads and writes to a temporary file. Reads begin from the start of the file and writes always append to the end. The type maintains separate read and write positions internally.

func NewFIFO

func NewFIFO() (*FIFO, error)

NewFIFO creates a new FIFO backed by a temporary file. The caller is responsible for calling Close() to clean up the temporary file.

func NewFIFOInDir

func NewFIFOInDir(dir string) (*FIFO, error)

NewFIFOInDir creates a new FIFO backed by a temporary file in the provided directory. If dir is empty, the system temporary directory is used. The caller is responsible for calling Close() to clean up the temporary file.

func (*FIFO) Close

func (f *FIFO) Close() error

Close closes the FIFO and removes the temporary file. Any blocked Read or Write operations will be interrupted. Close is safe to call multiple times.

func (*FIFO) CloseWrite

func (f *FIFO) CloseWrite()

CloseWrite signals that no more writes will happen. Readers can still read remaining data, and will receive EOF when all data is consumed. Does not clean up resources - use Close() for that.

func (*FIFO) Read

func (f *FIFO) Read(p []byte) (int, error)

Read implements io.Reader. Reads from the current read position in the file. Read blocks until data is available or the FIFO is closed. Read is safe for concurrent use with Write.

func (*FIFO) Write

func (f *FIFO) Write(p []byte) (int, error)

Write implements io.Writer. Writes always append to the end of the file. Write is safe for concurrent use with Read.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL