Class: Ccrypto::Ruby::Compression

Inherits:
Object
  • Object
show all
Includes:
TeLogger::TeLogHelper
Defined in:
lib/ccrypto/ruby/engines/compression_engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Compression

Returns a new instance of Compression.

Raises:

  • (CompressionError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ccrypto/ruby/engines/compression_engine.rb', line 11

def initialize(*args, &block)

  @config = args.first
  raise CompressionError, "Compress Config is expected. Given #{@config}" if not @config.is_a?(Ccrypto::CompressionConfig)
  
  if block

    outPath = block.call(:out_path)
    if is_empty?(outPath)
      outFile = block.call(:out_file) 
      raise CompressionError, "Given out_file required to support write() call" if not outFile.respond_to?(:write)
      @out = outFile
    else
      @out = Tempfile.new(SecureRandom.hex(24)) 
    end

    @intBufSize = block.call(:int_buf_size) || 102400

  else
    @intBufSize = 102400

  end

  case @config.level
  when :best_compression
    teLogger.debug "Best compression"
    @eng = Zlib::Deflate.new(Zlib::BEST_COMPRESSION)
  when :best_speed
    teLogger.debug "Best compression"
    @eng = Zlib::Deflate.new(Zlib::BEST_SPEED)
  when :no_compression
    teLogger.debug "No compression"
    @eng = Zlib::Deflate.new(Zlib::NO_COMPRESSION)
  else
    teLogger.debug "Default compression"
    @eng = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION)
  end

end

Instance Method Details

#finalObject



55
56
57
# File 'lib/ccrypto/ruby/engines/compression_engine.rb', line 55

def final
  
end

#update(val) ⇒ Object



51
52
53
# File 'lib/ccrypto/ruby/engines/compression_engine.rb', line 51

def update(val)
  @eng.deflate(val, Zlib::SYNC_FLUSH)
end