man > Archive::Extract(3pm)

Archive::Extract(3pm) User Contributed Perl Documentation Archive::Extract(3pm)

๐Ÿ“› NAME

Archive::Extract - A generic archive extracting mechanism

๐Ÿš€ Quick Reference

Use CaseCommandDescription
Create extractor objectmy $ae = Archive::Extract->new( archive => 'file.tar.gz' );Auto-detects type from extension
Extract to current directory$ae->extract;Extracts archive to cwd()
Extract to specific path$ae->extract( to => '/tmp' );Extract to given directory
Handle extraction errors$ae->extract or die $ae->error;Die with error message on failure
List files in archivemy @files = @{ $ae->files };Array ref of file paths
Get extraction directorymy $outdir = $ae->extract_path;Path where files were extracted
Determine type from filenamemy $type = Archive::Extract->type_for('file.zip');Returns type string based on extension
Check if archive is .tgz$ae->is_tgz;True/false for .tar.gz

๐Ÿ“– SYNOPSIS

use Archive::Extract;

### build an Archive::Extract object ###
my $ae = Archive::Extract->new( archive => 'foo.tgz' );

### extract to cwd() ###
my $ok = $ae->extract;

### extract to /tmp ###
my $ok = $ae->extract( to => '/tmp' );

### what if something went wrong?
my $ok = $ae->extract or die $ae->error;

### files from the archive ###
my $files   = $ae->files;

### dir that was extracted to ###
my $outdir  = $ae->extract_path;


### quick check methods ###
$ae->is_tar     # is it a .tar file?
$ae->is_tgz     # is it a .tar.gz or .tgz file?
$ae->is_gz;     # is it a .gz file?
$ae->is_zip;    # is it a .zip file?
$ae->is_bz2;    # is it a .bz2 file?
$ae->is_tbz;    # is it a .tar.bz2 or .tbz file?
$ae->is_lzma;   # is it a .lzma file?
$ae->is_xz;     # is it a .xz file?
$ae->is_txz;    # is it a .tar.xz or .txz file?

### absolute path to the archive you provided ###
$ae->archive;

### commandline tools, if found ###
$ae->bin_tar     # path to /bin/tar, if found
$ae->bin_gzip    # path to /bin/gzip, if found
$ae->bin_unzip   # path to /bin/unzip, if found
$ae->bin_bunzip2 # path to /bin/bunzip2 if found
$ae->bin_unlzma  # path to /bin/unlzma if found
$ae->bin_unxz    # path to /bin/unxz if found

๐Ÿ“˜ DESCRIPTION

Archive::Extract is a generic archive extraction mechanism.

It allows you to extract any archive file of the type .tar, .tar.gz, .gz, .Z, tar.bz2, .tbz, .bz2, .zip, .xz,, .txz, .tar.xz or .lzma without having to worry how it does so, or use different interfaces for each type by using either perl modules, or commandline tools on your system.

See the โ€œHOW IT WORKSโ€ section further down for details.

๐Ÿ”ง METHODS

๐Ÿ—๏ธ $ae = Archive::Extract->new( archive => '/path/to/archive', [type => TYPE] )

Creates a new โ€œArchive::Extractโ€ object based on the archive file you passed it. Automatically determines the type of archive based on the extension, but you can override that by explicitly providing the โ€œtypeโ€ argument, potentially by calling type_for().

Valid values for โ€œtypeโ€ are:

Returns a โ€œArchive::Extractโ€ object on success, or false on failure.

๐Ÿ“ค $ae->extract( [to => '/output/path'] )

Extracts the archive represented by the Archive::Extract object to the path of your choice as specified by the โ€œtoโ€ argument. Defaults to cwd().

Since โ€œ.gzโ€ files never hold a directory, but only a single file; if the โ€œtoโ€ argument is an existing directory, the file is extracted there, with its โ€œ.gzโ€ suffix stripped. If the โ€œtoโ€ argument is not an existing directory, the โ€œtoโ€ argument is understood to be a filename, if the archive type is โ€œgzโ€. In the case that you did not specify a โ€œtoโ€ argument, the output file will be the name of the archive file, stripped from its โ€œ.gzโ€ suffix, in the current working directory.

extract will try a pure perl solution first, and then fall back to commandline tools if they are available. See the โ€œGLOBAL VARIABLESโ€ section below on how to alter this behaviour.

It will return true on success, and false on failure.

On success, it will also set the follow attributes in the object:

๐Ÿ” ACCESSORS

๐Ÿ› ๏ธ UTILITY FUNCTION

type_for($archive)

Given an archive file name, it determines the type by parsing the file name extension. Used by โ€œnew()โ€ when the โ€œtypeโ€ parameter is not passed. Also useful when the archive file does not include a suffix but the file name is otherwise known, such as when a file is uploaded to a web server and stored with a temporary name that differs from the original name, and you want to use the same detection pattern as Archive::Extract. Example:

