(Objective-C) Unzip Text File to String
Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable. Note: This example requires Chilkat v11.0.0 or greater.
#import <CkoZip.h>
#import <CkoZipEntry.h>
#import <NSString.h>
BOOL success = NO;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoZip *zip = [[CkoZip alloc] init];
success = [zip OpenZip: @"qa_data/zips/EC16100.zip"];
if (success == NO) {
NSLog(@"%@",zip.LastErrorText);
return;
}
// Get the 1st file in the .zip
CkoZipEntry *entry = [[CkoZipEntry alloc] init];
success = [zip EntryAt: [NSNumber numberWithInt: 0] entry: entry];
if (success == NO) {
NSLog(@"%@",zip.LastErrorText);
return;
}
NSString *fileContents = [entry UnzipToString: [NSNumber numberWithInt: 0] srcCharset: @"utf-8"];
NSLog(@"%@",fileContents);
|