4 use std
::os
::unix
::io
::FromRawFd
;
5 use std
::path
::{Path, PathBuf}
;
10 /// Writer implementation to deccode a .pxar archive (download).
12 pub struct PxarDecodeWriter
{
13 pipe
: Option
<std
::fs
::File
>,
14 child
: Option
<thread
::JoinHandle
<()>>,
17 impl Drop
for PxarDecodeWriter
{
20 drop(self.pipe
.take());
21 self.child
.take().unwrap().join().unwrap();
25 impl PxarDecodeWriter
{
27 pub fn new(base
: &Path
, verbose
: bool
) -> Result
<Self, Error
> {
28 let (rx
, tx
) = nix
::unistd
::pipe()?
;
30 let base
= PathBuf
::from(base
);
32 let child
= thread
::spawn(move|| {
33 let mut reader
= unsafe { std::fs::File::from_raw_fd(rx) }
;
34 let mut decoder
= pxar
::SequentialDecoder
::new(&mut reader
, pxar
::flags
::DEFAULT
);
35 decoder
.set_callback(move |path
| {
37 println
!("{:?}", path
);
42 if let Err(err
) = decoder
.restore(&base
, &Vec
::new()) {
43 eprintln
!("pxar decode failed - {}", err
);
47 let pipe
= unsafe { std::fs::File::from_raw_fd(tx) }
;
49 Ok(Self { pipe: Some(pipe), child: Some(child) }
)
53 impl Write
for PxarDecodeWriter
{
55 fn write(&mut self, buffer
: &[u8]) -> Result
<usize, std
::io
::Error
> {
56 let pipe
= match self.pipe
{
57 Some(ref mut pipe
) => pipe
,
58 None
=> unreachable
!(),
63 fn flush(&mut self) -> Result
<(), std
::io
::Error
> {
64 let pipe
= match self.pipe
{
65 Some(ref mut pipe
) => pipe
,
66 None
=> unreachable
!(),