<commit_before>require 'zip'

module DC

  # Helper methods for dealing with packaging zip archives, for mixing in to
  # controllers.
  module ZipUtils

    def package(zip_name)
      temp_dir = Dir.mktmpdir# do |temp_dir|
        zipfile = "#{temp_dir}/#{zip_name}"
        Zip::File.open(zipfile, Zip::File::CREATE) do |zip|
          yield zip
        end
        # TODO: We can stream, or even better, use X-Accel-Redirect, if we can
        # be sure to clean up the Zip after the fact -- with a cron or equivalent.
        send_file zipfile, :stream => false
#      end
    end

  end

end<commit_msg>Use Tempfile for zipfile creation<commit_after>require 'zip'

module DC

  # Helper methods for dealing with packaging zip archives, for mixing in to
  # controllers.
  module ZipUtils

    def package(zip_name)
      zipfile = Tempfile.new(["dc",".zip"])
      Zip::File.open(zipfile.path, Zip::File::CREATE) do |zip|
        yield zip
      end
      send_file zipfile.path, :type => 'application/zip', :disposition => 'attachment', :filename => zip_name
      zipfile.close
    end

  end

end
{'fraction_non_alphanumeric': 0.09864253393665158, 'fraction_numerical': 0.0, 'mean_word_length': 2.7491525423728813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4968404', 'n_tokens_mistral': 353, 'n_tokens_neox': 335, 'n_words': 114}