0

At the very end of inflate() method, I put a log indicating state->last is LAST, and I do see that log about 3 times at the end of successful uncompression, resulting in some 289MB file. I was hoping to see that log per some block, more than 3 times.

 inf_leave:

    strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
                      (state->mode == TYPE ? 128 : 0) +
                      (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
                      **if(state->last) fprintf(stderr, "Fernando: %s() its LAST\n",__func__);**

Bit of background, I am using WinZip to compress and archive the input files, then inside unzip.c's unzReadCurrentFile() calls zlib's inflate(, Z_BLOCK). I am experimenting on Windows. unzOpenCurrentFile() does prepare some stream fields before calling inflateInit2().

So bit perplexed why deflate block boundary is not logged somewhat periodically, I realize there is that unzip.c layer between the application and zlib library.

As detecting the deflate boundary is the first step, so putting some minimum logs to understand how often block boundaries are seen, and of course use of Z_BLOCK in inflate call, also working with a medium size files. Obviously eventual goal is to continue uncompresssion over a reboot.

Appreciate any feedbacks.

1 Answers1

0

First off, don't modify zlib. Especially when you don't need to. You can see three lines up that zlib is returning exactly that information in strm->data_type, in particular in bit 6. You can check that after inflate() returns.

Second, what you are looking at is a flag that says you are in the last deflate block of all of the deflate blocks. It has nothing to do with deflate block boundaries. (When you see that along with a deflate block boundary, then you know this one is the last deflate block in the stream.) If you want to know when a deflate block has ended, you need to look at bit 7 of strm->data_type. If that is true, then you just finished a deflate block. You will see many of those.

This is clearly documented in zlib.h. Read all of zlib.h. More than once. You will need a thorough understanding to do what you're trying to do.

The Z_BLOCK option assists in appending to or combining deflate streams. To assist in this, on return inflate() always sets strm->data_type to the number of unused bits in the last byte taken from strm->next_in, plus 64 if inflate() is currently decoding the last block in the deflate stream, plus 128 if inflate() returned immediately after decoding an end-of-block code or decoding the complete header up to just before the first byte of the deflate stream.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • "Read all of zlib.h. More than once", yes definitely I need to understand it more, and checking bit 7 gives me some 5630 lines of logs, suggesting some 23kb per deflate block size. Thanks a lot Mark. – Anton Fernando Nov 23 '22 at 01:27