是否有可在iPhone上使用的压缩API?我们正在为我们的iPhone应用程序构建一些RESTful Web服务,但我们希望至少压缩一些对话以提高效率.
我不关心格式(ZIP,LHA,等等)是什么,并且它不需要是安全的.
一些受访者指出服务器可以压缩其输出,而iPhone可以消耗它.我们的情景正好相反.我们将压缩内容发布到 Web服务.我们并不关心压缩的另一种方式.
在搜索如何在iOS上膨胀gzip压缩数据时,会在结果数量中显示以下方法:
- (NSData *)gzipInflate
{
if ([self length] == 0) return self;
unsigned full_length = [self length];
unsigned half_length = [self length] / 2;
NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];
BOOL done = NO;
int status;
z_stream strm;
strm.next_in = (Bytef *)[self bytes];
strm.avail_in = [self length];
strm.total_out = 0;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
if (inflateInit2(&strm, (15+32)) != Z_OK) return nil;
while (!done)
{
// Make sure we have enough room and reset the lengths.
if …Run Code Online (Sandbox Code Playgroud)