Skip to content

Reader

Mojo trait 🡭

Trait for reading bytes from a source (file, memory, gzip, etc.).

Implement this trait to provide a custom data source to FastqParser via BufferedReader. read_to_buffer() fills the given buffer span and returns the number of bytes read (0 at EOF). The parser uses this with LineIterator / BufferedReader for efficient line-based parsing.

Example: mojo from blazeseq.io.readers import Reader struct MyReader(Reader): def read_to_buffer(mut self, mut buf: Span[Byte, MutExternalOrigin], amt: Int, pos: Int) raises -> UInt64: # ... copy up to amt bytes from your source into buf starting at pos var bytes_read: Int = 0 return UInt64(bytes_read) def __init__(out self, *, deinit take: Self): ...

AnyType, ImplicitlyDestructible, Movable

def __init__(out self: _Self, *, deinit take: _Self)

Args:

  • take (_Self)
  • self (_Self)

Returns:

_Self

def read_to_buffer(mut self: _Self, mut buf: Span[Byte, MutExternalOrigin], amt: Int, pos: Int) -> UInt64

Read up to amt bytes into buf at offset pos. Returns bytes read (0 at EOF).

Args:

  • self (_Self)
  • buf (Span)
  • amt (Int)
  • pos (Int)

Returns:

UInt64

Raises: