.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.if !\nF .nr F 0
.if \nF>0 \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
.\}
.\" ========================================================================
.\"
.IX Title "Archive::Tar::Wrapper 3pm"
.TH Archive::Tar::Wrapper 3pm "2018-07-24" "perl v5.26.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Archive::Tar::Wrapper \- API wrapper around the 'tar' utility
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Archive::Tar::Wrapper;
\&
\& my $arch = Archive::Tar::Wrapper\->new();
\&
\& # Open a tarball, expand it into a temporary directory
\& $arch\->read("archive.tgz");
\&
\& # Iterate over all entries in the archive
\& $arch\->list_reset(); # Reset Iterator
\& # Iterate through archive
\& while(my $entry = $arch\->list_next()) {
\& my($tar_path, $phys_path) = @$entry;
\& print "$tar_path\en";
\& }
\&
\& # Get a huge list with all entries
\& for my $entry (@{$arch\->list_all()}) {
\& my($tar_path, $real_path) = @$entry;
\& print "Tarpath: $tar_path Tempfile: $real_path\en";
\& }
\&
\& # Add a new entry
\& $arch\->add($logic_path, $file_or_stringref);
\&
\& # Remove an entry
\& $arch\->remove($logic_path);
\&
\& # Find the physical location of a temporary file
\& my($tmp_path) = $arch\->locate($tar_path);
\&
\& # Create a tarball
\& $arch\->write($tarfile, $compress);
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Archive::Tar::Wrapper is an \s-1API\s0 wrapper around the \f(CW\*(C`tar\*(C'\fR command line
program. It never stores anything in memory, but works on temporary
directory structures on disk instead. It provides a mapping between
the logical paths in the tarball and the 'real' files in the temporary
directory on disk.
.PP
It differs from Archive::Tar in two ways:
.IP "\(bu" 4
Archive::Tar::Wrapper doesn't hold anything in memory. Everything is
stored on disk.
.IP "\(bu" 4
Archive::Tar::Wrapper is 100% compliant with the platform's \f(CW\*(C`tar\*(C'\fR
utility because it uses it internally.
.SH "METHODS"
.IX Header "METHODS"
.IP "\fBmy \f(CB$arch\fB = Archive::Tar::Wrapper\->\f(BInew()\fB\fR" 4
.IX Item "my $arch = Archive::Tar::Wrapper->new()"
Constructor for the tar wrapper class. Finds the \f(CW\*(C`tar\*(C'\fR executable
by searching \f(CW\*(C`PATH\*(C'\fR and returning the first hit. In case you want
to use a different tar executable, you can specify it as a parameter:
.Sp
.Vb 1
\& my $arch = Archive::Tar::Wrapper\->new(tar => \*(Aq/path/to/tar\*(Aq);
.Ve
.Sp
Since \f(CW\*(C`Archive::Tar::Wrapper\*(C'\fR creates temporary directories to store
tar data, the location of the temporary directory can be specified:
.Sp
.Vb 1
\& my $arch = Archive::Tar::Wrapper\->new(tmpdir => \*(Aq/path/to/tmpdir\*(Aq);
.Ve
.Sp
Tremendous performance increases can be achieved if the temporary
directory is located on a ram disk. Check the \*(L"Using \s-1RAM\s0 Disks\*(R"
section below for details.
.Sp
Additional options can be passed to the \f(CW\*(C`tar\*(C'\fR command by using the
\&\f(CW\*(C`tar_read_options\*(C'\fR and \f(CW\*(C`tar_write_options\*(C'\fR parameters. Example:
.Sp
.Vb 3
\& my $arch = Archive::Tar::Wrapper\->new(
\& tar_read_options => "p"
\& );
.Ve
.Sp
will use \f(CW\*(C`tar xfp archive.tgz\*(C'\fR to extract the tarball instead of just
\&\f(CW\*(C`tar xf archive.tgz\*(C'\fR. Gnu tar supports even more options, these can
be passed in via
.Sp
.Vb 3
\& my $arch = Archive::Tar::Wrapper\->new(
\& tar_gnu_read_options => ["\-\-numeric\-owner"],
\& );
.Ve
.Sp
Similarly, \f(CW\*(C`tar_gnu_write_options\*(C'\fR can be used to provide additional
options for Gnu tar implementations. For example, the tar object
.Sp
.Vb 3
\& my $tar = Archive::Tar::Wrapper\->new(
\& tar_gnu_write_options => ["\-\-exclude=foo"],
\& );
.Ve
.Sp
will call the \f(CW\*(C`tar\*(C'\fR utility internally like
.Sp
.Vb 1
\& tar cf tarfile \-\-exclude=foo ...
.Ve
.Sp
when the \f(CW\*(C`write\*(C'\fR method gets called.
.Sp
By default, the \f(CW\*(C`list_*()\*(C'\fR functions will return only file entries.
Directories will be suppressed. To have \f(CW\*(C`list_*()\*(C'\fR
return directories as well, use
.Sp
.Vb 3
\& my $arch = Archive::Tar::Wrapper\->new(
\& dirs => 1
\& );
.Ve
.Sp
If more files are added to a tarball than the command line can handle,
\&\f(CW\*(C`Archive::Tar::Wrapper\*(C'\fR will switch from using the command
.Sp
.Vb 1
\& tar cfv tarfile file1 file2 file3 ...
.Ve
.Sp
to
.Sp
.Vb 1
\& tar cfv tarfile \-T filelist
.Ve
.Sp
where \f(CW\*(C`filelist\*(C'\fR is a file containing all file to be added. The default
for this switch is 512, but it can be changed by setting the parameter
\&\f(CW\*(C`max_cmd_line_args\*(C'\fR:
.Sp
.Vb 3
\& my $arch = Archive::Tar::Wrapper\->new(
\& max_cmd_line_args => 1024
\& );
.Ve
.ie n .IP "\fB\f(CB$arch\fB\->read(""archive.tgz"")\fR" 4
.el .IP "\fB\f(CB$arch\fB\->read(``archive.tgz'')\fR" 4
.IX Item "$arch->read(archive.tgz)"
\&\f(CW\*(C`read()\*(C'\fR opens the given tarball, expands it into a temporary directory
and returns 1 on success or \f(CW\*(C`undef\*(C'\fR on failure.
The temporary directory holding the tar data gets cleaned up when \f(CW$arch\fR
goes out of scope.
.Sp
\&\f(CW\*(C`read\*(C'\fR handles both compressed and uncompressed files. To find out if
a file is compressed or uncompressed, it tries to guess by extension,
then by checking the first couple of bytes in the tarfile.
.Sp
If only a limited number of files is needed from a tarball, they
can be specified after the tarball name:
.Sp
.Vb 1
\& $arch\->read("archive.tgz", "path/file.dat", "path/sub/another.txt");
.Ve
.Sp
The file names are passed unmodified to the \f(CW\*(C`tar\*(C'\fR command, make sure
that the file paths match exactly what's in the tarball, otherwise
\&\f(CW\*(C`read()\*(C'\fR will fail.
.IP "\fB\f(CB$arch\fB\->\f(BIlist_reset()\fB\fR" 4
.IX Item "$arch->list_reset()"
Resets the list iterator. To be used before the first call to
\&\fB\f(CB$arch\fB\->\f(BIlist_next()\fB\fR.
.IP "\fBmy($tar_path, \f(CB$phys_path\fB, \f(CB$type\fB) = \f(CB$arch\fB\->\f(BIlist_next()\fB\fR" 4
.IX Item "my($tar_path, $phys_path, $type) = $arch->list_next()"
Returns the next item in the tarfile. It returns a list of three scalars:
the relative path of the item in the tarfile, the physical path
to the unpacked file or directory on disk, and the type of the entry
(f=file, d=directory, l=symlink). Note that by default,
Archive::Tar::Wrapper won't display directories, unless the \f(CW\*(C`dirs\*(C'\fR
parameter is set when running the constructor.
.IP "\fBmy \f(CB$items\fB = \f(CB$arch\fB\->\f(BIlist_all()\fB\fR" 4
.IX Item "my $items = $arch->list_all()"
Returns a reference to a (possibly huge) array of items in the
tarfile. Each item is a reference to an array, containing two
elements: the relative path of the item in the tarfile and the
physical path to the unpacked file or directory on disk.
.Sp
To iterate over the list, the following construct can be used:
.Sp
.Vb 5
\& # Get a huge list with all entries
\& for my $entry (@{$arch\->list_all()}) {
\& my($tar_path, $real_path) = @$entry;
\& print "Tarpath: $tar_path Tempfile: $real_path\en";
\& }
.Ve
.Sp
If the list of items in the tarfile is big, use \f(CW\*(C`list_reset()\*(C'\fR and
\&\f(CW\*(C`list_next()\*(C'\fR instead of \f(CW\*(C`list_all\*(C'\fR.
.IP "\fB\f(CB$arch\fB\->add($logic_path, \f(CB$file_or_stringref\fB, [$options])\fR" 4
.IX Item "$arch->add($logic_path, $file_or_stringref, [$options])"
Add a new file to the tarball. \f(CW$logic_path\fR is the virtual path
of the file within the tarball. \f(CW$file_or_stringref\fR is either
a scalar, in which case it holds the physical path of a file
on disk to be transferred (i.e. copied) to the tarball, or it is
a reference to a scalar, in which case its content is interpreted
to be the data of the file.
.Sp
If no additional parameters are given, permissions and user/group
id settings of a file to be added are copied. If you want different
settings, specify them in the options hash:
.Sp
.Vb 2
\& $arch\->add($logic_path, $stringref,
\& { perm => 0755, uid => 123, gid => 10 });
.Ve
.Sp
If \f(CW$file_or_stringref\fR is a reference to a Unicode string, the \f(CW\*(C`binmode\*(C'\fR
option has to be set to make sure the string gets written as proper \s-1UTF\-8\s0
into the tarfile:
.Sp
.Vb 1
\& $arch\->add($logic_path, $stringref, { binmode => ":utf8" });
.Ve
.IP "\fB\f(CB$arch\fB\->remove($logic_path)\fR" 4
.IX Item "$arch->remove($logic_path)"
Removes a file from the tarball. \f(CW$logic_path\fR is the virtual path
of the file within the tarball.
.IP "\fB\f(CB$arch\fB\->locate($logic_path)\fR" 4
.IX Item "$arch->locate($logic_path)"
Finds the physical location of a file, specified by \f(CW$logic_path\fR, which
is the virtual path of the file within the tarball. Returns a path to
the temporary file \f(CW\*(C`Archive::Tar::Wrapper\*(C'\fR created to manipulate the
tarball on disk.
.IP "\fB\f(CB$arch\fB\->write($tarfile, \f(CB$compress\fB)\fR" 4
.IX Item "$arch->write($tarfile, $compress)"
Write out the tarball by tarring up all temporary files and directories
and store it in \f(CW$tarfile\fR on disk. If \f(CW$compress\fR holds a true value,
compression is used.
.IP "\fB\f(CB$arch\fB\->\f(BItardir()\fB\fR" 4
.IX Item "$arch->tardir()"
Return the directory the tarball was unpacked in. This is sometimes useful
to play dirty tricks on \f(CW\*(C`Archive::Tar::Wrapper\*(C'\fR by mass-manipulating
unpacked files before wrapping them back up into the tarball.
.IP "\fB\f(CB$arch\fB\->\f(BIis_gnu()\fB\fR" 4
.IX Item "$arch->is_gnu()"
Checks if the tar executable is a \s-1GNU\s0 tar by running 'tar \-\-version'
and parsing the output for \*(L"\s-1GNU\*(R".\s0
.Sp
Returns true or false (in Perl terms).
.IP "\fB\f(CB$arch\fB\->\f(BIis_bsd()\fB\fR" 4
.IX Item "$arch->is_bsd()"
Same as \f(CW\*(C`is_gnu()\*(C'\fR, but for \s-1BSD.\s0
.SH "Using RAM Disks"
.IX Header "Using RAM Disks"
On Linux, it's quite easy to create a \s-1RAM\s0 disk and achieve tremendous
speedups while untarring or modifying a tarball. You can either
create the \s-1RAM\s0 disk by hand by running
.PP
.Vb 2
\& # mkdir \-p /mnt/myramdisk
\& # mount \-t tmpfs \-o size=20m tmpfs /mnt/myramdisk
.Ve
.PP
and then feeding the ramdisk as a temporary directory to
Archive::Tar::Wrapper, like
.PP
.Vb 1
\& my $tar = Archive::Tar::Wrapper\->new( tmpdir => \*(Aq/mnt/myramdisk\*(Aq );
.Ve
.PP
or using Archive::Tar::Wrapper's built-in option 'ramdisk':
.PP
.Vb 6
\& my $tar = Archive::Tar::Wrapper\->new(
\& ramdisk => {
\& type => \*(Aqtmpfs\*(Aq,
\& size => \*(Aq20m\*(Aq, # 20 MB
\& },
\& );
.Ve
.PP
Only drawback with the latter option is that creating the \s-1RAM\s0 disk needs
to be performed as root, which often isn't desirable for security reasons.
For this reason, Archive::Tar::Wrapper offers a utility functions that
mounts the ramdisk and returns the temporary directory it's located in:
.PP
.Vb 5
\& # Create new ramdisk (as root):
\& my $tmpdir = Archive::Tar::Wrapper\->ramdisk_mount(
\& type => \*(Aqtmpfs\*(Aq,
\& size => \*(Aq20m\*(Aq, # 20 MB
\& );
\&
\& # Delete a ramdisk (as root):
\& Archive::Tar::Wrapper\->ramdisk_unmount();
.Ve
.PP
Optionally, the \f(CW\*(C`ramdisk_mount()\*(C'\fR command accepts a \f(CW\*(C`tmpdir\*(C'\fR parameter
pointing to a temporary directory for the ramdisk if you wish to set it
yourself instead of letting Archive::Tar::Wrapper create it automatically.
.SH "KNOWN LIMITATIONS"
.IX Header "KNOWN LIMITATIONS"
.IP "\(bu" 4
Currently, only \f(CW\*(C`tar\*(C'\fR programs supporting the \f(CW\*(C`z\*(C'\fR option (for
compressing/decompressing) are supported. Future version will use
\&\f(CW\*(C`gzip\*(C'\fR alternatively.
.IP "\(bu" 4
Currently, you can't add empty directories to a tarball directly.
You could add a temporary file within a directory, and then
\&\f(CW\*(C`remove()\*(C'\fR the file.
.IP "\(bu" 4
If you delete a file, the empty directories it was located in
stay in the tarball. You could try to \f(CW\*(C`locate()\*(C'\fR them and delete
them. This will be fixed, though.
.IP "\(bu" 4
Filenames containing newlines are causing problems with the list
iterators. To be fixed.
.IP "\(bu" 4
If you ask Archive::Tar::Wrapper to add a file to a tarball, it copies it into
a temporary directory and then calls the system tar to wrap up that directory
into a tarball.
.Sp
This approach has limitations when it comes to file permissions: If the file to
be added belongs to a different user/group, Archive::Tar::Wrapper will adjust
the uid/gid/permissions of the target file in the temporary directory to
reflect the original file's settings, to make sure the system tar will add it
like that to the tarball, just like a regular tar run on the original file
would. But this will fail of course if the original file's uid is different
from the current user's, unless the script is running with superuser rights.
The tar program by itself (without Archive::Tar::Wrapper) works differently:
It'll just make a note of a file's uid/gid/permissions in the tarball (which it
can do without superuser rights) and upon extraction, it'll adjust the
permissions of newly generated files if the \-p option is given (default for
superuser).
.SH "BUGS"
.IX Header "BUGS"
Archive::Tar::Wrapper doesn't currently handle filenames with embedded
newlines.
.SS "Microsoft Windows support"
.IX Subsection "Microsoft Windows support"
Support on Microsoft Windows is limited.
.PP
Version below Windows 10 will not be supported for desktops, and for servers from Windows 2012 and above.
.PP
The \s-1GNU\s0 \f(CW\*(C`tar.exe\*(C'\fR program doesn't work properly with the current interface of Archive::Tar::Wrapper.
You must use the \f(CW\*(C`bsdtar.exe\*(C'\fR and make sure it appears first in the \f(CW\*(C`PATH\*(C'\fR environment variable than
the \s-1GNU\s0 tar (if it is installed). See for details about how to download and
install \f(CW\*(C`bsdtar.exe\*(C'\fR, or go to for a direct download.
.PP
Windows 10 might come already with bsdtar program installed. Check
for
more details.
.PP
Having spaces in the path string to the tar program might be an issue too. Although there is some effort
in terms of workaround it, you best might avoid it completely by installing in a different path than
\&\f(CW\*(C`C:\eProgram Files\*(C'\fR.
.SH "LEGALESE"
.IX Header "LEGALESE"
This software is copyright (c) 2005 of Mike Schilli.
.PP
Archive-Tar-Wrapper is free software: you can redistribute it and/or modify
it under the terms of the \s-1GNU\s0 General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.
.PP
Archive-Tar-Wrapper is distributed in the hope that it will be useful, but
\&\s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0 or
\&\s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the \s-1GNU\s0 General Public License for more
details.
.PP
You should have received a copy of the \s-1GNU\s0 General Public License along with
Archive-Tar-Wrapper. If not, see .
.SH "AUTHOR"
.IX Header "AUTHOR"
2005, Mike Schilli
.SH "MAINTAINER"
.IX Header "MAINTAINER"
2018, Alceu Rodrigues de Freitas Junior