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.
5 6 7 8 9 10 |
# File 'lib/snappy/reader.rb', line 5 def initialize(io) @io = io @io.set_encoding Encoding::ASCII_8BIT unless RUBY_VERSION =~ /^1\.8/ read_header! yield self if block_given? end |
Instance Attribute Details
#default_version ⇒ Object (readonly)
Returns the value of attribute default_version.
3 4 5 |
# File 'lib/snappy/reader.rb', line 3 def default_version @default_version end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
3 4 5 |
# File 'lib/snappy/reader.rb', line 3 def io @io end |
#magic ⇒ Object (readonly)
Returns the value of attribute magic.
3 4 5 |
# File 'lib/snappy/reader.rb', line 3 def magic @magic end |
#minimum_compatible_version ⇒ Object (readonly)
Returns the value of attribute minimum_compatible_version.
3 4 5 |
# File 'lib/snappy/reader.rb', line 3 def minimum_compatible_version @minimum_compatible_version end |
Instance Method Details
#each ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/snappy/reader.rb', line 12 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
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/snappy/reader.rb', line 31 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
23 24 25 26 27 28 29 |
# File 'lib/snappy/reader.rb', line 23 def read @buff = StringIO.new each do |chunk| @buff << chunk end @buff.string end |