Sha256: 655f42c80bdad12907a1d344ffdeff3180195e28ca0c751170e83928e27b78ea
Contents?: true
Size: 1.19 KB
Versions: 6
Compression:
Stored size: 1.19 KB
Contents
# encoding: UTF-8 module Yajl module Deflate # 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 StreamReader < ::Zlib::Inflate # Wrapper to the initialize method so we can set the initial IO to parse from. def initialize(io, options) @io = io super(options) end # A helper method to allow use similar to IO#read def read(len=nil, buffer=nil) buffer.replace inflate(@io.read(len)) and return unless buffer.nil? inflate(@io.read(len)) end alias :eof? :finished? # Helper method for one-off parsing from a deflate-compressed stream # # See Yajl::Parser#parse for parameter documentation def self.parse(input, options={}, buffer_size=nil, &block) if input.is_a?(String) input = StringIO.new(input) end if options.is_a?(Hash) Yajl::Parser.new(options).parse(new(input), buffer_size, &block) elsif options.is_a?(Fixnum) Yajl::Parser.new.parse(new(input, options), buffer_size, &block) end end end end end
Version data entries
6 entries across 6 versions & 2 rubygems