From: "Thomas Harte" Newsgroups: comp.os.msdos.djgpp Subject: Re: Need HELP with the ZLIB !!! Date: Sun, 16 Apr 2000 23:10:17 +0100 Organization: BT Internet Lines: 88 Message-ID: <8ddduf$dim$1@plutonium.btinternet.com> References: <8dcpbo$b32$2 AT news00 DOT btx DOT dtag DOT de> NNTP-Posting-Host: host213-1-128-147.btinternet.com X-Newsreader: Microsoft Outlook Express 4.72.3155.0 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com >Can anybody code a Function and offers the Sourcecode in this Forum ?? > >The one function should be: You could write the functions you suggest, but there is no need. Zlib supports functionality almost identical to the regular stdio file and stream commands. For example, where you used to do this : FILE *infile; infile = fopen("filename.bin", "rb"); or something, you can just do this : gzfile *ginfile; ginfile = gzopen("filename.bin", "rb"); And then, in place of : fgetc(infile); You just use : gzgetc(ginfile); And so on. Notice however, that gzread/gzwrite correlate to fread/fwrite slightly differently. They take a single length parameter, but if you can only think in terms of size and quantity, just multiply those together. The good thing about zlib is that if you do something like 'gzopen("jkdf", "rt") on a file that isn't actually gzipped then the library doesn't think anything of it and simply reads the file as fopen would have done. Instantly your application supports both compressed and uncompressed file types without you having to do anything about it. Therefore, possible (dumb) definitions of your prototypes would be (sorry about the lack of indenting - tab is broken on this mail reader) : >int GZFileTONFile (char *gzf, char *nf) >{ gzfile *in; FILE *out; char buffer; if(!(in = gzopen(gzf, "rb"))) return -1; if(!(out = fopen(nf, "wb"))) { gzclose(in); return -2; } while(1) { buffer = gzgetc(in); if(gzeof(in)) break; fputc(out, buffer); } gzclose(in); fclose(out); return 0; >} >int NFileTOGZFile (char *gzf, char *nf) >{ //more or less the same thing except that the gzip file is opened for output, the normal file for input, and the while loop uses fgetc and feof in place of gz versions, and gzputc in place of f version. >} > >The two should give back a 0 if everything was okay and another Number if an >Error occurs. As you can see, negative values are returned on error. Of course, better versions would use a larger than one byte buffer, but I'm sure you can better understand the function descriptions in zlib.h now that you've had a push in the right direction! -Thomas