Extract & OpenReader methods fail on entry created from ZipInputStream?

Oct 12, 2011 at 10:10 PM

I'm a new user, so perhaps I've misread the docs, but it appears that these methods (on the ZipEntry type) don't work when applied to a ZipEntry which was obtained from a ZipInputStream (as opposed to a ZipFile). When I use these methods I get an InvalidOperationException, complaining "Use OpenReader() only with ZipFile" (or "Use Extract() only with ZipFile).

Is there a way to extract an entry from a Zip archive obtained via a ZipInputStream rather than an actual file?

I'm using DotNetZipLib-DevKit-v1.9 which I have just downloaded from CodePlex.

Thanks in advance for any help with this...

Bill

Coordinator
Oct 13, 2011 at 7:38 PM

Yes, you've missed it.

As the exception tells you: you may not call OpenReader() or Extract() on a ZipEntry obtained from a ZipInputStream.  If you want to understand why, the documentation includes a clear and complete discussion of the issue. The metaphor for ZipInputStream is a stream - read it and you read uncompressed data.

Check the reference documentation of the ZipInputStream constructor for a clear, simple example showing how to use ZipInputStream to extract an entry from a Zip file.