Skip to main content

ArchiveReader

Trait ArchiveReader 

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

Source

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.

Source

fn entry_exists(&mut self, name: &str) -> bool

Check if an entry exists.

§Parameters
  • name: Path to the entry within the archive
§Returns

true if the entry exists, false otherwise.

Source

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.

Implementors§