class Ciphr::Functions::ZLib::Deflate

Public Class Methods

params() click to toggle source
# File lib/ciphr/functions/zlib.rb, line 32
def self.params 
  [:input]
end
variants() click to toggle source
# File lib/ciphr/functions/zlib.rb, line 26
def self.variants
  [
    [['deflate'], {}]
  ]
end

Public Instance Methods

apply() click to toggle source
# File lib/ciphr/functions/zlib.rb, line 5
def apply
  input = @args[0]
  zstream = invert ? Zlib::Inflate.new : Zlib::Deflate.new
  Proc.new do
    chunk = input.read(256)
    if chunk
      if invert
        zstream.inflate(chunk)
      else
        zstream.deflate(chunk,Zlib::SYNC_FLUSH)
      end
    else
      begin
        #zstream.finish if invert
      ensure
        zstream.close
      end
    end
  end
end