Created
January 16, 2012 18:32
-
-
Save Nyx0uf/1622210 to your computer and use it in GitHub Desktop.
Fast gzip deflate for small files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSData*)gzDeflate | |
{ | |
/// Max decompressed data size : 128Kb | |
/// Feel free to increase it to suit your needs | |
unsigned char outt[131072]; | |
z_stream strm = (z_stream){.zalloc = Z_NULL, .zfree = Z_NULL, .opaque = Z_NULL, .avail_in = [self length], .next_in = (Bytef*)[self bytes], .avail_out = 131072, .next_out = outt}; | |
if (inflateInit2(&strm, (15 + 16)) != Z_OK) | |
return nil; | |
int ret = inflate(&strm, Z_NO_FLUSH); | |
if (ret != Z_STREAM_END && ret != Z_OK) | |
{ | |
inflateEnd(&strm); | |
return nil; | |
} | |
return [NSData dataWithBytes:outt length:strm.total_out]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment