压缩文件:
ZipArchive *zip = [[ZipArchive alloc] init];
NSString *sZipPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.zip"];
NSString *img1Path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/img1.jpg"] ;
NSString* img2Path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/img2.jpg"] ;
BOOL bRet = [zip CreateZipFile2:sZipPath];
bRet = [zip addFileToZip:img1Path newname:@"img1.jpg"];
bRet = [zip addFileToZip:img2Path newname:@"img2.jpg"];
[zip CloseZipFile2];
[zip release];
解压缩:
ZipArchive *zip = [[ZipArchive alloc] init];
NSString *sZipPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.zip"];
NSString *unZipTo = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test"];
if ([zip UnzipOpenFile:sZipPath])
{
[zip UnzipFileTo:unZipTo overWrite:YES];
[zip UnzipCloseFile];
}
[zip release];