Archive-Libarchive-FFI

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

     
     archive_entry_set_pathname($entry, "привет.txt");
     my $string = archive_entry_pathname($entry); # "привет.txt"
     
     archive_entry_free($entry);

    If you try to pass a string with characters unsupported by your current
    locale, the behavior is undefined. If you try to retrieve strings with
    characters unsupported by your current locale you will get undef.

    Unfortunately locale names are not portable across systems, so you
    should probably not hard code the locale as shown here unless you know
    the correct locale name for all the platforms that your script will
    run.

    There are two Perl only functions that give information about the
    current codeset as understood by libarchive. archive_perl_utf8_mode if
    the currently selected codeset is UTF-8.

     use strict;
     use warnings;
     use Archive::Libarchive::FFI qw( :all );
     
     die "must use UTF-8 locale" unless archive_perl_utf8_mode();

    archive_perl_codeset returns the currently selected codeset.

     use strict;
     use warnings;
     use Archive::Libarchive::FFI qw( :all );
     
     my $entry = archive_entry_new();
     
     if(archive_perl_codeset() =~ /^(ISO-8859-5|CP1251|KOI8-R|UTF-8)$/)
     {
       archive_entry_set_pathname($entry, "привет.txt");
       my $string = archive_entry_pathname($entry); # "привет.txt"
     }
     else
     {
       archive_entry_set_pathname($entry, "privet.txt");
       my $string = archive_entry_pathname($entry); # "privet.txt"
     }

    Because libarchive reads and writes file content within an archive
    using raw bytes, if your file content has non ASCII characters in it,
    then you need to encode them

     use Encode qw( encode );
     
     archive_write_data($archive, encode('UTF-8', "привет.txt");
     # or
     archive_write_data($archive, encode('KOI8-R', "привет.txt");

    read:

     use Encode qw( decode );
     
     my $raw;
     archive_read_data($archive, $raw, 10240);
     my $decoded_content = decode('UTF-8', $raw);
     # or
     my $decoded_content = decode('KOI8-R', $raw);

SUPPORT

    If you find bugs, please open an issue on the project GitHub
    repository:

    https://github.com/plicease/Archive-Libarchive-FFI/issues?state=open

    If you have a fix, please open a pull request. You can see the
    CONTRIBUTING file for traps, hints and pitfalls.

CAVEATS

    Archive and entry objects are really pointers to opaque C structures
    and need to be freed using one of archive_read_free, archive_write_free
    or archive_entry_free, in order to free the resources associated with
    those objects.

    Proper Unicode (or non-ASCII character support) depends on setting the
    correct POSIX locale, which is system dependent.

    The documentation that comes with libarchive is not that great (by its
    own admission), being somewhat incomplete, and containing a few subtle
    errors. In writing the documentation for this distribution, I borrowed
    heavily (read: stole wholesale) from the libarchive documentation,
    making changes where appropriate for use under Perl (changing NULL to
    undef for example, along with the interface change to make that work).
    I may and probably have introduced additional subtle errors. Patches to
    the documentation that match the implementation, or fixes to the
    implementation so that it matches the documentation (which ever is
    appropriate) would greatly appreciated.

SEE ALSO

    The intent of this module is to provide a low level fairly thin direct
    interface to libarchive, on which a more Perlish OO layer could easily
    be written.

    Archive::Libarchive::XS

    Archive::Libarchive::FFI

      Both of these provide the same API to libarchive but the bindings are
      implemented in XS for one and via FFI::Raw for the other.

    Archive::Libarchive::Any

      Offers whichever is available, either the XS or FFI version. The
      actual algorithm as to which is picked is subject to change,
      depending on with version seems to be the most reliable.

    Archive::Peek::Libarchive

    Archive::Extract::Libarchive

      Both of these provide a higher level, less complete perlish interface
      to libarchive.

    Archive::Tar



( run in 1.110 second using v1.01-cache-2.11-cpan-39bf76dae61 )