Skip to content

Commit

Permalink
Use Tempfiles, rather than StringIO, when decompressing a tarball (#719)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Kadel <[email protected]>
Co-authored-by: Mark Zelesky <[email protected]>
Co-authored-by: Christina Chortaria <[email protected]>
  • Loading branch information
4 people authored Mar 14, 2024
1 parent 5a9e970 commit fa0e961
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/models/tarball.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# take some .tar.gz IO (File, Net::SFTP::Operations::File, StringIO,
# or similar) and make its uncompressed contents available as an
# array of IO objects
# array of Tempfile objects
class Tarball
def initialize(file)
@file = file
Expand All @@ -14,7 +14,12 @@ def initialize(file)
def contents
@contents ||= untar.map do |entry|
next unless entry.file?
StringIO.new entry.read
tempfile = Tempfile.new(binmode: true)
while (chunk = entry.read(10))
tempfile.write chunk
end
tempfile.rewind
tempfile
end.compact
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'<subfield code="b">Indian agriculture after liberalization /</subfield>'\
'<subfield code="c">edited by R. Ramakumar.</subfield></datafield>'
decompressed_file_contents = alma_recap_file_list.download_and_decompress_file(alma_recap_filename)
expect(decompressed_file_contents.first.string).to include(title_field)
expect(decompressed_file_contents.first.read).to include(title_field)
end
end
describe '#mark_files_as_processed' do
Expand Down

0 comments on commit fa0e961

Please sign in to comment.