| Crates.io | lib-epub |
| lib.rs | lib-epub |
| version | 0.0.8 |
| created_at | 2025-12-23 07:00:42.282867+00 |
| updated_at | 2026-01-18 10:18:20.677409+00 |
| description | A Rust library for reading and manipulating EPUB files. |
| homepage | |
| repository | https://github.com/KikkiZ/lib-epub.git |
| max_upload_size | |
| id | 2000924 |
| size | 307,716 |
A Rust library for reading and manipulating EPUB eBook files.
This library provides complete EPUB file parsing functionality, supporting EPUB 2 and EPUB 3 formats. It can extract metadata, access content files, and handle encrypted resources. Furthermore, this library also provides a convenient way to build epub files from a set of resources.
Add this to your Cargo.toml:
[dependencies]
lib-epub = "0.0.5"
Reading an EPUB file and extracting metadata:
use lib_epub::{error::EpubError, epub::EpubDoc};
fn main() -> Result<(), EpubError> {
// Open EPUB file
let mut doc = EpubDoc::new("path/to/epub/file.epub")?;
// Get metadata
println!("Title: {:?}", doc.get_title()?);
println!("Creator: {:?}", doc.get_metadata_value("creator")?);
// Read content
let (_content, _mime) = doc.spine_current()?;
let (_content, _mime) = doc.next_spine()?;
Ok(())
}
Building an EPUB file:
use lib_epub::{
builder::{EpubBuilder, EpubVersion3},
error::EpubError,
types::{MetadataItem, ManifestItem, NavPoint, SpineItem},
};
fn main() -> Result<(), EpubError> {
let mut builder = EpubBuilder::<EpubVersion3>::new()?;
builder
.add_rootfile("EPUB/content.opf")?
.add_metadata(MetadataItem::new("title", "Test Book"))
.add_metadata(MetadataItem::new("language", "en"))
.add_metadata(
MetadataItem::new("identifier", "unique-id")
.with_id("pub-id")
.build(),
)
.add_manifest(
"./test_case/Overview.xhtml",
ManifestItem::new("content", "target/path")?,
)?
.add_spine(SpineItem::new("content"))
.add_catalog_item(NavPoint::new("label"));
builder.build("output.epub")?;
Ok(())
}
Enable the builder feature in Cargo.toml:
[dependencies]
lib-epub = { version = "0.0.5", features = ["builder"] }
The minimum supported Rust version is 1.85.0.
This project is licensed under the MIT License.