34 # autogenerate the name unless if none supplied
35 $_ = "tst" . $index ++ . ".tmp"
39 for (@_) { 1 while unlink $_ } ;
46 chmod 0777, @{ $self } ;
47 for (@$self) { 1 while unlink $_ } ;
59 foreach (@_) { rmtree $_ }
66 foreach (@$self) { rmtree $_ }
75 if (Compress::Zlib::Common::isaFilehandle($f))
85 or croak "Cannot open $f: $!\n" ;
90 return @strings if wantarray ;
91 return join "", @strings ;
96 foreach (@_) { writeFile($_, '') }
101 my($filename, @strings) = @_ ;
102 1 while unlink $filename ;
103 open (F, ">$filename")
104 or croak "Cannot open $filename: $!\n" ;
115 my ($filename) = shift ;
119 my $fil = gzopen($filename, "rb")
120 or croak "Cannopt open '$filename': $Compress::Zlib::gzerrno" ;
123 while $fil->gzread($line) > 0;
133 if (Compress::Zlib::Common::isaFilehandle($d))
137 elsif (Compress::Zlib::Common::isaFilename($d))
148 $d = '' unless defined $d ;
149 #while (read(STDIN, $data, 16)) {
150 while (my $data = substr($d, 0, 16)) {
151 substr($d, 0, 16) = '' ;
152 printf "# %8.8lx ", $offset;
155 my @array = unpack('C*', $data);
157 printf('%2.2x ', $_);
159 print " " x (16 - @array)
161 $data =~ tr/\0-\37\177-\377/./;
176 ok my $x = new IO::Compress::Gzip $name, %opts
177 or diag "GzipError is $IO::Compress::Gzip::GzipError" ;
178 ok $x->write($string) ;
181 is GZreadFile($name), $string ;
183 ok my $gunz = new IO::Uncompress::Gunzip $name, Strict => 0
184 or diag "GunzipError is $IO::Uncompress::Gunzip::GunzipError" ;
185 ok my $hdr = $gunz->getHeaderInfo();
187 ok $gunz->read($uncomp) ;
188 ok $uncomp eq $string;
196 my ($filename, $uue) = @_ ;
197 return readFile($filename) eq unpack("u", $uue) ;
202 my $compWith = shift ;
205 my %mapping = ( 'IO::Compress::Gzip' => 'IO::Uncompress::Gunzip',
206 'IO::Compress::Gzip::gzip' => 'IO::Uncompress::Gunzip',
207 'IO::Compress::Deflate' => 'IO::Uncompress::Inflate',
208 'IO::Compress::Deflate::deflate' => 'IO::Uncompress::Inflate',
209 'IO::Compress::RawDeflate' => 'IO::Uncompress::RawInflate',
210 'IO::Compress::RawDeflate::rawdeflate' => 'IO::Uncompress::RawInflate',
211 'IO::Compress::Bzip2' => 'IO::Uncompress::Bunzip2',
212 'IO::Compress::Bzip2::bzip2' => 'IO::Uncompress::Bunzip2',
213 'IO::Compress::Zip' => 'IO::Uncompress::Unzip',
214 'IO::Compress::Zip::zip' => 'IO::Uncompress::Unzip',
215 'IO::Compress::Lzop' => 'IO::Uncompress::UnLzop',
216 'IO::Compress::Lzop::lzop' => 'IO::Uncompress::UnLzop',
220 my $obj = $mapping{$compWith}->new( \$buffer, -Append => 1);
221 1 while $obj->read($out) > 0 ;
226 my %ErrorMap = ( 'IO::Compress::Gzip' => \$IO::Compress::Gzip::GzipError,
227 'IO::Compress::Gzip::gzip' => \$IO::Compress::Gzip::GzipError,
228 'IO::Uncompress::Gunzip' => \$IO::Uncompress::Gunzip::GunzipError,
229 'IO::Uncompress::Gunzip::gunzip' => \$IO::Uncompress::Gunzip::GunzipError,
230 'IO::Uncompress::Inflate' => \$IO::Uncompress::Inflate::InflateError,
231 'IO::Uncompress::Inflate::inflate' => \$IO::Uncompress::Inflate::InflateError,
232 'IO::Compress::Deflate' => \$IO::Compress::Deflate::DeflateError,
233 'IO::Compress::Deflate::deflate' => \$IO::Compress::Deflate::DeflateError,
234 'IO::Uncompress::RawInflate' => \$IO::Uncompress::RawInflate::RawInflateError,
235 'IO::Uncompress::RawInflate::rawinflate' => \$IO::Uncompress::RawInflate::RawInflateError,
236 'IO::Uncompress::AnyInflate' => \$IO::Uncompress::AnyInflate::AnyInflateError,
237 'IO::Uncompress::AnyInflate::anyinflate' => \$IO::Uncompress::AnyInflate::AnyInflateError,
238 'IO::Uncompress::AnyUncompress' => \$IO::Uncompress::AnyUncompress::AnyUncompressError,
239 'IO::Uncompress::AnyUncompress::anyUncompress' => \$IO::Uncompress::AnyUncompress::AnyUncompressError,
240 'IO::Compress::RawDeflate' => \$IO::Compress::RawDeflate::RawDeflateError,
241 'IO::Compress::RawDeflate::rawdeflate' => \$IO::Compress::RawDeflate::RawDeflateError,
242 'IO::Compress::Bzip2' => \$IO::Compress::Bzip2::Bzip2Error,
243 'IO::Compress::Bzip2::bzip2' => \$IO::Compress::Bzip2::Bzip2Error,
244 'IO::Uncompress::Bunzip2' => \$IO::Uncompress::Bunzip2::Bunzip2Error,
245 'IO::Uncompress::Bunzip2::bunzip2' => \$IO::Uncompress::Bunzip2::Bunzip2Error,
246 'IO::Compress::Zip' => \$IO::Compress::Zip::ZipError,
247 'IO::Compress::Zip::zip' => \$IO::Compress::Zip::ZipError,
248 'IO::Uncompress::Unzip' => \$IO::Uncompress::Unzip::UnzipError,
249 'IO::Uncompress::Unzip::unzip' => \$IO::Uncompress::Unzip::UnzipError,
250 'IO::Compress::Lzop' => \$IO::Compress::Lzop::LzopError,
251 'IO::Compress::Lzop::lzop' => \$IO::Compress::Lzop::LzopError,
252 'IO::Uncompress::UnLzop' => \$IO::Uncompress::UnLzop::UnLzopError,
253 'IO::Uncompress::UnLzop::unlzop' => \$IO::Uncompress::UnLzop::UnLzopError,
256 my %TopFuncMap = ( 'IO::Compress::Gzip' => 'IO::Compress::Gzip::gzip',
257 'IO::Uncompress::Gunzip' => 'IO::Uncompress::Gunzip::gunzip',
259 'IO::Compress::Deflate' => 'IO::Compress::Deflate::deflate',
260 'IO::Uncompress::Inflate' => 'IO::Uncompress::Inflate::inflate',
262 'IO::Compress::RawDeflate' => 'IO::Compress::RawDeflate::rawdeflate',
263 'IO::Uncompress::RawInflate' => 'IO::Uncompress::RawInflate::rawinflate',
265 'IO::Uncompress::AnyInflate' => 'IO::Uncompress::AnyInflate::anyinflate',
266 'IO::Uncompress::AnyUncompress' => 'IO::Uncompress::AnyUncompress::anyuncompress',
268 'IO::Compress::Bzip2' => 'IO::Compress::Bzip2::bzip2',
269 'IO::Uncompress::Bunzip2' => 'IO::Uncompress::Bunzip2::bunzip2',
271 'IO::Compress::Zip' => 'IO::Compress::Zip::zip',
272 'IO::Uncompress::Unzip' => 'IO::Uncompress::Unzip::unzip',
273 'IO::Compress::Lzop' => 'IO::Compress::Lzop::lzop',
274 'IO::Uncompress::UnLzop' => 'IO::Uncompress::UnLzop::unlzop',
277 %TopFuncMap = map { ($_ => $TopFuncMap{$_},
278 $TopFuncMap{$_} => $TopFuncMap{$_}) }
281 #%TopFuncMap = map { ($_ => \&{ $TopFuncMap{$_} ) }
285 my %inverse = ( 'IO::Compress::Gzip' => 'IO::Uncompress::Gunzip',
286 'IO::Compress::Gzip::gzip' => 'IO::Uncompress::Gunzip::gunzip',
287 'IO::Compress::Deflate' => 'IO::Uncompress::Inflate',
288 'IO::Compress::Deflate::deflate' => 'IO::Uncompress::Inflate::inflate',
289 'IO::Compress::RawDeflate' => 'IO::Uncompress::RawInflate',
290 'IO::Compress::RawDeflate::rawdeflate' => 'IO::Uncompress::RawInflate::rawinflate',
291 'IO::Compress::Bzip2::bzip2' => 'IO::Uncompress::Bunzip2::bunzip2',
292 'IO::Compress::Bzip2' => 'IO::Uncompress::Bunzip2',
293 'IO::Compress::Zip::zip' => 'IO::Uncompress::Unzip::unzip',
294 'IO::Compress::Zip' => 'IO::Uncompress::Unzip',
295 'IO::Compress::Lzop::lzop' => 'IO::Uncompress::UnLzop::unlzop',
296 'IO::Compress::Lzop' => 'IO::Uncompress::UnLzop',
299 %inverse = map { ($_ => $inverse{$_}, $inverse{$_} => $_) } keys %inverse;
305 return $inverse{$class} ;
312 return $ErrorMap{$class} ;
319 return \&{ $TopFuncMap{$class} } ;
326 return $TopFuncMap{$class} ;
331 my $compWith = shift ;
334 my %mapping = ( 'IO::Uncompress::Gunzip' => 'IO::Compress::Gzip',
335 'IO::Uncompress::Gunzip::gunzip' => 'IO::Compress::Gzip',
336 'IO::Uncompress::Inflate' => 'IO::Compress::Deflate',
337 'IO::Uncompress::Inflate::inflate' => 'IO::Compress::Deflate',
338 'IO::Uncompress::RawInflate' => 'IO::Compress::RawDeflate',
339 'IO::Uncompress::RawInflate::rawinflate' => 'IO::Compress::RawDeflate',
340 'IO::Uncompress::Bunzip2' => 'IO::Compress::Bzip2',
341 'IO::Uncompress::Bunzip2::bunzip2' => 'IO::Compress::Bzip2',
342 'IO::Uncompress::Unzip' => 'IO::Compress::Zip',
343 'IO::Uncompress::Unzip::unzip' => 'IO::Compress::Zip',
344 'IO::Uncompress::UnLzop' => 'IO::Compress::Lzop',
345 'IO::Uncompress::UnLzop::unlzop' => 'IO::Compress::Lzop',
346 'IO::Uncompress::AnyInflate' => 'IO::Compress::Gzip',
347 'IO::Uncompress::AnyInflate::anyinflate' => 'IO::Compress::Gzip',
348 'IO::Uncompress::AnyUncompress' => 'IO::Compress::Gzip',
349 'IO::Uncompress::AnyUncompress::anyuncompress' => 'IO::Compress::Gzip',
353 my $obj = $mapping{$compWith}->new( \$out);
354 $obj->write($buffer) ;
360 use IO::Uncompress::AnyUncompress qw($AnyUncompressError);
367 if (ref $buffer && ref $buffer eq 'ARRAY')
370 $buffer = shift @opts;
375 croak "buffer is undef" unless defined $$buffer;
376 croak "buffer is empty" unless length $$buffer;
382 if (Compress::Zlib::Common::isaFilehandle($buffer))
384 $data = readFile($buffer);
386 elsif (Compress::Zlib::Common::isaFilename($buffer))
388 $data = readFile($buffer);
395 if (defined $already && length $already)
398 my $got = substr($data, 0, length($already));
399 substr($data, 0, length($already)) = '';
401 is $got, $already, ' Already OK' ;
405 my $o = new IO::Uncompress::AnyUncompress \$data, -Append => 1, Transparent => 0, @opts
406 or croak "Cannot open buffer/file: $AnyUncompressError" ;
408 1 while $o->read($out) > 0 ;
410 croak "Error uncompressing -- " . $o->error()
423 if (ref $buffer && ref $buffer eq 'ARRAY')
426 $buffer = shift @opts;
431 croak "buffer is undef" unless defined $$buffer;
432 croak "buffer is empty" unless length $$buffer;
438 if (Compress::Zlib::Common::isaFilehandle($buffer))
440 $data = readFile($buffer);
442 elsif (Compress::Zlib::Common::isaFilename($buffer))
444 $data = readFile($buffer);
451 if (defined $already && length $already)
454 my $got = substr($data, 0, length($already));
455 substr($data, 0, length($already)) = '';
457 is $got, $already, ' Already OK' ;
461 my $o = new IO::Uncompress::AnyUncompress \$data, MultiStream => 1, -Append => 1, Transparent => 0, @opts
462 or croak "Cannot open buffer/file: $AnyUncompressError" ;
464 1 while $o->read($out) > 0 ;
466 croak "Error uncompressing -- " . $o->error()
469 return ($o->getHeaderInfo()) ;
477 my $Error = getErrorRef($class);
482 if ($class eq 'IO::Compress::Gzip') {
485 -Comment => "a comment",
486 -ExtraField => ['ab' => "extra"],
489 elsif ($class eq 'IO::Compress::Zip'){
491 # TODO -- add more here
493 -Comment => "a comment",
497 my $z = new $class( \$buffer, %params)
498 or croak "Cannot create $class object: $$Error";
502 my $unc = getInverse($class);
503 my $u = new $unc( \$buffer);
504 my $info = $u->getHeaderInfo() ;
507 return wantarray ? ($info, $buffer) : $buffer ;
513 my ($dummy, $file, $line) = caller ;
516 $file = quotemeta($file);
518 return "/$string\\s+at $file line $line/" if $] >= 5.006 ;
519 return "/$string\\s+at /" ;
526 return "/$string\\s+at \\(eval /" if $] > 5.006 ;
527 return "/$string\\s+at /" ;
534 my ($dummy, $file, $line) = caller ;
538 print "#\n# dumpOBJ from $file line $line @_\n" ;
542 print "#\n# dumpOBJ from $file line $line \n" ;
546 foreach my $k (keys %{ *$obj })
548 $max = length $k if length $k > $max ;
551 foreach my $k (sort keys %{ *$obj })
554 $v = '-undef-' unless defined $v;
555 my $pad = ' ' x ($max - length($k) + 2) ;
556 print "# $k$pad: [$v]\n";
562 package ZlibTestUtils;