| 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 /** | 6 /** |
| 7 * FileMode describes the modes in which a file can be opened. | 7 * FileMode describes the modes in which a file can be opened. |
| 8 */ | 8 */ |
| 9 class FileMode { | 9 class FileMode { |
| 10 static final READ = const FileMode(0); | 10 static final READ = const FileMode(0); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 * fails. | 156 * fails. |
| 157 */ | 157 */ |
| 158 void readAsBytes(void callback(List<int> bytes)); | 158 void readAsBytes(void callback(List<int> bytes)); |
| 159 | 159 |
| 160 /** | 160 /** |
| 161 * Synchronously read the entire file contents as a list of bytes. | 161 * Synchronously read the entire file contents as a list of bytes. |
| 162 */ | 162 */ |
| 163 List<int> readAsBytesSync(); | 163 List<int> readAsBytesSync(); |
| 164 | 164 |
| 165 /** | 165 /** |
| 166 * Read the entire file contents as text using the given [encoding] | 166 * Read the entire file contents as text using the given |
| 167 * ('UTF-8', 'ISO-8859-1', 'ASCII'). | 167 * [encoding]. The default encoding is UTF-8 - [:Encoding.UTF_8:]. |
| 168 * | 168 * |
| 169 * When the operation completes the callback is called. The | 169 * When the operation completes the callback is called. The |
| 170 * [onError] function registered on the file object is called if the | 170 * [onError] function registered on the file object is called if the |
| 171 * operation fails. | 171 * operation fails. |
| 172 */ | 172 */ |
| 173 void readAsText(String encoding, void callback(String text)); | 173 void readAsText(Encoding encoding, void callback(String text)); |
| 174 | 174 |
| 175 /** | 175 /** |
| 176 * Synchronously read the entire file contents as text using the | 176 * Synchronously read the entire file contents as text using the |
| 177 * given [encoding] ('UTF-8', 'ISO-8859-1', 'ASCII'). By default the | 177 * given [encoding]. The default encoding is UTF-8 - [:Encoding.UTF_8:]. |
| 178 * encoding is 'UTF-8'. | |
| 179 */ | 178 */ |
| 180 String readAsTextSync([String encoding]); | 179 String readAsTextSync([Encoding encoding]); |
| 181 | 180 |
| 182 /** | 181 /** |
| 183 * Read the entire file contents as lines of text using the give | 182 * Read the entire file contents as lines of text using the give |
| 184 * [encoding] ('UTF-8', 'ISO-8859-1', 'ASCII'). | 183 * [encoding]. The default encoding is UTF-8 - [:Encoding.UTF_8:]. |
| 185 * | 184 * |
| 186 * When the operation completes the callback is called. The | 185 * When the operation completes the callback is called. The |
| 187 * [onError] function registered on the file object is called if the | 186 * [onError] function registered on the file object is called if the |
| 188 * operation fails. | 187 * operation fails. |
| 189 */ | 188 */ |
| 190 void readAsLines(String encoding, void callback(List<String> lines)); | 189 void readAsLines(Encoding encoding, void callback(List<String> lines)); |
| 191 | 190 |
| 192 /** | 191 /** |
| 193 * Synchronously read the entire file contents as lines of text | 192 * Synchronously read the entire file contents as lines of text |
| 194 * using the given [encoding] ('UTF-8', 'ISO-8859-1', 'ASCII'). By | 193 * using the given [encoding] The default encoding is UTF-8 - |
| 195 * default the encoding is 'UTF-8'. | 194 * [:Encoding.UTF_8:]. |
| 196 */ | 195 */ |
| 197 List<String> readAsLinesSync([String encoding]); | 196 List<String> readAsLinesSync([Encoding encoding]); |
| 198 | 197 |
| 199 /** | 198 /** |
| 200 * Get the name of the file. | 199 * Get the name of the file. |
| 201 */ | 200 */ |
| 202 String get name(); | 201 String get name(); |
| 203 | 202 |
| 204 /** | 203 /** |
| 205 * Sets the handler that gets called when errors occur during | 204 * Sets the handler that gets called when errors occur during |
| 206 * operations on this file. | 205 * operations on this file. |
| 207 */ | 206 */ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 */ | 268 */ |
| 270 void writeList(List<int> buffer, int offset, int bytes); | 269 void writeList(List<int> buffer, int offset, int bytes); |
| 271 | 270 |
| 272 /** | 271 /** |
| 273 * Synchronously write a List<int> to the file. Returns the number | 272 * Synchronously write a List<int> to the file. Returns the number |
| 274 * of bytes successfully written. | 273 * of bytes successfully written. |
| 275 */ | 274 */ |
| 276 int writeListSync(List<int> buffer, int offset, int bytes); | 275 int writeListSync(List<int> buffer, int offset, int bytes); |
| 277 | 276 |
| 278 /** | 277 /** |
| 279 * Write a string to the file. If the string cannot be written the | 278 * Write a string to the file using the given [encoding]. If the |
| 280 * [onError] is called. When all pending write operations have | 279 * string cannot be written [onError] is called. The default |
| 281 * finished [onNoPendingWrites] is called. | 280 * encoding is UTF-8 - [:Encoding.UTF_8:]. |
| 281 * |
| 282 * When all pending write operations have finished |
| 283 * [onNoPendingWrites] is called. |
| 282 */ | 284 */ |
| 283 // TODO(ager): writeString should take an encoding. | 285 void writeString(String string, [Encoding encoding]); |
| 284 void writeString(String string); | |
| 285 | 286 |
| 286 /** | 287 /** |
| 287 * Synchronously write a single string to the file. Returns the number | 288 * Synchronously write a single string to the file using the given |
| 288 * of characters successfully written. | 289 * [encoding]. Returns the number of characters successfully |
| 290 * written. The default encoding is UTF-8 - [:Encoding.UTF_8:]. |
| 289 */ | 291 */ |
| 290 // TODO(ager): writeStringSync should take an encoding. | 292 int writeStringSync(String string, [Encoding encoding]); |
| 291 int writeStringSync(String string); | |
| 292 | 293 |
| 293 /** | 294 /** |
| 294 * Get the current byte position in the file. When the operation | 295 * Get the current byte position in the file. When the operation |
| 295 * completes the callback is called with the position. | 296 * completes the callback is called with the position. |
| 296 */ | 297 */ |
| 297 void position(void callback(int position)); | 298 void position(void callback(int position)); |
| 298 | 299 |
| 299 /** | 300 /** |
| 300 * Synchronously get the current byte position in the file. | 301 * Synchronously get the current byte position in the file. |
| 301 */ | 302 */ |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 */ | 363 */ |
| 363 void set onError(void handler(String error)); | 364 void set onError(void handler(String error)); |
| 364 } | 365 } |
| 365 | 366 |
| 366 | 367 |
| 367 class FileIOException implements Exception { | 368 class FileIOException implements Exception { |
| 368 const FileIOException([String this.message = ""]); | 369 const FileIOException([String this.message = ""]); |
| 369 String toString() => "FileIOException: $message"; | 370 String toString() => "FileIOException: $message"; |
| 370 final String message; | 371 final String message; |
| 371 } | 372 } |
| OLD | NEW |