def inflate zstring=nil
@zstring = zstring unless zstring.nil?
@zstring.each_byte {|b| @input_buffer << b}
unless @rawdeflate then
compression_method_and_flags = @input_buffer[@in_pos+=1]
flags = @input_buffer[@in_pos+=1]
if ((compression_method_and_flags << 0x08) + flags) % 31 != 0 then raise Zlib::DataError.new("incorrect header check") end
compression_method = compression_method_and_flags & 0x0F
if compression_method != Z_DEFLATED then raise Zlib::DataError.new("unknown compression method") end
compression_info = compression_method_and_flags >> 0x04
if (compression_info + 8) > @w_bits then raise Zlib::DataError.new("invalid window size") end
preset_dictionary_flag = ((flags & 0x20) >> 0x05) == 1
compression_level = (flags & 0xC0) >> 0x06
if preset_dictionary_flag and @dict.nil? then raise Zlib::NeedDict.new "Preset dictionary needed!" end
if preset_dictionary_flag then
@dict_crc = @input_buffer[@in_pos+=1] << 24 | @input_buffer[@in_pos+=1] << 16 | @input_buffer[@in_pos+=1] << 8 | @input_buffer[@in_pos+=1]
end
end
last_block = false
until last_block
last_block = (get_bits(1) == 1)
block_type = get_bits(2)
case block_type
when 0 then no_compression
when 1 then fixed_codes
when 2 then dynamic_codes
when 3 then raise Zlib::DataError.new("invalid block type")
end
end
finish
end