| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 */ | 111 */ |
| 112 Future<bool> fileExists(file) { | 112 Future<bool> fileExists(file) { |
| 113 return new File(_getPath(file)).exists(); | 113 return new File(_getPath(file)).exists(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Reads the contents of the text file [file], which can either be a [String] or | 117 * Reads the contents of the text file [file], which can either be a [String] or |
| 118 * a [File]. | 118 * a [File]. |
| 119 */ | 119 */ |
| 120 Future<String> readTextFile(file) { | 120 Future<String> readTextFile(file) { |
| 121 return new File(_getPath(file)).readAsText(Encoding.UTF_8); | 121 return new File(_getPath(file)).readAsString(Encoding.UTF_8); |
| 122 } | 122 } |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * Creates [file] (which can either be a [String] or a [File]), and writes | 125 * Creates [file] (which can either be a [String] or a [File]), and writes |
| 126 * [contents] to it. Completes when the file is written and closed. | 126 * [contents] to it. Completes when the file is written and closed. |
| 127 */ | 127 */ |
| 128 Future<File> writeTextFile(file, String contents) { | 128 Future<File> writeTextFile(file, String contents) { |
| 129 file = new File(_getPath(file)); | 129 file = new File(_getPath(file)); |
| 130 return file.open(FileMode.WRITE).chain((opened) { | 130 return file.open(FileMode.WRITE).chain((opened) { |
| 131 return opened.writeString(contents).chain((ignore) { | 131 return opened.writeString(contents).chain((ignore) { |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 return new Directory(entry); | 746 return new Directory(entry); |
| 747 } | 747 } |
| 748 | 748 |
| 749 /** | 749 /** |
| 750 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 750 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 751 */ | 751 */ |
| 752 Uri _getUri(uri) { | 752 Uri _getUri(uri) { |
| 753 if (uri is Uri) return uri; | 753 if (uri is Uri) return uri; |
| 754 return new Uri.fromString(uri); | 754 return new Uri.fromString(uri); |
| 755 } | 755 } |
| OLD | NEW |