Class: AppleEpf::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_epf/extractor.rb

Defined Under Namespace

Classes: FileEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, files_to_extract) ⇒ Extractor

Returns a new instance of Extractor.



8
9
10
11
12
13
14
# File 'lib/apple_epf/extractor.rb', line 8

def initialize(filename, files_to_extract)
  @filename = filename
  @files_to_extract = files_to_extract

  @dirname = File.dirname(@filename)
  @basename = File.basename(@filename)
end

Instance Attribute Details

#basenameObject (readonly)

Returns the value of attribute basename.



5
6
7
# File 'lib/apple_epf/extractor.rb', line 5

def basename
  @basename
end

#dirnameObject (readonly)

Returns the value of attribute dirname.



5
6
7
# File 'lib/apple_epf/extractor.rb', line 5

def dirname
  @dirname
end

#file_entryObject (readonly)

Returns the value of attribute file_entry.



5
6
7
# File 'lib/apple_epf/extractor.rb', line 5

def file_entry
  @file_entry
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/apple_epf/extractor.rb', line 5

def filename
  @filename
end

#keep_tbz_after_extractObject

Returns the value of attribute keep_tbz_after_extract.



6
7
8
# File 'lib/apple_epf/extractor.rb', line 6

def keep_tbz_after_extract
  @keep_tbz_after_extract
end

Instance Method Details

#performObject

TODO use multithread uncompressing tool



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/apple_epf/extractor.rb', line 17

def perform
  @extracted_files = Array.new
  @files_to_extract.each do |f|
    @extracted_files.push File.basename(@filename, '.tbz') + '/' + f
  end

  result = system "cd #{@dirname} && tar -xjf #{@basename} #{@extracted_files.join(' ')}"

  if result
    _extracted_files = @extracted_files.map{|f| File.join(@dirname, f)}
    @file_entry = FileEntry.new(@filename, Hash[@files_to_extract.zip(_extracted_files)])
    FileUtils.remove_file(@filename, true) unless keep_tbz_after_extract?
  else
    raise "Unable to extract files '#{@files_to_extract.join(' ')}' from #{@filename}"
  end

  @file_entry
end