Thread: Some questions about ZLIB

  1. #1
    Guest
    Guest

    Some questions about ZLIB

    I'm currently wrestling with zlib, trying to write a program that extracts gzip archives containing a single (large) text file. I was wondering if anyone here is more familiar with the library and could give me some advice.

    I have succeeded in loading an archive wholly into memory and then decompressing the data piece-wise into a target byte stream. I don't do the latter in a single swoop, because the decompressed data becomes very big; hence my plan to process (and discard) it in steps.

    I noticed that zlib's inflate function appears to ensure that sequential calls to it leave no gaps in the decompressed data, even though I stop the output at an arbitrary number of bytes (my buffer size). So far, so good.

    My question is, can I accomplish the same with an input stream that's read in steps rather than all at once? So far inflate always had the whole stream to work with, allowing it to stop and resume where feasible, probably looking ahead a bit, while giving me a straight forward interface to use.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    I think z_stream's next_in buffer and avail_in can be changed on the fly, between inflate calls. So, it should work.
    ( I haven't touched zlib ever, so take my advice with a grain of salt )

    Quote Originally Posted by zlib manual
    inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full.
    ...
    Before the call of inflate(), the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating the next_* and avail_* values accordingly.
    Last edited by GReaper; 03-01-2016 at 10:47 AM.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zlib, GZip
    By Brandon9000 in forum C Programming
    Replies: 4
    Last Post: 11-28-2012, 05:11 PM
  2. zlib Problems
    By nathanpc in forum C++ Programming
    Replies: 12
    Last Post: 09-06-2009, 11:09 PM
  3. ZLIB help!
    By anthonyfg in forum C Programming
    Replies: 3
    Last Post: 04-09-2008, 06:36 PM
  4. zlib
    By walden in forum C++ Programming
    Replies: 0
    Last Post: 11-18-2003, 06:23 PM
  5. compression: zlib....?
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-23-2003, 02:56 AM