Module: Zopfli

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

Constant Summary collapse

VERSION =
"0.0.8"

Class Method Summary collapse

Class Method Details

.deflate(*args) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'ext/zopfli.c', line 73

static VALUE
zopfli_deflate(int argc, VALUE *argv, VALUE self)
{
    zopfli_deflate_args_t args;
    VALUE in, out, opts;

    ZopfliInitOptions(&args.options);

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

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

    StringValue(in);

    args.in = (unsigned char*)RSTRING_PTR(in);
    args.insize = RSTRING_LEN(in);

    args.out = NULL;
    args.outsize = 0;

    rb_thread_call_without_gvl(zopfli_deflate_no_gvl, (void *)&args, NULL, NULL);

    out = rb_str_new((const char*)args.out, args.outsize);

    free(args.out);

    return out;
}