2012-09-25 2 views
0

Objective-Zip에 문제가 있습니다. 내 우편 번호를 확인할 때 예외가 발생합니다. 파일을 확인했는데 압축을 풀 때 아무런 문제가 없었습니다. 더 많은 것은 인 무엇 나는 시스템 디폴트 archiver와 다른을 가진 나의 파일을 지퍼로 잠근 시도한다.Objective-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; 
} 

어떤 조언을 사용할 수 있습니까?

+0

왜 unzopen에 대한 NSASCIIStringEncoding하지만 다른 곳에 UTF8을 사용합니까? (이것은 귀하의 문제와 관련이 없으며 단지 일반적인 의견입니다). –

+0

오오 .. 단지 오타 일 뿐이며 테스트 용으로 만 사용되지만 도움이되지 않습니다. – BW4

+0

Google에서 unzOpen을 검색하면 같은 문제가있는 다른 게시물을 찾을 수 있습니다. 하나의 텍스트 파일을 압축해서 시도해보십시오. 그렇지 않다면 아카이브에서 zip 파일 (여러 파일도 포함)을 추출하는 데 사용하기 쉬운 (이전 버전의) 프레임 워크가 있습니다. ZipArchive –

답변

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]; 

희망이 목적 지퍼가 사용할 수있는 64 비트 모드와

+0

파일이 리소스로 추가 되더라도? – BW4

+0

내 답변에 대한 팁을 추가했습니다. –

+0

고마워, 필자는 항상 @ "텍스트"가 작동한다고 생각했지만, 할 수있는 것처럼 ...하지는 않을 것이다. – BW4

0

당신이 겪고있는 문제가 있습니다 : 파일이 기본 번들입니다이 경우

사용.

아카이브를 만들 때 legacy32BitMode:YES을 추가하면 모든 것이 잘됩니다.

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