Class: Yajl::Deflate::StreamReader
- Defined in:
- lib/yajl/deflate/stream_reader.rb
Overview
This is a wrapper around Zlib::Inflate, creating a #read method that adheres to the IO spec, allowing for two parameters (length, and buffer)
Class Method Summary collapse
-
.parse(input, options = {}, buffer_size = nil, &block) ⇒ Object
Helper method for one-off parsing from a deflate-compressed stream.
Instance Method Summary collapse
-
#initialize(io, options) ⇒ StreamReader
constructor
Wrapper to the initialize method so we can set the initial IO to parse from.
-
#read(len = nil, buffer = nil) ⇒ Object
A helper method to allow use similar to IO#read.
Constructor Details
#initialize(io, options) ⇒ StreamReader
Wrapper to the initialize method so we can set the initial IO to parse from.
8 9 10 11 |
# File 'lib/yajl/deflate/stream_reader.rb', line 8 def initialize(io, ) @io = io super() end |
Class Method Details
.parse(input, options = {}, buffer_size = nil, &block) ⇒ Object
Helper method for one-off parsing from a deflate-compressed stream
See Yajl::Parser#parse for parameter documentation
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/yajl/deflate/stream_reader.rb', line 29 def self.parse(input, ={}, buffer_size=nil, &block) if input.is_a?(String) input = StringIO.new(input) end if .is_a?(Hash) = .delete(:deflate_options) Yajl::Parser.new().parse(new(input, ), buffer_size, &block) elsif .is_a?(Fixnum) Yajl::Parser.new.parse(new(input, ), buffer_size, &block) end end |
Instance Method Details
#read(len = nil, buffer = nil) ⇒ Object
A helper method to allow use similar to IO#read
14 15 16 17 18 19 20 21 22 23 24 |
# 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 |