Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-31-2009, 05:59 PM   #26 (permalink)
New Member
 
Join Date: Jul 2009
Posts: 3
Default

DO I need to add any particular flags for it to compile with Xcode. It doesn't like the way the functions are defined.
fugusowri is offline   Reply With Quote
Old 08-12-2009, 07:11 AM   #27 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Canada
Age: 26
Posts: 49
Default

I'm trying to compile this but I get:

miniunz.c:20:21: error: direct.h: No such file or directory
miniunz.c:21:17: error: io.h: No such file or directory

Should these files exist from the XCode SDK by default?
zenox is offline   Reply With Quote
Old 08-18-2009, 10:25 AM   #28 (permalink)
nyu
Registered Member
 
Join Date: Jul 2009
Posts: 2
Default

Hi.

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 hope someone could help me with this.
nyu is offline   Reply With Quote
Old 09-16-2009, 08:56 AM   #29 (permalink)
Candy Mountain, Charlie..
 
ovidiu's Avatar
 
Join Date: Mar 2009
Location: Romania
Age: 25
Posts: 116
Default

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.

Any ideas for achieving that?

Thanks.
__________________
Junior iPhone Developer
Mobile Touch Romania
ovidiu is offline   Reply With Quote
Old 09-16-2009, 11:14 AM   #30 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,558
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

Yea. You can run a synchronous method in a background thread and free up the interface so you can use your activity indicator.
smithdale87 is offline   Reply With Quote
Old 09-17-2009, 02:32 AM   #31 (permalink)
Candy Mountain, Charlie..
 
ovidiu's Avatar
 
Join Date: Mar 2009
Location: Romania
Age: 25
Posts: 116
Default

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..
__________________
Junior iPhone Developer
Mobile Touch Romania
ovidiu is offline   Reply With Quote
Old 09-17-2009, 11:48 AM   #32 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Quote:
Originally Posted by ovidiu View Post
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.

Mac Dev Center: NSObject Class Reference
jsd is offline   Reply With Quote
Old 12-30-2009, 09:37 AM   #33 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 33
Default how did you get Zip file in Document directory???

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....
asimrs is offline   Reply With Quote
Old 12-30-2009, 09:46 AM   #34 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

use this:

success = [[NSFileManager defaultManager] copyItemAtPath:defaultPath toPath:writablePath error:&error];
lbendlin is offline   Reply With Quote
Old 12-30-2009, 10:52 AM   #35 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 792
Default

You can add a couple methods to the ZipArchiveDelegate protocol that indicates progress and capture it back in your side, in a separate thread.
nobre84 is offline   Reply With Quote
Old 02-04-2010, 03:50 PM   #36 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 67
Question unzip arbitrary file extension

Hi,

I have a sample.zip file that I renamed to sample.xyz.

How can I modify the library to work for any arbitrary extension?

Does the current library look for .zip in the file name/path?

Thanks,

-FerrariX
FerrariX is offline   Reply With Quote
Old 02-04-2010, 07:29 PM   #37 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 246
Default

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?
linkmx is offline   Reply With Quote
Old 02-11-2010, 11:11 AM   #38 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 14
Default

Was able to get this running in my app.

Was able to NSData to file decompression and File to NSData decompression.

Wondering if someone has looked at modifying the classes to allow decompression/compression between NSData objects?

Thank you in advance
-James
JamesT0723 is offline   Reply With Quote
Old 02-17-2010, 07:24 PM   #39 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 62
Default can someone tell me what I'm doing wrong?

Code:
	
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];
oh, and constants defined in header file

Code:
#define l_zipfile @"test.zip"
#define l_photo @"happyJack.png"
happyJack.png is added to the project in Xcode.
I'm looking for the .zip file to be created in User/Applications/some big long string/Documents

Many thanks in advance
intomo is offline   Reply With Quote
Old 02-17-2010, 08:09 PM   #40 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Code:
NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
ZunePod is offline   Reply With Quote
Old 02-17-2010, 08:53 PM   #41 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 62
Default what else am I doing wrong?

So I've added the function
Code:
- (NSString *)dataFilePath
{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	return [documentsDirectory stringByAppendingPathComponent:l_zipfile];
}
and then I've modified the zip creating function

