title: decompression error while putting together parts with macHacha
body: <p>OK I have app for iPad that reads magazines. All previous issues works fine. I manage to make new issue (before it was done by other guy that left the firm) and to run it in simulator and on device without problems.</p>
  
  <p>Now I add row for new issue of magazine in database and compress all pictures and multimedia by  ZIP tool and divide them by MacHacha (because Java class that uploads demand parts from MacHacha to upload one by one) and upload it on server. In App store I downloaded magazine and can see new issue. On server new row is good have all good parameters and the size is adequate to size on disk. </p>
  
  <p>When new issue finnish download it shows me error. I tried same procedure from simulator and in OUTPUT in the moment it crashes shows me decompression error (0).</p>
  
  <p>I supposed that problem is with putting parts together with MacHacha. Can anyone help or give me that catch that solves this problem.</p>
  
  <p>if it will help I can upload new issue and provide link (it's free) I it will be helpful for  You guys and girls :)</p>
  
  <p><a href="http://www.mazzantieditori.it/applicazioni/219-nycit-italian-american-magazine.html" rel="nofollow">http://www.mazzantieditori.it/applicazioni/219-nycit-italian-american-magazine.html</a></p>
  
  <p>link for application. In library there is few issues and the last one is new (Giugno 2011).</p>
  
  <p>I will provide code for that method that gives me string for mistake:</p>
  
  <pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection
  </code></pre>
  
  <p>{<br>
      // controllo se il receipt è corretto e faccio partire il download
      if(min == 0 &amp;&amp; [receivedData length]
  
  <pre><code>NSString *file = [[self documentsDir:1] stringByAppendingPathComponent:@"archivio.zip"];
  
  if (max &lt;= num &amp;&amp; !cancelDownload) {
      self.progressBar.progress = (1.0f/num)*min;
      min = max+1;
      max += 5;
  
      // creo directory per l'elemento scaricato
      BOOL isDir = NO;
  
      if(![[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&amp;isDir]) {
          NSError *error;
          //creo directory
          [[NSFileManager defaultManager] createDirectoryAtPath:[self documentsDir:1] withIntermediateDirectories:YES attributes:nil error:&amp;error];
          //creo file vuoto
          [[NSFileManager defaultManager] createFileAtPath:file contents:nil attributes:nil];
      }
  
      NSFileHandle *handler = [NSFileHandle fileHandleForWritingAtPath:file];
  
      if(handler) {
          [handler seekToEndOfFile];
          [handler writeData:receivedData];
      }
      NSLog(@"Received %d bytes of data; min: %i max: %i",[receivedData length],min,max);
      [receivedData setLength:0];
  
      // questa è la seconda invocazione
      [self downloadArchivePart:@"verified"];
      [connection release];
      return;
  }
  
  NSFileManager *man = [[NSFileManager alloc] init];
  NSDictionary *attrs = [man attributesOfItemAtPath:file error: NULL];
  //UInt32 result = 
  NSNumber *size = [attrs objectForKey:NSFileSize];
  //int length = [receivedData length];
  NSLog(@"Succeeded! Received %i bytes of data",[size intValue]);
  [man release];
  
  //1.038.090 è il numero di byte della parte più piccola dell'archivio
  if([size intValue]  &gt;= kMinPartSize) {  
  
      NSLog(@"prod %@",self.prodName);
      if(self.prodName == nil || [self.prodName isEqualToString:@""]) self.prodName = prodId;         
  
      NSError *error;
      BOOL ok = [TWZipArchive unzipFileAtPath:file toDestination:[self documentsDir:1] overwrite:YES password:nil error:&amp;error];
      //unzipFileAtPath:file toDestination:[self documentsDir]];
  
      NSString *msg;
      if(ok) {
          NSLog(@"decompression successfull");
          self.progressBar.progress = 1.0f;
          NSFileManager *fm = [NSFileManager defaultManager];
          [fm removeItemAtPath:file error:&amp;error];
          msg = @"Download completed: new issue added in libray";
  
          NSMutableArray *array;
          NSMutableDictionary *dict = [NSMutableDictionary dictionary];
          NSString *path = [[self documentsDir:0] stringByAppendingPathComponent:@"downloaded.plist"];
          if(![[NSFileManager defaultManager] fileExistsAtPath:path]) {   
              [dict setObject:prodId forKey:@"id"];
              [dict setObject:prodName forKey:@"titolo"];
              array = [NSArray arrayWithObject:dict];
              [array writeToFile:path atomically:YES];
          }
          array = [NSMutableArray arrayWithContentsOfFile:path];
          BOOL exist = NO;
          for (int i=0; i&lt;[array count]; i++) {
              if ([[[array objectAtIndex:i] objectForKey:@"id"] isEqualToString:prodId]) {
                  exist = YES;
                  //prodId = [NSString stringWithFormat:@"%@%i",prodId,i];
              }
          }   
  
          if(exist == NO) {
              [dict setObject:prodId forKey:@"id"];
              [dict setObject:prodName forKey:@"titolo"];
              [array insertObject:dict atIndex:0];    //sempre in testa l'ultimo elemento scaricato
              [array writeToFile:path atomically:YES];
          }
  
      }
      else {
          NSLog(@"decompression error");
          msg = @"An error has occurred";
      }
  
      //[myAlert release];
      UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                      message:@"Download completed: new issue added in libray"
                                                     delegate:self 
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles: nil];
      [alert show];
  
      //[alert release];
  }else {
  
      if(cancelDownload == YES) {
  
          UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                          message:@"Download stopped for user action" 
                                                         delegate:self 
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles: nil];
          [alert show];
  
      }else {
  
          NSString *errFile = [[self documentsDir:1] stringByAppendingPathComponent:@"errFile.html"]; 
          [receivedData writeToFile:errFile atomically:YES];
          NSLog(@"err : %@",errFile);
          NSLog(@"scrittura error file eseguita");
  
          NSLog(@"receipt non valido");
          UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                    message:@"Downloading error: please retry later!" 
                                                    delegate:self 
                                                    cancelButtonTitle:@"OK"
                                                    otherButtonTitles: nil];
          [alert show];
      }
  
  
  }
  [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
  progressBar.hidden = YES;
  
  // release the connection, and the data object
  [connection release];
  //[receivedData release];
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks in Advance...</p>