From: celldee Date: 2008-03-11T19:03:20+09:00 Subject: Re: Getting files out of a .tar.gz archive Thanks Mac, works like a charm. Thanks for your efforts everybody else. On Mar 11, 12:44 am, Paul Mckibbin wrote: > Daniel Brumbaugh Keeney wrote: > > On Mon, Mar 10, 2008 at 7:01 PM, Daniel Brumbaugh Keeney > > wrote: > >>  tgz = Zlib::GzipReader.new(File.open('test.tgz', 'rb')) > >>  # Warning: tgz and the file will be closed. > > > I seem to have failed to remove the former comment. It looks like > > Minitar::Reader at no point closes tgz or the file, and therefore tgz > > needs to be closed manually afterward, as I my code correctly > > demonstrated, though the comment did not. > > > Daniel Brumbaugh Keeney > > You can use Zlib::GzipReader.open with a block. (Since I set Chris the > original problem, and this isn't the hard part, I'll show the code that > is used in the app, with a couple of minor mods to make it look like > Chris's example.) > > Zlib::GzipReader.open(@tarfile) { |tgz| >   Archive::Tar::Minitar::Reader.open(tgz).each do |entry| > > # Chris's code > #    fpl = StringIO.new( entry.read) if entry.name =~ > /#{@date}#{channel}_pl/ > #    fpi = StringIO.new( entry.read) if entry.name =~ > /#{@date}#{channel}_pi/ > > # Or test the verification by using the XML document directly > #   fpl=REXML::Document.new(StringIO.new(entry.read)) if entry.name > =~/#{date}#{channel}_pl/ > #   fpi=REXML::Document.new(StringIO.new(entry.read)) if entry.name > =~/#{date}#{channel}_pi/ > >   end > > } > > Mac > -- > Posted viahttp://www.ruby-forum.com/.