EDIT
// open output file for writing
if ( ( outfilefd = fopen( file_name, "w+t" ) ) == NULL )
{
fprintf(stderr, "Unable to create file\n");
exit(1);
}
Write to the file, then need to zip it.
Opening a .z file and then calling def()
FILE *zipFile;
if ( ( zipFile = fopen( "C:\\LOGS\\test.txt.z", "w+t" ) ) == NULL )
{
fprintf(stderr, "Unable to create file\n");
exit(1);
}
int ret = def(outfilefd, zipFile, Z_DEFAULT_COMPRESSION);
if (ret != Z_OK)
printf("ZLIB Error");
using def(), right from the site:
int def(FILE *source, FILE *dest, int level)
{
int ret, flush;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, level);
if (ret != Z_OK)
return ret;
/* compress until end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
int g = ferror(source);//<---------------- EROR HERE returning 32?
if (ferror(source)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
zipFile
is not null, strm.avail_in
= 16343, in
has the data but ferror(source)
returns 32?
EDIT - Also strm.avail_in
= 16343 caught my eye as CHUNK
= 16384....is that OK?
Any ideas or help is appreciated.
Thank You.