bind method

  1. @override
Stream<HashDigest> bind(
  1. Stream<List<int>> stream
)
override

Transforms the byte array input stream to generate a new stream which contains a single HashDigest

The expected behavior of this method is described below:

  • When the returned stream has a subscriber (calling Stream.listen), the message-digest generation begins from the input stream.
  • If the returned stream is paused, the processing of the input stream is also paused, and on resume, it continue processing from where it was left off.
  • If the returned stream is cancelled, the subscription to the input stream is also cancelled.
  • When the input stream is closed, the returned stream also gets closed with a HashDigest data. The returned stream may produce only one such data event in its life-time.
  • On error reading the input stream, or while processing the message digest, the subscription to input stream cancels immediately and the returned stream closes with an error event.

Implementation

@override
Stream<HashDigest> bind(Stream<List<int>> stream) async* {
  var sink = createSink();
  await for (var x in stream) {
    sink.add(x);
  }
  yield sink.digest();
}