OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library front_end.file_system; | 5 library front_end.file_system; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 /// Abstract interface to file system operations. | 9 /// Abstract interface to file system operations. |
10 /// | 10 /// |
(...skipping 21 matching lines...) Expand all Loading... |
32 /// hashCode. | 32 /// hashCode. |
33 /// | 33 /// |
34 /// Not intended to be implemented or extended by clients. | 34 /// Not intended to be implemented or extended by clients. |
35 abstract class FileSystemEntity { | 35 abstract class FileSystemEntity { |
36 /// The absolute normalized URI represented by this file system entity. | 36 /// The absolute normalized URI represented by this file system entity. |
37 /// | 37 /// |
38 /// Note: this is not necessarily the same as the URI that was passed to | 38 /// Note: this is not necessarily the same as the URI that was passed to |
39 /// [FileSystem.entityForUri], since the URI might have been normalized. | 39 /// [FileSystem.entityForUri], since the URI might have been normalized. |
40 Uri get uri; | 40 Uri get uri; |
41 | 41 |
| 42 /// Whether this file system entity exists. |
| 43 Future<bool> exists(); |
| 44 |
| 45 /// Extracts the last-modification time of the file system entity, if it |
| 46 /// exists and it is a file, otherwise the future is completed with |
| 47 /// [FileSystemException]. |
| 48 Future<DateTime> lastModified(); |
| 49 |
42 /// Attempts to access this file system entity as a file and read its contents | 50 /// Attempts to access this file system entity as a file and read its contents |
43 /// as raw bytes. | 51 /// as raw bytes. |
44 /// | 52 /// |
45 /// If an error occurs while attempting to read the file (e.g. because no such | 53 /// If an error occurs while attempting to read the file (e.g. because no such |
46 /// file exists, or the entity is a directory), the future is completed with | 54 /// file exists, or the entity is a directory), the future is completed with |
47 /// an [Exception]. | 55 /// [FileSystemException]. |
48 Future<List<int>> readAsBytes(); | 56 Future<List<int>> readAsBytes(); |
49 | 57 |
50 /// Attempts to access this file system entity as a file and read its contents | 58 /// Attempts to access this file system entity as a file and read its contents |
51 /// as a string. | 59 /// as a string. |
52 /// | 60 /// |
53 /// The file is assumed to be UTF-8 encoded. | 61 /// The file is assumed to be UTF-8 encoded. |
54 /// | 62 /// |
55 /// If an error occurs while attempting to read the file (e.g. because no such | 63 /// If an error occurs while attempting to read the file (e.g. because no such |
56 /// file exists, the entity is a directory, or the file is not valid UTF-8), | 64 /// file exists, the entity is a directory, or the file is not valid UTF-8), |
57 /// the future is completed with an [Exception]. | 65 /// the future is completed with [FileSystemException]. |
58 Future<String> readAsString(); | 66 Future<String> readAsString(); |
| 67 } |
59 | 68 |
60 /// Whether this file system entity exists. | 69 /** |
61 Future<bool> exists(); | 70 * Base class for all file system exceptions. |
| 71 */ |
| 72 class FileSystemException implements Exception { |
| 73 final Uri uri; |
| 74 final String message; |
62 | 75 |
63 /// Extracts the last-modification time of the file system entity, if it | 76 FileSystemException(this.uri, this.message); |
64 /// exists and it is a file, otherwise the future is completed with an | 77 |
65 /// [Exception]. | 78 @override |
66 Future<DateTime> lastModified(); | 79 String toString() => 'FileSystemException(uri=$uri; message=$message)'; |
67 } | 80 } |
OLD | NEW |