Skip to content

Instantly share code, notes, and snippets.

@timothyklim
Created May 23, 2011 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothyklim/987001 to your computer and use it in GitHub Desktop.
Save timothyklim/987001 to your computer and use it in GitHub Desktop.
require 'zlib'
require 'lzoruby'
module GZIP
def self.compress string, level
z = Zlib::Deflate.new level
dst = z.deflate string, Zlib::FINISH
z.close
dst
end
def self.decompress string
zstream = Zlib::Inflate.new
buf = zstream.inflate string
zstream.finish
zstream.close
buf
end
end
class Zip
attr_reader :type
def initialize type
fail "Error" unless [:lzo, :gzip].include? type.downcase
instance_eval %{@type = #{type.to_s.upcase}}
end
def method_missing name, *args
@type.send name, *args
end
end
compressor = Zip.new :gzip
yeah = compressor.compress "Yeah", 1
puts yeah
puts compressor.decompress yeah
compressor = Zip.new :lzo
yeah = compressor.compress "Yeah", 1
puts yeah
puts compressor.decompress yeah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment