readFile method

Future<Uint8List?> readFile()

Reads this file from its stream and returns its bytes.

Note: Be sure not to read the stream while this method executes.

Implementation

Future<Uint8List?> readFile() {
  return _readGuard.protect(() async {
    var content = stream;
    if (content != null) {
      List<int> data = [];

      StreamQueue queue = StreamQueue(content);
      while (await queue.hasNext) {
        data.addAll(await queue.next);
      }

      bytes.value = Uint8List.fromList(data);
      _readStream = null;
    }

    await _determineDimension();

    return bytes.value;
  });
}