Binary Lion Studios

I code for fun and for food.

ZipKit example

Quick and easy way to inflate an archive using the fantastic ZipKit.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
- (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 - ZKArchive delegate methods

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

  if ([self archiveSize] <= 0) return;

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

- (BOOL)zkDelegateWantsSizes {
  return YES;
}