pub struct EpubFile {
pub id: String,
pub href: String,
pub title: Option<String>,
pub content: String,
pub media_type: String,
}Expand description
Represents a single file within an EPUB
Fields§
§id: String§href: String§title: Option<String>§content: String§media_type: StringImplementations§
Source§impl EpubFile
impl EpubFile
pub fn get_id(&self) -> &str
Sourcepub fn get_href(&self) -> &str
pub fn get_href(&self) -> &str
Examples found in repository?
examples/basic_usage.rs (line 48)
3fn main() {
4 // Example of how to use the epubie-lib library
5 let epub_path = "./example-files/iia.epub";
6
7 println!("Attempting to parse EPUB: {}", epub_path);
8
9 match Epub::new(epub_path.to_string()) {
10 Ok(epub) => {
11 // Display basic metadata
12 println!("\n=== EPUB Metadata ===");
13 println!("Title: {}", epub.get_title());
14 println!("Creator: {}", epub.get_creator());
15 println!("Language: {}", epub.get_language());
16 println!("Identifier: {}", epub.get_identifier());
17 println!("Date: {}", epub.get_date());
18
19 if let Some(publisher) = epub.get_publisher() {
20 println!("Publisher: {}", publisher);
21 }
22
23 if let Some(description) = epub.get_description() {
24 println!("Description: {}", description);
25 }
26
27 // Display chapter information
28 println!("\n=== Chapters ({}) ===", epub.get_chapter_count());
29 for (i, chapter) in epub.get_chapters().iter().enumerate() {
30 println!(
31 "Chapter {}: {} ({} file{})",
32 i + 1,
33 chapter.get_title(),
34 chapter.get_file_count(),
35 if chapter.get_file_count() == 1 {
36 ""
37 } else {
38 "s"
39 }
40 );
41
42 // Display files in each chapter
43 for (j, file) in chapter.get_files().iter().enumerate() {
44 println!(
45 " File {}: {} ({})",
46 j + 1,
47 file.get_title().unwrap_or("No title"),
48 file.get_href()
49 );
50
51 // Show if it's an HTML file
52 if file.is_html() {
53 println!(" [HTML file - {} bytes]", file.get_html_bytes().len());
54 }
55 }
56 }
57
58 // Display table of contents
59 let toc = epub.get_table_of_contents();
60 println!(
61 "\n=== Table of Contents ({} entries) ===",
62 toc.get_entry_count()
63 );
64 for (i, entry) in toc.get_entries().iter().enumerate() {
65 let indent = " ".repeat(entry.get_level() as usize);
66 println!(
67 "{}{}: {} ({})",
68 indent,
69 i + 1,
70 entry.get_title(),
71 entry.get_href()
72 );
73 }
74
75 // Display total file count
76 println!("\n=== File Summary ===");
77 println!("Total files: {}", epub.get_file_count());
78 println!("All files:");
79 for (i, file) in epub.get_all_files().iter().enumerate() {
80 println!(
81 " {}: {} ({}) - {}",
82 i + 1,
83 file.get_title().unwrap_or("No title"),
84 file.get_href(),
85 file.get_media_type()
86 );
87 }
88 }
89 Err(e) => {
90 eprintln!("Error parsing EPUB: {}", e);
91 eprintln!("Make sure the file exists and is a valid EPUB file.");
92 }
93 }
94}Sourcepub fn get_title(&self) -> Option<&str>
pub fn get_title(&self) -> Option<&str>
Examples found in repository?
examples/basic_usage.rs (line 47)
3fn main() {
4 // Example of how to use the epubie-lib library
5 let epub_path = "./example-files/iia.epub";
6
7 println!("Attempting to parse EPUB: {}", epub_path);
8
9 match Epub::new(epub_path.to_string()) {
10 Ok(epub) => {
11 // Display basic metadata
12 println!("\n=== EPUB Metadata ===");
13 println!("Title: {}", epub.get_title());
14 println!("Creator: {}", epub.get_creator());
15 println!("Language: {}", epub.get_language());
16 println!("Identifier: {}", epub.get_identifier());
17 println!("Date: {}", epub.get_date());
18
19 if let Some(publisher) = epub.get_publisher() {
20 println!("Publisher: {}", publisher);
21 }
22
23 if let Some(description) = epub.get_description() {
24 println!("Description: {}", description);
25 }
26
27 // Display chapter information
28 println!("\n=== Chapters ({}) ===", epub.get_chapter_count());
29 for (i, chapter) in epub.get_chapters().iter().enumerate() {
30 println!(
31 "Chapter {}: {} ({} file{})",
32 i + 1,
33 chapter.get_title(),
34 chapter.get_file_count(),
35 if chapter.get_file_count() == 1 {
36 ""
37 } else {
38 "s"
39 }
40 );
41
42 // Display files in each chapter
43 for (j, file) in chapter.get_files().iter().enumerate() {
44 println!(
45 " File {}: {} ({})",
46 j + 1,
47 file.get_title().unwrap_or("No title"),
48 file.get_href()
49 );
50
51 // Show if it's an HTML file
52 if file.is_html() {
53 println!(" [HTML file - {} bytes]", file.get_html_bytes().len());
54 }
55 }
56 }
57
58 // Display table of contents
59 let toc = epub.get_table_of_contents();
60 println!(
61 "\n=== Table of Contents ({} entries) ===",
62 toc.get_entry_count()
63 );
64 for (i, entry) in toc.get_entries().iter().enumerate() {
65 let indent = " ".repeat(entry.get_level() as usize);
66 println!(
67 "{}{}: {} ({})",
68 indent,
69 i + 1,
70 entry.get_title(),
71 entry.get_href()
72 );
73 }
74
75 // Display total file count
76 println!("\n=== File Summary ===");
77 println!("Total files: {}", epub.get_file_count());
78 println!("All files:");
79 for (i, file) in epub.get_all_files().iter().enumerate() {
80 println!(
81 " {}: {} ({}) - {}",
82 i + 1,
83 file.get_title().unwrap_or("No title"),
84 file.get_href(),
85 file.get_media_type()
86 );
87 }
88 }
89 Err(e) => {
90 eprintln!("Error parsing EPUB: {}", e);
91 eprintln!("Make sure the file exists and is a valid EPUB file.");
92 }
93 }
94}pub fn get_content(&self) -> &str
Sourcepub fn get_media_type(&self) -> &str
pub fn get_media_type(&self) -> &str
Examples found in repository?
examples/basic_usage.rs (line 85)
3fn main() {
4 // Example of how to use the epubie-lib library
5 let epub_path = "./example-files/iia.epub";
6
7 println!("Attempting to parse EPUB: {}", epub_path);
8
9 match Epub::new(epub_path.to_string()) {
10 Ok(epub) => {
11 // Display basic metadata
12 println!("\n=== EPUB Metadata ===");
13 println!("Title: {}", epub.get_title());
14 println!("Creator: {}", epub.get_creator());
15 println!("Language: {}", epub.get_language());
16 println!("Identifier: {}", epub.get_identifier());
17 println!("Date: {}", epub.get_date());
18
19 if let Some(publisher) = epub.get_publisher() {
20 println!("Publisher: {}", publisher);
21 }
22
23 if let Some(description) = epub.get_description() {
24 println!("Description: {}", description);
25 }
26
27 // Display chapter information
28 println!("\n=== Chapters ({}) ===", epub.get_chapter_count());
29 for (i, chapter) in epub.get_chapters().iter().enumerate() {
30 println!(
31 "Chapter {}: {} ({} file{})",
32 i + 1,
33 chapter.get_title(),
34 chapter.get_file_count(),
35 if chapter.get_file_count() == 1 {
36 ""
37 } else {
38 "s"
39 }
40 );
41
42 // Display files in each chapter
43 for (j, file) in chapter.get_files().iter().enumerate() {
44 println!(
45 " File {}: {} ({})",
46 j + 1,
47 file.get_title().unwrap_or("No title"),
48 file.get_href()
49 );
50
51 // Show if it's an HTML file
52 if file.is_html() {
53 println!(" [HTML file - {} bytes]", file.get_html_bytes().len());
54 }
55 }
56 }
57
58 // Display table of contents
59 let toc = epub.get_table_of_contents();
60 println!(
61 "\n=== Table of Contents ({} entries) ===",
62 toc.get_entry_count()
63 );
64 for (i, entry) in toc.get_entries().iter().enumerate() {
65 let indent = " ".repeat(entry.get_level() as usize);
66 println!(
67 "{}{}: {} ({})",
68 indent,
69 i + 1,
70 entry.get_title(),
71 entry.get_href()
72 );
73 }
74
75 // Display total file count
76 println!("\n=== File Summary ===");
77 println!("Total files: {}", epub.get_file_count());
78 println!("All files:");
79 for (i, file) in epub.get_all_files().iter().enumerate() {
80 println!(
81 " {}: {} ({}) - {}",
82 i + 1,
83 file.get_title().unwrap_or("No title"),
84 file.get_href(),
85 file.get_media_type()
86 );
87 }
88 }
89 Err(e) => {
90 eprintln!("Error parsing EPUB: {}", e);
91 eprintln!("Make sure the file exists and is a valid EPUB file.");
92 }
93 }
94}Sourcepub fn get_html_bytes(&self) -> &[u8] ⓘ
pub fn get_html_bytes(&self) -> &[u8] ⓘ
Get HTML content as bytes for parsing with external libraries
Examples found in repository?
examples/basic_usage.rs (line 53)
3fn main() {
4 // Example of how to use the epubie-lib library
5 let epub_path = "./example-files/iia.epub";
6
7 println!("Attempting to parse EPUB: {}", epub_path);
8
9 match Epub::new(epub_path.to_string()) {
10 Ok(epub) => {
11 // Display basic metadata
12 println!("\n=== EPUB Metadata ===");
13 println!("Title: {}", epub.get_title());
14 println!("Creator: {}", epub.get_creator());
15 println!("Language: {}", epub.get_language());
16 println!("Identifier: {}", epub.get_identifier());
17 println!("Date: {}", epub.get_date());
18
19 if let Some(publisher) = epub.get_publisher() {
20 println!("Publisher: {}", publisher);
21 }
22
23 if let Some(description) = epub.get_description() {
24 println!("Description: {}", description);
25 }
26
27 // Display chapter information
28 println!("\n=== Chapters ({}) ===", epub.get_chapter_count());
29 for (i, chapter) in epub.get_chapters().iter().enumerate() {
30 println!(
31 "Chapter {}: {} ({} file{})",
32 i + 1,
33 chapter.get_title(),
34 chapter.get_file_count(),
35 if chapter.get_file_count() == 1 {
36 ""
37 } else {
38 "s"
39 }
40 );
41
42 // Display files in each chapter
43 for (j, file) in chapter.get_files().iter().enumerate() {
44 println!(
45 " File {}: {} ({})",
46 j + 1,
47 file.get_title().unwrap_or("No title"),
48 file.get_href()
49 );
50
51 // Show if it's an HTML file
52 if file.is_html() {
53 println!(" [HTML file - {} bytes]", file.get_html_bytes().len());
54 }
55 }
56 }
57
58 // Display table of contents
59 let toc = epub.get_table_of_contents();
60 println!(
61 "\n=== Table of Contents ({} entries) ===",
62 toc.get_entry_count()
63 );
64 for (i, entry) in toc.get_entries().iter().enumerate() {
65 let indent = " ".repeat(entry.get_level() as usize);
66 println!(
67 "{}{}: {} ({})",
68 indent,
69 i + 1,
70 entry.get_title(),
71 entry.get_href()
72 );
73 }
74
75 // Display total file count
76 println!("\n=== File Summary ===");
77 println!("Total files: {}", epub.get_file_count());
78 println!("All files:");
79 for (i, file) in epub.get_all_files().iter().enumerate() {
80 println!(
81 " {}: {} ({}) - {}",
82 i + 1,
83 file.get_title().unwrap_or("No title"),
84 file.get_href(),
85 file.get_media_type()
86 );
87 }
88 }
89 Err(e) => {
90 eprintln!("Error parsing EPUB: {}", e);
91 eprintln!("Make sure the file exists and is a valid EPUB file.");
92 }
93 }
94}Sourcepub fn is_html(&self) -> bool
pub fn is_html(&self) -> bool
Check if this file contains HTML content
Examples found in repository?
examples/basic_usage.rs (line 52)
3fn main() {
4 // Example of how to use the epubie-lib library
5 let epub_path = "./example-files/iia.epub";
6
7 println!("Attempting to parse EPUB: {}", epub_path);
8
9 match Epub::new(epub_path.to_string()) {
10 Ok(epub) => {
11 // Display basic metadata
12 println!("\n=== EPUB Metadata ===");
13 println!("Title: {}", epub.get_title());
14 println!("Creator: {}", epub.get_creator());
15 println!("Language: {}", epub.get_language());
16 println!("Identifier: {}", epub.get_identifier());
17 println!("Date: {}", epub.get_date());
18
19 if let Some(publisher) = epub.get_publisher() {
20 println!("Publisher: {}", publisher);
21 }
22
23 if let Some(description) = epub.get_description() {
24 println!("Description: {}", description);
25 }
26
27 // Display chapter information
28 println!("\n=== Chapters ({}) ===", epub.get_chapter_count());
29 for (i, chapter) in epub.get_chapters().iter().enumerate() {
30 println!(
31 "Chapter {}: {} ({} file{})",
32 i + 1,
33 chapter.get_title(),
34 chapter.get_file_count(),
35 if chapter.get_file_count() == 1 {
36 ""
37 } else {
38 "s"
39 }
40 );
41
42 // Display files in each chapter
43 for (j, file) in chapter.get_files().iter().enumerate() {
44 println!(
45 " File {}: {} ({})",
46 j + 1,
47 file.get_title().unwrap_or("No title"),
48 file.get_href()
49 );
50
51 // Show if it's an HTML file
52 if file.is_html() {
53 println!(" [HTML file - {} bytes]", file.get_html_bytes().len());
54 }
55 }
56 }
57
58 // Display table of contents
59 let toc = epub.get_table_of_contents();
60 println!(
61 "\n=== Table of Contents ({} entries) ===",
62 toc.get_entry_count()
63 );
64 for (i, entry) in toc.get_entries().iter().enumerate() {
65 let indent = " ".repeat(entry.get_level() as usize);
66 println!(
67 "{}{}: {} ({})",
68 indent,
69 i + 1,
70 entry.get_title(),
71 entry.get_href()
72 );
73 }
74
75 // Display total file count
76 println!("\n=== File Summary ===");
77 println!("Total files: {}", epub.get_file_count());
78 println!("All files:");
79 for (i, file) in epub.get_all_files().iter().enumerate() {
80 println!(
81 " {}: {} ({}) - {}",
82 i + 1,
83 file.get_title().unwrap_or("No title"),
84 file.get_href(),
85 file.get_media_type()
86 );
87 }
88 }
89 Err(e) => {
90 eprintln!("Error parsing EPUB: {}", e);
91 eprintln!("Make sure the file exists and is a valid EPUB file.");
92 }
93 }
94}Sourcepub fn get_parsable_html(&self) -> &str
pub fn get_parsable_html(&self) -> &str
Get the HTML content ready for parsing with external HTML parsers
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EpubFile
impl RefUnwindSafe for EpubFile
impl Send for EpubFile
impl Sync for EpubFile
impl Unpin for EpubFile
impl UnsafeUnpin for EpubFile
impl UnwindSafe for EpubFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more