First, thanks for this useful script.
But I have some errors occurring when I want to use it in an XCode project.
I've added the libz.1.2.3.dylib in the project and also checked that a reference for 'ZipArchive.mm' was added in 'Targets -> Project Name -> Compile Sources'. I've corrected in 'ZipArchive.h' the paths for 'zip.h' and 'unzip.h' by deleting '../'.
But I'm still having some error lines and don't know where did they come from. Here's a sample of an error I'm facing :
'"_unzCloseCurrentFile", referenced from:'
'-[ZipArchive UnzipFileTo: overWrite:] in ZipArchive.o'
The others are similar to this one.
I bring the topic alive again, I am interested if any improvements showed up meanwhile for this tool.
The situation is that I have to unarchive a large .zip file (20 MB), and it takes about 10 seconds on the device because it is a syncronous operation and it blocks the interface.. So what I want to do is to show up an UIActivityIndicatorView while the app is performing the unarchiving operation.
Ok, but how can I know exactly when the unarchiving is done? The only thing I have in mind is to use an NSTimer and check periodically if it finished.. then stop the activity indicator..
Ok, but how can I know exactly when the unarchiving is done? The only thing I have in mind is to use an NSTimer and check periodically if it finished.. then stop the activity indicator..
Start the activity indicator, fire the thread, in the thread that does the unarchiving, when it finishes, do a performSelectorOnMainThread to remove the activity indicator.
Only problem which I m facing is how do I move Abc.zip file from resource folder to Documents directory, where I can run Unzip function easily. I tried to copy Abc.zip file throuh NSFileManager but it seems that Xcode doesn't recognize zip as single file. I need your help, please help me to sort it out....
I'm currently using this for an app and it's great, very easy to use. It does accept a zip file even if the extention is not ".zip". A liitle bit off-topic, does anyone knows of a similar library for rar files?
ZipArchive *currentZip = [[ZipArchive alloc] init];
BOOL ret = [currentZip CreateZipFile2:l_zipfile];
// OR
//BOOL ret = [zip CreateZipFile2:l_zipfile Password:@"your password"]; //
//if the Password is empty, will get the same effect as [zip CreateZipFile2:l_zipfile];
ret = [currentZip addFileToZip:l_photo newname:@"jack.png"];
if( ![currentZip CloseZipFile2] )
{
NSLog(@"Zip Error");
}
[currentZip release];
-(IBAction)createZip:(id)sender
{
NSLog(@"Entering %s", __FUNCTION__);
NSString *filePath = [self dataFilePath];
ZipArchive *currentZip = [[ZipArchive alloc] init];
BOOL ret = [currentZip CreateZipFile2:filePath];
// OR
//BOOL ret = [zip CreateZipFile2:l_zipfile Password:@"your password"]; //
//if the Password is empty, will get the same effect as [zip CreateZipFile2:l_zipfile];
ret = [currentZip addFileToZip:@"happyJack.png" newname:@"jack.png"];
if( ![currentZip CloseZipFile2] )
{
NSLog(@"Zip Error");
}
[currentZip release];
}
So it works and the zip file magically appears in the Documents directory. However, when I click on it it says "the file is empty". What else am I doing wrong?
For what it's worth, here is the code to unpack the physical zip file into a NSData structure. Caveat: will only work correctly if the ZIP contains one file.
Code:
-(NSData*) UnzipFileToData {
NSMutableData* data = [[NSMutableData alloc] init];
int ret = unzGoToFirstFile( _unzFile );
unsigned char buffer[4096] = {0};
if( ret!=UNZ_OK )
{
[self OutputErrorMessage:@"Failed to go to first file"];
return data;
}
ret = unzOpenCurrentFile( _unzFile );
if( ret!=UNZ_OK )
{
[self OutputErrorMessage:@"Error opening file"];
return data;
}
// reading data and write to data object
int read = 1 ;
while( read > 0 )
{
read=unzReadCurrentFile(_unzFile, buffer, 4096);
if( read > 0 )
{
[data appendBytes:buffer length:read];
}
else if( read<0 )
{
[self OutputErrorMessage:@"Failed to reading zip file"];
break;
}
else
break;
}
unzCloseCurrentFile( _unzFile );
ret = unzGoToNextFile( _unzFile );
return data;
}
don't work
I added NSString parameter
-(NSData*) UnzipFileToData: (NSString*) unzipFile {
NSMutableData* data = [[NSMutableData alloc] init];
int ret = unzGoToFirstFile( unzipFile );
unsigned char buffer[4096] = {0};
...........
This is a well built library. Great job acsolu..!!
What I wanted to know is how can I zip entire folders with ZipArchive.
I'm developing an app where I need to zip the entire Documents folder in device sandbox.