<commit_before># Uses the official Amazon Web Services SDK gem:
#   gem install aws-sdk
module EchoUploads
  class S3Store < ::EchoUploads::AbstractStore    
    def delete(key)
      bucket.objects[path(key)].delete
    end
    
    def exists?(key)
      bucket.objects[path(key)].exists?
    end
    
    def read(key)
      data = ''
      bucket.objects[path(key)].read { |chunk| data << chunk }
      data
    end
    
    def url(key, options = {})
      options = {method: :read}.merge(options)
      bucket.objects[path(key)].url_for options.delete(:method), options
    end
    
    def write(key, file)
      bucket.objects[path(key)].write file
    end
    
    private
    
    def bucket
      if Rails.configuration.echo_uploads.aws
        s3 = AWS::S3.new Rails.configuration.echo_uploads.aws
      else<commit_msg>S3Store now rewinds files before writing them to S3<commit_after># Uses the official Amazon Web Services SDK gem:
#   gem install aws-sdk
module EchoUploads
  class S3Store < ::EchoUploads::AbstractStore    
    def delete(key)
      bucket.objects[path(key)].delete
    end
    
    def exists?(key)
      bucket.objects[path(key)].exists?
    end
    
    def read(key)
      data = ''
      bucket.objects[path(key)].read { |chunk| data << chunk }
      data
    end
    
    def url(key, options = {})
      options = {method: :read}.merge(options)
      bucket.objects[path(key)].url_for options.delete(:method), options
    end
    
    def write(key, file)
      file.rewind
      bucket.objects[path(key)].write file
    end
    
    private
    
    def bucket
      if Rails.configuration.echo_uploads.aws
        s3 = AWS::S3.new Rails.configuration.echo_uploads.aws
      else
{'fraction_non_alphanumeric': 0.1063953488372093, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 2.4214711729622267, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7561207', 'n_tokens_mistral': 548, 'n_tokens_neox': 531, 'n_words': 126}