| 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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 } | 659 } |
| 660 | 660 |
| 661 if (environment != null) { | 661 if (environment != null) { |
| 662 options.environment = new Map.from(Platform.environment); | 662 options.environment = new Map.from(Platform.environment); |
| 663 environment.forEach((key, value) => options.environment[key] = value); | 663 environment.forEach((key, value) => options.environment[key] = value); |
| 664 } | 664 } |
| 665 | 665 |
| 666 return fn(executable, args, options); | 666 return fn(executable, args, options); |
| 667 } | 667 } |
| 668 | 668 |
| 669 /// Closes [response] while ignoring the body of [request]. Returns a Future | |
| 670 /// that completes once the response is closed. | |
| 671 /// | |
| 672 /// Due to issue 6984, it's necessary to drain the request body before closing | |
| 673 /// the response. | |
| 674 Future closeHttpResponse(HttpRequest request, HttpResponse response) { | |
| 675 // TODO(nweiz): remove this when issue 4061 is fixed. | |
| 676 var stackTrace; | |
| 677 try { | |
| 678 throw ""; | |
| 679 } catch (_, localStackTrace) { | |
| 680 stackTrace = localStackTrace; | |
| 681 } | |
| 682 | |
| 683 var completer = new Completer(); | |
| 684 request.inputStream.onError = (e) => | |
| 685 completer.completeException(e, stackTrace); | |
| 686 request.inputStream.onData = request.inputStream.read; | |
| 687 request.inputStream.onClosed = () { | |
| 688 response.outputStream.close(); | |
| 689 completer.complete(null); | |
| 690 }; | |
| 691 return completer.future; | |
| 692 } | |
| 693 | |
| 694 /** | 669 /** |
| 695 * Wraps [input] to provide a timeout. If [input] completes before | 670 * Wraps [input] to provide a timeout. If [input] completes before |
| 696 * [milliseconds] have passed, then the return value completes in the same way. | 671 * [milliseconds] have passed, then the return value completes in the same way. |
| 697 * However, if [milliseconds] pass before [input] has completed, it completes | 672 * However, if [milliseconds] pass before [input] has completed, it completes |
| 698 * with a [TimeoutException] with [description] (which should be a fragment | 673 * with a [TimeoutException] with [description] (which should be a fragment |
| 699 * describing the action that timed out). | 674 * describing the action that timed out). |
| 700 * | 675 * |
| 701 * Note that timing out will not cancel the asynchronous operation behind | 676 * Note that timing out will not cancel the asynchronous operation behind |
| 702 * [input]. | 677 * [input]. |
| 703 */ | 678 */ |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 return new Directory(entry); | 994 return new Directory(entry); |
| 1020 } | 995 } |
| 1021 | 996 |
| 1022 /** | 997 /** |
| 1023 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 998 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 1024 */ | 999 */ |
| 1025 Uri _getUri(uri) { | 1000 Uri _getUri(uri) { |
| 1026 if (uri is Uri) return uri; | 1001 if (uri is Uri) return uri; |
| 1027 return new Uri.fromString(uri); | 1002 return new Uri.fromString(uri); |
| 1028 } | 1003 } |
| OLD | NEW |