I wondered how this might be achieved so decided to have a go. I prepared a ZIP archive containing three bzip2'ed files (man page outputs) stored without further compression.

$ man ls > ls.man $ man xterm > xterm.man $ man cp > cp.man $ bzip2 -v *.man cp.man: 2.496:1, 3.206 bits/byte, 59.93% saved, 5690 in, 2280 o +ut. ls.man: 2.644:1, 3.026 bits/byte, 62.18% saved, 8093 in, 3061 o +ut. xterm.man: 5.062:1, 1.580 bits/byte, 80.24% saved, 264279 in, 5221 +0 out. $ zip -0m mans *.man.bz2 adding: cp.man.bz2 (stored 0%) adding: ls.man.bz2 (stored 0%) adding: xterm.man.bz2 (stored 0%) $

The following script constructs an Archive::Zip object to access the ZIP file and gets a list of member files. Then for each member it creates a member object and uses that to obtain the content. A reference to this content, by way of an on-the-fly subroutine, is used as the argument to the IO::Uncompress::Bunzip2 constructor which can then be read line by line. I just print the first five lines of each member file to demonstrate that the method works. I have not incorporated any error checking, this is left as an exercise for the reader.

use strict; use warnings; use 5.014; use Archive::Zip; use IO::Uncompress::Bunzip2; my $zipFile = q{mans.zip}; my $zip = Archive::Zip->new( $zipFile ); my @members = $zip->memberNames(); foreach my $member ( @members ) { say qq{Member: $member}; my $memberFH = $zip->memberNamed( $member ); my $bzFH = IO::Uncompress::Bunzip2->new( sub { \ $_[ 0 ] }->( $memberFH->contents() ) ); my $lineCt = 0; while ( my $line = $bzFH->getline() ) { last if $lineCt ++ > 5; print $line; } }

The output.

Member: cp.man.bz2 CP(1) User Commands + CP(1) NAME cp - copy files and directories Member: ls.man.bz2 LS(1) User Commands + LS(1) NAME ls - list directory contents Member: xterm.man.bz2 XTERM(1) X Window System + XTERM(1) NAME xterm - terminal emulator for X

I hope this is useful.

Cheers,

JohnGG


In reply to Re: reading zipped bzipped files! by johngg
in thread reading zipped bzipped files! by mike_gerard

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.