How to read image files directly from zip without extracting to disk?

What I want to do is assign images to ui elements at runtime (think of Winamp style), but I have no idea how to proceed with reading from zip without saving to disk. Or how to assign each image to ui element

I am working on mac with cocoa and objective c

+6
source share
2 answers

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]; 
+5
source

zipzap version:

 ZZArchive* archive = [ZZArchive archiveWithContentsOfURL:[NSURL fileURLWithPath:@"test.zip"]]; NSData* data = [archive.entries[0] newDataWithError:nil]; 

Or if you are looking for a specific 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 such files is pretty optimal. The scan uses only the central zip directory and does not actually retrieve data until -[entry newDataWithError:] .

+1
source

Source: https://habr.com/ru/post/913637/


All Articles