mbook
mbook is a file format for books: chapters in Markdown, pictures in AVIF, and small typed tables that describe the book, all stored as independent OpenZL frames inside one indexed container.
The pairing of OpenZL and AVIF is what makes a book small and quick: an illustrated EPUB of 7.0 MB became an mbook file of 1.6 MB that opens in 80 µs and decodes its text at more than a gigabyte per second. The conditions are in RFC 0001, A converted book.
This site holds the specification of the format and the documentation of the three crates built on it.
| Part | What it is | Start at |
|---|---|---|
| The format | The specification every reader and writer is checked against, and the decisions behind it | RFC 0001 |
mbook | The Rust library that reads, edits and writes mbook files | mbook |
mbook-converter | The Rust library that turns EPUB, FB2, PDF and five other formats into mbook, and back | mbook-converter |
mbook-ui | The application: a library of books, a reader and an editor | mbook-ui |
Where to start
| If you want to… | Read |
|---|---|
| see what the format gains over EPUB and FB2 | RFC 0001, Motivation |
| see what a file contains and how it is opened | RFC 0001, guide-level explanation |
| implement a reader or a writer | RFC 0001, reference-level explanation |
| understand why the format looks this way | Decision records |
| read or write books from Rust | Using mbook |
| look up a type or a call of the library | mbook, API reference, or docs.rs |
| convert a book into mbook, or export one | Using mbook-converter |
| know what a conversion keeps and what it drops | Conversion rules |
| read and edit books without writing code | Using the application |
| work on the application | mbook-ui, Architecture |
| know what is still open | Unresolved questions of RFC 0001, and "Settled and open questions" of mbook, mbook-converter and mbook-ui |
Two kinds of document
The format is specified; the crates are described.
| The format | A crate | |
|---|---|---|
| Documents | RFC 0001 and the decision records | The pages of mbook, mbook-converter and mbook-ui |
| Says | What a file MUST contain and what a reader MUST do with it | What the code does today, and why it is built this way |
| Binds | Every implementation of the format, in any language | This repository only |
| A choice between alternatives is recorded | As a decision record (ADR) | In the "Rationale and alternatives" table of the crate's Design page |
| Changes | When the format changes | With the code, in the same change |
An RFC specifies behaviour: it is what an implementation is checked against. A decision record explains one choice the RFC makes: the options that were compared, the trade-off, and what follows from it. The RFC links to the records instead of repeating them.
The pages of a crate are not normative. They describe what exists, mark what is not implemented, and where they say that something "must" hold, they state an invariant of this code that a test or a review keeps. RFC 0002 to RFC 0004, which described the three crates in earlier versions of this site, became these pages; the old addresses lead to them.
| Page of a crate | What it answers |
|---|---|
| Overview | What the crate is, what it is for, its goals and non-goals. |
| Guide | How each task is done, with its code or its screen. |
| API reference, Conversion rules, Architecture | What exactly the crate does: its types, its rules, its parts. |
| Design | Its dependencies, what the design costs, the alternatives that were rejected, and what is still open. |
Documents
| Document | Title | Status |
|---|---|---|
| RFC 0001 | The mbook file format, version 1 | Draft |
| ADR-0001 … ADR-0011 | Decisions behind RFC 0001 | See the overview |
| mbook | The library that reads and writes the format | Implements the whole of RFC 0001 |
| mbook-converter | Import from eight formats, export to the same eight | Implemented; limits per format |
| mbook-ui | The reading and editing application | A first version; what is implemented |
Outline of an RFC
| Section | What it answers |
|---|---|
| Summary | What is proposed, in a paragraph. |
| Motivation | Why the format needs it; goals and non-goals. |
| Guide-level explanation | How it looks to someone packing or reading a book. |
| Reference-level explanation | The normative rules an implementation follows. |
| Drawbacks | What the design costs. |
| Rationale and alternatives | The decisions taken, with links to their records. |
| Prior art | Related formats and what was taken from them. |
| Unresolved questions | What must be settled before the RFC is accepted. |
| Future possibilities | What the design leaves room for. |
Reading the normative text
The key words MUST, MUST NOT, REQUIRED, SHOULD, SHOULD NOT, RECOMMENDED, MAY and OPTIONAL are to be interpreted as described in RFC 2119 and RFC 8174 when, and only when, they appear in capitals. They are used in the Reference-level explanation of an RFC and nowhere else: everything outside that section, and every page of a crate, is informative.
Building this site
The site is an mdBook in the docs
folder of the
repository, with
mdbook-mermaid for the diagrams.
It is published to GitHub Pages from the main branch.
Extract the diagram scripts once:
mdbook-mermaid install docs
Then serve the book with live reload:
mdbook serve docs --open
The HTML is written to target/book.