EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Avoid overwrite when extracting with ZipReader

Posted: 04/13/2012 09:28:33
by Niklas Kjellander (Standard support level)
Joined: 09/30/2008
Posts: 54

The following applies when using the .Net libraries.

When using the ZipReader to extract files from a zip archive the ZipReader can raise the OnUserActionNeeded.

For example: this happens when the zipWriter detects that there already is a file in the target folder with the same name as the file that is about to be extracted from the archive.

In the event handler the ForEvent is then ZIP_EVENT_FILE_ALREADY_EXISTS. Now there seems to be two options:
1. set UserAction to ZIP_ACTION_IGNORE and the existing file will be overwritten with the file from the archive
2. set UserAction to ZIP_ACTION_ABORT. This will result in the Extract method of the ZipReader to throw a ZipFatalError exception, no moore files will be extracted (if it is a batch extraction).

But what is the best way to go about if you just want to skip the extraction of the file and continue to extract the remaining files in the archive? If you are using the overload of Extract that takes a mask and an output path there is no obvious way to overcome this scenario.

What you can do is to iterate the directory entries in the ZipReader an extract each file using the overload of Extract that takes an entry and an output path. Either you ignore the raised OnUserActionNeeded event and catches the exception and then tries to verify that this exception was thrown because a file with the same name already exists and then continue to iterate the directory entries and extract them.
On the other hand you can set some flag in the event handler that tells you that there was a conflict and then set UserAction to abort. This will result in an exeption but now you can check your flag in the catch.

Seems to me that Skip would be a nice UserAction option to avoid all this trouble or do you have any recommendations on how to solve this?
Posted: 04/16/2012 01:08:41
by Vsevolod Ievgiienko (Team)

Thank you for contacting us.

You can skip extraction of an archive entry using TElZipReader.OnExtractionStart and its Skip parameter.
Posted: 04/16/2012 01:22:34
by Niklas Kjellander (Standard support level)
Joined: 09/30/2008
Posts: 54

Yes, of course.

Thanks' for the assistance!
Posted: 04/16/2012 02:05:59
by Eugene Mayevski (Team)

We will improve the component in the next build to have Skip mode.

Sincerely yours
Eugene Mayevski



Topic viewed 634 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!