0

When I save the 'state of uncompression', I also need to save: "location in the compressed data, which is both a byte offset and bit offset within that byte".

After a reboot, along with inflateSetDictionary(), I call inflatePrime() as below, "to feed the bits from the byte at the compressed data offset".

inflatePrime ( , streamBits, streamCurrentPos)

Both APIs return Z_OK, but params to inflatePrime(), I am bit uncertain.

This is how I gathered them:

typedef struct state_of_uncompression
{
  uInt streamCurrentPos;      // Missing this, tried the output from unzGetCurrentFileZStreamPos64()
  int  streamBits;            // from : stream.data_type, after clearing bits 8,7,6: stream.data_type & (~0x1C0)
  Byte dictionary_buf[32768]; // from : inflateGetDictionary()
  uInt dictLength;            // from : inflateGetDictionary();
  uint64_t output_wrt_offset  // got this already. 
} uncompression_state_info;

So after the reboot, the plan is to recontinue the uncompression, but inflate() returns Z_STREAM_END inside unzReadCurrentFile(), as if, inflate() doesn't know where to restart from.

Thanks appreciate any feedback.

1 Answers1

0

The third argument to inflatePrime() is not a position. It is the actual bits to insert, which you need to get from the compressed data. You use fseek() or lseek() to go to the byte offset in the file, where you saved that offset as part of your entry point information. You get that byte, which advances the file pointer to the next byte, and shift down by the number of bits you are not providing, i.e. 8 minus the second argument. That's the third argument. The second argument is always in 1..7. If there are no bits to insert, then you don't call inflatePrime(), and just leave the file pointer where it is to begin inflating.

The position in your state should be a 64-bit value, not a 32-bit value as you currently have it.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158