Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
clean up some apis (#30)
Browse files Browse the repository at this point in the history
- drop support for Uri objects in DirectoryDescriptor.load
- Use Object? instead of dynamic for `FileDescriptor` contents parameter
- Remove `parents` param in DirectoryDescriptor.load
  • Loading branch information
jakemac53 authored Nov 5, 2020
1 parent ac318af commit 852698f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* Migrate to null safety.
* Fix outdated URLs in `README.md`.
* BREAKING: Removed archive support.
* BREAKING: `DirectoryDescriptor.load` only supports a `String` path instead of
also accepting relative `Uri` objects.
* BREAKING: `DirectoryDescriptor.load` no longer has an optional `parents`
parameter - this was intended for internal use only.

## 1.2.0

Expand Down
23 changes: 6 additions & 17 deletions lib/src/directory_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,14 @@ class DirectoryDescriptor extends Descriptor {
}

/// Treats this descriptor as a virtual filesystem and loads the binary
/// contents of the [FileDescriptor] at the given relative [url], which may be
/// a [Uri] or a [String].
///
/// The [parents] parameter should only be passed by subclasses of
/// [DirectoryDescriptor] that are recursively calling [load]. It's the
/// URL-format path of the directories that have been loaded so far.
Stream<List<int>> load(url, [String? parents]) {
String path;
if (url is String) {
path = url;
} else if (url is Uri) {
path = url.toString();
} else {
throw ArgumentError.value(url, 'url', 'must be a Uri or a String.');
}
/// contents of the [FileDescriptor] at the given relative [path].
Stream<List<int>> load(String path) => _load(path);

/// Implementation of [load], tracks parents through recursive calls.
Stream<List<int>> _load(String path, [String? parents]) {
if (!p.url.isWithin('.', path)) {
throw ArgumentError.value(
url, 'url', 'must be relative and beneath the base URL.');
path, 'path', 'must be relative and beneath the base URL.');
}

return StreamCompleter.fromFuture(Future.sync(() {
Expand All @@ -117,7 +106,7 @@ class DirectoryDescriptor extends Descriptor {
return (matchingEntries.first as FileDescriptor).readAsBytes();
} else {
return (matchingEntries.first as DirectoryDescriptor)
.load(p.url.joinAll(remainingPath), parentsAndSelf);
._load(p.url.joinAll(remainingPath), parentsAndSelf);
}
}
}));
Expand Down
2 changes: 1 addition & 1 deletion lib/src/file_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class FileDescriptor extends Descriptor {
///
/// To match a [Matcher] against a file's binary contents, use [new
/// FileDescriptor.binaryMatcher] instead.
factory FileDescriptor(String name, contents) {
factory FileDescriptor(String name, Object? contents) {
if (contents is String) return _StringFileDescriptor(name, contents);
if (contents is List) {
return _BinaryFileDescriptor(name, contents.cast<int>());
Expand Down

0 comments on commit 852698f

Please sign in to comment.