CyberPeasant wrote:
> > I would like to zip a file, specified by the user, from within a C
> > program. Currently I use the system() command to invoke gzip. Is there a
> > compression library or routenes out there somewhere, or is there a
> > better way of doing this ?
>
> There are compression libraries, but I don't see their advantage in
> this case, nor do I know if they will produce a true "gzip" format
> file. If the problem is waiting for system() to complete on a long
> gzipping, consider forking a process to do it.
zlib will read/write gzip files. The zlib distribution comes with a
`mini-gzip' program which demonstrates it's usage. It basically boils
down to:
gzFile in = gzopen(filename, "rb");
for (;;) {
int len = gzread(in, buf, sizeof(buf));
if (len == 0) break;
/* do something with the contents of `buf' */
}
gzclose(in);
> Another possibility is to use popen() with the appropriate flags to
> gzip to deal with stdin/stdout.
Yep. And this approach can easily be generalised to handle other
encodings (e.g. bzip2, uucode/base64, PGP encryption, ...).
--
Glynn Clements <[EMAIL PROTECTED]>