Class: ActiveTools::CoreExtension::Kabuki::Zip

Inherits:
Object
  • Object
show all
Defined in:
lib/active_tools/core_extension/kabuki/zip.rb

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Zip

Returns a new instance of Zip.



6
7
8
# File 'lib/active_tools/core_extension/kabuki/zip.rb', line 6

def initialize(string)
  @string = string
end

Instance Method Details

#compress(level = 3) ⇒ Object



10
11
12
13
14
15
# File 'lib/active_tools/core_extension/kabuki/zip.rb', line 10

def compress(level=3)
  z = Zlib::Deflate.new(level)
  dst = z.deflate(@string, Zlib::FINISH)
  z.close
  dst
end

#decompressObject



17
18
19
20
21
22
23
# File 'lib/active_tools/core_extension/kabuki/zip.rb', line 17

def decompress
  zstream = Zlib::Inflate.new
  buf = zstream.inflate(@string)
  zstream.finish
  zstream.close
  buf
end