Name

gzread Reads from a compressed file.    


Library

Libz.lib


Synopsis

#include <zlib.h>
int gzread (gzFile file, voidp buf, unsigned int len);


Return Value

On success, gzread() shall return the number of bytes decompressed into buf. If gzread() returns 0, either the end-of-file has been reached or an underlying read error has occurred. Applications should use gzerror() or gzeof() to determine which occurred. On other errors, gzread() shall return a value less than 0 and and applications may examine the cause using gzerror().


Detailed Description

The gzread() function shall read data from the compressed file referenced by file, which shall have been opened in a read mode (see gzopen() and gzdopen()). The gzread() function shall read data from file, and uncompress it into buf. At most, len bytes of uncompressed data shall be copied to buf. If the file is not compressed, gzread() shall simply copy data from file to buf without alteration.


Examples

To read from a compressed file:

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

void Gzread( )
{

char * buf1 = (char*)malloc(1024);
int len1;
char *file=FILETESTGZ;
char *infile;
gzFile in;
infile = file;
in = gzopen(infile, "rb");
for (;;)
{
len1 = gzread(in, buf1, sizeof(buf1));
if (len1 == 0) break;
}
free(buf1);
}

Errors

On error, gzread() shall set the error number associated with the stream identified by file to indicate the error. Applications should use gzerror() to access this error value.

Z_ERRNO

An underlying base library function has indicated an error. The global variable errno may be examined for further information.

Z_STREAM_END

End of file has been reached on input.

Z_DATA_ERROR

A CRC error occurred when reading data; the file is corrupt.

Z_STREAM_ERROR

The stream is invalid, or is in an invalid state.

Z_NEED_DICT

A dictionary is needed (see inflateSetDictionary()).

Z_MEM_ERROR

Insufficient memory available to decompress.


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