我正在开发一个 iOS 应用程序,并试图压缩我在该应用程序中创建的文件,是否有任何内置函数可以执行此操作?
最佳答案
我绝对推荐 Objective-Zip。它最近刚搬到 https://github.com/flyingdolphinstudio/Objective-Zip :
他们文档中的一些示例:
创建 Zip 文件:
ZipFile *zipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeCreate];
将文件添加到 zip 文件:
ZipWriteStream *stream= [zipFile writeFileInZipWithName:@"abc.txt" compressionLevel:ZipCompressionLevelBest];
[stream writeData:abcData];
[stream finishedWriting];
从 zip 文件中读取文件:
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
[unzipFile goToFirstFileInZip];
ZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
int bytesRead= [read readDataWithBuffer:data];
[read finishedReading];
关于objective-c - 如何使用 Objective C 创建 zip 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/286496/