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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-22-2010, 09:18 AM   #47 (permalink)
Taz
Registered Member
 
Join Date: Jun 2010
Posts: 3
Taz is on a distinguished road
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
 

» Advertisements
» Online Users: 372
13 members and 359 guests
Apptronics RBC, Bad_bmw3, Creativ, Domele, eski, iMax 3060, jbro, JoeRCruso, linkmx, mistergreen2011, Newbie123, revg, RickSDK
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,551
Threads: 94,078
Posts: 402,727
Top Poster: BrianSlick (7,990)
Welcome to our newest member, hongto24
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:31 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.