extern crate std;
use subprocess;
use unpacker;
struct Bzip2 {
}
impl unpacker::Unpacker for Bzip2 {
fn unpack(&self, in_file: &std::path::Path, out_dir: &std::path::Path) -> Result<std::path::PathBuf, unpacker::Error> {
info!("Unpacking (bzip2) {:?} in {:?}", in_file, out_dir);
unpacker::check_unpack_args(in_file, out_dir)?;
let in_path_str = match in_file.to_str() {
Some(path) => path,
None => { return Err(unpacker::PathError); }
};
if ! out_dir.exists() {
std::fs::create_dir_all(out_dir)?;
}
let mut output = out_dir.to_path_buf();
match in_file.file_name() {
Some(os_str) => {
output.push(os_str);
},
None => { return Err(unpacker::PathError); }
}
output.set_extension("");
let mut cmd = subprocess::new("bzip2");
cmd.stdout(std::process::Stdio::null());
cmd.arg("-d");
cmd.arg(in_path_str);
subprocess::run(&mut cmd)?;
Ok(output)
}
}
pub fn new() -> Box<unpacker::Unpacker> {
Box::new(Bzip2 {
})
}
pub fn name_get() -> &'static str {
"bz2"
}