Class: MetaBuild::Helper::ZipHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_build/helper/zip_helper.rb

Class Method Summary collapse

Class Method Details

.extract(file, path, target) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/meta_build/helper/zip_helper.rb', line 7

def extract(file, path, target)
  Zip::File.open(file) do |zip_file|
    zip_file.each do |entry|              
      next unless entry.name.start_with? path

      target_file = File.join(target, entry.name)
      if entry.directory?
        FileUtils.makedirs target_file
        next
      end

      dir = File.dirname target_file
      FileUtils.makedirs dir unless  File.exist? dir

      File.open(target_file, 'wb') { |io| io.write entry.get_input_stream.read }
    end
  end
end