lz4

How to decode last block in LZ4


I'm trying to understand how LZ4 compresses the last block in a sequence. According to LZ4 block format, there are specific rules required to terminate a block.

Here is a small example:

Raw Data (a new line character is included at the end):

abcdabcdabcd\n

xxd dump of compressed data that is encapsulated in LZ4 frame (block starts with 0x8061 and end with 0x640a):

00000000: 0422 4d18 6440 a70d 0000 8061 6263 6461  ."M.d@.....abcda
00000010: 6263 6461 6263 640a 0000 0000 8f1a 578b  bcdabcd.......W.

According to the example above, there is only one block and there is no offset in compressed data.

How should I interpret this block?


Solution

  • I've found the solution here.

    The problem arises from my misunderstanding the frame format. The block is not compressed since highest bit of the block size field in the frame is set to one.