简体   繁体   English

在Xcode中使用GZIP压缩CSV文件

[英]Compress CSV file with GZIP in xcode

I need to create a big table to csv file and compress it. 我需要创建一个大表以csv文件并将其压缩。

I can create the csv file like this: Xcode - Create csv/spreadsheet file 我可以这样创建csv文件: Xcode-创建csv /电子表格文件

It is possible compress it with GZIP? 可以用GZIP压缩吗?

Thanks for all. 谢谢大家

Best regards. 最好的祝福。

I recommend you use SSZipArchive: https://github.com/soffes/ssziparchive 我建议您使用SSZipArchive: https : //github.com/soffes/ssziparchive

Then you can do: 然后,您可以执行以下操作:

NSString *content = @"1,2,3"
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"somefile.zip"];
SSZipArchive *zip = [[SSZipArchive alloc] initWithPath:path];
[zip open];
[zip writeData:[content dataUsingEncoding:NSUTF8StringEncoding] filename:@"data.csv"];
[zip close];

That will produce a zip file named "somefile.zip" in the temporary directory, containing one file inside named "data.csv" 这将在临时目录中生成一个名为“ somefile.zip”的zip文件,其中包含一个名为“ data.csv”的文件

最简单的方法可能是不使用标准的复制构建阶段将文件移动到位,而是使用Shell脚本构建阶段复制文件,然后使用gzip将其压缩到位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM