title: Ruby - Append content at the end of the existing s3 file using fog
body: <p>How to append text in an existing or newly created file in S3. I am using <code>fog</code> and I have following code</p>
  
  <pre><code>require 'fog'
  file    = "abc.csv"
  bucket  = 'my_bucket'
  storage = Fog::Storage.new(:provider =&gt; 'AWS', :aws_access_key_id =&gt; 'XXXXXXXX', :aws_secret_access_key =&gt; 'YYYYYYYY')
  dir     = connection.directories.new(:key =&gt; bucket) # no harm, if this bucket already exists, if not create one
  buffer  = ["big_chunk1", "big_chunk2", "big_chunk3", "big_chunk4", "big_chunk5"]
  
  # I need help after this line. No changes above.
  buffer.each do |chunk|
    # this will not work as it will not append text below the existing file or 
    # newly created one. I am not looking for solution suggesting, buffer.join('') 
    # and then write whole chunk at once. I have to write in chuck for some specific reason.
    # Also I dont want to first read existing data and then take in to memory
    # and then append and finally write back.
    dir.files.create(:key =&gt; file, :body =&gt; chunk, :public =&gt; false) 
  end
  </code></pre>