Documentation
¶
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.WriterSeeker.
func New ¶
func New(w io.Writer) BufferedWriter
New is shorthand for NewSize(w, 4096), a 4KB Buffer.
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 a buffered 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 ¶
type WriteSeeker struct {
// contains filtered or unexported fields
}
func (*WriteSeeker) Flush ¶
func (w *WriteSeeker) Flush() error
Click to show internal directories.
Click to hide internal directories.