Skip to content

API Reference

SV-Stark edited this page Aug 6, 2026 · 8 revisions

📚 ebook-rs Complete API Reference & Parity Guide

This document provides complete API documentation for ebook-rs (v0.5.3), bifurcated into Drop-in Replacements for epub.js and ebook-rs Native Extensions.


🟢 Section A: Drop-in Replacement for epub.js APIs

These ebook-rs APIs match the concepts, structures, and behavior of epub.js (e.g. ePub(url), book.loaded.*, rendition.display(), rendition.annotations), enabling web developers and Rust engineers to migrate seamlessly.

epub.js Feature / API 🚀 ebook-rs Equivalent API Description
ePub(url) / ePub(buffer) Book::from_file(path) / Book::from_bytes(bytes) Loads and parses package files into an in-memory Book struct.
book.loaded.metadata book.metadata() Returns Metadata containing title, creators, publishers, languages, pub_date, etc.
book.loaded.spine book.spine() Returns Vec<SpineItem> containing ordered chapter items (idref, href, linear).
book.loaded.navigation.toc book.toc() Returns Vec<NavPoint> hierarchical Table of Contents points.
book.loaded.navigation.landmarks book.landmarks() Returns Vec<Landmark> (cover, titlepage, bodymatter).
book.loaded.navigation.pageList book.page_list() Returns Vec<PageListItem> printed page numbers.
book.locations.generate() book.generate_locations(chunk_size) Generates discrete location progress markers across chapters.
book.locations.percentageFromCfi() book.locations.percentage_from_location(loc) Converts location integer indices to decimal progress percentage (0.0 .. 1.0).
rendition.display(cfi) book.get_section(spine_idx) / Cfi::parse() Retrieves raw and processed HTML content at specified CFI location.
rendition.annotations.add() book.annotations.create_highlight() / to_w3c_json() Creates highlights and exports W3C Web Annotation JSON-LD format.

🔵 Section B: ebook-rs Native Extensions (Beyond epub.js)

Where ebook-rs extends far beyond epub.js to provide native multi-format support, zero-alloc searching, font de-obfuscation, EPUB 3 Accessibility, SMIL Media Overlays, and built-in HTTP reader server capabilities.

1. Multi-Format Native Parsers (MobiBook, Fb2Book, LitBook, CbzBook)

epub.js only supports .epub files. ebook-rs natively supports MOBI, AZW3, FB2, KEPUB, LIT, and CBZ formats out of the box.

2. EPUB 3 Accessibility Metadata (AccessibilityMetadata)

EPUB 3 Accessibility 1.1 & Schema.org metadata parsing:

let a11y = &book.metadata().accessibility;
println!("Access Modes: {:?}", a11y.access_modes);
println!("Summary: {:?}", a11y.accessibility_summary);
assert!(a11y.is_screen_reader_friendly());

3. EPUB 3 Media Overlays (SMIL Sync) (MediaOverlayPackage)

Synchronized audio-text read-aloud overlays (.smil):

for (smil_path, pkg) in &book.media_overlays {
    if let Some(text_ref) = pkg.find_text_ref_by_timestamp("ch1.mp3", 8.5) {
        println!("Active element ID: {:?}", text_ref.element_id);
    }
}

4. Zero-Allocation Full-Text Search Engine

let matches = book.search("Wonderland");

5. Font De-Obfuscation Engine (FontDeobfuscator)

Native IDPF & Adobe font decryption supporting SHA-1 key generation and XOR transformations.

Clone this wiki locally