_set_gzerr(0) ;
if ($writing) {
- $gz = new IO::Compress::Gzip($file, Minimal => 1, AutoClose => 1, %defOpts)
+ $gz = new IO::Compress::Gzip($file, Minimal => 1, AutoClose => 1,
+ BinModeOut => 1, %defOpts)
or $Compress::Zlib::gzerrno = $IO::Compress::Gzip::GzipError;
}
else {
- $gz = new IO::Uncompress::Gunzip($file, Append => 0, AutoClose => 1, Strict => 0)
+ $gz = new IO::Uncompress::Gunzip($file,
+ Transparent => 1,
+ BinModeIn => 1, Append => 0,
+ AutoClose => 1, Strict => 0)
or $Compress::Zlib::gzerrno = $IO::Uncompress::Gunzip::GunzipError;
}
WANT_HASH
);
-sub setBinModeInput($)
+our ($wantBinmode);
+$wantBinmode = ($] >= 5.006 && eval ' ${^UNICODE} || ${^UTF8LOCALE} ')
+ ? 1 : 0 ;
+
+sub setBinModeInput($$)
{
my $handle = shift ;
+ my $want = defined $_[0] ? shift : $wantBinmode ;
binmode $handle
- unless $^O eq 'MSWin32' && ! ( ${^UNICODE} || ${^UTF8LOCALE} );
+ if $want;
}
-sub setBinModeOutput($)
+sub setBinModeOutput($$)
{
my $handle = shift ;
+ my $want = defined $_[0] ? shift : $wantBinmode ;
binmode $handle
- unless $^O eq 'MSWin32' && ! ( ${^UNICODE} || ${^UTF8LOCALE} );
+ if $want;
}
sub isaFilehandle($)
sub whatIsInput($;$)
{
my $got = whatIs(@_);
- #return $got;
+
if (defined $got && $got eq 'filename' && defined $_[0] && $_[0] eq '-')
{
use IO::File;
sub whatIsOutput($;$)
{
my $got = whatIs(@_);
- #return $got;
+
if (defined $got && $got eq 'filename' && defined $_[0] && $_[0] eq '-')
{
$got = 'handle';
'Strict' => [Parse_boolean, 1],
'Append' => [Parse_boolean, 0],
'Merge' => [Parse_boolean, 0],
+ 'BinModeIn' => [Parse_boolean, undef],
+ 'BinModeOut'=> [Parse_boolean, undef],
# zlib behaviour
#'Method' => [Parse_unsigned, Z_DEFLATED],
'Strict' => [Parse_boolean, 1],
'Append' => [Parse_boolean, 0],
'Merge' => [Parse_boolean, 0],
+ 'BinModeIn' => [Parse_boolean, undef],
+ 'BinModeOut'=> [Parse_boolean, undef],
# zlib behaviour
#'Method' => [Parse_unsigned, Z_DEFLATED],
if ($outType eq 'handle') {
$outValue->flush() ;
*$obj->{FH} = $outValue ;
+ setBinModeOutput(*$obj->{FH}, $got->valueOrDefault('BinModeOut')) ;
*$obj->{Handle} = 1 ;
if ($appendOutput)
{
*$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) {
defined *$obj->{FH}->write(*$obj->{Header}, length(*$obj->{Header}))
or return $obj->saveErrorString(undef, $!, $!) ;
*$obj->{OutputRawDeflate} = $rfc1951;
*$obj->{Output} = $outValue;
*$obj->{ClassName} = $class;
+ *$obj->{Got} = $got;
return $obj ;
}
$fh = new IO::File "<$input"
or return $self->saveErrorString(undef, "cannot open file '$input': $!", $!) ;
}
- setBinModeInput($fh) ;
+ setBinModeInput($fh, *$self->{Got}->valueOrDefault('BinModeIn')) ;
my $status ;
my $buff ;
'Transparent' => [Parse_any, 1],
'Scan' => [Parse_boolean, 0],
'InputLength' => [Parse_unsigned, undef],
-
+ 'BinModeIn' => [Parse_boolean, undef],
+ 'BinModeOut' => [Parse_boolean, undef],
#'Todo - Revert to ordinary file on end Z_STREAM_END'=> 0,
# ContinueAfterEof
} ;
or return $obj->saveErrorString(undef, "cannot open file '$inValue': $!", $!) ;
*$obj->{LineNo} = 0;
}
- # Setting STDIN to binmode causes grief
- setBinModeInput(*$obj->{FH}) ;
+
+ setBinModeInput(*$obj->{FH}, $got->valueOrDefault('BinModeIn')) ;
my $buff = "" ;
*$obj->{Buffer} = \$buff ;
if $x->{Got}->value('Append') ;
$x->{fh} = new IO::File "$mode $output"
or return retErr($x, "cannot open file '$output': $!") ;
- setBinModeOutput($x->{fh});
+ setBinModeOutput($x->{fh}, $x->{Got}->valueOrDefault('BinModeOut'));
}
elsif ($x->{outType} eq 'handle') {
$x->{fh} = $output;
- setBinModeOutput($x->{fh});
+ setBinModeOutput($x->{fh}, $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: $!") ;
my $count = 0 ;
if ($] < 5.005) {
- $count = 340 ;
+ $count = 353 ;
}
else {
- $count = 351 ;
+ $count = 364 ;
}
ok ! defined $ungzip ;
}
+{
+ title "Check all bytes can be handled";
+
+ my $lex = "\r\n" . new LexFile my $name ;
+ my $data = join '', map { chr } 0x00 .. 0xFF;
+ $data .= "\r\nabd\r\n";
+
+ my $fil;
+ ok $fil = gzopen($name, "wb") ;
+ is $fil->gzwrite($data), length $data ;
+ ok ! $fil->gzclose();
+
+ my $input;
+ ok $fil = gzopen($name, "rb") ;
+ is $fil->gzread($input), length $data ;
+ ok ! $fil->gzclose();
+ ok $input eq $data;
+
+ title "Check all bytes can be handled - transparent mode";
+ writeFile($name, $data);
+ ok $fil = gzopen($name, "rb") ;
+ is $fil->gzread($input), length $data ;
+ ok ! $fil->gzclose();
+ ok $input eq $data;
+
+}
+
title 'memGunzip with a gzopen created file';
{
my $name = "test.gz" ;
ok $Func->(\$data, \$out), " $TopType ok";
# corrupt the compressed data
- substr($out, -10, 10) = "x" x 10 ;
+ #substr($out, -10, 10) = "x" x 10 ;
+ substr($out, int(length($out)/3), 10) = 'abcdeabcde';
my $result;
ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
}
my $gz1 = $CompressClass->new($dest, Merge => 1, AutoClose => 1)
- or die "## $GzipError\n";
+ or die "## Error is $$Error\n";
+
#print "YYY\n";
#hexDump($buffer);
#print "XXX\n";
}
+
foreach my $CompressClass ( map { "IO::Compress::$_" } qw( Gzip RawDeflate Deflate) )
{
my $Error = getErrorRef($CompressClass);