anyreader_walker/
stack.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
36
37
38
39
40
41
use crate::entry::{EntryDetails, FileEntry};
use crate::walkers::ArchiveVisitor;
use anyreader::FormatKind;
use std::io::Read;

#[allow(unused_variables)]
pub trait AnyWalker: Sized {
    fn visit_file_entry(&mut self, entry: &mut FileEntry<impl Read>) -> std::io::Result<()>;

    fn begin_visit_archive(
        &mut self,
        details: &EntryDetails,
        format: FormatKind,
    ) -> std::io::Result<bool> {
        Ok(true)
    }

    fn end_visit_archive(
        &mut self,
        details: EntryDetails,
        format: FormatKind,
    ) -> std::io::Result<()> {
        Ok(())
    }

    fn walk(&mut self, mut entry: FileEntry<impl Read>) -> std::io::Result<()> {
        if entry.supports_recursion()
            && self.begin_visit_archive(entry.details(), entry.format())?
        {
            let details = entry.details().clone();
            let format = entry.format();
            entry.visit(self)?;
            self.end_visit_archive(details, format)?;
            Ok(())
        } else {
            self.visit_file_entry(&mut entry)?;
            // std::io::copy(&mut entry, &mut std::io::sink())?;
            Ok(())
        }
    }
}