Documentation
¶
Overview ¶
Package nio provides a few buffered io primitives.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
Copy copies from src to buf, and from buf to dst in parallel until either EOF is reached on src or an error occurs. It returns the number of bytes copied to dst and the first error encountered while copying, if any. EOF is not considered to be an error. If src implements WriterTo, it is used to write to the supplied Buffer. If dst implements ReaderFrom, it is used to read from the supplied Buffer.
func NewReader ¶
func NewReader(src io.Reader, buf Buffer) io.ReadCloser
NewReader reads from the buffer which is concurrently filled with data from the passed src.
func Pipe ¶
func Pipe(buf Buffer) (r *PipeReader, w *PipeWriter)
Pipe creates a buffered pipe. It can be used to connect code expecting an io.Reader with code expecting an io.Writer. Reads on one end read from the supplied Buffer. Writes write to the supplied Buffer. It is safe to call Read and Write in parallel with each other or with Close. Close will complete once pending I/O is done, and may cancel blocking Read/Writes. Buffered data will still be available to Read after the Writer has been closed. Parallel calls to Read, and parallel calls to Write are also safe : the individual calls will be gated sequentially.
Types ¶
type Buffer ¶
type Buffer interface { // Len returns how many bytes are buffered Len() int64 // Cap returns how many bytes can in the buffer at a time Cap() int64 // ReadWriter writes are stored in the buffer, reads return the stored data io.ReadWriter }
Buffer is used to store bytes.
type PipeReader ¶
type PipeReader struct {
// contains filtered or unexported fields
}
PipeReader is the read half of the pipe.
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 io.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.
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; once the buffer is empty subsequent reads from the read half of the pipe will return no bytes and io.EOF after all the buffer has been read. CloseWithError always returns nil.
func (*PipeWriter) CloseWithError ¶
func (w *PipeWriter) CloseWithError(err error) error
CloseWithError closes the writer; once the buffer is empty subsequent reads from the read half of the pipe will return no bytes and the error err, or io.EOF if err is nil. CloseWithError always returns nil.