我想解压一些zlib编码数据,我使用ASIHTTPRequest包装器下载。解压缩zlib编码nsdata
这是我迄今为止..拦着的数据,现在我希望一些帮助,开始解压过程。
- (IBAction)sendHttpsRequest
{
//Set request address
NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"https://192.168.17.36:443"];
//call ASIHTTP delegates (Used to connect to database)
NSURL *url = [NSURL URLWithString:databaseURL];
//This sets up all other request
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request setValidatesSecureCertificate:NO];
[request setPostValue:@"ClientDataSet.xml" forKey:@"filename"];
[request startSynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
responseData = [request responseData]; //Pass requested data from server over to NSData variable..
//Is this where I have to think about decompression? or do I pass this data out to another method?
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
self.hudCheck = NO;
[NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(stopAnimating) userInfo:nil repeats:NO];
NSError *error = [request error];
NSLog(@"%@", error);
}
所以相当多,我到减压阶段但是我不知道哪个函数/方法等,我需要使用解压缩这些数据。我只用过gzip尝试过,因为ASI包装器本身就处理所有事情。
但是由于我的控制现在我得到的数据是zlib的编码的外部环境。所以任何功能,方法或例子,你能告诉我,这将有助于我的事业将不胜感激。
编辑:
从我加入 @Caleb响应前进“zlib.h”我的文件,现在有机会获得这个构架的方法。其中之一是inflate()方法..但是我不确定需要输入什么参数?有任何想法吗?。
是的,我看到了,但我认为我正在看一个C++的例子,不知道如何得到这个与我正在做的工作。只需要添加#include“zlib.h”,然后我可以在我的NSData对象上调用inFlate? –
很酷,我只是想弄清楚什么样的参数应该被用于膨胀(__,__) –
这个例子是在普通的老C中。它有很多注释,所以通读它几次,并确保你明白它首先。示例中的'inf()'函数读写文件;你可能会想调整它来读取你的NSData并写入你提供的NSMutableData。用调用NS [Mutable] Data来替换'fread()'和'fwrite()'并不难,但是你可能想要使用NSInputStream和NSOutputStream来使事情变得更容易。从概念上讲,NS [输入|输出]流的工作方式与FILE *很相似 - 只是按顺序读取或写入的缓冲区。 – Caleb