Crates.io | mobi |
lib.rs | mobi |
version | 0.8.0 |
source | src |
created_at | 2019-08-28 12:25:01.256725 |
updated_at | 2022-12-11 06:49:57.027696 |
description | A library for handling MOBI format files |
homepage | |
repository | https://github.com/vv9k/mobi-rs |
max_upload_size | |
id | 160379 |
size | 162,354 |
A crate to work with MOBI format ebooks.
Cargo.toml
[dependencies]
mobi = "0.8"
main.rs
use mobi::{Mobi, MobiError};
fn main() -> Result<(), MobiError> {
let book = vec![0, 0, 0];
// You can either create a Mobi struct from a slice
let m = Mobi::new(&book)?;
// Or from an instance of io::Read
let stdin = std::io::stdin();
let mut handle = stdin.lock();
let m = Mobi::from_read(&mut handle)?;
// Or from filesystem
let m = Mobi::from_path("/some/path/to/book.mobi")?;
// Access metadata
let title = m.title();
let author = m.author().unwrap_or_default();
let publisher = m.publisher().unwrap_or_default();
let desc = m.description().unwrap_or_default();
let isbn = m.isbn().unwrap_or_default();
let pub_date = m.publish_date().unwrap_or_default();
let contributor = m.contributor().unwrap_or_default();
// Access Headers
let metadata = &m.metadata;
let header = &metadata.header; // Normal Header
let pdheader = &metadata.palmdoc; // PalmDOC Header
let mheader = &metadata.mobi; // MOBI Header
let exth = &metadata.exth; // Extra Header
// Access content
let content = m.content_as_string();
Ok(())
}
kroo for inspiration and idea.