• 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.

    Type Parameters

    • Type

      The type of the writer.

    Parameters

    • writer: Writer<Type>

      The writer for the EPUB book.

    • structure: EpubStructure

      The structure of the EPUB book.

    • Optionaloptions: GenerateOptions

      The options for the ZIP writer.

    Returns Promise<Type>

    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);