Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: Zlib::GzipReader doesn't work as expected Date: Wed, 25 Apr 2012 21:03:44 +0200 Lines: 60 Message-ID: <9vr04hFh0cU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net U+8DoTwdBzLrfN8wOdVObAuUZukQ7B2oNyxweki4huKa9UE08= Cancel-Lock: sha1:6xxQ0Deyt9arCCt//zZZmEhgJ0w= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 In-Reply-To: Xref: csiph.com comp.lang.ruby:6518 On 04/25/2012 10:57 AM, Thomas Wolf wrote: > Hi, > given 2 files: > cat 5lines.txt > 5 lines > 5 lines > 5 lines > 5 lines > 5 lines > > cat more5lines.txt > More 5 lines > More 5 lines > More 5 lines > More 5 lines > More 5 lines > > These files are "gzip"ed as follows: > gzip < 5lines.txt > foo.gz > gzip < more5lines.txt >> foo.gz > > zcat foo.gz: > 5 lines > 5 lines > 5 lines > 5 lines > 5 lines > More 5 lines > More 5 lines > More 5 lines > More 5 lines > More 5 lines > > This ruby code only reads the first 5 lines: > #!/usr/bin/ruby > require "zlib" > filename = ARGV[0] > > Zlib::GzipReader.open(filename) {|gz| > print gz.read > } > > ./test.rb foo.gz > 5 lines > 5 lines > 5 lines > 5 lines > 5 lines > > How do I force Zlib::GzipReader do read the whole file? That's a fairly common limitation of GZip libs (Java's standard lib also has this limitation, or at least hat last time I checked). You might get away with wrapping the GzipReader around an open IO object and wrapping another GzipReader when the first finishes. Kind regards robert