Skip to content

Streaming API

The streaming API enables memory-efficient processing of large archives by controlling how data flows through the system.

Overview

For large archives, especially solid archives with big blocks, the standard API may require significant memory. The streaming API provides fine-grained control over memory usage.

rust
use zesven::{StreamingArchive, StreamingConfig, Result};

fn main() -> Result<()> {
    let config = StreamingConfig::default()
        .max_memory_buffer(64 * 1024 * 1024);  // 64 MB limit

    // With default features (aes enabled), pass empty string for unencrypted archives
    let archive = StreamingArchive::open_path_with_config("large.7z", "", config)?;

    for entry in archive.entries()? {
        let entry = entry?;
        println!("Processing: {}", entry.name());
    }
    Ok(())
}

When to Use Streaming

Use the streaming API when:

  • Processing archives larger than available RAM
  • Working with solid archives containing large blocks
  • Need to control memory usage precisely
  • Processing entries one at a time without random access

Key Types

TypeDescription
StreamingArchiveMemory-efficient archive reader
StreamingConfigMemory and buffer configuration
StreamingEntryEntry with streaming data access
MemoryEstimateEstimate memory requirements

Topics

Basic Example

rust
use zesven::{StreamingArchive, StreamingConfig, Result};
use std::fs::File;

fn main() -> Result<()> {
    let config = StreamingConfig::default()
        .max_memory_buffer(32 * 1024 * 1024);

    // With default features (aes enabled), pass empty string for unencrypted archives
    let mut archive = StreamingArchive::open_path_with_config("large.7z", "", config)?;
    let mut iter = archive.entries()?;

    while let Some(entry_result) = iter.next() {
        let entry = entry_result?;
        if !entry.is_directory() {
            let path = format!("./output/{}", entry.name());
            std::fs::create_dir_all(std::path::Path::new(&path).parent().unwrap())?;
            let mut file = File::create(&path)?;
            iter.extract_current_to(&mut file)?;
        }
    }
    Ok(())
}

Memory vs. Standard API

FeatureStandard APIStreaming API
Random accessYesNo
Memory usageHigherControlled
SpeedFasterSlightly slower
API complexitySimpleMore complex

See Also

Released under MIT OR Apache-2.0 License