Skip to content

Commit 91fee34

Browse files
authored
Update the Resource API spec (#2084)
- Adds async apis to the `Resource` class now that we allow async code - Adds a todo for a random access resource api. - [A question](#1482 (comment)) came up about listing directories/files, so added a todo to evaluate that, as well as random access files.
1 parent 29ef4a3 commit 91fee34

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

working/macros/feature-specification.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,9 @@ declaration that a macro is applied to.
10931093
used to import them? The latter would mean that files under `lib` could not read
10941094
resources outside of `lib`, which has both benefits and drawbacks.
10951095

1096-
Lastly, since macros must return synchronously, we only expose a synchronous
1097-
API for reading resources.
1096+
**TODO**: Evaluate APIs for listing files and directories.
1097+
1098+
**TODO**: Consider adding `RandomAccessResource` api.
10981099

10991100
The specific API is as follows, and would only be available at compile time:
11001101

@@ -1116,12 +1117,24 @@ class Resource {
11161117
/// Whether or not a resource actually exists at [uri].
11171118
bool get exists;
11181119
1120+
/// Read this resource as a stream of bytes.
1121+
Stream<Uint8List> openRead([int? start, int? end]);
1122+
1123+
/// Asynchronously reads this resource as bytes.
1124+
Future<Uint8List> readAsBytes();
1125+
11191126
/// Synchronously reads this resource as bytes.
11201127
Uint8List readAsBytesSync();
11211128
1129+
/// Asynchronously reads this resource as text using [encoding].
1130+
Future<String> readAsString({Encoding encoding = utf8});
1131+
11221132
/// Synchronously reads this resource as text using [encoding].
11231133
String readAsStringSync({Encoding encoding = utf8});
11241134
1135+
/// Asynchronously reads the resource as lines of text using [encoding].
1136+
Future<List<String>> readAsLines({Encoding encoding = utf8});
1137+
11251138
/// Synchronously reads the resource as lines of text using [encoding].
11261139
List<String> readAsLinesSync({Encoding encoding = utf8});
11271140
}

0 commit comments

Comments
 (0)