Documentation ¶
Overview ¶
This package provides basic interfaces to I/O primitives. Its primary job is to wrap existing implementations of such primitives, such as those in package os, into shared public interfaces that abstract the functionality, plus some other related primitives.
Index ¶
- Variables
- func Copy(dst Writer, src Reader) (written int64, err os.Error)
- func Copyn(dst Writer, src Reader, n int64) (written int64, err os.Error)
- func Pipe() (*PipeReader, *PipeWriter)
- func ReadAtLeast(r Reader, buf []byte, min int) (n int, err os.Error)
- func ReadFull(r Reader, buf []byte) (n int, err os.Error)
- func WriteString(w Writer, s string) (n int, err os.Error)
- type Closer
- type Error
- type PipeReader
- type PipeWriter
- type ReadByter
- type ReadCloser
- type ReadSeeker
- type ReadWriteCloser
- type ReadWriteSeeker
- type ReadWriter
- type Reader
- type ReaderAt
- type ReaderFrom
- type SectionReader
- type Seeker
- type WriteCloser
- type WriteSeeker
- type Writer
- type WriterAt
- type WriterTo
Constants ¶
This section is empty.
Variables ¶
var ErrShortWrite os.Error = &Error{"short write"}
ErrShortWrite means that a write accepted fewer bytes than requested but failed to return an explicit error.
var ErrUnexpectedEOF os.Error = &Error{"unexpected EOF"}
ErrUnexpectedEOF means that os.EOF was encountered in the middle of reading a fixed-size block or data structure.
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 error, if any.
If dst implements the ReaderFrom interface, the copy is implemented by calling dst.ReadFrom(src). Otherwise, if src implements the WriterTo interface, the copy is implemented by calling src.WriteTo(dst).
func Copyn ¶
Copyn copies n bytes (or until an error) from src to dst. It returns the number of bytes copied and the error, if any.
If dst implements the ReaderFrom interface, the copy is implemented by calling dst.ReadFrom(src).
func Pipe ¶
func Pipe() (*PipeReader, *PipeWriter)
Pipe creates a synchronous in-memory pipe. It can be used to connect code expecting an io.Reader with code expecting an io.Writer. Reads on one end are matched with writes on the other, copying data directly between the two; there is no internal buffering.
func ReadAtLeast ¶
ReadAtLeast reads from r into buf until it has read at least min bytes. It returns the number of bytes copied and an error if fewer bytes were read. The error is os.EOF only if no bytes were read. If an EOF happens after reading fewer than min bytes, ReadAtLeast returns ErrUnexpectedEOF.
Types ¶
type PipeReader ¶
type PipeReader struct {
// contains filtered or unexported fields
}
A PipeReader is the read half of a pipe.
func (*PipeReader) Close ¶
func (r *PipeReader) Close() os.Error
Close closes the reader; subsequent writes to the write half of the pipe will return the error os.EPIPE.
func (*PipeReader) CloseWithError ¶
func (r *PipeReader) CloseWithError(rerr os.Error) os.Error
CloseWithError closes the reader; subsequent writes to the write half of the pipe will return the error rerr.
func (*PipeReader) Read ¶
func (r *PipeReader) Read(data []byte) (n int, err os.Error)
Read implements the standard Read interface: it reads data from the pipe, blocking until a writer arrives or the write end is closed. If the write end is closed with an error, that error is returned as err; otherwise err is nil.
type PipeWriter ¶
type PipeWriter struct {
// contains filtered or unexported fields
}
Write half of pipe.
func (*PipeWriter) Close ¶
func (w *PipeWriter) Close() os.Error
Close closes the writer; subsequent reads from the read half of the pipe will return no bytes and a nil error.
func (*PipeWriter) CloseWithError ¶
func (w *PipeWriter) CloseWithError(werr os.Error) os.Error
CloseWithError closes the writer; subsequent reads from the read half of the pipe will return no bytes and the error werr.
func (*PipeWriter) Write ¶
func (w *PipeWriter) Write(data []byte) (n int, err os.Error)
Write implements the standard Write interface: it writes data to the pipe, blocking until readers have consumed all the data or the read end is closed. If the read end is closed with an error, that err is returned as err; otherwise err is os.EPIPE.
type ReadByter ¶
ReadByter is the interface that wraps the ReadByte method.
ReadByte reads and returns the next byte from the input. If no byte is available, err will be set.
type ReadCloser ¶
ReadCloser is the interface that groups the basic Read and Close methods.
type ReadSeeker ¶
ReadSeeker is the interface that groups the basic Read and Seek methods.
type ReadWriteCloser ¶
ReadWriteCloser is the interface that groups the basic Read, Write and Close methods.
type ReadWriteSeeker ¶
ReadWriteSeeker is the interface that groups the basic Read, Write and Seek methods.
type ReadWriter ¶
ReadWriter is the interface that groups the basic Read and Write methods.
type Reader ¶
Reader is the interface that wraps the basic Read method.
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Even if Read returns n < len(p), it may use all of p as scratch space during the call. If some data is available but not len(p) bytes, Read conventionally returns what is available rather than block waiting for more.
At the end of the input stream, Read returns 0, os.EOF. Read may return a non-zero number of bytes with a non-nil err. In particular, a Read that exhausts the input may return n > 0, os.EOF.
func LimitReader ¶
LimitReader returns a Reader that reads from r but stops with os.EOF after n bytes.
type ReaderAt ¶
ReaderAt is the interface that wraps the basic ReadAt method.
ReadAt reads len(p) bytes into p starting at offset off in the underlying data stream. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.
Even if ReadAt returns n < len(p), it may use all of p as scratch space during the call. If some data is available but not len(p) bytes, ReadAt blocks until either all the data is available or an error occurs.
At the end of the input stream, ReadAt returns 0, os.EOF. ReadAt may return a non-zero number of bytes with a non-nil err. In particular, a ReadAt that exhausts the input may return n > 0, os.EOF.
type ReaderFrom ¶
ReaderFrom is the interface that wraps the ReadFrom method.
type SectionReader ¶
type SectionReader struct {
// contains filtered or unexported fields
}
SectionReader implements Read, Seek, and ReadAt on a section of an underlying ReaderAt.
func NewSectionReader ¶
func NewSectionReader(r ReaderAt, off int64, n int64) *SectionReader
NewSectionReader returns a SectionReader that reads from r starting at offset off and stops with os.EOF after n bytes.
func (*SectionReader) Size ¶
func (s *SectionReader) Size() int64
Size returns the size of the section in bytes.
type Seeker ¶
Seeker is the interface that wraps the basic Seek method.
Seek sets the offset for the next Read or Write to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. Seek returns the new offset and an Error, if any.
type WriteCloser ¶
WriteCloser is the interface that groups the basic Write and Close methods.
type WriteSeeker ¶
WriteSeeker is the interface that groups the basic Write and Seek methods.
type Writer ¶
Writer is the interface that wraps the basic Write method.
Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write must return a non-nil error if it returns n < len(p).
type WriterAt ¶
WriterAt is the interface that wraps the basic WriteAt method.
WriteAt writes len(p) bytes from p to the underlying data stream at offset off. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. WriteAt must return a non-nil error if it returns n < len(p).