Snappy压缩仅返回SNAPPY_INVALID_INPUT

时间:2013-01-20 19:37:03

标签: nsdata snappy

我在NSData上写了一个用libSnappy进行压缩的简短类别。它在压缩过程中像魅力一样,但解压缩代码会产生SNAPPY_INVALID_INPUT。有趣的是,尽管Op-Code无效,但snappy仍会使用未压缩的数据填充我的result缓冲区。有谁知道为什么snappy向我扔这个?

- (NSData*)dataBySnappyUncompression {
    NSMutableData *result = nil;
    if (self.bytes != NULL) {
        size_t uncompress_result = 0;
        snappy_status opCode = snappy_uncompressed_length(self.bytes, self.length, &uncompress_result);
        if (opCode == SNAPPY_OK) {
            result = [NSMutableData dataWithLength:uncompress_result];
            opCode = snappy_uncompress(self.bytes, self.length, [result mutableBytes], &uncompress_result);
            if (opCode == SNAPPY_OK) {
                [result setLength:uncompress_result];
                return result;
            }
        }
    }
    LEPLog(@"Failed snappy de-compress: tried to de-compress %lu bytes", self.length);
    NSAssert(nil, @"Failed Snappy de-compress");
    result = nil;
    return result;
}

我应该注意,正在压缩/未压缩的数据是NSKeyedArchiver调用的结果。

0 个答案:

没有答案