The writer for the EPUB book.
The structure of the EPUB book.
Optional
options: GenerateOptionsThe options for the ZIP writer.
The writer with the EPUB book.
import { generateEpub, type EpubStructure } from "./generate";
import { BlobWriter } from "@zip.js/zip.js";
// Create a ZIP writer for the EPUB book.
// In this case, we use the BlobWriter to write the EPUB book to a Blob.
const writer = new BlobWriter("application/epub+zip");
// The structure of the EPUB book.
const structure: EpubStructure = {
mimetype: "application/epub+zip",
META_INF: {
"container.xml": `<?xml version="1.0" encoding="UTF-8"?>...`,
},
OEBPS: {
"content.opf": `<?xml version="1.0" encoding="UTF-8"?>...`,
"nav.xhtml": `<?xml version="1.0" encoding="UTF-8"?>...`,
},
};
// Generate the EPUB book.
const blob = await generateEpub(writer, structure);
Generate an EPUB book.
This function generates an EPUB book from the given structure and options. The resulting EPUB book is written to the writer, allowing you to handle the output in different ways, such as saving it to a file or streaming it over the network.