how do i unzip stream while reading it in c# [closed]
i read a zip file in my application and i don't want to extract after i read it all ..
i want to extract it while i am reading it.
so how do i extract stream of bytes for a file while i am reading it ?
The GZipStream and DeflateStream classes are wrappers around a normal Stream object. This means that you can extract the data as you're going along before a) the whole file has been downloaded and b) without loading all of the data in to memory.
These are available in .NET 4 upwards, otherwise you'll need to use #ZipLib as suggested.
EDIT: After looking around it would appear that #ZipLib is definitely the way forwards with this. The same principles apply to these classes in that they are streams, they can work as the file is being downloaded or read over a network and they don't require the whole file to be in memory. I'm currently using it in a project to open zip files from an http server, so I've seen it in action!
The .NET Base Class Library doesn't include classes to stream .zip files. Take a look at SharpZipLib.
Here are various examples of compression/decompression using the #Zip library.
http://wiki.sharpdevelop.net/SharpZipLib-Zip-Samples.ashx
精彩评论