Struct tar::Archive

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

A top-level representation of an archive file.

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

Implementations§

source§

impl<R: Read> Archive<R>

source

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

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

source

pub fn into_inner(self) -> R

Unwrap this archive, returning the underlying object.

source

pub 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.

source

pub 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.

This operation is relatively sensitive in that it will not write files outside of the path specified by dst. Files in the archive which have a ‘..’ in their path are skipped during the unpacking process.

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

let mut ar = Archive::new(File::open("foo.tar").unwrap());
ar.unpack("foo").unwrap();
source

pub 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.

source

pub 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.

source

pub fn set_overwrite(&mut self, overwrite: bool)

Indicate whether files and symlinks should be overwritten on extraction.

source

pub 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.

source

pub 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.

source§

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

source

pub 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> Send for Archive<R>
where R: Send + ?Sized,

§

impl<R> !Sync for Archive<R>

§

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

§

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

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

§

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

§

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.