pub struct Sfv {
pub files: BTreeMap<PathBuf, Vec<u8>>,
}
Fields§
§files: BTreeMap<PathBuf, Vec<u8>>
The file paths and their checksums/hashes
Implementations§
Source§impl Sfv
impl Sfv
Sourcepub fn from_sfv<P: AsRef<Path>, S: AsRef<str>>(
base_directory: P,
sfv: S,
) -> Result<Self, ()>
pub fn from_sfv<P: AsRef<Path>, S: AsRef<str>>( base_directory: P, sfv: S, ) -> Result<Self, ()>
Convert a SFV file in string format to a Sfv object.
use sfv::Sfv;
use std::collections::BTreeMap;
use std::path::PathBuf;
let sfv_file = r#"
; This is a comment
file_one.zip c45ad668
file_two.zip 7903b8e6
file_three.zip e99a65fb
"#;
let sfv = Sfv::from_sfv("/test", sfv_file).unwrap();
assert_eq!(
*sfv.files.get(&PathBuf::from("/test/file_one.zip")).unwrap(),
vec![0xc4, 0x5a, 0xd6, 0x68]
)
Sourcepub fn add_file<P: AsRef<Path>, D: AsRef<[u8]>>(&mut self, path: P, data: D)
pub fn add_file<P: AsRef<Path>, D: AsRef<[u8]>>(&mut self, path: P, data: D)
Adds a file and checksum entry to the Sfv.
use sfv::Sfv;
use std::path::PathBuf;
let mut sfv = Sfv::new();
let path = PathBuf::from("/test.txt");
let checksum: Vec<u8> = vec![0x42, 0x42, 0x42, 0x42];
sfv.add_file(&path, &checksum);
assert_eq!(
*sfv.files.get(&PathBuf::from("/test.txt")).unwrap(),
vec![0x42, 0x42, 0x42, 0x42]
)
Trait Implementations§
Source§impl Ord for Sfv
impl Ord for Sfv
Source§impl PartialOrd for Sfv
impl PartialOrd for Sfv
impl Eq for Sfv
impl StructuralPartialEq for Sfv
Auto Trait Implementations§
impl Freeze for Sfv
impl RefUnwindSafe for Sfv
impl Send for Sfv
impl Sync for Sfv
impl Unpin for Sfv
impl UnwindSafe for Sfv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more