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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
6 library io; | 6 library io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 // Writing empty data to a closed stream can cause errors. | 603 // Writing empty data to a closed stream can cause errors. |
604 if (data.isEmpty) return; | 604 if (data.isEmpty) return; |
605 | 605 |
606 // TODO(nweiz): remove this try/catch when issue 7836 is fixed. | 606 // TODO(nweiz): remove this try/catch when issue 7836 is fixed. |
607 try { | 607 try { |
608 _outputStream.write(data); | 608 _outputStream.write(data); |
609 } catch (e, stack) { | 609 } catch (e, stack) { |
610 if (!completed) completer.completeError(e, stack); | 610 if (!completed) completer.completeError(e, stack); |
611 completed = true; | 611 completed = true; |
612 } | 612 } |
613 }, onDone: () { | 613 }, onDone: () => _outputStream.close()); |
614 _outputStream.close(); | |
615 // TODO(nweiz): wait until _outputStream.onClosed is called once issue | |
616 // 7761 is fixed. | |
617 if (!completed) completer.complete(null); | |
618 completed = true; | |
619 }); | |
620 | 614 |
621 _outputStream.onError = (e) { | 615 _outputStream.onError = (e) { |
622 if (!completed) completer.completeError(e); | 616 if (!completed) completer.completeError(e); |
623 completed = true; | 617 completed = true; |
624 }; | 618 }; |
625 | 619 |
| 620 _outputStream.onClosed = () { |
| 621 if (!completed) completer.complete(); |
| 622 completed = true; |
| 623 }; |
| 624 |
626 return completer.future; | 625 return completer.future; |
627 } | 626 } |
628 } | 627 } |
629 | 628 |
630 /// Spawns and runs the process located at [executable], passing in [args]. | 629 /// Spawns and runs the process located at [executable], passing in [args]. |
631 /// Returns a [Future] that will complete with the results of the process after | 630 /// Returns a [Future] that will complete with the results of the process after |
632 /// it has ended. | 631 /// it has ended. |
633 /// | 632 /// |
634 /// The spawned process will inherit its parent's environment variables. If | 633 /// The spawned process will inherit its parent's environment variables. If |
635 /// [environment] is provided, that will be used to augment (not replace) the | 634 /// [environment] is provided, that will be used to augment (not replace) the |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 Directory _getDirectory(entry) { | 1027 Directory _getDirectory(entry) { |
1029 if (entry is Directory) return entry; | 1028 if (entry is Directory) return entry; |
1030 return new Directory(entry); | 1029 return new Directory(entry); |
1031 } | 1030 } |
1032 | 1031 |
1033 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1032 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
1034 Uri _getUri(uri) { | 1033 Uri _getUri(uri) { |
1035 if (uri is Uri) return uri; | 1034 if (uri is Uri) return uri; |
1036 return new Uri.fromString(uri); | 1035 return new Uri.fromString(uri); |
1037 } | 1036 } |
OLD | NEW |