withOpenLineFile<R> function

Future<R> withOpenLineFile<R>(
  1. String pathToFile,
  2. Future<R> action(
    1. LineFile
    ), {
  3. FileMode fileMode = FileMode.writeOnlyAppend,
})

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;
}