Skip to content

FileReader

Mojo struct 🡭

@memory_only
struct FileReader

Reader that reads from a file on disk. Use with FastqParser for .fastq files.

Example:

from blazeseq import FileReader, FastqParser
from std.pathlib import Path
var r = FileReader(Path("data.fastq"))
var parser = FastqParser[FileReader](r^, "generic")
for record in parser.records():
_ = record.id()
  • handle (FileHandle)

AnyType, ImplicitlyDestructible, Movable, Reader

def __init__(out self, path: Path)

Open a file for reading.

Args:

  • path (Path): Path to the file (e.g. Path(“data.fastq”)).
  • self (Self)

Returns:

Self

Raises:

Error: If the file cannot be opened.

def read_bytes(mut self, amt: Int = -1) -> List[Byte]

Read up to amt bytes (or all if amt < 0) as a list of bytes.

Args:

  • self (Self)
  • amt (Int)

Returns:

List

Raises:

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

Read up to amt bytes from the file into buf at offset pos. Returns bytes read.

Args:

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

Returns:

UInt64

Raises: