Вопрос

I am using flyingdolphinstudio's Objective-Zip which is an Objective-C zipping library. I am using this to zip a .txt file following the answer given in this question.

For my case, I do not have an array to cycle through so just for a single file I have the following:

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];

The zipping process seems to work, I get a .zip file with the correct name and a non-zero size. However, when I try and un-zip this on my mac, it runs into a .cpgz loop. And judging by this article, I presume its because my file is getting corrupted somewhere in there. Also when I upload it to a server and we try to open it on a linux machine, it spits it back out at us with the error:

$ 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.

Which also suggests it is corrupted.

Does anybody have any ideas as to why it may be getting corrupted? Thanks!

Это было полезно?

Решение

Solved this by switching to a different Zip client. Moved from Objective-Zip to ZipArchive and that seemed to work just fine.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top