Class: RIO::IOH::Stream
- Inherits:
-
Base
show all
- Extended by:
- Forwardable
- Defined in:
- lib/rio/ioh.rb
Constant Summary
collapse
- DEFAULT_BLKSIZE =
1024
Instance Attribute Summary collapse
Attributes inherited from Base
#ios
Instance Method Summary
collapse
Methods inherited from Base
#callstr, #open?
Constructor Details
#initialize(iosp, *args) ⇒ Stream
Returns a new instance of Stream.
61
62
63
64
65
|
# File 'lib/rio/ioh.rb', line 61
def initialize(iosp,*args)
super
@iostack = [@ios]
@hindex = -1
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
114
115
116
117
|
# File 'lib/rio/ioh.rb', line 114
def method_missing(sym,*args,&block)
handle.__send__(sym,*args,&block)
end
|
Instance Attribute Details
Returns the value of attribute hindex.
60
61
62
|
# File 'lib/rio/ioh.rb', line 60
def hindex
@hindex
end
|
Returns the value of attribute iostack.
59
60
61
|
# File 'lib/rio/ioh.rb', line 59
def iostack
@iostack
end
|
Instance Method Details
#_stat_blksize(st) ⇒ Object
129
130
131
132
133
134
|
# File 'lib/rio/ioh.rb', line 129
def _stat_blksize(st)
s = st.blksize
return nil unless s
return nil if s == 0
s
end
|
#_stream_blksize(*streams) ⇒ Object
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/rio/ioh.rb', line 119
def _stream_blksize(*streams)
sizes = []
streams.each do |s|
next unless s.kind_of?(::IO)
next unless s.respond_to?(:stat)
size = _stat_blksize(s.stat)
sizes << size if size
end
sizes.min || DEFAULT_BLKSIZE
end
|
80
|
# File 'lib/rio/ioh.rb', line 80
def close() handle.close unless self.closed? end
|
#closed? ⇒ Boolean
81
|
# File 'lib/rio/ioh.rb', line 81
def closed?() handle.nil? or handle.closed? end
|
#copy_blksize ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/rio/ioh.rb', line 71
def copy_blksize()
if @ios.respond_to? :stat
sz = @ios.stat.blksize
sz = nil if sz.nil? || sz == 0
end
sz || 512
end
|
#copy_stream(dst) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/rio/ioh.rb', line 83
def copy_stream(dst)
blksize = _stream_blksize(handle,dst)
until handle.eof?
dst.print(handle.read(blksize))
end
self
end
|
#each_bytes(nb, &block) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/rio/ioh.rb', line 94
def each_bytes(nb,&block)
until handle.eof?
break unless s = handle.read(nb)
yield s
end
self
end
|
#each_line(*args, &block) ⇒ Object
101
102
103
|
# File 'lib/rio/ioh.rb', line 101
def each_line(*args,&block)
handle.each_line(*args,&block)
end
|
#eof? ⇒ Boolean
82
|
# File 'lib/rio/ioh.rb', line 82
def eof?() closed? or handle.eof? end
|
79
|
# File 'lib/rio/ioh.rb', line 79
def handle() @iostack[@hindex] end
|
#initialize_copy(*args) ⇒ Object
66
67
68
69
70
|
# File 'lib/rio/ioh.rb', line 66
def initialize_copy(*args)
super
@iostack = @iostack.map { |io| io.nil? || io.equal?(@ios) ? io : io.clone }
end
|
#puts(*args) ⇒ Object
91
92
93
|
# File 'lib/rio/ioh.rb', line 91
def puts(*args)
handle.puts(*args)
end
|