From: Lyle Johnson Date: 2003-05-05T23:58:08+09:00 Subject: Re: Problem using FXFileStream Thomas Stammeier wrote: > I'm having problems using FXFileStream in FXRuby. I want so save an > FXImage using the "save" method. Here's the piece of code: > > FXFileStream.open ("test.jpg", FXStreamSave) do |stream | > img.savePixels(stream) > end > > This actually works, but the file is not closed until I quit the > application. After "end" the file is still open and no data has been > written to it. When I quit the application the file is a valid .jpg > file. Is this a bug or is there anything wrong with my code? I don't see anything wrong with your code, but I also don't understand how you could be seeing the behavior you describe. For reference, here's the code that implements the FXFileStream.open singleton method (from lib/fox/iterators.rb): def FXFileStream.open(filename, save_or_load, container=nil) fstream = FXFileStream.new(container) status = fstream.open(filename, save_or_load) if block_given? begin yield fstream ensure fstream.close end else fstream end end When you use FXFileStream.open as shown, there's an 'ensure' block that closes the file stream (and this calls the standard C library's fclose() function under the hood). The only possible problem I see (and one I should account for) is that FXFileStream#open (the instance method) returns some kind of error code. But if that were to happen, I don't think that call to FXImage#savePixels would have any effect, i.e. you wouldn't end up with a valid JPEG file at the end. Lyle