OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 541 } |
542 | 542 |
543 /// Creates a temporary directory and passes its path to [fn]. Once the [Future] | 543 /// Creates a temporary directory and passes its path to [fn]. Once the [Future] |
544 /// returned by [fn] completes, the temporary directory and all its contents | 544 /// returned by [fn] completes, the temporary directory and all its contents |
545 /// will be deleted. [fn] can also return `null`, in which case the temporary | 545 /// will be deleted. [fn] can also return `null`, in which case the temporary |
546 /// directory is deleted immediately afterwards. | 546 /// directory is deleted immediately afterwards. |
547 /// | 547 /// |
548 /// Returns a future that completes to the value that the future returned from | 548 /// Returns a future that completes to the value that the future returned from |
549 /// [fn] completes to. | 549 /// [fn] completes to. |
550 Future withTempDir(Future fn(String path)) { | 550 Future withTempDir(Future fn(String path)) { |
551 return new Future.of(() { | 551 return new Future.sync(() { |
552 var tempDir = createTempDir(); | 552 var tempDir = createTempDir(); |
553 return new Future.of(() => fn(tempDir)) | 553 return new Future.sync(() => fn(tempDir)) |
554 .whenComplete(() => deleteEntry(tempDir)); | 554 .whenComplete(() => deleteEntry(tempDir)); |
555 }); | 555 }); |
556 } | 556 } |
557 | 557 |
558 /// Extracts a `.tar.gz` file from [stream] to [destination]. Returns whether | 558 /// Extracts a `.tar.gz` file from [stream] to [destination]. Returns whether |
559 /// or not the extraction was successful. | 559 /// or not the extraction was successful. |
560 Future<bool> extractTarGz(Stream<List<int>> stream, String destination) { | 560 Future<bool> extractTarGz(Stream<List<int>> stream, String destination) { |
561 log.fine("Extracting .tar.gz stream to $destination."); | 561 log.fine("Extracting .tar.gz stream to $destination."); |
562 | 562 |
563 if (Platform.operatingSystem == "windows") { | 563 if (Platform.operatingSystem == "windows") { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 729 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
730 | 730 |
731 bool get success => exitCode == 0; | 731 bool get success => exitCode == 0; |
732 } | 732 } |
733 | 733 |
734 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 734 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
735 Uri _getUri(uri) { | 735 Uri _getUri(uri) { |
736 if (uri is Uri) return uri; | 736 if (uri is Uri) return uri; |
737 return Uri.parse(uri); | 737 return Uri.parse(uri); |
738 } | 738 } |
OLD | NEW |