# File temp/source.rb, line 138 def initialize(arg, block_size=500, encoding=nil) @er_source = @source = arg @to_utf = false # Determining the encoding is a deceptively difficult issue to resolve. # First, we check the first two bytes for UTF-16. Then we # assume that the encoding is at least ASCII enough for the '>', and # we read until we get one of those. This gives us the XML declaration, # if there is one. If there isn't one, the file MUST be UTF-8, as per # the XML spec. If there is one, we can determine the encoding from # it. @buffer = "" str = @source.read( 2 ) || '' if encoding self.encoding = encoding elsif str[0,2] == "\xfe\xff" @line_break = "\000>" elsif str[0,2] == "\xff\xfe" @line_break = ">\000" elsif str[0,2] == "\xef\xbb" str += @source.read(1) str = '' if (str[2,1] == "\xBF") @line_break = ">" else @line_break = ">" end super( @source.eof? ? str : str+@source.readline( @line_break ) ) end