readFile<T> static method

T readFile<T>({
  1. required File file,
  2. required FileParser<T> parser,
})

Attempts to read a File from the specified filePath, and parse it with the specified parser. Common FileParser implementations are available from FileParsers. If the file doesn't exist, throws a FileSystemException

Implementation

static T readFile<T>({required File file, required FileParser<T> parser}) {
  if (!file.existsSync()) {
    throw FileSystemException('File not found', file.path);
  }

  return parser(file.readAsBytesSync());
}