| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 Future<File> writeTextFile(file, String contents) { | 118 Future<File> writeTextFile(file, String contents) { |
| 119 file = new File(_getPath(file)); | 119 file = new File(_getPath(file)); |
| 120 return file.open(FileMode.WRITE).chain((opened) { | 120 return file.open(FileMode.WRITE).chain((opened) { |
| 121 return opened.writeString(contents).chain((ignore) { | 121 return opened.writeString(contents).chain((ignore) { |
| 122 return opened.close().transform((ignore) => file); | 122 return opened.close().transform((ignore) => file); |
| 123 }); | 123 }); |
| 124 }); | 124 }); |
| 125 } | 125 } |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * Asynchronously deletes [file], which can be a [String] or a [File]. Returns a |
| 129 * [Future] that completes when the deletion is done. |
| 130 */ |
| 131 Future<Directory> deleteFile(file) { |
| 132 file = _getFile(file); |
| 133 return file.delete(); |
| 134 } |
| 135 |
| 136 /** |
| 128 * Creates a directory [dir]. Returns a [Future] that completes when the | 137 * Creates a directory [dir]. Returns a [Future] that completes when the |
| 129 * directory is created. | 138 * directory is created. |
| 130 */ | 139 */ |
| 131 Future<Directory> createDir(dir) { | 140 Future<Directory> createDir(dir) { |
| 132 dir = _getDirectory(dir); | 141 dir = _getDirectory(dir); |
| 133 return dir.create(); | 142 return dir.create(); |
| 134 } | 143 } |
| 135 | 144 |
| 136 /** | 145 /** |
| 137 * Ensures that [path] and all its parent directories exist. If they don't | 146 * Ensures that [path] and all its parent directories exist. If they don't |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 return new Directory(entry); | 469 return new Directory(entry); |
| 461 } | 470 } |
| 462 | 471 |
| 463 /** | 472 /** |
| 464 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 473 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 465 */ | 474 */ |
| 466 Uri _getUri(uri) { | 475 Uri _getUri(uri) { |
| 467 if (uri is Uri) return uri; | 476 if (uri is Uri) return uri; |
| 468 return new Uri.fromString(uri); | 477 return new Uri.fromString(uri); |
| 469 } | 478 } |
| OLD | NEW |