Class: CompressionTask

Inherits:
Task
  • Object
show all
Defined in:
ext/lib/CompLearnLib/CompressionTask.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cObjects) ⇒ CompressionTask

Returns a new instance of CompressionTask.



35
36
37
38
39
40
41
# File 'ext/lib/CompLearnLib/CompressionTask.rb', line 35

def initialize(cObjects)
  @cObjects = cObjects.clone
  @idTotal = ""
  cObjects.each { |obj|
      idTotal << obj.to_s
  }
end

Instance Attribute Details

#idTotalObject (readonly)

Returns the value of attribute idTotal.



33
34
35
# File 'ext/lib/CompLearnLib/CompressionTask.rb', line 33

def idTotal
  @idTotal
end

Instance Method Details

#executeObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/lib/CompLearnLib/CompressionTask.rb', line 43

def execute()
  total = ""
  @cObjects.each { |obj|
    total << obj.value
  }
  compmethod = CLConfig.getDefaultConfig().compressor

  case compmethod.downcase

    when "bz2", "bzip2", "bzip", "bz"

    if FoundComp::FOUNDBZIP2
      reply(BZ2.compress(total).size)
    else
      fail "Sorry, bzip2 compression is not installed on this system."
    end

    when "gzip", "gz"
    if FoundComp::FOUNDGZIP
      reply(gzipCompress(total).size)
    else
      fail "Sorry, gzip compression is not installed on this system."
    end

    when "shell"
      cmd = CLConfig.getDefaultConfig().compressorCommand
      result = 0
      begin
      f = IO.popen(cmd, "w+")
      writer = Thread.new() {
        blocksize, inpos = 1024, 0
        while inpos < total.size
          wanted = total.size - inpos
          wanted = blocksize if wanted > blocksize
          inpos += f.write(total[inpos...inpos+wanted])
        end
        f.close_write
      }
      result = f.read.size
      f.close
      rescue
        puts "Got error: #{$!}"
        result = -1
      end
      reply(result)

    when "none"
      fail "Sorry, no valid compressors installed!"

    else
      fail "Sorry, compression method #{compmethod} is not supported"

  end

end