class Generic
Base class for stream implementations providing common functionality.
Definitions
def initialize(**options)
Initialize a new generic stream.
Signature
-
parameter
options
Hash
Options passed to included modules.
Implementation
def initialize(**options)
super(**options)
end
def closed?
Check if the stream is closed.
Signature
-
returns
Boolean
False by default, should be overridden by subclasses.
Implementation
def closed?
false
end
def close
Best effort to flush any unwritten data, and then close the underling IO.
Implementation
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 sysclose
Closes the underlying IO stream. This method should be implemented by subclasses to handle the specific closing logic.
Implementation
def sysclose
raise NotImplementedError
end
def syswrite(buffer)
Writes data to the underlying stream. This method should be implemented by subclasses to handle the specific writing logic.
Signature
-
parameter
buffer
String
The data to write.
-
returns
Integer
The number of bytes written.
Implementation
def syswrite(buffer)
raise NotImplementedError
end
def sysread(size, buffer)
Reads data from the underlying stream as efficiently as possible. This method should be implemented by subclasses to handle the specific reading logic.
Implementation
def sysread(size, buffer)
raise NotImplementedError
end