Chromium Code Reviews| Index: pkg/front_end/lib/file_system.dart |
| diff --git a/pkg/front_end/lib/file_system.dart b/pkg/front_end/lib/file_system.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..087f4998fb94dea22353748df0b12d7e73bdd4a8 |
| --- /dev/null |
| +++ b/pkg/front_end/lib/file_system.dart |
| @@ -0,0 +1,78 @@ |
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library front_end.file_system; |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:path/path.dart' as path; |
| + |
| +/// Abstract interface to file system operations. |
| +/// |
| +/// All front end interaction with the file system goes through this interface; |
| +/// this makes it possible for clients to use the front end in a way that |
| +/// doesn't require file system access (e.g. to run unit tests, or to run |
| +/// inside a browser). |
| +/// |
| +/// Not intended to be implemented or extended by clients. |
| +abstract class FileSystem { |
| + /// Returns a path context suitable for use with this [FileSystem]. |
| + path.Context get context; |
| + |
| + /// Returns a [FileSystemEntity] corresponding to the given [path]. |
| + /// |
| + /// Uses of `..` and `.` in path are normalized before returning (so, for |
| + /// example, `entityForPath('./foo')` and `entityForPath('foo')` are |
| + /// equivalent). |
| + /// |
| + /// Does not check whether a file or folder exists at the given location. |
| + FileSystemEntity entityForPath(String path); |
| + |
| + /// Returns a [FileSystemEntity] corresponding to the given [uri]. |
| + /// |
| + /// Uses of `..` and `.` in the URI are normalized before returning. |
| + /// |
| + /// If [uri] is not a `file:` URI, an [Error] will be thrown. |
| + /// |
| + /// Does not check whether a file or folder exists at the given location. |
| + FileSystemEntity entityForUri(Uri uri); |
| +} |
| + |
| +/// Abstract representation of a file system entity that may or may not exist. |
| +/// |
| +/// Not intended to be implemented or extended by clients. |
| +abstract class FileSystemEntity { |
| + /// Returns the absolute path represented by this file system entity. |
|
scheglov
2016/10/18 20:43:40
A small tweak.
/User/foo/../bar/baz.dart is absolu
Paul Berry
2016/10/18 21:09:39
Done. I also modified the documentation on `entit
|
| + /// |
| + /// Note: if the [FileSystemEntity] was created using |
| + /// [FileSystem.entityForPath], this is not necessarily the same as the path |
| + /// that was used to create the object, since the path my have been |
|
scheglov
2016/10/18 20:43:40
"my have", "might have"?
Paul Berry
2016/10/18 21:09:39
Done.
|
| + /// normalized. |
| + String get path; |
| + |
| + /// Returns a `file:` URI representing this file system entity. |
|
scheglov
2016/10/18 20:43:40
It still does not answer my question, whether this
Paul Berry
2016/10/18 21:09:39
After some discussion, we decided to remove this g
|
| + /// |
| + /// Note: if the [FileSystemEntity] was created using |
| + /// [FileSystem.entityForUri], this is not necessarily the same as the Uri |
| + /// that was used to create the object, since the Uri my have been normalized. |
|
scheglov
2016/10/18 20:43:40
Same here my/might.
Paul Berry
2016/10/18 21:09:39
Acknowledged.
|
| + Uri get uri; |
| + |
| + /// Attempts to access this file system entity as a file and read its contents |
| + /// as raw bytes. |
| + /// |
| + /// If an error occurs while attempting to read the file (e.g. because no such |
| + /// file exists, or the entity is a directory), the future is completed with |
| + /// an [Exception]. |
| + Future<List<int>> readBytes(); |
|
Brian Wilkerson
2016/10/18 20:52:03
I still think this should be consistent with dart:
Paul Berry
2016/10/18 21:09:39
Done.
|
| + |
| + /// Attempts to access this file system entity as a file and read its contents |
| + /// as a string. |
| + /// |
| + /// The file is assumed to be UTF-8 encoded. |
| + /// |
| + /// If an error occurs while attempting to read the file (e.g. because no such |
| + /// file exists, or the entity is a directory), the future is completed with |
| + /// an [Exception]. |
| + Future<String> readString(); |
| +} |