Name

deflateBound Estimates the size of buffer required to compress sourceLen bytes of data.


Library

Libz.lib


Synopsis

#include <zlib.h>
int deflateBound(z_streamp stream, uLong sourceLen);


Return Value

The deflateBound() shall return a value representing the upper bound of an array to allocate to hold the compressed data in a single call to deflate(). If the stream is not correctly initialized, or is NULL, then deflateBound() may return a conservative value that may be larger than sourceLen.


Detailed Description

The deflateBound() function estimates the size of buffer required to compress sourceLen bytes of data. If successful, the value returned shall be an upper bound for the size of buffer required to compress sourceLen bytes of data, using the parameters stored in stream, in a single call to deflate() with flush set to Z_FINISH.

On entry, stream should have been initialized via a call to deflateInit_() or deflateInit2_().


Examples

Size of buffer required to compress sourceLength bytes of data: 

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

void Deflatebound( )
{
uLong len = (uLong)strlen(hello)+1;
Byte *compr, *uncompr;
uLong comprLen = 20*sizeof(int);
uLong uncomprLen = comprLen;
const char hello[] = "hello, hello!";
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
stream.next_in = (Bytef*)hello;
stream.avail_in = (uInt)comprLen;
stream.next_out = dest;
stream.avail_out = (uInt)*len;
deflateInit(&stream, level);
int y= deflateBound(&stream, sourceLen);
deflateEnd(&stream);
printf("size of buffer required is %d",x);
}

Output

Size of buffer required is 28.

Errors

None defined.


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top