Class: DarwinCore::Expander

Inherits:
Object
  • Object
show all
Defined in:
lib/dwc_archive/expander.rb

Overview

Unpacks compressed archives into a temp directory

Instance Method Summary collapse

Constructor Details

#initialize(archive_path, tmp_dir) ⇒ Expander

Returns a new instance of Expander.


6
7
8
9
10
11
# File 'lib/dwc_archive/expander.rb', line 6

def initialize(archive_path, tmp_dir)
  @archive_path = archive_path
  @tmp_dir = tmp_dir
  @dir_path = DarwinCore.random_path(tmp_dir)
  @unpacker = init_unpacker
end

Instance Method Details

#cleanObject


29
30
31
# File 'lib/dwc_archive/expander.rb', line 29

def clean
  DarwinCore.clean(@dir_path)
end

#filesObject


33
34
35
# File 'lib/dwc_archive/expander.rb', line 33

def files
  DarwinCore.files(path)
end

#pathObject


25
26
27
# File 'lib/dwc_archive/expander.rb', line 25

def path
  @path ||= files_path
end

#unpackObject


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dwc_archive/expander.rb', line 13

def unpack
  clean
  raise DarwinCore::FileNotFoundError unless File.exist?(@archive_path)
  success = @unpacker.call(@dir_path, @archive_path) if @unpacker
  if @unpacker && success && $CHILD_STATUS.exitstatus.zero?
    success
  else
    clean
    raise DarwinCore::UnpackingError
  end
end