MemoryReader
Mojo struct 🡭
MemoryReader
Section titled “MemoryReader”@memory_onlystruct MemoryReaderReader that reads from an in-memory buffer.
Use for testing, benchmarking (without disk I/O), or when FASTQ data is already in memory. Implements the same Reader trait as FileReader and GZFile.
Fields
Section titled “Fields”- data (
List[UInt8]) - position (
Int)
Implemented traits
Section titled “Implemented traits”AnyType, ImplicitlyDestructible, Movable, Reader
Methods
Section titled “Methods”__init__
Section titled “__init__”fn __init__(out self, var data: List[UInt8])Initialize with an owned List[Byte] buffer. Takes ownership of data.
Args:
- data (
List[UInt8]) - self (
Self)
Returns:
Self
fn __init__(out self, data: Span[UInt8])Initialize with a Span[Byte]; bytes are copied into an internal list.
Args:
- data (
Span[UInt8]) - self (
Self)
Returns:
Self
fn __init__(out self, var content: String)Initialize from a string; copies its bytes into an internal buffer.
Args:
- content (
String) - self (
Self)
Returns:
Self
Raises:
fn __init__(out self, *, deinit take: Self)Move constructor for Movable trait compliance.
Args:
- take (
Self) - self (
Self)
Returns:
Self
read_to_buffer
Section titled “read_to_buffer”fn read_to_buffer(mut self, mut buf: Span[UInt8, MutExternalOrigin], amt: Int, pos: Int = 0) -> UInt64Read bytes from the memory buffer into the destination buffer.
Args:
- self (
Self) - buf (
Span[UInt8, MutExternalOrigin]): The destination buffer to write into. - amt (
Int): The number of bytes to read. - pos (
Int): The position in the destination buffer to start writing.
Returns:
UInt64: The number of bytes actually read (0 if EOF).
Raises:
fn reset(mut self)Reset the read position to the start. Use to re-read the same buffer (e.g. for benchmarking).
Args:
- self (
Self)