File: readcab.rs

package info (click to toggle)
rust-cab 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 256 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::fs::File;
use std::path::PathBuf;

use anyhow::Context;
use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, about)]
struct Cli {
    path: PathBuf,
}

fn main() -> anyhow::Result<()> {
    let cli = Cli::parse();

    let input_file = File::open(cli.path)?;
    let cabinet = cab::Cabinet::new(input_file)
        .context("Failed to open cabinet file")?;
    for (index, folder) in cabinet.folder_entries().enumerate() {
        println!("Folder #{}:", index);
        println!("  compression_type = {:?}", folder.compression_type());
        println!("  reserve_data = {:?}", folder.reserve_data());
        println!("  num_data_blocks = {}", folder.num_data_blocks());
        let mut total_size = 0;
        for file in folder.file_entries() {
            let size = file.uncompressed_size();
            println!("  {:?} ({} bytes)", file.name(), size);
            total_size += size;
        }
        println!("  {} bytes total", total_size);
    }

    Ok(())
}