| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 /** | 263 /** |
| 264 * Write a list of bytes to a file. | 264 * Write a list of bytes to a file. |
| 265 * | 265 * |
| 266 * Opens the file, writes the list of bytes to it, and closes the file. | 266 * Opens the file, writes the list of bytes to it, and closes the file. |
| 267 * Returns a [:Future<File>:] that completes with this [File] object once | 267 * Returns a [:Future<File>:] that completes with this [File] object once |
| 268 * the entire operation has completed. | 268 * the entire operation has completed. |
| 269 * | 269 * |
| 270 * By default [writeAsBytes] creates the file for writing and truncates the | 270 * By default [writeAsBytes] creates the file for writing and truncates the |
| 271 * file if it already exists. In order to append the bytes to an existing | 271 * file if it already exists. In order to append the bytes to an existing |
| 272 * file, pass [FileMode.APPEND] as the optional mode parameter. | 272 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 273 * |
| 274 * If the argument [flush] is set to `true`, the data written will be |
| 275 * flushed to the file system before the returned future completes. |
| 273 */ | 276 */ |
| 274 Future<File> writeAsBytes(List<int> bytes, {FileMode mode: FileMode.WRITE}); | 277 Future<File> writeAsBytes(List<int> bytes, |
| 278 {FileMode mode: FileMode.WRITE, |
| 279 bool flush: false}); |
| 275 | 280 |
| 276 /** | 281 /** |
| 277 * Synchronously write a list of bytes to a file. | 282 * Synchronously write a list of bytes to a file. |
| 278 * | 283 * |
| 279 * Opens the file, writes the list of bytes to it and closes the file. | 284 * Opens the file, writes the list of bytes to it and closes the file. |
| 280 * | 285 * |
| 281 * By default [writeAsBytesSync] creates the file for writing and truncates | 286 * By default [writeAsBytesSync] creates the file for writing and truncates |
| 282 * the file if it already exists. In order to append the bytes to an existing | 287 * the file if it already exists. In order to append the bytes to an existing |
| 283 * file, pass [FileMode.APPEND] as the optional mode parameter. | 288 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 284 * | 289 * |
| 290 * If the [flush] argument is set to `true` data written will be |
| 291 * flushed to the file system before the returning. |
| 292 * |
| 285 * Throws a [FileException] if the operation fails. | 293 * Throws a [FileException] if the operation fails. |
| 286 */ | 294 */ |
| 287 void writeAsBytesSync(List<int> bytes, {FileMode mode: FileMode.WRITE}); | 295 void writeAsBytesSync(List<int> bytes, |
| 296 {FileMode mode: FileMode.WRITE, |
| 297 bool flush: false}); |
| 288 | 298 |
| 289 /** | 299 /** |
| 290 * Write a string to a file. | 300 * Write a string to a file. |
| 291 * | 301 * |
| 292 * Opens the file, writes the string in the given encoding, and closes the | 302 * Opens the file, writes the string in the given encoding, and closes the |
| 293 * file. Returns a [:Future<File>:] that completes with this [File] object | 303 * file. Returns a [:Future<File>:] that completes with this [File] object |
| 294 * once the entire operation has completed. | 304 * once the entire operation has completed. |
| 295 * | 305 * |
| 296 * By default [writeAsString] creates the file for writing and truncates the | 306 * By default [writeAsString] creates the file for writing and truncates the |
| 297 * file if it already exists. In order to append the bytes to an existing | 307 * file if it already exists. In order to append the bytes to an existing |
| 298 * file, pass [FileMode.APPEND] as the optional mode parameter. | 308 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 309 * |
| 310 * If the argument [flush] is set to `true`, the data written will be |
| 311 * flushed to the file system before the returned future completes. |
| 299 */ | 312 */ |
| 300 Future<File> writeAsString(String contents, | 313 Future<File> writeAsString(String contents, |
| 301 {FileMode mode: FileMode.WRITE, | 314 {FileMode mode: FileMode.WRITE, |
| 302 Encoding encoding: Encoding.UTF_8}); | 315 Encoding encoding: Encoding.UTF_8, |
| 316 bool flush: false}); |
| 303 | 317 |
| 304 /** | 318 /** |
| 305 * Synchronously write a string to a file. | 319 * Synchronously write a string to a file. |
| 306 * | 320 * |
| 307 * Opens the file, writes the string in the given encoding, and closes the | 321 * Opens the file, writes the string in the given encoding, and closes the |
| 308 * file. | 322 * file. |
| 309 * | 323 * |
| 310 * By default [writeAsStringSync] creates the file for writing and | 324 * By default [writeAsStringSync] creates the file for writing and |
| 311 * truncates the file if it already exists. In order to append the bytes | 325 * truncates the file if it already exists. In order to append the bytes |
| 312 * to an existing file, pass [FileMode.APPEND] as the optional mode | 326 * to an existing file, pass [FileMode.APPEND] as the optional mode |
| 313 * parameter. | 327 * parameter. |
| 314 * | 328 * |
| 329 * If the [flush] argument is set to `true` data written will be |
| 330 * flushed to the file system before the returning. |
| 331 * |
| 315 * Throws a [FileException] if the operation fails. | 332 * Throws a [FileException] if the operation fails. |
| 316 */ | 333 */ |
| 317 void writeAsStringSync(String contents, | 334 void writeAsStringSync(String contents, |
| 318 {FileMode mode: FileMode.WRITE, | 335 {FileMode mode: FileMode.WRITE, |
| 319 Encoding encoding: Encoding.UTF_8}); | 336 Encoding encoding: Encoding.UTF_8, |
| 337 bool flush: false}); |
| 320 | 338 |
| 321 /** | 339 /** |
| 322 * Get the path of the file. | 340 * Get the path of the file. |
| 323 */ | 341 */ |
| 324 String get path; | 342 String get path; |
| 325 } | 343 } |
| 326 | 344 |
| 327 | 345 |
| 328 /** | 346 /** |
| 329 * [RandomAccessFile] provides random access to the data in a | 347 * [RandomAccessFile] provides random access to the data in a |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 } | 564 } |
| 547 } else if (osError != null) { | 565 } else if (osError != null) { |
| 548 sb.write(": osError"); | 566 sb.write(": osError"); |
| 549 if (path != null) { | 567 if (path != null) { |
| 550 sb.write(", path = $path"); | 568 sb.write(", path = $path"); |
| 551 } | 569 } |
| 552 } | 570 } |
| 553 return sb.toString(); | 571 return sb.toString(); |
| 554 } | 572 } |
| 555 } | 573 } |
| OLD | NEW |