Skip to content

Commit

Permalink
Properly close the GZip::Writer
Browse files Browse the repository at this point in the history
Co-authored-by: Christina Chortaria <[email protected]>
  • Loading branch information
sandbergja and christinach committed Aug 14, 2023
1 parent 44f94af commit 66fa270
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/models/alma_submit_collection/marc_s3_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def done
compressed = StringIO.new
compressor = Zlib::GzipWriter.new(compressed)
compressor.write file_contents.read
compressor.flush
client.put_object(bucket:, body: compressed, key: "#{Rails.configuration.scsb_s3[:scsb_s3_updates]}/scsb_#{File.basename(file_path)}")
compressor.close
client.put_object(bucket:, body: compressed.string, key: "#{Rails.configuration.scsb_s3[:scsb_s3_updates]}/scsb_#{File.basename(file_path)}")
end
@current_file.unlink
end
Expand All @@ -49,7 +49,7 @@ def done

def filename_components
components = ["scsb_submitcollection_#{@file_type}"]
components << "#{Time.current.iso8601}.marcxml"
components << "#{Time.current.iso8601}.marcxml.gz"
components
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
stub_alma_bibs(ids: constituent_ids, status: 200, fixture: "constituent_records.xml", apikey: '1234')
s3_client.stub_responses(
:put_object, lambda { |context|
files_sent_to_s3 << Zlib::GzipReader.new(context.params[:body])
files_sent_to_s3 << Zlib::GzipReader.new(StringIO.new(context.params[:body]))
}
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/alma_submit_collection/marc_s3_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
files_sent_to_s3 = []
s3_client.stub_responses(
:put_object, lambda { |context|
files_sent_to_s3 << Zlib::GzipReader.new(context.params[:body])
files_sent_to_s3 << Zlib::GzipReader.new(StringIO.new(context.params[:body]))
}
)

Expand Down

0 comments on commit 66fa270

Please sign in to comment.