To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / ce / ce0ddfb0e373d214b7494e9b42aebe1b7d26bc67.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (1.04 KB)

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