Mercurial > hg > soundsoftware-site
annotate vendor/gems/coderay-1.0.0/lib/coderay/helpers/gzip.rb @ 1171:b4558bc5837f bug_505
Close obsolete branch bug_505
author | Chris Cannam |
---|---|
date | Fri, 03 Aug 2012 19:40:23 +0100 |
parents | cbb26bc654de |
children |
rev | line source |
---|---|
Chris@909 | 1 module CodeRay |
Chris@909 | 2 |
Chris@909 | 3 # A simplified interface to the gzip library +zlib+ (from the Ruby Standard Library.) |
Chris@909 | 4 module GZip |
Chris@909 | 5 |
Chris@909 | 6 require 'zlib' |
Chris@909 | 7 |
Chris@909 | 8 # The default zipping level. 7 zips good and fast. |
Chris@909 | 9 DEFAULT_GZIP_LEVEL = 7 |
Chris@909 | 10 |
Chris@909 | 11 # Unzips the given string +s+. |
Chris@909 | 12 # |
Chris@909 | 13 # Example: |
Chris@909 | 14 # require 'gzip_simple' |
Chris@909 | 15 # print GZip.gunzip(File.read('adresses.gz')) |
Chris@909 | 16 def GZip.gunzip s |
Chris@909 | 17 Zlib::Inflate.inflate s |
Chris@909 | 18 end |
Chris@909 | 19 |
Chris@909 | 20 # Zips the given string +s+. |
Chris@909 | 21 # |
Chris@909 | 22 # Example: |
Chris@909 | 23 # require 'gzip_simple' |
Chris@909 | 24 # File.open('adresses.gz', 'w') do |file |
Chris@909 | 25 # file.write GZip.gzip('Mum: 0123 456 789', 9) |
Chris@909 | 26 # end |
Chris@909 | 27 # |
Chris@909 | 28 # If you provide a +level+, you can control how strong |
Chris@909 | 29 # the string is compressed: |
Chris@909 | 30 # - 0: no compression, only convert to gzip format |
Chris@909 | 31 # - 1: compress fast |
Chris@909 | 32 # - 7: compress more, but still fast (default) |
Chris@909 | 33 # - 8: compress more, slower |
Chris@909 | 34 # - 9: compress best, very slow |
Chris@909 | 35 def GZip.gzip s, level = DEFAULT_GZIP_LEVEL |
Chris@909 | 36 Zlib::Deflate.new(level).deflate s, Zlib::FINISH |
Chris@909 | 37 end |
Chris@909 | 38 |
Chris@909 | 39 end |
Chris@909 | 40 |
Chris@909 | 41 end |