-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscrub.rs
40 lines (31 loc) · 1.06 KB
/
scrub.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
use std::collections::HashMap;
use std::io;
use std::io::{BufReader, Read, Seek};
use chunkfs::bench::generator::fio;
use chunkfs::chunkers::SuperChunker;
use chunkfs::hashers::Sha256Hasher;
use chunkfs::FileSystem;
fn main() -> io::Result<()> {
let mut fs = FileSystem::new_with_scrubber(
HashMap::default(),
HashMap::default(),
Box::new(chunkfs::CopyScrubber),
Sha256Hasher::default(),
);
const SIZE: usize = 8192 * 100;
const KB: usize = 1024;
let mut handle = fs.create_file("file", SuperChunker::default())?;
let mut file = BufReader::new(fio("scrub", SIZE, 30)?.open()?);
fs.write_from_stream(&mut handle, &mut file)?;
fs.close_file(handle)?;
let res = fs.scrub()?;
println!("{res:?}");
let handle = fs.open_file_readonly("file")?;
let read = fs.read_file_complete(&handle)?;
assert_eq!(read.len(), SIZE * KB);
let mut buffer = Vec::with_capacity(SIZE * KB);
file.seek(io::SeekFrom::Start(0))?;
file.read_to_end(&mut buffer)?;
assert_eq!(read, buffer);
Ok(())
}