Archive-Libarchive

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

      The constructor does not take any arguments, instead you will
      configure it in the next step.

    Configure it using "support" or "set" calls

      Support calls allow Archive::Libarchive to decide when to use a
      feature; "set" calls enable the feature unconditionally.

    "Open" a particular data source

      This can be using callbacks for a custom source, or one of the
      pre-canned data sources supported directly by Archive::Libarchive.

    Iterate over the contents

      Ask alternatively for "header" or entry/file metadata (which is
      represented by a Archive::Libarchive::Entry instance), and entry/file
      content.

    Finish by calling "close"

README  view on Meta::CPAN

       $r->read_data_skip;
     }

    There are also variants to read from an already-opened file descriptor,
    a libc FILE pointer, or a Perl file handle.

 List contents of archive with custom read functions

    Sometimes, none of the packaged open methods will work for you. In that
    case, you can use the lower-level open method, which accepts a number
    of callbacks. For this example we will use the open, read and close
    callbacks.

     use 5.020;
     use Archive::Libarchive qw( :const );
     
     my $r = Archive::Libarchive::ArchiveRead->new;
     $r->support_filter_all;
     $r->support_format_all;
     
     my $fh;
     

README  view on Meta::CPAN

     while(1) {
       my $ret = $r->next_header($e);
       last if $ret == ARCHIVE_EOF;
       die $r->error_string if $ret < ARCHIVE_WARN;
       warn $r->error_string if $ret != ARCHIVE_OK;
       say $e->pathname;
     }
     
     $r->close;

    For full power of read callbacks see the open method's documentation.

    When writing to an archive the Archive::Libarchive::ArchiveWrite class
    also has its own open method and callbacks.

 A universal decompressor / defilter-er

    The "raw" format handler treats arbitrary binary input as a
    single-element archive. This allows you to get the output of a
    libarchive filter chain, including files with multiple encodings, such
    as gz.uu files:

     use 5.020;
     use Archive::Libarchive;

lib/Archive/Libarchive.pm  view on Meta::CPAN

The constructor does not take any arguments, instead you will configure it in the
next step.

=item Configure it using "support" or "set" calls

Support calls allow L<Archive::Libarchive> to decide when to use a feature; "set" calls
enable the feature unconditionally.

=item "Open" a particular data source

This can be using callbacks for a custom source, or one of the pre-canned data sources supported directly by
L<Archive::Libarchive>.

=item Iterate over the contents

Ask alternatively for "header" or entry/file metadata (which is represented by a L<Archive::Libarchive::Entry> instance),
and entry/file content.

=item Finish by calling "close"

This will be called automatically if the archive instance falls out of scope.

lib/Archive/Libarchive.pm  view on Meta::CPAN

   say $e->pathname;
   $r->read_data_skip;
 }

There are also variants to read from an already-opened file descriptor, a C<libc> C<FILE> pointer, or a Perl
file handle.

=head2 List contents of archive with custom read functions

Sometimes, none of the packaged open methods will work for you.  In that case, you can use the lower-level C<open>
method, which accepts a number of callbacks.  For this example we will use the C<open>, C<read> and C<close>
callbacks.

 use 5.020;
 use Archive::Libarchive qw( :const );
 
 my $r = Archive::Libarchive::ArchiveRead->new;
 $r->support_filter_all;
 $r->support_format_all;
 
 my $fh;
 

lib/Archive/Libarchive.pm  view on Meta::CPAN

 while(1) {
   my $ret = $r->next_header($e);
   last if $ret == ARCHIVE_EOF;
   die $r->error_string if $ret < ARCHIVE_WARN;
   warn $r->error_string if $ret != ARCHIVE_OK;
   say $e->pathname;
 }
 
 $r->close;

For full power of read callbacks see the L<open method's documentation|Archive::Libarchive::ArchiveRead/open>.

When writing to an archive the L<Archive::Libarchive::ArchiveWrite> class also has its own
L<open method and callbacks|Archive::Libarchive::ArchiveWrite/open>.

=head2 A universal decompressor / defilter-er

The "raw" format handler treats arbitrary binary input as a single-element archive.  This allows you to get the
output of a libarchive filter chain, including files with multiple encodings, such as C<gz.uu> files:

 use 5.020;
 use Archive::Libarchive;
 
 my $r = Archive::Libarchive::ArchiveRead->new;

lib/Archive/Libarchive/API.pm  view on Meta::CPAN


