fast-fs 0.2.1

High-speed async file system traversal library with batteries-included file browser component
Documentation
//! Streaming API example
//!
//! This example demonstrates memory-efficient streaming traversal
//! with backpressure support.
//!
//! Run with: `cargo run --example streaming`

use fast_fs::{read_dir_stream, TraversalOptions};
use futures::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let path = std::env::args().nth(1).unwrap_or_else(|| ".".to_string());

    println!("=== Streaming Directory Traversal ===");
    println!("Streaming from: {}\n", path);

    let options = TraversalOptions::default()
        .with_max_depth(3)
        .with_gitignore(true);

    // Create a stream - entries are yielded as they're discovered
    let stream = read_dir_stream(&path, options);

    // Process entries one at a time (memory efficient for large directories)
    let mut count = 0;
    let mut total_size: u64 = 0;
    let mut dir_count = 0;
    let mut file_count = 0;

    // Pin the stream for iteration
    tokio::pin!(stream);

    while let Some(result) = stream.next().await {
        match result {
            Ok(entry) => {
                count += 1;
                total_size += entry.size;

                if entry.is_dir {
                    dir_count += 1;
                } else {
                    file_count += 1;
                }

                // Print progress every 100 entries
                if count % 100 == 0 {
                    println!("  Processed {} entries...", count);
                }
            }
            Err(e) => {
                eprintln!("  Error: {}", e);
            }
        }
    }

    println!("\n=== Results ===");
    println!("Total entries: {}", count);
    println!("  Directories: {}", dir_count);
    println!("  Files: {}", file_count);
    println!(
        "Total size: {} bytes ({:.2} MB)",
        total_size,
        total_size as f64 / 1_048_576.0
    );

    Ok(())
}