I'm sending a large amount of text to my webpage by POST that's received by PHP. It's approximately 500kb - 1.5 mb. The problem with this, is that it's very repetitive data and I'd like to compress it. The data looks like this, "123,123,123,124,124,124,125,126... etc"
I found the NSData+Compression Library by Geoggrey Garside http://cocoadev.com/wiki/NSDataCategory that contains the methods gzipInflate and gzipDeflate and have gotten the gzipInflate method to correctly uncompress data from the server, but cannot for the life of me figure out how to compress a string in iOS and send it to the server to be decompressed via PHP.
Here's my iOS Code:
NSData* uncompressedStringData = [@"test" dataUsingEncoding:NSUTF8StringEncoding];
NSData* compressedData = [uncompressedStringData gzipDeflate];
ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"myserver"]];
[request setPostValue:@compressedData forKey:@"1"];
...more code to deal with sending the request.. etc...
Here's my PHP Code:
echo gzinflate($_POST['1']);
All I get back from the server is
Warning: gzinflate() data error
Any help would be much appreciated!
Try gzdecode rather than gzinflate
[EDIT]
It looks like gzdecode is only available from php5.4(That's the version I have with gzdecode)
From the comments I got the below, I tested it on php5.3 and it worked
<?php
function gzdecode($data)
{
return gzinflate(substr($data,10,-8));
}
?>