Class: RSI::CompressedSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/rsi/compressed_serializers.rb

Overview

Serializer which performs gzip/libz compression on the output of another base serializer. By default, this sits on top of an RSI::NativeSerializer.

(unconfirmed) This may be particularly sensitive to when the underlying stream passed to #dump and #load is closed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_serializer = RSI::NativeSerializer.new()) ⇒ CompressedSerializer

By default, this serializer is based on NativeSerializer. If you prefer another underlying serializer, you may pass it as an argument to new().



22
23
24
# File 'lib/rsi/compressed_serializers.rb', line 22

def initialize( base_serializer=RSI::NativeSerializer.new() )
  @base=base_serializer
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



17
18
19
# File 'lib/rsi/compressed_serializers.rb', line 17

def base
  @base
end

Instance Method Details

#dump(obj, stream) ⇒ Object



26
27
28
29
# File 'lib/rsi/compressed_serializers.rb', line 26

def dump( obj, stream )
  w = ZLib::GZipWriter.new( stream )
  @base.dump( obj, w )
end

#load(stream) ⇒ Object



31
32
33
34
# File 'lib/rsi/compressed_serializers.rb', line 31

def load( stream )
  r = ZLib.GZipReader.new( stream )
  return @base.load( r )
end