35 # autogenerate the name unless if none supplied
36 $_ = "tst" . $index ++ . ".tmp"
40 for (@_) { 1 while unlink $_ } ;
47 chmod 0777, @{ $self } ;
48 for (@$self) { 1 while unlink $_ } ;
60 foreach (@_) { rmtree $_ }
67 foreach (@$self) { rmtree $_ }
76 if (IO::Compress::Base::Common::isaFilehandle($f))
86 or croak "Cannot open $f: $!\n" ;
92 return @strings if wantarray ;
93 return join "", @strings ;
98 foreach (@_) { writeFile($_, '') }
103 my($filename, @strings) = @_ ;
104 1 while unlink $filename ;
105 open (F, ">$filename")
106 or croak "Cannot open $filename: $!\n" ;
117 my ($filename) = shift ;
121 my $fil = gzopen($filename, "rb")
122 or croak "Cannopt open '$filename': $Compress::Zlib::gzerrno" ;
125 while $fil->gzread($line) > 0;
135 if (IO::Compress::Base::Common::isaFilehandle($d))
139 elsif (IO::Compress::Base::Common::isaFilename($d))
150 $d = '' unless defined $d ;
151 #while (read(STDIN, $data, 16)) {
152 while (my $data = substr($d, 0, 16)) {
153 substr($d, 0, 16) = '' ;
154 printf "# %8.8lx ", $offset;
157 my @array = unpack('C*', $data);
159 printf('%2.2x ', $_);
161 print " " x (16 - @array)
163 $data =~ tr/\0-\37\177-\377/./;
178 ok my $x = new IO::Compress::Gzip $name, %opts
179 or diag "GzipError is $IO::Compress::Gzip::GzipError" ;
180 ok $x->write($string) ;
183 #is GZreadFile($name), $string ;
185 ok my $gunz = new IO::Uncompress::Gunzip $name, Strict => 0
186 or diag "GunzipError is $IO::Uncompress::Gunzip::GunzipError" ;
187 ok my $hdr = $gunz->getHeaderInfo();
189 ok $gunz->read($uncomp) ;
190 ok $uncomp eq $string;
198 my ($filename, $uue) = @_ ;
199 return readFile($filename) eq unpack("u", $uue) ;
204 my $compWith = shift ;
207 my %mapping = ( 'IO::Compress::Gzip' => 'IO::Uncompress::Gunzip',
208 'IO::Compress::Gzip::gzip' => 'IO::Uncompress::Gunzip',
209 'IO::Compress::Deflate' => 'IO::Uncompress::Inflate',
210 'IO::Compress::Deflate::deflate' => 'IO::Uncompress::Inflate',
211 'IO::Compress::RawDeflate' => 'IO::Uncompress::RawInflate',
212 'IO::Compress::RawDeflate::rawdeflate' => 'IO::Uncompress::RawInflate',
213 'IO::Compress::Bzip2' => 'IO::Uncompress::Bunzip2',
214 'IO::Compress::Bzip2::bzip2' => 'IO::Uncompress::Bunzip2',
215 'IO::Compress::Zip' => 'IO::Uncompress::Unzip',
216 'IO::Compress::Zip::zip' => 'IO::Uncompress::Unzip',
217 'IO::Compress::Lzop' => 'IO::Uncompress::UnLzop',
218 'IO::Compress::Lzop::lzop' => 'IO::Uncompress::UnLzop',
219 'IO::Compress::DummyComp' => 'IO::Uncompress::DummyUncomp',
220 'IO::Compress::DummyComp::dummycomp' => 'IO::Uncompress::DummyUncomp',
224 my $obj = $mapping{$compWith}->new( \$buffer, -Append => 1);
225 1 while $obj->read($out) > 0 ;
230 my %ErrorMap = ( 'IO::Compress::Gzip' => \$IO::Compress::Gzip::GzipError,
231 'IO::Compress::Gzip::gzip' => \$IO::Compress::Gzip::GzipError,
232 'IO::Uncompress::Gunzip' => \$IO::Uncompress::Gunzip::GunzipError,
233 'IO::Uncompress::Gunzip::gunzip' => \$IO::Uncompress::Gunzip::GunzipError,
234 'IO::Uncompress::Inflate' => \$IO::Uncompress::Inflate::InflateError,
235 'IO::Uncompress::Inflate::inflate' => \$IO::Uncompress::Inflate::InflateError,
236 'IO::Compress::Deflate' => \$IO::Compress::Deflate::DeflateError,
237 'IO::Compress::Deflate::deflate' => \$IO::Compress::Deflate::DeflateError,
238 'IO::Uncompress::RawInflate' => \$IO::Uncompress::RawInflate::RawInflateError,
239 'IO::Uncompress::RawInflate::rawinflate' => \$IO::Uncompress::RawInflate::RawInflateError,
240 'IO::Uncompress::AnyInflate' => \$IO::Uncompress::AnyInflate::AnyInflateError,
241 'IO::Uncompress::AnyInflate::anyinflate' => \$IO::Uncompress::AnyInflate::AnyInflateError,
242 'IO::Uncompress::AnyUncompress' => \$IO::Uncompress::AnyUncompress::AnyUncompressError,
243 'IO::Uncompress::AnyUncompress::anyUncompress' => \$IO::Uncompress::AnyUncompress::AnyUncompressError,
244 'IO::Compress::RawDeflate' => \$IO::Compress::RawDeflate::RawDeflateError,
245 'IO::Compress::RawDeflate::rawdeflate' => \$IO::Compress::RawDeflate::RawDeflateError,
246 'IO::Compress::Bzip2' => \$IO::Compress::Bzip2::Bzip2Error,
247 'IO::Compress::Bzip2::bzip2' => \$IO::Compress::Bzip2::Bzip2Error,
248 'IO::Uncompress::Bunzip2' => \$IO::Uncompress::Bunzip2::Bunzip2Error,
249 'IO::Uncompress::Bunzip2::bunzip2' => \$IO::Uncompress::Bunzip2::Bunzip2Error,
250 'IO::Compress::Zip' => \$IO::Compress::Zip::ZipError,
251 'IO::Compress::Zip::zip' => \$IO::Compress::Zip::ZipError,
252 'IO::Uncompress::Unzip' => \$IO::Uncompress::Unzip::UnzipError,
253 'IO::Uncompress::Unzip::unzip' => \$IO::Uncompress::Unzip::UnzipError,
254 'IO::Compress::Lzop' => \$IO::Compress::Lzop::LzopError,
255 'IO::Compress::Lzop::lzop' => \$IO::Compress::Lzop::LzopError,
256 'IO::Uncompress::UnLzop' => \$IO::Uncompress::UnLzop::UnLzopError,
257 'IO::Uncompress::UnLzop::unlzop' => \$IO::Uncompress::UnLzop::UnLzopError,
259 'IO::Compress::DummyComp' => \$IO::Compress::DummyComp::DummyCompError,
260 'IO::Compress::DummyComp::dummycomp'=> \$IO::Compress::DummyComp::DummyCompError,
261 'IO::Uncompress::DummyUncomp' => \$IO::Uncompress::DummyUncomp::DummyUncompError,
262 'IO::Uncompress::DummyUncomp::dummyuncomp' => \$IO::Uncompress::DummyUncomp::DummyUncompError,
265 my %TopFuncMap = ( 'IO::Compress::Gzip' => 'IO::Compress::Gzip::gzip',
266 'IO::Uncompress::Gunzip' => 'IO::Uncompress::Gunzip::gunzip',
268 'IO::Compress::Deflate' => 'IO::Compress::Deflate::deflate',
269 'IO::Uncompress::Inflate' => 'IO::Uncompress::Inflate::inflate',
271 'IO::Compress::RawDeflate' => 'IO::Compress::RawDeflate::rawdeflate',
272 'IO::Uncompress::RawInflate' => 'IO::Uncompress::RawInflate::rawinflate',
274 'IO::Uncompress::AnyInflate' => 'IO::Uncompress::AnyInflate::anyinflate',
275 'IO::Uncompress::AnyUncompress' => 'IO::Uncompress::AnyUncompress::anyuncompress',
277 'IO::Compress::Bzip2' => 'IO::Compress::Bzip2::bzip2',
278 'IO::Uncompress::Bunzip2' => 'IO::Uncompress::Bunzip2::bunzip2',
280 'IO::Compress::Zip' => 'IO::Compress::Zip::zip',
281 'IO::Uncompress::Unzip' => 'IO::Uncompress::Unzip::unzip',
282 'IO::Compress::Lzop' => 'IO::Compress::Lzop::lzop',
283 'IO::Uncompress::UnLzop' => 'IO::Uncompress::UnLzop::unlzop',
284 'IO::Compress::DummyComp' => 'IO::Compress::DummyComp::dummyuncomp',
285 'IO::Uncompress::DummyUncomp' => 'IO::Uncompress::DummyUncomp::dummyuncomp',
288 %TopFuncMap = map { ($_ => $TopFuncMap{$_},
289 $TopFuncMap{$_} => $TopFuncMap{$_}) }
292 #%TopFuncMap = map { ($_ => \&{ $TopFuncMap{$_} ) }
296 my %inverse = ( 'IO::Compress::Gzip' => 'IO::Uncompress::Gunzip',
297 'IO::Compress::Gzip::gzip' => 'IO::Uncompress::Gunzip::gunzip',
298 'IO::Compress::Deflate' => 'IO::Uncompress::Inflate',
299 'IO::Compress::Deflate::deflate' => 'IO::Uncompress::Inflate::inflate',
300 'IO::Compress::RawDeflate' => 'IO::Uncompress::RawInflate',
301 'IO::Compress::RawDeflate::rawdeflate' => 'IO::Uncompress::RawInflate::rawinflate',
302 'IO::Compress::Bzip2::bzip2' => 'IO::Uncompress::Bunzip2::bunzip2',
303 'IO::Compress::Bzip2' => 'IO::Uncompress::Bunzip2',
304 'IO::Compress::Zip::zip' => 'IO::Uncompress::Unzip::unzip',
305 'IO::Compress::Zip' => 'IO::Uncompress::Unzip',
306 'IO::Compress::Lzop::lzop' => 'IO::Uncompress::UnLzop::unlzop',
307 'IO::Compress::Lzop' => 'IO::Uncompress::UnLzop',
308 'IO::Compress::DummyComp::dummycomp' => 'IO::Uncompress::DummyUncomp::dummyuncomp',
309 'IO::Compress::DummyComp' => 'IO::Uncompress::DummyUncomp',
312 %inverse = map { ($_ => $inverse{$_}, $inverse{$_} => $_) } keys %inverse;
318 return $inverse{$class} ;
325 return $ErrorMap{$class} ;
332 return \&{ $TopFuncMap{$class} } ;
339 return $TopFuncMap{$class} ;
344 my $compWith = shift ;
347 my %mapping = ( 'IO::Uncompress::Gunzip' => 'IO::Compress::Gzip',
348 'IO::Uncompress::Gunzip::gunzip' => 'IO::Compress::Gzip',
349 'IO::Uncompress::Inflate' => 'IO::Compress::Deflate',
350 'IO::Uncompress::Inflate::inflate' => 'IO::Compress::Deflate',
351 'IO::Uncompress::RawInflate' => 'IO::Compress::RawDeflate',
352 'IO::Uncompress::RawInflate::rawinflate' => 'IO::Compress::RawDeflate',
353 'IO::Uncompress::Bunzip2' => 'IO::Compress::Bzip2',
354 'IO::Uncompress::Bunzip2::bunzip2' => 'IO::Compress::Bzip2',
355 'IO::Uncompress::Unzip' => 'IO::Compress::Zip',
356 'IO::Uncompress::Unzip::unzip' => 'IO::Compress::Zip',
357 'IO::Uncompress::UnLzop' => 'IO::Compress::Lzop',
358 'IO::Uncompress::UnLzop::unlzop' => 'IO::Compress::Lzop',
359 'IO::Uncompress::AnyInflate' => 'IO::Compress::Gzip',
360 'IO::Uncompress::AnyInflate::anyinflate' => 'IO::Compress::Gzip',
361 'IO::Uncompress::AnyUncompress' => 'IO::Compress::Gzip',
362 'IO::Uncompress::AnyUncompress::anyuncompress' => 'IO::Compress::Gzip',
363 'IO::Uncompress::DummyUncomp' => 'IO::Compress::DummyComp',
364 'IO::Uncompress::DummyUncomp::dummyuncomp'=> 'IO::Compress::DummyComp',
368 my $obj = $mapping{$compWith}->new( \$out);
369 $obj->write($buffer) ;
374 our ($AnyUncompressError);
377 eval { require IO::Uncompress::AnyUncompress ;
378 import IO::Uncompress::AnyUncompress qw($AnyUncompressError) } ;
387 if (ref $buffer && ref $buffer eq 'ARRAY')
390 $buffer = shift @opts;
395 croak "buffer is undef" unless defined $$buffer;
396 croak "buffer is empty" unless length $$buffer;
402 if (IO::Compress::Base::Common::isaFilehandle($buffer))
404 $data = readFile($buffer);
406 elsif (IO::Compress::Base::Common::isaFilename($buffer))
408 $data = readFile($buffer);
415 if (defined $already && length $already)
418 my $got = substr($data, 0, length($already));
419 substr($data, 0, length($already)) = '';
421 is $got, $already, ' Already OK' ;
425 my $o = new IO::Uncompress::AnyUncompress \$data, -Append => 1, Transparent => 0, @opts
426 or croak "Cannot open buffer/file: $AnyUncompressError" ;
428 1 while $o->read($out) > 0 ;
430 croak "Error uncompressing -- " . $o->error()
443 if (ref $buffer && ref $buffer eq 'ARRAY')
446 $buffer = shift @opts;
451 croak "buffer is undef" unless defined $$buffer;
452 croak "buffer is empty" unless length $$buffer;
458 if (IO::Compress::Base::Common::isaFilehandle($buffer))
460 $data = readFile($buffer);
462 elsif (IO::Compress::Base::Common::isaFilename($buffer))
464 $data = readFile($buffer);
471 if (defined $already && length $already)
474 my $got = substr($data, 0, length($already));
475 substr($data, 0, length($already)) = '';
477 is $got, $already, ' Already OK' ;
481 my $o = new IO::Uncompress::AnyUncompress \$data, MultiStream => 1, -Append => 1, Transparent => 0, @opts
482 or croak "Cannot open buffer/file: $AnyUncompressError" ;
484 1 while $o->read($out) > 0 ;
486 croak "Error uncompressing -- " . $o->error()
489 return ($o->getHeaderInfo()) ;
497 my $Error = getErrorRef($class);
502 if ($class eq 'IO::Compress::Gzip') {
505 Comment => "a comment",
506 ExtraField => ['ab' => "extra"],
509 elsif ($class eq 'IO::Compress::Zip'){
512 Comment => "a comment",
513 ZipComment => "last comment",
514 exTime => [100, 200, 300],
515 ExtraFieldLocal => ["ab" => "extra1"],
516 ExtraFieldCentral => ["cd" => "extra2"],
520 my $z = new $class( \$buffer, %params)
521 or croak "Cannot create $class object: $$Error";
525 my $unc = getInverse($class);
526 anyUncompress(\$buffer) eq $data
527 or die "bad bad bad";
528 my $u = new $unc( \$buffer);
529 my $info = $u->getHeaderInfo() ;
532 return wantarray ? ($info, $buffer) : $buffer ;
538 my ($dummy, $file, $line) = caller ;
541 $file = quotemeta($file);
543 return "/$string\\s+at $file line $line/" if $] >= 5.006 ;
544 return "/$string\\s+at /" ;
551 return "/$string\\s+at \\(eval /" if $] > 5.006 ;
552 return "/$string\\s+at /" ;
559 my ($dummy, $file, $line) = caller ;
563 print "#\n# dumpOBJ from $file line $line @_\n" ;
567 print "#\n# dumpOBJ from $file line $line \n" ;
571 foreach my $k (keys %{ *$obj })
573 $max = length $k if length $k > $max ;
576 foreach my $k (sort keys %{ *$obj })
579 $v = '-undef-' unless defined $v;
580 my $pad = ' ' x ($max - length($k) + 2) ;
581 print "# $k$pad: [$v]\n";
587 package CompTestUtils;