flush method

  1. @override
Future<void> flush()
override

Flushes buffered OS writes to durable storage.

Implementation

@override
Future<void> flush() {
  if (readOnly) {
    return Future<void>.value();
  }
  return _ioMutex.synchronized(() async {
    final raf = _requireOpen();
    try {
      if (ioMode == .sync) {
        raf.flushSync();
        if (_darwinSyncFd >= 0) {
          PosixFs.syncFd(_darwinSyncFd);
        }
      } else {
        await raf.flush();
        if (_darwinSyncFd >= 0) {
          await PosixFs.syncFdAsync(_darwinSyncFd);
        }
      }
      if (_needsDirectorySync) {
        final dir = File(path).absolute.parent.path;
        if (ioMode == .sync) {
          PosixFs.syncDirectory(dir);
        } else {
          await PosixFs.syncDirectoryAsync(dir);
        }
        _needsDirectorySync = false;
      }
    } finally {
      _releaseIfTransient();
    }
  });
}