Skip to content

Commit

Permalink
Close gzipped file handle
Browse files Browse the repository at this point in the history
  • Loading branch information
zinkkrysty committed Jul 10, 2017
1 parent c7ec7a9 commit 78200a8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/asset_sync/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def upload_file(f)
one_year = 31557600
ext = File.extname(f)[1..-1]
mime = MultiMime.lookup(ext)
gzip_file_handle = nil
file_handle = File.open("#{path}/#{f}")
file = {
:key => f,
Expand Down Expand Up @@ -169,9 +170,10 @@ def upload_file(f)

if gzipped_size < original_size
percentage = ((gzipped_size.to_f/original_size.to_f)*100).round(2)
gzip_file_handle = File.open(gzipped)
file.merge!({
:key => f,
:body => File.open(gzipped),
:body => gzip_file_handle,
:content_encoding => 'gzip'
})
log "Uploading: #{gzipped} in place of #{f} saving #{percentage}%"
Expand Down Expand Up @@ -202,6 +204,7 @@ def upload_file(f)

bucket.files.create( file ) unless ignore
file_handle.close
gzip_file_handle.close if gzip_file_handle
end

def upload_files
Expand Down

0 comments on commit 78200a8

Please sign in to comment.