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