# LZ4 API Example : Dictionary Random Access
dictionaryRandomAccess.c
is LZ4 API example which implements dictionary compression and random access decompression.
Please note that the output file is not compatible with lz4frame and is platform dependent.
Reads the dictionary from a file, and uses it as the history for each block. This allows each block to be independent, but maintains compression ratio.
Dictionary + | v +---------+ | Block#1 | +----+----+ | v {Out#1} Dictionary + | v +---------+ | Block#2 | +----+----+ | v {Out#2}
After writing the magic bytes TEST
and then the compressed blocks, write out the jump table. The last 4 bytes is an integer containing the number of blocks in the stream. If there are N
blocks, then just before the last 4 bytes is N + 1
4 byte integers containing the offsets at the beginning and end of each block. Let Offset#K
be the total number of bytes written after writing out Block#K
including the magic bytes for simplicity.
+------+---------+ +---------+---+----------+ +----------+-----+ | TEST | Block#1 | ... | Block#N | 4 | Offset#1 | ... | Offset#N | N+1 | +------+---------+ +---------+---+----------+ +----------+-----+
Decompression will do reverse order.
Continue these procedure until all the required data has been read.