OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 { |
11 static const READ = const FileMode._internal(0); | 11 static const READ = const FileMode._internal(0); |
12 static const WRITE = const FileMode._internal(1); | 12 static const WRITE = const FileMode._internal(1); |
13 static const APPEND = const FileMode._internal(2); | 13 static const APPEND = const FileMode._internal(2); |
14 const FileMode._internal(int this._mode); | 14 const FileMode._internal(int this._mode); |
15 final int _mode; | 15 final int _mode; |
16 } | 16 } |
17 | 17 |
18 | 18 |
19 /** | 19 /** |
20 * [File] objects are references to files. | 20 * [File] objects are references to files. |
21 * | 21 * |
22 * To operate on the underlying file data you need to either get | 22 * To operate on the underlying file data there are two options: |
23 * streams using [openInputStream] and [openOutputStream] or open the | 23 * |
24 * file for random access operations using [open]. | 24 * * use streaming by getting a [Stream] for the contents of the file |
| 25 * with [openRead] and by getting a [IOSink] for |
| 26 * writing contents to the file using [openWrite], or |
| 27 * * open the file for random access operations using [open]. |
25 */ | 28 */ |
26 abstract class File { | 29 abstract class File extends FileSystemEntity { |
27 /** | 30 /** |
28 * Create a File object. | 31 * Create a File object. |
29 */ | 32 */ |
30 factory File(String name) => new _File(name); | 33 factory File(String name) => new _File(name); |
31 | 34 |
32 /** | 35 /** |
33 * Create a File object from a Path object. | 36 * Create a File object from a Path object. |
34 */ | 37 */ |
35 factory File.fromPath(Path path) => new _File.fromPath(path); | 38 factory File.fromPath(Path path) => new _File.fromPath(path); |
36 | 39 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 * Returns a [:Future<String>:] that completes with the path. | 147 * Returns a [:Future<String>:] that completes with the path. |
145 */ | 148 */ |
146 Future<String> fullPath(); | 149 Future<String> fullPath(); |
147 | 150 |
148 /** | 151 /** |
149 * Synchronously get the canonical full path corresponding to the file name. | 152 * Synchronously get the canonical full path corresponding to the file name. |
150 */ | 153 */ |
151 String fullPathSync(); | 154 String fullPathSync(); |
152 | 155 |
153 /** | 156 /** |
154 * Create a new independent input stream for the file. The file | 157 * Create a new independent [Stream] for the contents of this |
155 * input stream must be closed when no longer used to free up system | 158 * file. |
156 * resources. | 159 * |
| 160 * In order to make sure that system resources are freed, the stream |
| 161 * must be read to completion or the subscription on the stream must |
| 162 * be cancelled. |
157 */ | 163 */ |
158 InputStream openInputStream(); | 164 Stream<List<int>> openRead(); |
| 165 |
159 | 166 |
160 /** | 167 /** |
161 * Creates a new independent output stream for the file. The file | 168 * Creates a new independent [IOSink] for the file. The |
162 * output stream must be closed when no longer used to free up | 169 * stream consumer must be closed when no longer used to free up |
163 * system resources. | 170 * system resources. |
164 * | 171 * |
165 * An output stream can be opened in two modes: | 172 * A IOSink can be opened for a file in two modes: |
166 * | 173 * |
167 * FileMode.WRITE: create the stream and truncate the underlying | 174 * * FileMode.WRITE: truncates the underlying file to length zero. |
168 * file to length zero. | 175 * * FileMode.APPEND: sets the position to the end of the underlying file. |
169 * | |
170 * FileMode.APPEND: create the stream and set the position to the end of | |
171 * the underlying file. | |
172 */ | 176 */ |
173 OutputStream openOutputStream([FileMode mode = FileMode.WRITE]); | 177 IOSink<File> openWrite([FileMode mode = FileMode.WRITE]); |
174 | 178 |
175 /** | 179 /** |
176 * Read the entire file contents as a list of bytes. Returns a | 180 * Read the entire file contents as a list of bytes. Returns a |
177 * [:Future<List<int>>:] that completes with the list of bytes that | 181 * [:Future<List<int>>:] that completes with the list of bytes that |
178 * is the contents of the file. | 182 * is the contents of the file. |
179 */ | 183 */ |
180 Future<List<int>> readAsBytes(); | 184 Future<List<int>> readAsBytes(); |
181 | 185 |
182 /** | 186 /** |
183 * Synchronously read the entire file contents as a list of bytes. | 187 * Synchronously read the entire file contents as a list of bytes. |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 sb.add(" ($osError)"); | 455 sb.add(" ($osError)"); |
452 } | 456 } |
453 } else if (osError != null) { | 457 } else if (osError != null) { |
454 sb.add(": osError"); | 458 sb.add(": osError"); |
455 } | 459 } |
456 return sb.toString(); | 460 return sb.toString(); |
457 } | 461 } |
458 final String message; | 462 final String message; |
459 final OSError osError; | 463 final OSError osError; |
460 } | 464 } |
OLD | NEW |