OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:convert'; | 5 import 'dart:convert'; |
6 | 6 |
7 import 'package:async/async.dart'; | 7 import 'package:async/async.dart'; |
8 | 8 |
9 import '../stream_channel.dart'; | 9 import '../stream_channel.dart'; |
10 import 'stream_channel_transformer.dart'; | 10 import 'stream_channel_transformer.dart'; |
(...skipping 22 matching lines...) Expand all Loading... |
33 JsonDocumentTransformer({reviver(key, value), toEncodable(object)}) | 33 JsonDocumentTransformer({reviver(key, value), toEncodable(object)}) |
34 : _codec = new JsonCodec(reviver: reviver, toEncodable: toEncodable); | 34 : _codec = new JsonCodec(reviver: reviver, toEncodable: toEncodable); |
35 | 35 |
36 JsonDocumentTransformer._(this._codec); | 36 JsonDocumentTransformer._(this._codec); |
37 | 37 |
38 StreamChannel bind(StreamChannel<String> channel) { | 38 StreamChannel bind(StreamChannel<String> channel) { |
39 var stream = channel.stream.map(_codec.decode); | 39 var stream = channel.stream.map(_codec.decode); |
40 var sink = new StreamSinkTransformer.fromHandlers(handleData: (data, sink) { | 40 var sink = new StreamSinkTransformer.fromHandlers(handleData: (data, sink) { |
41 sink.add(_codec.encode(data)); | 41 sink.add(_codec.encode(data)); |
42 }).bind(channel.sink); | 42 }).bind(channel.sink); |
43 return new StreamChannel(stream, sink); | 43 return new StreamChannel.withCloseGuarantee(stream, sink); |
44 } | 44 } |
45 } | 45 } |
OLD | NEW |