compressed files
Robert Skinner
robert at victoria.esd.sgi.com
Thu Jan 18 05:27:58 AEST 1990
In article <3339 at uceng.UC.EDU>, trohling at uceng.UC.EDU (tom rohling) writes:
>
> Can a compressed file be accessed through fortran (or C) much in the
> same way that 'zcat' uncompresses the file to std out but leaves the file
> in its compressed state? i.e. can I read the contents of a compressed file
> from a program without having to uncompress it first? Sort of like zcat
> it into ram....
You can use popen to get a file pointer to the output of zcat. This acts
just like fopen, but if the file isn't there, it looks for the compressed
version (with the .Z extension) and makes a pipe that zcat's it into
your program.
#include <stdio.h>
#include <errno.h>
FILE *zopen( name )
char *name;
{
FILE *fp;
char cmd[256];
errno = 0;
fp = fopen( name, "r" );
if( !fp && errno == 0 ) { /* file doesn't exist */
sprintf( cmd, "zcat %s.Z" );
fp = popen( cmd, "r" );
}
return fp;
}
(No, this isn't debugged, and I should check whether the compressed
file is there, but you get the idea.) One drawback is that you can't
seek on it.
I think you lose if you HAVE to seek on the file. Seeking is very tricky
when a (de)compression scheme is involved.
good luck,
Robert Skinner
robert at sgi.com
Which is worse, ignorance or apathy?
Who knows? Who cares?
More information about the Comp.sys.sgi
mailing list