Skip to main content

EpubFile

Struct EpubFile 

Source
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: String

Implementations§

Source§

impl EpubFile

Source

pub fn get_id(&self) -> &str

Source

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}
Source

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}
Source

pub fn get_content(&self) -> &str

Source

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}
Source

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}
Source

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}
Source

pub fn get_parsable_html(&self) -> &str

Get the HTML content ready for parsing with external HTML parsers

Trait Implementations§

Source§

impl Clone for EpubFile

Source§

fn clone(&self) -> EpubFile

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EpubFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.