chapter-tgz 0.1.0

Specially crafted .tar.gz with embedded chapter boundary information
Documentation
use anyhow::Result;
use chapter_tgz::TgzReader;
use std::env;
use std::fs::File;
use std::path::{Path, PathBuf};
use std::process::ExitCode;

fn main() -> ExitCode {
    let mut args = env::args_os();
    if args.len() != 2 {
        eprintln!("Usage: cargo run --example=list --release -- path/to/input.tgz");
        return ExitCode::FAILURE;
    }

    let path = PathBuf::from(args.nth(1).unwrap());
    if let Err(err) = do_main(&path) {
        eprintln!("Error: {err:?}");
        return ExitCode::FAILURE;
    }

    ExitCode::SUCCESS
}

fn do_main(path: &Path) -> Result<()> {
    let file = File::open(path)?;
    let mut tgz = TgzReader::open(file)?;
    let mut i = 0;
    while let Some(mut chapter) = tgz.next_chapter() {
        println!("Chapter {i}:");
        for entry in chapter.entries()? {
            let entry = entry?;
            let path = entry.path()?;
            println!("  {}", path.display());
        }
        i += 1;
    }
    Ok(())
}