AlanQuatermain / aqtoolkit

A toolkit consisting of a bunch of generally useful routines and extensions I wrote when putting together other projects.
http://blog.alanquatermain.net/code
BSD 3-Clause "New" or "Revised" License
785 stars 149 forks source link

Fixed error when reading with AQGZipStream into AQXMLParser using HTTPMessage #13

Closed audungk closed 7 years ago

audungk commented 12 years ago

I was having an error with AQGZipInputStream used together with AQXMLParser and HTTPMessage, where the stream would throw a Z_BUF_ERROR with no error message, while bytes where still available to read from the buffer. This fix commit solves the issue, but it might be other ways to fix it.

http://zlib,net has further explanation:

inflate() can also return Z_STREAM_ERROR, which should not be possible here, but could be checked for as >noted above for def(). Z_BUF_ERROR does not need to be checked for here, for the same reasons noted for >def(). Z_STREAM_END will be checked for later.

Also, in some cases when used together with GCD, I would experience issues with close being called twice on the same stream. A check if status equals NSStreamStatusClosed solves this issue

audungk commented 12 years ago

Example code used to set up stream. Project is using ARC

    @autoreleasepool {

        HTTPMessage *message = [HTTPMessage requestMessageWithMethod:@"GET" url:url version:HTTPVersion1_1];
        [message setUseGzipEncoding:YES];       
        AQGzipInputStream *inputstream = [[AQGzipInputStream alloc] initWithCompressedStream:[message inputStream]];

        AQXMLParser *parser = [[AQXMLParser alloc] initWithStream:  inputstream];       
        parser.delegate = delegate;
        [parser parse];

    }