Skip to content

MappedFile

Mojo struct 🡭

@memory_only
struct MappedFile

Read-only memory map of a file.

Example:

var mapped = MappedFile(Path("data.fastq"))
var view = mapped.view() # Span[Byte] over the whole file

The mapping lives for the lifetime of the struct; __deinit__ unmaps and closes the descriptor. Keep the struct alive while any view into it is used — views do not extend the mapping’s lifetime.

AnyType, Deinitable, Movable

fn def __init__(out self, path: Path)

Args:

  • path (Path)
  • self (Self)

Returns:

Self

Raises:

fn def __init__(out self, *, deinit move: Self)

Args:

  • move (Self)
  • self (Self)

Returns:

Self

fn def __deinit__(deinit self)

Args:

  • self (Self)
fn def size(self) -> Int

Args:

  • self (Self)

Returns:

Int

fn def view(self) -> Span[UInt8, MutUntrackedOrigin]

Whole-file byte span. Empty file yields a zero-length span.

Args:

  • self (Self)

Returns:

Span[UInt8, MutUntrackedOrigin]