Module: Zopfli

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

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.deflate(*args) ⇒ Object



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
105
106
107
108
109
110
111
112
113
114
# File 'ext/zopfli.c', line 79

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;

#ifdef HAVE_RUBY_THREAD_H
    rb_thread_call_without_gvl(zopfli_deflate_no_gvl, (void *)&args, NULL, NULL);
#else
    zopfli_deflate_no_gvl((void *)&args);
#endif

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

    free(args.out);

    return out;
}