Unlike the gzip stream, the bzip2 stream doesn't store the uncompressed
size explicitly:
http://en.wikipedia.org/wiki/Gzip#File_format
http://en.wikipedia.org/wiki/Bzip2#File_format
If you want to limit the size of the decompressed output, try
1. bunzip2 -c FILE.bz2 | head -c NUM_BYTES > FILE
or rather
2. ( ulimit NUM_KILOBYTES && bunzip2 -c FILE.bz2 > FILE )
In case 1, check the exit status of bunzip2 as ${PIPESTATUS[0]} (in bash),
if it's 141 (128 + 13), bunzip2 died with SIGPIPE. In case 2, check the
exit status of bunzip2 as $?, if it's 153 (128 + 25), bunzip2 died with
SIGXFSZ. Delete the truncated output.
I recommend case 2 if you want the output in a file, since there is no
pipe involved. The case against a pipe (or head):
$ head -c 3000 /dev/urandom \
| bzip2 \
| tee >(wc -c >&2) \
| bunzip2 \
| tee >(wc -c >&2) \
| head -c 2000 \
| wc -c >&2
3448
3000
2000
$ echo [EMAIL PROTECTED]
0 0 0 0 0 0 0
Bunzip2 places 3000 bytes into the pipe buffer and exits successfully.
Head copies 2000 and throws away 1000.
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]