To clarify, I guess bms might have been misunderstood:

A bz2 file is not called an "archive" exactly because it cannot contain more than one file. bzip2 (like compress, gzip and lzma) can only compress a single file, the archiving of several files into such a compressed file is usually done using tar which in turn cannot compress. This is different from programs like zip, lha or rar that do the archiving and compression all in one. The idea of the Unix-style approach is that any of the compressors can be used for other things than compressing archives too (like in a pipe to compress network transfers) while when you're archiving you can combine tar with any of these compressors for different speed/compression tradeoffs.

Now, do you have a tar.bz2 archive with texts that you want to read or are the texts individually compressed? I suppose it's the former, so you could use Archive::Tar that transparently decompresses compressed tar archives and lets you read individual entries.

Regarding efficiency, it depends. Unlike zip-style archivers that have a table of contents at the end, you have to read a tar archive completely to get the contents. If it contains two files of a gigabyte each, you have to decompress the full two gigs just to get the names, and then again to get the contents. Then it might be worth decompressing it to disk first. If you know the names or know that you need everything though, decompressing on the fly will usually be faster. If the archive is not the British National Corpus or worse, it probably doesn't matter :)


In reply to Re^3: Read multiple text file from bz2 without extract first by mbethke
in thread Read multiple text file from bz2 without extract first by prescott2006

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.