Documentation ¶
Overview ¶
Package pio provides a context-cancelable stream copier, a closable buffer, line-based reader and other io functions
EofReader is an empty reader returning EOF. Thread-safe
ReadWriteCloserSlice is a read-writer with a slice as intermediate storage. thread-safe.
Index ¶
- Variables
- func CopyContext(dst io.Writer, src io.Reader, buf []byte, ctx context.Context) (written int64, err error)
- func CopyThread(label string, reader io.Reader, writer io.Writer, errCh chan<- error, ...)
- func InitWriteCloserToChan(wcp *WriteCloserToChan)
- func NewContextReaderX(ctx context.Context, reader io.Reader) io.Reader
- func NewFastReader(reader io.Reader) (fastReader io.Reader)
- func NewFastWriter(writer io.Writer) (fastWriter io.WriteCloser)
- func NewFileCloseInterceptor(osFile *os.File, label string, closeInterceptor CloseInterceptor) (fileCloser io.ReadWriteCloser)
- func NewNetConnTap(conn net.Conn, readsWriter, writesWriter io.Writer, addError parl.AddError) (socketTap io.ReadWriter)
- func NewPioError(source PIOErrorSource, e error) (err error)
- func NewReadWriterCloseInterceptor(readWriter io.ReadWriter, label string, closeInterceptor CloseInterceptor) (fileCloser io.ReadWriteCloser)
- func NewReadWriterTap(readWriter io.ReadWriter, reads, writes io.Writer, errs func(err error)) (socketTap io.ReadWriter)
- func NewReaderCloseInterceptor(reader io.Reader, label string, closeInterceptor CloseInterceptor) (readCloser io.ReadCloser)
- func NewTLSTap(conn *tls.Conn, readsWriter, writesWriter io.Writer, addError parl.AddError) (socketTap io.ReadWriter)
- func NewTeeWriter(closeInterceptor TeeWriterCloseInterceptor, writers ...io.Writer) (teeWriter io.WriteCloser)
- func NewThreadSafeRwc() (readWriteCloser io.ReadWriteCloser)
- func NewWriteCloserToChan() (writeCloser io.WriteCloser)
- func NewWriteCloserToChanLine(withNewline ...bool) (writeCloser io.WriteCloser)
- func NewWriterCloseInterceptor(writer io.Writer, label string, closeInterceptor CloseInterceptor) (readCloser io.WriteCloser)
- type CloseCallback
- type CloseCallbacker
- type CloseInterceptor
- type CloseWait
- type CloserBuffer
- func (b *CloserBuffer) Close() (err error)
- func (b *CloserBuffer) Read(p []byte) (n int, err error)
- func (b *CloserBuffer) ReadByte() (c byte, err error)
- func (b *CloserBuffer) ReadFrom(r io.Reader) (n int64, err error)
- func (b *CloserBuffer) ReadRune() (r rune, size int, err error)
- func (b *CloserBuffer) Reset()
- func (b *CloserBuffer) UnreadByte() (err error)
- func (b *CloserBuffer) UnreadRune() (err error)
- func (b *CloserBuffer) Write(p []byte) (n int, err error)
- func (b *CloserBuffer) WriteByte(c byte) (err error)
- func (b *CloserBuffer) WriteString(s string) (n int, err error)
- func (b *CloserBuffer) WriteTo(w io.Writer) (n int64, err error)
- type ContextCloser
- type ContextCopier
- type ContextReader
- type ContextReaderX
- type ContextWriter
- type FastReader
- type FastWriter
- type FileCloseInterceptor
- type LineFilterFunc
- type LineFilterWriter
- type LineReader
- type NetConnTap
- type PIOError
- type PIOErrorSource
- type ReadWriteCloserSlice
- type ReadWriterCloseInterceptor
- type ReadWriterTap
- type ReaderCloseInterceptor
- type TLSTap
- type Tap
- type TeeWriter
- type TeeWriterCloseInterceptor
- type ThreadSafeRwc
- type WriteCloserToChan
- type WriteCloserToChanLine
- type WriterCloseInterceptor
Constants ¶
This section is empty.
Variables ¶
var EofReader io.Reader = &eofReader{}
EofReader is an empty reader returning EOF. Thread-safe
var ErrCopyShutdown = errors.New("Copy received Shutdown")
var ErrInvalidWrite = errors.New("invalid write result")
errInvalidWrite means that a write returned an impossible count
- cause is buggy io.Writer implementation
var ( // [NewContextCopier] and [CopyContext]: no buffer provided NoBuffer []byte )
var TeeWriterDoClose = true
[TeeWriterCloseInterceptor.Closer] do regular close on return
var TeeWriterNoClose = false
[TeeWriterCloseInterceptor.Closer] no regular close on return
Functions ¶
func CopyContext ¶ added in v0.4.108
func CopyContext(dst io.Writer, src io.Reader, buf []byte, ctx context.Context) (written int64, err error)
CopyContext is like io.Copy but is cancelable via context
- dst: the writer data is copied to
- src: the reader where data is read
- buf: a buffer that can be used
- buf pio.NoBuffer: no buffer is available
- — if reader implements WriteTo or writer implements ReadFrom, no buffer is required
- — if a buffer is required and missing, 1 MiB is allocated
- ctx: context that when canceled, aborts copying
- — context cancel is detected on any io.File.Read or io.File.Write invocation and carried out by parallel io.File.Close if either reader or writer is closable
- CopyContext closes both reader and writer if their runtime type is closable
- may launch 1 thread while copying
- err may be context.Canceled
func CopyThread ¶ added in v0.4.95
func CopyThread( label string, reader io.Reader, writer io.Writer, errCh chan<- error, ctx context.Context, )
CopyThread copies from an io.Reader to an io.Writer.
- label is used for thread identification on panics
- errCh receives result and makes thread awaitable
- if ctx, a CancelContext, is non-nil and error occurs, ctx is cancelled
- CopyThread itself never fails
func InitWriteCloserToChan ¶
func InitWriteCloserToChan(wcp *WriteCloserToChan)
func NewContextReaderX ¶ added in v0.4.143
NewContextReader instantiates ContextReader
func NewFastReader ¶ added in v0.4.179
NewFastReader returns a unbound-buffered reader draining its provided reader quickly
- because the underlyign reader should be reead even if there are no Read invocations, NewFastReader has a thread fastReaderDrainThread
- FastReader.Read is the only operational method
- — any available data upon Read is immediately returned
- — once the buffer is empty, any error is returned
- — errors are: io.EOF, os.ErrClosed or any error from underlying reader
- — otherwise the Read blocks until data or error
- the thread exits on error:
- — to release resources the underlying reader must be read until error
- — Close of the underlying reader is necessary
- FastReader.Buffer returns a copy of the buffer for testing
- FastReader.Length returns the number of buffered bytes for testing
func NewFastWriter ¶ added in v0.4.179
func NewFastWriter(writer io.Writer) (fastWriter io.WriteCloser)
NewFastWriter returns a unbound-buffered writer providing fast Write
- writer: the writer data is eventually written to
- FastWriter.Write quickly accepts any provided data
- — returns any error from previous Write
- — data is buffered for deferred writer.Write
- FastWriter.Close returns any error from previous Write
- — prevents further Write
- a thread is used to enable Write to return quickly
- thread-safe
func NewFileCloseInterceptor ¶ added in v0.4.184
func NewFileCloseInterceptor(osFile *os.File, label string, closeInterceptor CloseInterceptor) (fileCloser io.ReadWriteCloser)
NewReaderCloseInterceptor…
- readWriter: io.ReadWriter or io.ReadWriteCloser: the reader and writer with altered Close behavior
func NewNetConnTap ¶ added in v0.4.159
func NewNetConnTap(conn net.Conn, readsWriter, writesWriter io.Writer, addError parl.AddError) (socketTap io.ReadWriter)
NewNetConnTap returns a data tap for a bidirectional data stream
- data from readWriter.Read is written to reads.Write if non-nil
- data written to readWriter.Write is written to writes.Write if non-nil
- a non-nil errs receives all errors from delegated Read Write reads and writes
- if errs is nil, an error from the reads and writes taps is panic
- ReadWriterTap impements idempotent Close
- if any of readWriter, reads or writes implements io.Close, they are closed on socketTap.Close
- the consumer may invoke socketTap.Close to ensure reads and writes are closed
- errors in reads or writes do not affect the socketTap consumer
func NewPioError ¶ added in v0.4.159
func NewPioError(source PIOErrorSource, e error) (err error)
func NewReadWriterCloseInterceptor ¶ added in v0.4.179
func NewReadWriterCloseInterceptor(readWriter io.ReadWriter, label string, closeInterceptor CloseInterceptor) (fileCloser io.ReadWriteCloser)
NewReaderCloseInterceptor…
- readWriter: io.ReadWriter or io.ReadWriteCloser: the reader and writer with altered Close behavior
func NewReadWriterTap ¶ added in v0.4.159
func NewReadWriterTap(readWriter io.ReadWriter, reads, writes io.Writer, errs func(err error)) (socketTap io.ReadWriter)
NewReadWriterTap returns a data tap for a bidirectional data stream
- data from readWriter.Read is written to reads.Write if non-nil
- data written to readWriter.Write is written to writes.Write if non-nil
- a non-nil errs receives all errors from delegated Read Write reads and writes
- if errs is nil, an error from the reads and writes taps is panic
- ReadWriterTap impements idempotent Close
- if any of readWriter, reads or writes implements io.Close, they are closed on socketTap.Close
- the consumer may invoke socketTap.Close to ensure reads and writes are closed
- errors in reads or writes do not affect the socketTap consumer
func NewReaderCloseInterceptor ¶ added in v0.4.179
func NewReaderCloseInterceptor(reader io.Reader, label string, closeInterceptor CloseInterceptor) (readCloser io.ReadCloser)
NewReaderCloseInterceptor…
- reader: io.Reader or io.ReadCloser: the reader with altered Close behavior
func NewTLSTap ¶ added in v0.4.159
func NewTLSTap(conn *tls.Conn, readsWriter, writesWriter io.Writer, addError parl.AddError) (socketTap io.ReadWriter)
NewNetConnTap returns a data tap for a bidirectional data stream
- data from readWriter.Read is written to reads.Write if non-nil
- data written to readWriter.Write is written to writes.Write if non-nil
- a non-nil errs receives all errors from delegated Read Write reads and writes
- if errs is nil, an error from the reads and writes taps is panic
- ReadWriterTap impements idempotent Close
- if any of readWriter, reads or writes implements io.Close, they are closed on socketTap.Close
- the consumer may invoke socketTap.Close to ensure reads and writes are closed
- errors in reads or writes do not affect the socketTap consumer
func NewTeeWriter ¶ added in v0.4.38
func NewTeeWriter(closeInterceptor TeeWriterCloseInterceptor, writers ...io.Writer) (teeWriter io.WriteCloser)
TeeWriter returns an io.WriteCloser writer that duplicates its Write invocations to one or more writers. Close behavior is configurable using TeeWriterCloseInterceptor
- closeInterceptor: if present determines custom TeeWriter.Close behavior
- closeInterceptor TeeWriterNoInterceptor: default behavior:
- — any writer implementing io.Closer is closed
- writers: non-empty list of io.Writer that the Write method duplicates writes to. Cannot be empty
- TeeWriter.Write duplicates Write to all writers. Returns fs.ErrClosed if after Close, and transparently the first error from any writer
- TeeWriter.Close closes all writers while honoring closeInterceptor behavior Returns fs.ErrClosed if more than one Close invocation
- TeeWriter is an io.MultiWriter with an optionally custom Close implementation
func NewThreadSafeRwc ¶ added in v0.4.179
func NewThreadSafeRwc() (readWriteCloser io.ReadWriteCloser)
func NewWriteCloserToChan ¶
func NewWriteCloserToChan() (writeCloser io.WriteCloser)
func NewWriteCloserToChanLine ¶
func NewWriteCloserToChanLine(withNewline ...bool) (writeCloser io.WriteCloser)
func NewWriterCloseInterceptor ¶ added in v0.4.179
func NewWriterCloseInterceptor(writer io.Writer, label string, closeInterceptor CloseInterceptor) (readCloser io.WriteCloser)
NewReaderCloseInterceptor…
- writer: io.Writer or io.WriteCloser the writer with altered Close behavior
Types ¶
type CloseCallback ¶ added in v0.4.135
type CloseCallbacker ¶ added in v0.4.135
type CloseCallbacker struct {
// contains filtered or unexported fields
}
CloseCallbacker implements a close callback for io.Closer 231128 unused
func NewCloseCallbacker ¶ added in v0.4.135
func NewCloseCallbacker(closer io.Closer, closeCallback CloseCallback) (closeCallbacker *CloseCallbacker)
func (*CloseCallbacker) Close ¶ added in v0.4.135
func (c *CloseCallbacker) Close() (err error)
func (*CloseCallbacker) IsClosed ¶ added in v0.4.135
func (c *CloseCallbacker) IsClosed() (isClosed bool)
func (*CloseCallbacker) Wait ¶ added in v0.4.135
func (c *CloseCallbacker) Wait()
type CloseInterceptor ¶ added in v0.4.179
type CloseInterceptor interface { // CloseIntercept decides if Close should be invoked on the wrapped type // - closer: the wrapped value as [io.Closer]: nil if Close is not available // - label: name assigned to the wrapped io type // - closeNo: the number for the Close invocation 1… // - err non-nil: ignore doClose and instead return the error // - underlying Close is a noop if the wrapped type does not implement Close // - CloseIntercept is intended to: // - — implement idempotent Close // - — print stack traces for Close invocations // - — prevent Close even if the wrapped object does implement it // - — otherwise modify the behavior of Close // - — CloseIntercept is invoked behind wrapper-specific lock. // Only one invocation per closer is active at any one time CloseIntercept(closer io.Closer, label string, closeNo int) (err error) }
CloseInterceptor is a type executing a Close strategy for certain stream types
- new functions that adds a wrapper to an io value:
- — NewReaderCloseInterceptor wraps an io.Reader or io.ReadCloser
- — NewWriterCloseInterceptor wraps an io.Writer or io.WriteCloser
- — NewReadWriterCloseInterceptor wraps an io.ReadWriter or io.ReadWriteCloser
- — pio.NewCloseWait wraps an io.Closer with a close strategy
- predefined strategies:
- — pio.CloseStackTraces prints a stack trace for each close invocation
- — pio.CloseIdempotent makes close idempotent
- — pio.NoClose prevents any Close invocation
- stream types:
- — io.Closer io.ReadCloser io.WriteCloser io.ReadWriteCloser
- — io.ReadSeekCloser
var ( // CloseStackTraces prints a stack trace for each close invocation // - also makes Close idempotent CloseStackTraces CloseInterceptor = &stackTraceClose{} // CloseIdempotent makes close Idempotent // - only the first Close invocation may receive any error CloseIdempotent CloseInterceptor = &idempotentClose{} // NoClose prevents any Close invocation NoClose CloseInterceptor = &noClose{} )
type CloseWait ¶ added in v0.4.179
type CloseWait struct {
// contains filtered or unexported fields
}
func NewCloseWait ¶ added in v0.4.179
func NewCloseWait(closer any, label string, closeInterceptor CloseInterceptor) (closeWait *CloseWait)
type CloserBuffer ¶ added in v0.4.135
type CloserBuffer struct { // Available() AvailableBuffer() Bytes() Cap() Grow() Len() Next() // Read() ReadByte() ReadBytes() ReadFrom() ReadRune() ReadString() // Reset() String() Truncate() UnreadByte() UnreadRune() // Write() WriteByte() WriteRune() WriteString() WriteTo() bytes.Buffer // contains filtered or unexported fields }
CloserBuffer extends byte.Buffer to be io.Closer
func NewCloserBuffer ¶ added in v0.4.135
func NewCloserBuffer(buffer ...*bytes.Buffer) (closer *CloserBuffer)
NewCloserBuffer returns an bytes.Buffer implementing io.Closer
- if buffer is present, it is copied
- implements:
- io.Closer io.ReadCloser io.WriteCloser io.ReadWriteCloser
- io.ReadWriter
- io.Reader io.WriterTo
- io.Writer io.ReaderFrom
- io.ByteReader io.RuneReader
- io.StringWriter io.ByteWriter
- io.ByteScanner io.RuneScanner
func (*CloserBuffer) Close ¶ added in v0.4.135
func (b *CloserBuffer) Close() (err error)
Close should only be invoked once. Close is not required for releasing resources.
func (*CloserBuffer) Read ¶ added in v0.4.135
func (b *CloserBuffer) Read(p []byte) (n int, err error)
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.
func (*CloserBuffer) ReadByte ¶ added in v0.4.135
func (b *CloserBuffer) ReadByte() (c byte, err error)
ReadByte reads and returns the next byte from the input or any error encountered. If ReadByte returns an error, no input byte was consumed, and the returned byte value is undefined.
func (*CloserBuffer) ReadFrom ¶ added in v0.4.135
func (b *CloserBuffer) ReadFrom(r io.Reader) (n int64, err error)
ReadFrom reads data from r until EOF or error. The return value n is the number of bytes read. Any error except EOF encountered during the read is also returned.
func (*CloserBuffer) ReadRune ¶ added in v0.4.135
func (b *CloserBuffer) ReadRune() (r rune, size int, err error)
ReadRune reads a single encoded Unicode character and returns the rune and its size in bytes. If no character is available, err will be set.
func (*CloserBuffer) Reset ¶ added in v0.4.135
func (b *CloserBuffer) Reset()
Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes.
func (*CloserBuffer) UnreadByte ¶ added in v0.4.135
func (b *CloserBuffer) UnreadByte() (err error)
UnreadByte causes the next call to ReadByte to return the last byte read.
func (*CloserBuffer) UnreadRune ¶ added in v0.4.135
func (b *CloserBuffer) UnreadRune() (err error)
UnreadRune causes the next call to ReadRune to return the last rune read.
func (*CloserBuffer) Write ¶ added in v0.4.135
func (b *CloserBuffer) Write(p []byte) (n int, err error)
Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write must return a non-nil error if it returns n < len(p).
func (*CloserBuffer) WriteByte ¶ added in v0.4.135
func (b *CloserBuffer) WriteByte(c byte) (err error)
WriteByte writes a byte to w.
func (*CloserBuffer) WriteString ¶ added in v0.4.135
func (b *CloserBuffer) WriteString(s string) (n int, err error)
WriteString writes the contents of the string s to w, which accepts a slice of bytes.
func (*CloserBuffer) WriteTo ¶ added in v0.4.135
func (b *CloserBuffer) WriteTo(w io.Writer) (n int64, err error)
WriteTo writes data to w until there's no more data to write or when an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.
type ContextCloser ¶ added in v0.4.108
type ContextCloser struct {
// contains filtered or unexported fields
}
ContextCloser is an idempotent io.Closer
- implements io.Closer
func NewContextCloser ¶ added in v0.4.108
func NewContextCloser(closer io.Closer) (contextCloser *ContextCloser)
NewContextCloser returns a an idempotent io.Closer
- closer may be nil
- panic-free idempotent observable
func (*ContextCloser) Close ¶ added in v0.4.108
func (c *ContextCloser) Close() (err error)
Close closes the io.Closer
- if Close has already been invoked, noop, no error
- if io.Closer is nil, noop, no error
- panic-free idempotent
func (*ContextCloser) IsCloseable ¶ added in v0.4.108
func (c *ContextCloser) IsCloseable() (isCloseable bool)
IsCloseable indicates whether an io.Closer is present that can be closed
type ContextCopier ¶ added in v0.4.108
type ContextCopier struct {
// contains filtered or unexported fields
}
ContextCopier is an io.Copy cancelable via context
func NewContextCopier ¶ added in v0.4.108
func NewContextCopier(buf ...[]byte) (copier *ContextCopier)
NewContextCopier copies src to dst aborting if context is canceled
- buf: a buffer that can be used
- buf pio.NoBuffer: no buffer is available
- — if reader implements WriteTo or writer implements ReadFrom, no buffer is required
- — if a buffer is required and missing, 1 MiB is allocated
- ContextCopier.Copy does copying
- ContextCopier.Shutdown or context cancel aborts Copy in progress
- if the runtime type of reader or writer is io.Closable, a thread is active during copying
func (*ContextCopier) Copy ¶ added in v0.4.134
func (c *ContextCopier) Copy( dst io.Writer, src io.Reader, ctx context.Context, ) (n int64, err error)
Copy copies from src to dst until end of data, error, Shutdown or context cancel
- Shutdown method or context cancel aborts copy in progress
- on context cancel, error returned is context.Canceled
- on Shutdown, error returned has ErrCopyShutdown
- if the runtime type of dst or src is io.Closable, a thread is active during copying
- such reader or writer will be closed
func (*ContextCopier) Shutdown ¶ added in v0.4.134
func (c *ContextCopier) Shutdown()
Shutdown order the thread to exit and wait for its result
- every Copy invocation will have a Shutdown either by consumer or the deferred copyEnd method
type ContextReader ¶ added in v0.4.108
type ContextReader struct { // idempotent pannic-free closer if reader implemented [io.Closer] // - Close() IsClosable() ContextCloser // contains filtered or unexported fields }
ContextReader is an io.ReadCloser that aborts on context cancel
- on context cancel, Read returns error context.Canceled
- If the runtime type of reader implements io.Close, it ContextReader can close it
func NewContextReader ¶ added in v0.4.108
func NewContextReader(reader io.Reader, ctx context.Context) (contextReader *ContextReader)
NewContextReader returns an io.ReadCloser that aborts on context cancel
- on context cancel, Read returns error context.Canceled
- If the runtime type of reader implements io.Close, it can be closed
func (*ContextReader) Read ¶ added in v0.4.108
func (c *ContextReader) Read(p []byte) (n int, err error)
Read is like io.Reader.Read but cancels if the context is canceled
- on context cancel, the error returned is context.Canceled
type ContextReaderX ¶ added in v0.4.143
ContextReader reader terminated by context
type ContextWriter ¶ added in v0.4.108
type ContextWriter struct { // idempotent pannic-free closer if reader implemented [io.Closer] // - Close() IsClosable() ContextCloser // contains filtered or unexported fields }
ContextWriter is an io.WriteCloser that aborts on context cancel
- on context cancel, Write returns error context.Canceled
- If the runtime type of writer implements io.Close, it ContextWriter can close it
func NewContextWriter ¶ added in v0.4.108
func NewContextWriter(writer io.Writer, ctx context.Context) (contextWriter *ContextWriter)
NewContextWriter returns an io.WriteCloser that aborts on context cancel
- on context cancel, Write returns error context.Canceled
- If the runtime type of reader implements io.Close, it can be closed
func (*ContextWriter) Write ¶ added in v0.4.108
func (c *ContextWriter) Write(p []byte) (n int, err error)
Write is like io.Writer.Write but cancels if the context is canceled
- on context cancel, the error returned is context.Canceled
type FastReader ¶ added in v0.4.179
type FastReader struct {
// contains filtered or unexported fields
}
FastReader is an unbound-buffered reader draining a provided reader quickly
func (*FastReader) Buffer ¶ added in v0.4.179
func (r *FastReader) Buffer() (buffer []byte)
Buffer returns a copy of currently buffered data
- thread-safe
func (*FastReader) Length ¶ added in v0.4.179
func (r *FastReader) Length() (length int)
Length returns the number of bytes curently buffered
- thread-safe
type FastWriter ¶ added in v0.4.179
type FastWriter struct {
// contains filtered or unexported fields
}
FastWriter is an unbound-buffered write-closer-reader with fast Write
func (*FastWriter) Buffer ¶ added in v0.4.179
func (w *FastWriter) Buffer() (buffer []byte)
Buffer returns a copy of currently buffered data
- thread-safe
func (*FastWriter) Close ¶ added in v0.4.179
func (w *FastWriter) Close() (err error)
Close prevents any further Write
- err: any previously occuring writer.Write error
- idempotent thread-safe
func (*FastWriter) Length ¶ added in v0.4.179
func (w *FastWriter) Length() (length int)
Length returns the number of bytes curently buffered
- thread-safe
func (*FastWriter) Write ¶ added in v0.4.179
func (w *FastWriter) Write(p []byte) (n int, err error)
Write quickly stores a clone of p in internal buffer
- err == nil: n == len(p), no short writes
- err !- nil:
- — Write after Close returns os.ErrClosed
- — any error from previous Write invocation returned by writer.Write
- because writes are deferred, FastWriter must be closed to determine success
type FileCloseInterceptor ¶ added in v0.4.184
type FileCloseInterceptor struct { // the wrapped File: many methods *os.File // promoted public methods IsClosed() Ch() Close() *CloseWait }
func (*FileCloseInterceptor) Close ¶ added in v0.4.184
func (f *FileCloseInterceptor) Close() (err error)
type LineFilterFunc ¶ added in v0.4.135
LineFilterFunc receives lines as they are written to the writer
- can modify the line
- can skip the line using skipLine
- can return error
type LineFilterWriter ¶ added in v0.4.135
type LineFilterWriter struct {
// contains filtered or unexported fields
}
LineFilterWriter is a writer that filters each line using a filter function
func NewLineFilterWriter ¶ added in v0.4.135
func NewLineFilterWriter(writeCloser io.WriteCloser, filter LineFilterFunc) (lineWriter *LineFilterWriter)
NewLineFilterWriter is a writer that filters each line using a filter function
func (*LineFilterWriter) Close ¶ added in v0.4.135
func (wc *LineFilterWriter) Close() (err error)
Close closes
type LineReader ¶ added in v0.4.38
type LineReader struct {
// contains filtered or unexported fields
}
LineReader reads a io.Reader stream returing one line per Read invocation
- operates on efficient byte
- does not implement io.WriteTo or io.Closer
- alternative to using bufio.Scanner
func NewLineReader ¶ added in v0.4.38
func NewLineReader(reader io.Reader) (lineReader *LineReader)
NewLineReader reads a io.Reader stream returing one line per Read invocation
- operates on efficient byte
- does not implement io.WriteTo or io.Closer
- alternative to using bufio.Scanner
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 NetConnTap ¶ added in v0.4.159
func (*NetConnTap) Close ¶ added in v0.4.159
func (t *NetConnTap) Close() (err error)
type PIOError ¶ added in v0.4.159
type PIOError struct {
// contains filtered or unexported fields
}
ReadError indicates an
func (*PIOError) PIOErrorSource ¶ added in v0.4.159
func (e *PIOError) PIOErrorSource() (source PIOErrorSource)
type PIOErrorSource ¶ added in v0.4.159
type PIOErrorSource uint8
error source for a data tap
const ( // error during delegated Read PeRead PIOErrorSource = iota + 1 // error during delegated Write PeWrite // error during delegated Close PeClose // error from reads [io.Writer] PeReads // error from writes [io.Writer] PeWrites )
func (PIOErrorSource) String ¶ added in v0.4.159
func (s PIOErrorSource) String() (s2 string)
type ReadWriteCloserSlice ¶
type ReadWriteCloserSlice struct {
// contains filtered or unexported fields
}
ReadWriteCloserSlice is a read-writer with slice as intermediate storage. thread-safe.
func NewReadWriteCloserSlice ¶
func NewReadWriteCloserSlice() (readWriteCloser *ReadWriteCloserSlice)
NewReadWriteCloserSlice returns an object that copies from Write to Read and has Close
func (*ReadWriteCloserSlice) Buffer ¶ added in v0.4.95
func (r *ReadWriteCloserSlice) Buffer() (buffer []byte)
func (*ReadWriteCloserSlice) Close ¶
func (r *ReadWriteCloserSlice) Close() (err error)
Close prevents further Writes and causes Read to evetually return io.EOF
- subsequent Close returns ErrFileAlreadyClosed
- check using: errors.Is(err, fs.ErrClosed)
- thread-safe
func (*ReadWriteCloserSlice) Read ¶
func (r *ReadWriteCloserSlice) Read(p []byte) (n int, err error)
Read returns at most len(p) bytes read in n and possibly io.EOF
- Read blocks if no data is available and Close has not occurred
- Read blocks until Write of any data or Close
- Read returns io.EOF once buffer is empty and Close has occurred
- this implementation only returns the error io.EOF
- this implementation returns no data, n == 0, with io.EOF
- n may be less than len(p)
- thread-safe
func (*ReadWriteCloserSlice) Write ¶
func (r *ReadWriteCloserSlice) Write(p []byte) (n int, err error)
Write copies data directly to Reader buffer or to intermediate data slice
- if after Close, returns ErrFileAlreadyClosed
- check using: errors.Is(err, fs.ErrClosed)
- this implementation returns no other errors
- thread-safe
type ReadWriterCloseInterceptor ¶ added in v0.4.179
type ReadWriterCloseInterceptor struct { // the wrapped File: many methods io.ReadWriter // promoted public methods IsClosed() Ch() Close() *CloseWait }
func (*ReadWriterCloseInterceptor) Close ¶ added in v0.4.179
func (f *ReadWriterCloseInterceptor) Close() (err error)
type ReadWriterTap ¶ added in v0.4.159
type ReadWriterTap struct { io.ReadWriter // contains filtered or unexported fields }
func (*ReadWriterTap) Close ¶ added in v0.4.159
func (t *ReadWriterTap) Close() (err error)
type ReaderCloseInterceptor ¶ added in v0.4.179
type Tap ¶ added in v0.4.159
Tap returns a socket tap producing two streams of data read from and written to a socket
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.
type TeeWriterCloseInterceptor ¶ added in v0.4.179
type TeeWriterCloseInterceptor interface {
Closer(teeWriter *TeeWriter, writers []io.Writer) (doRegularClose bool, err error)
}
TeeWriterCloseInterceptor implements a custom Close function for TeeWriter
var TeeWriterNoInterceptor TeeWriterCloseInterceptor
NewTeeWriter closer: there is no closer
type ThreadSafeRwc ¶ added in v0.4.179
type ThreadSafeRwc struct {
// contains filtered or unexported fields
}
func (*ThreadSafeRwc) Close ¶ added in v0.4.179
func (r *ThreadSafeRwc) Close() (err error)
Close: prevents further Write. No errors
- idempotent thread-safe
func (*ThreadSafeRwc) Read ¶ added in v0.4.179
func (r *ThreadSafeRwc) Read(p []byte) (n int, err error)
Read reads bytes until io.EOF
- n: number of bytes read. non-zero if not error
- err: only error is io.EOF. n is 0
- thread-safe
func (*ThreadSafeRwc) Write ¶ added in v0.4.179
func (r *ThreadSafeRwc) Write(p []byte) (n int, err error)
Write saves p to internal buffer
- err non-nil: Close was invoked, errorr is os.ErrClosed
- — n is 0
- err == nil: p was stored in internal buffer, n == len(p)
- — no short Write
- no error other than os.ErrClosed
- thread-safe
type WriteCloserToChan ¶
type WriteCloserToChan struct {
// contains filtered or unexported fields
}
func (*WriteCloserToChan) Ch ¶
func (wc *WriteCloserToChan) Ch() (readCh parl.ClosableAllSource[[]byte])
func (*WriteCloserToChan) Close ¶
func (wc *WriteCloserToChan) Close() (err error)
type WriteCloserToChanLine ¶
type WriteCloserToChanLine struct {
// contains filtered or unexported fields
}
func (*WriteCloserToChanLine) Ch ¶
func (wc *WriteCloserToChanLine) Ch() (readCh parl.ClosableAllSource[string])
func (*WriteCloserToChanLine) Close ¶
func (wc *WriteCloserToChanLine) Close() (err error)
type WriterCloseInterceptor ¶ added in v0.4.179
Source Files ¶
- close-callbacker.go
- close-interceptor.go
- close-wait.go
- closer-buffer.go
- context-closer.go
- context-copier.go
- context-reader-x.go
- context-reader.go
- context-writer.go
- copy-context.go
- copy-thread.go
- eof-reader.go
- fast-reader.go
- fast-writer.go
- line-filter-writer.go
- line-reader.go
- net-conn-tap.go
- os-file-close-interceptor.go
- pio-error.go
- read-write-closer-slice.go
- read-writer-close-interceptor.go
- read-writer-tap.go
- reader-close-interceptor.go
- tap.go
- tee-writer.go
- thread-safe-rwc.go
- tls-tap.go
- write-closer-to-chan-line.go
- write-closer-to-chan.go
- writer-close-interceptor.go