I want to use zlib because I'm assuming it's the best & fastest way to gzip
NSData
. But, is there a better way?If not, which version of the zlib library should I link to in Xcode: libz.dylib, libz.1.dylib, libz.1.1.3.dylib, or libz.1.2.5.dylib?
Please provide a code example of how to us zlib to convert
NSData *normalHTTPBody
intoNSData gzippedHTTPBody
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
- Yes, zlib is what is used to gzip data. I know of no better way. As for speed, you can select the compression level to optimize speed vs. compression for your application.
- You will likely find that libz.dylib and libz.1.dylib are symbolic links to libz.1.2.5.dylib. You should be using libz.1.2.5.dylib as opposed to 1.1.3 due to many bug fixes and performance enhancements between the two.
- This link from your answer is a very well commented example. You can also look at this heavily commented example of zlib use (in C).
回答2:
3. Here are some solutions I found on the web:
- http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMNSData%2Bzlib.m
- http://www.cocoadev.com/index.pl?NSDataCategory
- http://code.google.com/p/polkit/source/browse/trunk/Extensions/NSData%2BGZip.m?r=135
- https://github.com/st3fan/cocoa-utils/blob/master/src/NSDataGZipAdditions.m
- http://www.clintharris.net/2009/how-to-gzip-data-in-memory-using-objective-c/
- http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html