Documentation ¶
Index ¶
- Variables
- func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error)
- func FprintfIfTrue(w io.Writer, format string, ok bool) (int, error)
- func HashData(src io.Reader) (string, error)
- func MultiReadSeeker(readers ...io.ReadSeeker) io.ReadSeeker
- func NewCancelReadCloser(ctx context.Context, in io.ReadCloser) io.ReadCloser
- func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser
- func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader
- func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func TempDir(dir, prefix string) (string, error)
- type BytesPipe
- type NopFlusher
- type NopWriter
- type OnEOFReader
- type WriteCounter
- type WriteFlusher
- Bugs
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("write to closed BytesPipe")
ErrClosed is returned when Write is called on a closed BytesPipe.
Functions ¶
func FprintfIfNotEmpty ¶ added in v1.7.0
FprintfIfNotEmpty prints the string value if it's not empty
func FprintfIfTrue ¶ added in v1.9.0
FprintfIfTrue prints the boolean value if it's true
func MultiReadSeeker ¶ added in v1.8.0
func MultiReadSeeker(readers ...io.ReadSeeker) io.ReadSeeker
MultiReadSeeker returns a ReadSeeker that's the logical concatenation of the provided input readseekers. After calling this method the initial position is set to the beginning of the first ReadSeeker. At the end of a ReadSeeker, Read always advances to the beginning of the next ReadSeeker and returns EOF at the end of the last ReadSeeker. Seek can be used over the sum of lengths of all readseekers.
When a MultiReadSeeker is used, no Read and Seek operations should be made on its ReadSeeker components. Also, users should make no assumption on the state of individual readseekers while the MultiReadSeeker is used.
func NewCancelReadCloser ¶
func NewCancelReadCloser(ctx context.Context, in io.ReadCloser) io.ReadCloser
NewCancelReadCloser creates a wrapper that closes the ReadCloser when the context is cancelled. The returned io.ReadCloser must be closed when it is no longer needed.
func NewReadCloserWrapper ¶
func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser
NewReadCloserWrapper returns a new io.ReadCloser.
func NewReaderErrWrapper ¶
NewReaderErrWrapper returns a new io.Reader.
func NewWriteCloserWrapper ¶
func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser
NewWriteCloserWrapper returns a new io.WriteCloser.
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
NopWriteCloser returns a nopWriteCloser.
Types ¶
type BytesPipe ¶ added in v1.9.0
type BytesPipe struct {
// contains filtered or unexported fields
}
BytesPipe is io.ReadWriteCloser which works similarly to pipe(queue). All written data may be read at most once. Also, BytesPipe allocates and releases new byte slices to adjust to current needs, so the buffer won't be overgrown after peak loads.
func NewBytesPipe ¶ added in v1.9.0
NewBytesPipe creates new BytesPipe, initialized by specified slice. If buf is nil, then it will be initialized with slice which cap is 64. buf will be adjusted in a way that len(buf) == 0, cap(buf) == cap(buf).
func (*BytesPipe) CloseWithError ¶
CloseWithError causes further reads from a BytesPipe to return immediately.
type NopFlusher ¶
type NopFlusher struct{}
NopFlusher represents a type which flush operation is nop.
type OnEOFReader ¶ added in v1.8.0
type OnEOFReader struct { Rc io.ReadCloser Fn func() }
OnEOFReader wraps a io.ReadCloser and a function the function will run at the end of file or close the file.
func (*OnEOFReader) Close ¶ added in v1.8.0
func (r *OnEOFReader) Close() error
Close closes the file and run the function.
type WriteCounter ¶ added in v1.7.0
WriteCounter wraps a concrete io.Writer and hold a count of the number of bytes written to the writer during a "session". This can be convenient when write return is masked (e.g., json.Encoder.Encode())
func NewWriteCounter ¶ added in v1.7.0
func NewWriteCounter(w io.Writer) *WriteCounter
NewWriteCounter returns a new WriteCounter.
type WriteFlusher ¶ added in v1.7.0
type WriteFlusher struct {
// contains filtered or unexported fields
}
WriteFlusher wraps the Write and Flush operation ensuring that every write is a flush. In addition, the Close method can be called to intercept Read/Write calls if the targets lifecycle has already ended.
func NewWriteFlusher ¶ added in v1.7.0
func NewWriteFlusher(w io.Writer) *WriteFlusher
NewWriteFlusher returns a new WriteFlusher.
func (*WriteFlusher) Close ¶ added in v1.9.1
func (wf *WriteFlusher) Close() error
Close closes the write flusher, disallowing any further writes to the target. After the flusher is closed, all calls to write or flush will result in an error.
func (*WriteFlusher) Flush ¶ added in v1.7.0
func (wf *WriteFlusher) Flush()
Flush the stream immediately.
func (*WriteFlusher) Flushed ¶ added in v1.7.0
func (wf *WriteFlusher) Flushed() bool
Flushed returns the state of flushed. If it's flushed, return true, or else it return false.
Notes ¶
Bugs ¶
Remove this method. Its use is inherently racy. Seems to be used to detect whether or a response code has been issued or not. Another hook should be used instead.