|

Latest Release: v1.0.0
Chilkat
Real-Time Compression is FREE.
DOWNLOAD
Documentation
Example Program
Chilkat RT Compress
is a free COM component offering real-time memory-to-memory compression
and decompression. Unlike other Chilkat components, RT Compress
is not a full ActiveX control callable from any language, but
is instead a simple COM component callable from C++. It currently
implements the LZO
compression algorithm provided by Markus Oberhumer, although
future versions may include other algorithms.
Chilkat RT Compress
is distributed under the terms of the GNU General
Public License (GPL)
This component is
free, and unlike other Chilkat components, does not require registration
or an unlock code. The full source is available here.
This source includes the LZO 1.07 source code, as well as the
Microsoft Visual C++ 6.0 project and source files for the COM
component.
About
LZO
- LZO is a data compression
library suitable for real-time operation, favoring speed over
compression ratio.
- LZO stands for
Lempel-Ziv-Oberhumer.
- Compresses at about
5 MB/second.
- Decompresses at
about 16 MB/second.
C++
Example
A simple example demonstrating
compression and decompression is shown below.
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include "../ChilkatRtCompress.h"
#include "../ChilkatRtCompress_i.c"
int main(int argc, char* argv[])
{
CoInitialize(0);
IChilkatRtCompress *pComp = 0;
// Create an instance of the COM component.
CoCreateInstance(CLSID_ChilkatRtCompress,
NULL,CLSCTX_INPROC_SERVER,
IID_IChilkatRtCompress,
(void **)&pComp);
// Create some data to be compressed.
char data[1000];
const char *msg = "This is the data that will be compressed.\n";
strcpy(data,msg);
strcat(data,msg);
strcat(data,msg);
strcat(data,msg);
strcat(data,msg);
strcat(data,msg);
long dataLen = strlen((const char *)data);
printf("Original data size: %d\n",dataLen);
printf("Original data: \n%s\n",data);
// Calculate the amount of memory potentially needed to
// hold the compressed data.
// This is typically a little bit larger than the original buffer.
long compressedDataLen = dataLen;
pComp->CalcBufferSize(&compressedDataLen);
unsigned char *pCompressedData = new unsigned char[compressedDataLen];
// Compress the data.
printf("Compressing...\n");
printf("Buffer size = %d\n",compressedDataLen);
pComp->Compress((unsigned char *)data,dataLen,
pCompressedData,&compressedDataLen);
printf("Compressed data size: %d\n\n",compressedDataLen);
//Now decompress back to the original buffer.
// The last parameter (dataLen) contains the size of the output buffer
// on input, and the size of the decompressed data on output.
data[0] = '\0';
dataLen = 1000;
printf("Decompressing...\n");
pComp->Decompress(pCompressedData,compressedDataLen,
(unsigned char *)data,&dataLen);
printf("Decompressed data size: %d\n",dataLen);
printf("Decompressed data: \n%s\n",data);
// Cleanup
delete [] pCompressedData;
pComp->Release();
CoUninitialize();
return 0;
}
|
* All
functions return S_OK (0) when successful.
- HRESULT CalcBufferSize(long
*bufSize)
- Calculates the buffer size required
to compress a given amount of data. On input, bufSize
contains the number of bytes to be compressed. On output, bufSize
contains the size (in bytes) of the buffer necessary to hold
the compressed data.
-
- HRESULT Compress(unsigned
char *inData, long inSize, unsigned char *outData, long outSize)
- Compresses a memory buffer. The
calling application must provide a memory buffer that is large
enough to hold the compressed data. The size of this buffer
is computed by calling CalcBufferSize.
-
-
- HRESULT Decompress(unsigned
char *inData, long inSize, unsigned char *outData, long outSize)
- Decompresses data to a memory
buffer provided by the calling application. The output memory
buffer must be large enough to hold the decompressed data, or
the call will fail.
|