Created
May 23, 2011 16:31
-
-
Save timothyklim/987001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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