Class: Yajl::Bzip2::StreamReader

Inherits:
Bzip2::Reader
  • Object
show all
Defined in:
lib/yajl/bzip2/stream_reader.rb

Overview

This is a wrapper around Bzip::Reader to allow it’s #read method to adhere to the IO spec, allowing for two parameters (length, and buffer)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(input, options = {}, buffer_size = nil, &block) ⇒ Object

Helper method for one-off parsing from a bzip2-compressed stream

See Yajl::Parser#parse for parameter documentation



20
21
22
23
24
25
26
# File 'lib/yajl/bzip2/stream_reader.rb', line 20

def self.parse(input, options={}, buffer_size=nil, &block)
  if input.is_a?(String)
    input = StringIO.new(input)
  end
  
  Yajl::Parser.new(options).parse(new(input), buffer_size, &block)
end

Instance Method Details

#read(len = nil, buffer = nil) ⇒ Object

A helper method to allow use similar to IO#read



9
10
11
12
13
14
15
# File 'lib/yajl/bzip2/stream_reader.rb', line 9

def read(len=nil, buffer=nil)
  unless buffer.nil?
    buffer.replace super(len)
    return buffer
  end
  super(len)
end