EpubBookRef class
Represents a reference to an EPUB book for lazy loading.
An EpubBookRef provides access to EPUB content without loading it all into memory at once. Content is loaded on-demand when accessed, making it ideal for large EPUB files or memory-constrained environments.
This is the result of calling EpubReader.openBook and provides the same functionality as EpubBook but with lazy loading behavior.
Key Features
- Metadata available immediately (title, author, schema)
- Chapter structure available without loading content
- Content loaded only when explicitly requested
- Support for chapter splitting on-demand
Example
final bytes = await File('large_book.epub').readAsBytes();
final bookRef = await EpubReader.openBook(bytes);
// Metadata available immediately
print('Title: ${bookRef.title}');
print('Author: ${bookRef.author}');
// Get chapter references (no content loaded yet)
final chapters = bookRef.getChapters();
print('Chapter count: ${chapters.length}');
// Load content for specific chapter only
final firstChapterContent = await chapters[0].readHtmlContent();
// Or get chapters with automatic splitting
final splitChapters = await bookRef.getChaptersWithSplitting();
- Implementers
- Available extensions
Constructors
-
EpubBookRef({required Archive epubArchive, String? title, String? author, List<
String> authors = const [], EpubSchema? schema, EpubContentRef? content}) -
const
Properties
-
final
-
final
- cfiManager → EpubCFIManager
-
Available on EpubBookRef, provided by the EpubBookRefCFI extension
Creates a CFI manager for this book.no setter - content → EpubContentRef?
-
final
- epubArchive → Archive
-
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- schema → EpubSchema?
-
final
- spineItemCount → int
-
Available on EpubBookRef, provided by the EpubBookRefCFI extension
Gets the total number of spine items in the book.no setter - title → String?
-
final
Methods
-
createProgressCFI(
int spineIndex, {double fraction = 0.0}) → CFI -
Available on EpubBookRef, provided by the EpubBookRefCFI extension
Creates a simple CFI for reading progress tracking. -
getChapterRefsWithSplitting(
) → Future< List< EpubChapterRef> > - Gets chapter references with automatic splitting for long chapters.
-
getChapters(
) → List< EpubChapterRef> - Gets the chapter structure without loading content.
-
getChaptersInCFIRange(
CFI startCFI, CFI endCFI) → Future< List< EpubChapterRef> > -
Available on EpubBookRef, provided by the EpubBookRefCFI extension
Finds chapters that contain CFIs within a specific range. -
getChaptersWithSplitting(
) → Future< List< EpubChapter> > - Gets chapters and automatically splits any that exceed 3000 words.
-
getSpineChapterMap(
) → Map< int, EpubChapterRef> -
Available on EpubBookRef, provided by the EpubBookRefCFI extension
Gets a map of spine indices to chapter references. -
Available on EpubBookRef, provided by the EpubBookRefCFI extension
Navigates to a CFI location within the book. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
readCover(
) → Future< Image?> - Reads the book's cover image.
-
toString(
) → String -
A string representation of this object.
inherited
-
validateCFI(
CFI cfi) → Future< bool> -
Available on EpubBookRef, provided by the EpubBookRefCFI extension
Validates that a CFI can be resolved within this book.
Operators
-
operator ==(
covariant EpubBookRef other) → bool -
The equality operator.
override