From: Jeremy Bopp Date: 2011-02-04T07:38:04+09:00 Subject: Re: Zlib::GzipReader and multiple compressed blobs in a single stream On 2/3/2011 3:57 PM, Jos Backus wrote: > On Thu, Feb 03, 2011 at 02:03:49PM +0900, Jeremy Bopp wrote: >> Once your fix is in place and GZipReader#unused works correctly, is >> there any convenient way to take the returned string and continue >> processing it along with the remaining file contents with an instance of >> GzipReader? > > Fwiw, with the changes just committed to trunk the following code works for me > on a file with multiple gzipped blobs: > > require 'stringio' > require 'zlib' > > def inflate(filename) > File.open(filename) do |file| > zio = StringIO.new(file.read) > loop do > io = Zlib::GzipReader.new zio > puts io.read > unused = io.unused > io.finish > break if unused.nil? > zio.pos -= unused.length > end > end > end > > inflate "gz" That's great! How does the performance compare to zcat with your data? BTW, this implementation does require that you have enough memory to hold all of the gzipped file data at once. That will be a problem with sufficiently large files or constrained resources. -Jeremy