سؤال

I am trying to implement an inflate algorithm for deflate-compressed data with static Huffman codes. After reading the specification I came into conclusion that these the steps that I am going to need:

  1. read the block 3-bits header
  2. build Huffman tree based on the specification
  3. decode the Huffman codes
  4. decode the lz77 compressed data

Am I missing steps, or adding unnecessary steps?

هل كانت مفيدة؟

المحلول

#2 requires reading the specification, if there is one, after the first three bits. Those bits indicate if there is a specification, or if you should use the static tree description, or if the data is stored with no compression. In the latter case, you skip steps #2-4 and instead read the block length and complement, and then that number of bytes for that block.

#3 should be: decode the Huffman codes until an end-block code is read.

#4 is done at the same time as #3. As each code is decoded, that action is taken to generate the uncompressed data.

There should be a step #5: if that was not the last block (so marked in the first three bits), then go back to step #1.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top