| Index: lib/stream_channel.dart
|
| diff --git a/lib/stream_channel.dart b/lib/stream_channel.dart
|
| index fd7b0932733e56808a3c2b87b68c723bcc8ab9c6..8cd27199614512d396a7aeb33cf0389a6a212f56 100644
|
| --- a/lib/stream_channel.dart
|
| +++ b/lib/stream_channel.dart
|
| @@ -3,6 +3,9 @@
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| import 'dart:async';
|
| +import 'dart:convert';
|
| +
|
| +import 'package:async/async.dart';
|
|
|
| export 'src/delegating_stream_channel.dart';
|
| export 'src/multi_channel.dart';
|
| @@ -64,6 +67,13 @@ abstract class StreamChannel<T> {
|
| /// Connects [this] to [other], so that any values emitted by either are sent
|
| /// directly to the other.
|
| void pipe(StreamChannel<T> other);
|
| +
|
| + /// Transforms [this] using [codec].
|
| + ///
|
| + /// This returns a stream channel that encodes all input using [Codec.encoder]
|
| + /// before passing it to this channel's [sink], and decodes all output from
|
| + /// this channel's [stream] using [Codec.decoder].
|
| + StreamChannel transform(Codec<dynamic, T> codec);
|
| }
|
|
|
| /// An implementation of [StreamChannel] that simply takes a stream and a sink
|
| @@ -85,4 +95,12 @@ abstract class StreamChannelMixin<T> implements StreamChannel<T> {
|
| stream.pipe(other.sink);
|
| other.stream.pipe(sink);
|
| }
|
| +
|
| + StreamChannel transform(Codec<dynamic, T> codec) {
|
| + var sinkTransformer =
|
| + new StreamSinkTransformer.fromStreamTransformer(codec.encoder);
|
| + return new _StreamChannel(
|
| + stream.transform(codec.decoder),
|
| + sinkTransformer.bind(sink));
|
| + }
|
| }
|
|
|