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