Inflar bytes comprimidos con gzip en un iPhone

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.

Cualquier ayuda sería apreciada.

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 aquí. 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.

preguntado el 30 de enero de 12 a las 19:01

Agregué el código ahora. -

2 Respuestas

I can't see all your code - so this is a bit of a stab in the dark - but it looks like you're reading into uselessArray - but you're appending data from appendedArray...

¿Debería esto:

uselessArray[0] = [self readByte]; // neccessary, because [self readByte] returns a uint8_t.
[tempdata appendBytes:appendArray length:1];

ser esto:

uselessArray[0] = [self readByte]; // neccessary, because [self readByte] returns a uint8_t.
[tempdata appendBytes:uselessArray length:1];

?

Respondido el 31 de enero de 12 a las 02:01

It would have been great if that was the fix, but it was just a problem from copying and pasting to here. - magmastonealex

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.

Respondido 03 Feb 12, 01:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.