bufferedwriter

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

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

func (*WriteSeeker) Seek

func (w *WriteSeeker) Seek(offset int64, whence int) (n int64, err error)

func (*WriteSeeker) Write

func (w *WriteSeeker) Write(p []byte) (n int, err error)

type WriterAt

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

func (*WriterAt) Flush

func (w *WriterAt) Flush() error

func (*WriterAt) Write

func (w *WriterAt) Write(p []byte) (n int, err error)

func (*WriterAt) WriteAt

func (w *WriterAt) WriteAt(p []byte, offset int64) (n int, err error)

Jump to

Keyboard shortcuts

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