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>>] and provide | 8 * Helper class to wrap a [StreamConsumer<List<int>>] 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 all [StringSink] methods and will delay | 10 * [IOSink] buffers the input given by all [StringSink] methods and will delay |
(...skipping 28 matching lines...) Expand all Loading... | |
39 * Writes an error to the consumer. | 39 * Writes an error to the consumer. |
40 */ | 40 */ |
41 void addError(error); | 41 void addError(error); |
42 | 42 |
43 /** | 43 /** |
44 * Adds all elements of the given [stream] to `this`. | 44 * Adds all elements of the given [stream] to `this`. |
45 */ | 45 */ |
46 Future addStream(Stream<List<int>> stream); | 46 Future addStream(Stream<List<int>> stream); |
47 | 47 |
48 /** | 48 /** |
49 * Flushes the data currently buffered in the stream through the | |
50 * synchronous Sink methods, to the underlying storage, if possible. | |
51 * | |
52 * Returns a future which completes when the flush operation is | |
53 * complete. If the target of the [IOSink] is a file then a file | |
54 * system flush will be performed as well. | |
55 * | |
56 * If [addStream] is currently active this method will fail. | |
57 */ | |
58 Future flush(); | |
Anders Johnsen
2013/10/28 15:13:22
I still disagree that this should be part of the I
| |
59 | |
60 /** | |
49 * Close the target. | 61 * Close the target. |
50 */ | 62 */ |
51 Future close(); | 63 Future close(); |
52 | 64 |
53 /** | 65 /** |
54 * Get a future that will complete when all synchronous have completed, or an | 66 * Get a future that will complete when all synchronous have completed, or an |
55 * error happened. This future is identical to the future returned from close. | 67 * error happened. This future is identical to the future returned from close. |
56 */ | 68 */ |
57 Future get done; | 69 Future get done; |
58 } | 70 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 } | 236 } |
225 | 237 |
226 void writeln([Object obj = ""]) { | 238 void writeln([Object obj = ""]) { |
227 write(obj); | 239 write(obj); |
228 write("\n"); | 240 write("\n"); |
229 } | 241 } |
230 | 242 |
231 void writeCharCode(int charCode) { | 243 void writeCharCode(int charCode) { |
232 write(new String.fromCharCode(charCode)); | 244 write(new String.fromCharCode(charCode)); |
233 } | 245 } |
246 | |
247 Future flush() { | |
248 return addStream((new StreamController()..close()).stream) | |
249 .then((_) { | |
250 if (_target is _FileStreamConsumer) { | |
251 return _target.flush(); | |
252 } else { | |
253 return new Future.value(null); | |
254 } | |
255 }); | |
256 } | |
234 } | 257 } |
OLD | NEW |