Rizin
unix-like reverse engineering framework and cli tools
|
by Takayuki Matsuoka
blockStreaming_lineByLine.c
is LZ4 Straming API example which implements line by line incremental (de)compression.
Please note the following restrictions :
First of all, allocate "Ring Buffer" for input and LZ4 compressed data buffer for output.
Next (see (1)), read first line to ringbuffer and compress it by LZ4_compress_continue()
. For the first time, LZ4 doesn't know any previous dependencies, so it just compress the line without dependencies and generates compressed line {Out#1} to LZ4 compressed data buffer. After that, write {Out#1} to the file and forward ringbuffer offset.
Do the same things to second line (see (2)). But in this time, LZ4 can use dependency to Line#1 to improve compression ratio. This dependency is called "Prefix mode".
Eventually, we'll reach end of ringbuffer at Line::X (see (4)). This time, we should reset ringbuffer offset. After resetting, at Line::X+1 pointer is not adjacent, but LZ4 still maintain its memory. This is called "External Dictionary Mode".
In Line::X+2 (see (5)), finally LZ4 forget almost all memories but still remains Line::X+1. This is the same situation as Line#2.
Continue these procedure to the end of text file.
Decompression will do reverse order.
Continue these procedure to the end of the compressed file.