Module: VirtFS::ThinIODelegatorMethodsBufferio
- Included in:
- ThinIODelegatorMethods
- Defined in:
- lib/virtfs/thin_io_delegator_methods_bufferio.rb
Overview
Dispatches BufferIO calls to/from VirtFS and the ‘Thin’ subsystem
Constant Summary collapse
- MIN_READ_BUF_SZ =
1024 * 32
- MAX_CHAR_LEN =
8
Instance Attribute Summary collapse
-
#end_byte_addr ⇒ Object
readonly
Returns the value of attribute end_byte_addr.
-
#fs_io_obj ⇒ Object
readonly
Returns the value of attribute fs_io_obj.
-
#min_read_buf_sz ⇒ Object
readonly
Returns the value of attribute min_read_buf_sz.
-
#read_buffer ⇒ Object
readonly
Returns the value of attribute read_buffer.
Instance Method Summary collapse
- #<<(obj) ⇒ Object
-
#bytes ⇒ Object
deprecated.
-
#chars ⇒ Object
deprecated.
- #each(*args, &block) ⇒ Object (also: #each_line)
- #each_byte ⇒ Object
- #each_char ⇒ Object
- #each_codepoint ⇒ Object (also: #codepoints)
- #each_common(sep, lim, block) ⇒ Object
- #getbyte ⇒ Object
- #getc ⇒ Object
- #gets(*args) ⇒ Object
- #lineno ⇒ Object
- #lineno=(ln) ⇒ Object
-
#lines(*args) ⇒ Object
deprecated.
- #print(*args) ⇒ Object
- #printf(format_str, *args) ⇒ Object
- #putc(obj) ⇒ Object
- #puts(*args) ⇒ Object
- #read(len = nil, buffer = nil) ⇒ Object
- #readbyte ⇒ Object
- #readchar ⇒ Object
- #readline(*args) ⇒ Object
- #readlines(*args) ⇒ Object
- #sync ⇒ Object
- #sync=(bool) ⇒ Object
- #ungetbyte(val) ⇒ Object
- #ungetc(string) ⇒ Object
- #write(buf) ⇒ Object
Instance Attribute Details
#end_byte_addr ⇒ Object (readonly)
Returns the value of attribute end_byte_addr.
5 6 7 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 5 def end_byte_addr @end_byte_addr end |
#fs_io_obj ⇒ Object (readonly)
Returns the value of attribute fs_io_obj.
5 6 7 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 5 def fs_io_obj @fs_io_obj end |
#min_read_buf_sz ⇒ Object
Returns the value of attribute min_read_buf_sz.
5 6 7 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 5 def min_read_buf_sz @min_read_buf_sz end |
#read_buffer ⇒ Object (readonly)
Returns the value of attribute read_buffer.
5 6 7 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 5 def read_buffer @read_buffer end |
Instance Method Details
#<<(obj) ⇒ Object
16 17 18 19 20 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 16 def <<(obj) file_open && for_writing write(obj.to_s) self end |
#bytes ⇒ Object
deprecated
22 23 24 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 22 def bytes # deprecated to_enum(:enumerate_til_eof, :getbyte, nil, nil) end |
#chars ⇒ Object
deprecated
26 27 28 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 26 def chars # deprecated to_enum(:enumerate_til_eof, :getc, nil, nil) end |
#each(*args, &block) ⇒ Object Also known as: each_line
30 31 32 33 34 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 30 def each(*args, &block) sep, lim = separator_limit_args(args) # block = block_given? ? Proc.new : nil each_common(sep, lim, block) end |
#each_byte ⇒ Object
44 45 46 47 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 44 def each_byte block = block_given? ? Proc.new : nil enumerate_return(:getbyte, self, block) end |
#each_char ⇒ Object
49 50 51 52 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 49 def each_char block = block_given? ? Proc.new : nil enumerate_return(:getc, self, block) end |
#each_codepoint ⇒ Object Also known as: codepoints
54 55 56 57 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 54 def each_codepoint block = block_given? ? Proc.new : nil enumerate_return(:codepoint, self, block) end |
#each_common(sep, lim, block) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 37 def each_common(sep, lim, block) return enumerate_return(:read, self, block) if sep.nil? return enumerate_return(:read_paragraph, self, lim, block) if sep.empty? return enumerate_return(:read_line_with_limit, self, sep, lim, block) if lim > 0 enumerate_return(:read_line, self, sep, block) end |
#getbyte ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 69 def getbyte file_open && for_reading return nil if eof? rv = @io_buffer.get_byte(@seek_pos) @seek_pos += 1 rv end |
#getc ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 77 def getc file_open && for_reading return nil if eof? rv = @io_buffer.get_char(@seek_pos) @seek_pos += rv.bytesize rv.encode!(internal_encoding) if internal_encoding rv end |
#gets(*args) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 86 def gets(*args) file_open && for_reading return nil if eof? sep, lim = separator_limit_args(args) return read if sep.nil? return read_paragraph(lim) if sep.empty? return read_line_with_limit(sep, lim) if lim > 0 read_line(sep) end |
#lineno ⇒ Object
96 97 98 99 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 96 def lineno file_open && for_reading @lineno end |
#lineno=(ln) ⇒ Object
101 102 103 104 105 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 101 def lineno=(ln) file_open && for_reading raise TypeError, "no implicit conversion from #{ln.class.name} to integer" unless ln.respond_to?(:to_int) @lineno = ln end |
#lines(*args) ⇒ Object
deprecated
107 108 109 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 107 def lines(*args) # deprecated to_enum(:enumerate_til_eof, :gets, self, *args, nil) end |
#print(*args) ⇒ Object
111 112 113 114 115 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 111 def print(*args) file_open && for_writing write(objects_to_str(args, true, $_, $\, $,)) nil end |
#printf(format_str, *args) ⇒ Object
117 118 119 120 121 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 117 def printf(format_str, *args) file_open && for_writing write(format(format_str, *args)) nil end |
#putc(obj) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 123 def putc(obj) file_open && for_writing c = obj.is_a?(Integer) ? obj.chr : obj.to_s[0] write(c) obj end |
#puts(*args) ⇒ Object
130 131 132 133 134 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 130 def puts(*args) file_open && for_writing write(objects_to_str(args, false, $/, $/, $/)) nil end |
#read(len = nil, buffer = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 136 def read(len = nil, buffer = nil) file_open && for_reading if len.nil? return "" if eof? len = @size encode = true else return nil if eof? encode = false end rv = @io_buffer.get_str(@seek_pos, len) @seek_pos += rv.bytesize if encode rv.force_encoding(external_encoding) if external_encoding rv.encode!(internal_encoding) if internal_encoding end buffer.replace(rv) unless buffer.nil? rv end |
#readbyte ⇒ Object
158 159 160 161 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 158 def readbyte file_open && for_reading && not_at_eof getbyte end |
#readchar ⇒ Object
163 164 165 166 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 163 def readchar file_open && for_reading && not_at_eof getc end |
#readline(*args) ⇒ Object
168 169 170 171 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 168 def readline(*args) file_open && for_reading && not_at_eof gets(*args) end |
#readlines(*args) ⇒ Object
173 174 175 176 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 173 def readlines(*args) file_open && for_reading each(*args).to_a end |
#sync ⇒ Object
178 179 180 181 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 178 def sync file_open @io_buffer.sync end |
#sync=(bool) ⇒ Object
183 184 185 186 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 183 def sync=(bool) file_open @io_buffer.sync = bool end |
#ungetbyte(val) ⇒ Object
188 189 190 191 192 193 194 195 196 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 188 def ungetbyte(val) file_open && for_reading str = val.respond_to?(:to_int) ? val.to_int.chr : val.to_str @io_buffer.cover_range(@seek_pos, 1) @io_buffer.truncate_left(@seek_pos) len = @io_buffer.prepend_bytes(str) @seek_pos -= len nil end |
#ungetc(string) ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 198 def ungetc(string) file_open && for_reading @io_buffer.cover_range(@seek_pos, 1) @io_buffer.truncate_left(@seek_pos) len = @io_buffer.prepend_str(string) @seek_pos -= len nil end |
#write(buf) ⇒ Object
207 208 209 210 211 212 213 214 215 |
# File 'lib/virtfs/thin_io_delegator_methods_bufferio.rb', line 207 def write(buf) file_open && for_writing buf = buf.dup buf.encode!(external_encoding) if external_encoding buf.force_encoding(@binary_encoding) rv = @io_buffer.write_to_buffer(@seek_pos, buf) update_write_pos(rv) rv end |