Class: NdrImport::File::SevenZip

Inherits:
Base
  • Object
show all
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

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, options = {})
  super
  @pattern = options['pattern'] || //
  @unzip_path = options['unzip_path']
  @password = options['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

#tablesObject

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