this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at bdd902269b57947f3d8bebccb528b8a9482993fe 71 lines 2.2 kB view raw
1use std::io; 2use std::path::{Path, PathBuf}; 3 4/// Common interface for all compressor implementations 5#[allow(unused_variables)] 6pub trait Compressor { 7 /// Name of this Compressor 8 fn name(&self) -> &str; 9 10 /// Default extension for this Compressor 11 fn extension(&self) -> &str { 12 self.name() 13 } 14 15 /// Detect if the input is an archive of this type 16 #[allow(dead_code)] 17 fn is_archive(&self, in_path: &Path) -> bool { 18 in_path.extension().unwrap_or_default() == self.extension() 19 } 20 21 /// Generate the default name for the compressed file 22 fn default_compressed_filename(&self, in_path: &Path) -> String { 23 format!( 24 "{}.{}", 25 in_path.file_name().unwrap().to_str().unwrap(), 26 self.extension() 27 ) 28 } 29 30 /// Generate the default extracted filename 31 fn default_extracted_filename(&self, in_path: &Path) -> String { 32 // If the file has the extension for this type, return the filename without the extension 33 if in_path.extension().unwrap() == self.extension() { 34 return in_path.file_stem().unwrap().to_str().unwrap().to_string(); 35 } 36 // If the file has no extension, return the current directory 37 if in_path.extension().is_none() { 38 return ".".to_string(); 39 } 40 // Otherwise, return the current directory and hope for the best 41 ".".to_string() 42 } 43 44 fn compress(&self, input: CmprssInput, output: CmprssOutput) -> Result<(), io::Error> { 45 cmprss_error("compress_target unimplemented") 46 } 47 48 fn extract(&self, input: CmprssInput, output: CmprssOutput) -> Result<(), io::Error> { 49 cmprss_error("extract_target unimplemented") 50 } 51} 52 53pub fn cmprss_error(message: &str) -> Result<(), io::Error> { 54 Err(io::Error::new(io::ErrorKind::Other, message)) 55} 56 57/// Defines the possible inputs of a compressor 58#[derive(Debug)] 59pub enum CmprssInput { 60 /// Path(s) to the input files. 61 Path(Vec<PathBuf>), 62 /// Input pipe 63 Pipe(std::io::Stdin), 64} 65 66/// Defines the possible outputs of a compressor 67#[derive(Debug)] 68pub enum CmprssOutput { 69 Path(PathBuf), 70 Pipe(std::io::Stdout), 71}