Verifying a zip file

F

Frank Munsberg

I've been looking for something that allows me to verify that a zip file is
still healty without actually extracting it to disk.
So far I've found at least two free components (SharpZipLib and
DotNetZipLib) and a handful of commercial components that neither could do
the trick.

Does anyone know of some component (commercial or not) that can actually do
this in .Net 2.0? Some restrictions outside of my control forbid 3.5 at those
machines.

Last resort would be to integrate 7-zip via a command line call but i really
would like to avoid going down that route.
 
F

Frank Munsberg

Do neither of those libraries allow you to specify the Stream to which a
..zip file is decompressed?

If either do, then you can just provide your own Stream implementation
that discards all of the data sent to it, using that as the output for the
library. Then the library will go through the motions of decompressing
the archive without any data actually being sent anywhere.

That's a good idea. I just tried with the DotNetZipLib 1.7 and indeed it can
get me a Stream for every single file in the zip. Like you said all it takes
is some sort of NullStream implementation that discards any data it gets so
memory usage stays flat during the check.
It threw an exception when I fed it a broken zip file so I'll take that route.

Thanks!
Also thanks Mark for the other hint ;)
 
J

Jeff Johnson

I've been looking for something that allows me to verify that a zip file
is
still healty without actually extracting it to disk.
So far I've found at least two free components (SharpZipLib and
DotNetZipLib) and a handful of commercial components that neither could do
the trick.

Does anyone know of some component (commercial or not) that can actually
do
this in .Net 2.0? Some restrictions outside of my control forbid 3.5 at
those
machines.

Last resort would be to integrate 7-zip via a command line call but i
really
would like to avoid going down that route.

I've already modified my copy of SharpZipLib to handle some stuff it didn't
out-of-the-box (like per-file compression levels), so I think I'll take a
look at making sure it can handle something like this. Thanks for the idea!
 
A

Arne Vajhøj

Frank said:
I've been looking for something that allows me to verify that a zip file is
still healty without actually extracting it to disk.
So far I've found at least two free components (SharpZipLib and
DotNetZipLib) and a handful of commercial components that neither could do
the trick.

The following works for me with SharpZipLib:

public static bool Test(string fnm)
{
ZipFile zf = new ZipFile(fnm);
bool res = zf.TestArchive(true);
zf.Close();
return res;
}

Arne
 
C

Cheeso

I disagree with the question - DotNetZip has a static IsZipFile()
method that does exactly what you want. Checks the zip without
extracting it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top