readAsBytes method

Future<List<int>> readAsBytes(
  1. Stream<List<int>> source
)

Implementation

static Future<List<int>> readAsBytes(Stream<List<int>> source) {
  Completer<List<int>> completer = Completer<List<int>>();
  ByteConversionSink sink =
      ByteConversionSink.withCallback((List<int> accumulated) {
    completer.complete(accumulated);
  });
  source.listen(
    sink.add,
    onError: completer.completeError,
    onDone: sink.close,
    cancelOnError: true,
  );
  return completer.future;
}