Module: VCR::Cassette::Serializers::Compressed

Extended by:
Compressed
Included in:
Compressed
Defined in:
lib/vcr/cassette/serializers/compressed.rb

Overview

The compressed serializer. This serializer wraps the YAML serializer to write compressed cassettes to disk.

Cassettes containing responses with JSON data often compress at greater than 10:1. The tradeoff is that cassettes will not diff nicely or be easily inspectable or editable.

See Also:

Instance Method Summary collapse

Instance Method Details

#deserialize(string) ⇒ Hash

Deserializes the given compressed cassette data.

Parameters:

  • string (String)

    the compressed YAML cassette data

Returns:

  • (Hash)

    the deserialized object



38
39
40
41
# File 'lib/vcr/cassette/serializers/compressed.rb', line 38

def deserialize(string)
  yaml = Zlib::Inflate.inflate(string)
  VCR::Cassette::Serializers::YAML.deserialize(yaml)
end

#file_extensionString

The file extension to use for this serializer.

Returns:

  • (String)

    "zz"



21
22
23
# File 'lib/vcr/cassette/serializers/compressed.rb', line 21

def file_extension
  'zz'
end

#serialize(hash) ⇒ String

Serializes the given hash using YAML and Zlib.

Parameters:

  • hash (Hash)

    the object to serialize

Returns:

  • (String)

    the compressed cassette data



29
30
31
32
# File 'lib/vcr/cassette/serializers/compressed.rb', line 29

def serialize(hash)
  string = VCR::Cassette::Serializers::YAML.serialize(hash)
  Zlib::Deflate.deflate(string)
end