Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!arisia!sgi!shinobu!odin!victoria.esd.sgi.com!robert From: robert@victoria.esd.sgi.com (Robert Skinner) Newsgroups: comp.sys.sgi Subject: Re: compressed files Keywords: a question for the compression gods Message-ID: <2893@odin.SGI.COM> Date: 17 Jan 90 18:27:58 GMT References: <3339@uceng.UC.EDU> Sender: news@odin.SGI.COM Reply-To: robert@victoria.esd.sgi.com (Robert Skinner) Organization: Silicon Graphics, Inc. Lines: 46 In article <3339@uceng.UC.EDU>, trohling@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 #include 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@sgi.com Which is worse, ignorance or apathy? Who knows? Who cares?