Class: Mfp::Compressor
- Inherits:
-
Object
- Object
- Mfp::Compressor
- Defined in:
- lib/mfp/compressor.rb
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Instance Method Summary collapse
- #compress(data) ⇒ Object
- #decompress(data) ⇒ Object
-
#initialize(algo) ⇒ Compressor
constructor
A new instance of Compressor.
Constructor Details
#initialize(algo) ⇒ Compressor
Returns a new instance of Compressor.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mfp/compressor.rb', line 7 def initialize(algo) @kind = algo case algo when :identity nil when :gzip @compress = Zlib.method(:gzip) @decompress = Zlib.method(:gunzip) when :brotli @compress = Brotli.method(:deflate) @decompress = Brotli.method(:inflate) else raise ArgumentError, "Unknown compression algorithm #{algo}" end end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
5 6 7 |
# File 'lib/mfp/compressor.rb', line 5 def kind @kind end |
Instance Method Details
#compress(data) ⇒ Object
23 24 25 26 27 |
# File 'lib/mfp/compressor.rb', line 23 def compress(data) return data unless @compress @compress.call(data) end |
#decompress(data) ⇒ Object
29 30 31 32 33 |
# File 'lib/mfp/compressor.rb', line 29 def decompress(data) return data unless @decompress @decompress.call(data) end |