Search code examples
dictionaryzlibdeflate

Q- How to use a Prehistory buffer with deflateSetDictionary


I have a requirement that while doing raw deflate, zlib is provided with a prehistory buffer of 4KB to seed dictionary. The input Data CHUNK Size is also 4KB and prehistory needs to be used for each one of them, and every 4KB data from file is independently compressed. I have doubts about window size and where is Dictionary loaded in Window (at position 0) Following are some questions.

  1. Should my Window size here be 8KB [4KB for Prehistory + 4KB for history produced with Raw Data]
  2. Is it correct that while using deflateSetDictionary, the first 4KB of window will be loaded with Dictionary(pre-history) buffer and next 4KB in window will be filled as raw data is compressed

Solution

    1. Yes, your dictionary size should be at least 8K.
    2. You simply provide 4K of data with deflateSetDictionary(), using the length argument. zlib deals with where it actually goes in the buffer.