Archive-Libarchive-FFI
view release on metacpan or search on metacpan
{
die archive_error_string($aw), "\n";
}
}
}
Unicode
Libarchive deals with two types of string like data. Pathnames, user
and group names are proper strings and are encoded in the codeset for
the current POSIX locale. Content data for files stored and retrieved
from in raw bytes.
The usual operational procedure in Perl is to convert everything on
input into UTF-8, operate on the UTF-8 data and then convert (if
necessary) everything on output to the desired output format.
In order to get useful string data out of libarchive, this module
translates its input/output using the codeset for the current POSIX
locale. So you must be using a POSIX locale that supports the
characters in the pathnames of the archives you are going to process,
and it is highly recommend that you use a UTF-8 locale, which should
cover everything.
use strict;
use warnings;
use utf8;
use Archive::Libarchive::FFI qw( :all );
use POSIX qw( setlocale LC_ALL );
# substitute en_US.utf8 for the correct UTF-8 locale for your region.
setlocale(LC_ALL, "en_US.utf8"); # or 'export LANG=en_US.utf8' from your shell.
my $entry = archive_entry_new();
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)$/)
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
lib/Archive/Libarchive/FFI.pm view on Meta::CPAN
{
die archive_error_string($aw), "\n";
}
}
}
=head2 Unicode
Libarchive deals with two types of string like data. Pathnames, user and
group names are proper strings and are encoded in the codeset for the
current POSIX locale. Content data for files stored and retrieved from in
raw bytes.
The usual operational procedure in Perl is to convert everything on input
into UTF-8, operate on the UTF-8 data and then convert (if necessary)
everything on output to the desired output format.
In order to get useful string data out of libarchive, this module translates
its input/output using the codeset for the current POSIX locale. So you must
be using a POSIX locale that supports the characters in the pathnames of
the archives you are going to process, and it is highly recommend that you
use a UTF-8 locale, which should cover everything.
use strict;
use warnings;
use utf8;
use Archive::Libarchive::FFI qw( :all );
use POSIX qw( setlocale LC_ALL );
# substitute en_US.utf8 for the correct UTF-8 locale for your region.
setlocale(LC_ALL, "en_US.utf8"); # or 'export LANG=en_US.utf8' from your shell.
my $entry = archive_entry_new();
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 C<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.
L<archive_perl_utf8_mode|Archive::Libarchive::FFI::Function#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();
L<archive_perl_codeset|Archive::Libarchive::FFI::Function#archive_perl_codeset>
returns the currently selected codeset.
use strict;
use warnings;
use Archive::Libarchive::FFI qw( :all );
my $entry = archive_entry_new();
lib/Archive/Libarchive/FFI.pm view on Meta::CPAN
=head1 CAVEATS
Archive and entry objects are really pointers to opaque C structures
and need to be freed using one of
L<archive_read_free|Archive::Libarchive::FFI::Function#archive_read_free>,
L<archive_write_free|Archive::Libarchive::FFI::Function#archive_write_free> or
L<archive_entry_free|Archive::Libarchive::FFI::Function#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 C<NULL> to C<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.
lib/Archive/Libarchive/FFI/Function.pod view on Meta::CPAN
my $bool = archive_match_time_excluded($archive, $entry);
Test if a file is excluded by its time stamp.
=head2 archive_perl_codeset
my $string = archive_perl_codeset();
Returns the name of the "codeset" (character encoding, example: "UTF-8" for
UTF-8 or "ANSI_X3.4-1968" for ASCII) of the currently configured locale.
=head2 archive_perl_utf8_mode
my $bool = archive_perl_utf8_mode();
Returns true if the internal "codeset" used by libarchive is UTF-8.
=head2 archive_read_append_filter
my $status = archive_read_append_filter($archive, $code)
t/common_unicode.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use open ':std', ':encoding(utf8)';
use Test::More;
use Archive::Libarchive::FFI qw( :all );
plan skip_all => 'test requires unicode locale' unless archive_perl_utf8_mode();
plan tests => 2;
my $e = archive_entry_new();
my $r = archive_entry_set_pathname($e, "пÑивеÑ.txt");
is $r, ARCHIVE_OK, 'archive_entry_set_pathname';
is archive_entry_pathname($e), "пÑивеÑ.txt", 'archive_entry_pathname';
( run in 1.387 second using v1.01-cache-2.11-cpan-5a3173703d6 )