Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library front_end.file_system; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:path/path.dart' as path; | |
| 10 | |
| 11 /// Abstract interface to file system operations. | |
| 12 /// | |
| 13 /// All front end interaction with the filesystem goes through this interface; | |
|
scheglov
2016/10/18 17:10:32
"filesystem" or "file system" here?
Paul Berry
2016/10/18 20:34:57
I'm now using "file system" consistently.
| |
| 14 /// this makes it possible for clients to use the front end in a way that | |
| 15 /// doesn't require file system access (e.g. to run unit tests, or to run | |
| 16 /// inside a browser). | |
| 17 /// | |
| 18 /// Not intended to be implemented or extended by clients. | |
| 19 abstract class FileSystem { | |
| 20 /// Returns a [path.Context] suitable for use with this [FileSystem]. | |
|
Brian Wilkerson
2016/10/18 17:36:59
opinion: "[path.Context]" --> "context" | "path co
Paul Berry
2016/10/18 20:34:57
Done.
| |
| 21 path.Context get context; | |
| 22 | |
| 23 /// Returns a [FileSystemEntity] corresponding to the given [path]. | |
| 24 /// | |
| 25 /// Uses of `..` and `.` in path are normalized before returning (so, for | |
| 26 /// example, `entityForPath('./foo') and entityForPath('foo') are equivalent). | |
|
Brian Wilkerson
2016/10/18 17:36:59
nit: Missing or extra back-quote(s).
Paul Berry
2016/10/18 20:34:58
Done.
| |
| 27 /// | |
| 28 /// Does not check whether a file or folder exists at the given location. | |
| 29 FileSystemEntity entityForPath(String path); | |
|
scheglov
2016/10/18 17:10:32
Maybe drop some extra strings and just name this F
Paul Berry
2016/10/18 20:34:57
I'm concerned that this would lead to confusion, b
| |
| 30 | |
| 31 /// Returns a [FileSystemEntity] corresponding to the given [uri]. | |
| 32 /// | |
| 33 /// Uses of `..` and `.` in the URI are normalized before returning. | |
| 34 /// | |
| 35 /// If [uri] is not a `file:` URI, an [Error] will be thrown. | |
| 36 /// | |
| 37 /// Does not check whether a file or folder exists at the given location. | |
| 38 FileSystemEntity entityForUri(Uri uri); | |
| 39 } | |
| 40 | |
| 41 /// Abstract representation of a file system entity that may or may not exist. | |
| 42 /// | |
| 43 /// Not intended to be implemented or extended by clients. | |
| 44 abstract class FileSystemEntity { | |
|
Paul Berry
2016/10/18 16:56:43
I'm not sure how useful this class is. An alterna
scheglov
2016/10/18 17:10:31
I like having a more structured API with separate
Brian Wilkerson
2016/10/18 17:36:59
I agree.
1. It's better to have objects with an A
Paul Berry
2016/10/18 20:34:58
Acknowledged. Leaving as is.
| |
| 45 /// Returns the absolute path represented by this file system entity. | |
|
Brian Wilkerson
2016/10/18 17:36:59
Is it a normalized path or the path passed in to e
Paul Berry
2016/10/18 20:34:57
The normalized path. I've added a clarifying comm
| |
| 46 String get path; | |
| 47 | |
| 48 /// Returns a `file:` URI representing this file system entity. | |
|
scheglov
2016/10/18 17:10:31
Is it a Uri wrapper for [path], or the original Ur
Paul Berry
2016/10/18 20:34:58
It's a Uri built from [path] (it has to be because
| |
| 49 Uri get uri; | |
| 50 | |
| 51 /// Attempts to access this file system entity as a file and read its contents | |
| 52 /// as raw bytes. | |
| 53 /// | |
| 54 /// If no such file exists, `null` is returned. If an error occurs while | |
| 55 /// attempting to read the file, or the entity is a directory, the future is | |
| 56 /// completed with an [Exception]. | |
| 57 Future<List<int>> readFileBytes(); | |
|
scheglov
2016/10/18 17:10:32
Maybe just readBytes().
I don't think we need to
Brian Wilkerson
2016/10/18 17:36:59
Unless there's a strong argument to do otherwise I
Paul Berry
2016/10/18 20:34:57
Good points. Fixed.
Paul Berry
2016/10/18 20:34:57
Good point. You are correct that this is how dart
| |
| 58 | |
| 59 /// Attempts to access this file system entity as a file and read its contents | |
| 60 /// as a string. | |
| 61 /// | |
| 62 /// If no such file exists, `null` is returned. If an error occurs while | |
| 63 /// attempting to read the file, or the entity is a directory, the future is | |
| 64 /// completed with an [Exception]. | |
| 65 Future<String> readFileString(); | |
|
scheglov
2016/10/18 17:10:32
Again, maybe just readString().
We could specify
Paul Berry
2016/10/18 20:34:57
Done.
| |
| 66 } | |
| OLD | NEW |