iOS学习笔记之文件的压缩和解压(zip)

来源:互联网 发布:分享赚钱的软件 编辑:程序博客网 时间:2024/06/06 04:50

*******************************文件的压缩和解压*****************************
运行环境:Xcode7 iOS9.0


第三方框架:SSZipArchive
动态库:libz.tbd


/**
 * zip : 压缩文件
 * filePath : 压缩后存放的路径
 * directory : 需要压缩的文件夹路径
 */
- (void)zip
{
    NSString *filePath = @"/Users/iphone5solo/Desktop/images.zip";
    NSString *directory = @"/Users/iphone5solo/Documents/截图文件";
    [SSZipArchive createZipFileAtPath:filePath withContentsOfDirectory:directory];
}


/**
 * unzip : 解压文件
 * filePath : 需要解压文件的路径
 * directory : 解压后的文件夹路径
 */
- (void)unzip
{
    NSString *filePath = @"/Users/iphone5solo/Desktop/images.zip";
    NSString *directory = @"/Users/iphone5solo/Desktop/images";
    [SSZipArchive unzipFileAtPath:filePath toDestination:directory];
}


/**
 * selectZip : 选择性压缩文件
 * filePath : 解压后文件的路径
 * arrayZip : 这是一个数组,存储所要压缩的文件的路径
 */
- (void)selectZip
{
    NSString *filePath = @"/Users/iphone5solo/Desktop/images.zip";
    NSArray *arrayZip = @[@"/Users/iphone5solo/Documents/截图文件/1.jpg",@"/Users/iphone5solo/Documents/截图文件/2.jpg",@"/Users/iphone5solo/Documents/截图文件/3.jpg"];
    [SSZipArchive createZipFileAtPath:filePath withFilesAtPaths:arrayZip];
    
}
0 0
原创粉丝点击