The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tar - module for manipulation of tar archives.

SYNOPSIS

    use Archive::Tar;

    # or use Archive::Tar::Win32 directly - not recommended
    # use Archive::Tar::Win32

    $tar = Archive::Tar->new();
    $tar->read("origin.tar.gz",1);
    $tar->add_files("file/foo.c", "file/bar.c");
    $tar->add_data("file/baz.c","This is the file contents");
    $tar->write("files.tar");

DESCRIPTION

This is a module for the handling of tar archives. Due to the nature of the Win32 environment, Archive::Tar falls back to an older version. Although less in features, it's proven to work.

At the moment these methods are implemented:

new()

Returns a new Tar object. If given a filename as an argument, it will try to load that as a tar file. If given a true value as a second argument, will assume that the tar file is compressed, and will attempt to read it using Compress::Zlib.

add_files(@filenamelist)

Takes a list of filenames and adds them to the in-memory archive. I suspect that this function will produce bogus tar archives when used under MacOS, but I'm not sure and I have no Mac to test it on.

add_data($filename,$data,$opthashref)

Takes a filename, a scalar full of data and optionally a reference to a hash with specific options. Will add a file to the in-memory archive, with name $filename and content $data. Specific options can be set using $opthashref, which will be documented later.

remove(@filenamelist)

Removes any entries with names matching any of the given filenames from the in-memory archive. String comparisons are done with eq.

read('file.tar',$compressed)

Try to read the given tarfile into memory. If the second argument is a true value, the tarfile is assumed to be compressed. Will replace any previous content in $tar!

write('file.tar',$compressed)

Will write the in-memory archive to disk. If no filename is given, returns the entire formatted archive as a string, which should be useful if you'd like to stuff the archive into a socket or a pipe to gzip or something. If the second argument is true, the module will try to write the file compressed.

data()

Returns the in-memory archive. This is a list of references to hashes, the internals of which is not currently documented.

extract(@filenames)

Write files whose names are equivalent to any of the names in @filenames to disk, creating subdirectories as neccesary. This might not work too well under VMS and MacOS.

list_files()

Returns a list with the names of all files in the in-memory archive.

get_content($file)

Return the content of the named file.

replace_content($file,$content)

Make the string $content be the content for the file named $file.

CHANGES

Version 0.073

Bundle Archive::Tar 0.072 and 0.22 together. Falling back to 0.072 version if on a Win32 platform (now called Archive::Tar::Win32) and 0.22 if on another platform (now called Archive::Tar::Std).

This change should work transparently for users.

Added the error() and set_error() methods as also available in 0.22

Version 0.071

Minor release.

Arrange to chmod() at the very end in case it makes the file readonly. Win32 is actually picky about that.

SunOS 4.x tar makes tarfiles that contain directory entries that don't have typeflag set properly. We use the trailing slash to recognize directories in such tarfiles.

Version 0.07

Fixed (hopefully) broken portability to MacOS, reported by Paul J. Schinder at Goddard Space Flight Center.

Fixed two bugs with symlink handling, reported in excellent detail by an admin at teleport.com called Chris.

Primive tar program (called ptar) included with distribution. Useage should be pretty obvious if you've used a normal tar program.

Added methods get_content and replace_content.

Added support for paths longer than 100 characters, according to POSIX. This is compatible with just about everything except GNU tar. Way to go, GNU tar (use a better tar, or GNU cpio).

NOTE: When adding files to an archive, files with basenames longer than 100 characters will be silently ignored. If the prefix part of a path is longer than 155 characters, only the last 155 characters will be stored.

Version 0.06

Added list_files() method, as requested by Michael Wiedman.

Fixed a couple of dysfunctions when run under Windows NT. Michael Wiedmann reported the bugs.

Changed the documentation to reflect reality a bit better.

Fixed bug in format_tar_entry. Bug reported by Michael Schilli.

Version 0.05

Quoted lots of barewords to make use strict; stop complaining under perl version 5.003.

Ties to Compress::Zlib put in. Will warn if it isn't available.

$tar->write() with no argument now returns the formatted archive.

Version 0.04

Made changes to write_tar so that Solaris tar likes the resulting archives better.

Protected the calls to readlink() and symlink(). AFAIK this module should now run just fine on Windows NT.

Add method to write a single entry to disk (extract)

Added method to add entries entirely from scratch (add_data)

Changed name of add() to add_file()

All calls to croak() removed and replaced with returning undef and setting Tar::error.

Better handling of tarfiles with garbage at the end.

COPYRIGHT

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 746:

You forgot a '=back' before '=head1'