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 * The modes in which a File can be opened. | 8 * The modes in which a File can be opened. |
9 */ | 9 */ |
10 class FileMode { | 10 class FileMode { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 * } | 107 * } |
108 * | 108 * |
109 * A more flexible and useful way to read a file is with a [Stream]. | 109 * A more flexible and useful way to read a file is with a [Stream]. |
110 * Open the file with [openRead], which returns a stream that | 110 * Open the file with [openRead], which returns a stream that |
111 * provides the data in the file as chunks of bytes. | 111 * provides the data in the file as chunks of bytes. |
112 * Listen to the stream for data and process as needed. | 112 * Listen to the stream for data and process as needed. |
113 * You can use various transformers in succession to manipulate the | 113 * You can use various transformers in succession to manipulate the |
114 * data into the required format or to prepare it for output. | 114 * data into the required format or to prepare it for output. |
115 * | 115 * |
116 * You might want to use a stream to read large files, | 116 * You might want to use a stream to read large files, |
117 * to manipulate the data with tranformers, | 117 * to manipulate the data with transformers, |
118 * or for compatibility with another API, such as [WebSocket]s. | 118 * or for compatibility with another API, such as [WebSocket]s. |
119 * | 119 * |
120 * import 'dart:io'; | 120 * import 'dart:io'; |
121 * import 'dart:convert'; | 121 * import 'dart:convert'; |
122 * import 'dart:async'; | 122 * import 'dart:async'; |
123 * | 123 * |
124 * main() { | 124 * main() { |
125 * final file = new File('file.txt'); | 125 * final file = new File('file.txt'); |
126 * Stream<List<int>> inputStream = file.openRead(); | 126 * Stream<List<int>> inputStream = file.openRead(); |
127 * | 127 * |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 * | 579 * |
580 * Throws a [FileSystemException] if the operation fails. | 580 * Throws a [FileSystemException] if the operation fails. |
581 */ | 581 */ |
582 List<int> readSync(int bytes); | 582 List<int> readSync(int bytes); |
583 | 583 |
584 /** | 584 /** |
585 * Reads into an existing [List<int>] from the file. If [start] is present, | 585 * Reads into an existing [List<int>] from the file. If [start] is present, |
586 * the bytes will be filled into [buffer] from at index [start], otherwise | 586 * the bytes will be filled into [buffer] from at index [start], otherwise |
587 * index 0. If [end] is present, the [end] - [start] bytes will be read into | 587 * index 0. If [end] is present, the [end] - [start] bytes will be read into |
588 * [buffer], otherwise up to [buffer.length]. If [end] == [start] nothing | 588 * [buffer], otherwise up to [buffer.length]. If [end] == [start] nothing |
589 * happends. | 589 * happens. |
590 * | 590 * |
591 * Returns a [:Future<int>:] that completes with the number of bytes read. | 591 * Returns a [:Future<int>:] that completes with the number of bytes read. |
592 */ | 592 */ |
593 Future<int> readInto(List<int> buffer, [int start = 0, int end]); | 593 Future<int> readInto(List<int> buffer, [int start = 0, int end]); |
594 | 594 |
595 /** | 595 /** |
596 * Synchronously reads into an existing [List<int>] from the file. If [start] | 596 * Synchronously reads into an existing [List<int>] from the file. If [start] |
597 * is present, the bytes will be filled into [buffer] from at index [start], | 597 * is present, the bytes will be filled into [buffer] from at index [start], |
598 * otherwise index 0. If [end] is present, the [end] - [start] bytes will be | 598 * otherwise index 0. If [end] is present, the [end] - [start] bytes will be |
599 * read into [buffer], otherwise up to [buffer.length]. If [end] == [start] | 599 * read into [buffer], otherwise up to [buffer.length]. If [end] == [start] |
600 * nothing happends. | 600 * nothing happens. |
601 * | 601 * |
602 * Throws a [FileSystemException] if the operation fails. | 602 * Throws a [FileSystemException] if the operation fails. |
603 */ | 603 */ |
604 int readIntoSync(List<int> buffer, [int start = 0, int end]); | 604 int readIntoSync(List<int> buffer, [int start = 0, int end]); |
605 | 605 |
606 /** | 606 /** |
607 * Writes a single byte to the file. Returns a | 607 * Writes a single byte to the file. Returns a |
608 * [:Future<RandomAccessFile>:] that completes with this | 608 * [:Future<RandomAccessFile>:] that completes with this |
609 * RandomAccessFile when the write completes. | 609 * RandomAccessFile when the write completes. |
610 */ | 610 */ |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 sb.write(": $osError"); | 890 sb.write(": $osError"); |
891 if (path != null) { | 891 if (path != null) { |
892 sb.write(", path = '$path'"); | 892 sb.write(", path = '$path'"); |
893 } | 893 } |
894 } else if (path != null) { | 894 } else if (path != null) { |
895 sb.write(": $path"); | 895 sb.write(": $path"); |
896 } | 896 } |
897 return sb.toString(); | 897 return sb.toString(); |
898 } | 898 } |
899 } | 899 } |
OLD | NEW |