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. |
| 611 /// TODO(rnystrom): Get rid of this once #7218 is fixed. |
| 612 InputStream wrapInputStream(InputStream source) { |
| 613 var sink = new ListInputStream(); |
| 614 // TODO(nweiz): Due to issuee 3657, pipeInputToInput naturally avoids calling |
| 615 // both onClosed and onError. If 3657 gets fixed before 7013, we'll need to do |
| 616 // that explicitly. |
| 617 pipeInputToInput(source, sink); |
| 618 return sink; |
| 619 } |
| 620 |
608 /// Spawns and runs the process located at [executable], passing in [args]. | 621 /// 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 | 622 /// Returns a [Future] that will complete with the results of the process after |
610 /// it has ended. | 623 /// it has ended. |
611 /// | 624 /// |
612 /// The spawned process will inherit its parent's environment variables. If | 625 /// The spawned process will inherit its parent's environment variables. If |
613 /// [environment] is provided, that will be used to augment (not replace) the | 626 /// [environment] is provided, that will be used to augment (not replace) the |
614 /// the inherited variables. | 627 /// the inherited variables. |
615 Future<PubProcessResult> runProcess(String executable, List<String> args, | 628 Future<PubProcessResult> runProcess(String executable, List<String> args, |
616 {workingDir, Map<String, String> environment}) { | 629 {workingDir, Map<String, String> environment}) { |
617 return _doProcess(Process.run, executable, args, workingDir, environment) | 630 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); | 1032 return new Directory(entry); |
1020 } | 1033 } |
1021 | 1034 |
1022 /** | 1035 /** |
1023 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1036 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
1024 */ | 1037 */ |
1025 Uri _getUri(uri) { | 1038 Uri _getUri(uri) { |
1026 if (uri is Uri) return uri; | 1039 if (uri is Uri) return uri; |
1027 return new Uri.fromString(uri); | 1040 return new Uri.fromString(uri); |
1028 } | 1041 } |
OLD | NEW |