首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目标- Zip无法打开Zip

目标- Zip无法打开Zip
EN

Stack Overflow用户
提问于 2012-09-25 21:58:09
回答 2查看 1.2K关注 0票数 0

我对Objective-Zip有问题。它在验证我zip时抛出异常。我检查了文件,没有问题的解压缩/压缩。更重要的是,我尝试压缩我的文件与系统默认的存档程序和其他。

我使用ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"textPack.zip" mode:ZipFileModeUnzip];

验证方法

代码语言:javascript
复制
- (id) initWithFileName:(NSString *)fileName mode:(ZipFileMode)mode {
    if (self= [super init]) {
        _fileName= [fileName retain];
        _mode= mode;

        switch (mode) {
            case ZipFileModeUnzip:
                _unzFile= unzOpen([_fileName cStringUsingEncoding:NSUTF8StringEncoding]);
                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;
}

有什么建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-25 22:10:47

代码语言:javascript
复制
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"textPack.zip" mode:ZipFileModeUnzip];

不起作用,因为@"textPack.zip“不是有效的文件。"FileName“必须包含路径。我想他们在这里用了一个误导性的名字。

如果您的文件来自主包,请使用以下命令:

代码语言:javascript
复制
NSString *path=[[NSBundle mainBundle] pathForResource:@"textPack" ofType:@"zip"];
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:path mode:ZipFileModeUnzip];

希望这能有所帮助

票数 1
EN

Stack Overflow用户

发布于 2016-10-27 18:03:55

您在使用objective-zip可以使用的64位模式时遇到了问题。

如果在创建归档文件时只添加legacy32BitMode:YES,一切都会好起来的。

代码语言:javascript
复制
OZZipFile *zipFile= [[OZZipFile alloc] initWithFileName:zipPath 
                                                   mode:OZZipFileModeCreate 
                                        legacy32BitMode:YES];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12584530

复制
相关文章

相似问题

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