| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Helper class to wrap a [StreamConsumer<List<int>, T>] and provide | 8 * Helper class to wrap a [StreamConsumer<List<int>, T>] and provide |
| 9 * utility functions for writing to the StreamConsumer directly. The | 9 * utility functions for writing to the StreamConsumer directly. The |
| 10 * [IOSink] buffers the input given by [write], [writeAll], [writeln], | 10 * [IOSink] buffers the input given by [write], [writeAll], [writeln], |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 * Writes the bytes uninterpreted to the consumer. | 30 * Writes the bytes uninterpreted to the consumer. |
| 31 */ | 31 */ |
| 32 void writeBytes(List<int> data); | 32 void writeBytes(List<int> data); |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Provide functionality for piping to the [IOSink]. | 35 * Provide functionality for piping to the [IOSink]. |
| 36 */ | 36 */ |
| 37 Future<T> consume(Stream<List<int>> stream); | 37 Future<T> consume(Stream<List<int>> stream); |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Adds all elements of the given [stream] to `this`. |
| 41 */ |
| 42 Future<T> addStream(Stream<List<int>> stream); |
| 43 |
| 44 /** |
| 40 * Like [consume], but will not close the target when done. | 45 * Like [consume], but will not close the target when done. |
| 46 * |
| 47 * *Deprecated*: use [addStream] instead. |
| 41 */ | 48 */ |
| 42 Future<T> writeStream(Stream<List<int>> stream); | 49 Future<T> writeStream(Stream<List<int>> stream); |
| 43 | 50 |
| 44 /** | 51 /** |
| 45 * Close the target. | 52 * Close the target. |
| 46 */ | 53 */ |
| 47 void close(); | 54 // TODO(floitsch): Currently the future cannot be typed because it has |
| 55 // hardcoded type Future<HttpClientResponse> in subclass HttpClientRequest. |
| 56 Future close(); |
| 48 | 57 |
| 49 /** | 58 /** |
| 50 * Get future that will complete when all data has been written to | 59 * Get future that will complete when all data has been written to |
| 51 * the IOSink and it has been closed. | 60 * the IOSink and it has been closed. |
| 52 */ | 61 */ |
| 53 Future<T> get done; | 62 Future<T> get done; |
| 54 } | 63 } |
| 55 | 64 |
| 56 | 65 |
| 57 class _IOSinkImpl<T> implements IOSink<T> { | 66 class _IOSinkImpl<T> implements IOSink<T> { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 136 } |
| 128 | 137 |
| 129 Future<T> consume(Stream<List<int>> stream) { | 138 Future<T> consume(Stream<List<int>> stream) { |
| 130 if (_isBound) { | 139 if (_isBound) { |
| 131 throw new StateError("IOSink is already bound to a stream"); | 140 throw new StateError("IOSink is already bound to a stream"); |
| 132 } | 141 } |
| 133 return _fillFromStream(stream); | 142 return _fillFromStream(stream); |
| 134 } | 143 } |
| 135 | 144 |
| 136 Future<T> writeStream(Stream<List<int>> stream) { | 145 Future<T> writeStream(Stream<List<int>> stream) { |
| 146 return addStream(stream); |
| 147 } |
| 148 |
| 149 Future<T> addStream(Stream<List<int>> stream) { |
| 137 if (_isBound) { | 150 if (_isBound) { |
| 138 throw new StateError("IOSink is already bound to a stream"); | 151 throw new StateError("IOSink is already bound to a stream"); |
| 139 } | 152 } |
| 140 return _fillFromStream(stream, unbind: true); | 153 return _fillFromStream(stream, unbind: true); |
| 141 } | 154 } |
| 142 | 155 |
| 143 void close() { | 156 Future close() { |
| 144 if (_isBound) { | 157 if (_isBound) { |
| 145 throw new StateError("IOSink is already bound to a stream"); | 158 throw new StateError("IOSink is already bound to a stream"); |
| 146 } | 159 } |
| 147 _controller.close(); | 160 _controller.close(); |
| 161 return _pipeFuture; |
| 148 } | 162 } |
| 149 | 163 |
| 150 Future<T> get done { | 164 Future<T> get done { |
| 151 _controller; | 165 _controller; |
| 152 return _pipeFuture; | 166 return _pipeFuture; |
| 153 } | 167 } |
| 154 | 168 |
| 155 void _completeWriteStreamCompleter([error]) { | 169 void _completeWriteStreamCompleter([error]) { |
| 156 if (_writeStreamCompleter == null) return; | 170 if (_writeStreamCompleter == null) return; |
| 157 var tmp = _writeStreamCompleter; | 171 var tmp = _writeStreamCompleter; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 }, | 251 }, |
| 238 onError: _controller.addError); | 252 onError: _controller.addError); |
| 239 if (_paused) _pause(); | 253 if (_paused) _pause(); |
| 240 if (unbind) { | 254 if (unbind) { |
| 241 return _writeStreamCompleter.future; | 255 return _writeStreamCompleter.future; |
| 242 } else { | 256 } else { |
| 243 return _pipeFuture; | 257 return _pipeFuture; |
| 244 } | 258 } |
| 245 } | 259 } |
| 246 } | 260 } |
| OLD | NEW |