Name

deflateEnd — Frees all allocated state information referenced by stream .


Library

Libz.lib


Synopsis

#include <zlib.h>
int deflateEnd(z_streamp stream);

Return Value

On success, deflateEnd() shall return Z_OK, or Z_DATA_ERROR if there was pending output discarded or input unprocessed. Otherwise it shall return Z_STREAM_ERROR to indicate the error.


Detailed Description

The deflateEnd() function shall free all allocated state information referenced by stream. All pending output is discarded, and unprocessed input is ignored.


Examples

To free all allocated state information referenced by c_stream:

#include <stdio.h> 
#include <zlib.h>
void Deflateend( )
{    
    z_stream c_stream; /* compression stream */ 
    uLong len = (uLong)strlen(hello)+1; 
    Byte *compr, *uncompr;
    uLong comprLen = 20*sizeof(int);
    uLong uncomprLen = comprLen;
    compr    = (Byte*)calloc((uInt)comprLen, 1);
    uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
    const char hello[] = "hello, hello!";
    c_stream.zalloc = (alloc_func)0; 
    c_stream.zfree = (free_func)0;
    c_stream.opaque = (voidpf)0;
    compress(compr, &comprLen, (const Bytef*)hello, len); 
    err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
    c_stream.next_in  = (Bytef*)hello;
    c_stream.next_out = compr;

    while (c_stream.total_in != len && c_stream.total_out < comprLen)
{
        c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
        err = deflate(&c_stream, Z_NO_FLUSH);
     }
    /* Finish the stream, still forcing small buffers: */
    for (;;)
 {
        c_stream.avail_out = 1;
        err = deflate(&c_stream, Z_FINISH);
        if (err == Z_STREAM_END) break;
    }
   deflateEnd(&c_stream); 
   free(compr);
   free(uncompr);
}

Errors

On error, deflateEnd() shall return Z_STREAM_ERROR. The following conditions shall be treated as an error:

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