Class: Zopfli::Bin

Inherits:
Object
  • Object
show all
Defined in:
lib/zopfli/bin.rb

Constant Summary collapse

PATH =
File.expand_path("../../../vendor/zopfli/zopfli", __FILE__)

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/zopfli/bin.rb', line 9

def self.available?
  File.exists?(PATH)
end

.compress(filename, overwrite = false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zopfli/bin.rb', line 13

def self.compress(filename, overwrite=false)

  if !available? then
    raise "zopfli binary not found!"
  end

  if !File.exists?(filename) then
    raise "File not found: #{filename}"
  end

  if File.exists?(filename+".gz") && !overwrite then
    raise "Target file already exists: #{filename}.gz"
  end

  cmd = Mixlib::ShellOut.new("#{PATH} #{filename}")
  cmd.run_command

  return !cmd.error?
end