pio

package
v0.4.69 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: ISC Imports: 8 Imported by: 0

Documentation

Overview

EofReader is an empty reader returning EOF. Thread-safe

LineReader reads a stream one line per Read invocation.

LineReader reads a stream one line per Read invocation.

ReadWriteCloserSlice is a read-writer with a slice as intermediate storage. thread-safe.

TeeWriter is a writer that copies its writes to one or more other writers.

Index

Constants

This section is empty.

Variables

View Source
var EofReader io.Reader = &eofReader{}

EofReader is an empty reader returning EOF. Thread-safe

View Source
var ErrFileAlreadyClosed = errors.New("file alread closed")

On write after close, ErrFileAlreadyClosed is returned.

if errors.Is(err, pio.ErrFileAlreadyClosed)…

Functions

func InitWriteCloserToChan

func InitWriteCloserToChan(wcp *WriteCloserToChan)

func NewReadCloserCallbacker added in v0.4.38

func NewReadCloserCallbacker(closeCallback func(err error) (e error), readCloser io.ReadCloser) (readCloserCallbacker io.ReadCloser)

func NewTeeWriter added in v0.4.38

func NewTeeWriter(closeCallback func() (err error), writers ...io.Writer) (teeWriter io.WriteCloser)

TeeWriter is a writer that copies its writes to one or more other writers.

func NewWriteCloserCallbacker added in v0.4.38

func NewWriteCloserCallbacker(closeCallback func(err error) (e error), writeCloser io.WriteCloser) (writeCloserCallbacker io.WriteCloser)

func NewWriteCloserToChan

func NewWriteCloserToChan() (writeCloser io.WriteCloser)

func NewWriteCloserToChanLine

func NewWriteCloserToChanLine(withNewline ...bool) (writeCloser io.WriteCloser)

func NewWriteCloserToString

func NewWriteCloserToString() io.WriteCloser

NewWriteCloserToString returns an io.WriteCloser that aggregates its oputput in a string. Thread-safe.

Types

type CloserCallbacker added in v0.4.38

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

CloserCallbacker implements a close callback for io.Closer

func (*CloserCallbacker) Close added in v0.4.38

func (cc *CloserCallbacker) Close(closer io.Closer) (err error)

func (*CloserCallbacker) IsClosed added in v0.4.38

func (cc *CloserCallbacker) IsClosed() (isClosed bool)

func (*CloserCallbacker) Wait added in v0.4.38

func (cc *CloserCallbacker) Wait()

type LineReader added in v0.4.38

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

LineReader reads a stream one line per Read invocation.

func NewLineReader added in v0.4.38

func NewLineReader(reader io.Reader) (lineReader *LineReader)

func (*LineReader) Read added in v0.4.38

func (rr *LineReader) Read(p []byte) (n int, err error)

Read returns a byte-sequence ending with newline if size of p is sufficient.

  • if size of p is too short, the text will not end with newline
  • if EOF without newline, text has no newline and err is io.EOF

func (*LineReader) ReadLine added in v0.4.38

func (rr *LineReader) ReadLine(p []byte) (line []byte, isEOF bool, err error)

ReadLine returns full lines, extending p as necessary

  • len(line) is number of bytes
  • max line length 1 MiB
  • line will end with newLine unless 1 MiB or isEOF
  • EOF is returned as isEOF true

type LineWriter added in v0.4.38

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

func NewLineWriter added in v0.4.38

func NewLineWriter(writeCloser io.WriteCloser,
	filter func(line *[]byte, isLastLine bool) (skipLine bool, err error)) (lineWriter *LineWriter)

func (*LineWriter) Close added in v0.4.38

func (wc *LineWriter) Close() (err error)

Close closes

func (*LineWriter) Write added in v0.4.38

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

Write saves data in slice and returns all bytes written or ErrFileAlreadyClosed

type ReadCloserCallbacker added in v0.4.38

type ReadCloserCallbacker struct {
	io.ReadCloser
	CloserCallbacker
}

func (*ReadCloserCallbacker) Close added in v0.4.38

func (cc *ReadCloserCallbacker) Close() (err error)

type ReadWriteCloserSlice

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

ReadWriteCloserSlice is a read-writer with a slice as intermediate storage. thread-safe.

  • Close closes the writer side indicating no further data will be added
  • Write and Close may return error that can be checked: errors.Is(err, pio.ErrFileAlreadyClosed)
  • read will eventually return io.EOF after a Close
  • there are no other errors

func NewReadWriteCloserSlice

func NewReadWriteCloserSlice() (readWriteCloser *ReadWriteCloserSlice)

func (*ReadWriteCloserSlice) Close

func (wc *ReadWriteCloserSlice) Close() (err error)

Close closes thw Write part, may return ErrFileAlreadyClosed

func (*ReadWriteCloserSlice) Read

func (wc *ReadWriteCloserSlice) Read(p []byte) (n int, err error)

Read returns at most len(p) bytes read in n and possibly io.EOF

  • Read is blocking
  • n may be less than len(p)
  • if len(p) > 0, non-error return will have n > 0

func (*ReadWriteCloserSlice) Write

func (wc *ReadWriteCloserSlice) Write(p []byte) (n int, err error)

Write saves data in slice and returns all bytes written or ErrFileAlreadyClosed

type TeeWriter added in v0.4.38

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

TeeWriter is a writer that copies its writes to one or more other writers.

func (*TeeWriter) Close added in v0.4.38

func (tw *TeeWriter) Close() (err error)

func (*TeeWriter) Write added in v0.4.38

func (tw *TeeWriter) Write(p []byte) (n int, err error)

type WriteCloserCallbacker added in v0.4.38

type WriteCloserCallbacker struct {
	io.WriteCloser
	CloserCallbacker
}

func (*WriteCloserCallbacker) Close added in v0.4.38

func (cc *WriteCloserCallbacker) Close() (err error)

type WriteCloserToChan

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

func (*WriteCloserToChan) Ch

func (wc *WriteCloserToChan) Ch() (readCh <-chan []byte)

func (*WriteCloserToChan) Close

func (wc *WriteCloserToChan) Close() (err error)

func (*WriteCloserToChan) Write

func (wc *WriteCloserToChan) Write(p []byte) (n int, err error)

type WriteCloserToChanLine

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

func (*WriteCloserToChanLine) Ch

func (wc *WriteCloserToChanLine) Ch() (readCh <-chan string)

func (*WriteCloserToChanLine) Close

func (wc *WriteCloserToChanLine) Close() (err error)

func (*WriteCloserToChanLine) Write

func (wc *WriteCloserToChanLine) Write(p []byte) (n int, err error)

type WriteCloserToString

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

WriteCloserToString is an io.WriteCloser that aggregates its oputput in a string. Thread-safe.

  • the string is available using the Data method.

func (*WriteCloserToString) Close

func (wc *WriteCloserToString) Close() (err error)

Close should only be invoked once. Close is not required for releasing resources.

func (*WriteCloserToString) Data

func (wc *WriteCloserToString) Data() (s string)

Data returns current string data

func (*WriteCloserToString) Write

func (wc *WriteCloserToString) Write(p []byte) (n int, err error)

Write always succeeds

Jump to

Keyboard shortcuts

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