module Sprockets::Utils

def self.read_unicode(pathname)

def self.read_unicode(pathname)
  pathname.read.tap do |data|
    # Eager validate the file's encoding. In most cases we
    # expect it to be UTF-8 unless `default_external` is set to
    # something else. An error is usually raised if the file is
    # saved as UTF-16 when we expected UTF-8.
    if !data.valid_encoding?
      raise EncodingError, "#{pathname} has a invalid " +
        "#{data.encoding} byte sequence"
    # If the file is UTF-8 and theres a BOM, strip it for safe concatenation.
    elsif data.encoding.name == "UTF-8" && data =~ UTF8_BOM_PATTERN
      data.sub!(UTF8_BOM_PATTERN, "")
    end
  end
end