Skip to content

std.bufio

buffered io::Reader/io::Writer wrappers; the caller owns the buffer

pub BufReader :: struct {
src: *Reader,
buf: []u8,
start: usize,
end: usize,
at_end: bool,
failed: bool,
}

unread bytes are buf[start..end]

pub buffered :: fn(self: *Self) -> []const u8

read but not yet taken

pub fill :: fn(self: *Self) -> usize ! IoError

compacts, reads more from src; returns bytes added (0 at end or when full)

pub read_byte :: fn(self: *Self) -> ?u8 ! IoError

null at the end

pub read_until :: fn(self: *Self, delim: u8) -> ?[]const u8 ! IoError

up to delim, excluded; the tail at end, then null; buffer_full if no delim fits slice into the buffer; valid until the next read

pub read_line :: fn(self: *Self) -> ?[]const u8 ! IoError

like read_until(‘\n’), “\r” stripped too; no empty last line

pub lines :: fn(self: *Self) -> Lines

remaining lines; a failed read ends the loop and sets failed

pub Lines :: struct {
r: *BufReader,
}

iterator from BufReader.lines

pub next :: fn(self: *Self) -> ?[]const u8
pub reader :: fn(src: *Reader, buf: []u8) -> BufReader

uses buf as the buffer

pub reader_in :: fn(a: *Arena, src: *Reader, size: usize) -> BufReader

size-byte buffer in a

pub BufWriter :: struct {
dst: *Writer,
buf: []u8,
n: usize,
}

buf[0..n] waits to be written; flush writes it

pub drain :: fn(self: *Self) -> void ! IoError

writes the buffer to dst; does not flush dst

pub writer :: fn(dst: *Writer, buf: []u8) -> BufWriter

uses buf as the buffer

pub writer_in :: fn(a: *Arena, dst: *Writer, size: usize) -> BufWriter

size-byte buffer in a

pub read_all :: fn(a: *Arena, src: *Reader) -> []u8 ! IoError

reads src to its end into a