Name

deflateInit2_ Initializes the compression system.


Library

Libz.lib


Synopsis

#include <zlib.h>

int deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, char * version, int stream_size);


Return Value

On success, the deflateInit2_() function shall return Z_OK. Otherwise, deflateInit2_() shall return a value as described below to indicate the error.

Detailed Description

The deflateInit2_() function shall initialize the compression system. On entry, strm shall refer to a user supplied z_stream object (a z_stream_s structure). The following fields shall be set on entry:
 
zalloc  

a pointer to an alloc_func function, used to allocate state information. If this is NULL, a default allocation function will be used.

zfree  

a pointer to a free_func function, used to free memory allocated by the zalloc function. If this is NULL a default free function will be used.

opaque  

If alloc_func is not NULL, opaque is a user supplied pointer to data that will be passed to the alloc_func and free_func functions.

If the version requested is not compatible with the version implemented, or if the size of the z_stream_s structure provided in stream_size does not match the size in the library implementation, deflateInit2_() shall fail, and return Z_VERSION_ERROR.

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.

The method selects the compression algorithm to use. LSB conforming implementation shall support the Z_DEFLATED method, and may support other implementation defined methods.

The windowBits parameter shall be a base 2 logarithm of the window size to use, and shall be a value between 8 and 15. A smaller value will use less memory, but will result in a poorer compression ratio, while a higher value will give better compression but utilize more memory.

The memLevel parameter specifies how much memory to use for the internal state. The value of memLevel shall be between 1 and MAX_MEM_LEVEL. Smaller values use less memory but are slower, while higher values use more memory to gain compression speed.

The strategy parameter selects the compression strategy to use:
Z_DEFAULT_STRATEGY  

use the system default compression strategy. Z_DEFAULT_STRATEGY is particularly appropriate for text data.

Z_FILTERED  

use a compression strategy tuned for data consisting largely of small values with a fairly random distribution. Z_FILTERED uses more Huffman encoding and less string matching than Z_DEFAULT_STRATEGY.

Z_HUFFMAN_ONLY  

force Huffman encoding only, with no string match.

The deflateInit2_() function is not in the source standard; it is only in the binary standard. Source applications should use the deflateInit2() macro.


Examples

To initialize the compression system with method=8 ,windowBits =15 ,memlevel=8: 

include <stdio.h> 
#include <zlib.h>    
void DeflateInit2_( )
{ 
    z_stream stream;   
   int level=Z_DEFAULT_COMPRESSION;
    const char hello[] = "hello, hello!";
    uLong sourceLen = (uLong)strlen(hello)+1;
    Byte *compr;
    uLong comprLen = 10*sizeof(int);
    uLong uncomprLen = comprLen;
    compr = (Byte*)calloc((uInt)comprLen, 1);
    stream.zalloc = (alloc_func)0; 
    stream.zfree = (free_func)0;
    stream.opaque = (voidpf)0;  

    deflateInit2_(&stream, level, 8, 15, 8, 0, zlibVersion(), sizeof(z_stream));
    deflateEnd(&stream);
    free(compr);  
}

Errors

On error, deflateInit2_() shall return one of the following error indicators:
 
Z_STREAM_ERROR

Invalid parameter.

Z_MEM_ERROR

Insufficient memory available.

Z_VERSION_ERROR

The version requested is not compatible with the library version, or the z_stream size differs from that used by the library.

In addition, the msg field of the strm may be set to an error message.


Feedback

For additional information or queries on this page send feedback


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