Archive-Libarchive-XS
view release on metacpan or search on metacpan
inc/XS.pm.template view on Meta::CPAN
while(archive_read_next_header($archive, my $entry) == ARCHIVE_OK)
{
print archive_entry_pathname($entry), "\n";
archive_read_data_skip($archive);
}
archive_read_free($archive);
extract archive
use Archive::Libarchive::XS qw( :all );
my $archive = archive_read_new();
archive_read_support_filter_all($archive);
archive_read_support_format_all($archive);
my $disk = archive_write_disk_new();
archive_write_disk_set_options($disk,
ARCHIVE_EXTRACT_TIME |
ARCHIVE_EXTRACT_PERM |
ARCHIVE_EXTRACT_ACL |
ARCHIVE_EXTRACT_FFLAGS
);
archive_write_disk_set_standard_lookup($disk);
archive_read_open_filename($archive, 'archive.tar', 10240);
while(1)
{
my $r = archive_read_next_header($archive, my $entry);
last if $r == ARCHIVE_EOF;
archive_write_header($disk, $entry);
while(1)
{
my $r = archive_read_data_block($archive, my $buffer, my $offset);
last if $r == ARCHIVE_EOF;
archive_write_data_block($disk, $buffer, $offset);
}
}
archive_read_close($archive);
archive_read_free($archive);
archive_write_close($disk);
archive_write_free($disk);
write archive
use File::stat;
use File::Slurp qw( read_file );
use Archive::Libarchive::XS qw( :all );
my $archive = archive_write_new();
# many other formats are supported ...
archive_write_set_format_pax_restricted($archive);
archive_write_open_filename($archive, 'archive.tar');
foreach my $filename (@filenames)
{
my $entry = archive_entry_new();
archive_entry_set_pathname($entry, $filename);
archive_entry_set_size($entry, stat($filename)->size);
archive_entry_set_filetype($entry, AE_IFREG);
archive_entry_set_perm($entry, 0644);
archive_write_header($archive, $entry);
archive_write_data($archive, scalar read_file($filename));
archive_entry_free($entry);
}
archive_write_close($archive);
archive_write_free($archive);
=head1 DESCRIPTION
This module provides a functional interface to libarchive. libarchive is a
C library that can read and write archives in a variety of formats and with a
variety of compression filters, optimized in a stream oriented way. A familiarity
with the libarchive documentation would be helpful, but may not be necessary
for simple tasks. The documentation for this module is split into four separate
documents:
=over 4
=item L<Archive::Libarchive::XS>
This document, contains an overview and some examples.
=item L<Archive::Libarchive::XS::Callback>
Documents the callback interface, used for customizing input and output.
=item L<Archive::Libarchive::XS::Constant>
Documents the constants provided by this module.
=item L<Archive::Libarchive::XS::Function>
The function reference, includes a list of all functions provided by this module.
=back
If you are linking against an older version of libarchive, some functions
and constants may not be available. You can use the C<can> method to test if
a function or constant is available, for example:
if(Archive::Libarchive::XS->can('archive_read_support_filter_grzip')
{
# grzip filter is available.
}
if(Archive::Libarchive::XS->can('ARCHIVE_OK'))
{
# ... although ARCHIVE_OK should always be available.
}
=cut
sub _define_constant ($) {
my($name) = @_;
my $value = eval { _constant($name) };
return if $@;
eval qq{ sub $name() { $value }; 1 };
}
( run in 1.779 second using v1.01-cache-2.11-cpan-5a3173703d6 )