Zlib decompression throws header error

need help on decompressing chunk data from a stream api. I am connecting
to Gnip stream api which returns json output using gzip compression.
When I try to decompress the output data, it throws me the following
error “Zlib::DataError: incorrect header check”.

It might be very close to this issue -

Here I attached my code snippets for your reference:

require ‘rubygems’
require ‘curl’
require ‘stringio’
require ‘zlib’
url =
crl = Curl::Easy.new(url)
“Accept-Encoding” => “deflate, gzip”}
zstream = Zlib::Inflate.new
crl.on_body { |data| zstream.inflate(data);}

So when I print the data, I can see some compressed output with unknown
characters. But when I tried to uncompress the chunked data, it always
returns “Zlib::DataError: incorrect header check”.

I know the gnip returns the data chunk by chunk so the required gzip’ed
output will not be in the first chunk. So how can I collect all required
chunk of gzip’ed outputs and decompress them to get required single json

Thanks in Advance.