我正在使用Objective Zip库来解压iPhone中的文件。目标 - 邮编仅适用于文本文件?
所有工作正常,除了文本文件没有问题没有问题没有压缩,文件是正确的。但与压缩PNG文件都损坏。文件的大小都与原始文件相同,但全部损坏。
这是代码:
-(void)installPackageFromZipFile:(NSString *)zipFile
{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:zipFile mode:ZipFileModeUnzip];
packageRegisterController *pckReg = [[packageRegisterController alloc] init];
[unzipFile goToFirstFileInZip];
NSArray *infos= [unzipFile listFileInZipInfos];
for (FileInZipInfo *info in infos)
{
NSLog([NSString stringWithFormat:@"File Found in Zip File- %@ Size:%d", info.name, info.length]);
ZipReadStream *read = [unzipFile readCurrentFileInZip];
if (![pckReg detectIfFileExists:[documentsDir stringByAppendingPathComponent:info.name]])
{
NSMutableData *data = [[NSMutableData alloc] initWithLength:info.length];
int bytesRead = [read readDataWithBuffer:data];
[data writeToFile:[documentsDir stringByAppendingPathComponent:info.name] atomically:NO];
[read finishedReading];
[data release];
if ([[NSString stringWithFormat:@"%@",info.name] isEqualToString:@"TEMAMANIFEST.xml"])
{
if([self parseManifest:[documentsDir stringByAppendingPathComponent:info.name]])
if ([pckReg validateManifestId:self.temaToInstall.idManifest])
[self installManifest];
}
}
[unzipFile goToNextFileInZip];
}
[unzipFile close];
[unzipFile release];
}
此功能解压缩具有良好的尺寸和文本文件中的所有文件都OK,但不是PNG文件。
有人可以帮助我吗?
您是否尝试解压缩另一个盒子上的zip文件,并确保其压缩正确? –
剔除我在这个问题中的答案: - http://stackoverflow.com/questions/2161327/creating-zip-files-in-objectivec-for-iphone – nlg