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 Reader
- func (b *Reader) Buffered() int
- func (b *Reader) Discard(n int) (discarded int, err error)
- func (b *Reader) Peek(n int) ([]byte, error)
- func (b *Reader) Pop(n int) ([]byte, error)
- func (b *Reader) Read(p []byte) (n int, err error)
- func (b *Reader) ReadByte() (c byte, err error)
- func (b *Reader) ReadLine() (line []byte, isPrefix bool, err error)
- func (b *Reader) ReadSlice(delim byte) (line []byte, err error)
- func (b *Reader) Reset(r io.Reader)
- func (b *Reader) ResetBuffer(r io.Reader, buf []byte)
- type Writer
- func (b *Writer) Available() int
- func (b *Writer) Buffered() int
- func (b *Writer) Flush() error
- func (b *Writer) Peek(n int) ([]byte, error)
- func (b *Writer) Reset(w io.Writer)
- func (b *Writer) ResetBuffer(w io.Writer, buf []byte)
- func (b *Writer) Write(p []byte) (nn int, err error)
- func (b *Writer) WriteRaw(p []byte) (nn int, err error)
- func (b *Writer) WriteString(s string) (int, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidUnreadByte invalid use of UnreadByete ErrInvalidUnreadByte = errors.New("bufio: invalid use of UnreadByte") // ErrInvalidUnreadRune invalid use of UnreadRune ErrInvalidUnreadRune = errors.New("bufio: invalid use of UnreadRune") // ErrBufferFull buffer full ErrBufferFull = errors.New("bufio: buffer full") // ErrNegativeCount negative count ErrNegativeCount = errors.New("bufio: negative count") )
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader implements buffering for an io.Reader object.
func NewReaderSize ¶
NewReaderSize returns a new Reader whose buffer has at least the specified size. If the argument io.Reader is already a Reader with large enough size, it returns the underlying Reader.
func (*Reader) Buffered ¶
Buffered returns the number of bytes that can be read from the current buffer.
func (*Reader) Discard ¶
Discard skips the next n bytes, returning the number of bytes discarded.
If Discard skips fewer than n bytes, it also returns an error. If 0 <= n <= b.Buffered(), Discard is guaranteed to succeed without reading from the underlying io.Reader.
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) Pop ¶
Pop returns the next n bytes with advancing the reader. The bytes stop being valid at the next read call. If Pop 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 io.EOF.
func (*Reader) ReadByte ¶
ReadByte reads and returns a single byte. If no byte is available, returns an error.
func (*Reader) ReadLine ¶
ReadLine is a low-level line-reading primitive. Most callers should use ReadBytes('\n') or ReadString('\n') instead or use a Scanner.
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.
The text returned from ReadLine does not include the line end ("\r\n" or "\n"). No indication or error is given if the input ends without a final line end. Calling UnreadByte after ReadLine will always unread the last byte read (possibly a character belonging to the line end) even if that byte is not part of the line returned by ReadLine.
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. If ReadSlice encounters an error before finding a delimiter, it returns all the data in the buffer and the error itself (often io.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.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements buffering for an io.Writer object. If an error occurs writing to a Writer, no more data will be accepted and all subsequent writes will return the error. After all data has been written, the client should call the Flush method to guarantee all data has been forwarded to the underlying io.Writer.
func NewWriterSize ¶
NewWriterSize returns a new Writer whose buffer has at least the specified size. If the argument io.Writer is already a Writer with large enough size, it returns the underlying Writer.
func (*Writer) Buffered ¶
Buffered returns the number of bytes that have been written into the current buffer.
func (*Writer) Peek ¶
Peek returns the next n bytes with advancing the writer. The bytes stop being used at the next write 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 (*Writer) Reset ¶
Reset discards any unflushed buffered data, clears any error, and resets b to write its output to w.
func (*Writer) ResetBuffer ¶
ResetBuffer discards any unflushed buffered data, clears any error, and resets b to write its output to w.
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.