Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!ucsd!chem.ucsd.edu!tps From: tps@chem.ucsd.edu (Tom Stockfisch) Newsgroups: comp.sys.sgi Subject: Re: compressed files Keywords: a question for the compression gods Message-ID: <653@chem.ucsd.EDU> Date: 18 Jan 90 22:46:33 GMT References: <3339@uceng.UC.EDU> Reply-To: tps@chem.ucsd.edu (Tom Stockfisch) Organization: Chemistry Dept, UC San Diego Lines: 67 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 where my program can get at it without creating file out >of it and taking up all that space. > We have these rather large files (20 Meg uncompressed) we are using >... and alot of the time there isn't enough room on >the disk to uncompress all the files and run the program for a while and >still leave enough disk space for other users. Use the following routine in place of fopen( "bigFile", "r" ): /* zopen(): * open a compressed file for reading, filtering it thru zcat. */ # include static void defaultErrHndlr(); void (*zopenErrHndlr)() = defaultErrHndlr; FILE * zopen(name) char *name; { FILE *stream; int piped[2]; # define READ 0 # define WRITE 1 if ( pipe(piped) == -1 ) (*zopenErrHndlr)( "pipe failure\n" ); switch ( fork() ) { case -1: (*zopenErrHndlr)( "fork failure\n" ); case 0: /* child */ close( piped[READ] ); close(1); if ( dup( piped[WRITE] ) != 1 ) (*zopenErrHndlr)( "dup screwup\n" ); close( piped[WRITE] ); execlp( "zcat", "zcat", name, (char *)0 ); (*zopenErrHndlr)( "cannot start zcat" ); default: /* parent */ close( piped[WRITE] ); stream = fdopen( piped[READ], "r" ); if (stream == NULL) (*zopenErrHndlr)( "cannot open pipe\n" ); break; } return stream; } static void defaultErrHndlr(diagnostic) char *diagnostic; { fprintf( stderr, "zopen(): %s\n", diagnostic ); exit(1); } -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu