pub struct Builder<W: Write> { /* private fields */ }Expand description
A structure for building Common or BSD-variant archives (the archive format typically used on e.g. BSD and Mac OS X systems).
This structure has methods for building up an archive from scratch into any arbitrary writer.
Implementations§
Source§impl<W: Write> Builder<W>
impl<W: Write> Builder<W>
Sourcepub fn new(writer: W) -> Builder<W>
pub fn new(writer: W) -> Builder<W>
Create a new archive builder with the underlying writer object as the destination of all data written.
Examples found in repository?
examples/create.rs (line 33)
22fn main() {
23 let num_args = env::args().count();
24 if num_args < 3 {
25 println!("Usage: create <outpath> <inpath> [<inpath>...]");
26 return;
27 }
28
29 let output_path = env::args().nth(1).unwrap();
30 let output_path = Path::new(&output_path);
31 let output_file =
32 File::create(output_path).expect("failed to open output file");
33 let mut builder = ar::Builder::new(output_file);
34
35 for index in 2..num_args {
36 let input_path = env::args().nth(index).unwrap();
37 let input_path = Path::new(&input_path);
38 builder
39 .append_path(input_path)
40 .expect(&format!("failed to add {:?} to archive", input_path));
41 }
42}Sourcepub fn into_inner(self) -> Result<W>
pub fn into_inner(self) -> Result<W>
Unwrap this archive builder, returning the underlying writer object.
Sourcepub fn append<R: Read>(&mut self, header: &Header, data: R) -> Result<()>
pub fn append<R: Read>(&mut self, header: &Header, data: R) -> Result<()>
Adds a new entry to this archive.
Sourcepub fn append_path<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn append_path<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Adds a file on the local filesystem to this archive, using the file name as its identifier.
Examples found in repository?
examples/create.rs (line 39)
22fn main() {
23 let num_args = env::args().count();
24 if num_args < 3 {
25 println!("Usage: create <outpath> <inpath> [<inpath>...]");
26 return;
27 }
28
29 let output_path = env::args().nth(1).unwrap();
30 let output_path = Path::new(&output_path);
31 let output_file =
32 File::create(output_path).expect("failed to open output file");
33 let mut builder = ar::Builder::new(output_file);
34
35 for index in 2..num_args {
36 let input_path = env::args().nth(index).unwrap();
37 let input_path = Path::new(&input_path);
38 builder
39 .append_path(input_path)
40 .expect(&format!("failed to add {:?} to archive", input_path));
41 }
42}Auto Trait Implementations§
impl<W> Freeze for Builder<W>where
W: Freeze,
impl<W> RefUnwindSafe for Builder<W>where
W: RefUnwindSafe,
impl<W> Send for Builder<W>where
W: Send,
impl<W> Sync for Builder<W>where
W: Sync,
impl<W> Unpin for Builder<W>where
W: Unpin,
impl<W> UnwindSafe for Builder<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more