my $ae = Archive::Extract->new(
    archive => '/tmp/02af6s',
    type    => Archive::Extract::type_for('archive.zip'),
);

โš™๏ธ HOW IT WORKS

โ€œArchive::Extractโ€ tries first to determine what type of archive you are passing it, by inspecting its suffix. It does not do this by using Mime magic, or something related. See โ€œCAVEATSโ€ below.

Once it has determined the file type, it knows which extraction methods it can use on the archive. It will try a perl solution first, then fall back to a commandline tool if that fails. If that also fails, it will return false, indicating it was unable to extract the archive. See the section on โ€œGLOBAL VARIABLESโ€ to see how to alter this order.

โš ๏ธ CAVEATS

๐Ÿ“ File Extensions

โ€œArchive::Extractโ€ trusts on the extension of the archive to determine what type it is, and what extractor methods therefore can be used. If your archives do not have any of the extensions as described in the โ€œnew()โ€ method, you will have to specify the type explicitly, or โ€œArchive::Extractโ€ will not be able to extract the archive for you.

๐Ÿ“ฆ Supporting Very Large Files

โ€œArchive::Extractโ€ can use either pure perl modules or command line programs under the hood. Some of the pure perl modules (like โ€œArchive::Tarโ€ and Compress::unLZMA) take the entire contents of the archive into memory, which may not be feasible on your system. Consider setting the global variable $Archive::Extract::PREFER_BIN to 1, which will prefer the use of command line programs and wonโ€™t consume so much memory.

See the โ€œGLOBAL VARIABLESโ€ section below for details.

๐Ÿฐ Bunzip2 support of arbitrary extensions

Older versions of /bin/bunzip2 do not support arbitrary file extensions and insist on a โ€œ.bz2โ€ suffix. Although we do our best to guard against this, if you experience a bunzip2 error, it may be related to this. For details, please see the โ€œhave_old_bunzip2โ€ method.

๐ŸŒ GLOBAL VARIABLES

๐Ÿ› $Archive::Extract::DEBUG

Set this variable to true to have all calls to command line tools be printed out, including all their output. This also enables Carp::longmess errors, instead of the regular carp errors.

Good for tracking down why things donโ€™t work with your particular setup.

Defaults to false.

โš ๏ธ $Archive::Extract::WARN

This variable controls whether errors encountered internally by โ€œArchive::Extractโ€ should be carpโ€™d or not.

Set to false to silence warnings. Inspect the output of the error() method manually to see what went wrong.

Defaults to true.

๐Ÿ”ง $Archive::Extract::PREFER_BIN

This variable controls whether โ€œArchive::Extractโ€ should prefer the use of perl modules, or commandline tools to extract archives.

Set to true to have โ€œArchive::Extractโ€ prefer commandline tools.

Defaults to false.

๐Ÿ“ TODO / CAVEATS

๐Ÿ”ฎ Mime magic support

Maybe this module should use something like โ€œFile::Typeโ€ to determine the type, rather than blindly trust the suffix.

๐Ÿงต Thread safety

Currently, โ€œArchive::Extractโ€ does a chdir to the extraction dir before extraction, and a chdir back again after. This is not necessarily thread safe. See โ€œrt.cpan.orgโ€ bug โ€œ#45671โ€ for details.

๐Ÿž BUG REPORTS

Please report bugs or other issues to <bug-archive-extract AT rt.org>.

๐Ÿ‘ค AUTHOR

This module by Jos Boumans <kane AT cpan.org>.

ยฉ๏ธ COPYRIGHT

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

perl v5.32.1 2021-09-25 Archive::Extract(3pm)

Archive::Extract(3pm)
๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ“– SYNOPSIS ๐Ÿ“˜ DESCRIPTION ๐Ÿ”ง METHODS
๐Ÿ—๏ธ $ae = Archive::Extract->new( archive => '/path/to/archive', [type => TYPE] ) ๐Ÿ“ค $ae->extract( [to => '/output/path'] )
๐Ÿ” ACCESSORS ๐Ÿ› ๏ธ UTILITY FUNCTION โš™๏ธ HOW IT WORKS โš ๏ธ CAVEATS
๐Ÿ“ File Extensions ๐Ÿ“ฆ Supporting Very Large Files ๐Ÿฐ Bunzip2 support of arbitrary extensions
๐ŸŒ GLOBAL VARIABLES
๐Ÿ› $Archive::Extract::DEBUG โš ๏ธ $Archive::Extract::WARN ๐Ÿ”ง $Archive::Extract::PREFER_BIN
๐Ÿ“ TODO / CAVEATS
๐Ÿ”ฎ Mime magic support ๐Ÿงต Thread safety
๐Ÿž BUG REPORTS ๐Ÿ‘ค AUTHOR ยฉ๏ธ COPYRIGHT

Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-10 08:29 @216.73.216.58
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^