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 |
# File 'lib/snappy/reader.rb', line 16 def each until @io.eof? if @chunked size = @io.read(4).unpack('N').first yield Snappy.inflate(@io.read(size)) if block_given? else yield Snappy.inflate @io.read if block_given? end end end |
#each_line(sep_string = $/) {|last| ... } ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/snappy/reader.rb', line 35 def each_line(sep_string = $/) last = "" each do |chunk| chunk = last + chunk lines = chunk.split(sep_string) last = lines.pop lines.each do |line| yield line if block_given? end end yield last end |
#read ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/snappy/reader.rb', line 27 def read @buff = StringIO.new each do |chunk| @buff << chunk end @buff.string end |