Namespace: go.std.bufio
v1.0Contents
Summary
Provides a low-level interface to the bufio package.
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
- *ReadWriter
- *Reader
- *Scanner
- *SplitFunc
- *Writer
- ErrAdvanceTooFar
- ErrBadReadCount
- ErrBufferFull
- ErrFinalToken
- ErrInvalidUnreadByte
- ErrInvalidUnreadRune
- ErrNegativeAdvance
- ErrNegativeCount
- ErrTooLong
- MaxScanTokenSize
- NewReadWriter
- NewReader
- NewReaderSize
- NewScanner
- NewWriter
- NewWriterSize
- ReadWriter
- Reader
- ScanBytes
- ScanLines
- ScanRunes
- ScanWords
- Scanner
- SplitFunc
- Writer
- arrayOfReadWriter
- arrayOfReader
- arrayOfScanner
- arrayOfSplitFunc
- arrayOfWriter
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
MaxScanTokenSize
Int v1.0MaxScanTokenSize is the maximum size used to buffer a token
unless the user provides an explicit buffer with Scanner.Buffer.
The actual maximum token size may be smaller as the buffer
may need to include, for instance, a newline.
Variables
-
ErrAdvanceTooFar
Var v1.0Errors returned by Scanner.
-
ErrBadReadCount
Var v1.0Errors returned by Scanner.
-
ErrBufferFull
Var v1.0 -
ErrFinalToken
Var v1.0ErrFinalToken is a special sentinel error value. It is intended to be
returned by a Split function to indicate that the token being delivered
with the error is the last token and scanning should stop after this one.
After ErrFinalToken is received by Scan, scanning stops with no error.
The value is useful to stop processing early or when it is necessary to
deliver a final empty token. One could achieve the same behavior
with a custom error value but providing one here is tidier.
See the emptyFinalToken example for a use of this value.
-
ErrInvalidUnreadByte
Var v1.0 -
ErrInvalidUnreadRune
Var v1.0 -
ErrNegativeAdvance
Var v1.0Errors returned by Scanner.
-
ErrNegativeCount
Var v1.0 -
ErrTooLong
Var v1.0Errors returned by Scanner.
Functions, Macros, and Special Forms
-
NewReadWriter
Function v1.0(NewReadWriter r w)
NewReadWriter allocates a new ReadWriter that dispatches to r and w.
Go input arguments: (r *Reader, w *Writer)
Go returns: *ReadWriter
Joker input arguments: [^*Reader r, ^*Writer w]
Joker returns: ^*ReadWriter -
NewReader
Function v1.0(NewReader rd)
NewReader returns a new Reader whose buffer has the default size.
Go input arguments: (rd io.Reader)
Go returns: *Reader
Joker input arguments: [^go.std.io/Reader rd]
Joker returns: ^*Reader -
NewReaderSize
Function v1.0(NewReaderSize rd size)
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.
Go input arguments: (rd io.Reader, size int)
Go returns: *Reader
Joker input arguments: [^go.std.io/Reader rd, ^Int size]
Joker returns: ^*Reader -
NewScanner
Function v1.0(NewScanner r)
NewScanner returns a new Scanner to read from r.
The split function defaults to ScanLines.
Go input arguments: (r io.Reader)
Go returns: *Scanner
Joker input arguments: [^go.std.io/Reader r]
Joker returns: ^*Scanner -
NewWriter
Function v1.0(NewWriter w)
NewWriter returns a new Writer whose buffer has the default size.
If the argument io.Writer is already a Writer with large enough buffer size,
it returns the underlying Writer.
Go input arguments: (w io.Writer)
Go returns: *Writer
Joker input arguments: [^go.std.io/Writer w]
Joker returns: ^*Writer -
NewWriterSize
Function v1.0(NewWriterSize w size)
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.
Go input arguments: (w io.Writer, size int)
Go returns: *Writer
Joker input arguments: [^go.std.io/Writer w, ^Int size]
Joker returns: ^*Writer -
ScanBytes
Function v1.0(ScanBytes data atEOF)
ScanBytes is a split function for a Scanner that returns each byte as a token.
Go input arguments: (data []byte, atEOF bool)
Go returns: (advance int, token []byte, err error)
Joker input arguments: [^arrayOfByte data, ^Boolean atEOF]
Joker returns: [^Int advance, ^arrayOfByte token, ^Error err] -
ScanLines
Function v1.0(ScanLines data atEOF)
ScanLines is a split function for a Scanner that returns each line of
text, stripped of any trailing end-of-line marker. The returned line may
be empty. The end-of-line marker is one optional carriage return followed
by one mandatory newline. In regular expression notation, it is `\r?\n`.
The last non-empty line of input will be returned even if it has no
newline.
Go input arguments: (data []byte, atEOF bool)
Go returns: (advance int, token []byte, err error)
Joker input arguments: [^arrayOfByte data, ^Boolean atEOF]
Joker returns: [^Int advance, ^arrayOfByte token, ^Error err] -
ScanRunes
Function v1.0(ScanRunes data atEOF)
ScanRunes is a split function for a Scanner that returns each
UTF-8-encoded rune as a token. The sequence of runes returned is
equivalent to that from a range loop over the input as a string, which
means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
Because of the Scan interface, this makes it impossible for the client to
distinguish correctly encoded replacement runes from encoding errors.
Go input arguments: (data []byte, atEOF bool)
Go returns: (advance int, token []byte, err error)
Joker input arguments: [^arrayOfByte data, ^Boolean atEOF]
Joker returns: [^Int advance, ^arrayOfByte token, ^Error err] -
ScanWords
Function v1.0(ScanWords data atEOF)
ScanWords is a split function for a Scanner that returns each
space-separated word of text, with surrounding spaces deleted. It will
never return an empty string. The definition of space is set by
unicode.IsSpace.
Go input arguments: (data []byte, atEOF bool)
Go returns: (advance int, token []byte, err error)
Joker input arguments: [^arrayOfByte data, ^Boolean atEOF]
Joker returns: [^Int advance, ^arrayOfByte token, ^Error err]
Types
-
*ReadWriter
Concrete Type v1.0ReadWriter stores pointers to a Reader and a Writer.
It implements io.ReadWriter.
-
Available
Receiver for *ReadWriter v1.0([])
Available returns how many bytes are unused in the buffer.
-
AvailableBuffer
Receiver for *ReadWriter v1.0([])
AvailableBuffer returns an empty buffer with b.Available() capacity.
This buffer is intended to be appended to and
passed to an immediately succeeding Write call.
The buffer is only valid until the next write operation on b.
-
Discard
Receiver for *ReadWriter v1.0([n])
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.
-
Flush
Receiver for *ReadWriter v1.0([])
Flush writes any buffered data to the underlying io.Writer.
-
Peek
Receiver for *ReadWriter v1.0([n])
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.
Calling Peek prevents a UnreadByte or UnreadRune call from succeeding
until the next read operation.
-
Read
Receiver for *ReadWriter v1.0([p])
Read reads data into p.
It returns the number of bytes read into p.
The bytes are taken from at most one Read on the underlying Reader,
hence n may be less than len(p).
To read exactly len(p) bytes, use io.ReadFull(b, p).
At EOF, the count will be zero and err will be io.EOF.
-
ReadByte
Receiver for *ReadWriter v1.0([])
ReadByte reads and returns a single byte.
If no byte is available, returns an error.
-
ReadBytes
Receiver for *ReadWriter v1.0([delim])
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 io.EOF).
ReadBytes returns err != nil if and only if the returned data does not end in
delim.
For simple uses, a Scanner may be more convenient.
-
ReadFrom
Receiver for *ReadWriter v1.0([r])
ReadFrom implements io.ReaderFrom. If the underlying writer
supports the ReadFrom method, this calls the underlying ReadFrom.
If there is buffered data and an underlying ReadFrom, this fills
the buffer and writes it before calling ReadFrom.
-
ReadLine
Receiver for *ReadWriter v1.0([])
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.
-
ReadRune
Receiver for *ReadWriter v1.0([])
ReadRune reads a single UTF-8 encoded Unicode character and returns the
rune and its size in bytes. If the encoded rune is invalid, it consumes one byte
and returns unicode.ReplacementChar (U+FFFD) with a size of 1.
-
ReadSlice
Receiver for *ReadWriter v1.0([delim])
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.
-
ReadString
Receiver for *ReadWriter v1.0([delim])
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 io.EOF).
ReadString returns err != nil if and only if the returned data does not end in
delim.
For simple uses, a Scanner may be more convenient.
-
UnreadByte
Receiver for *ReadWriter v1.0([])
UnreadByte unreads the last byte. Only the most recently read byte can be unread.
UnreadByte returns an error if the most recent method called on the
Reader was not a read operation. Notably, Peek, Discard, and WriteTo are not
considered read operations.
-
UnreadRune
Receiver for *ReadWriter v1.0([])
UnreadRune unreads the last rune. If the most recent method called on
the Reader 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.)
-
Write
Receiver for *ReadWriter v1.0([p])
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.
-
WriteByte
Receiver for *ReadWriter v1.0([c])
WriteByte writes a single byte.
-
WriteRune
Receiver for *ReadWriter v1.0([r])
WriteRune writes a single Unicode code point, returning
the number of bytes written and any error.
-
WriteString
Receiver for *ReadWriter v1.0([s])
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.
-
WriteTo
Receiver for *ReadWriter v1.0([w])
WriteTo implements io.WriterTo.
This may make multiple calls to the Read method of the underlying Reader.
If the underlying reader supports the WriteTo method,
this calls the underlying WriteTo without buffering.
-
*Reader
Concrete Type v1.0Reader implements buffering for an io.Reader object.
-
Buffered
Receiver for *Reader v1.0([])
Buffered returns the number of bytes that can be read from the current buffer.
-
Discard
Receiver for *Reader v1.0([n])
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.
-
Peek
Receiver for *Reader v1.0([n])
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.
Calling Peek prevents a UnreadByte or UnreadRune call from succeeding
until the next read operation.
-
Read
Receiver for *Reader v1.0([p])
Read reads data into p.
It returns the number of bytes read into p.
The bytes are taken from at most one Read on the underlying Reader,
hence n may be less than len(p).
To read exactly len(p) bytes, use io.ReadFull(b, p).
At EOF, the count will be zero and err will be io.EOF.
-
ReadByte
Receiver for *Reader v1.0([])
ReadByte reads and returns a single byte.
If no byte is available, returns an error.
-
ReadBytes
Receiver for *Reader v1.0([delim])
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 io.EOF).
ReadBytes returns err != nil if and only if the returned data does not end in
delim.
For simple uses, a Scanner may be more convenient.
-
ReadLine
Receiver for *Reader v1.0([])
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.
-
ReadRune
Receiver for *Reader v1.0([])
ReadRune reads a single UTF-8 encoded Unicode character and returns the
rune and its size in bytes. If the encoded rune is invalid, it consumes one byte
and returns unicode.ReplacementChar (U+FFFD) with a size of 1.
-
ReadSlice
Receiver for *Reader v1.0([delim])
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.
-
ReadString
Receiver for *Reader v1.0([delim])
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 io.EOF).
ReadString returns err != nil if and only if the returned data does not end in
delim.
For simple uses, a Scanner may be more convenient.
-
Reset
Receiver for *Reader v1.0([r])
Reset discards any buffered data, resets all state, and switches
the buffered reader to read from r.
Calling Reset on the zero value of Reader initializes the internal buffer
to the default size.
-
Size
Receiver for *Reader v1.0([])
Size returns the size of the underlying buffer in bytes.
-
UnreadByte
Receiver for *Reader v1.0([])
UnreadByte unreads the last byte. Only the most recently read byte can be unread.
UnreadByte returns an error if the most recent method called on the
Reader was not a read operation. Notably, Peek, Discard, and WriteTo are not
considered read operations.
-
UnreadRune
Receiver for *Reader v1.0([])
UnreadRune unreads the last rune. If the most recent method called on
the Reader 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.)
-
WriteTo
Receiver for *Reader v1.0([w])
WriteTo implements io.WriterTo.
This may make multiple calls to the Read method of the underlying Reader.
If the underlying reader supports the WriteTo method,
this calls the underlying WriteTo without buffering.
-
*Scanner
Concrete Type v1.0Scanner provides a convenient interface for reading data such as
a file of newline-delimited lines of text. Successive calls to
the Scan method will step through the 'tokens' of a file, skipping
the bytes between the tokens. The specification of a token is
defined by a split function of type SplitFunc; the default split
function breaks the input into lines with line termination stripped. Split
functions are defined in this package for scanning a file into
lines, bytes, UTF-8-encoded runes, and space-delimited words. The
client may instead provide a custom split function.
Scanning stops unrecoverably at EOF, the first I/O error, or a token too
large to fit in the buffer. When a scan stops, the reader may have
advanced arbitrarily far past the last token. Programs that need more
control over error handling or large tokens, or must run sequential scans
on a reader, should use bufio.Reader instead.
-
Buffer
Receiver for *Scanner v1.0([buf max])
Buffer sets the initial buffer to use when scanning and the maximum
size of buffer that may be allocated during scanning. The maximum
token size is the larger of max and cap(buf). If max <= cap(buf),
Scan will use this buffer only and do no allocation.
By default, Scan uses an internal buffer and sets the
maximum token size to MaxScanTokenSize.
Buffer panics if it is called after scanning has started.
-
Bytes
Receiver for *Scanner v1.0([])
Bytes returns the most recent token generated by a call to Scan.
The underlying array may point to data that will be overwritten
by a subsequent call to Scan. It does no allocation.
-
Err
Receiver for *Scanner v1.0([])
Err returns the first non-EOF error that was encountered by the Scanner.
-
Scan
Receiver for *Scanner v1.0([])
Scan advances the Scanner to the next token, which will then be
available through the Bytes or Text method. It returns false when the
scan stops, either by reaching the end of the input or an error.
After Scan returns false, the Err method will return any error that
occurred during scanning, except that if it was io.EOF, Err
will return nil.
Scan panics if the split function returns too many empty
tokens without advancing the input. This is a common error mode for
scanners.
-
Split
Receiver for *Scanner v1.0([split])
Split sets the split function for the Scanner.
The default split function is ScanLines.
Split panics if it is called after scanning has started.
-
Text
Receiver for *Scanner v1.0([])
Text returns the most recent token generated by a call to Scan
as a newly allocated string holding its bytes.
-
*SplitFunc
Concrete Type v1.0SplitFunc is the signature of the split function used to tokenize the
input. The arguments are an initial substring of the remaining unprocessed
data and a flag, atEOF, that reports whether the Reader has no more data
to give. The return values are the number of bytes to advance the input
and the next token to return to the user, if any, plus an error, if any.
Scanning stops if the function returns an error, in which case some of
the input may be discarded. If that error is ErrFinalToken, scanning
stops with no error.
Otherwise, the Scanner advances the input. If the token is not nil,
the Scanner returns it to the user. If the token is nil, the
Scanner reads more data and continues scanning; if there is no more
data--if atEOF was true--the Scanner returns. If the data does not
yet hold a complete token, for instance if it has no newline while
scanning lines, a SplitFunc can return (0, nil, nil) to signal the
Scanner to read more data into the slice and try again with a
longer slice starting at the same point in the input.
The function is never called with an empty data slice unless atEOF
is true. If atEOF is true, however, data may be non-empty and,
as always, holds unprocessed text.
-
*Writer
Concrete Type v1.0Writer 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, and Flush, 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.
-
Available
Receiver for *Writer v1.0([])
Available returns how many bytes are unused in the buffer.
-
AvailableBuffer
Receiver for *Writer v1.0([])
AvailableBuffer returns an empty buffer with b.Available() capacity.
This buffer is intended to be appended to and
passed to an immediately succeeding Write call.
The buffer is only valid until the next write operation on b.
-
Buffered
Receiver for *Writer v1.0([])
Buffered returns the number of bytes that have been written into the current buffer.
-
Flush
Receiver for *Writer v1.0([])
Flush writes any buffered data to the underlying io.Writer.
-
ReadFrom
Receiver for *Writer v1.0([r])
ReadFrom implements io.ReaderFrom. If the underlying writer
supports the ReadFrom method, this calls the underlying ReadFrom.
If there is buffered data and an underlying ReadFrom, this fills
the buffer and writes it before calling ReadFrom.
-
Reset
Receiver for *Writer v1.0([w])
Reset discards any unflushed buffered data, clears any error, and
resets b to write its output to w.
Calling Reset on the zero value of Writer initializes the internal buffer
to the default size.
-
Size
Receiver for *Writer v1.0([])
Size returns the size of the underlying buffer in bytes.
-
Write
Receiver for *Writer v1.0([p])
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.
-
WriteByte
Receiver for *Writer v1.0([c])
WriteByte writes a single byte.
-
WriteRune
Receiver for *Writer v1.0([r])
WriteRune writes a single Unicode code point, returning
the number of bytes written and any error.
-
WriteString
Receiver for *Writer v1.0([s])
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.
-
ReadWriter
Concrete Type v1.0ReadWriter stores pointers to a Reader and a Writer.
It implements io.ReadWriter.
-
Available
Receiver for ReadWriter v1.0([])
Available returns how many bytes are unused in the buffer.
-
AvailableBuffer
Receiver for ReadWriter v1.0([])
AvailableBuffer returns an empty buffer with b.Available() capacity.
This buffer is intended to be appended to and
passed to an immediately succeeding Write call.
The buffer is only valid until the next write operation on b.
-
Discard
Receiver for ReadWriter v1.0([n])
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.
-
Flush
Receiver for ReadWriter v1.0([])
Flush writes any buffered data to the underlying io.Writer.
-
Peek
Receiver for ReadWriter v1.0([n])
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.
Calling Peek prevents a UnreadByte or UnreadRune call from succeeding
until the next read operation.
-
Read
Receiver for ReadWriter v1.0([p])
Read reads data into p.
It returns the number of bytes read into p.
The bytes are taken from at most one Read on the underlying Reader,
hence n may be less than len(p).
To read exactly len(p) bytes, use io.ReadFull(b, p).
At EOF, the count will be zero and err will be io.EOF.
-
ReadByte
Receiver for ReadWriter v1.0([])
ReadByte reads and returns a single byte.
If no byte is available, returns an error.
-
ReadBytes
Receiver for ReadWriter v1.0([delim])
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 io.EOF).
ReadBytes returns err != nil if and only if the returned data does not end in
delim.
For simple uses, a Scanner may be more convenient.
-
ReadFrom
Receiver for ReadWriter v1.0([r])
ReadFrom implements io.ReaderFrom. If the underlying writer
supports the ReadFrom method, this calls the underlying ReadFrom.
If there is buffered data and an underlying ReadFrom, this fills
the buffer and writes it before calling ReadFrom.
-
ReadLine
Receiver for ReadWriter v1.0([])
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.
-
ReadRune
Receiver for ReadWriter v1.0([])
ReadRune reads a single UTF-8 encoded Unicode character and returns the
rune and its size in bytes. If the encoded rune is invalid, it consumes one byte
and returns unicode.ReplacementChar (U+FFFD) with a size of 1.
-
ReadSlice
Receiver for ReadWriter v1.0([delim])
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.
-
ReadString
Receiver for ReadWriter v1.0([delim])
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 io.EOF).
ReadString returns err != nil if and only if the returned data does not end in
delim.
For simple uses, a Scanner may be more convenient.
-
UnreadByte
Receiver for ReadWriter v1.0([])
UnreadByte unreads the last byte. Only the most recently read byte can be unread.
UnreadByte returns an error if the most recent method called on the
Reader was not a read operation. Notably, Peek, Discard, and WriteTo are not
considered read operations.
-
UnreadRune
Receiver for ReadWriter v1.0([])
UnreadRune unreads the last rune. If the most recent method called on
the Reader 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.)
-
Write
Receiver for ReadWriter v1.0([p])
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.
-
WriteByte
Receiver for ReadWriter v1.0([c])
WriteByte writes a single byte.
-
WriteRune
Receiver for ReadWriter v1.0([r])
WriteRune writes a single Unicode code point, returning
the number of bytes written and any error.
-
WriteString
Receiver for ReadWriter v1.0([s])
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.
-
WriteTo
Receiver for ReadWriter v1.0([w])
WriteTo implements io.WriterTo.
This may make multiple calls to the Read method of the underlying Reader.
If the underlying reader supports the WriteTo method,
this calls the underlying WriteTo without buffering.
-
Reader
Concrete Type v1.0Reader implements buffering for an io.Reader object.
-
Scanner
Concrete Type v1.0Scanner provides a convenient interface for reading data such as
a file of newline-delimited lines of text. Successive calls to
the Scan method will step through the 'tokens' of a file, skipping
the bytes between the tokens. The specification of a token is
defined by a split function of type SplitFunc; the default split
function breaks the input into lines with line termination stripped. Split
functions are defined in this package for scanning a file into
lines, bytes, UTF-8-encoded runes, and space-delimited words. The
client may instead provide a custom split function.
Scanning stops unrecoverably at EOF, the first I/O error, or a token too
large to fit in the buffer. When a scan stops, the reader may have
advanced arbitrarily far past the last token. Programs that need more
control over error handling or large tokens, or must run sequential scans
on a reader, should use bufio.Reader instead.
-
SplitFunc
Concrete Type v1.0SplitFunc is the signature of the split function used to tokenize the
input. The arguments are an initial substring of the remaining unprocessed
data and a flag, atEOF, that reports whether the Reader has no more data
to give. The return values are the number of bytes to advance the input
and the next token to return to the user, if any, plus an error, if any.
Scanning stops if the function returns an error, in which case some of
the input may be discarded. If that error is ErrFinalToken, scanning
stops with no error.
Otherwise, the Scanner advances the input. If the token is not nil,
the Scanner returns it to the user. If the token is nil, the
Scanner reads more data and continues scanning; if there is no more
data--if atEOF was true--the Scanner returns. If the data does not
yet hold a complete token, for instance if it has no newline while
scanning lines, a SplitFunc can return (0, nil, nil) to signal the
Scanner to read more data into the slice and try again with a
longer slice starting at the same point in the input.
The function is never called with an empty data slice unless atEOF
is true. If atEOF is true, however, data may be non-empty and,
as always, holds unprocessed text.
-
Writer
Concrete Type v1.0Writer 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, and Flush, 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.
-
arrayOfReadWriter
Concrete Type v1.0ReadWriter stores pointers to a Reader and a Writer.
It implements io.ReadWriter.
-
arrayOfReader
Concrete Type v1.0Reader implements buffering for an io.Reader object.
-
arrayOfScanner
Concrete Type v1.0Scanner provides a convenient interface for reading data such as
a file of newline-delimited lines of text. Successive calls to
the Scan method will step through the 'tokens' of a file, skipping
the bytes between the tokens. The specification of a token is
defined by a split function of type SplitFunc; the default split
function breaks the input into lines with line termination stripped. Split
functions are defined in this package for scanning a file into
lines, bytes, UTF-8-encoded runes, and space-delimited words. The
client may instead provide a custom split function.
Scanning stops unrecoverably at EOF, the first I/O error, or a token too
large to fit in the buffer. When a scan stops, the reader may have
advanced arbitrarily far past the last token. Programs that need more
control over error handling or large tokens, or must run sequential scans
on a reader, should use bufio.Reader instead.
-
arrayOfSplitFunc
Concrete Type v1.0SplitFunc is the signature of the split function used to tokenize the
input. The arguments are an initial substring of the remaining unprocessed
data and a flag, atEOF, that reports whether the Reader has no more data
to give. The return values are the number of bytes to advance the input
and the next token to return to the user, if any, plus an error, if any.
Scanning stops if the function returns an error, in which case some of
the input may be discarded. If that error is ErrFinalToken, scanning
stops with no error.
Otherwise, the Scanner advances the input. If the token is not nil,
the Scanner returns it to the user. If the token is nil, the
Scanner reads more data and continues scanning; if there is no more
data--if atEOF was true--the Scanner returns. If the data does not
yet hold a complete token, for instance if it has no newline while
scanning lines, a SplitFunc can return (0, nil, nil) to signal the
Scanner to read more data into the slice and try again with a
longer slice starting at the same point in the input.
The function is never called with an empty data slice unless atEOF
is true. If atEOF is true, however, data may be non-empty and,
as always, holds unprocessed text.
-
arrayOfWriter
Concrete Type v1.0Writer 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, and Flush, 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.