Class: ZSTDS::Stream::Reader
- Includes:
- ReaderHelpers
- Defined in:
- lib/zstds/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
-
#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
-
#readpartial(bytes_to_read, out_buffer = nil) ⇒ Object
– asynchronous –.
- #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 26 |
# File 'lib/zstds/stream/reader.rb', line 16 def initialize(source_io, = {}, *args) @options = super source_io, *args initialize_source_buffer_length reset_io_remainder reset_need_to_flush @lineno = 0 end |
Instance Attribute Details
#lineno ⇒ Object
Returns the value of attribute lineno.
14 15 16 |
# File 'lib/zstds/stream/reader.rb', line 14 def lineno @lineno end |
Instance Method Details
#close ⇒ Object
82 83 84 85 86 |
# File 'lib/zstds/stream/reader.rb', line 82 def close raw_wrapper :close super end |
#eof? ⇒ Boolean
88 89 90 |
# File 'lib/zstds/stream/reader.rb', line 88 def eof? empty? && @io.eof? end |
#read(bytes_to_read = nil, out_buffer = nil) ⇒ Object
– synchronous –
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/zstds/stream/reader.rb', line 53 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? unless bytes_to_read.nil? return ::String.new :encoding => ::Encoding::BINARY if bytes_to_read.zero? return nil if eof? append_io_data @io.read(@source_buffer_length) while @buffer.bytesize < bytes_to_read && !@io.eof? flush_io_data if @buffer.bytesize < bytes_to_read return read_bytes_from_buffer bytes_to_read, out_buffer end append_io_data @io.read(@source_buffer_length) until @io.eof? flush_io_data read_buffer out_buffer end |
#read_nonblock(bytes_to_read, out_buffer = nil, *options) ⇒ Object
98 99 100 |
# File 'lib/zstds/stream/reader.rb', line 98 def read_nonblock(bytes_to_read, out_buffer = nil, *) read_more_nonblock(bytes_to_read, out_buffer) { @io.read_nonblock(@source_buffer_length, *) } end |
#readpartial(bytes_to_read, out_buffer = nil) ⇒ Object
– asynchronous –
94 95 96 |
# File 'lib/zstds/stream/reader.rb', line 94 def readpartial(bytes_to_read, out_buffer = nil) read_more_nonblock(bytes_to_read, out_buffer) { @io.readpartial @source_buffer_length } end |
#rewind ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/zstds/stream/reader.rb', line 73 def rewind raw_wrapper :close reset_io_remainder reset_need_to_flush super end |