# man > Archive::Extract

---
type: CommandReference
command: Archive::Extract
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference

- `$ae = Archive::Extract->new(archive => 'file.tgz')` — create object from archive
- `$ae->extract(to => '/tmp')` — extract archive to directory
- `$ae->extract or die $ae->error` — extract with error handling
- `$ae->files` — list files in archive
- `$ae->extract_path` — directory where extracted
- `$ae->is_tgz` — check if archive is .tar.gz
- `$ae->bin_tar` — path to tar binary
- `Archive::Extract::type_for('archive.zip')` — determine type from filename

## Name

[Archive::Extract](http://localhost/phpMan.php/perldoc/Archive%3A%3AExtract/markdown) — A generic archive extracting mechanism

## Synopsis

perl
use Archive::Extract;

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

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

$ae->extract or die $ae->error;

my $files  = $ae->files;
my $outdir = $ae->extract_path;
## Options

### Constructor

- `$ae = Archive::Extract->new(archive => '/path/to/archive', [type => TYPE])` — creates a new object. Automatically determines type from extension; override with `type`. Valid types: tar, tgz, gz, Z, zip, bz2, tbz, lzma, xz, txz.

### Extraction

- `$ae->extract([to => '/output/path'])` — extracts archive. Returns true on success, false on failure. Sets `$ae->extract_path` and `$ae->files`.

### Accessors

- `$ae->error([BOOL])` — returns last error string; pass true for `Carp::longmess` output.
- `$ae->extract_path` — directory where files were extracted.
- `$ae->files` — arrayref of file paths relative to extraction directory.
- `$ae->archive` — full path to the archive file.
- `$ae->type` — archive type as string.
- `$ae->types` — list of all known types.

### Type Check Methods

- `$ae->is_tar` — true if .tar
- `$ae->is_tgz` — true if .tar.gz/.tgz
- `$ae->is_gz` — true if .gz
- `$ae->is_Z` — true if .Z
- `$ae->is_zip` — true if .zip
- `$ae->is_bz2` — true if .bz2
- `$ae->is_tbz` — true if .tar.bz2/.tbz
- `$ae->is_lzma` — true if .lzma
- `$ae->is_xz` — true if .xz
- `$ae->is_txz` — true if .tar.xz/.txz

### Binary Path Methods

- `$ae->bin_tar` — path to tar binary (if found)
- `$ae->bin_gzip` — path to gzip
- `$ae->bin_unzip` — path to unzip
- `$ae->bin_bunzip2` — path to bunzip2
- `$ae->bin_unlzma` — path to unlzma
- `$ae->bin_unxz` — path to unxz
- `$ae->have_old_bunzip2` — check if bunzip2 is old (requires .bz2 extension)

### Utility

- `$ae->debug(MESSAGE)` — outputs message if `$DEBUG` is true.
- `Archive::Extract::type_for($archive)` — determines type from filename extension.

## Examples

**Basic extraction:**

perl
use Archive::Extract;

my $ae = Archive::Extract->new(archive => 'project.tar.gz');
$ae->extract(to => '/tmp/project') or die $ae->error;
print "Extracted to: $ae->extract_path\n";
print "Files: @{$ae->files}\n";
**Handling .gz files (single file):**

perl
my $ae = Archive::Extract->new(archive => 'readme.gz');
$ae->extract;  # extracts to 'readme' in cwd()
$ae->extract(to => '/tmp/readme.txt');  # extracts to specified filename
**Using type detection for temporary files:**

perl
my $ae = Archive::Extract->new(
    archive => '/tmp/upload_XXXX',
    type    => Archive::Extract::type_for('original.zip'),
);
## See Also

- [Archive::Tar](http://localhost/phpMan.php/perldoc/Archive%3A%3ATar/markdown)
- [Archive::Zip](http://localhost/phpMan.php/perldoc/Archive%3A%3AZip/markdown)
- [Compress::Zlib](http://localhost/phpMan.php/perldoc/Compress%3A%3AZlib/markdown)
- [File::Spec](http://localhost/phpMan.php/perldoc/File%3A%3ASpec/markdown)

## Exit Codes

Not documented.