NAME

Archive::Tar::Wrapper - API wrapper around the 'tar' utility

SYNOPSIS

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\n";
}

    # 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\n";
}

    # 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);

DESCRIPTION

Archive::Tar::Wrapper is an API wrapper around the 'tar' command line utility. 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.

It differs from Archive::Tar in two ways:

METHODS

Using RAM Disks

On Linux, it's quite easy to create a RAM disk and achieve tremendous speedups while untarring or modifying a tarball. You can either create the RAM disk by hand by running

# mkdir -p /mnt/myramdisk
# mount -t tmpfs -o size=20m tmpfs /mnt/myramdisk

and then feeding the ramdisk as a temporary directory to Archive::Tar::Wrapper, like

my $tar = Archive::Tar::Wrapper->new( tmpdir => '/mnt/myramdisk' );

or using Archive::Tar::Wrapper's built-in option 'ramdisk':

my $tar = Archive::Tar::Wrapper->new(
    ramdisk => {
        type => 'tmpfs',
        size => '20m',   # 20 MB
    },
);

Only drawback with the latter option is that creating the RAM 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:

  # Create new ramdisk (as root):
my $tmpdir = Archive::Tar::Wrapper->ramdisk_mount(
    type => 'tmpfs',
    size => '20m',   # 20 MB
);

  # Delete a ramdisk (as root):
Archive::Tar::Wrapper->ramdisk_unmount();

Optionally, the ramdisk_mount() command accepts a tmpdir 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.

KNOWN LIMITATIONS

BUGS

Archive::Tar::Wrapper doesn't currently handle filenames with embedded newlines.

Microsoft Windows support

Support on Microsoft Windows is limited.

Version below Windows 10 will not be supported for desktops, and for servers from Windows 2012 and above.

The GNU tar.exe program doesn't work properly with the current interface of Archive::Tar::Wrapper. You must use the bsdtar.exe and make sure it appears first in the PATH environment variable than the GNU tar (if it is installed). See http://libarchive.org/ for details about how to download and install bsdtar.exe, or go to http://gnuwin32.sourceforge.net/packages.html for a direct download.

Windows 10 might come already with bsdtar program installed. Check https://blogs.technet.microsoft.com/virtualization/2017/12/19/tar-and-curl-come-to-windows/ for more details.

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 C:\Program Files.

LEGALESE

This software is copyright (c) 2005 of Mike Schilli.

Archive-Tar-Wrapper is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Archive-Tar-Wrapper is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Archive-Tar-Wrapper. If not, see <http://www.gnu.org/licenses/>.

AUTHOR

2005, Mike Schilli cpan@perlmeister.com

MAINTAINER

2018, Alceu Rodrigues de Freitas Junior arfreitas@cpan.org