Documentation
¶
Index ¶
- Variables
- func CloseIgnored(c io.Closer)
- func CloseLogged(c io.Closer, message string)
- func CloseLoggedWithIgnores(c io.Closer, message string, ignore ...error)
- func ClosePanicked(c io.Closer, message string)
- func ClosePanickedWithIgnores(c io.Closer, message string, ignore ...error)
- func CopyNoWarning(out io.Writer, in io.Reader) int64
- func CopyWithWarning(out io.Writer, in io.Reader) int64
- func Discard(in io.Reader) (int64, error)
- func DiscardN(in io.Reader, n int64) (int64, error)
- func MustReadAll(in io.Reader) []byte
- func MustReadByte(in io.Reader) byte
- func MustReadBytes(in io.Reader, dst []byte)
- func MustReadFull(in io.Reader, dst []byte)
- func MustReadN(in io.Reader, n uint) []byte
- func NewCloseSequence(seq ...io.Closer) io.Closer
- func NewCloserWrapper(closer io.Closer) *closerWrapper
- func ReadAll(in io.Reader) ([]byte, error)
- func ReadByte(in io.Reader) (byte, error)
- func ReadExpect(next byte, in io.Reader) (bool, error)
- func ReadN(in io.Reader, n uint) ([]byte, error)
- func ReadUntil(in io.Reader, stop byte) ([]byte, error)
- func Transfer(wg *sync.WaitGroup, dst io.Writer, src io.Reader)
- type CountingWriter
- type NopCloser
Constants ¶
This section is empty.
Variables ¶
var ErrIncompleteRead = errors.NewStringError("incomplete read")
var ErrSequenceFailure = errors.NewStringError("error while executing sequence of closers")
Functions ¶
func CloseIgnored ¶
CloseIgnored closes the closer and discards any possible error.
func CloseLogged ¶
CloseLogged closes the closer and logs specified message in case of error. Any error except is logged. The error message is logged as a warning.
func CloseLoggedWithIgnores ¶
CloseLoggedWithIgnores closes the closer and logs specified message in case of error. Any error except for ignored are logged. The error message is logged as a warning. Typical ignored errors: net.ErrClosed (when closed elsewhere), io.ErrClosedPipe (when closed elsewhere)
func ClosePanicked ¶
ClosePanicked closes the closer and panics with specified message in case of any error.
func ClosePanickedWithIgnores ¶
ClosePanickedWithIgnores closes the closer and panics with specified message in case of any error, except for those in `ignore`. Typical ignored errors: net.ErrClosed (when closed elsewhere), io.ErrClosedPipe (when closed elsewhere)
func CopyNoWarning ¶
CopyNoWarning copies contents from in to out. Do NOT log anything in case transfer interrupts.
func CopyWithWarning ¶
CopyWithWarning copies contents from in to out. It logs a warning in case transfer interrupts.
func Discard ¶
Discard reads remaining data from reader and discards it.
Returns nr of bytes read, thus discarded. An error is returned if encountered while reading from input.
func DiscardN ¶
DiscardN reads `n` bytes from `in` and discards them.
The number of discarded bytes is returned, and an error is returned only if it is not successful in reading and discarding `n` bytes.
func MustReadAll ¶
MustReadAll reads all data from reader and panics in case an error occurs.
func MustReadByte ¶
func MustReadBytes ¶
MustReadBytes reads bytes into dst and fails if anything out of the ordinary happens.
func MustReadFull ¶
func MustReadN ¶
MustReadN creates then fills the buffer to `n` by reading from `in` and panics on error.
func NewCloseSequence ¶
NewCloseSequence creates a new composite sequential closer that closes in the order provided.
The sequence will not halt on error. If closing behavior is dependent on other closers, this should be part of the closer's logic. Instead, errors are collected and an aggregate error is returned that includes error messages from all the failures that occurred while closing the sequence.
Returns `ErrSequenceFailure` with context in case at least one of the closers fails to close.
Panics are not mitigated in any way.
func NewCloserWrapper ¶
func ReadExpect ¶
ReadExpect reads and checks if the read byte is the expected `next` byte.
func ReadUntil ¶
ReadUntil reads until a specific byte is encountered.
All bytes read before the stop-byte are returned. If an error is encountered, everything read until the error is returned together with the error. Following the behavior of `io.ReadFull`, ReadUntil will return io.EOF if end-of-file is reached.
For more sophisticated and more capable functions, use `bufio` (buffered-io). These functions are provided for one-off cases and cases where reading ahead is not desirable or not allowed.
Types ¶
type CountingWriter ¶
type CountingWriter struct { // FIXME consider better name for field; something that is descriptive when used. Cum int64 // contains filtered or unexported fields }
TODO make `Cum` (cumulative) public or private with accessor function?
func NewCountingWriter ¶
func NewCountingWriter(out io.Writer) CountingWriter
func (*CountingWriter) Write ¶
func (w *CountingWriter) Write(p []byte) (int, error)
Write writes `p` to the underlying output and counts the number of bytes written. Write follows the conventions of io.Writer. It will add up the number of bytes written, even if the write was incomplete and consequently an error returned.
type NopCloser ¶
type NopCloser struct {
Rw io.ReadWriter
}
NopCloser is a no-op close ReadWriteCloser implementation.
One would typically want to respect the Close method on writers. This implementation provides no-op closing for cases where `Close()` is already handled at a different level of nesting.