Module archive

Module archive 

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

  1. Trait-based abstraction: ArchiveReader and ArchiveWriter traits decouple the parser from the underlying ZIP implementation, allowing different backends (file, memory, async, etc.)
  2. OPC relationship discovery: The find_model_path function traverses _rels/.rels files to locate the main 3D model XML file within the archive.
  3. Default ZIP implementation: ZipArchiver provides 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:

  1. Read _rels/.rels (package-level relationships)
  2. Find relationship with type http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel
  3. Extract target path (e.g., /3D/3dmodel.model)
  4. 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:

Implementations must also satisfy Read + Seek for compatibility with the ZIP crate.

§ArchiveWriter Trait

The ArchiveWriter trait provides a single operation:

Implementations handle compression, content type registration, and relationship generation.

Re-exports§

pub use model_locator::*;
pub use zip_archive::*;

Modules§

model_locator
opc
zip_archive

Traits§

ArchiveReader
Trait for reading entries from an archive (ZIP).
ArchiveWriter
Trait for writing entries to an archive.