Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had this issue and sorted it out. The code is slightly buggy as it breaks if Z_BUF_ERROR is returned, yet on reading the <a href="http://zlib.net/zlib_how.html" rel="nofollow noreferrer">zlib Documentation</a> it turns out that Z_BUF_ERROR should not be checked on inflation, as it can be thrown even if the resulting output is fine.</p> <p>Changing the code thus worked:</p> <pre><code>// Inflate another chunk. status = inflate (&amp;strm, Z_SYNC_FLUSH); if ( (status == Z_STREAM_END) || (status == Z_BUF_ERROR) ) done = YES; </code></pre> <p>Hope this works for you.</p> <p>EDIT: (18th June 2011)<br> Here is the full inflation method, as requested. It is implemented as a category on NSData:</p> <pre><code>@interface NSData (NSDataExtension) - (NSData *) zlibInflate; @end @implementation NSData (NSDataExtension) - (NSData *)zlibInflate { if ([self length] == 0) return self; unsigned full_length = [self length]; unsigned half_length = [self length] / 2; NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length]; BOOL done = NO; int status; z_stream strm; strm.next_in = (Bytef *)[self bytes]; strm.avail_in = [self length]; strm.total_out = 0; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; if (inflateInit (&amp;strm) != Z_OK) return nil; while (!done) { // Make sure we have enough room and reset the lengths. if (strm.total_out &gt;= [decompressed length]) [decompressed increaseLengthBy: half_length]; strm.next_out = [decompressed mutableBytes] + strm.total_out; strm.avail_out = [decompressed length] - strm.total_out; // Inflate another chunk. status = inflate (&amp;strm, Z_SYNC_FLUSH); if ( (status == Z_STREAM_END) || (status == Z_BUF_ERROR) ) done = YES; else if (status != Z_OK) break; } if (inflateEnd (&amp;strm) != Z_OK) return nil; // Set real length. if (done) { [decompressed setLength: strm.total_out]; return [NSData dataWithData: decompressed]; } else return nil; } @end </code></pre> <p>Carlos</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload