Class: ASIR::Coder::Zlib

Inherits:
ASIR::Coder show all
Defined in:
lib/asir/coder/zlib.rb

Instance Attribute Summary collapse

Attributes included from Log

#_logger

Instance Method Summary collapse

Methods inherited from ASIR::Coder

#_subclass_responsibility, #decode, #encode, #prepare

Methods included from Log

#_log, #_log_enabled=, #_log_enabled?, #_log_format, #_log_result, enabled, enabled=, included

Methods included from Initialization

#initialize

Instance Attribute Details

#compression_levelObject

Returns the value of attribute compression_level.



8
9
10
# File 'lib/asir/coder/zlib.rb', line 8

def compression_level
  @compression_level
end

Instance Method Details

#_decode(obj) ⇒ Object

Raises:

  • (TypeError)


14
15
16
17
# File 'lib/asir/coder/zlib.rb', line 14

def _decode obj
  raise TypeError unless String === obj
  ::Zlib::Inflate.inflate(obj)
end

#_encode(obj) ⇒ Object

Raises:

  • (TypeError)


10
11
12
13
# File 'lib/asir/coder/zlib.rb', line 10

def _encode obj
  raise TypeError unless String === obj
  ::Zlib::Deflate.deflate(obj, @compression_level || ::Zlib::DEFAULT_COMPRESSION)
end