toBinaryContent method
Implementation
Future<Uint8List?> toBinaryContent() async {
if (!await _exists) {
return null;
}
// Open read.
Stream<List<int>> blobStream = _blob.openRead();
// Consume stream.
Completer<Uint8List> completer = Completer<Uint8List>();
ByteConversionSink sink = ByteConversionSink.withCallback(
(bytes) => completer.complete(Uint8List.fromList(bytes)));
blobStream.listen(
sink.add,
onError: completer.completeError,
onDone: sink.close,
cancelOnError: true);
return completer.future;
}