Sample code for 30+ languages & platforms
Objective-C

Download a Zip from a URL and OpenBd. (No .zip file is created)

See more Zip Examples

Demonstrates how to download a .zip from a URL, opens the Zip, and gets the contents of a file. No file is ever written.

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoBinData.h>
#import <CkoZip.h>
#import <CkoZipEntry.h>
#import <NSString.h>
#import <CkoStringBuilder.h>

BOOL success = NO;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];

CkoBinData *bd = [[CkoBinData alloc] init];

// This URL is valid and can be tested...
success = [http QuickGetBd: @"https://chilkatdownload.com/example_data/hamlet.zip" binData: bd];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoZip *zip = [[CkoZip alloc] init];

// Open the zip from the bytes contained in bd.
success = [zip OpenBd: bd];
if (success == NO) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

// Get the entry for the file we want..
CkoZipEntry *entry = [[CkoZipEntry alloc] init];
success = [zip EntryOf: @"hamlet.xml" entry: entry];
if (success == NO) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

// Convert all line endings to CRLF (if needed)
int lineEndingBehavior = 2;
NSString *xmlStr = [entry UnzipToString: [NSNumber numberWithInt: lineEndingBehavior] srcCharset: @"utf-8"];
if (entry.LastMethodSuccess == NO) {
    NSLog(@"%@",entry.LastErrorText);
    return;
}

// The XML in this case is about 274K, so let's just examine the last 20 lines...
CkoStringBuilder *sb = [[CkoStringBuilder alloc] init];
[sb Append: xmlStr];

NSLog(@"%@",[sb LastNLines: [NSNumber numberWithInt: 20] bCrlf: YES]);