pub struct ZipHandler<R: Read + Seek> { /* private fields */ }Expand description
A handler for reading EPUB files as ZIP archives.
This struct wraps a ZipArchive and provides convenience methods
for reading specific files needed for EPUB parsing:
- Locating the OPF file via META-INF/container.xml
- Reading text files (XML, HTML, CSS, etc.)
- Reading binary files (images, fonts, etc.)
§Example
use std::path::Path;
use epub_parser::utils::ZipHandler;
let mut handler = ZipHandler::new(Path::new("book.epub"))?;
let opf_path = handler.get_opf_path()?;
println!("OPF location: {}", opf_path);Implementations§
Source§impl ZipHandler<File>
impl ZipHandler<File>
Sourcepub fn new(path: &Path) -> Result<Self, Error>
pub fn new(path: &Path) -> Result<Self, Error>
Creates a new ZipHandler from a file path.
§Arguments
path- The path to the EPUB file.
§Returns
Returns Ok(ZipHandler) on success, or an error if the file
cannot be opened or is not a valid ZIP archive.
§Errors
Returns an error if:
- The file does not exist
- The file cannot be opened
- The file is not a valid ZIP archive
Source§impl<R: Read + Seek> ZipHandler<R>
impl<R: Read + Seek> ZipHandler<R>
Sourcepub fn new_from_reader(reader: R) -> Result<Self, Error>
pub fn new_from_reader(reader: R) -> Result<Self, Error>
Creates a new ZipHandler from any reader that implements
Read + Seek.
This is useful for parsing EPUBs from memory (e.g., byte buffers) or network streams.
§Arguments
reader- Any type implementingRead + Seek(e.g.,Cursor<Vec<u8>>).
§Returns
Returns Ok(ZipHandler) on success, or an error if the reader
does not contain a valid ZIP archive.
§Example
use std::io::Cursor;
use epub_parser::utils::ZipHandler;
let data = vec![0u8; 100]; // In practice, this would be EPUB data
// handler = ZipHandler::new_from_reader(Cursor::new(data))?;Sourcepub fn get_opf_path(&mut self) -> Result<String, Error>
pub fn get_opf_path(&mut self) -> Result<String, Error>
Locates the OPF (Open Package Format) file path.
EPUB files contain a META-INF/container.xml file that specifies
the location of the OPF file. This method parses that XML and
returns the path to the OPF file.
§Returns
Returns the path to the OPF file as a string (e.g., “OEBPS/content.opf”).
§Errors
Returns Error::MissingContainer if META-INF/container.xml is missing.
Returns Error::MissingOpf if the OPF path cannot be found.