0

Unzipping Files In iOS Using ZipArchive

-

In this tutorial, I am going to demonstrate how you can zip and unzip files from within your iOS applications. We will be using a third party library called ZipArchive to achieve this. While there are a couple solutions out there to zip and unzip files, I feel that the ZipArchive library was the fastest and easiest way to get up and running.

(more...)

0

ZipKit Example

-

Quick and easy way to inflate an archive using the fantastic ZipKit.
<br />

  1. - (void)inflateArchive {
  2. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  3.  
  4. NSString *archivePath = [self archivePath];
  5. ZKFileArchive *archive = [ZKFileArchive archiveWithArchivePath:archivePath];
  6. [archive setDelegate:self];
  7. [self setArchiveSize:[[[archive centralDirectory] valueForKeyPath:@"@sum.uncompressedSize"] unsignedLongValue]];
  8. [archive inflateToDiskUsingResourceFork:NO];
  9.  
  10. // do something with inflated archive.
  11. // zipkit puts all inflated files in the same directory as the archive.
  12.  
  13. [self performSelectorOnMainThread:@selector(inflateComplete) withObject:nil waitUntilDone:NO];
  14.  
  15. [pool drain];
  16. }
  17.  
  18. - (void)inflateComplete {
  19. // do something after inflate finishes.
  20. }
  21.  
  22. # pragma mark -
  23. # pragma mark ZKArchive delegate methods
  24.  
  25. - (void)onZKArchive:(ZKArchive *) archive didUpdateBytesWritten:(unsigned long long)byteCount {
  26. [self setArchiveProgress:[self archiveProgress] + byteCount];
  27.  
  28. if ([self archiveSize]
  29.  
  30. [[self progressView] setProgress:(float)[self archiveProgress] / (float)[self archiveSize]];
  31. }
  32.  
  33. - (BOOL)zkDelegateWantsSizes {
  34. return YES;
  35. }
- (void)inflateArchive {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSString *archivePath = [self archivePath];
ZKFileArchive *archive = [ZKFileArchive archiveWithArchivePath:archivePath];
[archive setDelegate:self];
[self setArchiveSize:[[[archive centralDirectory] valueForKeyPath:@"@sum.uncompressedSize"] unsignedLongValue]];
[archive inflateToDiskUsingResourceFork:NO];

// do something with inflated archive.
// zipkit puts all inflated files in the same directory as the archive.

[self performSelectorOnMainThread:@selector(inflateComplete) withObject:nil waitUntilDone:NO];

[pool drain];
}

- (void)inflateComplete {
// do something after inflate finishes.
}

# pragma mark -
# pragma mark ZKArchive delegate methods

- (void)onZKArchive:(ZKArchive *) archive didUpdateBytesWritten:(unsigned long long)byteCount {
[self setArchiveProgress:[self archiveProgress] + byteCount];

if ([self archiveSize]

[[self progressView] setProgress:(float)[self archiveProgress] / (float)[self archiveSize]];
}

- (BOOL)zkDelegateWantsSizes {
return YES;
}

<br />