$run->(@ARGV);
}
+
+# magic identification
+use constant GZIP_ID1 => 0x1F;
+use constant GZIP_ID2 => 0x8B;
+use constant BZIP2_ID1 => 0x42;
+use constant BZIP2_ID2 => 0x5a;
+
+# compression methods
+# 0x00-0x07 are reserved
+use constant GZIP_METHOD_DEFLATE => 0x08;
+# 'h' for Bzip2 ('H'uffman coding)
+use constant BZIP2_METHOD_HUFFMAN => 0x68;
+
+# flags
+use constant {
+ GZIP_FLAG_FTEXT => 0,
+ GZIP_FLAG_FHCRC => 1,
+ GZIP_FLAG_FEXTRA => 2,
+ GZIP_FLAG_FNAME => 3,
+ GZIP_FLAG_FCOMMENT => 4,
+ # the rest are reserved
+};
+# compression level
+use constant {
+ GZIP_COMPRESSION_NORMAL => 0,
+ GZIP_COMPRESSION_BEST => 2,
+ GZIP_COMPRESSION_FAST => 4,
+};
+# operating systems
+use constant {
+ GZIP_OS_MSDOS => 0,
+ GZIP_OS_AMIGA => 1,
+ GZIP_OS_VMS => 2,
+ GZIP_OS_UNIX => 3,
+ GZIP_OS_VMCMS => 4,
+ GZIP_OS_ATARI => 5,
+ GZIP_OS_HPFS => 6,
+ GZIP_OS_MACINTOSH => 7,
+ GZIP_OS_ZSYSTEM => 8,
+ GZIP_OS_CPM => 9,
+ GZIP_OS_TOPS => 10,
+ GZIP_OS_NTFS => 11,
+ GZIP_OS_QDOS => 12,
+ GZIP_OS_RISCOS => 13,
+ GZIP_OS_VFAT => 14,
+ GZIP_OS_UNKNOWN => 255,
+};
+
1
use IPC::Open2;
use IO::Handle;
-use constant BZIP2_DEBUG => 1;
-
-# magic identification
-use constant BZIP2_ID1 => 0x42;
-use constant BZIP2_ID2 => 0x5a;
-
-# compression methods, 'h' for Bzip2 ('H'uffman coding), '0' for Bzip1 (deprecated)
-use constant BZIP2_METHOD_HUFFMAN => 0x68;
-
my @supported_bzip2_programs = qw(bzip2 pbzip2 zgz);
my $try=0;
# we actually want the value, not the ascii position
$level-=48;
- if ($id1 != BZIP2_ID1 || $id2 != BZIP2_ID2 || $method != BZIP2_METHOD_HUFFMAN || $level !~ /^[1-9]$/) {
+ if ($id1 != Pristine::Tar::BZIP2_ID1 ||
+ $id2 != Pristine::Tar::BZIP2_ID2 ||
+ $method != Pristine::Tar::BZIP2_METHOD_HUFFMAN ||
+ $level !~ /^[1-9]$/) {
die("This is not a valid BZip2 archive.\n");
}
use File::Basename qw/basename/;
use IPC::Open2;
-use constant GZIP_DEBUG => 1;
-
-# magic identification
-use constant GZIP_ID1 => 0x1F;
-use constant GZIP_ID2 => 0x8B;
-
-# compression methods, 0x00-0x07 are reserved
-use constant GZIP_METHOD_DEFLATE => 0x08;
-
-# flags
-use constant {
- GZIP_FLAG_FTEXT => 0,
- GZIP_FLAG_FHCRC => 1,
- GZIP_FLAG_FEXTRA => 2,
- GZIP_FLAG_FNAME => 3,
- GZIP_FLAG_FCOMMENT => 4,
- # the rest are reserved
-};
-# compression level
-use constant {
- GZIP_COMPRESSION_NORMAL => 0,
- GZIP_COMPRESSION_BEST => 2,
- GZIP_COMPRESSION_FAST => 4,
-};
-# operating systems
-use constant {
- GZIP_OS_MSDOS => 0,
- GZIP_OS_AMIGA => 1,
- GZIP_OS_VMS => 2,
- GZIP_OS_UNIX => 3,
- GZIP_OS_VMCMS => 4,
- GZIP_OS_ATARI => 5,
- GZIP_OS_HPFS => 6,
- GZIP_OS_MACINTOSH => 7,
- GZIP_OS_ZSYSTEM => 8,
- GZIP_OS_CPM => 9,
- GZIP_OS_TOPS => 10,
- GZIP_OS_NTFS => 11,
- GZIP_OS_QDOS => 12,
- GZIP_OS_RISCOS => 13,
- GZIP_OS_VFAT => 14,
- GZIP_OS_UNKNOWN => 255,
-};
-
dispatch(
commands => {
usage => [\&usage],
my ($id1, $id2, $method, $flags, $timestamp, $level, $os, $name)
= (unpack("CCCb8VCC", $chars), '');
- if ($id1 != GZIP_ID1 || $id2 != GZIP_ID2 || $method != GZIP_METHOD_DEFLATE) {
+ if ($id1 != Pristine::Tar::GZIP_ID1 ||
+ $id2 != Pristine::Tar::GZIP_ID2 ||
+ $method != Pristine::Tar::GZIP_METHOD_DEFLATE) {
die("This is not a valid GZip archive.\n");
}
my @flags = split(//, $flags);
- if ($flags[GZIP_FLAG_FNAME]) {
+ if ($flags[Pristine::Tar::GZIP_FLAG_FNAME]) {
# read a null-terminated string
$name .= $chars
while (read(GZIP, $chars, 1) == 1 && ord($chars) != 0);
my @flags = @$flags;
my @args;
- unless ($flags[GZIP_FLAG_FNAME]) {
+ unless ($flags[Pristine::Tar::GZIP_FLAG_FNAME]) {
push @args, '-n';
push @args, '-M' if $timestamp;
}
- if ($level == GZIP_COMPRESSION_BEST) {
+ if ($level == Pristine::Tar::GZIP_COMPRESSION_BEST) {
push @args, '-9'
}
- elsif ($level == GZIP_COMPRESSION_FAST) {
+ elsif ($level == Pristine::Tar::GZIP_COMPRESSION_FAST) {
push @args, '-1'
}
my @try;
- if ($os == GZIP_OS_UNIX) {
+ if ($os == Pristine::Tar::GZIP_OS_UNIX) {
# for 98% of the cases the simple heuristic above works
# and it was produced by gnu gzip.
push @try, ['--gnu', @args];
# set the Operating System flag to the one found in the original
# archive
- push @args, ("--osflag", $os) if $os != GZIP_OS_UNIX;
+ push @args, ("--osflag", $os) if $os != Pristine::Tar::GZIP_OS_UNIX;
# many of the .gz out there are created using the BSD version of
# gzip which is using the zlib library; try with our version of
# Windows' NTFS gzip implementation; quirk is really really evil
# it should be the last test: it can result in a corrupted archive!
- if ($os == GZIP_OS_NTFS) {
+ if ($os == Pristine::Tar::GZIP_OS_NTFS) {
pop @args; pop @args; # ntfs quirk implies NTFS osflag
push @try, [@args, '--quirk', 'ntfs'];
}
use File::Basename;
use Cwd qw{getcwd abs_path};
-# magic identification
-use constant GZIP_ID1 => 0x1F;
-use constant GZIP_ID2 => 0x8B;
-use constant BZIP2_ID1 => 0x42;
-use constant BZIP2_ID2 => 0x5a;
-
-# compression methods, 0x00-0x07 are reserved
-use constant GZIP_METHOD_DEFLATE => 0x08;
-
-# compression methods, 'h' for Bzip2 ('H'uffman coding), '0' for Bzip1 (deprecated)
-use constant BZIP2_METHOD_HUFFMAN => 0x68;
-
# Force locale to C since tar may output utf-8 filenames differently
# depending on the locale.
$ENV{LANG}='C';
my ($chars, $id1, $id2, $method);
if (read(IN, $chars, 10) == 10 &&
(($id1, $id2, $method) = unpack("CCC", $chars)) &&
- $id1 == GZIP_ID1 && $id2 == GZIP_ID2 &&
- $method == GZIP_METHOD_DEFLATE) {
+ $id1 == Pristine::Tar::GZIP_ID1 &&
+ $id2 == Pristine::Tar::GZIP_ID2 &&
+ $method == Pristine::Tar::GZIP_METHOD_DEFLATE) {
$compression='gz';
open(IN, "-|", "zcat", $tarball) || die "zcat: $!";
open(OUT, ">", "$tempdir/origtarball") || die "$tempdir/origtarball: $!";
seek(IN, 0, 0) || die "seek: $!";
if (read(IN, $chars, 3) == 3 &&
(($id1, $id2, $method) = unpack("CCC", $chars)) &&
- $id1 == BZIP2_ID1 && $id2 == BZIP2_ID2 &&
- $method == BZIP2_METHOD_HUFFMAN) {
+ $id1 == Pristine::Tar::BZIP2_ID1 &&
+ $id2 == Pristine::Tar::BZIP2_ID2 &&
+ $method == Pristine::Tar::BZIP2_METHOD_HUFFMAN) {
$compression='bz2';
open(IN, "-|", "bzcat", $tarball) || die "bzcat: $!";
open(OUT, ">", "$tempdir/origtarball") || die "$tempdir/origtarball: $!";