Module: PrelandsRails::CreateSimpleSource::CheckZipFiles::ExtractFiles
- Included in:
- PrelandsRails::CreateSimpleSource::CheckZipFiles
- Defined in:
- lib/prelands_rails/create_simple_source/check_zip_files/extract_files.rb
Instance Method Summary collapse
-
#read_into_memory(expected_files, tempfile) ⇒ Hash
{ file_name => file_content, … }.
Instance Method Details
#read_into_memory(expected_files, tempfile) ⇒ Hash
Returns { file_name => file_content, … }.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prelands_rails/create_simple_source/check_zip_files/extract_files.rb', line 9 def read_into_memory(expected_files, tempfile) Zip::File.open(tempfile) do |zipfile| zipfile.map do |entry| next unless expected_files.find_index { |efile| efile.name == entry.name }.present? # Extract tmp_path = make_tmp_path entry.extract tmp_path # Read into memory content = entry.get_input_stream.read # Remove tmp file # File.delete(tmp_path) if File.exist?(tmp_path) [entry.name, content] end.compact.to_h end end |