mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
25 lines
606 B
Rust
25 lines
606 B
Rust
use std::{path::Path, process::Stdio};
|
|
|
|
use anyhow::{bail, Result};
|
|
use tokio::{io::{AsyncReadExt, BufReader}, process::Command};
|
|
|
|
pub async fn unar_head(path: &Path, target: &Path) -> Result<Vec<u8>> {
|
|
let mut child = Command::new("unar")
|
|
.args(&[path, target])
|
|
.args(&["-o", "-"])
|
|
.stdout(Stdio::piped())
|
|
.stderr(Stdio::null())
|
|
.kill_on_drop(true)
|
|
.spawn()?;
|
|
|
|
let mut buf = vec![0; 1024];
|
|
let mut reader = BufReader::new(child.stdout.take().unwrap());
|
|
|
|
reader.read(&mut buf).await.ok();
|
|
child.kill().await.ok();
|
|
|
|
if buf.is_empty() {
|
|
bail!("failed to get head of unar");
|
|
}
|
|
Ok(buf)
|
|
}
|