From: Guido de Melo Date: 2005-11-15T01:07:16+09:00 Subject: Re: trouble reading a gzipped xml-file Thank you very much! You solved it! Robert Klemme wrote: >>>You're not closing f here. >>[...] >>>I'm not so sure that it fails just because of this. >> >>It shouldn't, because ruby will determine the end of the file by >>itself and close the handle on exiting. > > I didn't mean to say that it fails because of the open file. My point > with the first remark was that it's a good habit to open files for only as > long as they are actually used. The block form is the idiom of choice > here: it's not much longer as a simple File.open() or File.new() and it > ensures the file is always properly closed. You are right of course, I will try to do this in the future. > But you can do this > > xmldoc = Zlib::GzipReader.open('file.dia') {|gz| REXML::Document.new( > gz.read )} And this worked perfect for me :-) > If there is no exception during GZIP reading I guess there might be a bug > somewhere. As a test I'd write the gunzipped content to another file and > do a diff on the plain xml and this output to see whether GzipReader > actually yields the same content. They do > Btw, did you actually try to make REXML read the first variant? Maybe you > have a problem in your XML file. Thank goodness the XML produced by dia is sound :-) Kind regards, Guido