Class: RubyLepton::Base

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

Class Method Summary collapse

Class Method Details

.compress(source_file, options = {}) ⇒ Object



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

def compress(source_file, options={})
  generated_file = "output/"+SecureRandom.hex(4)+".lep"
  `lepton -memory=1024M -threadmemory=128M #{source_file} #{generated_file}`
  if File.exist? generated_file
    output = File.open(generated_file, 'rb')
    if options[:binary].to_s == "true"
      File.delete(generated_file)
      return output.read
    else
      puts "Compressed file saved to: " + generated_file
      return generated_file
    end
  else
    puts "Error in compression"
  end
end

.decompress(source_file, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_lepton.rb', line 25

def decompress(source_file, options={})
  generated_file = "output/"+SecureRandom.hex(4)+".jpeg"
  `lepton -memory=1024M -threadmemory=128M #{source_file} #{generated_file}`
  if File.exist? generated_file
    output = File.open(generated_file, 'rb')
    if options[:binary].to_s == "true"
      File.delete(generated_file)
      return output.read
    else
      puts "Decompressed file saved to: " + generated_file
      return generated_file
    end
  else
    puts "Error in decompression"
  end
end