Skip to content

MemoryReader

Mojo struct 🡭

@memory_only
struct MemoryReader

Reader 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.

  • data (List[Byte])
  • position (Int)

AnyType, ImplicitlyDestructible, Movable, Reader

def __init__(out self, var data: List[Byte])

Initialize with an owned List[Byte] buffer. Takes ownership of data.

Args:

  • data (List)
  • self (Self)

Returns:

Self

def __init__(out self, data: Span[Byte, data.origin])

Initialize with a Span[Byte]; bytes are copied into an internal list.

Args:

  • data (Span)
  • self (Self)

Returns:

Self

def __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:

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

Move constructor for Movable trait compliance.

Args:

  • take (Self)
  • self (Self)

Returns:

Self

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

Read bytes from the memory buffer into the destination buffer.

Args:

  • self (Self)
  • buf (Span): 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:

def reset(mut self)

Reset the read position to the start. Use to re-read the same buffer (e.g. for benchmarking).

Args:

  • self (Self)