Module: Rabbit::Compressor
Constant Summary collapse
- Error =
Class.new(StandardError)
- UncompressingError =
Class.new(Error)
Instance Method Summary collapse
- #dump(data, msgpack_options: {}, with_base64: false) ⇒ Object
- #load(data, msgpack_options: {}, with_base64: false) ⇒ Object
Instance Method Details
#dump(data, msgpack_options: {}, with_base64: false) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rabbit/compressor.rb', line 15 def dump(data, msgpack_options: {}, with_base64: false) dumped = Zlib::Deflate.deflate(MessagePack.pack(data, )) return dumped unless with_base64 strict_encode64(dumped) end |
#load(data, msgpack_options: {}, with_base64: false) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/rabbit/compressor.rb', line 23 def load(data, msgpack_options: {}, with_base64: false) return {} unless data data = decode64(data) if with_base64 MessagePack.unpack(Zlib::Inflate.inflate(data), ) rescue Zlib::Error, MessagePack::UnpackError => error raise UncompressingError, "Unable to uncompress data, #{error}" end |