io

package
v0.0.0-...-90c9d3a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 2 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrShortWrite os.Error = &Error{"short write"}

ErrShortWrite means that a write accepted fewer bytes than requested but failed to return an explicit error.

View Source
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

func Copy(dst Writer, src Reader) (written int64, err os.Error)

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

func Copyn(dst Writer, src Reader, n int64) (written int64, err os.Error)

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

func ReadAtLeast(r Reader, buf []byte, min int) (n int, err os.Error)

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.

func ReadFull

func ReadFull(r Reader, buf []byte) (n int, err os.Error)

ReadFull reads exactly len(buf) bytes from r into buf. 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 some but not all the bytes, ReadFull returns ErrUnexpectedEOF.

func WriteString

func WriteString(w Writer, s string) (n int, err os.Error)

WriteString writes the contents of the string s to w, which accepts an array of bytes.

Types

type Closer

type Closer interface {
	Close() os.Error
}

Closer is the interface that wraps the basic Close method.

type Error

type Error struct {
	os.ErrorString
}

Error represents an unexpected I/O behavior.

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

type ReadByter interface {
	ReadByte() (c byte, err os.Error)
}

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

type ReadCloser interface {
	Reader
	Closer
}

ReadCloser is the interface that groups the basic Read and Close methods.

type ReadSeeker

type ReadSeeker interface {
	Reader
	Seeker
}

ReadSeeker is the interface that groups the basic Read and Seek methods.

type ReadWriteCloser

type ReadWriteCloser interface {
	Reader
	Writer
	Closer
}

ReadWriteCloser is the interface that groups the basic Read, Write and Close methods.

type ReadWriteSeeker

type ReadWriteSeeker interface {
	Reader
	Writer
	Seeker
}

ReadWriteSeeker is the interface that groups the basic Read, Write and Seek methods.

type ReadWriter

type ReadWriter interface {
	Reader
	Writer
}

ReadWriter is the interface that groups the basic Read and Write methods.

type Reader

type Reader interface {
	Read(p []byte) (n int, err os.Error)
}

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

func LimitReader(r Reader, n int64) Reader

LimitReader returns a Reader that reads from r but stops with os.EOF after n bytes.

type ReaderAt

type ReaderAt interface {
	ReadAt(p []byte, off int64) (n int, err os.Error)
}

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

type ReaderFrom interface {
	ReadFrom(r Reader) (n int64, err os.Error)
}

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) Read

func (s *SectionReader) Read(p []byte) (n int, err os.Error)

func (*SectionReader) ReadAt

func (s *SectionReader) ReadAt(p []byte, off int64) (n int, err os.Error)

func (*SectionReader) Seek

func (s *SectionReader) Seek(offset int64, whence int) (ret int64, err os.Error)

func (*SectionReader) Size

func (s *SectionReader) Size() int64

Size returns the size of the section in bytes.

type Seeker

type Seeker interface {
	Seek(offset int64, whence int) (ret int64, err os.Error)
}

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

type WriteCloser interface {
	Writer
	Closer
}

WriteCloser is the interface that groups the basic Write and Close methods.

type WriteSeeker

type WriteSeeker interface {
	Writer
	Seeker
}

WriteSeeker is the interface that groups the basic Write and Seek methods.

type Writer

type Writer interface {
	Write(p []byte) (n int, err os.Error)
}

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

type WriterAt interface {
	WriteAt(p []byte, off int64) (n int, err os.Error)
}

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).

type WriterTo

type WriterTo interface {
	WriteTo(w Writer) (n int64, err os.Error)
}

WriterTo is the interface that wraps the WriteTo method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL