read method

  1. @override
Future<ByteData> read()
override

Reads the whole content as raw bytes.

Implementation

@override
Future<ByteData> read() async {
  if (file is File) {
    try {
      // We only read files smaller than 100KB to avoid an [OutOfMemoryError].
      if (await (file as File).length() > 100000) {
        return ByteData(0);
      } else {
        return (file as File)
            .readAsBytes()
            .then((bytes) => ByteData.sublistView(bytes));
      }
    } on Exception catch (ex) {
      Fimber.e("ERROR reading file: $file", ex: ex);
      return ByteData(0);
    }
  }
  return ByteData(0);
}