Class: Ciphr::Functions::ZLib::Deflate

Inherits:
InvertibleFunction show all
Defined in:
lib/ciphr/functions/zlib.rb

Instance Attribute Summary

Attributes inherited from InvertibleFunction

#invert

Attributes inherited from Function

#args, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from InvertibleFunction

invertable?

Methods inherited from Function

aligned, inherited, #initialize, invertable?, #prepend, #read

Constructor Details

This class inherits a constructor from Ciphr::Functions::Function

Class Method Details

.paramsObject



32
33
34
# File 'lib/ciphr/functions/zlib.rb', line 32

def self.params 
  [:input]
end

.variantsObject



26
27
28
29
30
# File 'lib/ciphr/functions/zlib.rb', line 26

def self.variants
  [
    [['deflate'], {}]
  ]
end

Instance Method Details

#applyObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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