mattconnolly / ZipArchive

zip archive processing for Cocoa - iPhone and OS X
http://code.google.com/p/ziparchive/
MIT License
840 stars 260 forks source link

Refactor UnzipFileToMemory and getZipFileContents to use iterator #63

Open wallclimber21 opened 9 years ago

wallclimber21 commented 9 years ago

This patch adds the following iterator function:

-(BOOL)iterateZipFileContentsWithCheckDecompressBlock:(ZipArchiveCheckDecompressBlock)checkDecompressBlock dataAcceptBlock:(ZipArchiveDataAcceptBlock)dataAcceptBlock;

It loops over all entires in a zip file. For each entry, it first calls the CheckDecompressBlock to see if the file should be decompressed, and if so, then call the dataAcceptBlock with the decompressed data.

For some cases, this reduces the peak memory usage by orders of magnitude. (E.g. I have a .zip file with a thousand smaller entries that need to be imported into a sqlite database.)

The patch also refactors UnzipFileToMemory and getZipFileContents to use this iterator.

mattconnolly commented 9 years ago

Can you rename the method to be "enumerate" instead of "iterate" to be consistent with NSArray, NSFileManager, NSFastEnumeration etc.

wallclimber21 commented 9 years ago

Not sure if it will automatically show up here, but there was a crucial bug in the unzip code, that I fixed after renaming the iterate to enumerate. It's already present in my tree.