std/bufio
On this page
Index
- type
BufErr- method
BufErr.display
- method
- type
Reader- method
Reader.read - method
Reader.read_until - method
Reader.read_line - method
Reader.read_exact - method
Reader.peek - method
Reader.buffered
- method
- fn
reader
Types
BufErr
enum BufErr {
Net(err: NetErr)
TooLong
UnexpectedEof
}Why a read failed: the stream’s own error (a timeout, a cancellation,
a reset), a record longer than the limit given (a caller closes the
connection), or the stream ending before read_exact
had its bytes. Displays as the stream’s error text, bufio: record too long and bufio: unexpected EOF.
BufErr.display
fn (e: BufErr) display() -> StrReader
struct Reader {}A reader over a stream (move only: its buffer belongs to it, and bytes it read are not given back to the stream).
Reader.read
fn (var r: Reader) read(max: Int) -> Bytes? ! NetErr uses netUp to max bytes: what is buffered, else one read of the stream; None at the end of the stream (Go’s Read).
Reader.read_until
fn (var r: Reader) read_until(delim: UInt8, limit: Int = 1048576) -> Bytes? ! BufErr uses netThe bytes up to and including the next delim (Go’s ReadBytes). None
at the end of the stream with nothing left; at its end with bytes left
and no delimiter, those bytes are the last record. TooLong when
limit bytes come without a delimiter, so a peer cannot grow it
without bound; the chunks of the record already gathered are dropped
and the current chunk stays buffered, so a caller closes the connection.
Reader.read_line
fn (var r: Reader) read_line(limit: Int = 1048576) -> Str? ! BufErr uses netThe next line without its “\n” or “\r\n” (Go’s ReadString(’\n’) with the line ending trimmed, as bufio.Scanner’s ScanLines), invalid UTF-8 replaced by U+FFFD; a last line without an ending is a line. None at the end with nothing left.
Reader.read_exact
fn (var r: Reader) read_exact(n: Int) -> Bytes ! BufErr uses netExactly n bytes (Go’s io.ReadFull); UnexpectedEof when the stream ends
first (what was read is lost); n 0 is empty.
Reader.peek
fn (var r: Reader) peek(n: Int) -> Bytes ! BufErr uses netThe next n bytes without consuming them (Go’s Peek), fewer only when the stream ends first. Reads from the stream to fill.
Reader.buffered
fn (r: Reader) buffered() -> IntThe bytes buffered and not yet read (Go’s Buffered).
Functions
reader
fn reader(s: Stream, size: Int = 4096) -> ReaderA reader over s that reads size bytes at a time (Go’s NewReaderSize;
4096 is Go’s default, and at least 16 is used).