Package bufio
import "bufio"
This package implements buffered I/O. It wraps an io.Reader or io.Writer object, creating another object (Reader or Writer) that also implements the interface but provides buffering and some help for textual I/O.
Package files
bufio.goVariables
var (
ErrInvalidUnreadByte os.Error = &Error{"bufio: invalid use of UnreadByte"}
ErrBufferFull os.Error = &Error{"bufio: buffer full"}
)
type BufSizeError
BufSizeError is the error representing an invalid buffer size.
type BufSizeError int
func (BufSizeError) String
func (b BufSizeError) String() string
type Error
Errors introduced by this package.
type Error struct {
os.ErrorString
}
type ReadWriter
ReadWriter stores pointers to a Reader and a Writer. It implements io.ReadWriter.
type ReadWriter struct {
*Reader
*Writer
}
func NewReadWriter
func NewReadWriter(r *Reader, w *Writer) *ReadWriter
NewReadWriter allocates a new ReadWriter that dispatches to r and w.
type Reader
Reader implements buffering for an io.Reader object.
type Reader struct {
// contains unexported fields
}
func NewReader
func NewReader(rd io.Reader) *Reader
NewReader returns a new Reader whose buffer has the default size.
func NewReaderSize
func NewReaderSize(rd io.Reader, size int) (*Reader, os.Error)
NewReaderSize creates a new Reader whose buffer has the specified size, which must be greater than zero. If the argument io.Reader is already a Reader with large enough size, it returns the underlying Reader. It returns the Reader and any error.
func (*Reader) Buffered
func (b *Reader) Buffered() int
Buffered returns the number of bytes that can be read from the current buffer.
func (*Reader) Read
func (b *Reader) Read(p []byte) (nn int, err os.Error)
Read reads data into p. It returns the number of bytes read into p. If nn < len(p), also returns an error explaining why the read is short. At EOF, the count will be zero and err will be os.EOF.
func (*Reader) ReadByte
func (b *Reader) ReadByte() (c byte, err os.Error)
ReadByte reads and returns a single byte. If no byte is available, returns an error.
func (*Reader) ReadBytes
func (b *Reader) ReadBytes(delim byte) (line []byte, err os.Error)
ReadBytes reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often os.EOF). ReadBytes returns err != nil if and only if line does not end in delim.
func (*Reader) ReadRune
func (b *Reader) ReadRune() (rune int, size int, err os.Error)
ReadRune reads a single UTF-8 encoded Unicode character and returns the rune and its size in bytes.
func (*Reader) ReadSlice
func (b *Reader) ReadSlice(delim byte) (line []byte, err os.Error)
ReadSlice reads until the first occurrence of delim in the input, returning a slice pointing at the bytes in the buffer. The bytes stop being valid at the next read call. If ReadSlice encounters an error before finding a delimiter, it returns all the data in the buffer and the error itself (often os.EOF). ReadSlice fails with error ErrBufferFull if the buffer fills without a delim. Because the data returned from ReadSlice will be overwritten by the next I/O operation, most clients should use ReadBytes or ReadString instead. ReadSlice returns err != nil if and only if line does not end in delim.
func (*Reader) ReadString
func (b *Reader) ReadString(delim byte) (line string, err os.Error)
ReadString reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often os.EOF). ReadString returns err != nil if and only if line does not end in delim.
func (*Reader) UnreadByte
func (b *Reader) UnreadByte() os.Error
UnreadByte unreads the last byte. Only the most recently read byte can be unread.
type Writer
Writer implements buffering for an io.Writer object.
type Writer struct {
// contains unexported fields
}
func NewWriter
func NewWriter(wr io.Writer) *Writer
NewWriter returns a new Writer whose buffer has the default size.
func NewWriterSize
func NewWriterSize(wr io.Writer, size int) (*Writer, os.Error)
NewWriterSize creates a new Writer whose buffer has the specified size, which must be greater than zero. If the argument io.Writer is already a Writer with large enough size, it returns the underlying Writer. It returns the Writer and any error.
func (*Writer) Available
func (b *Writer) Available() int
Available returns how many bytes are unused in the buffer.
func (*Writer) Buffered
func (b *Writer) Buffered() int
Buffered returns the number of bytes that have been written into the current buffer.
func (*Writer) Flush
func (b *Writer) Flush() os.Error
Flush writes any buffered data to the underlying io.Writer.
func (*Writer) Write
func (b *Writer) Write(p []byte) (nn int, err os.Error)
Write writes the contents of p into the buffer. It returns the number of bytes written. If nn < len(p), it also returns an error explaining why the write is short.
func (*Writer) WriteByte
func (b *Writer) WriteByte(c byte) os.Error
WriteByte writes a single byte.
func (*Writer) WriteString
func (b *Writer) WriteString(s string) (int, os.Error)
WriteString writes a string. It returns the number of bytes written. If the count is less than len(s), it also returns an error explaining why the write is short.
