ZipArchive on the iPhone unzips files but they are empty

Posted by user345131 on Stack Overflow See other posts from Stack Overflow or by user345131
Published on 2010-05-20T18:47:19Z Indexed on 2010/05/20 18:50 UTC
Read the original article Hit count: 317

Filed under:

I'm trying to use ZipArchive on the iPhone to unzip a simple text file. It returns with no error but the file is empty. I would love to know why this doesn't work. I am using the following methods:

-(void)alert:(NSString*)message
{
  UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"" 
                         message:message delegate:self cancelButtonTitle:@"Ok"
                         otherButtonTitles:nil, nil]; 
 [myAlert show]; 
 [myAlert release];    
}

-(void)unzip
{
  NSString *sourcepath = [[NSBundle mainBundle] pathForResource:@"secret" ofType:@"zip"];  
  NSString*filename = @"secret.txt";
  NSArray *docPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
  NSString *destinationpath = [docPaths objectAtIndex: 0];
  if (filename != nil )
   destinationpath = [destinationpath stringByAppendingPathComponent: filename];

  ZipArchive* za = [[ZipArchive alloc] init];
  if( [za UnzipOpenFile:sourcepath Password:@""] )
  {
   BOOL ret = [za UnzipFileTo:destinationpath overWrite:YES];
   if( NO==ret ) [self alert:@"Problem"];
   else  [self alert:@"Success"];
   [za UnzipCloseFile];
  }
  [za release];
  NSString *test = [[NSString alloc] initWithContentsOfFile:destinationpath 
                                     encoding:NSASCIIStringEncoding error:nil];
 [self alert:test];
}

© Stack Overflow or respective owner

Related posts about iphone