withOpenFile<R> function
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
R withOpenFile<R>(
String pathToFile,
R Function(FileSync) action, {
FileMode fileMode = FileMode.writeOnlyAppend,
}) {
final file = FileSync(pathToFile, fileMode: fileMode);
R result;
try {
result = action(file);
} finally {
file.close();
}
return result;
}