unarchiver 0.0.2

CLI Tool for un/archive multiple formats of compressed files
Documentation
use std::fs::File;
use std::path::{Path, PathBuf};
use std::io::Write;

use anyhow::Result;
use tar::Builder;

use crate::archive::Unarchiver;

pub struct TarUnarchiver;

impl TarUnarchiver {
    pub fn new() -> Self {
        Self {}
    }
}

impl Unarchiver for TarUnarchiver {
    async fn unarchive<P: AsRef<Path>>(&self, path: P, out: P) -> Result<()> {
        let file = File::open(path.as_ref())?;
        let mut archive = tar::Archive::new(file);

        archive.unpack(out.as_ref())?;

        Ok(())
    }

    async fn archive<P: AsRef<Path>>(&self, path: P, out: P) -> Result<()> {
        let file = File::create(out.as_ref())?;
        let mut builder = Builder::new(file);
        // let path = PathBuf::from(path.as_ref());

        builder.append_path(path.as_ref().file_name().unwrap())?;
        builder.finish()?;

        Ok(())
    }
}