我使用 iOS,我想使用 zlib 将 .zip 文件解压缩到内存,但它总是返回错误代码-3
。
我的代码如下:
NSData *sData = [[NSFileManager defaultManager] contentsAtPath:[[NSBundle mainBundle] pathForResource:@"mactxt" ofType:@"zip"]];
NSData *srcData = [[NSFileManager defaultManager] contentsAtPath:[[NSBundle mainBundle] pathForResource:@"mactxt" ofType:@"rtf"]];
unsigned int l = srcData.length;
unsigned long srcLen = sData.length;
unsigned long dstLen = l;
void * dest =malloc(dstLen);
memset(dest, 0x00, dstLen);
const void * src =[sData bytes];
int a = uncompress(dest, &dstLen, src, srcLen);
if (a==0) {
NSData *data = [[NSData alloc] initWithBytes:dest length:dstLen];
[data writeToFile:[self dataFilePath:@"matxt.rtf"] atomically:YES];
}
我该如何解决?