diff options
author | murphy <murphy@rubychan.de> | 2010-06-29 06:56:40 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2010-06-29 06:56:40 +0000 |
commit | 57b35c22e258a8159532f92780f9ccc89a722bbd (patch) | |
tree | 7f3d4a4fbd16ff64bb45f833f1cf0cfc846f4582 /lib/coderay/helpers/gzip.rb | |
parent | 5d9e70269c0dfd328e0812913a2653a764ab6b19 (diff) | |
download | coderay-57b35c22e258a8159532f92780f9ccc89a722bbd.tar.gz |
Cleaned up GZip helper library (moved into CodeRay namespace, removed String extensions), improved FileType error message for ambiguous arguments.
Diffstat (limited to 'lib/coderay/helpers/gzip.rb')
-rw-r--r-- | lib/coderay/helpers/gzip.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/coderay/helpers/gzip.rb b/lib/coderay/helpers/gzip.rb new file mode 100644 index 0000000..43f1000 --- /dev/null +++ b/lib/coderay/helpers/gzip.rb @@ -0,0 +1,51 @@ +module CodeRay + +# =GZip Simple +# +# A simplified interface to the gzip library +zlib+ (from the Ruby Standard Library.) +# +# Author: murphy (mail to murphy rubychan de) +# +# Version: 0.2 (2005.may.28) +# +# ==Documentation +# +# See +GZip+ module and the +String+ extensions. +# +module GZip + + require 'zlib' + + # The default zipping level. 7 zips good and fast. + DEFAULT_GZIP_LEVEL = 7 + + # Unzips the given string +s+. + # + # Example: + # require 'gzip_simple' + # print GZip.gunzip(File.read('adresses.gz')) + def GZip.gunzip s + Zlib::Inflate.inflate s + end + + # Zips the given string +s+. + # + # Example: + # require 'gzip_simple' + # File.open('adresses.gz', 'w') do |file + # file.write GZip.gzip('Mum: 0123 456 789', 9) + # end + # + # If you provide a +level+, you can control how strong + # the string is compressed: + # - 0: no compression, only convert to gzip format + # - 1: compress fast + # - 7: compress more, but still fast (default) + # - 8: compress more, slower + # - 9: compress best, very slow + def GZip.gzip s, level = DEFAULT_GZIP_LEVEL + Zlib::Deflate.new(level).deflate s, Zlib::FINISH + end +end + +end |