Question

I wrote code to delete file in zip with minizip.

referenced http://www.winimage.com/zLibDll/del.cpp

I have to delete and modify the file and in zip frequently.

the zip file that used is 1.6 GB.

Deleting the file and in zip means

  1. copy whole zip file except the file to delete to new zip file
  2. delete old zip file.
  3. rename new zip file to old zip file.

so too slow delete and modify(delete and add).

how can I make faster deleting and modifying the file in zip?

is there any idea?

Was it helpful?

Solution

You can write your own code to delete a zip entry in place. That is a little more risky, since if there is a problem or the system goes down in the middle of the operation, you will have lost the file. Your current approach, copying the zip file, assures that you always have one good zip file available if something goes south.

The .ZIP File Format Specification provides all the information you need to write your own deleter. The structure of a zip file is relatively straightforward, but it will take some attention to detail to work through all the possibilities.

The deletion operation will still require copying all of the zip file content that follows the deleted entry down.

Having done that, adding a file in place will be relatively fast, since it just goes at the end, and the central directory is rewritten. If the deletion and additions are the same file or files, then they will naturally end up at the end, and the in-place operations should be faster than copying the whole zip file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top