0

Objective-Zipに問題があります。私の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"は有効なファイルではないため、機能しません。「FileName」にはパスを含める必要があります。ここでは誤解を招くような名前を使用したと思います。

ファイルがメインバンドルからのものである場合は、これを使用します。

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 に答える