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
use std::path::{PathBuf, Path};
use crate::error::FsResult;
use std::io::Write;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CurrentSrc{
SrcDir(PathBuf),
ArchiveFile(PathBuf),
}
impl CurrentSrc{
pub fn from_src_dir<P : AsRef<Path>>(src_dir : P) -> CurrentSrc{
CurrentSrc::SrcDir(PathBuf::from(src_dir.as_ref()))
}
pub fn from_archive_file<P : AsRef<Path>>(archive_file_path : P) -> CurrentSrc{
CurrentSrc::ArchiveFile(PathBuf::from(archive_file_path.as_ref()))
}
pub fn create_archive<W : Write>(&self, write : &mut W) -> FsResult<()>{
match &self{
CurrentSrc::SrcDir(src_dir) => {
dochy_core::archive_src_dir(src_dir, write)?;
Ok(())
},
CurrentSrc::ArchiveFile(path) =>{
let mut file = std::fs::File::open(path)?;
std::io::copy(&mut file, write)?;
Ok(())
}
}
}
}