Documentation
¶
Overview ¶
Package iohelper contains io package helpers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckWriter ¶ added in v0.2.0
type CheckWriter struct {
// contains filtered or unexported fields
}
CheckWriter is an io.Writer implementation, that checks the underlying io.Writer and slice data by calling the provided 'check' function before each io.Writer.Write call.
func NewCheckWriter ¶ added in v0.2.0
NewCheckWriter creates a new CheckWriter based on 'w' and 'check'. If 'check' returns an error, this error is returned by [Write] method. 'check' may replace the provided io.Writer.
type NilSafeWriter ¶ added in v0.6.0
type NilSafeWriter struct {
// contains filtered or unexported fields
}
NilSafeWriter is an io.Writer implementation, whose Write method does nothing if underlying io.Writer is nil.
func NewNilSafeWriter ¶ added in v0.6.0
func NewNilSafeWriter(w io.Writer) *NilSafeWriter
NewNilSafeWriter creates a new NilSafeWriter based on 'w'.
type NonBlockWriter ¶
type NonBlockWriter struct {
// contains filtered or unexported fields
}
NonBlockWriter is a wrapper around io.Writer that does not block on io.Writer.Write call. NonBlockWriter implements io.WriteCloser interface. To gracefully wait for the wrapped io.Writer to finish writing, NonBlockWriter.Close method must be called (typically by defer statement).
func NewNonBlockWriter ¶
func NewNonBlockWriter(ctx context.Context, w io.Writer, size int, onError func(error) bool) (*NonBlockWriter, error)
NewNonBlockWriter creates a new NonBlockWriter. 'w' - wrapped io.Writer. 'size' - buffer size of the underlying chan []byte (defaults to math.MaxInt16 if zero or negative). 'onError' (if not nil) is called if the wrapped io.Writer.Write returns an error. If 'onError' returns true (or ctx.Err() returns a non-nil error), NonBlockWriter is closed and any remaining non-written data is discarded by NonBlockWriter.Close method.
func (*NonBlockWriter) Close ¶
func (nbw *NonBlockWriter) Close() error
Close waits for the wrapped io.Writer to finish writing and returns the error (if any) returned by the last wrapped io.Writer.Write call. Close implements the io.Closer interface.
func (*NonBlockWriter) IsWriting ¶
func (nbw *NonBlockWriter) IsWriting() bool
IsWriting reports whether the wrapped io.Writer is in the writing phase or not.
func (*NonBlockWriter) LastResult ¶
func (nbw *NonBlockWriter) LastResult() (int, error)
LastResult returns result of the last wrapped io.Writer.Write call.
func (*NonBlockWriter) Write ¶
func (nbw *NonBlockWriter) Write(p []byte) (int, error)
Write implements the io.Writer interface. Write returns an error only if 'nbw' is closed. An error (if any) returned by the wrapped io.Writer.Write call is returned by NonBlockWriter.Close or NonBlockWriter.LastResult methods.