| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 |
| 6 /** |
| 7 * FileMode describes the modes in which a file can be opened. |
| 8 */ |
| 9 class FileMode { |
| 10 static final READ = const FileMode(0); |
| 11 static final WRITE = const FileMode(1); |
| 12 static final APPEND = const FileMode(2); |
| 13 const FileMode(int this.mode); |
| 14 final int mode; |
| 15 } |
| 16 |
| 5 interface File default _File { | 17 interface File default _File { |
| 6 /** | 18 /** |
| 7 * Create a File object. | 19 * Create a File object. |
| 8 */ | 20 */ |
| 9 File(String name); | 21 File(String name); |
| 10 | 22 |
| 11 /** | 23 /** |
| 12 * Check if the file exists. The [existsHandler] is called with the | 24 * Check if the file exists. The [existsHandler] is called with the |
| 13 * result when the operation completes. | 25 * result when the operation completes. |
| 14 */ | 26 */ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 42 */ | 54 */ |
| 43 void delete(); | 55 void delete(); |
| 44 | 56 |
| 45 /** | 57 /** |
| 46 * Synchronously delete the file. | 58 * Synchronously delete the file. |
| 47 */ | 59 */ |
| 48 void deleteSync(); | 60 void deleteSync(); |
| 49 | 61 |
| 50 /** | 62 /** |
| 51 * Open the file for random access operations. When the file is | 63 * Open the file for random access operations. When the file is |
| 52 * opened the openHandler is called with the resulting | 64 * opened the [openHandler] is called with the resulting |
| 53 * RandomAccessFile. RandomAccessFiles must be closed using the | 65 * RandomAccessFile. RandomAccessFiles must be closed using the |
| 54 * close method. By default writable is false. | 66 * [close] method. If the file cannot be opened the [errorHandler] |
| 67 * is called. |
| 68 * |
| 69 * Files can be opened in three modes: |
| 70 * |
| 71 * FileMode.READ: open the file for reading. If the file does not |
| 72 * exist the [errorHandler] is called. |
| 73 * |
| 74 * FileMode.WRITE: open the file for both reading and writing and |
| 75 * truncate the file to length zero. If the file does not exist the |
| 76 * file is created. |
| 77 * |
| 78 * FileMode.APPEND: same as FileMode.WRITE except that the file is |
| 79 * not truncated. |
| 80 * |
| 81 * By default mode is FileMode.READ. |
| 55 */ | 82 */ |
| 56 void open([bool writable]); | 83 void open([FileMode mode]); |
| 57 | 84 |
| 58 /** | 85 /** |
| 59 * Synchronously open the file for random access operations. The | 86 * Synchronously open the file for random access operations. The |
| 60 * result is a RandomAccessFile on which random access operations | 87 * result is a RandomAccessFile on which random access operations |
| 61 * can be performed. Opened RandomAccessFiles must be closed using | 88 * can be performed. Opened RandomAccessFiles must be closed using |
| 62 * the close method. By default writable is false. | 89 * the [close] method. |
| 90 * |
| 91 * Files can be opened in three modes: |
| 92 * |
| 93 * FileMode.READ: open the file for reading. If the file does not |
| 94 * exist the [errorHandler] is called. |
| 95 * |
| 96 * FileMode.WRITE: open the file for both reading and writing and |
| 97 * truncate the file to length zero. If the file does not exist the |
| 98 * file is created. |
| 99 * |
| 100 * FileMode.APPEND: same as FileMode.WRITE except that the file is |
| 101 * not truncated. |
| 102 * |
| 103 * By default mode is FileMode.READ. |
| 63 */ | 104 */ |
| 64 RandomAccessFile openSync([bool writable]); | 105 RandomAccessFile openSync([FileMode mode]); |
| 65 | 106 |
| 66 /** | 107 /** |
| 67 * Get the canonical full path corresponding to the file name. The | 108 * Get the canonical full path corresponding to the file name. The |
| 68 * [fullPathHandler] is called when the fullPath operation | 109 * [fullPathHandler] is called when the fullPath operation |
| 69 * completes. | 110 * completes. |
| 70 */ | 111 */ |
| 71 String fullPath(); | 112 String fullPath(); |
| 72 | 113 |
| 73 /** | 114 /** |
| 74 * Synchronously get the canonical full path corresponding to the file name. | 115 * Synchronously get the canonical full path corresponding to the file name. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 void set flushHandler(void handler()); | 293 void set flushHandler(void handler()); |
| 253 void set errorHandler(void handler(String error)); | 294 void set errorHandler(void handler(String error)); |
| 254 } | 295 } |
| 255 | 296 |
| 256 | 297 |
| 257 class FileIOException implements Exception { | 298 class FileIOException implements Exception { |
| 258 const FileIOException([String this.message = ""]); | 299 const FileIOException([String this.message = ""]); |
| 259 String toString() => "FileIOException: $message"; | 300 String toString() => "FileIOException: $message"; |
| 260 final String message; | 301 final String message; |
| 261 } | 302 } |
| OLD | NEW |