tags:

views:

42

answers:

2

Hi all, I'm currently trying to use the zlib to inflate a source of gzipped data.

It seems that the inflate API in zlib cannot inflate a gzipped data ( The example http://www.zlib.net/zpipe.c fails to read a gzipped file: "zpipe: invalid or incomplete deflate data" ). I noticed that there is a gzopen function in this API, but , as far as I understand, it only works with a filename or a file descriptor.

Can I use this API if my source of gzipped data is stored in memory, in a sql blob, etc... ?

Many Thanks

Pierre

+1  A: 

The gzip format just adds a simple header (and trailer) to a zlib compressed stream. Skipping over the header isn't difficult; the format is documented in RFC 1952.

Matthew Slattery
A: 

As another solution, there's gzdopen - which takes a file descriptor. You can obtain one to read memory with pipe(). You can then use some form of non-blocking file descriptors, or an auxiliary thread to read in data.

You may find this more trouble than it's worth: Matthew Slattery's solution may very well be more viable.

Thanatos