iostuff

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: BSD-3-Clause Imports: 5 Imported by: 1

README

A collection of I/O utilities for Go

GoDoc

Installation

Run go get resenje.org/iostuff from command line.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNopWriteCloser added in v0.1.3

func NewNopWriteCloser(w io.Writer) io.WriteCloser

Types

type LineWriter

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

LineWriter ensures that only whole lines are sent to encapsulated io.Writer. It is useful to simplify writers that work with whole lines, like log lines or textual data processing.

func NewLineWriter

func NewLineWriter(w io.Writer) *LineWriter

NewLineWriter wraps io.Writer and sends to its Write method only full lines. To flush the possible remaining bytes in buffer, make sure to call the Close method as soon as the writing is done.

func (*LineWriter) Close

func (w *LineWriter) Close() error

Close flushes the buffer and closes the encapsulated writer if it satisfies io.Closer interface.

func (*LineWriter) Flush added in v0.1.2

func (w *LineWriter) Flush() error

Flush writes any remaining data as a single line.

func (*LineWriter) Write

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

Write sends to the encapsulated Writer line by line and the remaining bytes keeps in buffer.

type NopWriteCloser added in v0.1.3

type NopWriteCloser struct {
	io.Writer
}

func (NopWriteCloser) Close added in v0.1.3

func (NopWriteCloser) Close() error

type PrefixWriter

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

PrefixWriter appends a fixed prefix to each line that is written to encapsulated io.Writer.

func NewPrefixWriter

func NewPrefixWriter(prefix string, w io.Writer) *PrefixWriter

NewPrefixWriter creates a new PrefixWriter.

func (*PrefixWriter) Write

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

type ReplaceableWriter added in v0.1.3

type ReplaceableWriter[F comparable] struct {
	// contains filtered or unexported fields
}

func NewReplaceableWriter added in v0.1.3

func NewReplaceableWriter[F comparable](constructor func(flag F) (io.Writer, F, error)) *ReplaceableWriter[F]

func (*ReplaceableWriter[F]) Close added in v0.1.3

func (w *ReplaceableWriter[F]) Close() error

func (*ReplaceableWriter[F]) Write added in v0.1.3

func (w *ReplaceableWriter[F]) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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