openMmapFile function

Future<MmapFile> openMmapFile(
  1. String path, {
  2. bool create = true,
  3. bool readOnly = false,
  4. bool direct = false,
  5. bool largePages = false,
  6. bool mmapCache = true,
})

Opens a native mmap file. Synchronous; run in a worker isolate for UI code.

direct uses FILE_FLAG_NO_BUFFERING on Windows, O_DIRECT on Linux/Android and F_NOCACHE on macOS/iOS. It requires 4 KiB aligned offsets/lengths and is for streaming files larger than RAM; random 4 KiB access is much slower than the buffered/mmap path.

Implementation

Future<MmapFile> openMmapFile(
  String path, {
  bool create = true,
  bool readOnly = false,
  bool direct = false,
  bool largePages = false,
  bool mmapCache = true,
}) async {
  if (Platform.isWindows) {
    return WindowsMmapFile.open(
      path,
      create: create,
      readOnly: readOnly,
      direct: direct,
      largePages: largePages,
      mmapCache: mmapCache,
    );
  }
  if (largePages) {
    throw UnsupportedError('large pages are only implemented on Windows');
  }
  return PosixMmapFile.open(
    path,
    create: create,
    readOnly: readOnly,
    direct: direct,
    mmapCache: mmapCache,
  );
}