开发者

Decompressing a gzip data stream in Objective-C

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 no开发者_如何学编程t, 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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