我对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;
}有什么建议吗?
发布于 2012-09-25 22:10:47
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];希望这能有所帮助
发布于 2016-10-27 18:03:55
您在使用objective-zip可以使用的64位模式时遇到了问题。
如果在创建归档文件时只添加legacy32BitMode:YES,一切都会好起来的。
OZZipFile *zipFile= [[OZZipFile alloc] initWithFileName:zipPath
mode:OZZipFileModeCreate
legacy32BitMode:YES];https://stackoverflow.com/questions/12584530
复制相似问题