-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfile.rs
More file actions
34 lines (29 loc) · 887 Bytes
/
Copy pathfile.rs
File metadata and controls
34 lines (29 loc) · 887 Bytes
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
use crate::checksum::{CheckSum, CheckSummer};
use std::path;
pub type SizeBytes = u64;
#[derive(Debug, Eq, Hash, PartialEq, Clone)]
pub struct File {
pub path: path::PathBuf,
pub size: SizeBytes,
pub check_sum: CheckSum,
}
impl File {
pub fn new(path: path::PathBuf, size_bytes: SizeBytes, check_sum: CheckSum) -> File {
return File {
path,
size: size_bytes,
check_sum,
};
}
pub fn equals(&self, f2: &File) -> bool {
return self.check_sum == f2.check_sum && self.size == f2.size;
}
#[allow(dead_code)]
pub fn from_strings(path: &str, contents: &str) -> File {
return File {
path: path::Path::new(path).to_path_buf(),
size: contents.len() as SizeBytes,
check_sum: CheckSummer::new().consume(contents.as_bytes()).finalize(),
};
}
}