How to gzip NSData with zlib?

随声附和 提交于 2019-12-22 13:55:47

问题


  1. I want to use zlib because I'm assuming it's the best & fastest way to gzip NSData. But, is there a better way?

  2. 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?

  3. Please provide a code example of how to us zlib to convert NSData *normalHTTPBody into NSData gzippedHTTPBody


回答1:


  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.
  2. 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.
  3. 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


来源:https://stackoverflow.com/questions/10270203/how-to-gzip-nsdata-with-zlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!