deflate(p1, p2 = v2)
public
Compresses the given string. Valid values of level are
NO_COMPRESSION, BEST_SPEED, BEST_COMPRESSION,
DEFAULT_COMPRESSION, and an integer from 0 to 9 (the default is
6).
This method is almost equivalent to the following code:
def deflate(string, level)
z = Zlib::Deflate.new(level)
dst = z.deflate(string, Zlib::NO_FLUSH)
z.close
dst
end
See also Zlib.inflate
Show source
static VALUE
rb_deflate_s_deflate(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;
}