Documentation ¶
Overview ¶
Package bufio 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.
Index ¶
- Variables
- type BufSizeError
- type Error
- type ReadWriter
- type Reader
- func (b *Reader) Buffered() int
- func (b *Reader) Peek(n int) ([]byte, os.Error)
- func (b *Reader) Read(p []byte) (n int, err os.Error)
- func (b *Reader) ReadByte() (c byte, err os.Error)
- func (b *Reader) ReadBytes(delim byte) (line []byte, err os.Error)
- func (b *Reader) ReadLine() (line []byte, isPrefix bool, err os.Error)
- func (b *Reader) ReadRune() (rune int, size int, err os.Error)
- func (b *Reader) ReadSlice(delim byte) (line []byte, err os.Error)
- func (b *Reader) ReadString(delim byte) (line string, err os.Error)
- func (b *Reader) UnreadByte() os.Error
- func (b *Reader) UnreadRune() os.Error
- type Writer
- func (b *Writer) Available() int
- func (b *Writer) Buffered() int
- func (b *Writer) Flush() os.Error
- func (b *Writer) Write(p []byte) (nn int, err os.Error)
- func (b *Writer) WriteByte(c byte) os.Error
- func (b *Writer) WriteRune(rune int) (size int, err os.Error)
- func (b *Writer) WriteString(s string) (int, os.Error)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type BufSizeError ¶
type BufSizeError int
BufSizeError is the error representing an invalid buffer size.
func (BufSizeError) String ¶
func (b BufSizeError) String() string
type ReadWriter ¶
ReadWriter stores pointers to a Reader and a Writer. It implements io.ReadWriter.
func NewReadWriter ¶
func NewReadWriter(r *Reader, w *Writer) *ReadWriter
NewReadWriter allocates a new ReadWriter that dispatches to r and w.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader implements buffering for an io.Reader object.
func NewReaderSize ¶
NewReaderSize creates a new Reader whose buffer has the specified size, which must be greater than one. 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 ¶
Buffered returns the number of bytes that can be read from the current buffer.
func (*Reader) Peek ¶
Peek returns the next n bytes without advancing the reader. The bytes stop being valid at the next read call. If Peek returns fewer than n bytes, it also returns an error explaining why the read is short. The error is ErrBufferFull if n is larger than b's buffer size.
func (*Reader) Read ¶
Read reads data into p. It returns the number of bytes read into p. It calls Read at most once on the underlying Reader, hence n may be less than len(p). At EOF, the count will be zero and err will be os.EOF.
func (*Reader) ReadByte ¶
ReadByte reads and returns a single byte. If no byte is available, returns an error.
func (*Reader) ReadBytes ¶
ReadBytes reads until the first occurrence of delim in the input, returning a slice 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 the returned data does not end in delim.
func (*Reader) ReadLine ¶
ReadLine tries to return a single line, not including the end-of-line bytes. If the line was too long for the buffer then isPrefix is set and the beginning of the line is returned. The rest of the line will be returned from future calls. isPrefix will be false when returning the last fragment of the line. The returned buffer is only valid until the next call to ReadLine. ReadLine either returns a non-nil line or it returns an error, never both.
func (*Reader) ReadRune ¶
ReadRune reads a single UTF-8 encoded Unicode character and returns the rune and its size in bytes.
func (*Reader) ReadSlice ¶
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 ¶
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 the returned data does not end in delim.
func (*Reader) UnreadByte ¶
UnreadByte unreads the last byte. Only the most recently read byte can be unread.
func (*Reader) UnreadRune ¶
UnreadRune unreads the last rune. If the most recent read operation on the buffer was not a ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.)
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements buffering for an io.Writer object.
func NewWriterSize ¶
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) Buffered ¶
Buffered returns the number of bytes that have been written into the current buffer.
func (*Writer) Write ¶
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.