Flowdock
new(p1 = v1, p2 = v2, p3 = v3, p4 = v4) public

Arguments

level

An Integer compression level between BEST_SPEED and BEST_COMPRESSION

windowBits

An Integer for the windowBits size. Should be in the range 8..15, larger values of this parameter result in better at the expense of memory usage.

memlevel

Specifies how much memory should be allocated for the internal compression state. Between DEF_MEM_LEVEL and MAX_MEM_LEVEL

strategy

A parameter to tune the compression algorithm. Use the DEFAULT_STRATEGY for normal data, FILTERED for data produced by a filter (or predictor), HUFFMAN_ONLY to force Huffman encoding only (no string match).

Description

Creates a new deflate stream for compression. See zlib.h for details of each argument. If an argument is nil, the default value of that argument is used.

examples

basic

f = File.new("compressed.file","w+")
#=> #<File:compressed.file>
f << Zlib::Deflate.new().deflate(File.read("big.file"))
#=> #<File:compressed.file>
f.close
#=> nil

a little more robust

compressed_file = File.open("compressed.file", "w+")
#=> #<File:compressed.file>
zd = Zlib::Deflate.new(Zlib::BEST_COMPRESSION, 15, Zlib::MAX_MEM_LEVEL, Zlib::HUFFMAN_ONLY)
#=> #<Zlib::Deflate:0x000000008610a0>
compressed_file << zd.deflate(File.read("big.file"))
#=> "\xD4z\xC6\xDE\b\xA1K\x1Ej\x8A ..."
compressed_file.close
#=> nil
zd.close
#=> nil

(while this example will work, for best optimization the flags need to be reviewed for your specific function)

Show source
Register or log in to add new notes.