Skip to content
FutureBlitz

    Install

    Import std.io.mapped

    std.io.mapped

    std.io's mapped files: a file's bytes mapped into memory, read and written in place, without copying the file in, which the OS pages in as they're used.

    std/io/mapped.fb

    Types

    MappedFile class

    Public Class MappedFile

    A file mapped into memory whole, read-only or writable, until it's closed or its last reference goes. Writing to a writable one changes the file, which Flush puts onto the disk. It has the bytes the file had when it was mapped: one that grows meanwhile isn't mapped again, and on POSIX, reading what a file that another program shortens no longer has ends the program, as it would C's. On Windows, a mapped file can't be replaced or shortened until it's closed, and a write that would is BUSY, but it can be deleted.

    std/io/mapped.fb, line 31

    • Public ReadOnly Field Path: Path field #

      The file it maps.

    • Public ReadOnly Field IsWritable: Bool field #

      Whether it was mapped to write.

    • Public New(path: Path, writable: Bool = False) Throws IOError constructor #

      Maps the file, which has to be there, read-only, or writable when writable is True.

    • Public Method Count(): Int64 method #

      How many bytes it has: the file's, or 0 once it's closed.

    • Public Method IsOpen(): Bool method #

      Whether it's still mapped.

    • @PanicsAtCaller Operator [](index: Int64): UInt8 operator #

      The byte at index, from 0. Panics when it's closed, or the index is out of range.

    • @PanicsAtCaller Operator []=(index: Int64, value: UInt8) operator #

      Sets the byte at index. Panics when it's read-only or closed, or the index is out of range.

    • @PanicsAtCaller Public Method ReadBytes(start: Int64, count: Int64): UInt8[] method #

      A copy of count bytes from start. Panics when it's closed, or they aren't all in it.

    • @PanicsAtCaller Public Method WriteBytes(start: Int64, bytes: UInt8[]) method #

      Puts the bytes at start, over what's there. Panics when it's read-only or closed, or they don't all fit.

    • Public Method Flush() Throws IOError method #

      Puts what's been written onto the disk, as File's atomic writes do theirs. A read-only or closed one has nothing to put there.

    • @PanicsAtCaller Public Method Bytes(): Buffer<UInt8> Throws IOError method #

      Its bytes as a Buffer<UInt8>, without copying them, for streams and C code to read in place. The Buffer, and each view of it, keeps them mapped while it is, even once this is closed. A writable one's Buffer is its bytes, so writing it changes the file, as []= does. A read-only one's Buffers share a view of their own, which copies a page of the file's as it's first written, so writing one changes every Buffer this gives, before it and after, but never the file or what [] reads. Throws an IOError when that view can't be made, the first time, and panics when it's closed.

    • Public Method Close() method #

      Unmaps it, and closes the file, which a second Close leaves alone, once no Buffer from Bytes is left. What was written stays in the file, for the OS to put onto the disk.

    Report an issue with this page or with FutureBlitz on GitHub.