Decompressing a gzip data stream in Objective-C

强颜欢笑 提交于 2019-12-11 03:04:49

问题


Is there a simple, standard way to decompress a gzip raw data buffer in Objective-C? I could not find anything useful in the Apple Developer documentation.

If not, can you point me to a code walk-through, a library, anything that will make my life easier? I am not afraid to write C code.


回答1:


There is a NSData category available at cocoadev that can handle zlib and gzip data: http://www.cocoadev.com/index.pl?NSDataCategory

If you just need gzip decompression, you can remove the zlib & hash related methods.
Don't forget to add a link libz.dylib (OS X standard library) build phase.

Update
As pointed out by marcos1490 in the comments, the original CocoaDev entry disappeared, but someone extended that NSData category and wrote about it: http://deusty.blogspot.de/2007/07/gzip-compressiondecompression.html




回答2:


You can try Ziparchive for decompression. I've tried compressing files using it, hope the other would work perfectly.

Here is the code snippet

ZipArchive *zip = [ZipArchive alloc];
[zip UnzipOpenFile:Zip-File-Path];
[zip UnzipFileTo:Unzip-Folder-Path overWrite:As-You-Wish];

Also include libz.dylib in build phase.



来源:https://stackoverflow.com/questions/7172734/decompressing-a-gzip-data-stream-in-objective-c

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