Documentation Index
Fetch the complete documentation index at: https://mintlify.com/johnfactotum/foliate-js/llms.txt
Use this file to discover all available pages before exploring further.
mobi.js reads both classic Mobipocket (MOBI) and Kindle Format 8 (KF8, commonly distributed as .azw3 or as the KF8 section inside a combo .mobi file) from a browser File or Blob object. Unlike the EPUB and CBZ parsers, it does not need a zip loader — it parses the PalmDB container format directly. The module exports two items: the isMOBI detection function and the MOBI class.
isMOBI(file)
BOOKMOBI magic string in the PalmDB record header. Returns a boolean. Use this before constructing a MOBI instance to avoid errors on unsupported file types.
The file to inspect. Only the first 68 bytes are read.
new MOBI(options).open(file)
MOBI parser instance and opens the file. Returns a Promise that resolves to the fully-initialised book object implementing the standard book interface.
Synchronous decompression function with the signature
(data: Uint8Array) => Uint8Array. Required when the KF8 file contains zlib-compressed fonts. view.js passes fflate.unzlibSync from the vendored fflate library. If omitted and the file contains compressed fonts, those fonts will not load correctly.The Mobipocket or KF8 file to open.
MOBI vs KF8 behaviour
Theopen() method detects which format the file uses (including combo MOBI/KF8 files, where it prefers the KF8 section) and returns the appropriate book object. The two formats behave differently at runtime:
| Behaviour | MOBI (version < 8) | KF8 (version ≥ 8 / AZW3) |
|---|---|---|
| Text decompression | All text records decompressed eagerly at open time, then split into sections at every <mbp:pagebreak> tag | Lazy — only the records needed for the current section are decompressed when .load() is called |
| Decompression algorithm | PalmDOC LZ77 | HUFF/CDIC (slower; current implementation is not optimised) |
| Images and resources | Loaded on demand from PalmDB records | Loaded on demand from PalmDB records |
| Font support | No zlib-compressed fonts | May contain zlib-compressed fonts — requires unzlib option |
For MOBI files, decompressing all text at once and splitting at
<mbp:pagebreak> tags dramatically improves rendering performance compared to rendering the book as a single long page. For KF8, lazy section loading is used instead, though it can still be slow due to the HUFF/CDIC decompressor.Returned book object
The resolved value of.open(file) is a book object that implements the standard foliate-js book interface:
| Property / method | Description |
|---|---|
.sections | Array of section objects, one per page-break-delimited chunk (MOBI) or KF8 fragment. Each has .load(), .unload(), .createDocument(), and .size. |
.toc | Parsed table of contents derived from the NCX or INDX structures in the file. |
.metadata | Book metadata (title, author, language, description, etc.) extracted from the EXTH header. |
.dir | Page progression direction. |
.resolveHref(href) | Resolves an internal href to { index, anchor }. |
.splitTOCHref(href) | Splits a TOC href into [path, fragment]. |
.isExternal(uri) | Returns true if the URI should be opened externally. |
.getCover() | Returns the cover image as a Blob. |
.destroy() | Frees any blob URLs created during loading. |