gzencode php to objective c nsdata

My question is similar to here:

iPhone and GZip

only, I get no result.

I gzipped the data in PHP:

$gztext = gzcompress($text,9);
var_dump(base64_encode($gztext));

and tried to decode in iOS:

NSString *encodedGzippedString = @"K0ktLlFIzSspqlTQ09MDYTCloKcApWEEGBkaGZuYAAA=";
NSData *decodedGzippedData     = [NSData dataByBase64DecodingString:encodedGzippedString];
NSData *unGzippedJsonData = [decodedGzippedData gzipInflate];
if(unGzippedJsonData){
    NSString* unGzippedJsonString  = [[NSString alloc] initWithData:unGzippedJsonData encoding:NSASCIIStringEncoding];       
    if(unGzippedJsonString)
         NSLog(@"Result: %@", unGzippedJsonString);
    else
       NSLog(@"string error");
}
else NSLog(@"gzip error");

The result is "gzip error"

Answers


This works as expected:

NSString* base64Str = @"eJwrSS0uUShJrQARxSUAKVwFhg==";
NSData* gzData = [NSData dataFromBase64String:base64Str];
NSData* flatData = [gzData gzipInflate];
NSString* result = [NSString stringWithUTF8String:(const char*) flatData.bytes];

With NSData+Base64 and NSData+Compression categories


My situation is that I would like to decode a gzip file. By following the answer of @sigman, I can decode the gzip file. For instance, NSString * gfile = [documentDirectory stringByAppendingPathComponent:@"randomgzip.c.gz"]; NSData * gdata = [[NSData alloc] initWithContentsOfFile:gfile]; NSData * flatData = [gdata gzipInflate];


Need Your Help

CMockery Mock, Duplicate Symbol Error

c linker cmake working-set cmockery

I'm having the problem with CMockery mocks that there are coming duplicate symbol warnings.

How to retrieve all positions of a profile, including past ones

javascript api profile linkedin

I have tried several things to be able to retrieve all positions of a profile, including past ones and somehow it still does not work.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.