readFile method

Future<FileContents> readFile(
  1. String filePath
)

Reads the file at filePath and returns its contents as a FileContents object.

Throws an Exception if the utility is not initialized.

Implementation

Future<FileContents> readFile(String filePath) async {
  late FileContents fileContents;
  if (isInitialized) {
    var stream = await _fileLoader.getFileStream(filePath);
    var list = await stream.toList();
    if (hasHeaders) {
      var headers = list[0];
      list.removeAt(0);
      fileContents = FileContents(lines: list, headers: headers);
    } else {
      fileContents = FileContents(lines: list);
    }
    return fileContents;
  }

  throw Exception('Not Initialized');
}