Standard library
std/bufio
Buffered reading and writing on top of io.Reader / io.Writer.
var input = bufio.reader(os.stdin())
loop {
let line = try input.readLine() ?? break
...
}
var out = bufio.writer(os.stdout())
try out.writeText("many small writes, one system call\n")
try out.flush()Types: struct Reader, struct Writer
Types
struct Reader
pub struct Reader[R: io.Reader] {
// and private fields
}Reads from R in large chunks, and line by line.
Reader.readByte
pub fn readByte(inout self) -> ?byte ! io.ErrorThe next byte, or none at the end.
Reader.readUntil
pub fn readUntil(inout self, delim: byte) -> ?Vec[byte] ! io.ErrorEverything up to and including delim (or to the end), or none when
nothing is left.
Reader.readLine
pub fn readLine(inout self) -> ?String ! io.ErrorThe next line without its "\n" (or "\r\n"), or none at the end.
Reader.read
pub fn read(inout self, buf: inout Vec[byte], max: int) -> int ! io.ErrorAs an io.Reader: what is buffered first.
Reader.readAll
pub fn readAll(inout self) -> Vec[byte] ! io.ErrorEverything that is left.
struct Writer
pub struct Writer[W: io.Writer] {
// and private fields
}Collects small writes and passes them to W in large ones (64 KB). What is
still buffered is written when the writer is dropped, but call flush to
see errors.
Writer.write
pub fn write(inout self, data: []byte) ! io.ErrorBuffers data (large writes go straight through).
Writer.writeText
pub fn writeText(inout self, s: str) ! io.ErrorBuffers the bytes of s.
Writer.flush
pub fn flush(inout self) ! io.ErrorWrites out everything buffered.
Functions
reader
pub fn reader[R: io.Reader](src: sink R) -> Reader[R]A buffered reader on src (which it owns).
writer
pub fn writer[W: io.Writer](dst: sink W) -> Writer[W]A buffered writer on dst (which it owns).