Documentation
¶
Index ¶
- func Transfer(dst io.Writer, src io.Reader) (int64, error)
- type Pipe
- func (p *Pipe) BufferSize() (int, error)
- func (p *Pipe) Close() error
- func (p *Pipe) CloseRead() error
- func (p *Pipe) CloseWrite() error
- func (p *Pipe) Read(b []byte) (n int, err error)
- func (p *Pipe) ReadFrom(src io.Reader) (int64, error)
- func (p *Pipe) SetBufferSize(n int) error
- func (p *Pipe) Tee(w io.Writer)
- func (p *Pipe) Write(b []byte) (n int, err error)
- func (p *Pipe) WriteTo(dst io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transfer ¶
Transfer is like io.Copy, but moves data through a pipe rather than through a userspace buffer. Given a pipe p, Transfer operates equivalently to p.ReadFrom(src) and p.WriteTo(dst), but in lock-step, and with no need to create additional goroutines.
Conceptually:
Transfer(upstream, downstream)
is equivalent to
p, _ := NewPipe() go p.ReadFrom(downstream) p.WriteTo(upstream)
but in more compact form, and slightly more resource-efficient.
Types ¶
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
A Pipe is a buffered, unidirectional data channel.
func (*Pipe) BufferSize ¶
BufferSize returns the buffer size of the pipe.
func (*Pipe) CloseWrite ¶
CloseWrite closes the write side of the pipe.
func (*Pipe) ReadFrom ¶
ReadFrom transfers data from src to the pipe.
If src implements syscall.Conn, ReadFrom tries to use splice(2) for the data transfer from the source file descriptor to the pipe. If that is not possible, ReadFrom falls back to a generic copy.
func (*Pipe) SetBufferSize ¶
SetBufferSize sets the pipe's buffer size to n.
func (*Pipe) Tee ¶
Tee arranges for data in the read side of the pipe to be mirrored to the specified writer. There is no internal buffering: writes must complete before the associated read completes.
If the argument is of concrete type *Pipe, the tee(2) system call is used when mirroring data from the read side of the pipe.
Tee must not be called concurrently with I/O methods, and must be called only once, and before any calls to Read or WriteTo.