Class: NdrImport::File::SevenZip
- Defined in:
- lib/ndr_import/file/seven_zip.rb
Overview
This class is a 7zip file handler that returns tables from the extracted files.
Instance Method Summary collapse
- #files(&block) ⇒ Object
-
#initialize(filename, format, options = {}) ⇒ SevenZip
constructor
A new instance of SevenZip.
-
#tables ⇒ Object
7zip files produce files, never tables.
Constructor Details
#initialize(filename, format, options = {}) ⇒ SevenZip
Returns a new instance of SevenZip.
11 12 13 14 15 16 17 18 |
# File 'lib/ndr_import/file/seven_zip.rb', line 11 def initialize(filename, format, = {}) super @pattern = ['pattern'] || // @unzip_path = ['unzip_path'] @password = ['password'] validate_unzip_path_is_safe! end |
Instance Method Details
#files(&block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ndr_import/file/seven_zip.rb', line 20 def files(&block) raise 'Not allowed in external environment' if defined?(::Rails) && ::Rails.env.external? return enum_for(:files) unless block destination = @unzip_path.join(Time.current.strftime('%H%M%S%L')) FileUtils.mkdir_p(SafeFile.safepath_to_string(destination)) ::File.open(SafeFile.safepath_to_string(@filename), 'rb') do |zipfile| unzip_entries(zipfile, destination, &block) end end |
#tables ⇒ Object
7zip files produce files, never tables.
34 35 36 |
# File 'lib/ndr_import/file/seven_zip.rb', line 34 def tables raise 'SevenZip#tables should never be called' end |