Class: Madeleine::ZMarshal

Inherits:
Object
  • Object
show all
Defined in:
lib/madeleine/zmarshal.rb

Overview

Snapshot marshaller for compressed snapshots.

Compresses the snapshots created by another marshaller. Uses either Marshal (the default) or another supplied marshaller.

Uses zlib to do on-the-fly compression/decompression.

ZMarshal works with Ruby’s own Marshal and YAML

Usage:

require 'madeleine'
require 'madeleine/zmarshal'

marshaller = Madeleine::ZMarshal.new(YAML)
madeleine = SnapshotMadeleine.new("my_example_storage", marshaller) {
  SomeExampleApplication.new
}

Defined Under Namespace

Classes: WorkaroundGzipReader

Instance Method Summary collapse

Constructor Details

#initialize(marshaller = Marshal) ⇒ ZMarshal

Returns a new instance of ZMarshal.



31
32
33
# File 'lib/madeleine/zmarshal.rb', line 31

def initialize(marshaller=Marshal)
  @marshaller = marshaller
end

Instance Method Details

#dump(system, stream) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/madeleine/zmarshal.rb', line 44

def dump(system, stream)
  zstream = Zlib::GzipWriter.new(stream)
  begin
    @marshaller.dump(system, zstream)
  ensure
    zstream.finish
  end
  nil
end

#load(stream) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/madeleine/zmarshal.rb', line 35

def load(stream)
  zstream = WorkaroundGzipReader.new(stream)
  begin
    return @marshaller.load(zstream)
  ensure
    zstream.finish
  end
end