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
42
43
44
45
46
47
48
49
50
51
52
//! A module for working with version 1 of directory signature
//!

mod writer;
mod progress;
mod hash;
mod scan;

use std::io;

pub use error::Error;

use self::progress::Progress;
use self::writer::SyncWriter;
use {ScannerConfig, HashType};

/// Create an index using specified config
///
/// It's better to use some buffered output file here.
pub fn scan<F: io::Write>(config: &ScannerConfig, out: &mut F)
    -> Result<(), Error>
{
    if config.print_progress {
        match config.hash {
            HashType::Sha512_256 => {
                scan::scan(config,
                    &mut Progress::new(io::stderr(),
                        SyncWriter::new(out,
                            hash::Sha512_256, config.block_size)?))
            }
            HashType::Blake2b_256 => {
                scan::scan(config,
                    &mut Progress::new(io::stderr(),
                        SyncWriter::new(out,
                            hash::Blake2b_256, config.block_size)?))
            }
        }
    } else {
        match config.hash {
            HashType::Sha512_256 => {
                scan::scan(config,
                    &mut SyncWriter::new(out,
                        hash::Sha512_256, config.block_size)?)
            }
            HashType::Blake2b_256 => {
                scan::scan(config,
                    &mut SyncWriter::new(out,
                        hash::Blake2b_256, config.block_size)?)
            }
        }
    }
}