This project is read-only.

extracting before saving

Aug 24, 2011 at 8:44 PM

ok here is annother odd question.

If I add a file to a ZipFile object and then I Extract() that file without first calling Save() then do I just get a copy of the original file or does it rey to compress and then extract the file?


Aug 24, 2011 at 11:05 PM

I don't know what happens if you call Extract on a file that has never been saved. I don't think this is a scenario I have tested. I would like the library to throw an error in that case, something like "Don't do this." But I'm not sure if it does.

Why don't you try it and see?

Aug 25, 2011 at 6:25 PM
Edited Aug 25, 2011 at 6:25 PM

It thew a BadStateException with the message "You must call ZipFile.Save before calling any Extract method."

Is there a way to check for this scenario before calling Extract()?


Aug 25, 2011 at 8:16 PM

That sounds like a reasonable exception to me. 

I think maybe the best solution is for your app to track  the state of the ZipFile instance.

It's reasonable to ask for a publicly accessible "state" property on the ZipFile instance that indicates whether it has changes pending, and maybe some other stuff. I like that idea.  I'll have to think about what it should look like.  That won't be feasible til I  do a significant revamp of the object model.  I had planned that for a "v2.0" release of DotNetZip.  I think it will be somewhat disruptive, which is why I have not released it. There's a backlog of features and capabilities that all depend on the revamp though.


Aug 25, 2011 at 8:17 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.