liblzg  1.0.8
 All Data Structures Files Functions Variables Typedefs Macros
liblzg Documentation

Introduction

liblzg is a minimal implementation of an LZ77 class compression library. The main characteristic of the library is that the decoding routine is very simple, fast and requires no extra memory (except for the encoded and decoded data buffers).

Functions

Compression

Here is a simple example of compressing an uncompressed data buffer (given as buf/bufSize).

unsigned char *encBuf;
lzg_uint32_t encSize, maxEncSize;
// Determine maximum size of compressed data
maxEncSize = LZG_MaxEncodedSize(bufSize);
// Allocate memory for the compressed data
encBuf = (unsigned char*) malloc(maxEncSize);
if (encBuf)
{
// Compress
encSize = LZG_Encode(buf, bufSize, encBuf, maxEncSize, NULL);
if (encSize)
{
// Compressed data is now in encBuf, use it...
// ...
}
else
fprintf(stderr, "Compression failed!\n");
// Free memory when we're done with the compressed data
free(encBuf);
}
else
fprintf(stderr, "Out of memory!\n");

Decompression

Here is a simple example of decompressing a compressed data buffer (given as buf/bufSize).

unsigned char *decBuf;
lzg_uint32_t decSize;
// Determine size of decompressed data
decSize = LZG_DecodedSize(buf, bufSize);
if (decSize)
{
// Allocate memory for the decompressed data
decBuf = (unsigned char*) malloc(decSize);
if (decBuf)
{
// Decompress
decSize = LZG_Decode(buf, bufSize, decBuf, decSize);
if (decSize)
{
// Uncompressed data is now in decBuf, use it...
// ...
}
else
printf("Decompression failed (bad data)!\n");
// Free memory when we're done with the decompressed data
free(decBuf);
}
else
printf("Out of memory!\n");
}
else
printf("Bad input data!\n");