# epub cheatsheet
Every export of @deckyard/epub. The guides are Writing a book and Reading a book .
jennifer import "@deckyard/epub/" as epub;
Builders return the updated book: $b = epub.author($b, "Ada"). Every error the deck throws itself is an EpubError (kind "epub"); a reached cap is kind "limit".
# Constants
Constant Value Meaning MIMETYPE"application/epub+zip"the content of the mimetype entry ERROR_KIND"epub"the kind of every EpubError DEFAULT_MAX_BYTES134217728the largest EPUB read takes (128 MiB) DEFAULT_MAX_ENTRIES10000the most files in the archive DEFAULT_MAX_ENTRY_BYTES67108864the largest unpacked file (64 MiB) DEFAULT_MAX_TOTAL_BYTES268435456the most unpacked bytes in all (256 MiB)
# Writing
Function Returns Does book(title, lang)Booka new book with a derived identifier, a fixed modified and a default style.css author(b, name)Bookappends a creator chapter(b, href, title, body)Bookappends a chapter from the XHTML of its <body>; reason "content" when not well formed markdownChapter(b, href, title, md)Bookappends a chapter rendered from Markdown image(b, href, data)Bookadds a picture; the media type comes from the extension cover(b, href, data)Bookadds a picture and marks it as the cover file(b, href, mediaType, data)Bookadds any other file (a font, audio) stylesheet(b, css)Bookreplaces style.css, which every chapter links tocEntry(b, title, href, level)Bookappends a table of contents line; href "" for a heading chapters(b, parts)Bookappends many chapters (list of ChapterSource) in one call images(b, pictures)Bookadds many pictures (list of ImageSource) in one call tocEntries(b, entries)Bookappends many table of contents lines (list of TocEntry) rename(b, oldHref, newHref)Bookrenames a chapter or file and rewrites the links, TOC, landmarks, pages and cover pointing at it check(b)list of stringwarnings for links, sources and #fragments in the book that lead nowhere writable(b)Bookthe book as build writes it, every conversion of a read book noted in notes (and empty TOC headings dropped) build(b)bytesthe EPUB 3.3 file; toc.ncx too when ncx is set, deflated when compress is
# Reading
Function Returns Does read(data)Bookreads an EPUB 2 or 3 file with the default caps readWith(data, opts)Bookreads with the caps in opts readOptions()ReadOptionsthe default caps, to adjust text(c)stringa chapter as plain text, one paragraph per block resource(b, href)Resourcea file of the book by href; reason "missing" when absent resolve(base, href)stringa link written in the file base, as an href
# Types
# Book
Field Meaning title as stringthe title lang as stringthe language, a BCP 47 tag identifier as stringthe unique identifier authors as list of stringthe creators, in order description as string"" for nonepublisher as string"" for nonedate as stringthe publication date, "" for none modified as stringYYYY-MM-DDThh:mm:ssZ; "" in a read EPUB 2 book, and build then writes 2026-01-01T00:00:00Zversion as string"3.0" when built; as declared when readcover as stringthe cover's href: an image among the resources or a chapter (cover page); "" for none chapters as list of Chapterthe spine, in reading order toc as list of TocEntrythe table of contents; when empty, build lists the chapters resources as list of Resourceevery other file ncx as boolbuild also writes toc.ncx; read sets it when the book has onedirection as string"" (none written), "ltr" or "rtl": the pages' dir and the spine's page-progression-directioncompress as boolbuild deflates every entry but mimetype; read sets it when an entry is deflatedlayout as string"", "reflowable" or "pre-paginated" (rendition:layout)orientation as string"", "auto", "landscape" or "portrait"spread as string"", "none", "landscape", "portrait", "both" or "auto"flow as string"", "paginated", "scrolled-continuous", "scrolled-doc" or "auto"viewport as stringa fixed-layout page's <meta name="viewport">; chapters take it when added landmarks as list of Landmarkthe landmarks; empty, build generates them pages as list of PageTargetthe page list of a printed edition mediaMeta as list of Metathe package's media: metadata, for media overlays notes as list of stringwhat read tolerated (a declared legacy charset, a missing or case-mismatched file, an imperfect mimetype); empty for a well-formed book, ignored by build
# Chapter
Field Meaning id as stringits manifest id href as stringits path, relative to the package document, decoded (a b.xhtml) title as stringits table of contents entry, else its <title> mediaType as stringapplication/xhtml+xml for XHTMLproperties as stringits manifest properties (svg, mathml, scripted) content as stringthe whole document; "" for a picture in the spine linear as boolfalse for linear="no" wellFormed as boolwhether the xml parser accepts it; false means it is read as HTML mediaOverlay as stringthe manifest id of its media overlay (SMIL), "" for none spineProperties as stringits spine itemref properties (page-spread-left, rendition:layout-pre-paginated)
# ChapterSource
A chapter for chapters.
Field Meaning href as stringits path in the book title as stringits title body as stringthe XHTML of its <body>, or Markdown markdown as boolbody is Markdown
# ImageSource
A picture for images.
Field Meaning href as stringits path in the book; the media type comes from the extension data as bytesthe image file
# Landmark
Field Meaning type as stringthe structural semantic (cover, toc, bodymatter, ...) title as stringthe label href as stringthe target, with its #fragment
Field Meaning property as stringa media: property (media:duration, media:narrator) refines as stringwhat it refines (#mo1), "" for the book value as stringits value
# PageTarget
Field Meaning label as stringthe page number as printed href as stringwhere the page starts, with its #fragment
# TocEntry
Field Meaning title as stringthe label href as stringa chapter's href with an optional #fragment; "" for a heading level as intthe nesting depth, 0 at the top
# Resource
Field Meaning id as stringits manifest id href as stringits path, relative to the package document mediaType as stringits media type properties as stringits manifest properties (cover-image) data as bytesits content; an obfuscated font comes back restored
# ReadOptions
A field at 0 takes the default, a negative one lifts the cap.
Field Meaning maxBytes as intthe largest EPUB file maxEntries as intthe most archive entries maxEntryBytes as intthe largest unpacked entry maxTotalBytes as intthe most unpacked bytes in all
# EpubError
Thrown, not returned: test $e.kind == "epub" before reading reason.
Field Meaning kind as string"epub"message as stringwhat went wrong, starting epub: reason as string"archive", "container", "package", "drm", "content", "toc", "missing" or "input"