Archive::Tar::File - a subclass for in-memory extracted file from Archive::Tar
| Use Case | Command | Description |
|---|---|---|
| π Create from file | Archive::Tar::File->new( file => $path ) | π§© Create a new object from an existing file |
| π Create from data | Archive::Tar::File->new( data => $path, $data, $opt ) | π§© Create a new object from in-memory data |
| π¦ Create from raw chunk | Archive::Tar::File->new( chunk => $chunk ) | π§© Create a new object from a raw 512-byte tar header chunk |
| π€ Extract file | $file->extract( [ $alternative_name ] ) | π¦ Extract the file to disk |
| π Get content | $file->get_content | π Return the file's content as a string |
| π Get content by reference | $file->get_content_by_ref | π Return the file's content as a scalar reference (memory efficient) |
| βοΈ Replace content | $file->replace_content( $content ) | π Replace the in-memory content of the file |
| βοΈ Rename file | $file->rename( $new_name ) | π·οΈ Rename the file in the archive |
| π Validate checksum | $file->validate | β Verify tar header checksum |
| π Check type | $file->is_file, $file->is_dir, ... | π Check file type (file, dir, symlink, etc.) |
| π Change mode | $file->chmod $mode | π Change file permissions |
| π Change owner | $file->chown( $user [, $group] ) | π€ Change file ownership |
my @items = $tar->get_files;
print $_->name, ' ', $_->size, "\n" for @items;
print $object->get_content;
$object->replace_content('new content');
$object->rename( 'new/full/path/to/file.c' );
Archive::Tar::Files provides a neat little object layer for in-memory extracted files. It's mostly used internally in Archive::Tar to tidy up the code, but there's no reason users shouldn't use this API as well.
A lot of the methods in this package are accessors to the various fields in the tar header:
Archive::Tar::File->new( file => $path )Returns a new Archive::Tar::File object from an existing file. Returns undef on failure.
Archive::Tar::File->new( data => $path, $data, $opt )Returns a new Archive::Tar::File object from data. $path defines the file name (which need not exist), $data the file contents, and $opt is a reference to a hash of attributes which may be used to override the default attributes (fields in the tar header). Returns undef on failure.
Archive::Tar::File->new( chunk => $chunk )Returns a new Archive::Tar::File object from a raw 512-byte tar archive chunk. Returns undef on failure.
$bool = $file->extract( [ $alternative_name ] )Extract this object, optionally to an alternative name. See βArchive::Tar->extract_fileβ for details. Returns true on success and false on failure.
$path = $file->full_pathReturns the full path from the tar header; this is basically a concatenation of the βprefixβ and βnameβ fields.
$bool = $file->validateDone by Archive::Tar internally when reading the tar file: validate the header against the checksum to ensure integer tar file. Returns true on success, false on failure.
$bool = $file->has_contentReturns a boolean to indicate whether the current object has content. Some special files like directories never have content. This method is mainly to avoid warnings for uninitialized values.
$content = $file->get_contentReturns the current content for the in-memory file.
$cref = $file->get_content_by_refReturns the current content for the in-memory file as a scalar reference. Saves memory for large files.
$bool = $file->replace_content( $content )Replace the current content of the file with new content. This only affects the in-memory archive, not the on-disk version until you write it. Returns true on success, false on failure.
$bool = $file->rename( $new_name )Rename the current file to $new_name. Note that you must specify a Unix path. Returns true on success and false on failure.
$bool = $file->chmod $modeChange mode of $file to $mode. The mode can be a string or a number interpreted as octal. Returns true on success and false on failure.
$bool = $file->chown( $user [, $group])Change owner of $file to $user. If a $group is given, that is changed as well. You can also pass a single parameter with a colon separating the user and group (e.g., βroot:wheelβ). Returns true on success and false on failure.
To quickly check the type of a βArchive::Tar::Fileβ object, you can use the following methods:
$file->is_file β π Returns true if the file is of type βfileβ$file->is_dir β π Returns true if the file is of type βdirβ$file->is_hardlink β π Returns true if the file is of type βhardlinkβ$file->is_symlink β π Returns true if the file is of type βsymlinkβ$file->is_chardev β βοΈ Returns true if the file is of type βchardevβ$file->is_blockdev β βοΈ Returns true if the file is of type βblockdevβ$file->is_fifo β π§΅ Returns true if the file is of type βfifoβ$file->is_socket β π Returns true if the file is of type βsocketβ$file->is_longlink β β οΈ Returns true if the file is of type βLongLinkβ. Should not happen after a successful βreadβ.$file->is_label β π·οΈ Returns true if the file is of type βLabelβ. Should not happen after a successful βreadβ.$file->is_unknown β β Returns true if the file type is βunknownβperl v5.34.0 2026-06-23 Archive::Tar::File(3perl)
Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-23 09:05 @216.73.216.102
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)