bzip2 compresses the data in blocks, where each block starts with a magic number 1AY&SY.
Can we determine the size of uncompressed data behind each block??
One way to do is to decompress the bzip2 file block-by-block and then find the size of each decompressed block. BUT I am trying to find a way which does not involve decompression and I can learn the size of uncompressed block during compression time.
The use case of it is that we need to tell the decompressing tool what would be the maximum size of decompressed block, so that it allocates sufficient memory. The decompression will be done in an embedded platform, so we have limited resources.
bzip2 header format for a block also does not contain any information about what will be the size of decompressed block. See wikipedia page for the bzip2 file format.
Note: I need a solution in terms of code in C, as I am using bzip2 in my console app developed in C and it runs on Linux and Windows both.
bzip2 header format for a block also does not contain any information about what will be the size of decompressed block. See wikipedia page for the bzip2 file format.
The above statement answers your own question. You can't because it's not available before decompression. It does not encode the block size before compression anywhere in the header, comfirmed here...
http://www.forensicswiki.org/wiki/Bzip2
You must decompress each bloc in order to know it's size.