Class: IOP::ZlibCompressor
- Inherits:
-
Object
- Object
- IOP::ZlibCompressor
- Defined in:
- lib/iop/zlib.rb
Overview
Filter class to perform data compression with Zlib algorithm.
This class is an adapter for the standard Ruby +Zlib::Deflate+ class.
Note that this class does not produce valid .gz files - use GzipCompressor for this purpose.
Use case: compress a string.
require 'iop/zlib'
require 'iop/string'
( IOP::StringSplitter.new('Hello IOP') | IOP::ZlibCompressor.new | (s = IOP::StringMerger.new) ).process!
puts s.to_s
Instance Attribute Summary
Attributes included from Sink
Attributes included from Feed
Instance Method Summary collapse
-
#initialize(*args) ⇒ ZlibCompressor
constructor
Creates class instance.
- #process(data = nil) ⇒ Object
- #process! ⇒ Object
Methods included from Feed
Constructor Details
#initialize(*args) ⇒ ZlibCompressor
Creates class instance.
32 33 34 |
# File 'lib/iop/zlib.rb', line 32 def initialize(*args) @args = args end |
Instance Method Details
#process(data = nil) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/iop/zlib.rb', line 36 def process(data = nil) if data.nil? super(@deflate.finish) super else super(@deflate.deflate(data)) end end |
#process! ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/iop/zlib.rb', line 45 def process! @deflate = Zlib::Deflate.new(*@args) begin super ensure @deflate.close end end |