Home > Enterprise >  How to decompress gzip stream
How to decompress gzip stream

Time:03-19

I would like to send data over a network which is gzip compressed. The data is sent in chunks from a C# server which compresses it using a stream compressor before it sends. I would like the C client to be able to decompress the data as it comes in and write it to a file. I have looked alot over the internet but have not come up with a good solution as of now. Methods I have found of doing this don't seem to decompress it as a stream but rather as an entire char array, which is an issue because of the amount of memory the data takes up.

CodePudding user response:

This is exactly what zlib is for. It is a C library that supports decompressing whatever size chunks at a time you like, delivering as much uncompressed data as can be extracted so far.

CodePudding user response:

Not tested, but I would launch gzip as a subprocess, fed by its standard input, and you read from its standard output the decompressed stream.

You need to either redirect the source stream to gzip's stdin, or to pump it "manually" from your program.

How you launch a subprocess and hook its standard streams is usually at least partially platform-dependent, so we'll need details for a more detailled answer.

For example, if you use C on Windows or on Linux, "piping" data to a subprocess is a bit different, and it's even more different if you use a framework like Qt.

  • Related