simple/
simple.rs

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
35
use anyreader::FormatKind;
use anyreader_walker::{AnyWalker, EntryDetails, FileEntry};
use std::io::Read;

struct Visitor;

impl AnyWalker for Visitor {
    fn visit_file_entry(&mut self, entry: &mut FileEntry<impl Read>) -> std::io::Result<()> {
        eprintln!(
            "Found file with format {}: {}",
            entry.format(),
            entry.path().display()
        );
        Ok(())
    }

    fn begin_visit_archive(
        &mut self,
        details: &EntryDetails,
        format: FormatKind,
    ) -> std::io::Result<bool> {
        eprintln!(
            "Found archive with format {}: {}",
            format,
            details.path.display()
        );
        Ok(true)
    }
}

fn main() {
    let entry = FileEntry::from_path("file.tar.gz").unwrap();
    let mut visitor = Visitor {};
    visitor.walk(entry).unwrap();
}