| 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * FileMode describes the modes in which a file can be opened. | 8 * FileMode describes the modes in which a file can be opened. |
| 9 */ | 9 */ |
| 10 class FileMode { | 10 class FileMode { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 * * [FileMode.WRITE]: truncates the file to length zero. | 197 * * [FileMode.WRITE]: truncates the file to length zero. |
| 198 * * [FileMode.APPEND]: sets the initial write position to the end | 198 * * [FileMode.APPEND]: sets the initial write position to the end |
| 199 * of the file. | 199 * of the file. |
| 200 * | 200 * |
| 201 * When writing strings through the returned [IOSink] the encoding | 201 * When writing strings through the returned [IOSink] the encoding |
| 202 * specified using [encoding] will be used. The returned [IOSink] | 202 * specified using [encoding] will be used. The returned [IOSink] |
| 203 * has an [:encoding:] property which can be changed after the | 203 * has an [:encoding:] property which can be changed after the |
| 204 * [IOSink] has been created. | 204 * [IOSink] has been created. |
| 205 */ | 205 */ |
| 206 IOSink openWrite({FileMode mode: FileMode.WRITE, | 206 IOSink openWrite({FileMode mode: FileMode.WRITE, |
| 207 Encoding encoding: Encoding.UTF_8}); | 207 Encoding encoding: UTF8}); |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * Read the entire file contents as a list of bytes. Returns a | 210 * Read the entire file contents as a list of bytes. Returns a |
| 211 * [:Future<List<int>>:] that completes with the list of bytes that | 211 * [:Future<List<int>>:] that completes with the list of bytes that |
| 212 * is the contents of the file. | 212 * is the contents of the file. |
| 213 */ | 213 */ |
| 214 Future<List<int>> readAsBytes(); | 214 Future<List<int>> readAsBytes(); |
| 215 | 215 |
| 216 /** | 216 /** |
| 217 * Synchronously read the entire file contents as a list of bytes. | 217 * Synchronously read the entire file contents as a list of bytes. |
| 218 * | 218 * |
| 219 * Throws a [FileException] if the operation fails. | 219 * Throws a [FileException] if the operation fails. |
| 220 */ | 220 */ |
| 221 List<int> readAsBytesSync(); | 221 List<int> readAsBytesSync(); |
| 222 | 222 |
| 223 /** | 223 /** |
| 224 * Read the entire file contents as a string using the given | 224 * Read the entire file contents as a string using the given |
| 225 * [Encoding]. | 225 * [Encoding]. |
| 226 * | 226 * |
| 227 * Returns a [:Future<String>:] that completes with the string once | 227 * Returns a [:Future<String>:] that completes with the string once |
| 228 * the file contents has been read. | 228 * the file contents has been read. |
| 229 */ | 229 */ |
| 230 Future<String> readAsString({Encoding encoding: Encoding.UTF_8}); | 230 Future<String> readAsString({Encoding encoding: UTF8}); |
| 231 | 231 |
| 232 /** | 232 /** |
| 233 * Synchronously read the entire file contents as a string using the | 233 * Synchronously read the entire file contents as a string using the |
| 234 * given [Encoding]. | 234 * given [Encoding]. |
| 235 * | 235 * |
| 236 * Throws a [FileException] if the operation fails. | 236 * Throws a [FileException] if the operation fails. |
| 237 */ | 237 */ |
| 238 String readAsStringSync({Encoding encoding: Encoding.UTF_8}); | 238 String readAsStringSync({Encoding encoding: UTF8}); |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * Read the entire file contents as lines of text using the given | 241 * Read the entire file contents as lines of text using the given |
| 242 * [Encoding]. | 242 * [Encoding]. |
| 243 * | 243 * |
| 244 * Returns a [:Future<List<String>>:] that completes with the lines | 244 * Returns a [:Future<List<String>>:] that completes with the lines |
| 245 * once the file contents has been read. | 245 * once the file contents has been read. |
| 246 */ | 246 */ |
| 247 Future<List<String>> readAsLines({Encoding encoding: Encoding.UTF_8}); | 247 Future<List<String>> readAsLines({Encoding encoding: UTF8}); |
| 248 | 248 |
| 249 /** | 249 /** |
| 250 * Synchronously read the entire file contents as lines of text | 250 * Synchronously read the entire file contents as lines of text |
| 251 * using the given [Encoding]. | 251 * using the given [Encoding]. |
| 252 * | 252 * |
| 253 * Throws a [FileException] if the operation fails. | 253 * Throws a [FileException] if the operation fails. |
| 254 */ | 254 */ |
| 255 List<String> readAsLinesSync({Encoding encoding: Encoding.UTF_8}); | 255 List<String> readAsLinesSync({Encoding encoding: UTF8}); |
| 256 | 256 |
| 257 /** | 257 /** |
| 258 * Write a list of bytes to a file. | 258 * Write a list of bytes to a file. |
| 259 * | 259 * |
| 260 * Opens the file, writes the list of bytes to it, and closes the file. | 260 * Opens the file, writes the list of bytes to it, and closes the file. |
| 261 * Returns a [:Future<File>:] that completes with this [File] object once | 261 * Returns a [:Future<File>:] that completes with this [File] object once |
| 262 * the entire operation has completed. | 262 * the entire operation has completed. |
| 263 * | 263 * |
| 264 * By default [writeAsBytes] creates the file for writing and truncates the | 264 * By default [writeAsBytes] creates the file for writing and truncates the |
| 265 * file if it already exists. In order to append the bytes to an existing | 265 * file if it already exists. In order to append the bytes to an existing |
| (...skipping 20 matching lines...) Expand all Loading... |
| 286 * Opens the file, writes the string in the given encoding, and closes the | 286 * Opens the file, writes the string in the given encoding, and closes the |
| 287 * file. Returns a [:Future<File>:] that completes with this [File] object | 287 * file. Returns a [:Future<File>:] that completes with this [File] object |
| 288 * once the entire operation has completed. | 288 * once the entire operation has completed. |
| 289 * | 289 * |
| 290 * By default [writeAsString] creates the file for writing and truncates the | 290 * By default [writeAsString] creates the file for writing and truncates the |
| 291 * file if it already exists. In order to append the bytes to an existing | 291 * file if it already exists. In order to append the bytes to an existing |
| 292 * file, pass [FileMode.APPEND] as the optional mode parameter. | 292 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 293 */ | 293 */ |
| 294 Future<File> writeAsString(String contents, | 294 Future<File> writeAsString(String contents, |
| 295 {FileMode mode: FileMode.WRITE, | 295 {FileMode mode: FileMode.WRITE, |
| 296 Encoding encoding: Encoding.UTF_8}); | 296 Encoding encoding: UTF8}); |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * Synchronously write a string to a file. | 299 * Synchronously write a string to a file. |
| 300 * | 300 * |
| 301 * Opens the file, writes the string in the given encoding, and closes the | 301 * Opens the file, writes the string in the given encoding, and closes the |
| 302 * file. | 302 * file. |
| 303 * | 303 * |
| 304 * By default [writeAsStringSync] creates the file for writing and | 304 * By default [writeAsStringSync] creates the file for writing and |
| 305 * truncates the file if it already exists. In order to append the bytes | 305 * truncates the file if it already exists. In order to append the bytes |
| 306 * to an existing file, pass [FileMode.APPEND] as the optional mode | 306 * to an existing file, pass [FileMode.APPEND] as the optional mode |
| 307 * parameter. | 307 * parameter. |
| 308 * | 308 * |
| 309 * Throws a [FileException] if the operation fails. | 309 * Throws a [FileException] if the operation fails. |
| 310 */ | 310 */ |
| 311 void writeAsStringSync(String contents, | 311 void writeAsStringSync(String contents, |
| 312 {FileMode mode: FileMode.WRITE, | 312 {FileMode mode: FileMode.WRITE, |
| 313 Encoding encoding: Encoding.UTF_8}); | 313 Encoding encoding: UTF8}); |
| 314 | 314 |
| 315 /** | 315 /** |
| 316 * Get the path of the file. | 316 * Get the path of the file. |
| 317 */ | 317 */ |
| 318 String get path; | 318 String get path; |
| 319 } | 319 } |
| 320 | 320 |
| 321 | 321 |
| 322 /** | 322 /** |
| 323 * [RandomAccessFile] provides random access to the data in a | 323 * [RandomAccessFile] provides random access to the data in a |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 * Throws a [FileException] if the operation fails. | 421 * Throws a [FileException] if the operation fails. |
| 422 */ | 422 */ |
| 423 void writeFromSync(List<int> buffer, [int start, int end]); | 423 void writeFromSync(List<int> buffer, [int start, int end]); |
| 424 | 424 |
| 425 /** | 425 /** |
| 426 * Writes a string to the file using the given [Encoding]. Returns a | 426 * Writes a string to the file using the given [Encoding]. Returns a |
| 427 * [:Future<RandomAccessFile>:] that completes with this | 427 * [:Future<RandomAccessFile>:] that completes with this |
| 428 * RandomAccessFile when the write completes. | 428 * RandomAccessFile when the write completes. |
| 429 */ | 429 */ |
| 430 Future<RandomAccessFile> writeString(String string, | 430 Future<RandomAccessFile> writeString(String string, |
| 431 {Encoding encoding: Encoding.UTF_8}); | 431 {Encoding encoding: UTF8}); |
| 432 | 432 |
| 433 /** | 433 /** |
| 434 * Synchronously writes a single string to the file using the given | 434 * Synchronously writes a single string to the file using the given |
| 435 * [Encoding]. | 435 * [Encoding]. |
| 436 * | 436 * |
| 437 * Throws a [FileException] if the operation fails. | 437 * Throws a [FileException] if the operation fails. |
| 438 */ | 438 */ |
| 439 void writeStringSync(String string, | 439 void writeStringSync(String string, |
| 440 {Encoding encoding: Encoding.UTF_8}); | 440 {Encoding encoding: UTF8}); |
| 441 | 441 |
| 442 /** | 442 /** |
| 443 * Gets the current byte position in the file. Returns a | 443 * Gets the current byte position in the file. Returns a |
| 444 * [:Future<int>:] that completes with the position. | 444 * [:Future<int>:] that completes with the position. |
| 445 */ | 445 */ |
| 446 Future<int> position(); | 446 Future<int> position(); |
| 447 | 447 |
| 448 /** | 448 /** |
| 449 * Synchronously gets the current byte position in the file. | 449 * Synchronously gets the current byte position in the file. |
| 450 * | 450 * |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 } | 540 } |
| 541 } else if (osError != null) { | 541 } else if (osError != null) { |
| 542 sb.write(": osError"); | 542 sb.write(": osError"); |
| 543 if (path != null) { | 543 if (path != null) { |
| 544 sb.write(", path = $path"); | 544 sb.write(", path = $path"); |
| 545 } | 545 } |
| 546 } | 546 } |
| 547 return sb.toString(); | 547 return sb.toString(); |
| 548 } | 548 } |
| 549 } | 549 } |
| OLD | NEW |