tags:

views:

92

answers:

1

Hi,

I would like to know how to determine how many zlib files are contained in a single file.

An example; Think I have 5 different files, and compressed them separately by using zlib. Then I combined them. So, I have one file contains 5 different zlib files. Now, how can I find how many zlib files are in that single file? I just need to find out the number of zlib files in a single file. I guess, I need to dump its hex code and grep some magic number, but could not figure out how to do that.

Could you help me out?

Thanks in advance,

A: 

The length of a block is not stored in the zlib encoded data (with the exception of non-compressed block). Instead the end of a block is signified by a token [256] in the stream. But this token is Huffman encoded and the Huffman encoding is usually dynamically generated so it can be different for each block. Furthermore the encoded token might start on any bit of the byte so there is no way to "grep" it. The only way to find the end of block token is to decode the entire block and check to see when you hit this token.

I think instead you should see if your container includes any length information and use that to find out how long the compressed data is.

For details of the zlib format see RFC 1950, and the related DEFLATE specification which is RFC 1951.

Mark Byers
Yes I know. Let me put it this way; I have a container that has multiple zlib files. How can I find how many zlib files are in that container?
merinn
@merinn: What "container" are you using? I think the format of the container is more important than the format of zlib.
Mark Byers
@merinn: Zlib doesn't compress files - it compresses data. There is no such thing as a 'zlib file'.
Mark Byers