| 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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 if (environment != null) { | 734 if (environment != null) { |
| 735 options.environment = new Map.from(Platform.environment); | 735 options.environment = new Map.from(Platform.environment); |
| 736 environment.forEach((key, value) => options.environment[key] = value); | 736 environment.forEach((key, value) => options.environment[key] = value); |
| 737 } | 737 } |
| 738 | 738 |
| 739 log.process(executable, args); | 739 log.process(executable, args); |
| 740 | 740 |
| 741 return fn(executable, args, options); | 741 return fn(executable, args, options); |
| 742 } | 742 } |
| 743 | 743 |
| 744 /// Closes [response] while ignoring the body of [request]. Returns a Future | |
| 745 /// that completes once the response is closed. | |
| 746 /// | |
| 747 /// Due to issue 6984, it's necessary to drain the request body before closing | |
| 748 /// the response. | |
| 749 Future closeHttpResponse(HttpRequest request, HttpResponse response) { | |
| 750 // TODO(nweiz): remove this when issue 4061 is fixed. | |
| 751 var stackTrace; | |
| 752 try { | |
| 753 throw ""; | |
| 754 } catch (_, localStackTrace) { | |
| 755 stackTrace = localStackTrace; | |
| 756 } | |
| 757 | |
| 758 var completer = new Completer(); | |
| 759 request.inputStream.onError = (e) => | |
| 760 completer.completeException(e, stackTrace); | |
| 761 request.inputStream.onData = request.inputStream.read; | |
| 762 request.inputStream.onClosed = () { | |
| 763 response.outputStream.close(); | |
| 764 completer.complete(null); | |
| 765 }; | |
| 766 return completer.future; | |
| 767 } | |
| 768 | |
| 769 /** | 744 /** |
| 770 * Wraps [input] to provide a timeout. If [input] completes before | 745 * Wraps [input] to provide a timeout. If [input] completes before |
| 771 * [milliseconds] have passed, then the return value completes in the same way. | 746 * [milliseconds] have passed, then the return value completes in the same way. |
| 772 * However, if [milliseconds] pass before [input] has completed, it completes | 747 * However, if [milliseconds] pass before [input] has completed, it completes |
| 773 * with a [TimeoutException] with [description] (which should be a fragment | 748 * with a [TimeoutException] with [description] (which should be a fragment |
| 774 * describing the action that timed out). | 749 * describing the action that timed out). |
| 775 * | 750 * |
| 776 * Note that timing out will not cancel the asynchronous operation behind | 751 * Note that timing out will not cancel the asynchronous operation behind |
| 777 * [input]. | 752 * [input]. |
| 778 */ | 753 */ |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 return new Directory(entry); | 1110 return new Directory(entry); |
| 1136 } | 1111 } |
| 1137 | 1112 |
| 1138 /** | 1113 /** |
| 1139 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1114 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 1140 */ | 1115 */ |
| 1141 Uri _getUri(uri) { | 1116 Uri _getUri(uri) { |
| 1142 if (uri is Uri) return uri; | 1117 if (uri is Uri) return uri; |
| 1143 return new Uri.fromString(uri); | 1118 return new Uri.fromString(uri); |
| 1144 } | 1119 } |
| OLD | NEW |