Archive-Tar-Wrapper
view release on metacpan or search on metacpan
will call the "tar" utility internally like
tar cf tarfile --exclude=foo ...
when the "write" method gets called.
By default, the "list_*()" functions will return only file entries:
directories will be suppressed. To have "list_*()" return directories as
well, use
my $arch = Archive::Tar::Wrapper->new(
dirs => 1
);
If more files are added to a tarball than the command line can handle,
Archive::Tar::Wrapper will switch from using the command
tar cfv tarfile file1 file2 file3 ...
to
tar cfv tarfile -T filelist
where "filelist" 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
"max_cmd_line_args":
my $arch = Archive::Tar::Wrapper->new(
max_cmd_line_args => 1024
);
The allowable parameters are:
* "tar"
* "tmpdir"
* "tar_read_options"
* "tar_write_options"
* "tar_gnu_read_options"
* "tar_gnu_write_options"
* "max_cmd_line_args": defaults to 512
* "ramdisk"
Returns a new instance of the class.
read
$arch->read("archive.tgz");
read() opens the given tarball, expands it into a temporary directory
and returns 1 on success or "undef" on failure. The temporary directory
holding the tar data gets cleaned up when $arch goes out of scope.
"read" 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 tar file.
If only a limited number of files is needed from a tarball, they can be
specified after the tarball name:
$arch->read("archive.tgz", "path/file.dat", "path/sub/another.txt");
The file names are passed unmodified to the "tar" command, make sure
that the file paths match exactly what's in the tarball, otherwise
read() will fail.
list_reset
$arch->list_reset()
Resets the list iterator. To be used before the first call to
list_next().
tardir
$arch->tardir();
Return the directory the tarball was unpacked in. This is sometimes
useful to play dirty tricks on Archive::Tar::Wrapper by
mass-manipulating unpacked files before wrapping them back up into the
tarball.
is_compressed
Returns a string to identify if the tarball is compressed or not.
Expect as parameter a string with the path to the tarball.
Returns:
* a "z" character if the file is compressed with "gzip".
* a "j" character if the file is compressed with "bzip2".
* a "" character if the file is not compressed at all.
locate
$arch->locate($logic_path);
Finds the physical location of a file, specified by $logic_path, which
is the virtual path of the file within the tarball. Returns a path to
the temporary file Archive::Tar::Wrapper created to manipulate the
tarball on disk.
add
$arch->add($logic_path, $file_or_stringref, [$options]);
Add a new file to the tarball. $logic_path is the virtual path of the
file within the tarball. $file_or_stringref 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.
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:
$arch->add($logic_path, $stringref,
( run in 1.667 second using v1.01-cache-2.11-cpan-39bf76dae61 )