What I want to do is assign images to ui elements at runtime (think Winamp style) but I have no idea how to go about reading from a zip without storing to disk. Or how to as
The zipzap version:
ZZArchive* archive = [ZZArchive archiveWithContentsOfURL:[NSURL fileURLWithPath:@"test.zip"]];
NSData* data = [archive.entries[0] newDataWithError:nil];
Or if you're looking for a particular entry:
ZZArchive* archive = [ZZArchive archiveWithContentsOfURL:[NSURL fileURLWithPath:@"test.zip"]];
NSData* data = nil;
for (ZZArchiveEntry* entry in archive.entries)
if ([entry.fileName isEqualToString:@"test.txt"])
{
data = [entry newDataWithError:nil];
break;
}
Scanning for files like this is pretty much optimal. The scan only uses the zip central directory and doesn't actually extract the data until -[entry newDataWithError:].
Use objective-c zip (iOS/Mac zlib wrapper)
Then you can do:
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
[unzipFile goToFirstFileInZip];
ZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
int bytesRead= [read readDataWithBuffer:data];
[read finishedReading];