How to decompress Gzip string in ruby?

Viewed 43638

Zlib::GzipReader can take "an IO, or IO-like, object." as it's input, as stated in docs.

Zlib::GzipReader.open('hoge.gz') {|gz|
  print gz.read
}

File.open('hoge.gz') do |f|
  gz = Zlib::GzipReader.new(f)
  print gz.read
  gz.close
end

How should I ungzip a string?

9 Answers

Using (-Zlib::MAX_WBITS), I got ERROR: invalid code lengths set and ERROR: invalid block type
The only following works for me, too.

Zlib::GzipReader.new(StringIO.new(response_body)).read
Related