Although not the most recommended usage, you can stream your content directly through your JS app. This can be helpful for kickstart or proof of concept projects. Ideally you may want to move the streamer to a service worker or a server to optimize your streaming process further and have more control.
Here is a basic example that demonstrate how to stream an epub:
import { createReader } from"@prose-reader/core";import { createArchiveFromText, generateManifestFromArchive, generateResourceFromArchive,} from"@prose-reader/streamer";import JSZip from"jszip";constreader=createReader({ containerElement:document.getElementById("app")!,});(async () => {constcontent=awaitfetch("content.epub");constzip=newJSZip();awaitzip.loadAsync(awaitcontent.blob());// we create the archive from our epub zip containerconstarchive=awaitcreateArchiveFromZip(awaitcontent.blob()); // the streamer can generate a manifest from various source // including jszip archiveconstmanifest=awaitgenerateManifestFromArchive(archive);reader.load(manifest, {// By default prose will fetch the resources via http. In our case we don't have// a server or a service worker so we want to serve the resource directly from// this script.fetchResource:async (item) => {// The streamer will automatically serve the correct resource for each item// provided the correct href and archive.constresource=awaitgenerateResourceFromArchive(archive,item.href);returnnewResponse(resource.body, { ...resource.params, status:200 }); }, });})();