BW4
BW4

Reputation: 111

Objective-Zip cannot open Zip

I have problem with Objective-Zip. It throw exeption when validate my zip. I checked file it's fine, no problems with unzip/zip. What's more I try zip my files with system default archiver and other.

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

Validate method

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

Any advice?

Upvotes: 0

Views: 1214

Answers (2)

olidem
olidem

Reputation: 2121

You are having trouble with the 64 bit mode that objective-zip can use.

If you just add legacy32BitMode:YES when creating the archive, everything will be fine.

OZZipFile *zipFile= [[OZZipFile alloc] initWithFileName:zipPath 
                                                   mode:OZZipFileModeCreate 
                                        legacy32BitMode:YES];

Upvotes: 0

FD_
FD_

Reputation: 12919

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

Won't work because @"textPack.zip" is no valid file. The "FileName" has to include the path. I think they used a misleading name here.

Use this if your file is from the main bundle:

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

Hope this helps

Upvotes: 1

Related Questions