class IOP::ZlibCompressor

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

@since 0.1

Public Class Methods

new(*args) click to toggle source

Creates class instance.

@param args [Array] arguments passed to Zlib::Deflate constructor

# File lib/iop/zlib.rb, line 32
def initialize(*args)
  @args = args
end

Public Instance Methods

process(data = nil) click to toggle source
Calls superclass method IOP::Sink#process
# 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!() click to toggle source
Calls superclass method IOP::Sink#process!
# File lib/iop/zlib.rb, line 45
def process!
  @deflate = Zlib::Deflate.new(*@args)
  begin
    super
  ensure
    @deflate.close
  end
end