我正在使用flyingdolphinstudio的Objective-Zip這是一個Objective-C壓縮庫。我正在使用這個按照this question中給出的答案壓縮.txt文件。iOS Objective-Zip損壞問題
對於我來說,我沒有一個數組循環,從而只爲一個單一的文件,我有以下:
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.
這也表明,它已損壞。
有沒有人有任何想法,爲什麼它可能會被損壞? 謝謝!