.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Archive::Extract 3" .TH Archive::Extract 3 2024-09-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Archive::Extract \- A generic archive extracting mechanism .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Archive::Extract; \& \& ### build an Archive::Extract object ### \& my $ae = Archive::Extract\->new( archive => \*(Aqfoo.tgz\*(Aq ); \& \& ### extract to cwd() ### \& my $ok = $ae\->extract; \& \& ### extract to /tmp ### \& my $ok = $ae\->extract( to => \*(Aq/tmp\*(Aq ); \& \& ### 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 .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Archive::Extract is a generic archive extraction mechanism. .PP 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. .PP See the \f(CW\*(C`HOW IT WORKS\*(C'\fR section further down for details. .SH METHODS .IX Header "METHODS" .ie n .SS "$ae = Archive::Extract\->new(archive => '/path/to/archive',[type => TYPE])" .el .SS "\f(CW$ae\fP = Archive::Extract\->new(archive => '/path/to/archive',[type => TYPE])" .IX Subsection "$ae = Archive::Extract->new(archive => '/path/to/archive',[type => TYPE])" Creates a new \f(CW\*(C`Archive::Extract\*(C'\fR 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 \&\f(CW\*(C`type\*(C'\fR argument, potentially by calling \f(CWtype_for()\fR. .PP Valid values for \f(CW\*(C`type\*(C'\fR are: .IP tar 4 .IX Item "tar" Standard tar files, as produced by, for example, \f(CW\*(C`/bin/tar\*(C'\fR. Corresponds to a \f(CW\*(C`.tar\*(C'\fR suffix. .IP tgz 4 .IX Item "tgz" Gzip compressed tar files, as produced by, for example \f(CW\*(C`/bin/tar \-z\*(C'\fR. Corresponds to a \f(CW\*(C`.tgz\*(C'\fR or \f(CW\*(C`.tar.gz\*(C'\fR suffix. .IP gz 4 .IX Item "gz" Gzip compressed file, as produced by, for example \f(CW\*(C`/bin/gzip\*(C'\fR. Corresponds to a \f(CW\*(C`.gz\*(C'\fR suffix. .IP Z 4 .IX Item "Z" Lempel-Ziv compressed file, as produced by, for example \f(CW\*(C`/bin/compress\*(C'\fR. Corresponds to a \f(CW\*(C`.Z\*(C'\fR suffix. .IP zip 4 .IX Item "zip" Zip compressed file, as produced by, for example \f(CW\*(C`/bin/zip\*(C'\fR. Corresponds to a \f(CW\*(C`.zip\*(C'\fR, \f(CW\*(C`.jar\*(C'\fR or \f(CW\*(C`.par\*(C'\fR suffix. .IP bz2 4 .IX Item "bz2" Bzip2 compressed file, as produced by, for example, \f(CW\*(C`/bin/bzip2\*(C'\fR. Corresponds to a \f(CW\*(C`.bz2\*(C'\fR suffix. .IP tbz 4 .IX Item "tbz" Bzip2 compressed tar file, as produced by, for example \f(CW\*(C`/bin/tar \-j\*(C'\fR. Corresponds to a \f(CW\*(C`.tbz\*(C'\fR or \f(CW\*(C`.tar.bz2\*(C'\fR suffix. .IP lzma 4 .IX Item "lzma" Lzma compressed file, as produced by \f(CW\*(C`/bin/lzma\*(C'\fR. Corresponds to a \f(CW\*(C`.lzma\*(C'\fR suffix. .IP xz 4 .IX Item "xz" Xz compressed file, as produced by \f(CW\*(C`/bin/xz\*(C'\fR. Corresponds to a \f(CW\*(C`.xz\*(C'\fR suffix. .IP txz 4 .IX Item "txz" Xz compressed tar file, as produced by, for example \f(CW\*(C`/bin/tar \-J\*(C'\fR. Corresponds to a \f(CW\*(C`.txz\*(C'\fR or \f(CW\*(C`.tar.xz\*(C'\fR suffix. .PP Returns a \f(CW\*(C`Archive::Extract\*(C'\fR object on success, or false on failure. .ie n .SS "$ae\->extract( [to => '/output/path'] )" .el .SS "\f(CW$ae\fP\->extract( [to => '/output/path'] )" .IX Subsection "$ae->extract( [to => '/output/path'] )" Extracts the archive represented by the \f(CW\*(C`Archive::Extract\*(C'\fR object to the path of your choice as specified by the \f(CW\*(C`to\*(C'\fR argument. Defaults to \&\f(CWcwd()\fR. .PP Since \f(CW\*(C`.gz\*(C'\fR files never hold a directory, but only a single file; if the \f(CW\*(C`to\*(C'\fR argument is an existing directory, the file is extracted there, with its \f(CW\*(C`.gz\*(C'\fR suffix stripped. If the \f(CW\*(C`to\*(C'\fR argument is not an existing directory, the \f(CW\*(C`to\*(C'\fR argument is understood to be a filename, if the archive type is \f(CW\*(C`gz\*(C'\fR. In the case that you did not specify a \f(CW\*(C`to\*(C'\fR argument, the output file will be the name of the archive file, stripped from its \f(CW\*(C`.gz\*(C'\fR suffix, in the current working directory. .PP \&\f(CW\*(C`extract\*(C'\fR will try a pure perl solution first, and then fall back to commandline tools if they are available. See the \f(CW\*(C`GLOBAL VARIABLES\*(C'\fR section below on how to alter this behaviour. .PP It will return true on success, and false on failure. .PP On success, it will also set the follow attributes in the object: .ie n .IP $ae\->extract_path 4 .el .IP \f(CW$ae\fR\->extract_path 4 .IX Item "$ae->extract_path" This is the directory that the files where extracted to. .ie n .IP $ae\->files 4 .el .IP \f(CW$ae\fR\->files 4 .IX Item "$ae->files" This is an array ref with the paths of all the files in the archive, relative to the \f(CW\*(C`to\*(C'\fR argument you specified. To get the full path to an extracted file, you would use: .Sp .Vb 1 \& File::Spec\->catfile( $to, $ae\->files\->[0] ); .Ve .Sp Note that all files from a tar archive will be in unix format, as per the tar specification. .SH ACCESSORS .IX Header "ACCESSORS" .ie n .SS $ae\->error([BOOL]) .el .SS \f(CW$ae\fP\->error([BOOL]) .IX Subsection "$ae->error([BOOL])" Returns the last encountered error as string. Pass it a true value to get the \f(CWCarp::longmess()\fR output instead. .ie n .SS $ae\->extract_path .el .SS \f(CW$ae\fP\->extract_path .IX Subsection "$ae->extract_path" This is the directory the archive got extracted to. See \f(CWextract()\fR for details. .ie n .SS $ae\->files .el .SS \f(CW$ae\fP\->files .IX Subsection "$ae->files" This is an array ref holding all the paths from the archive. See \f(CWextract()\fR for details. .ie n .SS $ae\->archive .el .SS \f(CW$ae\fP\->archive .IX Subsection "$ae->archive" This is the full path to the archive file represented by this \&\f(CW\*(C`Archive::Extract\*(C'\fR object. .ie n .SS $ae\->type .el .SS \f(CW$ae\fP\->type .IX Subsection "$ae->type" This is the type of archive represented by this \f(CW\*(C`Archive::Extract\*(C'\fR object. See accessors below for an easier way to use this. See the \f(CWnew()\fR method for details. .ie n .SS $ae\->types .el .SS \f(CW$ae\fP\->types .IX Subsection "$ae->types" Returns a list of all known \f(CW\*(C`types\*(C'\fR for \f(CW\*(C`Archive::Extract\*(C'\fR's \&\f(CW\*(C`new\*(C'\fR method. .ie n .SS $ae\->is_tgz .el .SS \f(CW$ae\fP\->is_tgz .IX Subsection "$ae->is_tgz" Returns true if the file is of type \f(CW\*(C`.tar.gz\*(C'\fR. See the \f(CWnew()\fR method for details. .ie n .SS $ae\->is_tar .el .SS \f(CW$ae\fP\->is_tar .IX Subsection "$ae->is_tar" Returns true if the file is of type \f(CW\*(C`.tar\*(C'\fR. See the \f(CWnew()\fR method for details. .ie n .SS $ae\->is_gz .el .SS \f(CW$ae\fP\->is_gz .IX Subsection "$ae->is_gz" Returns true if the file is of type \f(CW\*(C`.gz\*(C'\fR. See the \f(CWnew()\fR method for details. .ie n .SS $ae\->is_Z .el .SS \f(CW$ae\fP\->is_Z .IX Subsection "$ae->is_Z" Returns true if the file is of type \f(CW\*(C`.Z\*(C'\fR. See the \f(CWnew()\fR method for details. .ie n .SS $ae\->is_zip .el .SS \f(CW$ae\fP\->is_zip .IX Subsection "$ae->is_zip" Returns true if the file is of type \f(CW\*(C`.zip\*(C'\fR. See the \f(CWnew()\fR method for details. .ie n .SS $ae\->is_lzma .el .SS \f(CW$ae\fP\->is_lzma .IX Subsection "$ae->is_lzma" Returns true if the file is of type \f(CW\*(C`.lzma\*(C'\fR. See the \f(CWnew()\fR method for details. .ie n .SS $ae\->is_xz .el .SS \f(CW$ae\fP\->is_xz .IX Subsection "$ae->is_xz" Returns true if the file is of type \f(CW\*(C`.xz\*(C'\fR. See the \f(CWnew()\fR method for details. .ie n .SS $ae\->bin_tar .el .SS \f(CW$ae\fP\->bin_tar .IX Subsection "$ae->bin_tar" Returns the full path to your tar binary, if found. .ie n .SS $ae\->bin_gzip .el .SS \f(CW$ae\fP\->bin_gzip .IX Subsection "$ae->bin_gzip" Returns the full path to your gzip binary, if found .ie n .SS $ae\->bin_unzip .el .SS \f(CW$ae\fP\->bin_unzip .IX Subsection "$ae->bin_unzip" Returns the full path to your unzip binary, if found .ie n .SS $ae\->bin_unlzma .el .SS \f(CW$ae\fP\->bin_unlzma .IX Subsection "$ae->bin_unlzma" Returns the full path to your unlzma binary, if found .ie n .SS $ae\->bin_unxz .el .SS \f(CW$ae\fP\->bin_unxz .IX Subsection "$ae->bin_unxz" Returns the full path to your unxz binary, if found .ie n .SS "$bool = $ae\->have_old_bunzip2" .el .SS "\f(CW$bool\fP = \f(CW$ae\fP\->have_old_bunzip2" .IX Subsection "$bool = $ae->have_old_bunzip2" Older versions of \f(CW\*(C`/bin/bunzip2\*(C'\fR, from before the \f(CW\*(C`bunzip2 1.0\*(C'\fR release, require all archive names to end in \f(CW\*(C`.bz2\*(C'\fR or it will not extract them. This method checks if you have a recent version of \f(CW\*(C`bunzip2\*(C'\fR that allows any extension, or an older one that doesn't. .SS "debug( MESSAGE )" .IX Subsection "debug( MESSAGE )" This method outputs MESSAGE to the default filehandle if \f(CW$DEBUG\fR is true. It's a small method, but it's here if you'd like to subclass it so you can so something else with any debugging output. .SH "UTILITY FUNCTION" .IX Header "UTILITY FUNCTION" .SS type_for($archive) .IX Subsection "type_for($archive)" Given an archive file name, it determins the type by parsing the file name extension. Used by \f(CWnew()\fR when the \f(CW\*(C`type\*(C'\fR 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: .PP .Vb 4 \& my $ae = Archive::Extract\->new( \& archive => \*(Aq/tmp/02af6s\*(Aq, \& type => Archive::Extract::type_for(\*(Aqarchive.zip\*(Aq), \& ); .Ve .SH "HOW IT WORKS" .IX Header "HOW IT WORKS" \&\f(CW\*(C`Archive::Extract\*(C'\fR 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 \f(CW\*(C`CAVEATS\*(C'\fR below. .PP 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 \f(CW\*(C`GLOBAL VARIABLES\*(C'\fR to see how to alter this order. .SH CAVEATS .IX Header "CAVEATS" .SS "File Extensions" .IX Subsection "File Extensions" \&\f(CW\*(C`Archive::Extract\*(C'\fR 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 \&\f(CWnew()\fR method, you will have to specify the type explicitly, or \&\f(CW\*(C`Archive::Extract\*(C'\fR will not be able to extract the archive for you. .SS "Supporting Very Large Files" .IX Subsection "Supporting Very Large Files" \&\f(CW\*(C`Archive::Extract\*(C'\fR can use either pure perl modules or command line programs under the hood. Some of the pure perl modules (like \&\f(CW\*(C`Archive::Tar\*(C'\fR 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 \f(CW$Archive::Extract::PREFER_BIN\fR to \f(CW1\fR, which will prefer the use of command line programs and won't consume so much memory. .PP See the \f(CW\*(C`GLOBAL VARIABLES\*(C'\fR section below for details. .SS "Bunzip2 support of arbitrary extensions." .IX Subsection "Bunzip2 support of arbitrary extensions." Older versions of \f(CW\*(C`/bin/bunzip2\*(C'\fR do not support arbitrary file extensions and insist on a \f(CW\*(C`.bz2\*(C'\fR 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 \f(CW\*(C`have_old_bunzip2\*(C'\fR method. .SH "GLOBAL VARIABLES" .IX Header "GLOBAL VARIABLES" .ie n .SS $Archive::Extract::DEBUG .el .SS \f(CW$Archive::Extract::DEBUG\fP .IX Subsection "$Archive::Extract::DEBUG" Set this variable to \f(CW\*(C`true\*(C'\fR to have all calls to command line tools be printed out, including all their output. This also enables \f(CW\*(C`Carp::longmess\*(C'\fR errors, instead of the regular \&\f(CW\*(C`carp\*(C'\fR errors. .PP Good for tracking down why things don't work with your particular setup. .PP Defaults to \f(CW\*(C`false\*(C'\fR. .ie n .SS $Archive::Extract::WARN .el .SS \f(CW$Archive::Extract::WARN\fP .IX Subsection "$Archive::Extract::WARN" This variable controls whether errors encountered internally by \&\f(CW\*(C`Archive::Extract\*(C'\fR should be \f(CW\*(C`carp\*(C'\fR'd or not. .PP Set to false to silence warnings. Inspect the output of the \f(CWerror()\fR method manually to see what went wrong. .PP Defaults to \f(CW\*(C`true\*(C'\fR. .ie n .SS $Archive::Extract::PREFER_BIN .el .SS \f(CW$Archive::Extract::PREFER_BIN\fP .IX Subsection "$Archive::Extract::PREFER_BIN" This variables controls whether \f(CW\*(C`Archive::Extract\*(C'\fR should prefer the use of perl modules, or commandline tools to extract archives. .PP Set to \f(CW\*(C`true\*(C'\fR to have \f(CW\*(C`Archive::Extract\*(C'\fR prefer commandline tools. .PP Defaults to \f(CW\*(C`false\*(C'\fR. .SH "TODO / CAVEATS" .IX Header "TODO / CAVEATS" .IP "Mime magic support" 4 .IX Item "Mime magic support" Maybe this module should use something like \f(CW\*(C`File::Type\*(C'\fR to determine the type, rather than blindly trust the suffix. .IP "Thread safety" 4 .IX Item "Thread safety" Currently, \f(CW\*(C`Archive::Extract\*(C'\fR does a \f(CW\*(C`chdir\*(C'\fR to the extraction dir before extraction, and a \f(CW\*(C`chdir\*(C'\fR back again after. This is not necessarily thread safe. See \f(CW\*(C`rt.cpan.org\*(C'\fR bug \f(CW\*(C`#45671\*(C'\fR for details. .SH "BUG REPORTS" .IX Header "BUG REPORTS" Please report bugs or other issues to . .SH AUTHOR .IX Header "AUTHOR" This module by Jos Boumans . .SH COPYRIGHT .IX Header "COPYRIGHT" This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.