Skip to content

Commit

Permalink
examples: add example using ArchiveIterator
Browse files Browse the repository at this point in the history
Useful for running ArchiveIterator under valgrind, e.g. to check for
memory leaks.
  • Loading branch information
cgzones committed Mar 20, 2023
1 parent 2c86cfa commit 52960e0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/uncompress_iterator.rs
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

use argh::FromArgs;
use compress_tools::*;

#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Top-level command.
struct TopLevel {
/// source path
#[argh(positional)]
source_path: String,
}

fn main() -> compress_tools::Result<()> {
let cmd: TopLevel = argh::from_env();

let source = std::fs::File::open(cmd.source_path)?;

for content in ArchiveIterator::from_read(source)? {
if let ArchiveContents::StartOfEntry(name, stat) = content {
println!("{name}: size={}", stat.st_size);
}
}

Ok(())
}

0 comments on commit 52960e0

Please sign in to comment.