class Yajl::Deflate::StreamReader
This is a wrapper around Zlib::Inflate, creating a read method that adheres to the IO spec, allowing for two parameters (length, and buffer)
Public Class Methods
new(io, options)
click to toggle source
Wrapper to the initialize method so we can set the initial IO to parse from.
Calls superclass method
# File lib/yajl/deflate/stream_reader.rb, line 8 def initialize(io, options) @io = io super(options) end
parse(input, options={}, buffer_size=nil, &block)
click to toggle source
Helper method for one-off parsing from a deflate-compressed stream
See Yajl::Parser#parse for parameter documentation
# File lib/yajl/deflate/stream_reader.rb, line 29 def self.parse(input, options={}, buffer_size=nil, &block) if input.is_a?(String) input = StringIO.new(input) end if options.is_a?(Hash) deflate_options = options.delete(:deflate_options) Yajl::Parser.new(options).parse(new(input, deflate_options), buffer_size, &block) elsif options.is_a?(Fixnum) Yajl::Parser.new.parse(new(input, options), buffer_size, &block) end end
Public Instance Methods
read(len=nil, buffer=nil)
click to toggle source
A helper method to allow use similar to IO#read
# File lib/yajl/deflate/stream_reader.rb, line 14 def read(len=nil, buffer=nil) if val = @io.read(len) unless buffer.nil? buffer.replace(inflate(val)) return buffer end inflate(@io.read(len)) else nil end end