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