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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 } | 598 } |
| 599 | 599 |
| 600 var completer = new Completer<String>(); | 600 var completer = new Completer<String>(); |
| 601 var buffer = new StringBuffer(); | 601 var buffer = new StringBuffer(); |
| 602 stream.onClosed = () => completer.complete(buffer.toString()); | 602 stream.onClosed = () => completer.complete(buffer.toString()); |
| 603 stream.onData = () => buffer.add(stream.read()); | 603 stream.onData = () => buffer.add(stream.read()); |
| 604 stream.onError = (e) => completer.completeException(e, stackTrace); | 604 stream.onError = (e) => completer.completeException(e, stackTrace); |
| 605 return completer.future; | 605 return completer.future; |
| 606 } | 606 } |
| 607 | 607 |
| 608 /// Wrap an InputStream in a ListInputStream. This eagerly drains the [source] | |
| 609 /// input stream. This is useful for spawned processes which will not exit until | |
| 610 /// their output streams have been drained. | |
|
nweiz
2012/12/08 02:06:46
Mention the issue number here.
Bob Nystrom
2012/12/08 02:37:05
Done.
| |
| 611 InputStream wrapInputStream(InputStream source) { | |
| 612 var sink = new ListInputStream(); | |
| 613 // TODO(nweiz): Due to issuee 3657, pipeInputToInput naturally avoids calling | |
| 614 // both onClosed and onError. If 3657 gets fixed before 7013, we'll need to do | |
| 615 // that explicitly. | |
|
nweiz
2012/12/08 02:06:46
This comment is no longer relevant.
Bob Nystrom
2012/12/08 02:37:05
Done.
| |
| 616 pipeInputToInput(source, sink); | |
| 617 return sink; | |
| 618 } | |
| 619 | |
| 608 /// Spawns and runs the process located at [executable], passing in [args]. | 620 /// Spawns and runs the process located at [executable], passing in [args]. |
| 609 /// Returns a [Future] that will complete with the results of the process after | 621 /// Returns a [Future] that will complete with the results of the process after |
| 610 /// it has ended. | 622 /// it has ended. |
| 611 /// | 623 /// |
| 612 /// The spawned process will inherit its parent's environment variables. If | 624 /// The spawned process will inherit its parent's environment variables. If |
| 613 /// [environment] is provided, that will be used to augment (not replace) the | 625 /// [environment] is provided, that will be used to augment (not replace) the |
| 614 /// the inherited variables. | 626 /// the inherited variables. |
| 615 Future<PubProcessResult> runProcess(String executable, List<String> args, | 627 Future<PubProcessResult> runProcess(String executable, List<String> args, |
| 616 {workingDir, Map<String, String> environment}) { | 628 {workingDir, Map<String, String> environment}) { |
| 617 return _doProcess(Process.run, executable, args, workingDir, environment) | 629 return _doProcess(Process.run, executable, args, workingDir, environment) |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1019 return new Directory(entry); | 1031 return new Directory(entry); |
| 1020 } | 1032 } |
| 1021 | 1033 |
| 1022 /** | 1034 /** |
| 1023 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1035 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 1024 */ | 1036 */ |
| 1025 Uri _getUri(uri) { | 1037 Uri _getUri(uri) { |
| 1026 if (uri is Uri) return uri; | 1038 if (uri is Uri) return uri; |
| 1027 return new Uri.fromString(uri); | 1039 return new Uri.fromString(uri); |
| 1028 } | 1040 } |
| OLD | NEW |