epub-stream
Memory-efficient EPUB parser for embedded systems.
Streaming architecture targeting constrained devices.
no_std compatible with optional alloc.
Status
Core EPUB parsing, tokenization, navigation, CSS subset, and layout engine are implemented. See docs/spec-compliance.md and docs/compliance.md for current coverage details. Dataset bootstrap and corpus validation flow is documented in docs/datasets.md. Embedded-focused usage patterns are documented in docs/embedded.md.
Note: ZIP64 archives are currently not supported and are rejected explicitly.
Features
| Feature | Description | Default |
|---|---|---|
std |
Standard library + ZIP | yes |
layout |
Text layout / pagination | no |
async |
Async file-open helpers | no |
cli |
epub-stream inspect binary |
no |
Usage
[]
= "0.2"
Quick Start
use EpubBook;
Optional Safety Limits
By default, EPUB reading does not enforce implicit file-size caps. To enforce explicit limits, use either API below.
Builder API
use ;
let limits = new; // explicit caps
let mut book = builder
.with_zip_limits
.open?;
# Ok::
Chapter Ergonomics
use EpubBook;
let mut book = open?;
for chapter in book.chapters
let first_text = book.chapter_text?;
println!;
# Ok::
Rendering Stack (Decoupled Crates)
epub-stream remains the EPUB parse/prep crate.
Rendering is split into:
epub-stream-render: render IR + layout engine + chapter-to-pages orchestrationepub-stream-embedded-graphics:embedded-graphicsbackend executor for render commandsepub-stream-render-web: self-contained HTML preview generator for rapid layout/font/TOC validation
Add local workspace deps:
[]
= { = "." }
= { = "crates/epub-stream-render" }
= { = "crates/epub-stream-embedded-graphics" }
= { = "crates/epub-stream-render-web" }
Prepare a chapter into backend-agnostic render pages:
use EpubBook;
use ;
let mut book = open?;
let engine = new;
let pages = engine.prepare_chapter?;
println!;
# Ok::
Execute those pages on embedded-graphics:
use MockDisplay;
use BinaryColor;
use EgRenderer;
# use EpubBook;
# use ;
# let mut book = open?;
# let engine = new;
# let pages = engine.prepare_chapter?;
let mut display: = new;
let renderer = default;
renderer.render_page?;
# Ok::
Generate a web preview with TOC navigation, image embedding, embedded-font loading, and runtime font/layout controls:
Or export a standalone HTML snapshot:
Run the full reader-control regression harness (dynamic reflow + pagination + config mapping):
CLI (Unix-Friendly)
Install from crates.io:
Inspect metadata and chapter lists:
Extract chapter text for LLM/pipe workflows:
|
Validate structure/compliance signals:
Functional API
use ;
let limits = new;
let options = EpubBookOptions ;
let summary = parse_epub_file_with_options?;
println!;
# Ok::
Design
See docs/architecture.md for the full plan. The short version:
- Stream ZIP entries from storage with a bounded buffer.
- Parse OPF metadata and spine with
quick-xml(SAX-style, no DOM). - Tokenize XHTML chapters into a compact token stream.
- Lay out tokens into pages with greedy line breaking.
- Render glyphs from an LRU cache to a framebuffer.
Target peak RAM: <120KB beyond the framebuffer.
License
MIT