Struct Archive

pub struct Archive<R: ?Sized + Read> { /* private fields */ }

A top-level representation of an archive file.

This archive can have an entry added to it and it can be iterated over.

Implementations

impl<R: Read> Archive<R>

fn new(obj: R) -> Archive<R>

Create a new archive with the underlying object as the reader.

fn into_inner(self) -> R

Unwrap this archive, returning the underlying object.

fn entries(&mut self) -> Result<Entries<'_, R>>

Construct an iterator over the entries in this archive.

Note that care must be taken to consider each entry within an archive in sequence. If entries are processed out of sequence (from what the iterator returns), then the contents read for each entry may be corrupted.

fn unpack<P: AsRef<Path>>(&mut self, dst: P) -> Result<()>

Unpacks the contents tarball into the specified dst.

This function will iterate over the entire contents of this tarball, extracting each file in turn to the location specified by the entry's path name.

Security

See the [crate-level security documentation][crate#security]. If dst does not exist, it is created. Unpacking into an existing directory merges content.

Examples

use std::fs::File;
use tar::Archive;

let mut ar = Archive::new(File::open("foo.tar").unwrap());
ar.unpack("foo").unwrap();
fn set_mask(&mut self, mask: u32)

Set the mask of the permission bits when unpacking this entry.

The mask will be inverted when applying against a mode, similar to how umask works on Unix. In logical notation it looks like:

new_mode = old_mode & (~mask)

The mask is 0 by default and is currently only implemented on Unix.

fn set_unpack_xattrs(&mut self, unpack_xattrs: bool)

Indicate whether extended file attributes (xattrs on Unix) are preserved when unpacking this archive.

This flag is disabled by default and is currently only implemented on Unix using xattr support. This may eventually be implemented for Windows, however, if other archive implementations are found which do this as well.

fn set_preserve_permissions(&mut self, preserve: bool)

Indicate whether extended permissions (like suid on Unix) are preserved when unpacking this entry.

This flag is disabled by default and is currently only implemented on Unix.

fn set_preserve_ownerships(&mut self, preserve: bool)

Indicate whether numeric ownership ids (like uid and gid on Unix) are preserved when unpacking this entry.

This flag is disabled by default and is currently only implemented on Unix.

fn set_overwrite(&mut self, overwrite: bool)

Indicate whether files and symlinks should be overwritten on extraction.

fn set_preserve_mtime(&mut self, preserve: bool)

Indicate whether access time information is preserved when unpacking this entry.

This flag is enabled by default.

fn set_ignore_zeros(&mut self, ignore_zeros: bool)

Ignore zeroed headers, which would otherwise indicate to the archive that it has no more entries.

This can be used in case multiple tar archives have been concatenated together.

impl<R: Seek + Read> Archive<R>

fn entries_with_seek(&mut self) -> Result<Entries<'_, R>>

Construct an iterator over the entries in this archive for a seekable reader. Seek will be used to efficiently skip over file contents.

Note that care must be taken to consider each entry within an archive in sequence. If entries are processed out of sequence (from what the iterator returns), then the contents read for each entry may be corrupted.

Auto Trait Implementations

impl<R> !Freeze for Archive<R>

impl<R> !RefUnwindSafe for Archive<R>

impl<R> !Sync for Archive<R>

impl<R> Send for Archive<R> where ArchiveInner<R>: Send, R: ?Sized,

impl<R> Unpin for Archive<R> where ArchiveInner<R>: Unpin, R: ?Sized,

impl<R> UnsafeUnpin for Archive<R> where ArchiveInner<R>: UnsafeUnpin, R: ?Sized,

impl<R> UnwindSafe for Archive<R> where ArchiveInner<R>: UnwindSafe, R: ?Sized,

Blanket Implementations

impl<T> Any for Archive<R> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> From<T> for Archive<R>

fn from(t: T) -> T

Returns the argument unchanged.

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

fn into(self) -> U

Calls U::from(self).

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

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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