views:

187

answers:

3

What I need to do is unzip a file, (.gz or .z), read the first line and do some stuff according to the first line read. But the C standard library doesn't seem to offer a way to do this.

Is the a platform-independent way to do it?

+8  A: 

Use "zlib", the library that performs compression and decompression:

http://www.zlib.net/

It's included in the base of all Unix distributions, and you can easily link your program against it for the windows version and ship the DLL.

Zorglub
A: 

The info-zip libraries are quite portable.

Jerry Coffin
A: 

if you want to platform-independent, you'd have to have the unzipping code in your program. Likely, you'd want to link against a third-party library, such as ZLib which is standard on Unix systems, or use the DLL when on Windows.

The rest is pretty simple: use ZLib to unzip the file to a temporary location, read the file as normal, then remove the file when you're done.

Slokun
You don't even need a temporary file; zlib allows you to compress/decompress streaming in memory.
ephemient
Is the in memory thing faster than fiddling around with a temp file?
Helper Method