1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
//! EPUB library //! lib to read and navigate throught an epub file contents //! //! # Examples //! //! ## Opening //! //! ``` //! use epub::doc::EpubDoc; //! let doc = EpubDoc::new("test.epub"); //! assert!(doc.is_ok()); //! let doc = doc.unwrap(); //! //! ``` //! //! ## Getting doc metatada //! //! Metadata is a HashMap storing all metadata defined in the epub //! //! ``` //! # use epub::doc::EpubDoc; //! # let doc = EpubDoc::new("test.epub"); //! # let doc = doc.unwrap(); //! let title = doc.mdata("title"); //! assert_eq!(title.unwrap(), "Todo es mío"); //! ``` //! //! ## Accessing resources //! //! In the resources var is stored each resource defined //! in the epub indexed by the id and with the full internal //! path and mimetype. It's a HashMap<a: String, (b: String, c: String)> //! where 'a' is the resource id, 'b' is the resource full path and //! 'c' is the resource mimetype //! //! ``` //! # use epub::doc::EpubDoc; //! # use std::path::Path; //! # let doc = EpubDoc::new("test.epub"); //! # let doc = doc.unwrap(); //! assert_eq!(21, doc.resources.len()); //! let tpage = doc.resources.get("titlepage.xhtml"); //! assert_eq!(tpage.unwrap().0, Path::new("OEBPS/Text/titlepage.xhtml")); //! assert_eq!(tpage.unwrap().1, "application/xhtml+xml"); //! ``` //! //! ## Navigating usint the spine //! //! Spine is a Vec<String> storing the epub spine as resources ids //! //! ``` //! # use epub::doc::EpubDoc; //! # let doc = EpubDoc::new("test.epub"); //! # let doc = doc.unwrap(); //! assert_eq!(17, doc.spine.len()); //! assert_eq!("titlepage.xhtml", doc.spine[0]); //! ``` //! //! ## Navigation using the doc internal state //! //! ``` //! use epub::doc::EpubDoc; //! let doc = EpubDoc::new("test.epub"); //! let mut doc = doc.unwrap(); //! assert_eq!(0, doc.get_current_page()); //! assert_eq!("application/xhtml+xml", doc.get_current_mime().unwrap()); //! //! doc.go_next(); //! assert_eq!("000.xhtml", doc.get_current_id().unwrap()); //! doc.go_next(); //! assert_eq!("001.xhtml", doc.get_current_id().unwrap()); //! doc.go_prev(); //! assert_eq!("000.xhtml", doc.get_current_id().unwrap()); //! //! doc.set_current_page(2); //! assert_eq!("001.xhtml", doc.get_current_id().unwrap()); //! assert_eq!(2, doc.get_current_page()); //! assert!(doc.set_current_page(50).is_err()); //! //! // doc.get_current() will return a Vec<u8> with the current page content //! // doc.get_current_str() will return a String with the current page content //! ``` //! //! ## Getting the cover //! //! ```ignore //! use std::fs; //! use std::io::Write; //! use epub::doc::EpubDoc; //! //! let doc = EpubDoc::new("test.epub"); //! assert!(doc.is_ok()); //! let mut doc = doc.unwrap(); //! //! let cover_data = doc.get_cover().unwrap(); //! //! let f = fs::File::create("/tmp/cover.png"); //! assert!(f.is_ok()); //! let mut f = f.unwrap(); //! let resp = f.write_all(&cover_data); //! ``` #[macro_use] extern crate failure; mod xmlutils; pub mod archive; pub mod doc;