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
::CA_FORMAT_DEFAULT
);
36 if let Err(err
) = decoder
.restore(&base
, & |path
| {
38 println
!("{:?}", path
);
42 eprintln
!("pxar decode failed - {}", err
);
46 let pipe
= unsafe { std::fs::File::from_raw_fd(tx) }
;
48 Ok(Self { pipe: Some(pipe), child: Some(child) }
)
52 impl Write
for PxarDecodeWriter
{
54 fn write(&mut self, buffer
: &[u8]) -> Result
<usize, std
::io
::Error
> {
55 let pipe
= match self.pipe
{
56 Some(ref mut pipe
) => pipe
,
57 None
=> unreachable
!(),
62 fn flush(&mut self) -> Result
<(), std
::io
::Error
> {
63 let pipe
= match self.pipe
{
64 Some(ref mut pipe
) => pipe
,
65 None
=> unreachable
!(),