write

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: GPL-3.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyClosed = errors.New("writer already closed")
View Source
var ErrAttemptToWriteOnClosedFile = errors.New("cannot write to a closed or unopened file")

Functions

This section is empty.

Types

type Append

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

func NewAppend

func NewAppend(w io.Writer, fn WriterAppendFunc) *Append

func (*Append) Close

func (a *Append) Close() error

Close will close the destination writer if accessible

func (*Append) Write

func (a *Append) Write(data []byte) (int, error)

type Async

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

func NewAsync

func NewAsync(handler io.Writer, options ...AsyncOption) *Async

NewAsync creates a writer that accumulates Write requests and writes them at a fixed rate (every 250 ms by default)

func (*Async) Close

func (w *Async) Close() error

Close the writer. Any more call to Write will be ignored.

func (*Async) Flush

func (w *Async) Flush() error

func (*Async) Write

func (w *Async) Write(data []byte) (n int, err error)

Write asynchronously to the handler

type AsyncOption

type AsyncOption func(writer *Async)

func WithWriteInterval

func WithWriteInterval(duration time.Duration) AsyncOption

WithWriteInterval sets the interval at which writes happen at least when data is pending

type File

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

func NewFile

func NewFile(filename string, options ...FileOption) (f *File, err error)

func (*File) Close

func (f *File) Close() error

func (*File) Flush

func (f *File) Flush() error

func (*File) Write

func (f *File) Write(data []byte) (n int, err error)

type FileOption

type FileOption func(f *File)

func WithFileFlag

func WithFileFlag(flag int) FileOption

WithFileFlag sets file open flags

func WithFileKeepOpen

func WithFileKeepOpen(keepOpen bool) FileOption

WithFileKeepOpen toggles whether the file is kept open between writes. Defaults to true for all OS except Windows.

func WithFileKeepOpenTimeout

func WithFileKeepOpenTimeout(timeout time.Duration) FileOption

WithFileKeepOpenTimeout will automatically close the file after there was no more write during `timeout`. It defaults to 10ms.

func WithFilePerm

func WithFilePerm(perm os.FileMode) FileOption

WithFilePerm sets file perms to apply when creating the file

func WithFileTruncate

func WithFileTruncate() FileOption

WithFileTruncate enables that existing files are truncated

type WriterAppendFunc

type WriterAppendFunc func(dst []byte, c byte) []byte

WriterAppendFunc is called for every input byte when appending it to the output buffer (is similar to buf = append(buf, byte))

Jump to

Keyboard shortcuts

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