Sha256: 1997201af0fc2d4d188c9721ec671bf22de720e4f481046aeb503e109272530a

Contents?: true

Size: 1.43 KB

Versions: 9

Compression:

Stored size: 1.43 KB

Contents

#
# Author::    Anders Bengtsson <ndrsbngtssn@yahoo.se>
# Copyright:: Copyright (c) 2004
#

require 'zlib'

module Madeleine
  #
  # Snapshot marshaller for compressed snapshots.
  #
  # Compresses the snapshots created by another marshaller. Uses either
  # Marshal (the default) or another supplied marshaller.
  #
  # Uses <tt>zlib</tt> 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()
  #  }
  #
  class ZMarshal

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

    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

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

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
Pimki-1.4.092 libraries/madeleine/zmarshal.rb
Pimki-1.5.092 libraries/madeleine/zmarshal.rb
Pimki-1.8.200 libraries/madeleine/zmarshal.rb
Pimki-1.6.092 libraries/madeleine/zmarshal.rb
Pimki-1.7.092 libraries/madeleine/zmarshal.rb
Pimki-1.8.092 libraries/madeleine/zmarshal.rb
madeleine-0.7.3 lib/madeleine/zmarshal.rb
madeleine-0.7.2 lib/madeleine/zmarshal.rb
madeleine-0.7.1 lib/madeleine/zmarshal.rb