use friendly::bytes;
use indicatif::ProgressBar;
use log::*;
use std::fs;
use std::io::{BufRead, BufReader, Result as IOResult};
use std::path::{Path, PathBuf};
pub mod background;
pub mod compress;
pub mod ext;
pub mod lines;
pub mod object;
pub use compress::open_gzin_progress;
pub use lines::LineProcessor;
pub use object::ObjectWriter;
pub trait DataSink {
fn output_files(&self) -> Vec<PathBuf>;
fn input_files(&self) -> Vec<PathBuf> {
Vec::new()
}
}
pub fn log_file_info<P: AsRef<Path>, S: IntoIterator<Item = P>>(files: S) -> IOResult<()> {
for path in files {
let path = path.as_ref();
let size = file_size(path)?;
info!("output {:?}: {}", path, bytes(size));
}
Ok(())
}
pub fn path_list(paths: &[&str]) -> Vec<PathBuf> {
paths.into_iter().map(|p| PathBuf::from(p)).collect()
}
pub fn file_size<P: AsRef<Path>>(path: P) -> IOResult<u64> {
let meta = fs::metadata(path)?;
Ok(meta.len())
}
pub fn open_progress(path: &Path, pb: ProgressBar) -> IOResult<impl BufRead> {
let name = path.file_name().unwrap().to_string_lossy();
let read = fs::File::open(path)?;
pb.set_length(read.metadata()?.len());
pb.set_prefix(name.to_string());
let read = pb.wrap_read(read);
let read = BufReader::new(read);
Ok(read)
}