Class: BRS::Stream::Reader
- Includes:
- ReaderHelpers
- Defined in:
- lib/brs/stream/reader.rb
Constant Summary
Constants included from Delegates
Instance Attribute Summary collapse
-
#lineno ⇒ Object
Returns the value of attribute lineno.
Attributes inherited from Abstract
#external_encoding, #internal_encoding, #io, #pos, #stat, #transcode_options
Instance Method Summary collapse
- #close ⇒ Object
-
#eof? ⇒ Boolean
– common –.
-
#initialize(source_io, options = {}, *args) ⇒ Reader
constructor
A new instance of Reader.
-
#read(bytes_to_read = nil, out_buffer = nil) ⇒ Object
– synchronous –.
-
#read_nonblock(bytes_to_read, out_buffer = nil, *options) ⇒ Object
– asynchronous –.
- #readpartial(bytes_to_read = nil, out_buffer = nil) ⇒ Object
- #rewind ⇒ Object
Methods included from ReaderHelpers
#each_byte, #each_char, #each_line, #getbyte, #getc, #gets, included, #readbyte, #readchar, #readline, #readlines, #ungetbyte, #ungetc, #ungetline
Methods inherited from Abstract
#advise, #closed?, #set_encoding, #to_io
Methods included from Delegates
Constructor Details
#initialize(source_io, options = {}, *args) ⇒ Reader
Returns a new instance of Reader.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/brs/stream/reader.rb', line 16 def initialize(source_io, = {}, *args) = super source_io, *args initialize_source_buffer_length reset_io_remainder @lineno = 0 end |
Instance Attribute Details
#lineno ⇒ Object
Returns the value of attribute lineno.
14 15 16 |
# File 'lib/brs/stream/reader.rb', line 14 def lineno @lineno end |
Instance Method Details
#close ⇒ Object
100 101 102 103 104 |
# File 'lib/brs/stream/reader.rb', line 100 def close raw_wrapper :close super end |
#eof? ⇒ Boolean
– common –
123 124 125 |
# File 'lib/brs/stream/reader.rb', line 123 def eof? @io.eof? && @buffer.bytesize == 0 end |
#read(bytes_to_read = nil, out_buffer = nil) ⇒ Object
– synchronous –
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/brs/stream/reader.rb', line 47 def read(bytes_to_read = nil, out_buffer = nil) Validation.validate_not_negative_integer bytes_to_read unless bytes_to_read.nil? Validation.validate_string out_buffer unless out_buffer.nil? return ::String.new :encoding => ::Encoding::BINARY if bytes_to_read == 0 unless bytes_to_read.nil? return nil if eof? read_more_from_buffer until @buffer.bytesize >= bytes_to_read || @io.eof? return read_bytes_from_buffer bytes_to_read, out_buffer end read_more_from_buffer until @io.eof? result = @buffer reset_buffer @pos += result.bytesize result.force_encoding @external_encoding unless @external_encoding.nil? result = transcode_to_internal result result = out_buffer.replace result unless out_buffer.nil? result end |
#read_nonblock(bytes_to_read, out_buffer = nil, *options) ⇒ Object
– asynchronous –
108 109 110 111 112 113 114 |
# File 'lib/brs/stream/reader.rb', line 108 def read_nonblock(bytes_to_read, out_buffer = nil, *) raise ::EOFError if eof? read_more_from_buffer_nonblock(*) until @buffer.bytesize >= bytes_to_read || @io.eof? read_bytes_from_buffer bytes_to_read, out_buffer end |
#readpartial(bytes_to_read = nil, out_buffer = nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/brs/stream/reader.rb', line 79 def readpartial(bytes_to_read = nil, out_buffer = nil) raise ::EOFError if eof? readpartial_from_buffer until @buffer.bytesize >= bytes_to_read || @io.eof? read_bytes_from_buffer bytes_to_read, out_buffer end |
#rewind ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/brs/stream/reader.rb', line 92 def rewind raw_wrapper :close reset_io_remainder super end |