createFetcher method
Future<Try<Fetcher, OpeningException> >
createFetcher(
- PublicationAssetDependencies dependencies,
- String? credentials
override
Creates a fetcher used to access the asset's content.
Implementation
@override
Future<Try<Fetcher, OpeningException>> createFetcher(
PublicationAssetDependencies dependencies, String? credentials) async {
try {
Fetcher? fetcher;
if (await FileSystemEntity.isDirectory(file.path)) {
fetcher = FileFetcher.single(href: "/", file: file);
} else if (await file.exists()) {
if ((await mediaType).isZip) {
fetcher = await ArchiveFetcher.fromPath(file.path,
archiveFactory: dependencies.archiveFactory);
} else {
fetcher = FileFetcher.single(href: "/$name", file: file);
}
} else {
throw FileNotFoundException(file.path);
}
return Try.success(fetcher);
} on FileNotFoundException {
return Try.failure(OpeningException.notFound);
}
}