首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取Zip文件时,iphone中的objective-zip库出现错误

读取Zip文件时,iphone中的objective-zip库出现错误
EN

Stack Overflow用户
提问于 2011-07-07 18:18:25
回答 2查看 1K关注 0票数 0

unzOpen()函数在使用objective-zip库打开压缩文件时出现错误"Cann't open“

我尝试了以下内容:-其中路径是具有过多读/写权限的zip文件的有效路径

代码语言:javascript
复制
- (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

EN

回答 2

Stack Overflow用户

发布于 2011-07-07 18:23:55

我在我的一个应用程序中也遇到了同样的问题,经过长时间的研究和几天的研究,我发现问题出在服务器端,服务器端的zip文件没有正确归档。所以我建议你先检查zip文件是否正确。尝试首先从Mac解压本地zip文件,并确保zip文件格式已正确存档。

希望这能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2014-03-19 20:39:10

我知道这个话题已经超过3年了,但也许我的答案对其他人也有用。

我也有同样的问题。问题出在iOS 7.1上的64位体系结构上

首先,检查您是否有1.1版本的MiniZip。请勿复制包含adler32.c的Zlib目录。等文件。改用Xcode libs.1.2.5.dylib提供的lib。

代码语言:javascript
复制
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];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6609055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档