Documentation
¶
Overview ¶
Package bufferedwriter provides functionality to wrap an io.Writer while keep maintaining the underlying capability to write at specific bytes such as when it's implementing io.WriterAt or io.WriteSeeker. This package differs from bufio.Writer which encapsulates the writer's implementation details as io.Writer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferedWriter ¶
type BufferedWriter interface { io.Writer // Flush writes any buffered data to the underlying io.Writer. Flush() error }
BufferedWriter is a writter with buffer, it supports io.Writer, io.WriterAt and io.WriteSeeker.
func New ¶
func New(w io.Writer) BufferedWriter
New is shorthand for NewSize(w, 4096), a 4KB Buffer. See NewSize() for details.
func NewSize ¶
func NewSize(w io.Writer, size int) BufferedWriter
NewSize creates a buffered writer with a specified size while taking into account the underlying capabilities of the writer w, which might implement either io.WriterAt or io.WriteSeeker. This allows the buffered writer to maintain the ability to write at a specific byte position.
Use-case scenario:
- An *os.File may be passed to a function receiving an io.Writer, while that function may assert the original ability of the value to write at a specific byte position if possible to enable a faster processing path. Nonetheless, directly working with *os.File for frequent writing small byte segments can affect performance due to numerous syscalls. To alleviate this issue, incorporating a buffered writer for the *os.File becomes essential. Unlike bufio.Writer that encapsulates everything as an io.Writer, this approach preserves the inherent capabilities of io.WriterAt and io.WriteSeeker.
Just like any other buffered writer, the Flush() method should be called after the process is completed to write the unwritten buffered data.
type WriteSeeker ¶
WriteSeeker is an io.WriteSeeker buffer wrapper.