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 assign each image to a ui element
I'm working on a mac with cocoa and objective c
Vim command can also be used to view the contents of a ZIP archive without extracting it. It can work for both the archived files and folders. Along with ZIP, it can work with other extensions as well, such as tar. xz, tar.
ZIP file without extracting them, they might not be copied or moved correctly, even though it looks like they have been.
Because Windows makes it easy to work with zip files, there's generally no need to unzip them. However, if you would prefer to unzip them you can simply right-click the zip file's icon and select Extract All.
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];
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:]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With