Module tar
Read and write tar archives.
tar reads and writes the tar archive format,
which bundles files and their metadata into a single stream.
It does not compress:
a .tar.gz is a tar archive passed through gzip,
so pair this crate with flate2 to read or write one.
The API is abstract over Read and Write
rather than tied to files,
and it is streaming throughout —
an archive of any size can be processed
without holding it in memory.
Archive reads an existing archive,
yielding an Entry per member,
each of which is itself a Read.
Builder writes a new one.
Header carries the per-entry metadata:
path, size, mode, timestamps, and EntryType,
which distinguishes regular files from directories,
symlinks, and hard links.
Unpacking an untrusted archive can be insecure.
Entries can name absolute paths, paths containing ..,
and symlinks or hard links pointing anywhere on the filesystem.
Archive::unpack and Entry::unpack_in exist to contain that,
refusing to write outside the destination directory.
Examples
Writing an archive and reading it back, in memory:
use Read;
use ;
let mut header = new_gnu;
header.set_path.unwrap;
header.set_size;
header.set_mode;
header.set_cksum;
let mut builder = new;
builder.append.unwrap;
let bytes = builder.into_inner.unwrap;
let mut archive = new;
for entry in archive.entries.unwrap
Making a .tar.gz by layering a compressor over the archive:
use Compression;
use GzDecoder;
use GzEncoder;
use ;
let mut header = new_gnu;
header.set_path.unwrap;
header.set_size;
header.set_cksum;
let mut builder = new;
builder.append.unwrap;
let targz = builder.into_inner.unwrap.finish.unwrap;
let mut archive = new;
assert_eq!;
Unpacking to a directory:
use ;
let mut header = new_gnu;
header.set_path.unwrap;
header.set_size;
header.set_mode;
header.set_cksum;
let mut builder = new;
builder.append.unwrap;
let bytes = builder.into_inner.unwrap;
let dir = tempdir.unwrap;
new.unpack.unwrap;
assert_eq!;