Archive-Libarchive-FFI
view release on metacpan or search on metacpan
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::FFI 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::FFI 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);
DESCRIPTION
NOTE: This module has been deprecated in favor of Archive::Libarchive.
It provides a better thought out object-oriented interface and is
easier to maintain.
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:
Archive::Libarchive::FFI
This document, contains an overview and some examples.
Archive::Libarchive::FFI::Callback
Documents the callback interface, used for customizing input and
output.
Archive::Libarchive::FFI::Constant
Documents the constants provided by this module.
Archive::Libarchive::FFI::Function
The function reference, includes a list of all functions provided by
this module.
If you are linking against an older version of libarchive, some
functions and constants may not be available. You can use the can
method to test if a function or constant is available, for example:
if(Archive::Libarchive::FFI->can('archive_read_support_filter_grzip')
{
# grzip filter is available.
}
if(Archive::Libarchive::FFI->can('ARCHIVE_OK'))
{
# ... although ARCHIVE_OK should always be available.
}
EXAMPLES
These examples are translated from equivalent C versions provided on
the libarchive website, and are annotated here with Perl specific
details. These examples are also included with the distribution.
( run in 1.888 second using v1.01-cache-2.11-cpan-99c4e6809bf )