Class: Minizip::Zip

Inherits:
Object
  • Object
show all
Defined in:
lib/minizip/zip.rb

Class Method Summary collapse

Class Method Details

.extract(zip_name, options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/minizip/zip.rb', line 28

def self.extract(zip_name, options)
  if options && options.is_a?(String)
    puts "[DEPRECATED] Passing in 'directory' as the second argument is deprecated. Please pass it in as part of a hash instead, like this: extract(#{zip_name}, :directory => #{options}) #{caller.first}"
    options = {:directory => options}
  end
  options = options.with_indifferent_access
  directory = options[:directory]

  if File.exists?(zip_name)
    Dir.mkdir(directory) if directory && !File.exists?(directory)

    if USING_WINDOWS
      overwrite = options['overwrite'] ? '-y' : nil
      if directory
        system "7za x #{zip_name} -o#{directory} #{overwrite}"
      else
        system "7za x #{zip_name} #{overwrite}"
      end
    else
      overwrite = options['overwrite'] ? '-o' : nil
      if directory
        system "unzip #{overwrite} '#{zip_name}' -d #{directory}"
      else
        system "unzip #{overwrite} '#{zip_name}'"
      end
    end
  else
    puts "#{zip_name} doesn't exist in #{Dir.pwd}"
  end
end

.zip_dir(zip_name, directory) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/minizip/zip.rb', line 16

def self.zip_dir(zip_name, directory)
  if File.exists?(directory)
    if USING_WINDOWS
      system "7za a #{zip_name} #{directory}"
    else
      system "zip -r #{zip_name} #{directory}"
    end
  else
    puts "#{directory} doesn't exist in #{Dir.pwd}"
  end
end

.zip_files(zip_name, *files) ⇒ Object



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

def self.zip_files(zip_name, *files)
  if USING_WINDOWS
    system "7za a #{zip_name} #{files.join(' ')}"
  else
    system "zip #{zip_name} #{files.join(' ')}"
  end
end