unzOpen()函数在使用objective-zip库打开压缩文件时出现错误"Cann't open“
我尝试了以下内容:-其中路径是具有过多读/写权限的zip文件的有效路径
- (id) initWithFileName:(NSString *)fileName mode:(ZipFileMode)mode
{
if (self= [super init])
{
_fileName= [fileName retain];
_mode= mode;
switch (mode) {
case ZipFileModeUnzip:
_unzFile = unzOpen( (const char*)[_fileName UTF8String] );
if (_unzFile == NULL) {
NSString *reason= [NSString stringWithFormat:@"Can't open '%@'", _fileName];
@throw [[[ZipException alloc] initWithReason:reason] autorelease];
}
break;
case ZipFileModeCreate:
_zipFile= zipOpen([_fileName cStringUsingEncoding:NSUTF8StringEncoding], APPEND_STATUS_CREATE);
if (_zipFile == NULL) {
NSString *reason= [NSString stringWithFormat:@"Can't open '%@'", _fileName];
@throw [[[ZipException alloc] initWithReason:reason] autorelease];
}
break;
case ZipFileModeAppend:
_zipFile= zipOpen([_fileName cStringUsingEncoding:NSUTF8StringEncoding], APPEND_STATUS_ADDINZIP);
if (_zipFile == NULL) {
NSString *reason= [NSString stringWithFormat:@"Can't open '%@'", _fileName];
@throw [[[ZipException alloc] initWithReason:reason] autorelease];
}
break;
default: {
NSString *reason= [NSString stringWithFormat:@"Unknown mode %d", _mode];
@throw [[[ZipException alloc] initWithReason:reason] autorelease];
}
}
}
return self;
}出现错误Cann't open the file
其中,模式为ZipFileModeUnzip
发布于 2011-07-07 18:23:55
我在我的一个应用程序中也遇到了同样的问题,经过长时间的研究和几天的研究,我发现问题出在服务器端,服务器端的zip文件没有正确归档。所以我建议你先检查zip文件是否正确。尝试首先从Mac解压本地zip文件,并确保zip文件格式已正确存档。
希望这能有所帮助。
发布于 2014-03-19 20:39:10
我知道这个话题已经超过3年了,但也许我的答案对其他人也有用。
我也有同样的问题。问题出在iOS 7.1上的64位体系结构上
首先,检查您是否有1.1版本的MiniZip。请勿复制包含adler32.c的Zlib目录。等文件。改用Xcode libs.1.2.5.dylib提供的lib。
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:zipFilePath mode:ZipFileModeUnzip];
[unzipFile locateFileInZip:fileName];
FileInZipInfo *fileInfo = [unzipFile getCurrentFileInZipInfo];
ZipReadStream *read;
if(password){
read = [unzipFile readCurrentFileInZipWithPassword:password];
} else {
read = [unzipFile readCurrentFileInZip];
}
NSMutableData *data= [[NSMutableData alloc] initWithLength:[fileInfo length]];
[read readDataWithBuffer:data];
[read finishedReading];
[unzipFile close];https://stackoverflow.com/questions/6609055
复制相似问题