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.

LEGALESE

Copyright 2005 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

2005, Mike Schilli cpan@perlmeister.com

MAINTAINER

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