Archive::Ar(3pm)
π NAME π
hey bestie π so this whole page is about Archive::Ar β the Perl module that is literally your Interface for manipulating ar archives. that's the whole job, and it slays at it π
β¨
β¨ SYNOPSIS β¨
okay look at this gorgeous lil routine, no edits, exactly as written:
use Archive::Ar;
my $ar = Archive::Ar->new;
$ar->read('./foo.ar');
$ar->extract;
$ar->add_files('./bar.tar.gz', 'bat.pl')
$ar->add_data('newfile.txt','Some contents');
$ar->chmod('file1', 0644);
$ar->chown('file1', $uid, $gid);
$ar->remove('file1', 'file2');
my $filehash = $ar->get_content('bar.tar.gz');
my $data = $ar->get_data('bar.tar.gz');
my $handle = $ar->get_handle('bar.tar.gz');
my @files = $ar->list_files();
my $archive = $ar->write;
my $size = $ar->write('outbound.ar');
$ar->error();
π DESCRIPTION π
so Archive::Ar is a pure-perl way to handle standard ar archives π«Ά
why do you care, bestie? two reasons, and both are iconic:
- if you've got those types of archives chillin' on your system, this handles them β¨
- ALSO β and this is the main character moment β
.debpackages for the Debian GNU/Linux distribution areararchives. yes fr fr π
it's one building block in a future chain of modules to build, manipulate, extract, and test debian modules with no platform or architecture dependence π¦
and if the API feels familiar? not a coincidence, babes. the API to Archive::Ar is similar to Archive::Tar, and that was done intentionally to keep similarity between the Archive::* modules. consistency ate π
π§ METHODS π§
new π±
$ar = Archive::Ar->new()
$ar = Archive::Ar->new($filename)
$ar = Archive::Ar->new($filehandle)
returns a brand new Archive::Ar object π
- pass nothing? you get an empty object, a blank canvas, main character energy β
- pass a filename or an open filehandle? it reads the referenced archive into memory π§
- if the read fails for any reason, it returns
undefπ
set_opt βοΈ
$ar->set_opt($name, $val)
assigns option $name the value $val. here's the whole menu of possible options:
warnβ warning level. levels arezerofor no warnings,1for brief warnings, and2for warnings with a stack trace. default iszeroπchmodβ change the file permissions of files created when extracting. default is true (non-zero) βsame_permsβ when setting file permissions, use the values in the archive unchanged. if false, it removessetuidbits and applies the user'sumask. default istruefor therootuser,falseotherwise πchownβ change the owners of extracted files, if possible. default istrueπ«Άtypeβ archive type. may beGNU,BSDorCOMMON, orundefif no archive has been read. defaults to the type of the archive read, orundefπ·οΈsymbolsβ provide a filename for the symbol table, if present. if set, the symbol table is treated as a file that can be read from or written to an archive. it is an error if the filename provided matches the name of a file in the archive π¨. if undefined, the symbol table is ignored. defaults toundef
get_opt π
$val = $ar->get_opt($name)
returns the value of option $name. that's it, that's the whole thing π
type π·οΈ
$type = $ar->type()
returns the type of the ar archive. the type is undefined until an archive is loaded π«₯
- looks like a
gnu-style archive βGNUcomes back - looks like a
bsd-style archive βBSDcomes back - otherwise β
COMMONcomes back
heads up bestie: unless filenames exceed 16 characters in length,bsdarchives look like the common format π so don't come for the module when it saysCOMMON, it warned you
clear π§Ή
$ar->clear()
clears the current in-memory archive. poof, gone, fresh start πΈ
read π
$len = $ar->read($filename)
$len = $ar->read($filehandle)
this reads a new file into the object, removing any ar archive already represented in the object. the argument may be a filename, filehandle or IO::Handle object π₯
returns the size of the file contents, or undef if it fails π
read_memory π§
$len = $ar->read_memory($data)
parses the string argument as an archive, reading it into memory. replaces any previously loaded archive π«‘
returns the number of bytes read, or undef if it fails π
contains_file β
$bool = $ar->contains_file($filename)
returns true if the archive contains a file with $filename. returns undef otherwise π
extract π¦
$ar->extract()
$ar->extract_file($filename)
extracts files from the archive π
- the first form extracts all the files β go big
- the latter extracts just the named file β selective queen
extracted files are assigned the permissions and modification time stored in the archive, and, if possible, the user and group ownership π
returns non-zero upon success, or undef if failure π
rename βοΈ
$ar->rename($filename, $newname)
changes the name of a file in the in-memory archive. glow-up but for filenames β¨
chmod π§
$ar->chmod($filename, $mode);
change the mode of the member to $mode π
chown π
$ar->chown($filename, $uid, $gid);
$ar->chown($filename, $uid);
change the ownership of the member to user id $uid and (optionally) group id $gid. negative id values are ignored π«
remove ποΈ
$ar->remove(@filenames)
$ar->remove($arrayref)
removes files from the in-memory archive. returns the number of files removed. not me deleting things and getting a count back π
list_files π
@filenames = $ar->list_files()
returns a list of the names of all the files in the archive. if you call it in a scalar context, it returns a reference to an array π (iykyk)
add_files β
$ar->add_files(@filenames)
$ar->add_files($arrayref)
adds files to the archive. the arguments can be paths, but only the filenames are stored in the archive π«Ά
it stores the uid, gid, mode, size, and modification timestamp of the file as returned by stat() π
returns the number of files successfully added, or undef if failure π
add_data βοΈ
$ar->add_data("filename", $data)
$ar->add_data("filename", $data, $options)
adds a file to the in-memory archive with name $filename and content $data. file properties can be set with $optional_hashref:
$options = {
'data' => $data,
'uid' => $uid, #defaults to zero
'gid' => $gid, #defaults to zero
'date' => $date, #date in epoch seconds. Defaults to now.
'mode' => $mode, #defaults to 0100644;
}
π¨ you cannot add_data over another file however. no overwriting, that's the rule bestie
this returns the file length in bytes if it is successful, undef otherwise β¨
write πΎ
$data = $ar->write()
$len = $ar->write($filename)
returns the archive as a string, or writes it to disk as $filename π
returns the archive size upon success when writing to disk. returns undef if failure π
get_content π
$content = $ar->get_content($filename)
this returns a hash with the file content in it, including the data that the file would contain π
if the file does not exist or no filename is given, this returns undef. on success, a hash is returned:
$content = {
'name' => $filename,
'date' => $mtime,
'uid' => $uid,
'gid' => $gid,
'mode' => $mode,
'size' => $size,
'data' => $file_contents,
}
get_data π
$data = $ar->get_data("filename")
returns a scalar containing the file data of the given archive member. upon error, returns undef π
get_handle π£
$handle = $ar->get_handle("filename")>
returns a file handle to the in-memory file data of the given archive member. upon error, returns undef π
this can be useful for unpacking nested archives π¦π¦. uses IO::String if it's loaded β¨
(that lil > at the end of the synopsis line is in the original, we don't touch it, we respect it π
)
error π¨
$errstr = $ar->error($trace)
returns the current error string, which is usually the last error reported. if a true value is provided, returns the error message and stack trace π
π BUGS π
see https://github.com/jbazik/Archive-Ar/issues/ to report and view bugs π«Ά don't be shy, that's literally what it's for
π SOURCE π
the source code repository for Archive::Ar can be found at http://github.com/jbazik/Archive-Ar/ β go look, it's giving open source excellence π
π COPYRIGHT π
Copyright 2009-2014 John Bazik <jbazik@cpan.org>.
Copyright 2003 Jay Bonci <jaybonci@cpan.org>.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself π«Ά
see http://www.perl.com/perl/misc/Artistic.html
and that's the page, bestie π sign-off time: this was perl v5.36.0 and the date on it is 2022-10-13, and yes we are still obsessed with it π
β¨π
π¦ where this page comes from
- ubuntu noble: libarchive-ar-perl 2.02-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libarchive-ar-perl 2.02-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libarchive-ar-perl 2.02-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms