Objective-C
Objective-C
Example for the Zip AppendNew Function
See more Zip Examples
Demonstrates the Zip AppendNew function.Chilkat Objective-C Downloads
#import <CkoZip.h>
#import <NSString.h>
#import <CkoZipEntry.h>
BOOL success = NO;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoZip *zip = [[CkoZip alloc] init];
NSString *zipPath = @"c:/temp/qa_output/test.zip";
// Initialize the zip object, which also sets the FileName property to the path of the zip to be created.
[zip NewZip: zipPath];
// Append a new and empty file to the zip object.
// This does not write the zip file. It simply adds an entry
// that will get processed when the zip is written.
[zip AddEmpty: NO pathInZip: @"empty.txt"];
// Append another entry..
NSString *pathInZip = @"abc/helloWorld.txt";
[zip AddEmpty: NO pathInZip: pathInZip];
// Add some data to this entry..
CkoZipEntry *entry = [[CkoZipEntry alloc] init];
[zip EntryOf: pathInZip entry: entry];
[entry AppendString: @"Hello World" charset: @"utf-8"];
// Write the zip, which contains 2 files: empty.txt and helloWorld.txt
zip.FileName = zipPath;
success = [zip WriteZipAndClose];
if (success == NO) {
NSLog(@"%@",zip.LastErrorText);
return;
}
NSLog(@"%@",@"Success.");