(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.
#import <CkoZip.h>
#import <CkoZipEntry.h>
#import <NSString.h>
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoZip *zip = [[CkoZip alloc] init];
BOOL success = [zip OpenZip: @"qa_data/zips/EC16100.zip"];
if (success != YES) {
NSLog(@"%@",zip.LastErrorText);
return;
}
// Get the 1st file in the .zip
CkoZipEntry *entry = [zip GetEntryByIndex: [NSNumber numberWithInt: 0]];
if (zip.LastMethodSuccess != YES) {
NSLog(@"%@",@"No files in this zip.");
return;
}
NSString *fileContents = [entry UnzipToString: [NSNumber numberWithInt: 0] srcCharset: @"utf-8"];
NSLog(@"%@",fileContents);
|