Method: Zlib::Deflate#deflate

Defined in:
zlib.c

#deflate(*args) ⇒ Object

call-seq:

z.deflate(string, flush = Zlib::NO_FLUSH)                 -> String
z.deflate(string, flush = Zlib::NO_FLUSH) { |chunk| ... } -> nil

Inputs string into the deflate stream and returns the output from the stream. On calling this method, both the input and the output buffers of the stream are flushed. If string is nil, this method finishes the stream, just like Zlib::ZStream#finish.

If a block is given consecutive deflated chunks from the string are yielded to the block and nil is returned.

The flush parameter specifies the flush mode. The following constants may be used:

Zlib::NO_FLUSH

The default

Zlib::SYNC_FLUSH

Flushes the output to a byte boundary

Zlib::FULL_FLUSH

SYNC_FLUSH + resets the compression state

Zlib::FINISH

Pending input is processed, pending output is flushed.

See the constants for further description.



1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
# File 'zlib.c', line 1690

static VALUE
rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
{
    struct zstream *z = get_zstream(obj);
    VALUE src, flush;

    rb_scan_args(argc, argv, "11", &src, &flush);
    OBJ_INFECT(obj, src);
    do_deflate(z, src, ARG_FLUSH(flush));

    return zstream_detach_buffer(z);
}