6 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError);
8 die "Usage: zipcat file"
13 my $fh = new IO::File "<$file"
14 or die "Cannot open '$file': $!\n";
18 my $FIXED_HEADER_LENGTH = 30 ;
23 ($x = $fh->read($buffer, $FIXED_HEADER_LENGTH)) == $FIXED_HEADER_LENGTH
24 or die "Truncated file top: $x $!\n";
26 my $signature = unpack ("V", substr($buffer, 0, 4));
28 last unless $signature == 0x04034b50;
30 my $compressedMethod = unpack ("v", substr($buffer, 8, 2));
31 my $compressedLength = unpack ("V", substr($buffer, 18, 4));
32 #my $uncompressedLength = unpack ("V", substr($buffer, 22, 4));
33 my $filename_length = unpack ("v", substr($buffer, 26, 2));
34 my $extra_length = unpack ("v", substr($buffer, 28, 2));
36 warn "Compressed Length $compressedLength\n";
38 $fh->read($filename, $filename_length) == $filename_length
39 or die "Truncated file\n";
41 $fh->read($buffer, $extra_length) == $extra_length
42 or die "Truncated file\n";
44 if ($compressedMethod != 8 && $compressedMethod != 0)
46 warn "Skipping file '$filename' - not deflated $compressedMethod\n";
47 $fh->read($buffer, $compressedLength) == $compressedLength
48 or die "Truncated file\n";
52 next if $compressedLength == 0;
54 warn "Writing file '$filename' $compressedMethod\n";
56 mkpath basename $filename;
58 rawinflate $fh => $filename,
60 InputLength => $compressedLength
61 or die "Error uncompressing $file [$filename]: $RawInflateError\n" ;
64 sub decodeLocalFileHeader