I’m trying to inflate a gzipped byte buffer on an iOS 5.0.
I am using the NSData category found at CocoaDev.
However, every time I call gzipInflate on an NSData object, it returns “nil”.
I have tried linking to libz, building for both the simulator, and a device, and tried a clean build, but none have succeeded.
The NSData object contains valid gzipped data.
Any help would be appreciated.
EDIT1: Here’s the code I’m using.
uint8_t appendArray[1];
for (int i=0; i != 1024; i++) {
appendArray[0] = [self readByte]; // neccessary, because [self readByte] returns a uint8_t.
[tempdata appendBytes:appendArray length:1];
}
NSData *almostdata = [tempdata gzipInflate]; // Returns nil
assert(almostdata != nil); // Fails
Tempdata is an NSMutableData object, with 1024 bytes of capacity. readByte is a method to read one byte from a network stream.
The gzipInflate method comes from here.
The data from the stream is 1024 bytes long, while compressed.
EDIT2: It’s a Z_BUF_ERROR, and yet the output buffer is more than large enough for the bytes.
EDIT3: This problem was only caused because I misread the network protocol. I just had to combine ALL of the data from the stream before trying to ungzip.
EDIT: This problem was only caused because I misread the network protocol. I just had to combine ALL of the data from the stream before trying to ungzip.