open static method

MappedFile? open(
  1. String path
)

Maps path, or returns null if it cannot be opened, is empty, or does not fit in the address space.

Implementation

static MappedFile? open(String path) {
  if (_mapped[path] case final file?) {
    file._opens++;
    return file;
  }
  final bytes = utf8.encode(path);
  final cPath = NativeKernels.allocate<Uint8>(bytes.length + 1);
  cPath.asTypedList(bytes.length + 1)
    ..setAll(0, bytes)
    ..[bytes.length] = 0;
  final size = NativeKernels.allocate<Int64>(8);
  final p = _mapFile(cPath, size);
  final length = size.value;
  _free(cPath.cast());
  _free(size.cast());
  if (p == nullptr) return null;
  return _mapped[path] = MappedFile._(path, p.cast<Uint8>(), length);
}