From: Paul Marquess Date: Sun, 13 Nov 2005 17:09:08 +0000 (+0000) Subject: Compress::Zlib X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7581d28c2d4dcb4f3b408247518e6164f6b89764;p=p5sagit%2Fp5-mst-13.2.git Compress::Zlib From: "Paul Marquess" Message-ID: <00d101c5e874$f865f910$6d1c140a@myopwv.com> p4raw-id: //depot/perl@26120 --- diff --git a/ext/Compress/Zlib/Zlib.pm b/ext/Compress/Zlib/Zlib.pm index 44c8f0d..9a3598b 100644 --- a/ext/Compress/Zlib/Zlib.pm +++ b/ext/Compress/Zlib/Zlib.pm @@ -181,13 +181,13 @@ sub gzopen($$) if ($writing) { $gz = new IO::Compress::Gzip($file, Minimal => 1, AutoClose => 1, - BinModeOut => 1, %defOpts) + %defOpts) or $Compress::Zlib::gzerrno = $IO::Compress::Gzip::GzipError; } else { $gz = new IO::Uncompress::Gunzip($file, Transparent => 1, - BinModeIn => 1, Append => 0, + Append => 0, AutoClose => 1, Strict => 0) or $Compress::Zlib::gzerrno = $IO::Uncompress::Gunzip::GunzipError; } diff --git a/ext/Compress/Zlib/lib/Compress/Zlib/Common.pm b/ext/Compress/Zlib/lib/Compress/Zlib/Common.pm index aaf8332..36d6f64 100644 --- a/ext/Compress/Zlib/lib/Compress/Zlib/Common.pm +++ b/ext/Compress/Zlib/lib/Compress/Zlib/Common.pm @@ -23,26 +23,25 @@ $VERSION = '2.000_05'; WANT_HASH ); -our ($wantBinmode); -$wantBinmode = ($] >= 5.006 && eval ' ${^UNICODE} || ${^UTF8LOCALE} ') +our ($needBinmode); +$needBinmode = ($^O eq 'MSWin32' || + ($] >= 5.006 && eval ' ${^UNICODE} || ${^UTF8LOCALE} ')) ? 1 : 0 ; -sub setBinModeInput($$) +sub setBinModeInput($) { my $handle = shift ; - my $want = defined $_[0] ? shift : $wantBinmode ; binmode $handle - if $want; + if $needBinmode; } -sub setBinModeOutput($$) +sub setBinModeOutput($) { my $handle = shift ; - my $want = defined $_[0] ? shift : $wantBinmode ; binmode $handle - if $want; + if $needBinmode; } sub isaFilehandle($) diff --git a/ext/Compress/Zlib/lib/IO/Compress/Gzip.pm b/ext/Compress/Zlib/lib/IO/Compress/Gzip.pm index ee1e72d..e8e070b 100644 --- a/ext/Compress/Zlib/lib/IO/Compress/Gzip.pm +++ b/ext/Compress/Zlib/lib/IO/Compress/Gzip.pm @@ -458,8 +458,7 @@ sub checkParams 'Strict' => [Parse_boolean, 1], 'Append' => [Parse_boolean, 0], 'Merge' => [Parse_boolean, 0], - 'BinModeIn' => [Parse_boolean, undef], - 'BinModeOut'=> [Parse_boolean, undef], + 'BinModeIn' => [Parse_boolean, 0], # zlib behaviour #'Method' => [Parse_unsigned, Z_DEFLATED], @@ -486,8 +485,7 @@ sub checkParams 'Strict' => [Parse_boolean, 1], 'Append' => [Parse_boolean, 0], 'Merge' => [Parse_boolean, 0], - 'BinModeIn' => [Parse_boolean, undef], - 'BinModeOut'=> [Parse_boolean, undef], + 'BinModeIn' => [Parse_boolean, 0], # zlib behaviour #'Method' => [Parse_unsigned, Z_DEFLATED], @@ -678,7 +676,7 @@ sub new if ($outType eq 'handle') { $outValue->flush() ; *$obj->{FH} = $outValue ; - setBinModeOutput(*$obj->{FH}, $got->valueOrDefault('BinModeOut')) ; + setBinModeOutput(*$obj->{FH}) ; *$obj->{Handle} = 1 ; if ($appendOutput) { @@ -694,7 +692,7 @@ sub new *$obj->{FH} = new IO::File "$mode $outValue" or return $obj->saveErrorString(undef, "cannot open file '$outValue': $!", $!) ; *$obj->{StdIO} = ($outValue eq '-'); - setBinModeOutput(*$obj->{FH}, $got->valueOrDefault('BinModeOut')) ; + setBinModeOutput(*$obj->{FH}) ; } if (!$rfc1951) { @@ -922,7 +920,7 @@ sub _wr2 $fh = new IO::File "<$input" or return $self->saveErrorString(undef, "cannot open file '$input': $!", $!) ; } - setBinModeInput($fh, *$self->{Got}->valueOrDefault('BinModeIn')) ; + binmode $fh if *$self->{Got}->valueOrDefault('BinModeIn') ; my $status ; my $buff ; diff --git a/ext/Compress/Zlib/lib/IO/Uncompress/Gunzip.pm b/ext/Compress/Zlib/lib/IO/Uncompress/Gunzip.pm index d4c52d6..1700372 100644 --- a/ext/Compress/Zlib/lib/IO/Uncompress/Gunzip.pm +++ b/ext/Compress/Zlib/lib/IO/Uncompress/Gunzip.pm @@ -701,8 +701,7 @@ sub checkParams 'Transparent' => [Parse_any, 1], 'Scan' => [Parse_boolean, 0], 'InputLength' => [Parse_unsigned, undef], - 'BinModeIn' => [Parse_boolean, undef], - 'BinModeOut' => [Parse_boolean, undef], + 'BinModeOut' => [Parse_boolean, 0], #'Todo - Revert to ordinary file on end Z_STREAM_END'=> 0, # ContinueAfterEof } ; @@ -772,7 +771,7 @@ sub new *$obj->{LineNo} = 0; } - setBinModeInput(*$obj->{FH}, $got->valueOrDefault('BinModeIn')) ; + setBinModeInput(*$obj->{FH}) ; my $buff = "" ; *$obj->{Buffer} = \$buff ; @@ -1048,13 +1047,13 @@ sub _singleTarget if $x->{Got}->value('Append') ; $x->{fh} = new IO::File "$mode $output" or return retErr($x, "cannot open file '$output': $!") ; - setBinModeOutput($x->{fh}, $x->{Got}->valueOrDefault('BinModeOut')); + binmode $x->{fh} if $x->{Got}->valueOrDefault('BinModeOut'); } elsif ($x->{outType} eq 'handle') { $x->{fh} = $output; - setBinModeOutput($x->{fh}, $x->{Got}->valueOrDefault('BinModeOut')); + binmode $x->{fh} if $x->{Got}->valueOrDefault('BinModeOut'); if ($x->{Got}->value('Append')) { seek($x->{fh}, 0, SEEK_END) or return retErr($x, "Cannot seek to end of output filehandle: $!") ; diff --git a/ext/Compress/Zlib/t/09gziphdr.t b/ext/Compress/Zlib/t/09gziphdr.t index 9310e1f..e7b52a0 100644 --- a/ext/Compress/Zlib/t/09gziphdr.t +++ b/ext/Compress/Zlib/t/09gziphdr.t @@ -20,7 +20,7 @@ BEGIN { if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - plan tests => 788 + $extra ; + plan tests => 920 + $extra ; use_ok('Compress::Zlib', 2) ; use_ok('Compress::Gzip::Constants') ; @@ -162,6 +162,37 @@ my $lex = new LexFile $name ; } +for my $value ( "0D", "0A", "0A0D", "0D0A", "0A0A", "0D0D") +{ + title "Comment with $value" ; + + my $v = pack "H*", $value; + my $comment = "my${v}comment$v"; + my $hdr = readHeaderInfo $name, + Time => 0, + -TextFlag => 1, + -Name => "", + -Comment => $comment, + -ExtraField => ""; + my $after = time ; + + is $hdr->{Time}, 0 ; + + ok defined $hdr->{Name} ; + ok $hdr->{Name} eq ""; + ok defined $hdr->{Comment} ; + is $hdr->{Comment}, $comment; + ok defined $hdr->{ExtraFieldRaw} ; + ok $hdr->{ExtraFieldRaw} eq ""; + is $hdr->{ExtraFlags}, 0; + + ok ! $hdr->{isMinimalHeader} ; + ok $hdr->{TextFlag} ; + ok ! defined $hdr->{HeaderCRC} ; + is $hdr->{OsID}, $ThisOS_code ; + +} + { title "Check crchdr" ;