Name

uncompress — Un-compresses the data.


Library

Libz.lib


Synopsis

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


Return Value

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


Detailed Description

The uncompress() function shall attempt to uncompress sourceLen bytes of data in the buffer source, placing the result in the buffer dest.

On entry, destLen should point to a value describing the size of the dest buffer. The application should ensure that this value is large enough to hold the entire uncompressed data.

Note

Note: The LSB does not describe any mechanism by which a compressor can communicate the size required to the uncompressor.

On successful exit, the variable referenced by destLen shall be updated to hold the length of uncompressed data in dest.

Examples

To uncompress the compressed string in compr:

#include <stdio.h>  
#include <zlib.h>

void Uncompress( )
{
Byte *compr, *uncompr;
uLong comprLen = 20*sizeof(int);
uLong uncomprLen = comprLen;
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
int err;
const char hello[] = "hello, hello!";
uLong len = (uLong)strlen(hello)+1;
compress(compr, &comprLen, (const Bytef*)hello, len);
strcpy((char*)uncompr, "garbage");
uncompress(uncompr, &uncomprLen, compr, comprLen);
free(compr);
free(uncompr);
}

Output

uncompr contains uncompressed string.  

Errors

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

Z_BUF_ERROR  

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

Z_MEM_ERROR  

Insufficient memory.

Z_DATA_ERROR  

The compressed data (referenced by source) was corrupted.


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