EpubResourceFetcher

Fetches a resource that a book names by an absolute https URL instead of a file in its container, such as a font or an image on a web server (EPUB 3.3, 3.6). Reading systems should support such remote resources, and should load them over https only (EPUB Reading Systems 3.3, 3.3), so the book never passes another scheme here: an http URL is refused before it reaches the fetcher (#38).

Set one on EpubSettings.resourceFetcher. kitepdf-net ships one on a Ktor client. A fetch tells the URL's server that the book was opened, and the book's author chose that server, so fetching is opt-in: without a fetcher, a remote image takes its manifest fallback, else keeps the room its width and height give, and a remote font takes the next source of its rule.

The book calls fetch once per URL, on Dispatchers.Default, however many documents and chapters name it, and keeps the bytes it returns for its whole life, so a chapter that lays out again finds what it found the first time.

Functions

Link copied to clipboard
abstract suspend fun fetch(url: String): ByteArray?

The bytes at url, an absolute https URL, or null when they cannot be had. A throw counts as null. Cap the size: the book holds every resource in memory.