Chromium Code Reviews| 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 if (!sink.closed) sink.write(source.read()); | |
|
Bob Nystrom
2012/12/08 03:35:33
Should do the read() even if it's closed.
Also, m
nweiz
2012/12/08 03:38:04
I think it's more or less "business as usual" for
| |
| 624 }; | |
| 623 // TODO(nweiz): propagate this error to the sink. See issue 3657. | 625 // TODO(nweiz): propagate this error to the sink. See issue 3657. |
| 624 source.onError = (e) { throw e; }; | 626 source.onError = (e) { throw e; }; |
| 625 return completer.future; | 627 return completer.future; |
| 626 } | 628 } |
| 627 | 629 |
| 628 /** | 630 /** |
| 629 * Buffers all input from an InputStream and returns it as a future. | 631 * Buffers all input from an InputStream and returns it as a future. |
| 630 */ | 632 */ |
| 631 Future<List<int>> consumeInputStream(InputStream stream) { | 633 Future<List<int>> consumeInputStream(InputStream stream) { |
| 632 if (stream.closed) return new Future.immediate(<int>[]); | 634 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); | 1137 return new Directory(entry); |
| 1136 } | 1138 } |
| 1137 | 1139 |
| 1138 /** | 1140 /** |
| 1139 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1141 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 1140 */ | 1142 */ |
| 1141 Uri _getUri(uri) { | 1143 Uri _getUri(uri) { |
| 1142 if (uri is Uri) return uri; | 1144 if (uri is Uri) return uri; |
| 1143 return new Uri.fromString(uri); | 1145 return new Uri.fromString(uri); |
| 1144 } | 1146 } |
| OLD | NEW |