Documentation
¶
Index ¶
- func Copy(ctx context.Context, dst Writer, src Reader) (written int64, err error)
- func CopyBuffer(ctx context.Context, dst Writer, src Reader, buf []byte) (written int64, err error)
- func Pipe() (*PipeReader, *PipeWriter)
- func ReadAll(ctx context.Context, r Reader) ([]byte, error)
- func ReadAtLeast(ctx context.Context, r Reader, buf []byte, min int) (n int, err error)
- func ReadFull(ctx context.Context, r Reader, buf []byte) (n int, err error)
- func WriteStringContext(ctx context.Context, w Writer, s string) (n int, err error)
- type PipeReader
- type PipeWriter
- type ReadCloser
- type Reader
- type ReaderFrom
- type StringWriter
- type WriteCloser
- type Writer
- type WriterTo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.
A successful Copy returns err == nil, not err == EOF. Because Copy is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.
func CopyBuffer ¶
CopyBuffer is identical to Copy except that it stages through the provided buffer (if one is required) rather than allocating a temporary one. If buf is nil, one is allocated; otherwise if it has zero length, CopyBuffer panics.
func Pipe ¶
func Pipe() (*PipeReader, *PipeWriter)
func ReadAll ¶
ReadAll reads from r until an error or io.EOF and returns the data it read. A successful call returns err == nil, not err == io.EOF. Because ReadAll is defined to read from src until io.EOF, it does not treat an io.EOF from Read as an error to be reported.
func ReadAtLeast ¶
ReadAtLeast reads from r into buf until it has read at least min bytes.
Types ¶
type PipeReader ¶
type PipeReader struct {
// contains filtered or unexported fields
}
func (*PipeReader) Close ¶
func (r *PipeReader) Close() error
Close closes the reader; subsequent writes to the write half of the pipe will return the error ErrClosedPipe.
func (*PipeReader) CloseWithError ¶
func (r *PipeReader) CloseWithError(err error) error
CloseWithError closes the reader; subsequent writes to the write half of the pipe will return the error err.
CloseWithError never overwrites the previous error if it exists and always returns nil.
func (*PipeReader) ReadContext ¶
type PipeWriter ¶
type PipeWriter struct {
// contains filtered or unexported fields
}
A PipeWriter is the write half of a pipe.
func (*PipeWriter) Close ¶
func (w *PipeWriter) Close() error
Close closes the writer; subsequent reads from the read half of the pipe will return no bytes and EOF.
func (*PipeWriter) CloseWithError ¶
func (w *PipeWriter) CloseWithError(err error) error
CloseWithError closes the writer; subsequent reads from the read half of the pipe will return no bytes and the error err, or EOF if err is nil.
CloseWithError never overwrites the previous error if it exists and always returns nil.
func (*PipeWriter) WriteContext ¶
type ReadCloser ¶
func NewReader ¶
func NewReader(reader io.Reader) ReadCloser
func NopCloser ¶
func NopCloser(r Reader) ReadCloser
NopCloser returns a ReadCloser with a no-op Close method wrapping the provided Reader r.
type ReaderFrom ¶
ReaderFrom is the interface that wraps the ReadFromContext method.
ReadFromContext 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.
The Copy function uses ReaderFrom if available.
type StringWriter ¶
type StringWriter interface {
WriteStringContext(ctx context.Context, s string) (n int, err error)
}
StringWriter is the interface that wraps the WriteStringContext method.
type WriteCloser ¶
func NewWriter ¶
func NewWriter(writer io.Writer) WriteCloser
type Writer ¶
var Discard Writer = discard{}
Discard is a Writer on which all Write calls succeed without doing anything.
type WriterTo ¶
WriterTo is the interface that wraps the WriteToContext method.
WriteToContext 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.
The Copy function uses WriterTo if available.