Reading Zip file gives a error with objective-zip library in iphone
unzOpen() Function gives error "Cann't open" at the time of opening a zip file with objective-zip library
I tried following: - where the path is a valid path for a zip file having read/write excess
- (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;
}
it gives error Cann't open the file
where mode is ZipFileM开发者_如何学CodeUnzip
I had same problem in one of my app and after long research and spent couple of days I come to know that the problem was at server side and zip file was not properly archived at server side. So I would suggest you to first check zip file whether it is proper or not. Try unzipping local zip file first from your Mac and Make sure that zip file format is correctly archived.
Hope this help.
I know the topic has over than 3 years, but maybe my answer will be useful for others.
I had this same problem. The problem was on 64 bits architecture on iOS 7.1
First of all, check you have 1.1 version of MiniZip. Do not copy Zlib directory with adler32.c,compress.c.. etc. files. Use libs gave by Xcode libs.1.2.5.dylib instead.
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];
精彩评论