lpf static method
Sniffs a Lightweight Packaging MediaType (LPF).
References:
Implementation
static Future<MediaType?> lpf(SnifferContext context) async {
if (context.hasFileExtension(["lpf"]) ||
context.hasMediaType("application/lpf+zip")) {
return MediaType.lpf;
}
if (await context.containsArchiveEntryAt("index.html")) {
return MediaType.lpf;
}
// Somehow, [JSONObject] can't access JSON-LD keys such as `@context`.
MediaType? mediaType =
(await context.readArchiveEntryAt("publication.json"))
?.let((it) => utf8.decode(it.buffer.asUint8List()))
.let((manifest) {
if (manifest.contains("@context") &&
manifest.contains("https://www.w3.org/ns/pub-context")) {
return MediaType.lpf;
}
return null;
});
return mediaType;
}