Name

inflateSync — Advances compression stream to next sync point.


Library

Libz.lib


Synopsis

#include <zlib.h>

int inflateSync(z_streamp stream);

Return Value

On success, inflateSync() shall return Z_OK, and update the next_in,, avail_in, and, total_in fields of stream to reflect the number of bytes of compressed data that have been skipped. Otherwise, inflateSync() shall return a value as described below to indicate the error.


Detailed Description

The inflateSync() function shall advance through the compressed data in stream, skipping any invalid compressed data, until the next full flush point is reached, or all input is exhausted. See the description for deflate() with flush level Z_FULL_FLUSH. No output is placed in next_out.


Examples

To advance the compression stream to next sync point:

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

void inflateSync( )
{
z_stream d_stream; /* decompression stream */
uLong len = (uLong)strlen(hello)+1;
const char hello[] = "hello, hello!";
Byte *compr, *uncompr;
uLong comprLen = 20*sizeof(int);
uLong uncomprLen = comprLen;
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
uLong len = (uLong)strlen(hello)+1;
compress(compr, &comprLen, (const Bytef*)hello, len);
deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);


c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
c_stream.avail_in = 3;
c_stream.avail_out = (uInt)*comprLen;
err = deflate(&c_stream, Z_FULL_FLUSH);
int h=inflateSyncPoint(&c_stream);
compr[3]++; /* force an error in first compressed block */
c_stream.avail_in = len - 3;


deflate(&c_stream, Z_FINISH);
deflateEnd(&c_stream);
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = 2; /* just read the zlib header */
inflateInit(&d_stream);
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
inflate(&d_stream, Z_NO_FLUSH);
d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
err = inflateSync(&d_stream); /* but skip the damaged part */
inflate(&d_stream, Z_FINISH);
inflateEnd(&d_stream);
free(compr);
free(uncompr);
}

Errors

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

Z_STREAM_ERROR

The state (as represented in stream) is inconsistent, or stream was NULL.

Z_BUF_ERROR

There is no data available to skip over.

Z_DATA_ERROR

No sync point was found.


Feedback

For additional information or queries on this page send feedback

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