withOpenFile<R> function
Future<R>
withOpenFile<R>(})
Opens a File and calls action
passing in the open file.
When action completes the file is closed.
Use this method in preference to directly callling FileSync()
Implementation
Future<R> withOpenFile<R>(
String pathToFile,
R Function(RandomAccessFile) action, {
FileMode fileMode = FileMode.writeOnlyAppend,
}) async {
final raf = File(pathToFile).openSync(mode: fileMode);
R result;
try {
result = action(raf);
} finally {
await raf.close();
}
return result;
}