# File lib/html5/inputstream.rb, line 29
    def initialize(source, options = {})
      @encoding   = nil
      @parse_meta = true
      @chardet    = true

      options.each {|name, value| instance_variable_set("@#{name}", value) }

      # Raw Stream
      @raw_stream = open_stream(source)

      # Encoding Information
      #Number of bytes to use when looking for a meta element with
      #encoding information
      @NUM_BYTES_META = 512
      #Number of bytes to use when using detecting encoding using chardet
      @NUM_BYTES_CHARDET = 256
      #Number of bytes to use when reading content
      @NUM_BYTES_BUFFER = 1024

      #Encoding to use if no other information can be found
      @DEFAULT_ENCODING = 'windows-1252'
    
      #Detect encoding iff no explicit "transport level" encoding is supplied
      if @encoding.nil? or not HTML5.is_valid_encoding(@encoding)
        @char_encoding = detect_encoding
      else
        @char_encoding = @encoding
      end

      # Read bytes from stream decoding them into Unicode
      @buffer = @raw_stream.read(@NUM_BYTES_BUFFER) || ''
      if @char_encoding == 'windows-1252'
        @win1252 = true
      elsif @char_encoding != 'utf-8'
        require 'iconv'
        begin
          @buffer << @raw_stream.read unless @raw_stream.eof?
          @buffer = Iconv.iconv('utf-8', @char_encoding, @buffer).first
        rescue
          @win1252 = true
        end
      end

      @queue = []
      @errors = []

      # Reset position in the list to read from
      @tell = 0
      @line = @col = 0
      @line_lengths = []
    end