ZipErrorAction.Skip with non-seekable stream

Dec 21, 2011 at 1:57 PM

When I'm zipping to a network stream (Which obviously is non-seekable) the library is throwing a "Method not supported" exception. I understand why the program is throwing the exception (because when an item is skipped it tries to seek back on the stream), I just wanted to know if you had a method to get around this?

Thanks for any help

Dec 22, 2011 at 10:00 PM
Edited Dec 22, 2011 at 10:00 PM

Ah, yeah, "method not supported" sounds like DotNetZip is calling Seek() or something similar on a non-seekable stream. 

Before I am able to answer your question though, I'd need to see a stack trace.  It would also be helpful to see the code you use to cause the exception. I don't understand what ZipErrorAction.Skip has to do with the problem, though.

 Also what version of DotNetZip are you using?


Dec 23, 2011 at 2:39 PM

I am actually using the latest code from the repository and compiling the Zip DLL project in my solution.


I have pinpointed where the exception is happening. It is in the catch block of the ZipEntry.Write() where the code goes if ZipErrorAction == ZipErrorAction.Skip, line 2195 to be exact. I added a condition to the if statement to check if the stream is seekable. So now the statement is:

if (delta > 0 && s.CanSeek)
{ s.Seek(delta, SeekOrigin.Current); // may throw long p2 = s.Position; s.SetLength(s.Position); // to prevent garbage if this is the last entry if (cs1 != null) cs1.Adjust(p1 - p2); }

It seems to work ok but will this cause a problem at any point?

Dec 29, 2011 at 8:44 PM

Hmm, I don't know, I'd have to look at it more closely. If you have the latest snap you can run all the tests, to give you an idea if this will cause something to break.  But still, you'd need  a code review to be sure.  I can't do the review or run the tests at this time. (dev machine problem)