Builder

Struct Builder 

Source
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>

Source

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}
Source

pub fn into_inner(self) -> Result<W>

Unwrap this archive builder, returning the underlying writer object.

Source

pub fn append<R: Read>(&mut self, header: &Header, data: R) -> Result<()>

Adds a new entry to this archive.

Source

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}
Source

pub fn append_file(&mut self, name: &[u8], file: &mut File) -> Result<()>

Adds a file to this archive, with the given name as its identifier.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.