deflate(...)
public
Compresses the given string. Valid values of level are
Zlib::NO_COMPRESSION, Zlib::BEST_SPEED,
Zlib::BEST_COMPRESSION, Zlib::DEFAULT_COMPRESSION, and an
integer from 0 to 9.
This method is almost equivalent to the following code:
def deflate(string, level)
z = Zlib::Deflate.new(level)
dst = z.deflate(string, Zlib::FINISH)
z.close
dst
end
TODO: what’s default value of level?
Show source
/*
* call-seq: Zlib::Deflate.deflate(string[, level])
*
* Compresses the given +string+. Valid values of level are
* <tt>Zlib::NO_COMPRESSION</tt>, <tt>Zlib::BEST_SPEED</tt>,
* <tt>Zlib::BEST_COMPRESSION</tt>, <tt>Zlib::DEFAULT_COMPRESSION</tt>, and an
* integer from 0 to 9.
*
* This method is almost equivalent to the following code:
*
* def deflate(string, level)
* z = Zlib::Deflate.new(level)
* dst = z.deflate(string, Zlib::FINISH)
* z.close
* dst
* end
*
* TODO: what's default value of +level+?
*
*/
static VALUE
rb_deflate_s_deflate(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
struct zstream z;
VALUE src, level, dst, args[2];
int err, lev;
rb_scan_args(argc, argv, "11", &src, &level);
lev = ARG_LEVEL(level);
StringValue(src);
zstream_init_deflate(&z);
err = deflateInit(&z.stream, lev);
if (err != Z_OK) {
raise_zlib_error(err, z.stream.msg);
}
ZSTREAM_READY(&z);
args[0] = (VALUE)&z;
args[1] = src;
dst = rb_ensure(deflate_run, (VALUE)args, zstream_end, (VALUE)&z);
OBJ_INFECT(dst, src);
return dst;
}