=head2 open

 # archive_read_open1
 # archive_read_set_callback_data
 # archive_read_set_close_callback
 # archive_read_set_open_callback
 # archive_read_set_read_callback
 # archive_read_set_seek_callback
 # archive_read_set_skip_callback
 $r->open(%callbacks);

This is a basic open method, which relies on callbacks for its implementation.  The
only callback that is required is the C<read> callback.  The C<open> and C<close>
callbacks are made available mostly for the benefit of the caller.  The C<skip>
and C<seek> callbacks are used if available for some formats like C<zip> to improve
performance.  All callbacks should return a L<normal status code|Archive::Libarchive/CONSTANTS>,
which is C<ARCHIVE_OK> on success.

Unlike the C<libarchive> C-API, this interface doesn't provide a facility for
passing in "client" data.  In Perl this is implemented using a closure, which should
allow you to pass in arbitrary variables via proper scoping.

=over 4

=item open

lib/Archive/Libarchive/API.pm  view on Meta::CPAN

=head2 new

 # archive_write_new
 my $w = Archive::Libarchive::ArchiveWrite->new;

Create a new archive write object.

=head2 open

 # archive_write_open
 $w->open(%callbacks);

This is a basic open method, which relies on callbacks for its implementation.  The
only callback that is required is the C<write> callback.  The C<open> and C<close>
callbacks are made available mostly for the benefit of the caller.  All callbacks
should return a L<normal status code|Archive::Libarchive/CONSTANTS>, which is
C<ARCHIVE_OK> on success.

Unlike the C<libarchive> C-API, this interface doesn't provide a facility for
passing in "client" data.  In Perl this is implemented using a closure, which should
allow you to pass in arbitrary variables via proper scoping.

=over 4

=item open

lib/Archive/Libarchive/ArchiveRead.pm  view on Meta::CPAN

});


my %set_callback = map {
  ($_ => $ffi->function( "set_${_}_callback" => ['archive_read',"archive_${_}_callback"] => 'int' )->sub_ref)
} qw( open close read seek skip );

$ffi->attach( [ set_callback_data => '_set_callback_data' ] => ['archive_read','opaque'] => 'int' );

$ffi->attach( [ open1 => 'open' ] => [ 'archive_read'] => 'int' => sub {
  my($xsub, $self, %callbacks) = @_;

  Carp::croak("The read callback is required") unless $callbacks{read};

  foreach my $name (keys %set_callback)
  {
    my $set = $set_callback{$name};
    my $sub = delete $callbacks{$name};

    unless(defined $sub)
    {
      $set->($self, undef);
      next;
    }

    Carp::croak("Callback for $name is not a code reference") unless is_plain_coderef $sub;

    my $closure;

lib/Archive/Libarchive/ArchiveRead.pm  view on Meta::CPAN

        $r = bless { ptr => $r, cb => 1 }, __PACKAGE__;
        $sub->($r, @therest);
      });
    }

    push @{ $keep{refaddr $self} }, $closure;

    $set->($self, $closure);
  }

  Carp::croak("No such read callbacks: @{[ sort keys %callbacks ]}") if %callbacks;

  _set_callback_data($self, undef);

  $xsub->($self);
});


