| Module | Zlib |
| In: |
lib/more/facets/zlib.rb
|
A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip.
Compresses a string using gzip.
# File lib/more/facets/zlib.rb, line 16
16: def self.compress(source)
17: output = StringIO.new
18: class << output
19: def close; rewind; end
20: end
21: gz = GzipWriter.new(output)
22: gz.write(source)
23: gz.close
24: output.string
25: end
Decompresses a gzipped string.
# File lib/more/facets/zlib.rb, line 11
11: def self.decompress(source)
12: GzipReader.new(StringIO.new(source)).read
13: end
Deflate a string.
# File lib/more/facets/zlib.rb, line 33
33: def self.deflate(string, level=DEFAULT_COMPRESSION)
34: Deflate.deflate(string, level)
35: end