title: Streaming-download a gzipped file from s3 and unzip it?
body: <p>I was trying to download a gzipped file from s3 bucket using AWS-SDK and then unzip the file using Zlib. </p>
  
  <p>Here is my code for this part: </p>
  
  <pre><code>File.open('app/assets/data.xml.gz', 'wb') do |file|
    bucket.objects['linkshare_temp/data.gz'].read do |chunk|
      file.write(chunk)
    end
  end
  
  
  Zlib::GzipReader.open('app/assets/data.gz','rb') do |gz|
    File.new("data.xml", "w") do |g|
      IO.copy_stream(gz, g)
    end
  end
  </code></pre>
  
  <p>It gives me this error: </p>
  
  <pre><code>Zlib::GzipFile::Error: not in gzip format
  </code></pre>
  
  <p>The file was downloaded from s3 to my local disk. I can see the file in my local folder with the right name and "xml.gz" suffix, but for some reason I can not open that file. I think there is something wrong with my code for downloading from s3. </p>
  
  <p>Thanks in advance.</p>