1

I'm looking for some code such that I can compress a .txt file to a .gz file and then decmopress the .gz file to stdout.

I need to use zlib - trouble is, I can't really find anything to get started!

I've seen this: How can I easily compress and decompress files using zlib? and this: http://zlib.net/zlib_how.html

but it's not really helping me. If any zlib users out there have any code snippets, it would be most appreciated.

Thanks in advance,

Community
  • 1
  • 1
Eamorr
  • 9,872
  • 34
  • 125
  • 209
  • 2
    The question you linked to has code samples in its answers. What exactly is it you don't understand about them? – Mat Oct 04 '11 at 09:51
  • I know the API is not easy, but take Zlib's full example and take time to understand it: http://zlib.net/zpipe.c – wormsparty Oct 04 '11 at 10:00
  • I tried compressing the example, but when I open the .gz file, all that appears is "my decompressed data" i.e. it doesn't appear to be compressed... – Eamorr Oct 04 '11 at 10:04
  • How did you 'open' it? With an archiver? Sure, it will decompress it for you and show the decompressed data. Call `cat your_file.gz` and see if it's uncompressed or garbage. – wormsparty Oct 04 '11 at 10:07
  • Actually, when I do cat, it's garbage. If I open it with vim, it uncompresses it for me. Thanks! – Eamorr Oct 04 '11 at 10:15
  • Found suitable code at: http://www.gamedev.net/page/resources/_/technical/game-programming/in-memory-data-compression-and-decompression-r2279 Thanks for all the help guys! – Eamorr Oct 04 '11 at 11:12
  • 1
    zlib_how.html is a detailed explanation of zpipe.c. If reading zlib.h, followed by reading zlib_how.html is not helping you get started, then I am at a loss. zpipe.c does almost exactly what you want. It would take very little modification. To make this a good question, you would need to post code with _what you have tried_, what happened, and why you think it didn't work. – Mark Adler Oct 16 '17 at 23:22

0 Answers0