Skip to content

Buffered Reader

1 min read

Import: import system.io;

BufferedReader

Reads ahead from a borrowed reader without closing it; use this wrapper for positioning while buffered bytes remain, or recover them before accessing the source directly.

public class BufferedReader: Reader

constructor

Wraps source with an 8 KiB default buffer; nonpositive sizes fail on reads.

public constructor(source: Reader, buffer_size: int = 8192)

read

Returns up to max_bytes from buffered input, refilling as needed; may return fewer. Zero is a no-op, negative sizes are invalid, and empty success for positive sizes is EOF.

public fun read(max_bytes: int): Result<byte[], IoError>

read_line

Returns a line without LF or CRLF, preserving standalone CR and final unterminated lines. Returns None at EOF; ELIMIT consumes the prefix and exceeding byte when the pre-LF byte count exceeds max_bytes (default 1 MiB, including any CR).

public fun read_line(max_bytes: int = 1048576): Result<Option<string>, IoError>

seek

Seeks the source and discards buffered input only after success. Unsupported or failed seeks preserve unread buffered bytes.

public fun seek(position: long): Result<Unit, IoError>

tell

Returns the source position minus unread buffered bytes; propagates positioning errors.

public fun tell(): Result<long, IoError>

take_buffered

Copies and removes unread buffered bytes without repositioning the source. Recover these bytes before bypassing this wrapper to access the source directly.

public fun take_buffered(): byte[]