ZIPFoundation icon indicating copy to clipboard operation
ZIPFoundation copied to clipboard

API to remove multiple entries at once

Open Mark-s99 opened this issue 5 years ago • 1 comments

Currently entries can be removed one at a time, each time a temporary archive is created that replaces the original.

Would you consider extending the API to allow removing a list of entries?

For example:

public func remove(_ entries: [Entry], bufferSize: UInt32 = defaultReadChunkSize, 
                                  progress: Progress? = nil) throws

I'm currently looking into adding this myself, but I have not wrapped my head around CentralDirectoryStructure and endOfCentralDirectoryRecord and the various offsets that are involved.

Thank you!

Mark-s99 avatar Apr 09 '19 10:04 Mark-s99

Removing entries from ZIP archives is - in contrast to entry addition - very expensive. So providing a "batch removal" method would certainly make sense.
ZIP Foundation removes an entry by re-writing the whole archive to a temp file, but skipping the entry to remove. The part to skip is from Entry.centraldDirectoryStructure.relativeOffsetToLocalHeader to the end of the data section of the file. Wikipedia has a good introduction + diagram about the structure of archives:
https://en.wikipedia.org/wiki/Zip_(file_format)#Structure

weichsel avatar Apr 11 '19 20:04 weichsel