Name

gzwrite — Writes data to the compressed file referenced by file, opened in a write mode.


Library

Libz.lib


Synopsis

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


Return Value

On success, gzwrite() shall return the number of uncompressed bytes actually written to file. On error gzwrite() shall return a value less than or equal to 0. Applications may examine the cause using gzerror().


Detailed Description

The gzwrite() function shall write data to the compressed file referenced by file, which shall have been opened in a write mode (see gzopen() and gzdopen()). On entry, buf shall point to a buffer containing lenbytes of uncompressed data. The gzwrite() function shall compress this data and write it to file. The gzwrite() function shall return the number of uncompressed bytes actually written.


Examples

To write data to the compressed file referenced by file, which shall have been opened in a write mode:

#include <stdio.h>
#include <zlib.h>
void Gzwrite( )
{

gzFile file;
uInt size ,len;
const char *s="ritesh";
len=strlen(s);
const char * fname = TESTFILE ;
file = gzopen(fname, "wb");
size = gzwrite(file, (char*)s, (unsigned)strlen(s));
printf("size is %d",size);
gzclose(file);
}

Output

Size is 6.

Errors

On error, gzwrite() 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_ERROR

The stream is invalid, is not open for writing, or is in an invalid state.

Z_BUF_ERROR

no compression progress is possible (see deflate()).

Z_MEM_ERROR

Insufficient memory available to compress.


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top