pub trait ArchiveReader: Read + Seek {
// Required methods
fn read_entry(&mut self, name: &str) -> Result<Vec<u8>>;
fn entry_exists(&mut self, name: &str) -> bool;
fn list_entries(&mut self) -> Result<Vec<String>>;
}Expand description
Trait for reading entries from an archive (ZIP).
This trait abstracts over different ZIP backend implementations, allowing the parser to work with files, in-memory buffers, async I/O, or custom storage.
§Requirements
Implementations must also implement Read + Seek for compatibility with the underlying ZIP library.
§Examples
use lib3mf_core::archive::{ArchiveReader, ZipArchiver};
use std::fs::File;
let file = File::open("model.3mf")?;
let mut archive = ZipArchiver::new(file)?;
// Check if entry exists before reading
if archive.entry_exists("3D/3dmodel.model") {
let content = archive.read_entry("3D/3dmodel.model")?;
println!("Model XML size: {} bytes", content.len());
}
// List all entries
for entry in archive.list_entries()? {
println!("Found: {}", entry);
}Required Methods§
Sourcefn read_entry(&mut self, name: &str) -> Result<Vec<u8>>
fn read_entry(&mut self, name: &str) -> Result<Vec<u8>>
Read the content of an entry by name.
§Parameters
name: Path to the entry within the archive (e.g.,"3D/3dmodel.model","Metadata/thumbnail.png")
§Returns
The binary content of the entry as a Vec<u8>.
§Errors
Returns Lib3mfError::Io if the entry doesn’t exist or can’t be read.
Sourcefn entry_exists(&mut self, name: &str) -> bool
fn entry_exists(&mut self, name: &str) -> bool
Sourcefn list_entries(&mut self) -> Result<Vec<String>>
fn list_entries(&mut self) -> Result<Vec<String>>
List all entries in the archive.
§Returns
A vector of entry paths (e.g., ["3D/3dmodel.model", "Metadata/thumbnail.png", "_rels/.rels"])
§Errors
Returns Lib3mfError::Io if the archive can’t be read.