数据存储 - 使用 SSZipArchive 实现文件的压缩和解压缩
变更记录
序号 | 录入时间 | 录入人 | 备注 |
---|---|---|---|
1 | 2015-04-03 | Alfred Jiang | - |
2 | 2015-12-23 | Alfred Jiang | - |
方案名称
数据存储 - 使用 SSZipArchive 实现文件的压缩和解压缩
关键字
数据存储 \ 文件 \ 压缩 \ 解压缩 \ zip \ unzip
需求场景
- 需要对文件进行压缩和解压缩操作时
参考链接
详细内容
- 将 SSZipArchive 文件加入工程
- 引入 SSZipArchive.h 头文件
- 添加 libz.dylib 库
- 用法
1
2
3
4
5
6
7
8
9
10
11
12// Unzipping
NSString *zipPath = @"path_to_your_zip_file";
NSString *destinationPath = @"path_to_the_folder_where_you_want_it_unzipped";
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];
// Zipping
NSString *zippedPath = @"path_where_you_want_the_file_created";
NSArray *inputPaths = [NSArray arrayWithObjects:
[[NSBundle mainBundle] pathForResource:@"photo1" ofType:@"jpg"],
[[NSBundle mainBundle] pathForResource:@"photo2" ofType:@"jpg"]
nil];
[SSZipArchive createZipFileAtPath:zippedPath withFilesAtPaths:inputPaths];
Swift 使用实例
1 | var zipPath = NSBundle.mainBundle().pathForResource("TestArchive", ofType: "zip") |
Objective-C 使用实例
1 | NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestArchive" ofType:@"zip"]; |
效果图
(无)
备注
(无)
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 宁静至远,博雅多通!