toBytes method
Collects all emitted chunks into a single byte array.
Returns a Future that completes with the collected bytes.
Implementation
Future<Uint8List> toBytes() {
var completer = Completer<Uint8List>();
var sink = ByteConversionSink.withCallback((bytes) => completer.complete(Uint8List.fromList(bytes)));
listen(sink.add, onError: completer.completeError, onDone: sink.close, cancelOnError: true);
return completer.future;
}