iOS Objective-Zip 损坏问题

标签 ios objective-c zip objectivezip

我正在使用 flyingdolphinstudio 的 Objective-Zip,这是一个 Objective-C 压缩库。我正在按照 this question 中给出的答案使用它来压缩 .txt 文件.

对于我的情况,我没有要循环的数组,所以对于单个文件我有以下内容:

ZipFile *zipFile= [[ZipFile alloc] initWithFileName:zip_file_name mode:ZipFileModeCreate];

NSDictionary *attributes = [[NSFileManager defaultManager]attributesOfItemAtPath:txt_file_name error:&error];
NSDate *Date = [attributes objectForKey:NSFileCreationDate];

NSData *filedata = [NSData dataWithContentsOfFile:txt_file_name];

ZipWriteStream *stream = [zipFile writeFileInZipWithName:txt_file_name fileDate:Date compressionLevel:ZipCompressionLevelBest];
[stream writeData:filedata];
[stream finishedWriting];

[zipFile close];

压缩过程似乎有效,我得到了一个具有正确名称非零 大小的 .zip 文件。但是,当我尝试在我的 Mac 上解压缩它时,它会遇到 .cpgz 循环。并根据 this article 判断,我认为这是因为我的文件在那里的某个地方被损坏了。此外,当我将它上传到服务器并尝试在 Linux 机器上打开它时,它会向我们吐出错误:

$ unzip COCR2_100.zip Archive: COCR2_100.zip End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. note: COCR2_100.zip may be a plain executable, not an archive unzip: cannot find zipfile directory in one of COCR2_100.zip or COCR2_100.zip.zip, and cannot find COCR2_100.zip.ZIP, period.

这也表明它已损坏。

有人知道它为什么会损坏吗? 谢谢!

最佳答案

通过切换到不同的 Zip 客户端解决了这个问题。从 Objective-Zip 移动到 ZipArchive,这似乎工作得很好。

关于iOS Objective-Zip 损坏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17855716/

相关文章:

iphone - 是否可以在 iOS 应用程序中显示工具提示?

C# 和 Zip 文件操作

ios - Pod文件在一段时间后不断消失

ios - 将 bool 保存到 NSUserDefaults 并使用 Swift 在 if 语句中使用它

ios - NSClassFromString 为嵌套类返回 nil

ios - XCode - 添加带有选项卡样式的按钮?

objective-c - AF联网进展

objective-c - makeObjectsPerformSelector :

android - 在 Android Assets 中解压文件

C# 使用FileStream读取 'Zip'文件