diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2020-02-07 10:12:36 +0000 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2020-02-07 10:12:36 +0000 |
commit | 2db5b8da93078342162321482218d65cc5ec5eb5 (patch) | |
tree | a43eb6d04ca251b5dcc5bc77e8c1291e4fe9f3a8 /cpan | |
parent | ac3afc4b35675aec55918770197358190f782728 (diff) | |
download | perl-2db5b8da93078342162321482218d65cc5ec5eb5.tar.gz |
Update Archive-Tar to CPAN version 2.36
[DELTA]
2.36 02/02/2020
- Add xz test files to MANIFEST
2.34 01/02/2020 (HEANEY && SKAJI)
- Add xz support
- Use 4 digit year in Time::Local call
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/Archive-Tar/lib/Archive/Tar.pm | 72 | ||||
-rw-r--r-- | cpan/Archive-Tar/lib/Archive/Tar/Constant.pm | 13 | ||||
-rw-r--r-- | cpan/Archive-Tar/lib/Archive/Tar/File.pm | 2 | ||||
-rw-r--r-- | cpan/Archive-Tar/t/02_methods.t | 16 | ||||
-rw-r--r-- | cpan/Archive-Tar/t/09_roundtrip.t | 3 |
5 files changed, 84 insertions, 22 deletions
diff --git a/cpan/Archive-Tar/lib/Archive/Tar.pm b/cpan/Archive-Tar/lib/Archive/Tar.pm index 093579a6c2..af6786ee51 100644 --- a/cpan/Archive-Tar/lib/Archive/Tar.pm +++ b/cpan/Archive-Tar/lib/Archive/Tar.pm @@ -27,11 +27,11 @@ use vars qw[$DEBUG $error $VERSION $WARN $FOLLOW_SYMLINK $CHOWN $CHMOD ]; @ISA = qw[Exporter]; -@EXPORT = qw[ COMPRESS_GZIP COMPRESS_BZIP ]; +@EXPORT = qw[ COMPRESS_GZIP COMPRESS_BZIP COMPRESS_XZ ]; $DEBUG = 0; $WARN = 1; $FOLLOW_SYMLINK = 0; -$VERSION = "2.32"; +$VERSION = "2.36"; $CHOWN = 1; $CHMOD = 1; $SAME_PERMISSIONS = $> == 0 ? 1 : 0; @@ -76,6 +76,7 @@ Archive::Tar - module for manipulations of tar archives $tar->write('files.tar'); # plain tar $tar->write('files.tgz', COMPRESS_GZIP); # gzip compressed $tar->write('files.tbz', COMPRESS_BZIP); # bzip2 compressed + $tar->write('files.txz', COMPRESS_XZ); # xz compressed =head1 DESCRIPTION @@ -147,12 +148,13 @@ backwards compatibility. Archive::Tar now looks at the file magic to determine what class should be used to open the file and will transparently Do The Right Thing. -Archive::Tar will warn if you try to pass a bzip2 compressed file and the -IO::Zlib / IO::Uncompress::Bunzip2 modules are not available and simply return. +Archive::Tar will warn if you try to pass a bzip2 / xz compressed file and the +IO::Uncompress::Bunzip2 / IO::Uncompress::UnXz are not available and simply return. Note that you can currently B<not> pass a C<gzip> compressed filehandle, which is not opened with C<IO::Zlib>, a C<bzip2> compressed -filehandle, which is not opened with C<IO::Uncompress::Bunzip2>, nor a string +filehandle, which is not opened with C<IO::Uncompress::Bunzip2>, a C<xz> compressed +filehandle, which is not opened with C<IO::Uncompress::UnXz>, nor a string containing the full archive information (either compressed or uncompressed). These are worth while features, but not currently implemented. See the C<TODO> section. @@ -246,16 +248,40 @@ sub _get_handle { return; }; - ### read the first 4 bites of the file to figure out which class to + ### read the first 6 bytes of the file to figure out which class to ### use to open the file. - sysread( $tmp, $magic, 4 ); + sysread( $tmp, $magic, 6 ); close $tmp; } + ### is it xz? + ### if you asked specifically for xz compression, or if we're in + ### read mode and the magic numbers add up, use xz + if( XZ and ( + ($compress eq COMPRESS_XZ) or + ( MODE_READ->($mode) and $magic =~ XZ_MAGIC_NUM ) + ) + ) { + if( MODE_READ->($mode) ) { + $fh = IO::Uncompress::UnXz->new( $file ) or do { + $self->_error( qq[Could not read '$file': ] . + $IO::Uncompress::UnXz::UnXzError + ); + return; + }; + } else { + $fh = IO::Compress::Xz->new( $file ) or do { + $self->_error( qq[Could not write to '$file': ] . + $IO::Compress::Xz::XzError + ); + return; + }; + } + ### is it bzip? ### if you asked specifically for bzip compression, or if we're in ### read mode and the magic numbers add up, use bzip - if( BZIP and ( + } elsif( BZIP and ( ($compress eq COMPRESS_BZIP) or ( MODE_READ->($mode) and $magic =~ BZIP_MAGIC_NUM ) ) @@ -1246,8 +1272,8 @@ Write the in-memory archive to disk. The first argument can either be the name of a file or a reference to an already open filehandle (a GLOB reference). -The second argument is used to indicate compression. You can either -compress using C<gzip> or C<bzip2>. If you pass a digit, it's assumed +The second argument is used to indicate compression. You can +compress using C<gzip>, C<bzip2> or C<xz>. If you pass a digit, it's assumed to be the C<gzip> compression level (between 1 and 9), but the use of constants is preferred: @@ -1257,10 +1283,13 @@ constants is preferred: # write a bzip compressed file $tar->write( 'out.tbz', COMPRESS_BZIP ); + # write a xz compressed file + $tar->write( 'out.txz', COMPRESS_XZ ); + Note that when you pass in a filehandle, the compression argument is ignored, as all files are printed verbatim to your filehandle. If you wish to enable compression with filehandles, use an -C<IO::Zlib> or C<IO::Compress::Bzip2> filehandle instead. +C<IO::Zlib>, C<IO::Compress::Bzip2> or C<IO::Compress::Xz> filehandle instead. The third argument is an optional prefix. All files will be tucked away in the directory you specify as prefix. So if you have files @@ -1696,8 +1725,8 @@ Creates a tar file from the list of files provided. The first argument can either be the name of the tar file to create or a reference to an open file handle (e.g. a GLOB reference). -The second argument is used to indicate compression. You can either -compress using C<gzip> or C<bzip2>. If you pass a digit, it's assumed +The second argument is used to indicate compression. You can +compress using C<gzip>, C<bzip2> or C<xz>. If you pass a digit, it's assumed to be the C<gzip> compression level (between 1 and 9), but the use of constants is preferred: @@ -1707,10 +1736,13 @@ constants is preferred: # write a bzip compressed file Archive::Tar->create_archive( 'out.tbz', COMPRESS_BZIP, @filelist ); + # write a xz compressed file + Archive::Tar->create_archive( 'out.txz', COMPRESS_XZ, @filelist ); + Note that when you pass in a filehandle, the compression argument is ignored, as all files are printed verbatim to your filehandle. If you wish to enable compression with filehandles, use an -C<IO::Zlib> or C<IO::Compress::Bzip2> filehandle instead. +C<IO::Zlib>, C<IO::Compress::Bzip2> or C<IO::Compress::Xz> filehandle instead. The remaining arguments list the files to be included in the tar file. These files must all exist. Any files which don't exist or can't be @@ -1915,11 +1947,19 @@ Returns true if C<Archive::Tar> can extract C<bzip2> compressed archives sub has_bzip2_support { return BZIP } +=head2 $bool = Archive::Tar->has_xz_support + +Returns true if C<Archive::Tar> can extract C<xz> compressed archives + +=cut + +sub has_xz_support { return XZ } + =head2 Archive::Tar->can_handle_compressed_files A simple checking routine, which will return true if C<Archive::Tar> -is able to uncompress compressed archives on the fly with C<IO::Zlib> -and C<IO::Compress::Bzip2> or false if not both are installed. +is able to uncompress compressed archives on the fly with C<IO::Zlib>, +C<IO::Compress::Bzip2> and C<IO::Compress::Xz> or false if not both are installed. You can use this as a shortcut to determine whether C<Archive::Tar> will do what you think before passing compressed archives to its diff --git a/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm b/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm index a48968d9e0..398c4799a5 100644 --- a/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm +++ b/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm @@ -3,7 +3,7 @@ package Archive::Tar::Constant; BEGIN { require Exporter; - $VERSION = '2.32'; + $VERSION = '2.36'; @ISA = qw[Exporter]; require Time::Local if $^O eq "MacOS"; @@ -32,6 +32,7 @@ use constant BLOCK => 512; use constant COMPRESS_GZIP => 9; use constant COMPRESS_BZIP => 'bzip2'; +use constant COMPRESS_XZ => 'xz'; use constant BLOCK_SIZE => sub { my $n = int($_[0]/BLOCK); $n++ if $_[0] % BLOCK; $n * BLOCK }; use constant TAR_PAD => sub { my $x = shift || return; return "\0" x (BLOCK - ($x % BLOCK) ) }; @@ -58,7 +59,7 @@ use constant PACK => 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a use constant NAME_LENGTH => 100; use constant PREFIX_LENGTH => 155; -use constant TIME_OFFSET => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,70) : 0; +use constant TIME_OFFSET => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,1970) : 0; use constant MAGIC => "ustar"; use constant TAR_VERSION => "00"; use constant LONGLINK_NAME => '././@LongLink'; @@ -77,8 +78,16 @@ use constant BZIP => do { !$ENV{'PERL5_AT_NO_BZIP'} and $ENV{'PERL5_AT_NO_BZIP'} || $@ ? 0 : 1 }; + ### allow XZ to be turned off using ENV: DEBUG only +use constant XZ => do { !$ENV{'PERL5_AT_NO_XZ'} and + eval { require IO::Compress::Xz; + require IO::Uncompress::UnXz; }; + $ENV{'PERL5_AT_NO_XZ'} || $@ ? 0 : 1 + }; + use constant GZIP_MAGIC_NUM => qr/^(?:\037\213|\037\235)/; use constant BZIP_MAGIC_NUM => qr/^BZh\d/; +use constant XZ_MAGIC_NUM => qr/^\xFD\x37\x7A\x58\x5A\x00/; use constant CAN_CHOWN => sub { ($> == 0 and $^O ne "MacOS" and $^O ne "MSWin32") }; use constant CAN_READLINK => ($^O ne 'MSWin32' and $^O !~ /RISC(?:[ _])?OS/i and $^O ne 'VMS'); diff --git a/cpan/Archive-Tar/lib/Archive/Tar/File.pm b/cpan/Archive-Tar/lib/Archive/Tar/File.pm index 3efa3159d9..0887a923bd 100644 --- a/cpan/Archive-Tar/lib/Archive/Tar/File.pm +++ b/cpan/Archive-Tar/lib/Archive/Tar/File.pm @@ -13,7 +13,7 @@ use Archive::Tar::Constant; use vars qw[@ISA $VERSION]; #@ISA = qw[Archive::Tar]; -$VERSION = '2.32'; +$VERSION = '2.36'; ### set value to 1 to oct() it during the unpack ### diff --git a/cpan/Archive-Tar/t/02_methods.t b/cpan/Archive-Tar/t/02_methods.t index b740594203..4006d4eb31 100644 --- a/cpan/Archive-Tar/t/02_methods.t +++ b/cpan/Archive-Tar/t/02_methods.t @@ -99,9 +99,11 @@ my $TARX = $Class->new; my $TAR_FILE = File::Spec->catfile( @ROOT, 'bar.tar' ); my $TGZ_FILE = File::Spec->catfile( @ROOT, 'foo.tgz' ); my $TBZ_FILE = File::Spec->catfile( @ROOT, 'foo.tbz' ); +my $TXZ_FILE = File::Spec->catfile( @ROOT, 'foo.txz' ); my $OUT_TAR_FILE = File::Spec->catfile( @ROOT, 'out.tar' ); my $OUT_TGZ_FILE = File::Spec->catfile( @ROOT, 'out.tgz' ); my $OUT_TBZ_FILE = File::Spec->catfile( @ROOT, 'out.tbz' ); +my $OUT_TXZ_FILE = File::Spec->catfile( @ROOT, 'out.txz' ); my $COMPRESS_FILE = 'copy'; $^O eq 'VMS' and $COMPRESS_FILE .= '.'; @@ -110,8 +112,8 @@ chmod 0644, $COMPRESS_FILE; ### done setting up environment ### -### check for zlib/bzip2 support -{ for my $meth ( qw[has_zlib_support has_bzip2_support] ) { +### check for zlib/bzip2/xz support +{ for my $meth ( qw[has_zlib_support has_bzip2_support has_xz_support] ) { can_ok( $Class, $meth ); } } @@ -167,6 +169,7 @@ chmod 0644, $COMPRESS_FILE; { my @to_try = ($TAR_FILE); push @to_try, $TGZ_FILE if $Class->has_zlib_support; push @to_try, $TBZ_FILE if $Class->has_bzip2_support; + push @to_try, $TXZ_FILE if $Class->has_xz_support; for my $type( @to_try ) { @@ -462,6 +465,7 @@ SKIP: { ### pesky warnings { my @out; push @out, [ $OUT_TGZ_FILE => 1 ] if $Class->has_zlib_support; push @out, [ $OUT_TBZ_FILE => COMPRESS_BZIP ] if $Class->has_bzip2_support; + push @out, [ $OUT_TXZ_FILE => COMPRESS_XZ ] if $Class->has_xz_support; for my $entry ( @out ) { @@ -786,8 +790,14 @@ sub slurp_compressed_file { my $file = shift; my $fh; + ### xz + if( $file =~ /.txz$/ ) { + require IO::Uncompress::UnXz; + $fh = IO::Uncompress::UnXz->new( $file ) + or warn( "Error opening '$file' with IO::Uncompress::UnXz" ), return + ### bzip2 - if( $file =~ /.tbz$/ ) { + } elsif( $file =~ /.tbz$/ ) { require IO::Uncompress::Bunzip2; $fh = IO::Uncompress::Bunzip2->new( $file ) or warn( "Error opening '$file' with IO::Uncompress::Bunzip2" ), return diff --git a/cpan/Archive-Tar/t/09_roundtrip.t b/cpan/Archive-Tar/t/09_roundtrip.t index 8fb72a8023..3e612ef9c8 100644 --- a/cpan/Archive-Tar/t/09_roundtrip.t +++ b/cpan/Archive-Tar/t/09_roundtrip.t @@ -43,6 +43,8 @@ push @file_only_archives, [qw( src short foo.tgz )] if Archive::Tar->has_zlib_support; push @file_only_archives, [qw( src short foo.tbz )] if Archive::Tar->has_bzip2_support; +push @file_only_archives, [qw( src short foo.txz )] + if Archive::Tar->has_xz_support; @file_only_archives = map File::Spec->catfile(@$_), @file_only_archives; @@ -74,6 +76,7 @@ for my $archive_name (@file_only_archives) { my @compress = $ext =~ /t?gz$/ ? (COMPRESS_GZIP) : $ext =~ /(tbz|bz2?)$/ ? (COMPRESS_BZIP) + : $ext =~ /(t?xz)$/ ? (COMPRESS_XZ) : (); my ( $fh, $filename ) = tempfile( UNLINK => 1 ); |