Class: Moneta::Transforms::Bzip2
- Inherits:
-
Moneta::Transform
- Object
- Moneta::Transform
- Moneta::Transforms::Bzip2
- Defined in:
- lib/moneta/transforms/bzip2.rb
Overview
Compresses strings using the rbzip2 gem
Instance Method Summary collapse
-
#decode(value) ⇒ String
Decompresses BZip2-compressed data.
-
#encode(value) ⇒ String
Compresses using BZip2.
-
#encoded?(value) ⇒ Boolean
Returns true if the string starts with the right magic number (“BZh”).
Methods inherited from Moneta::Transform
#decodable?, delegate_to, #initialize, #method_missing, #respond_to_missing?
Constructor Details
This class inherits a constructor from Moneta::Transform
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Moneta::Transform
Instance Method Details
#decode(value) ⇒ String
Decompresses BZip2-compressed data
32 33 34 |
# File 'lib/moneta/transforms/bzip2.rb', line 32 def decode(value) ::RBzip2.default_adapter::Decompressor.new(::StringIO.new(value)).read end |
#encode(value) ⇒ String
Compresses using BZip2
12 13 14 15 16 17 18 |
# File 'lib/moneta/transforms/bzip2.rb', line 12 def encode(value) io = ::StringIO.new bz = ::RBzip2.default_adapter::Compressor.new(io) bz.write(value) bz.close io.string end |
#encoded?(value) ⇒ Boolean
Returns true if the string starts with the right magic number (“BZh”)
24 25 26 |
# File 'lib/moneta/transforms/bzip2.rb', line 24 def encoded?(value) String === value && value.byteslice(0, 3) == "BZh" end |