inDirectory static method

Future<SimpleOpfsFileSystem> inDirectory(
  1. FileSystemDirectoryHandle root, {
  2. String vfsName = 'simple-opfs',
})

Loads an SimpleOpfsFileSystem in the desired root directory, which must be a Dart wrapper around a FileSystemDirectoryHandle.

Implementation

static Future<SimpleOpfsFileSystem> inDirectory(
  FileSystemDirectoryHandle root, {
  String vfsName = 'simple-opfs',
}) async {
  Future<FileSystemSyncAccessHandle> open(String name) async {
    final handle = await root.openFile(name, create: true);
    return await handle.createSyncAccessHandle().toDart;
  }

  final meta = await open('meta');
  meta.truncate(2);
  final files = {
    for (final type in FileType.values) type: await open(type.name)
  };

  return SimpleOpfsFileSystem._(meta, files, vfsName: vfsName);
}