Class: Fox::FXFileStream

Inherits:
Object
  • Object
show all
Defined in:
lib/fox16/iterators.rb

Class Method Summary collapse

Class Method Details

.open(filename, save_or_load, size = 8192, container = nil) ⇒ Object

Construct a new FXFileStream object with the specified data flow direction (save_or_load) and container object. If an optional code block is given, it will be passed this file stream as an argument, and the file stream will automatically be closed when the block terminates. If no code block is provided, this method just returns the new file stream in an opened state.

Raises FXStreamNoWriteError if save_or_load is FXStreamSave but the file cannot be opened for writing. Raises FXStreamNoReadError if save_or_load is FXStreamLoad but the file cannot be opened for reading.



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/fox16/iterators.rb', line 283

def FXFileStream.open(filename, save_or_load, size=8192, container=nil) # :yields: theFileStream
  fstream = FXFileStream.new(container)
  if fstream.open(filename, save_or_load, size)
  	if block_given?
  	  begin
  	    yield fstream
  	  ensure
  	    fstream.close
  	  end
  	else
  	  fstream
  	end
  else
    # FXFileStream#open returned false, so report error
  	raise FXStreamError.makeStreamError(fstream.status)
  end
end