| 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 import 'package:path/path.dart' as path; |
| 10 |
| 9 /// Abstract interface to file system operations. | 11 /// Abstract interface to file system operations. |
| 10 /// | 12 /// |
| 11 /// All front end interaction with the file system goes through this interface; | 13 /// All front end interaction with the file system goes through this interface; |
| 12 /// this makes it possible for clients to use the front end in a way that | 14 /// this makes it possible for clients to use the front end in a way that |
| 13 /// doesn't require file system access (e.g. to run unit tests, or to run | 15 /// doesn't require file system access (e.g. to run unit tests, or to run |
| 14 /// inside a browser). | 16 /// inside a browser). |
| 15 /// | 17 /// |
| 16 /// Not intended to be implemented or extended by clients. | 18 /// Not intended to be implemented or extended by clients. |
| 17 abstract class FileSystem { | 19 abstract class FileSystem { |
| 20 /// Returns a path context suitable for use with this [FileSystem]. |
| 21 /// |
| 22 /// TODO(paulberry): try to eliminate all usages of this. Since the |
| 23 /// FileSystem API now uses URIs rather than paths, it should not be needed. |
| 24 path.Context get context; |
| 25 |
| 18 /// Returns a [FileSystemEntity] corresponding to the given [uri]. | 26 /// Returns a [FileSystemEntity] corresponding to the given [uri]. |
| 19 /// | 27 /// |
| 20 /// Uses of `..` and `.` in the URI are normalized before returning. | 28 /// Uses of `..` and `.` in the URI are normalized before returning. |
| 21 /// | 29 /// |
| 22 /// If the URI scheme is not supported by this file system, an [Error] will be | 30 /// If the URI scheme is not supported by this file system, an [Error] will be |
| 23 /// thrown. | 31 /// thrown. |
| 24 /// | 32 /// |
| 25 /// Does not check whether a file or folder exists at the given location. | 33 /// Does not check whether a file or folder exists at the given location. |
| 26 FileSystemEntity entityForUri(Uri uri); | 34 FileSystemEntity entityForUri(Uri uri); |
| 27 } | 35 } |
| 28 | 36 |
| 29 /// Abstract representation of a file system entity that may or may not exist. | 37 /// Abstract representation of a file system entity that may or may not exist. |
| 30 /// | 38 /// |
| 31 /// Instances of this class have suitable implementations of equality tests and | 39 /// Instances of this class have suitable implementations of equality tests and |
| 32 /// hashCode. | 40 /// hashCode. |
| 33 /// | 41 /// |
| 34 /// Not intended to be implemented or extended by clients. | 42 /// Not intended to be implemented or extended by clients. |
| 35 abstract class FileSystemEntity { | 43 abstract class FileSystemEntity { |
| 36 /// The absolute normalized URI represented by this file system entity. | 44 /// Returns the absolute normalized URI represented by this file system |
| 45 /// entity. |
| 37 /// | 46 /// |
| 38 /// Note: this is not necessarily the same as the URI that was passed to | 47 /// Note: this is not necessarily the same as the URI that was passed to |
| 39 /// [FileSystem.entityForUri], since the URI might have been normalized. | 48 /// [FileSystem.entityForUri], since the URI might have been normalized. |
| 40 Uri get uri; | 49 Uri get uri; |
| 41 | 50 |
| 42 /// Attempts to access this file system entity as a file and read its contents | 51 /// Attempts to access this file system entity as a file and read its contents |
| 43 /// as raw bytes. | 52 /// as raw bytes. |
| 44 /// | 53 /// |
| 45 /// If an error occurs while attempting to read the file (e.g. because no such | 54 /// 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 | 55 /// file exists, or the entity is a directory), the future is completed with |
| 47 /// an [Exception]. | 56 /// an [Exception]. |
| 48 Future<List<int>> readAsBytes(); | 57 Future<List<int>> readAsBytes(); |
| 49 | 58 |
| 50 /// Attempts to access this file system entity as a file and read its contents | 59 /// Attempts to access this file system entity as a file and read its contents |
| 51 /// as a string. | 60 /// as a string. |
| 52 /// | 61 /// |
| 53 /// The file is assumed to be UTF-8 encoded. | 62 /// The file is assumed to be UTF-8 encoded. |
| 54 /// | 63 /// |
| 55 /// If an error occurs while attempting to read the file (e.g. because no such | 64 /// 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), | 65 /// file exists, the entity is a directory, or the file is not valid UTF-8), |
| 57 /// the future is completed with an [Exception]. | 66 /// the future is completed with an [Exception]. |
| 58 Future<String> readAsString(); | 67 Future<String> readAsString(); |
| 59 | |
| 60 /// Whether this file system entity exists. | |
| 61 Future<bool> exists(); | |
| 62 | |
| 63 /// Extracts the last-modification time of the file system entity, if it | |
| 64 /// exists and it is a file, otherwise the future is completed with an | |
| 65 /// [Exception]. | |
| 66 Future<DateTime> lastModified(); | |
| 67 } | 68 } |
| OLD | NEW |