<commit_before>module S3Helper
  def read_s3_file(path)
    s3_object(path).read.chomp
  end

  def delete_s3_file(path)
    s3_object(path).delete
  end

  def create_s3_file(path, &block)
    @tmp = Tempfile.new('')

    File.open(@tmp, "w") do |f|
      yield f
    end

    s3_object(path).write(file: @tmp.path)
    rescue
    @tmp.close!
  end

  def s3_object(path)
    bucket  = bucket(path)
    s3_path = s3_path(path)

    s3.buckets[bucket].objects[s3_path]
  end

  private

  def bucket(path)
    path.split('/', -1).first
  end

  def s3_path(path)
    path.split('/', -1).drop(1).join('/')
  end

  def s3
    @s3 ||= ::AWS::S3.new
  end
end
<commit_msg>* Tempfile#close instead of Tempfile#close!    * not immediately delete but delete for GC<commit_after>module S3Helper
  def read_s3_file(path)
    s3_object(path).read.chomp
  end

  def delete_s3_file(path)
    s3_object(path).delete
  end

  def create_s3_file(path, &block)
    @tmp = Tempfile.new('')

    File.open(@tmp, "w") do |f|
      yield f
    end

    s3_object(path).write(file: @tmp.path)
  ensure
    @tmp.close
  end

  def s3_object(path)
    bucket  = bucket(path)
    s3_path = s3_path(path)

    s3.buckets[bucket].objects[s3_path]
  end

  private

  def bucket(path)
    path.split('/', -1).first
  end

  def s3_path(path)
    path.split('/', -1).drop(1).join('/')
  end

  def s3
    @s3 ||= ::AWS::S3.new
  end
end

{'fraction_non_alphanumeric': 0.14174344436569808, 'fraction_numerical': 0.026931254429482635, 'mean_word_length': 2.7754010695187166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3679697', 'n_tokens_mistral': 596, 'n_tokens_neox': 574, 'n_words': 115}