Class: Madeleine::ZMarshal
- Inherits:
-
Object
- Object
- Madeleine::ZMarshal
- 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, but not with SOAP marshalling.
Usage:
require 'madeleine'
require 'madeleine/zmarshal'
marshaller = Madeleine::ZMarshal.new(YAML)
madeleine = SnapshotMadeleine.new("my_example_storage", marshaller) {
SomeExampleApplication.new()
}
Instance Method Summary collapse
- #dump(system, stream) ⇒ Object
-
#initialize(marshaller = Marshal) ⇒ ZMarshal
constructor
A new instance of ZMarshal.
- #load(stream) ⇒ Object
Constructor Details
#initialize(marshaller = Marshal) ⇒ ZMarshal
Returns a new instance of ZMarshal.
32 33 34 |
# File 'lib/madeleine/zmarshal.rb', line 32 def initialize(marshaller=Marshal) @marshaller = marshaller end |
Instance Method Details
#dump(system, stream) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/madeleine/zmarshal.rb', line 50 def dump(system, stream) zstream = Zlib::GzipWriter.new(stream) begin @marshaller.dump(system, zstream) ensure zstream.finish end nil end |
#load(stream) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/madeleine/zmarshal.rb', line 36 def load(stream) zstream = Zlib::GzipReader.new(stream) begin # Buffer into a string first, since GzipReader can't handle # Marshal's 0-sized reads and SOAP can't handle streams at all. # In a bright future we can revert to reading directly from the # stream again. buffer = zstream.read return @marshaller.load(buffer) ensure zstream.finish end end |