views:

164

answers:

2

Hi,

I am trying to compress multiple files into a single zip archive and I am running into low memory warning. Since the complete zip file is loaded into the memory I guess that's the problem. Is there a way by which I can manage the compression/decompression better using ZipArchive so that not all the data is in the memory at once?

Thanks!

A: 

Have you figured this out guys? I ran into the same problem while unzipping a big file. With Instruments I managed to find that the minizip library (unzip.c) may have a problem. Mithin and Enrique have you managed to locate the source of the problem?

Alex
I haven't figured it out yet unfortunately :( My app keeps crashing when trying to add many large files. I'm about to try a different library called ZipKit: http://bitbucket.org/kolpanic/zipkit/wiki/UsingZipKit I will report my results with this library when I get it working.
Enrique R.
Thanks Enrique! Maybe I will try that too!
Alex
@Alex I just found an alternate solution that is working pretty good for me so far. Read my answer below. Cheers.
Enrique R.
A: 

After doing some investigation on alternatives to ZipArchive I found another project called Objective-zip that seems to be a little better than ZipArchive. Here is the link:

http://code.google.com/p/objective-zip/

The API is quite simple. One thing I ran into was that in the begging I was reading data and never releasing it so if you are adding a bunch of large files to the zip file remember to release the data. Here is a little code I used:

ZipFile *zipFile = [[ZipFile alloc] initWithFileName:archivePath mode:ZipFileModeCreate];

for(NSString *path in subpaths){
  NSData *data= [[NSData alloc] initWithContentsOfFile:longPath];
  ZipWriteStream *stream = [zipFile writeFileInZipWithName:path compressionLevel:ZipCompressionLevelNone];
  [stream writeData:data];
  [stream finishedWriting];
  [data release];
}

[zipFile close];
[zipFile release];

I hope this is helpful for anyone who runs into the same issue.

Enrique R.