Web (dom)
import { createReader } from "@prose-reader/core";
import {
createArchiveFromText,
generateManifestFromArchive,
generateResourceFromArchive,
} from "@prose-reader/streamer";
import JSZip from "jszip";
const reader = createReader({
containerElement: document.getElementById("app")!,
});
(async () => {
const content = await fetch("content.epub");
const zip = new JSZip();
await zip.loadAsync(await content.blob());
// we create the archive from our epub zip container
const archive = await createArchiveFromZip(await content.blob());
// the streamer can generate a manifest from various source
// including jszip archive
const manifest = await generateManifestFromArchive(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.
const resource = await generateResourceFromArchive(archive, item.href);
return new Response(resource.body, { ...resource.params, status: 200 });
},
});
})();Last updated