Class: Omnizip::IO::StreamManager
- Inherits:
-
Object
- Object
- Omnizip::IO::StreamManager
- Defined in:
- lib/omnizip/io/stream_manager.rb
Overview
Manages I/O operations and wraps various source types.
This class provides a unified interface for different I/O sources including files, IO objects, and strings.
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#buffered_input(buffer_size: BufferedInput::DEFAULT_BUFFER_SIZE) ⇒ BufferedInput
Create a buffered input from the source.
-
#buffered_output(buffer_size: BufferedOutput::DEFAULT_BUFFER_SIZE) ⇒ BufferedOutput
Create a buffered output to the source.
-
#close ⇒ void
Close the underlying source if owned.
-
#eof? ⇒ Boolean
Check if source is at end.
-
#initialize(source, mode: "rb") ⇒ StreamManager
constructor
Initialize stream manager.
-
#read_all ⇒ String
Read all data from source.
-
#write(data) ⇒ Integer
Write data to source.
Constructor Details
#initialize(source, mode: "rb") ⇒ StreamManager
Initialize stream manager.
34 35 36 37 |
# File 'lib/omnizip/io/stream_manager.rb', line 34 def initialize(source, mode: "rb") @source = normalize_source(source, mode) @owned = source.is_a?(String) && File.exist?(source) end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
28 29 30 |
# File 'lib/omnizip/io/stream_manager.rb', line 28 def source @source end |
Instance Method Details
#buffered_input(buffer_size: BufferedInput::DEFAULT_BUFFER_SIZE) ⇒ BufferedInput
Create a buffered input from the source.
43 44 45 |
# File 'lib/omnizip/io/stream_manager.rb', line 43 def buffered_input(buffer_size: BufferedInput::DEFAULT_BUFFER_SIZE) BufferedInput.new(@source, buffer_size: buffer_size) end |
#buffered_output(buffer_size: BufferedOutput::DEFAULT_BUFFER_SIZE) ⇒ BufferedOutput
Create a buffered output to the source.
51 52 53 |
# File 'lib/omnizip/io/stream_manager.rb', line 51 def buffered_output(buffer_size: BufferedOutput::DEFAULT_BUFFER_SIZE) BufferedOutput.new(@source, buffer_size: buffer_size) end |
#close ⇒ void
This method returns an undefined value.
Close the underlying source if owned.
73 74 75 |
# File 'lib/omnizip/io/stream_manager.rb', line 73 def close @source.close if @owned && @source.respond_to?(:close) end |
#eof? ⇒ Boolean
Check if source is at end.
80 81 82 |
# File 'lib/omnizip/io/stream_manager.rb', line 80 def eof? @source.eof? if @source.respond_to?(:eof?) end |
#read_all ⇒ String
Read all data from source.
58 59 60 |
# File 'lib/omnizip/io/stream_manager.rb', line 58 def read_all @source.read end |
#write(data) ⇒ Integer
Write data to source.
66 67 68 |
# File 'lib/omnizip/io/stream_manager.rb', line 66 def write(data) @source.write(data) end |