class IO::Stream::Generic

Base class for stream implementations providing common functionality.

def close

Best effort to flush any unwritten data, and then close the underling IO.
def close
	return if closed?
	
	begin
		self.flush
	rescue
		# We really can't do anything here unless we want #close to raise exceptions.
	ensure
		self.sysclose
	end
end

def closed?

@returns [Boolean] False by default, should be overridden by subclasses.
Check if the stream is closed.
def closed?
	false
end

def initialize(**options)

@parameter options [Hash] Options passed to included modules.
Initialize a new generic stream.
def initialize(**options)
	super(**options)
end

def sysclose

This method should be implemented by subclasses to handle the specific closing logic.
Closes the underlying IO stream.
def sysclose
	raise NotImplementedError
end

def sysread(size, buffer)

This method should be implemented by subclasses to handle the specific reading logic.
Reads data from the underlying stream as efficiently as possible.
def sysread(size, buffer)
	raise NotImplementedError
end

def syswrite(buffer)

@returns [Integer] The number of bytes written.
@parameter buffer [String] The data to write.
This method should be implemented by subclasses to handle the specific writing logic.
Writes data to the underlying stream.
def syswrite(buffer)
	raise NotImplementedError
end