I am developing an iOS application, and trying to zip the file I have created in the application, is there any built in function able to do this?
I definitely recommend Objective-Zip. It just recently moved to https://github.com/flyingdolphinstudio/Objective-Zip:
Some examples from their documentation:
Creating a Zip File:
ZipFile *zipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeCreate];
Adding a file to a zip file:
ZipWriteStream *stream= [zipFile writeFileInZipWithName:@"abc.txt" compressionLevel:ZipCompressionLevelBest];
[stream writeData:abcData];
[stream finishedWriting];
Reading a file from a zip file:
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
[unzipFile goToFirstFileInZip];
ZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
int bytesRead= [read readDataWithBuffer:data];
[read finishedReading];
As Alex pointed out, I responded to this question by pointing out the NSData category contributed by users of the Cocoadev wiki. That category includes methods for dealing with zipped and gzipped data in an NSData instance (that could be read from a Zip file or written to one). This should be all you need to implement the file zipping you describe, as long as you can feed your file data into an NSData instance.
For an example of this category in action, please see the source code for my iPhone application, Molecules. I only use the method to extract data from a gzipped file (in SLSMolecule+PDB.m), but you should be able to get the basic concepts from that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With