def write_to_temp_file(data, temp_base_name)
      Tempfile.new(temp_base_name, AttachmentMagic.tempfile_path).tap do |tmp|
        tmp.binmode
        tmp.write data
        tmp.close
      end
    end
def write_to_temp_file(data, temp_base_name)
      Tempfile.new(temp_base_name, AttachmentMagic.tempfile_path).tap do |tmp|
        tmp.binmode
        tmp.write data
        tmp.close
      end
    end
Writes the given data to a new tempfile, returning the closed tempfile.