@@ -27,11 +27,11 @@ use vars qw[$DEBUG $error $VERSION $WARN $FOLLOW_SYMLINK $CHOWN $CHMOD
27
27
] ;
28
28
29
29
@ISA = qw[ Exporter] ;
30
- @EXPORT = qw[ COMPRESS_GZIP COMPRESS_BZIP ] ;
30
+ @EXPORT = qw[ COMPRESS_GZIP COMPRESS_BZIP COMPRESS_XZ ] ;
31
31
$DEBUG = 0;
32
32
$WARN = 1;
33
33
$FOLLOW_SYMLINK = 0;
34
- $VERSION = " 2.32 " ;
34
+ $VERSION = " 2.36 " ;
35
35
$CHOWN = 1;
36
36
$CHMOD = 1;
37
37
$SAME_PERMISSIONS = $> == 0 ? 1 : 0;
@@ -76,6 +76,7 @@ Archive::Tar - module for manipulations of tar archives
76
76
$tar->write('files.tar'); # plain tar
77
77
$tar->write('files.tgz', COMPRESS_GZIP); # gzip compressed
78
78
$tar->write('files.tbz', COMPRESS_BZIP); # bzip2 compressed
79
+ $tar->write('files.txz', COMPRESS_XZ); # xz compressed
79
80
80
81
=head1 DESCRIPTION
81
82
@@ -147,12 +148,13 @@ backwards compatibility. Archive::Tar now looks at the file
147
148
magic to determine what class should be used to open the file
148
149
and will transparently Do The Right Thing.
149
150
150
- Archive::Tar will warn if you try to pass a bzip2 compressed file and the
151
- IO::Zlib / IO::Uncompress::Bunzip2 modules are not available and simply return.
151
+ Archive::Tar will warn if you try to pass a bzip2 / xz compressed file and the
152
+ IO::Uncompress::Bunzip2 / IO::Uncompress::UnXz are not available and simply return.
152
153
153
154
Note that you can currently B<not > pass a C<gzip > compressed
154
155
filehandle, which is not opened with C<IO::Zlib > , a C<bzip2 > compressed
155
- filehandle, which is not opened with C<IO::Uncompress::Bunzip2 > , nor a string
156
+ filehandle, which is not opened with C<IO::Uncompress::Bunzip2 > , a C<xz > compressed
157
+ filehandle, which is not opened with C<IO::Uncompress::UnXz > , nor a string
156
158
containing the full archive information (either compressed or
157
159
uncompressed). These are worth while features, but not currently
158
160
implemented. See the C<TODO > section.
@@ -246,16 +248,40 @@ sub _get_handle {
246
248
return ;
247
249
};
248
250
249
- # ## read the first 4 bites of the file to figure out which class to
251
+ # ## read the first 6 bytes of the file to figure out which class to
250
252
# ## use to open the file.
251
- sysread ( $tmp , $magic , 4 );
253
+ sysread ( $tmp , $magic , 6 );
252
254
close $tmp ;
253
255
}
254
256
257
+ # ## is it xz?
258
+ # ## if you asked specifically for xz compression, or if we're in
259
+ # ## read mode and the magic numbers add up, use xz
260
+ if ( XZ and (
261
+ ($compress eq COMPRESS_XZ) or
262
+ ( MODE_READ-> ($mode ) and $magic =~ XZ_MAGIC_NUM )
263
+ )
264
+ ) {
265
+ if ( MODE_READ-> ($mode ) ) {
266
+ $fh = IO::Uncompress::UnXz-> new( $file ) or do {
267
+ $self -> _error( qq[ Could not read '$file ': ] .
268
+ $IO::Uncompress::UnXz::UnXzError
269
+ );
270
+ return ;
271
+ };
272
+ } else {
273
+ $fh = IO::Compress::Xz-> new( $file ) or do {
274
+ $self -> _error( qq[ Could not write to '$file ': ] .
275
+ $IO::Compress::Xz::XzError
276
+ );
277
+ return ;
278
+ };
279
+ }
280
+
255
281
# ## is it bzip?
256
282
# ## if you asked specifically for bzip compression, or if we're in
257
283
# ## read mode and the magic numbers add up, use bzip
258
- if ( BZIP and (
284
+ } elsif ( BZIP and (
259
285
($compress eq COMPRESS_BZIP) or
260
286
( MODE_READ-> ($mode ) and $magic =~ BZIP_MAGIC_NUM )
261
287
)
@@ -1246,8 +1272,8 @@ Write the in-memory archive to disk. The first argument can either
1246
1272
be the name of a file or a reference to an already open filehandle (a
1247
1273
GLOB reference).
1248
1274
1249
- The second argument is used to indicate compression. You can either
1250
- compress using C<gzip > or C<bzip2 > . If you pass a digit, it's assumed
1275
+ The second argument is used to indicate compression. You can
1276
+ compress using C<gzip > , C< bzip2 > or C<xz > . If you pass a digit, it's assumed
1251
1277
to be the C<gzip > compression level (between 1 and 9), but the use of
1252
1278
constants is preferred:
1253
1279
@@ -1257,10 +1283,13 @@ constants is preferred:
1257
1283
# write a bzip compressed file
1258
1284
$tar->write( 'out.tbz', COMPRESS_BZIP );
1259
1285
1286
+ # write a xz compressed file
1287
+ $tar->write( 'out.txz', COMPRESS_XZ );
1288
+
1260
1289
Note that when you pass in a filehandle, the compression argument
1261
1290
is ignored, as all files are printed verbatim to your filehandle.
1262
1291
If you wish to enable compression with filehandles, use an
1263
- C<IO::Zlib > or C<IO::Compress::Bzip2 > filehandle instead.
1292
+ C<IO::Zlib > , C< IO::Compress::Bzip2 > or C<IO::Compress::Xz > filehandle instead.
1264
1293
1265
1294
The third argument is an optional prefix. All files will be tucked
1266
1295
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
1696
1725
argument can either be the name of the tar file to create or a
1697
1726
reference to an open file handle (e.g. a GLOB reference).
1698
1727
1699
- The second argument is used to indicate compression. You can either
1700
- compress using C<gzip > or C<bzip2 > . If you pass a digit, it's assumed
1728
+ The second argument is used to indicate compression. You can
1729
+ compress using C<gzip > , C< bzip2 > or C<xz > . If you pass a digit, it's assumed
1701
1730
to be the C<gzip > compression level (between 1 and 9), but the use of
1702
1731
constants is preferred:
1703
1732
@@ -1707,10 +1736,13 @@ constants is preferred:
1707
1736
# write a bzip compressed file
1708
1737
Archive::Tar->create_archive( 'out.tbz', COMPRESS_BZIP, @filelist );
1709
1738
1739
+ # write a xz compressed file
1740
+ Archive::Tar->create_archive( 'out.txz', COMPRESS_XZ, @filelist );
1741
+
1710
1742
Note that when you pass in a filehandle, the compression argument
1711
1743
is ignored, as all files are printed verbatim to your filehandle.
1712
1744
If you wish to enable compression with filehandles, use an
1713
- C<IO::Zlib > or C<IO::Compress::Bzip2 > filehandle instead.
1745
+ C<IO::Zlib > , C< IO::Compress::Bzip2 > or C<IO::Compress::Xz > filehandle instead.
1714
1746
1715
1747
The remaining arguments list the files to be included in the tar file.
1716
1748
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
1915
1947
1916
1948
sub has_bzip2_support { return BZIP }
1917
1949
1950
+ =head2 $bool = Archive::Tar->has_xz_support
1951
+
1952
+ Returns true if C<Archive::Tar > can extract C<xz > compressed archives
1953
+
1954
+ =cut
1955
+
1956
+ sub has_xz_support { return XZ }
1957
+
1918
1958
=head2 Archive::Tar->can_handle_compressed_files
1919
1959
1920
1960
A simple checking routine, which will return true if C<Archive::Tar >
1921
- is able to uncompress compressed archives on the fly with C<IO::Zlib >
1922
- and C<IO::Compress::Bzip2 > or false if not both are installed.
1961
+ is able to uncompress compressed archives on the fly with C<IO::Zlib > ,
1962
+ C< IO::Compress::Bzip2 > and C<IO::Compress::Xz > or false if not both are installed.
1923
1963
1924
1964
You can use this as a shortcut to determine whether C<Archive::Tar >
1925
1965
will do what you think before passing compressed archives to its
0 commit comments