IO Streams
License
Boost License 1.0.
Authors
Jason White
Synopsis:
// Creates a 1 GiB file containing random data.
import io.file;
import std.parallelism : parallel;
auto f = File("big_random_file.dat", FileFlags.writeNew);
f.length = 1024^^3; // 1 GiB

auto map = f.memoryMap!size_t(Access.write);
foreach (i, ref e; parallel(map[]))
    e = uniform!"[]"(size_t.min, size_t.max);

auto  memoryMap(T)(File file, Access access = Access.read, size_t length = 0, long start = 0, bool share = true, void* address = null);

Convenience function for creating a memory map.

Examples
auto tf = testFile();

immutable newData = "The quick brown fox jumps over the lazy dog.";

// Modify the file
{
    auto f = File(tf.name, FileFlags.readWriteEmpty);
    f.length = newData.length;

    auto map = f.memoryMap!char(Access.readWrite);
    assert(map.length == newData.length);

    map[] = newData[];

    assert(map[0 .. newData.length] == newData[]);
}

// Read the file back in
{
    auto f = File(tf.name, FileFlags.readExisting);
    auto map = f.memoryMap!char(Access.read);
    assert(map.length == newData.length);
    assert(map[0 .. newData.length] == newData[]);
}