EgretDoc
Back to Home
Location:system/io

Module

Module documentation.

moduleio
@briefBuffered I/O
@detailsProvides buffered Reader/Scanner helpers for line-based and delimiter-based reads.
@see
  • index.html

Classes

Classes and inheritance.

classio::DelimitedReader
@briefDelimitedReader for delimiter-based reads
@noteAn empty delim will not advance pos.
@see
  • io.StringReader
class DelimitedReader {
    /*
    @brief Underlying reader
classio::Scanner
@briefLine scanner
@see
  • io.StringReader
class Scanner {
    /*
    @brief Underlying reader
classio::StringReader
@briefStringReader
class StringReader {
    /*
    @brief Input data
classio::StringWriter
@briefStringWriter
class StringWriter {
    /*
    @brief Internal buffer
classio::BufReader<T
Base: io.Reader>
@brief`BufReader` type.
@details`BufReader` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
@noteInherits from `io.Reader>`.
class BufReader<T: io.Reader> {
    /*
    @brief `r` field.
classio::BufWriter<T
Base: io.Writer>
@brief`BufWriter` type.
@details`BufWriter` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
@noteInherits from `io.Writer>`.
class BufWriter<T: io.Writer> {
    /*
    @brief `w` field.

Functions

Free functions and class methods.

functionio::DelimitedReader.init
Signaturefunc init(self: io.DelimitedReader, r: io.StringReader) -> Void
    func init(self: io.DelimitedReader, r: io.StringReader) -> Void {
        self.r = r;
    }
@briefInitialize a Reader
@detailsBinds an io.StringReader as the data source.
@param
  • selfReader instance
  • rUnderlying reader (its pos will be advanced)
@returnVoid
functionio::DelimitedReader.deinit
Signaturefunc deinit(self: io.DelimitedReader) -> Void
    func deinit(self: io.DelimitedReader) -> Void {
    }
@briefReleases fallback resources at the end of the `DelimitedReader` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionio::DelimitedReader.read_string
Signaturefunc read_string(self: io.DelimitedReader, delim: String) -> String
    func read_string(self: io.DelimitedReader, delim: String) -> String {
        let s: String = self.r.s;
        let i: Int = self.r.pos;
@briefRead until delimiter
@param
  • selfReader instance
  • delimDelimiter string (should be non-empty in most cases)
@returnThe read substring
functionio::Scanner.init
Signaturefunc init(self: io.Scanner, r: io.StringReader) -> Void
    func init(self: io.Scanner, r: io.StringReader) -> Void {
        self.r = r;
        self.current_text = "";
@briefInitialize a Scanner
@detailsBinds the underlying io.StringReader and resets text to an empty string.
@param
  • selfScanner instance
  • rUnderlying reader
@returnVoid
functionio::Scanner.deinit
Signaturefunc deinit(self: io.Scanner) -> Void
    func deinit(self: io.Scanner) -> Void {
    }
@briefReleases fallback resources at the end of the `Scanner` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionio::Scanner.scan
Signaturefunc scan(self: io.Scanner) -> Bool
    func scan(self: io.Scanner) -> Bool {
        let s: String = self.r.s;
        if self.r.pos >= std.len(s) {
@briefScan the next line
@param
  • selfScanner instance
@returntrue if a line was read.
functionio::Scanner.text
Signaturefunc text(self: io.Scanner) -> String
    func text(self: io.Scanner) -> String {
        return self.current_text;
    }
@briefGet the most recently scanned line
@detailsEquivalent to returning the most recent scanned line.
@param
  • selfScanner instance
@returnThe line read by the most recent scan() call
functionio::StringReader.init
Signaturefunc init(self: io.StringReader, s: String) -> Void
    func init(self: io.StringReader, s: String) -> Void {
        self.s = s;
        self.pos = 0;
@briefInitialize the reader
@param
  • selfStringReader instance
  • sSource string
@returnVoid
functionio::StringReader.deinit
Signaturefunc deinit(self: io.StringReader) -> Void
    func deinit(self: io.StringReader) -> Void {
    }
@briefReleases fallback resources at the end of the `StringReader` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionio::StringReader.eof
Signaturefunc eof(self: io.StringReader) -> Bool
    func eof(self: io.StringReader) -> Bool {
        return self.pos >= std.len(self.s);
    }
@briefCheck EOF
@detailsReturns true when pos >= len(s).
@param
  • selfStringReader instance
@returnWhether EOF has been reached
functionio::StringReader.read
Signaturefunc read(self: io.StringReader, n: Int) -> String
    func read(self: io.StringReader, n: Int) -> String {
        if n <= 0 {
            return "";
@briefRead up to n characters
@param
  • selfStringReader instance
  • nMaximum number of characters to read
@returnThe read substring
functionio::StringReader.read_all
Signaturefunc read_all(self: io.StringReader) -> String
    func read_all(self: io.StringReader) -> String {
        return self.read(2147483647);
    }
@briefRead all remaining content
@detailsEquivalent to read(2147483647).
@param
  • selfStringReader instance
@returnRemaining content
functionio::StringWriter.init
Signaturefunc init(self: io.StringWriter) -> Void
    func init(self: io.StringWriter) -> Void {
        self.s = "";
    }
@briefInitialize the writer
@detailsResets the internal buffer to an empty string.
@param
  • selfStringWriter instance
@returnVoid
functionio::StringWriter.deinit
Signaturefunc deinit(self: io.StringWriter) -> Void
    func deinit(self: io.StringWriter) -> Void {
    }
@briefReleases fallback resources at the end of the `StringWriter` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionio::StringWriter.write
Signaturefunc write(self: io.StringWriter, x: String) -> Void
    func write(self: io.StringWriter, x: String) -> Void {
        self.s += x;
    }
@briefAppend a string
@param
  • selfStringWriter instance
  • xContent to append
@returnVoid
functionio::StringWriter.str
Signaturefunc str(self: io.StringWriter) -> String
    func str(self: io.StringWriter) -> String {
        return self.s;
    }
@briefGet accumulated content
@param
  • selfStringWriter instance
@returnCurrent accumulated string
functionio::BufReader<T.init
Signaturefunc init(self: io.BufReader<T>, r: T) -> Void
    func init(self: io.BufReader<T>, r: T) -> Void {
        self.r = r;
        self.buf = "";
@briefInitializes a `BufReader` instance.
@detailsEstablishes the initial field state for `BufReader` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
  • rResult object, reader object, or range value consumed by the operation.
@returnVoid
functionio::BufReader<T.deinit
Signaturefunc deinit(self: io.BufReader<T>) -> Void
    func deinit(self: io.BufReader<T>) -> Void {
    }
@briefReleases fallback resources at the end of the `BufReader` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionio::BufReader<T.fill
Signaturefunc fill(self: io.BufReader<T>, max_bytes: Int) -> Int, ErrCode
    func fill(self: io.BufReader<T>, max_bytes: Int) -> Int, ErrCode {
        let chunk: bytes.Bytes = io.Reader<T>.read(self.r, max_bytes)?;
        self.buf += chunk;
@briefProvides the system library operation `BufReader.fill`.
@detailsExecutes the `fill` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
  • max_bytesMaximum number of bytes to read or process in this operation.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionio::BufReader<T.read
Signaturefunc read(self: io.BufReader<T>, max_bytes: Int) -> bytes.Bytes, ErrCode
    func read(self: io.BufReader<T>, max_bytes: Int) -> bytes.Bytes, ErrCode {
        if max_bytes <= 0 {
            return "", std.OK;
@briefReads data with `BufReader.read`.
@detailsExecutes the `read` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
  • max_bytesMaximum number of bytes to read or process in this operation.
@returnReturns `bytes.Bytes, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionio::BufWriter<T.init
Signaturefunc init(self: io.BufWriter<T>, w: T, max_buffer: Int = 4096) -> Void
    func init(self: io.BufWriter<T>, w: T, max_buffer: Int = 4096) -> Void {
        self.w = w;
        self.buf = "";
@briefInitializes a `BufWriter` instance.
@detailsEstablishes the initial field state for `BufWriter` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
  • wWriter, weight, width, or second operand consumed by the operation.
  • max_bufferMaximum allowed count or byte size.
@returnVoid
functionio::BufWriter<T.deinit
Signaturefunc deinit(self: io.BufWriter<T>) -> Void
    func deinit(self: io.BufWriter<T>) -> Void {
    }
@briefReleases fallback resources at the end of the `BufWriter` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionio::BufWriter<T.write
Signaturefunc write(self: io.BufWriter<T>, data: bytes.Bytes) -> Int, ErrCode
    func write(self: io.BufWriter<T>, data: bytes.Bytes) -> Int, ErrCode {
        self.buf += data;
        if bytes.len(self.buf) >= self.max_buffer {
@briefWrites data with `BufWriter.write`.
@detailsExecutes the `write` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
  • dataInput or output data buffer.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionio::BufWriter<T.flush
Signaturefunc flush(self: io.BufWriter<T>) -> Int, ErrCode
    func flush(self: io.BufWriter<T>) -> Int, ErrCode {
        if bytes.len(self.buf) == 0 {
            return 0, std.OK;
@briefFlushes buffered data with `BufWriter.flush`.
@detailsExecutes the `flush` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionio::copy<R
Signaturefunc copy<R: io.Reader, W: io.Writer>(r: R, w: W, max_bytes: Int) -> Int, ErrCode
func copy<R: io.Reader, W: io.Writer>(r: R, w: W, max_bytes: Int) -> Int, ErrCode {
    let total: Int = 0;
    loop (; true; ) {
@briefProvides the system library operation `copy`.
@detailsExecutes the `copy` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • rResult object, reader object, or range value consumed by the operation.
  • wWriter, weight, width, or second operand consumed by the operation.
  • max_bytesMaximum number of bytes to read or process in this operation.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionio::read_all<R
Signaturefunc read_all<R: io.Reader>(r: R, max_bytes: Int = -1) -> String, ErrCode
func read_all<R: io.Reader>(r: R, max_bytes: Int = -1) -> String, ErrCode {
    let out: String = "";
    let total: Int = 0;
@briefReads all available data with `read_all`.
@detailsExecutes the `read_all` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • rResult object, reader object, or range value consumed by the operation.
  • max_bytesMaximum number of bytes to read or process in this operation.
@returnReturns `String, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.

Variables

Class fields (var).

vario::DelimitedReader.r
Typeio.StringReader
@briefUnderlying reader
    var r: io.StringReader;

    /*
vario::Scanner.r
Typeio.StringReader
@briefUnderlying reader
@detailsThe io.StringReader to scan from (scan advances its pos)
    var r: io.StringReader;

    /*
vario::Scanner.current_text
TypeString
@briefMost recent line
@detailsThe line content read by the most recent scan() call (without newline)
    var current_text: String;

    /*
vario::StringReader.s
TypeString
@briefInput data
@detailsThe source string to read from
    var s: String;

    /*
vario::StringReader.pos
TypeInt
@briefCurrent read position
@detailsIndex of the next character to read
    var pos: Int;

    /*
vario::StringWriter.s
TypeString
@briefInternal buffer
@detailsHolds the accumulated string
    var s: String;

    /*
vario::BufReader<T.r
TypeT
@brief`r` field.
@detailsHolds the `r` value for each `BufReader` instance. The field type is `T`, and constructors and methods keep it synchronized with the object's runtime state.
    var r: T;
    /*
    @brief `buf` field.
vario::BufReader<T.buf
Typebytes.Bytes
@brief`buf` field.
@detailsStores the internal buffer. The field type is `bytes.Bytes`, and it is maintained by the constructors and methods of `BufReader`.
    var buf: bytes.Bytes;
    /*
    @brief `pos` field.
vario::BufReader<T.pos
TypeInt
@brief`pos` field.
@detailsHolds the `pos` value for each `BufReader` instance. The field type is `Int`, and constructors and methods keep it synchronized with the object's runtime state.
    var pos: Int;

    /*
vario::BufWriter<T.w
TypeT
@brief`w` field.
@detailsHolds the `w` value for each `BufWriter` instance. The field type is `T`, and constructors and methods keep it synchronized with the object's runtime state.
    var w: T;
    /*
    @brief `buf` field.
vario::BufWriter<T.buf
Typebytes.Bytes
@brief`buf` field.
@detailsStores the internal buffer. The field type is `bytes.Bytes`, and it is maintained by the constructors and methods of `BufWriter`.
    var buf: bytes.Bytes;
    /*
    @brief `pos` field.
vario::BufWriter<T.max_buffer
TypeInt
@brief`max_buffer` field.
@detailsHolds the `max_buffer` value for each `BufWriter` instance. The field type is `Int`, and constructors and methods keep it synchronized with the object's runtime state.
    var max_buffer: Int;

    /*