5
5
import 'dart:convert' ;
6
6
import 'dart:typed_data' ;
7
7
8
+ import 'package:meta/meta.dart' show sealed;
9
+
8
10
// TODO(brianquinlan): When we switch to using exception types outside of
9
11
// `dart:io` then change the doc strings to use reference syntax rather than
10
12
// code syntax e.g. `PathExistsException` => [PathExistsException].
11
13
14
+ /// Information about a directory, link, etc. stored in the [FileSystem] .
15
+ abstract interface class Metadata {
16
+ // TODO(brianquinlan): Document all public fields.
17
+
18
+ bool get isFile;
19
+ bool get isDirectory;
20
+ bool get isLink;
21
+ int get size;
22
+ }
23
+
12
24
/// The modes in which a File can be written.
13
25
class WriteMode {
14
26
/// Open the file for writing such that data can only be appended to the end
@@ -34,26 +46,18 @@ class WriteMode {
34
46
}
35
47
36
48
/// An abstract representation of a file system.
37
- base class FileSystem {
38
- /// Checks whether two paths refer to the same object in the file system.
39
- ///
40
- /// Throws `PathNotFoundException` if either path doesn't exist.
41
- ///
42
- /// Links are resolved before determining if the paths refer to the same
43
- /// object. Throws `PathNotFoundException` if either path requires resolving
44
- /// a broken link.
45
- bool same (String path1, String path2) {
46
- throw UnsupportedError ('same' );
47
- }
48
-
49
+ ///
50
+ /// TODO(brianquinlan): Far now, this class is not meant to be implemented,
51
+ /// extended outside of this package. Clarify somewhere that people implementing
52
+ /// this class should reach out to be.
53
+ @sealed
54
+ abstract class FileSystem {
49
55
/// Create a directory at the given path.
50
56
///
51
57
/// If the directory already exists, then `PathExistsException` is thrown.
52
58
///
53
59
/// If the parent path does not exist, then `PathNotFoundException` is thrown.
54
- void createDirectory (String path) {
55
- throw UnsupportedError ('createDirectory' );
56
- }
60
+ void createDirectory (String path);
57
61
58
62
/// Creates a temporary directory and returns its path.
59
63
///
@@ -82,9 +86,13 @@ base class FileSystem {
82
86
/// fileSystem.createTemporaryDirectory(prefix: 'myproject');
83
87
/// }
84
88
/// ```
85
- String createTemporaryDirectory ({String ? parent, String ? prefix}) {
86
- throw UnsupportedError ('createTemporaryDirectory' );
87
- }
89
+ String createTemporaryDirectory ({String ? parent, String ? prefix});
90
+
91
+ /// Metadata for the file system object at [path] .
92
+ ///
93
+ /// If `path` represents a symbolic link then metadata for the link is
94
+ /// returned.
95
+ Metadata metadata (String path);
88
96
89
97
/// Deletes the directory at the given path.
90
98
///
@@ -97,17 +105,13 @@ base class FileSystem {
97
105
/// - On Windows, if `path` is a symbolic link to a directory then the
98
106
/// symbolic link is deleted. Otherwise, a `FileSystemException` is thrown.
99
107
/// - On POSIX, a `FileSystemException` is thrown.
100
- void removeDirectory (String path) {
101
- throw UnsupportedError ('removeDirectory' );
102
- }
108
+ void removeDirectory (String path);
103
109
104
110
/// Deletes the directory at the given path and its contents.
105
111
///
106
112
/// If the directory (or its subdirectories) contains any symbolic links then
107
113
/// those links are deleted but their targets are not.
108
- void removeDirectoryTree (String path) {
109
- throw UnsupportedError ('removeDirectoryTree' );
110
- }
114
+ void removeDirectoryTree (String path);
111
115
112
116
/// Renames, and possibly moves a file system object from one path to another.
113
117
///
@@ -125,14 +129,19 @@ base class FileSystem {
125
129
// If `newPath` identifies an existing file or link, that entity is removed
126
130
// first. If `newPath` identifies an existing directory, the operation
127
131
// fails and raises [PathExistsException].
128
- void rename (String oldPath, String newPath) {
129
- throw UnsupportedError ('rename' );
130
- }
132
+ void rename (String oldPath, String newPath);
131
133
132
134
/// Reads the entire file contents as a list of bytes.
133
- Uint8List readAsBytes (String path) {
134
- throw UnsupportedError ('readAsBytes' );
135
- }
135
+ Uint8List readAsBytes (String path);
136
+
137
+ /// Checks whether two paths refer to the same object in the file system.
138
+ ///
139
+ /// Throws `PathNotFoundException` if either path doesn't exist.
140
+ ///
141
+ /// Links are resolved before determining if the paths refer to the same
142
+ /// object. Throws `PathNotFoundException` if either path requires resolving
143
+ /// a broken link.
144
+ bool same (String path1, String path2);
136
145
137
146
/// The directory path used to store temporary files.
138
147
///
@@ -156,9 +165,7 @@ base class FileSystem {
156
165
String path,
157
166
Uint8List data, [
158
167
WriteMode mode = WriteMode .failExisting,
159
- ]) {
160
- throw UnsupportedError ('writeAsBytes' );
161
- }
168
+ ]);
162
169
163
170
/// Write the string to a file.
164
171
///
@@ -177,7 +184,5 @@ base class FileSystem {
177
184
WriteMode mode = WriteMode .failExisting,
178
185
Encoding encoding = utf8,
179
186
String ? lineTerminator,
180
- ]) {
181
- throw UnsupportedError ('writeAsString' );
182
- }
187
+ ]);
183
188
}
0 commit comments