OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
7 */ | 7 */ |
8 library io; | 8 library io; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 * Takes all input from [source] and writes it to [sink]. | 612 * Takes all input from [source] and writes it to [sink]. |
613 * | 613 * |
614 * Returns a future that completes when [source] is closed. | 614 * Returns a future that completes when [source] is closed. |
615 */ | 615 */ |
616 Future pipeInputToInput(InputStream source, ListInputStream sink) { | 616 Future pipeInputToInput(InputStream source, ListInputStream sink) { |
617 var completer = new Completer(); | 617 var completer = new Completer(); |
618 source.onClosed = () { | 618 source.onClosed = () { |
619 sink.markEndOfStream(); | 619 sink.markEndOfStream(); |
620 completer.complete(null); | 620 completer.complete(null); |
621 }; | 621 }; |
622 source.onData = () => sink.write(source.read()); | 622 source.onData = () { |
| 623 // Even if the sink is closed and we aren't going to do anything with more |
| 624 // data, we still need to drain it from source to work around issue 7218. |
| 625 var data = source.read(); |
| 626 if (!sink.closed) sink.write(data); |
| 627 }; |
623 // TODO(nweiz): propagate this error to the sink. See issue 3657. | 628 // TODO(nweiz): propagate this error to the sink. See issue 3657. |
624 source.onError = (e) { throw e; }; | 629 source.onError = (e) { throw e; }; |
625 return completer.future; | 630 return completer.future; |
626 } | 631 } |
627 | 632 |
628 /** | 633 /** |
629 * Buffers all input from an InputStream and returns it as a future. | 634 * Buffers all input from an InputStream and returns it as a future. |
630 */ | 635 */ |
631 Future<List<int>> consumeInputStream(InputStream stream) { | 636 Future<List<int>> consumeInputStream(InputStream stream) { |
632 if (stream.closed) return new Future.immediate(<int>[]); | 637 if (stream.closed) return new Future.immediate(<int>[]); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 return new Directory(entry); | 1140 return new Directory(entry); |
1136 } | 1141 } |
1137 | 1142 |
1138 /** | 1143 /** |
1139 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1144 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
1140 */ | 1145 */ |
1141 Uri _getUri(uri) { | 1146 Uri _getUri(uri) { |
1142 if (uri is Uri) return uri; | 1147 if (uri is Uri) return uri; |
1143 return new Uri.fromString(uri); | 1148 return new Uri.fromString(uri); |
1144 } | 1149 } |
OLD | NEW |