archive static method
Sniffs a simple Archive-based MediaType, like Comic Book Archive or Zipped Audio Book.
Reference: https://wiki.mobileread.com/wiki/CBR_and_CBZ
Implementation
static Future<MediaType?> archive(SnifferContext context) async {
if (context.hasFileExtension(["cbz"]) ||
context.hasAnyOfMediaTypes([
"application/vnd.comicbook+zip",
"application/x-cbz",
"application/x-cbr"
])) {
return MediaType.cbz;
}
if (context.hasFileExtension(["zab"])) {
return MediaType.zab;
}
if (await context.contentAsArchive() != null) {
bool isIgnored(ArchiveEntry entry, File file) => basename(file.path)
.let((name) => name.startsWith(".") || name == "Thumbs.db");
Future<bool> archiveContainsOnlyExtensions(
List<String> fileExtensions) async =>
await context.archiveEntriesAllSatisfy((entry) {
File file = File(entry.path);
return isIgnored(entry, file) ||
fileExtensions.contains(file.path.extension().toLowerCase());
});
if (await archiveContainsOnlyExtensions(cbzExtensions)) {
return MediaType.cbz;
}
if (await archiveContainsOnlyExtensions(zabExtensions)) {
return MediaType.zab;
}
}
return null;
}