DelimitedReader
Mojo struct 🡭
DelimitedReader
Section titled “DelimitedReader”@memory_onlystruct DelimitedReader[R: Reader, P: LinePolicy = DefaultLinePolicy, MAX: Int = 64]Generic delimited-file reader over a Reader.
Suitable for uncomplicated delimited files without quoting (no quoting, no escaping), FAI, BED, GFF, and similar bioinformatic formats.
The hot path — next_view() / for view in dr.views() — yields a
DelimitedView with zero heap allocations per row: the span
lives in the reader’s internal buffer and the offsets are stack-allocated.
Call .to_record() on the view when you need the record to outlive the
current iteration step; next_record() / for record in dr.records() do
this automatically (one BString alloc per row).
for view in dr (i.e. __iter__) defaults to the zero-alloc view path.
Example — filter without allocating on every row: ```mojo from blazeseq.io import DelimitedReader, FileReader from std.pathlib import Path from blazeseq.io import DelimitedRecord
var reader = FileReader(Path("data.tsv"))var dr = DelimitedReader[FileReader](reader^, has_header=True)var results = List[DelimitedRecord[64]]()while dr.has_more(): var view = dr.next_view() if String(view.get_span(2)) == "homo_sapiens": results.append(view^.to_record()) # alloc only on match```Parameters
Section titled “Parameters”- R (
Reader) - P (
LinePolicy) - MAX (
Int)
Fields
Section titled “Fields”- lines (
LineIterator[R]) - policy (
P)
Implemented traits
Section titled “Implemented traits”AnyType, ImplicitlyDestructible, Movable
Methods
Section titled “Methods”__init__
Section titled “__init__”def __init__(out self, var reader: R, delimiter: UInt8 = ord("\t"), has_header: Bool = False)Args:
- reader (
R) - delimiter (
UInt8) - has_header (
Bool) - self (
Self)
Returns:
Self
Raises:
has_more
Section titled “has_more”def has_more(self) -> BoolArgs:
- self (
Self)
Returns:
Bool
header
Section titled “header”def header(ref self) -> Optional[DelimitedRecord[MAX]]Copy of the stored header record, if present.
Args:
- self (
Self)
Returns:
Optional
next_view
Section titled “next_view”def next_view(mut self) -> DelimitedView[MutExternalOrigin, MAX]Return the next row as a zero-alloc DelimitedView.
The view borrows from the reader’s internal line buffer and is
invalidated on the next call to any advancing method. Call
.to_record() to obtain an owned DelimitedRecord.
Raises EOFError when no more records are available.
Args:
- self (
Self)
Returns:
DelimitedView
Raises:
next_record
Section titled “next_record”def next_record(mut self) -> DelimitedRecord[MAX]Return the next row as an owned DelimitedRecord.
Convenience wrapper around next_view().to_record().
Raises EOFError when no more records are available.
Args:
- self (
Self)
Returns:
DelimitedRecord
Raises:
def views(ref self) -> _DelimitedViewIter[R, P, MAX, origin_of(self)]Iterator yielding zero-alloc DelimitedViews.
Args:
- self (
Self)
Returns:
_DelimitedViewIter
records
Section titled “records”def records(ref self) -> _DelimitedRecordIter[R, P, MAX, origin_of(self)]Iterator yielding owned DelimitedRecords.
Args:
- self (
Self)
Returns:
_DelimitedRecordIter
__iter__
Section titled “__iter__”def __iter__(ref self) -> _DelimitedViewIter[R, P, MAX, origin_of(self)]Default iteration yields zero-alloc views.
Args:
- self (
Self)
Returns:
_DelimitedViewIter