Name

compress2 Compresses data at a specified level.


Library

Libz.lib


Synopsis

#include <zlib.h>
int compress2(Bytef * dest, uLongf * destLen, const Bytef * source, uLong sourceLen, int level);

Return Value

On success, compress2( ) shall return Z_OK. Otherwise, compress2( ) shall return a value to indicate the error.


Detailed Description

The compress2( ) function shall attempt to compress sourceLen bytes of data in the buffer source, placing the result in the buffer dest, at the level described by level. The level supplied shall be a value between 0 and 9, or the value Z_DEFAULT_COMPRESSION. A level of 1 requests the highest speed, while a level of 9 requests the highest compression. A level of 0 indicates that no compression should be used, and the output shall be the same as the input.

On entry, destLen should point to a value describing the size of the dest buffer. The application should ensure that this value be at least (sourceLen × 1.001) + 12. On successful exit, the variable referenced by destLen shall be updated to hold the length of compressed data in dest.

The compress( ) function is equivalent to compress2( ) with a level of Z_DEFAULT_LEVEL.


Examples

To compress string "hello":

#include <stdio.h> 
#include <zlib.h>
void test_compress(Byte * compr,uLong comprLen)
{
    const char hello[] = "hello, hello!";
    uLong len = (uLong)strlen(hello)+1;
    compress(compr, &comprLen, (const Bytef*)hello, len);
}

Output
compr contains the compressed data.

Errors

On error, compress2( ) shall return a value as described below:

Z_BUF_ERROR

The buffer dest was not large enough to hold the compressed data.

Z_MEM_ERROR

Insufficient memory.

Z_STREAM_ERROR

The level was not Z_DEFAULT_LEVEL, or was not between 0 and 9.


Feedback

For additional information or queries on this page send feedback

 

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top