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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 /** | 242 /** |
243 * Write a list of bytes to a file. | 243 * Write a list of bytes to a file. |
244 * | 244 * |
245 * Opens the file, writes the list of bytes to it, and closes the file. | 245 * Opens the file, writes the list of bytes to it, and closes the file. |
246 * Returns a [:Future<File>:] that completes with this [File] object once | 246 * Returns a [:Future<File>:] that completes with this [File] object once |
247 * the entire operation has completed. | 247 * the entire operation has completed. |
248 * | 248 * |
249 * By default [writeAsBytes] creates the file for writing and truncates the | 249 * By default [writeAsBytes] creates the file for writing and truncates the |
250 * file if it already exists. In order to append the bytes to an existing | 250 * file if it already exists. In order to append the bytes to an existing |
251 * file, pass [FileMode.APPEND] as the optional mode parameter. | 251 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 252 * |
| 253 * If the argument [flush] is set to `true`, the data written will be |
| 254 * flushed to the file system before the returned future completes. |
252 */ | 255 */ |
253 Future<File> writeAsBytes(List<int> bytes, {FileMode mode: FileMode.WRITE}); | 256 Future<File> writeAsBytes(List<int> bytes, |
| 257 {FileMode mode: FileMode.WRITE, |
| 258 bool flush: false}); |
254 | 259 |
255 /** | 260 /** |
256 * Synchronously write a list of bytes to a file. | 261 * Synchronously write a list of bytes to a file. |
257 * | 262 * |
258 * Opens the file, writes the list of bytes to it and closes the file. | 263 * Opens the file, writes the list of bytes to it and closes the file. |
259 * | 264 * |
260 * By default [writeAsBytesSync] creates the file for writing and truncates | 265 * By default [writeAsBytesSync] creates the file for writing and truncates |
261 * the file if it already exists. In order to append the bytes to an existing | 266 * the file if it already exists. In order to append the bytes to an existing |
262 * file, pass [FileMode.APPEND] as the optional mode parameter. | 267 * file, pass [FileMode.APPEND] as the optional mode parameter. |
263 * | 268 * |
| 269 * If the [flush] argument is set to `true` data written will be |
| 270 * flushed to the file system before returning. |
| 271 * |
264 * Throws a [FileSystemException] if the operation fails. | 272 * Throws a [FileSystemException] if the operation fails. |
265 */ | 273 */ |
266 void writeAsBytesSync(List<int> bytes, {FileMode mode: FileMode.WRITE}); | 274 void writeAsBytesSync(List<int> bytes, |
| 275 {FileMode mode: FileMode.WRITE, |
| 276 bool flush: false}); |
267 | 277 |
268 /** | 278 /** |
269 * Write a string to a file. | 279 * Write a string to a file. |
270 * | 280 * |
271 * Opens the file, writes the string in the given encoding, and closes the | 281 * Opens the file, writes the string in the given encoding, and closes the |
272 * file. Returns a [:Future<File>:] that completes with this [File] object | 282 * file. Returns a [:Future<File>:] that completes with this [File] object |
273 * once the entire operation has completed. | 283 * once the entire operation has completed. |
274 * | 284 * |
275 * By default [writeAsString] creates the file for writing and truncates the | 285 * By default [writeAsString] creates the file for writing and truncates the |
276 * file if it already exists. In order to append the bytes to an existing | 286 * file if it already exists. In order to append the bytes to an existing |
277 * file, pass [FileMode.APPEND] as the optional mode parameter. | 287 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 288 * |
| 289 * If the argument [flush] is set to `true`, the data written will be |
| 290 * flushed to the file system before the returned future completes. |
| 291 * |
278 */ | 292 */ |
279 Future<File> writeAsString(String contents, | 293 Future<File> writeAsString(String contents, |
280 {FileMode mode: FileMode.WRITE, | 294 {FileMode mode: FileMode.WRITE, |
281 Encoding encoding: UTF8}); | 295 Encoding encoding: UTF8, |
| 296 bool flush: false}); |
282 | 297 |
283 /** | 298 /** |
284 * Synchronously write a string to a file. | 299 * Synchronously write a string to a file. |
285 * | 300 * |
286 * 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 |
287 * file. | 302 * file. |
288 * | 303 * |
289 * By default [writeAsStringSync] creates the file for writing and | 304 * By default [writeAsStringSync] creates the file for writing and |
290 * 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 |
291 * to an existing file, pass [FileMode.APPEND] as the optional mode | 306 * to an existing file, pass [FileMode.APPEND] as the optional mode |
292 * parameter. | 307 * parameter. |
293 * | 308 * |
| 309 * If the [flush] argument is set to `true` data written will be |
| 310 * flushed to the file system before returning. |
| 311 * |
294 * Throws a [FileSystemException] if the operation fails. | 312 * Throws a [FileSystemException] if the operation fails. |
295 */ | 313 */ |
296 void writeAsStringSync(String contents, | 314 void writeAsStringSync(String contents, |
297 {FileMode mode: FileMode.WRITE, | 315 {FileMode mode: FileMode.WRITE, |
298 Encoding encoding: UTF8}); | 316 Encoding encoding: UTF8, |
| 317 bool flush: false}); |
299 | 318 |
300 /** | 319 /** |
301 * Get the path of the file. | 320 * Get the path of the file. |
302 */ | 321 */ |
303 String get path; | 322 String get path; |
304 } | 323 } |
305 | 324 |
306 | 325 |
307 /** | 326 /** |
308 * [RandomAccessFile] provides random access to the data in a | 327 * [RandomAccessFile] provides random access to the data in a |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 544 } |
526 } else if (osError != null) { | 545 } else if (osError != null) { |
527 sb.write(": osError"); | 546 sb.write(": osError"); |
528 if (path != null) { | 547 if (path != null) { |
529 sb.write(", path = $path"); | 548 sb.write(", path = $path"); |
530 } | 549 } |
531 } | 550 } |
532 return sb.toString(); | 551 return sb.toString(); |
533 } | 552 } |
534 } | 553 } |
OLD | NEW |