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
|