Code:
-(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?

Thanks again!
intomo is offline   Reply With Quote
Old 02-17-2010, 09:32 PM   #42 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 62
Default nevermind

Code:
- (NSString *)dataFilePath:(NSString *)file
{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	return [documentsDirectory stringByAppendingPathComponent:file];
}
I needed to modify that so that I could pass in parameters. The code didn't know where the photo file was.

Code:
-(IBAction)createZip:(id)sender
{
	
	NSLog(@"Entering %s", __FUNCTION__);
	
	NSString *filePath = [self dataFilePath:l_zipfile];
	
	ZipArchive *currentZip = [[ZipArchive alloc] init];
	BOOL ret = [currentZip CreateZipFile2:filePath];
	
	
	
	ret = [currentZip addFileToZip:[self dataFilePath:l_photo];" newname:@"jack.png"];
	if( ![currentZip CloseZipFile2] )
	{
		NSLog(@"Zip Error");
	}
	[currentZip release];
}
Thanks again!
intomo is offline   Reply With Quote
Old 02-22-2010, 12:39 AM   #43 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 246
Default

Hi, quick question, is there any way to check if a file is protected so I can ask the user for a password?
linkmx is offline   Reply With Quote
Old 02-27-2010, 12:47 PM   #44 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 67
Default non-US character password

Hi,

Is there away to make this work for non-US encoded character as password?

if the password is in japanese, it will not work.

I'm thinking it has to do with the CStringEncoding:NSASCIIEnconding line.

please share if you have successfully got it working for non-ascii character passwords.

Thanks,

-FerrariX
FerrariX is offline   Reply With Quote
Old 05-11-2010, 01:52 PM   #45 (permalink)
Tutorial Author
 
Steaps's Avatar
 
Join Date: Oct 2008
Location: Ontario, Canada
Posts: 466
Default

Will this work on Mac OS X? (I have only coded on iPhone OS so i have no idea looking through the source code :P)

And can you ZIP a folder with it?
Steaps is offline   Reply With Quote
Old 06-15-2010, 05:38 AM   #46 (permalink)
you are what you hide.
 
Join Date: Apr 2010
Location: India
Posts: 49
Default minizip

minizip is working. its not buggy.
Has anyone implemented this for ePub unzip?

Regards
Ranjan

Last edited by iRanjan; 06-15-2010 at 06:04 AM.
iRanjan is offline   Reply With Quote
Old 06-22-2010, 10:18 AM   #47 (permalink)
Taz
Registered Member
 
Join Date: Jun 2010
Posts: 3
Default

Quote:
Originally Posted by lbendlin View Post
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};
...........


NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
return;
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent: @"file.zip"];

NSData *dataDataSet = [self UnzipFileToData:appFile];

Program received signal: “EXC_BAD_ACCESS”.
in line int ret = unzGoToFirstFile( unzipFile );
Taz is offline   Reply With Quote
Old 06-30-2010, 09:26 PM   #48 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 1
Default Extract data to NSData

ZipArchive.h

-(NSArray *) UnzipFileLists;
-(NSData *) dataForUnzipFileNameNSString *)fileName;


ZipArchive.mm

Code:
-(NSData *) dataForUnzipFileName:(NSString *)fileName {
	int ret = unzLocateFile(_unzFile, [fileName UTF8String], 0);
	if(ret != UNZ_OK) {
		[self OutputErrorMessage:@"File not found!"];
		return nil;
	}
	
	NSMutableData *data = [NSMutableData data];
	unsigned char		buffer[4096] = {0};
	int byteRead;

	if( [_password length]==0 )
		ret = unzOpenCurrentFile( _unzFile );
	else
		ret = unzOpenCurrentFilePassword( _unzFile, [_password cStringUsingEncoding:NSASCIIStringEncoding] );
	if( ret!=UNZ_OK )
	{
		[self OutputErrorMessage:@"Error occurs"];
		return nil;
	}

	while( YES )
	{
		byteRead=unzReadCurrentFile(_unzFile, buffer, 4096);
		if( byteRead > 0 )
		{
			[data appendBytes:buffer length:byteRead];
//			fwrite(buffer, read, 1, fp );
		}
		else if( byteRead<0 )
		{
			[self OutputErrorMessage:@"Failed to reading zip file"];
			break;
		}
		else 
			break;				
	}
	unzCloseCurrentFile( _unzFile );
	return ([data length] != 0)?data:nil;
	
}

-(NSArray *) UnzipFileLists {
	BOOL success = YES;
	int ret = unzGoToFirstFile( _unzFile );
//	unsigned char		buffer[4096] = {0};
//	NSFileManager* fman = [NSFileManager defaultManager];
	if( ret!=UNZ_OK )
	{
		[self OutputErrorMessage:@"Failed"];
	}
	
	NSMutableArray *fileLists = [NSMutableArray array];
	
	do{
		// Get file info
		unz_file_info	fileInfo ={0};
		ret = unzGetCurrentFileInfo(_unzFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
		if( ret!=UNZ_OK )
		{
			[self OutputErrorMessage:@"Error occurs while getting file info"];
			success = NO;
			break;
		}
		char* filename = (char*) malloc( fileInfo.size_filename +1 );
		unzGetCurrentFileInfo(_unzFile, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
		filename[fileInfo.size_filename] = '\0';
		
		// check if it contains directory
		NSString * strPath = [NSString  stringWithCString:filename];
		BOOL isDirectory = NO;
		if( filename[fileInfo.size_filename-1]=='/' || filename[fileInfo.size_filename-1]=='\\')
			isDirectory = YES;
		free( filename );
		if( [strPath rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"/\\"]].location!=NSNotFound )
		{// contains a path
			strPath = [strPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
		}
		
		if(strPath != nil)
			[fileLists addObject:strPath];

		ret = unzGoToNextFile( _unzFile );
	}while( ret==UNZ_OK && UNZ_OK!=UNZ_END_OF_LIST_OF_FILE );
	return fileLists;
}
randomdot is offline   Reply With Quote
Old 08-05-2010, 10:46 AM   #49 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 1
Default

Hey

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.

Thanks in advance
Nik
cooldudenj is offline   Reply With Quote
Old 08-26-2010, 03:57 AM   #50 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 1
Default unzip file

Dear all,

I can't download the file : http://flyblog.com/wp-content/upload...zipfile-oc.zip.
Could somebody can upload the file ?

I don't know how to unzip a file. What's the calling sequence ?

Ohh... I can write the codes correctly.

Thanks for your help.

Last edited by cookie123tw; 08-27-2010 at 12:11 AM.
cookie123tw is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 253
19 members and 234 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, MACralik, NSeven, prchn4christ, Rudy
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0