Module: Zopfli

Defined in:
lib/zopfli/version.rb,
ext/zopfli.c

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.deflate(*args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'ext/zopfli.c', line 53

VALUE
zopfli_deflate(int argc, VALUE *argv, VALUE self)
{
    VALUE   in, out, opts;
    ZopfliOptions options;
    ZopfliFormat   format;
    unsigned char    *tmp = NULL;
    size_t        tmpsize = 0;

    ZopfliInitOptions(&options);

    rb_scan_args(argc, argv, "11", &in, &opts);

    if (!NIL_P(opts)) {
        format = zopfli_deflate_parse_options(&options, opts);
    } else {
        format = DEFAULT_FORMAT;
    }

    StringValue(in);

    ZopfliCompress(&options,
                   format,
                   RSTRING_PTR(in), RSTRING_LEN(in),
                   &tmp, &tmpsize);

    out = rb_str_new(tmp, tmpsize);

    free(tmp);

    return out;
}