Expand description
Archive layer for reading and writing 3MF container files.
This module implements the OPC (Open Packaging Conventions) container layer that 3MF is built on. 3MF files are ZIP archives containing XML model files, textures, thumbnails, and metadata, organized according to OPC relationship and content type conventions.
§Architecture
The archive layer provides:
- Trait-based abstraction:
ArchiveReaderandArchiveWritertraits decouple the parser from the underlying ZIP implementation, allowing different backends (file, memory, async, etc.) - OPC relationship discovery: The
find_model_pathfunction traverses_rels/.relsfiles to locate the main 3D model XML file within the archive. - Default ZIP implementation:
ZipArchiverprovides a standard file-based ZIP backend.
§Typical Usage
Opening and reading a 3MF file:
use lib3mf_core::archive::{ZipArchiver, ArchiveReader, find_model_path};
use std::fs::File;
// Open the 3MF ZIP archive
let file = File::open("model.3mf")?;
let mut archiver = ZipArchiver::new(file)?;
// Discover the main model XML path via OPC relationships
let model_path = find_model_path(&mut archiver)?;
// Typically returns "3D/3dmodel.model" or similar
// Read the model XML content
let model_xml = archiver.read_entry(&model_path)?;
// Read attachments (textures, thumbnails, etc.)
if archiver.entry_exists("Metadata/thumbnail.png") {
let thumbnail = archiver.read_entry("Metadata/thumbnail.png")?;
}
// List all entries
let entries = archiver.list_entries()?;
for entry in entries {
println!("Archive contains: {}", entry);
}§OPC Relationship Discovery
The find_model_path function implements the OPC discovery algorithm:
- Read
_rels/.rels(package-level relationships) - Find relationship with type
http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel - Extract target path (e.g.,
/3D/3dmodel.model) - Normalize path (remove leading
/)
This allows 3MF files to have different internal structures while remaining conformant to the spec.
§ArchiveReader Trait
The ArchiveReader trait provides three core operations:
read_entry: Read file content by pathentry_exists: Check if a path existslist_entries: Enumerate all archive contents
Implementations must also satisfy Read + Seek for compatibility with the ZIP crate.
§ArchiveWriter Trait
The ArchiveWriter trait provides a single operation:
write_entry: Write data to a path in the archive
Implementations handle compression, content type registration, and relationship generation.
Re-exports§
pub use model_locator::*;pub use zip_archive::*;
Modules§
Traits§
- Archive
Reader - Trait for reading entries from an archive (ZIP).
- Archive
Writer - Trait for writing entries to an archive.