0

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

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

验证方法

- (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;
}

有什么建议吗?

4

2 回答 2

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

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

如果您的文件来自主包,请使用此选项:

NSString *path=[[NSBundle mainBundle] pathForResource:@"textPack" ofType:@"zip"];
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:path mode:ZipFileModeUnzip];

希望这可以帮助

于 2012-09-25T14:10:47.357 回答
0

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

如果您只是legacy32BitMode:YES在创建存档时添加,一切都会好起来的。

OZZipFile *zipFile= [[OZZipFile alloc] initWithFileName:zipPath 
                                                   mode:OZZipFileModeCreate 
                                        legacy32BitMode:YES];
于 2016-10-27T10:03:54.937 回答