ar

Struct Header

Source
pub struct Header { /* private fields */ }
Expand description

Representation of an archive entry header.

Implementations§

Source§

impl Header

Source

pub fn new(identifier: Vec<u8>, size: u64) -> Header

Creates a header with the given file identifier and size, and all other fields set to zero.

Source

pub fn from_metadata(identifier: Vec<u8>, meta: &Metadata) -> Header

Creates a header with the given file identifier and all other fields set from the given filesystem metadata.

Source

pub fn identifier(&self) -> &[u8]

Returns the file identifier.

Examples found in repository?
examples/extract.rs (line 39)
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
fn main() {
    let num_args = env::args().count();
    if num_args != 2 {
        println!("Usage: extract <path/to/archive.a>");
        return;
    }

    let input_path = env::args().nth(1).unwrap();
    let input_path = Path::new(&input_path);
    let input_file =
        File::open(input_path).expect("failed to open input file");
    let mut archive = ar::Archive::new(input_file);

    while let Some(entry) = archive.next_entry() {
        let mut entry = entry.expect("failed to parse archive entry");
        let output_path = Path::new(
            str::from_utf8(entry.header().identifier())
                .expect("Non UTF-8 filename"),
        )
        .to_path_buf();
        let mut output_file = File::create(&output_path)
            .expect(&format!("unable to create file {:?}", output_path));
        io::copy(&mut entry, &mut output_file)
            .expect(&format!("failed to extract file {:?}", output_path));
    }
}
Source

pub fn set_identifier(&mut self, identifier: Vec<u8>)

Sets the file identifier.

Source

pub fn mtime(&self) -> u64

Returns the last modification time in Unix time format.

Source

pub fn set_mtime(&mut self, mtime: u64)

Sets the last modification time in Unix time format.

Source

pub fn uid(&self) -> u32

Returns the value of the owner’s user ID field.

Source

pub fn set_uid(&mut self, uid: u32)

Sets the value of the owner’s user ID field.

Source

pub fn gid(&self) -> u32

Returns the value of the group’s user ID field.

Source

pub fn set_gid(&mut self, gid: u32)

Returns the value of the group’s user ID field.

Source

pub fn mode(&self) -> u32

Returns the mode bits for this file.

Source

pub fn set_mode(&mut self, mode: u32)

Sets the mode bits for this file.

Source

pub fn size(&self) -> u64

Returns the length of the file, in bytes.

Source

pub fn set_size(&mut self, size: u64)

Sets the length of the file, in bytes.

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Header

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Header

Source§

fn eq(&self, other: &Header) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Header

Source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.