abbeycode / UnzipKit

An Objective-C zlib wrapper for compressing and decompressing ZIP files
BSD 2-Clause "Simplified" License
83 stars 22 forks source link

Running out of memory extracting archives with large files embedded #27

Closed brendand closed 8 years ago

brendand commented 8 years ago

Different from the 64 bit issue, this time my iOS app aborts when I attempt to unzip an archive that contains a file that expands to 1.4 GB. The zipped archive itself is 775 MB, but unzips much larger. There are other files in the archive, but the main file is this big 1.4 GB file.

The issue is in the extractFilesTo:overwrite:progress:error method. It reads the entire file from the archive into memory and then writes it out. Specifically right off the bat, the readFile:length:error method allocates an NSMutableData object that's as big as the file. Boom on iOS!

Instead, I would recommend using your own extractBufferedData:fromFile:error:action method to unzip all the files in an archive. That way you improve memory usage considerably and then it doesn't matter how big any individual file is.

abbeycode commented 8 years ago

That's a great idea! The extractBufferedData:fromFile:error:action call is newer and I didn't think to go back and use it there. I'll take a look at your pull request as soon as I can.

abbeycode commented 8 years ago

This has been addressed in PR #28 and will be released in v1.7

abbeycode commented 8 years ago

v1.7 is live on CocoaPods now, including this fix. Thanks again @brendand for all the hard work!

brendand commented 8 years ago

No, thank you for making this awesome library!