Reading Archives
zesven provides a flexible API for reading 7z archives, from simple file extraction to advanced streaming operations.
Overview
The main type for reading archives is Archive<R>, which is generic over any type that implements Read + Seek. This allows reading from files, memory buffers, or any other seekable source.
rust
use zesven::{Archive, Result};
use std::fs::File;
use std::io::Cursor;
fn main() -> Result<()> {
// From a file path (most common)
let archive = Archive::open_path("archive.7z")?;
// From an open file
let file = File::open("archive.7z")?;
let archive = Archive::open(file)?;
// From memory
let data = std::fs::read("archive.7z")?;
let archive = Archive::open(Cursor::new(data))?;
Ok(())
}Key Types
| Type | Description |
|---|---|
Archive<R> | Main archive reader, generic over reader type |
Entry | Metadata for a single file or directory |
ExtractOptions | Configuration for extraction operations |
ExtractResult | Statistics from an extraction operation |
Basic Workflow
- Open the archive with
Archive::open_path()orArchive::open() - Inspect entries using
archive.entries()orarchive.len() - Extract files using
archive.extract()orarchive.extract_entry()
Topics
- Opening Archives - Different ways to open archives
- Extracting Files - Extract to disk or memory
- Selective Extraction - Filter which files to extract
- Progress Callbacks - Monitor extraction progress
Quick Example
rust
use zesven::{Archive, ExtractOptions, Result};
fn main() -> Result<()> {
let mut archive = Archive::open_path("archive.7z")?;
// Print archive info
println!("Archive: {} entries, {} total bytes",
archive.len(),
archive.entries().map(|e| e.size).sum::<u64>());
// Extract with default options
let result = archive.extract("./output", (), &ExtractOptions::default())?;
println!("Extracted {} files ({} bytes)",
result.entries_extracted, result.bytes_extracted);
Ok(())
}