Extract all the files contained in a
".tar" file.
It is equivalent to calling the standard
tar program like so:
$ tar -x -f tarball.tar -C dir
So for example if the
tarball.tar file contains
foo/bar.txt then this will extract it to
dir/foo/bar.txt.
This is a high level "all in one" operation. Since you may need
variations on this function it is instructive to see how it is
written. It is just:
import qualified Data.ByteString.Lazy as BL
Tar.unpack dir . Tar.read =<< BL.readFile tar
Notes:
Extracting can fail for a number of reasons. The tarball may be
incorrectly formatted. There may be IO or permission errors. In such
cases an exception will be thrown and extraction will not continue.
Since the extraction may fail part way through it is not atomic. For
this reason you may want to extract into an empty directory and, if
the extraction fails, recursively delete the directory.
Security: only files inside the target directory will be written.
Tarballs containing entries that point outside of the tarball (either
absolute paths or relative paths) will be caught and an exception will
be thrown.