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[]); }
Convenience function for creating a memory map.