$ffi->attach( open_memory => ['archive_read','opaque','size_t'] => 'int' => sub {
  my($xsub, $self, $ref) = @_;
  Carp::croak("buffer must be a scalar reference")

lib/Archive/Libarchive/ArchiveRead.pm  view on Meta::CPAN


=head2 open

 # archive_read_open1
 # archive_read_set_callback_data
 # archive_read_set_close_callback
 # archive_read_set_open_callback
 # archive_read_set_read_callback
 # archive_read_set_seek_callback
 # archive_read_set_skip_callback
 $r->open(%callbacks);

This is a basic open method, which relies on callbacks for its implementation.  The
only callback that is required is the C<read> callback.  The C<open> and C<close>
callbacks are made available mostly for the benefit of the caller.  The C<skip>
and C<seek> callbacks are used if available for some formats like C<zip> to improve
performance.  All callbacks should return a L<normal status code|Archive::Libarchive/CONSTANTS>,
which is C<ARCHIVE_OK> on success.

Unlike the C<libarchive> C-API, this interface doesn't provide a facility for
passing in "client" data.  In Perl this is implemented using a closure, which should
allow you to pass in arbitrary variables via proper scoping.

=over 4

=item open

lib/Archive/Libarchive/ArchiveWrite.pm  view on Meta::CPAN

    {
      Carp::croak("The $name callback is not a subref");
    }
  }

  my $opener = delete $cb{open};
  my $writer = delete $cb{write};
  my $closer = delete $cb{close};

  Carp::croak("Write callback is required") unless $writer;
  Carp::croak("No such write callbacks: @{[ sort keys %cb ]}") if %cb;

  if($opener)
  {
    my $orig = $opener;
    $opener = FFI::Platypus->closure(sub ($w, $) {
      $w = bless { ptr => $w, cb => 1 }, __PACKAGE__;
      $orig->($w);
    });
    push @{ $keep{refaddr $self} }, $opener;
  }

lib/Archive/Libarchive/ArchiveWrite.pm  view on Meta::CPAN

Create a new archive write object.

=head1 METHODS

This is a subset of total list of methods available to all archive classes.
For the full list see L<Archive::Libarchive::API/Archive::Libarchive::ArchiveWrite>.

=head2 open

 # archive_write_open
 $w->open(%callbacks);

This is a basic open method, which relies on callbacks for its implementation.  The
only callback that is required is the C<write> callback.  The C<open> and C<close>
callbacks are made available mostly for the benefit of the caller.  All callbacks
should return a L<normal status code|Archive::Libarchive/CONSTANTS>, which is
C<ARCHIVE_OK> on success.

Unlike the C<libarchive> C-API, this interface doesn't provide a facility for
passing in "client" data.  In Perl this is implemented using a closure, which should
allow you to pass in arbitrary variables via proper scoping.

=over 4

=item open

lib/Archive/Libarchive/Lib.pm  view on Meta::CPAN

      native_type => 'opaque',
      native_to_perl => sub ($ptr,$) {
        my $raw = _ptr_to_str($ptr);
        decode('UTF-8', $raw, Encode::FB_CROAK);
      },
    });

    require FFI::C::Stat;
    $ffi->type('object(FFI::C::Stat)' => 'stat');

    # callbacks for both read/write
    $ffi->type('(opaque,opaque)->int'    => 'archive_open_callback'                 );
    $ffi->type('(opaque,opaque)->int'    => 'archive_close_callback'                );
    $ffi->type('(opaque,opaque)->opaque' => 'archive_passphrase_callback'           );  # actually returns a string :/

    # callbacks for write
    $ffi->type('(opaque,opaque,opaque,size_t)->ssize_t' => 'archive_write_callback' );

    # callbacks for read
    $ffi->type('(opaque,opaque,opaque)->ssize_t'    => 'archive_read_callback'      );
    $ffi->type('(opaque,opaque,sint64)->ssize_t'    => 'archive_skip_callback'      );
    $ffi->type('(opaque,opaque,sint64,int)->sint64' => 'archive_seek_callback'      );

    if($Archive::Libarchive::no_gen)
    {
      $ffi->type('int', $_) for qw( archive_entry_digest_t archive_filter_t archive_format_t );
    }
    else
    {

maint/ref-update.pl  view on Meta::CPAN

      push @prune, $name if $name =~ /^archive_(write_set_compression.*|read_support_compression.*|position_(compressed|uncompressed)|compression(_name|)|(read|write)_open_file|entry_acl_text(|_w))$/;

      # The _finish forms were renamed to _Free in 3.x and will be
      # removed in 4.x
      push @prune, $name if $name =~ /^archive_(read|write)_finish$/;

      # utility function to sort strings.  Don't really need this
      # in perl
      push @prune, $name if $name eq 'archive_utility_string_sort';

      # Since callbacks are closures we don't really need to worry about
      # client data.  Not 100% sure this is what I think it is so
      # we maybe should revisit later.
      push @prune, $name if $name =~ /^archive_read_(add_callback_data|append_callback_data|prepend_callback_data|set_callback_data2)$/;

      # The open and open2 archive read methods are permutations of setting callbacks and calling open1
      # that we don't really need.
      push @prune, $name if $name =~ /^archive_read_open2?$/l
    }

    foreach my $name (@prune)
    {
      if(delete $functions{$name})
      {
        $count{removed}++;
        $removed{$name}++ unless $manual{$name};

xt/author/pod_spelling_system.t  view on Meta::CPAN

Ollis
Mojolicious
plicease
CPAN
reinstall
TODO
filename
filenames
login
callback
callbacks
standalone
VMS
hostname
hostnames
TCP
UDP
IP
API
MSWin32
OpenBSD



( run in 0.602 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )