Class: Snappy::Reader
- Inherits:
-
Object
- Object
- Snappy::Reader
- Defined in:
- lib/snappy/reader.rb
Instance Attribute Summary collapse
-
#default_version ⇒ Object
readonly
Returns the value of attribute default_version.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#magic ⇒ Object
readonly
Returns the value of attribute magic.
-
#minimum_compatible_version ⇒ Object
readonly
Returns the value of attribute minimum_compatible_version.
Instance Method Summary collapse
- #each ⇒ Object
- #each_line(sep_string = $/) {|last| ... } ⇒ Object
-
#initialize(io) {|_self| ... } ⇒ Reader
constructor
A new instance of Reader.
- #read ⇒ Object
Constructor Details
#initialize(io) {|_self| ... } ⇒ Reader
Returns a new instance of Reader.
10 11 12 13 14 |
# File 'lib/snappy/reader.rb', line 10 def initialize(io) @io = Snappy.set_encoding io read_header! yield self if block_given? end |
Instance Attribute Details
#default_version ⇒ Object (readonly)
Returns the value of attribute default_version.
8 9 10 |
# File 'lib/snappy/reader.rb', line 8 def default_version @default_version end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
8 9 10 |
# File 'lib/snappy/reader.rb', line 8 def io @io end |
#magic ⇒ Object (readonly)
Returns the value of attribute magic.
8 9 10 |
# File 'lib/snappy/reader.rb', line 8 def magic @magic end |
#minimum_compatible_version ⇒ Object (readonly)
Returns the value of attribute minimum_compatible_version.
8 9 10 |
# File 'lib/snappy/reader.rb', line 8 def minimum_compatible_version @minimum_compatible_version end |
Instance Method Details
#each ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/snappy/reader.rb', line 16 def each return to_enum unless block_given? until @io.eof? if @chunked size = @io.read(4).unpack1("N") yield Snappy.inflate(@io.read(size)) else yield Snappy.inflate(@io.read) end end end |
#each_line(sep_string = $/) {|last| ... } ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/snappy/reader.rb', line 37 def each_line(sep_string = $/) return to_enum(:each_line, sep_string) unless block_given? last = "" each do |chunk| chunk = last + chunk lines = chunk.split(sep_string) last = lines.pop lines.each do |line| yield line end end yield last end |
#read ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/snappy/reader.rb', line 29 def read buff = StringIO.new each do |chunk| buff << chunk end buff.string end |