Struct tar::Archive [] [src]

pub struct Archive<R> {
    // some fields omitted
}

A top-level representation of an archive file.

This archive can have a file added to it and it can be iterated over.

Methods

impl<O> Archive<O>
[src]

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

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

Different methods are available on an archive depending on the traits that the underlying object implements.

fn into_inner(self) -> O

Unwrap this archive, returning the underlying object.

impl<R: Seek + Read> Archive<R>
[src]

fn files(&self) -> Result<Files<R>>

Construct an iterator over the files of this archive.

This function can return an error if any underlying I/O operation files while attempting to construct the iterator.

Additionally, the iterator yields io::Result<File> instead of File to handle invalid tar archives as well as any intermittent I/O error that occurs.

impl<R: Read> Archive<R>
[src]

fn files_mut(&mut self) -> Result<FilesMut<R>>

Construct an iterator over the files in this archive.

While similar to the files iterator, this iterator does not require that R implement Seek and restricts the iterator to processing only one file at a time in a streaming fashion.

Note that care must be taken to consider each file within an archive in sequence. If files are processed out of sequence (from what the iterator returns), then the contents read for each file 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.

This operation is relatively sensitive in that it will not write files outside of the path specified by into. 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();

impl<W: Write> Archive<W>
[src]

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

Adds a new entry to this archive.

This function will append the header specified, followed by contents of the stream specified by data. To produce a valid archive the size field of header must be the same as the length of the stream that's being written. Additionally the checksum for the header should have been set via the set_cksum method.

Note that this will not attempt to seek the archive to a valid position, so if the archive is in the middle of a read or some other similar operation then this may corrupt the archive.

Also note that after all files have been written to an archive the finish function needs to be called to finish writing the archive.

Errors

This function will return an error for any intermittent I/O error which occurs when either reading or writing.

Examples

use tar::{Archive, Header};

let mut header = Header::new();
header.set_path("foo");
header.set_size(4);
header.set_cksum();

let mut data: &[u8] = &[1, 2, 3, 4];

let mut ar = Archive::new(Vec::new());
ar.append(&header, &mut data).unwrap();
let archive = ar.into_inner();

fn append_path<P: AsRef<Path>>(&self, path: P) -> Result<()>

Adds a file on the local filesystem to this archive.

This function will open the file specified by path and insert the file into the archive with the appropriate metadata set, returning any I/O error which occurs while writing. The path name for the file inside of this archive will be the same as path, and it is recommended that the path is a relative path.

Note that this will not attempt to seek the archive to a valid position, so if the archive is in the middle of a read or some other similar operation then this may corrupt the archive.

Also note that after all files have been written to an archive the finish function needs to be called to finish writing the archive.

Examples

use tar::Archive;

let mut ar = Archive::new(Vec::new());

ar.append_path("foo/bar.txt").unwrap();

fn append_file<P: AsRef<Path>>(&self, path: P, file: &mut File) -> Result<()>

Adds a file to this archive with the given path as the name of the file in the archive.

This will use the metadata of file to populate a Header, and it will then append the file to the archive with the name path.

Note that this will not attempt to seek the archive to a valid position, so if the archive is in the middle of a read or some other similar operation then this may corrupt the archive.

Also note that after all files have been written to an archive the finish function needs to be called to finish writing the archive.

Examples

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

let mut ar = Archive::new(Vec::new());

// Open the file at one location, but insert it into the archive with a
// different name.
let mut f = File::open("foo/bar/baz.txt").unwrap();
ar.append_path("bar/baz.txt").unwrap();

fn finish(&self) -> Result<()>

Finish writing this archive, emitting the termination sections.

This function is required to be called to complete the archive, it will be invalid if this is not called.

Trait Implementations

impl<'a, R: Read> Read for &'a Archive<R>
[src]

fn read(&mut self, into: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usizeError>
1.0.0

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_to_string(&mut self, buf: &mut String) -> Result<usizeError>
1.0.0

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_exact(&mut self, buf: &mut [u8]) -> Result<()Error>
1.6.0

Read the exact number of bytes required to fill buf. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0

Creates a "by reference" adaptor for this instance of Read. Read more

fn bytes(self) -> Bytes<Self>
1.0.0

Transforms this Read instance to an Iterator over its bytes. Read more

fn chars(self) -> Chars<Self>

Unstable (io)

: the semantics of a partial read/write of where errors happen is currently unclear and may change

Transforms this Read instance to an Iterator over chars. Read more

fn chain<R>(self, next: R) -> Chain<Self, R> where R: Read
1.0.0

Creates an adaptor which will chain this stream with another. Read more

fn take(self, limit: u64) -> Take<Self>
1.0.0

Creates an adaptor which will read at most limit bytes from it. Read more