I wrote a short category on NSData that does compression with libSnappy. It works like a charm during compression, however the decompression code results in SNAPPY_INVALID_INPUT
. The interesting part is, despite the invalid Op-Code, snappy still fills my result
's buffer with uncompressed data. Does anybody know why snappy is throwing this at me?
- (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;
}
I should note that the data that is being compressed/uncompressed is the result of an NSKeyedArchiver
call.