views:

88

answers:

4

I have hundreds of CSV files zipped. This is great because they take very little space but when it is time to use them, I have to make some space on my HD and unzip them before I can process. I was wondering if it is possible with .NET to unzip a file while reading it. In other words, I would like to open a zip file, start to decompress the file and as we go, process the file.

So there would be no need for extra space on my drive. Any ideas or suggestions?

+1  A: 

A better solution might be to keep the files decompressed on the drive, but turn on compression on the file system level. This way you'll just be reading CSV files, and the OS will take care of making sure it doesn't take too much space.

Anyhoo, to answer your question, maybe the GZipStream class can help you.

Assaf Lavie
Good point! I though about that, but I am getting the files every week on a DVD...
Martin
A: 

I'm not sure about zip files, but you could use GZ format with GZipSteam (works like any other input stream). Unfortunately, the entire System.IO.Compression namespace is only 2 classes (the other does DEFLATE).

EDIT: There's a class called ZipPackage. I'm not sure how if it will let you do decompression streaming, but it might be worth looking into.

Also, take a look at #ziplib.

Brendan Long
+5  A: 

Yes. Zip is a streamed format which means that you can use the data as you decompress it rather than having to decompress everything first.

With .net's System.IO.Compression classes you can apply similar compression as used in zip files (Deflate & GZip) to any stream you like, but if you want to work with actual zip format files you'll need a third party library like this one (sharpziplib).

Jason Williams
+1  A: 

sharpziplib allows for stream-based decompression - see this related question - the item provides similar stream-based Read methods, so you can process each item like you would with any stream.

Marc Gravell