class Sprockets::Asset

def write_to(filename, options = {})

Save asset to disk.
def write_to(filename, options = {})
  # Gzip contents if filename has '.gz'
  options[:compress] ||= File.extname(filename) == '.gz'
  FileUtils.mkdir_p File.dirname(filename)
  File.open("#{filename}+", 'wb') do |f|
    if options[:compress]
      # Run contents through `Zlib`
      gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
      gz.mtime = mtime.to_i
      gz.write to_s
      gz.close
    else
      # Write out as is
      f.write to_s
    end
  end
  # Atomic write
  FileUtils.mv("#{filename}+", filename)
  # Set mtime correctly
  File.utime(mtime, mtime, filename)
  nil
ensure
  # Ensure tmp file gets cleaned up
  FileUtils.rm("#{filename}+") if File.exist?("#{filename}+")
end