vflight 0.9.2

Share files over the Veilid distributed network with content-addressable storage
Documentation
/// Example: Chunking a file
///
/// This example demonstrates how to split a file into chunks
/// and inspect the metadata.
use std::path::Path;
use vflight::chunk_file;

fn main() -> anyhow::Result<()> {
    // Create a sample file for demonstration
    let test_file = "example_file.txt";
    std::fs::write(test_file, b"Hello, World! This is a sample file.")?;

    println!("Chunking file: {}", test_file);

    // Chunk the file
    let chunks = chunk_file(Path::new(test_file))?;

    // Display chunk information
    println!("\nFile chunked into {} parts:\n", chunks.len());
    for chunk in &chunks {
        println!(
            "Chunk {}: {} bytes, hash: {}",
            chunk.index,
            chunk.data.len(),
            chunk.hash
        );
    }

    // Display total statistics
    let total_size: usize = chunks.iter().map(|c| c.data.len()).sum();
    println!("\nTotal: {} chunks, {} bytes", chunks.len(), total_size);

    // Cleanup
    std::fs::remove_file(test_file)?;

    Ok(())
}