Link to home
Start Free TrialLog in
Avatar of RonMexico
RonMexico

asked on

Using GZipStream to explore a zip file

Hello, I am writing a VB.NET program, and I'd like to just do a quick scan of a ZIP file to make sure it contains a small file called info.txt (and maybe look at the contents, not completely necessary).  I'm not sure if I have to decompress it to do this -- I'd rather not because the entire ZIP file is pretty big.

I'm not sure if it is possible to inspect w/o extracting, OR to just extract a single file info.txt, w/o doing the very slow (since lots of big files) decompression.

Anyway, since it's VB.NET the

Imports System.IO.Compression

namespace is available to me, with the GZipStream class.  The example code for this class talks about compression and decompression, but nothing more advanced like what I'm talking about (if possible).  If it is possible, sample code would be appreciated.  

Thanks VERY much.
Avatar of teebon
teebon
Flag of Singapore image

Hi Ron,

You may use DotNetZip library to achieve what you wanted.

http://dotnetzip.codeplex.com/
http://dotnetzip.codeplex.com/wikipage?title=VB-Examples&referringTitle=Examples

Refer to the second link above for the VB examples where you can loop through the files in the zip file and check the name:

  For Each e In zip1               
          'Check the file name for e here, if it is info.txt
          if(e.FileName = "info.txt")
             'Do something
      Next  

Open in new window

Avatar of RonMexico
RonMexico

ASKER

Thanks teebon... I'll take a look.  I came across that library in google hits and also read that it probably pre-dated the addition of the System.IO.Compression namespace to .NET.  I would prefer to use built-in namespaces if possible.  Do you happen to know whether this can't be done with the built-in component?

Also this might be greedy, but does that library allow you to look at the contents of a file w/o decompressing the whole thing?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of teebon
teebon
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome, thanks!   Was unable to find anything close to that helpful in sample code.  Did you find that online or write it.  Thanks either way...
Oh... I see the link now.  Don't know how I missed that.  Thanks again!
Ohhhhh.... THAT's how I missed it... it's not released yet.  :)
I downloaded VS2012, started a .NET 4.5 VB  application, does not seem like ZipARchive is part of IO.Compression.  What gives?
I modified the msdn code based on your requirement.

Have you add reference to System.IO.Compression?
Are you still facing any issue?