mkral
mkral

Reputation: 4085

Base64 string to NSData then gunzip

I have a base64 encoded NSString of the binary, which I convert to an NSData object, using @mattt's Godzippa class I am trying to gunzip the nsdata but I get an error:

Error Domain=com.godzippa.zlib.error Code=-3 "Error inflating payload" UserInfo=0x881b0b0 {NSLocalizedDescription=Error inflating payload}

When I investigated further the zStream.msg is msg = 0x000164de "incorrect header check"

But I am having troubles understanding what the incorrect header check means and how I can fix this issue. I appoligize in advance for the lack of detail, if someone can walk me through understanding the issues here I will promptly answer any questions.

Here is how I'm doing it, i removed the base64 string however:

NSString *dataString = @"REMOVED BASE64 STRING HERE";

NSData *data = [NSData dataFromBase64String:dataString];

NSError *error = nil;

NSData *decompressed = [data dataByGZipDecompressingDataWithError:&error];

if(error){
    NSLog(@"Error: %@", error);
}

Upvotes: 0

Views: 859

Answers (2)

idz
idz

Reputation: 12988

I have some code that does exactly what you looking for (gunzip not unzip). You can find the source on GitHub here and a line by line description on my blog here.

Upvotes: 1

mkral
mkral

Reputation: 4085

It turns out that I was trying to decompress a zlib archive when I needed to decompress a gzip file. Specifically I had to change the inflateInit() to the inflatateInit2() method in the libz/gzip library.

Upvotes: 0

Related Questions