Module: CodeRay::GZip
- Defined in:
- lib/coderay/helpers/gzip.rb
Overview
A simplified interface to the gzip library zlib (from the Ruby Standard Library.)
Constant Summary collapse
- DEFAULT_GZIP_LEVEL =
The default zipping level. 7 zips good and fast.
7
Class Method Summary collapse
-
.gunzip(s) ⇒ Object
Unzips the given string
s. -
.gzip(s, level = DEFAULT_GZIP_LEVEL) ⇒ Object
Zips the given string
s.
Class Method Details
.gunzip(s) ⇒ Object
Unzips the given string s.
Example:
require 'gzip_simple'
print GZip.gunzip(File.read('adresses.gz'))
16 17 18 |
# File 'lib/coderay/helpers/gzip.rb', line 16 def GZip.gunzip s Zlib::Inflate.inflate s end |
.gzip(s, level = DEFAULT_GZIP_LEVEL) ⇒ Object
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
35 36 37 |
# File 'lib/coderay/helpers/gzip.rb', line 35 def GZip.gzip s, level = DEFAULT_GZIP_LEVEL Zlib::Deflate.new(level).deflate s, Zlib::FINISH end |