Class: Bzip3::BlockProcessor

Inherits:
Object
  • Object
show all
Defined in:
ext/extbzip3.c

Instance Method Summary collapse

Constructor Details

#initializeObject

Instance Method Details

#blocksizeObject



136
137
138
139
140
# File 'ext/extbzip3.c', line 136

static VALUE
block_processor_blocksize(VALUE self)
{
    return SIZET2NUM(get_block_processor(self)->blocksize);
}

#decode(src, dest, originalsize) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'ext/extbzip3.c', line 142

static VALUE
block_processor_decode(VALUE self, VALUE src, VALUE dest, VALUE originalsize)
{
    rb_check_type(src, RUBY_T_STRING);
    rb_check_type(dest, RUBY_T_STRING);

    struct block_processor *p = get_block_processor(self);

    size_t origsize = NUM2SIZET(originalsize);
    if (origsize > (size_t)p->blocksize) {
        rb_raise(rb_eRuntimeError, "originalsize too big - %" PRIsVALUE, originalsize);
    }

    size_t srclen = RSTRING_LEN(src);
    size_t destcapa = bz3_bound((uint32_t)origsize);
    rb_str_modify(dest);
    rb_str_set_len(dest, 0);
    rb_str_modify_expand(dest, destcapa);

    memmove(RSTRING_PTR(dest), RSTRING_PTR(src), srclen);
    int32_t ret = aux_bz3_decode_block_nogvl(p->bzip3, RSTRING_PTR(dest), srclen, NUM2UINT(originalsize));
    extbzip3_check_error(ret);

    rb_str_set_len(dest, ret);

    return dest;
}

#encode(src, dest) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'ext/extbzip3.c', line 170

static VALUE
block_processor_encode(VALUE self, VALUE src, VALUE dest)
{
    rb_check_type(src, RUBY_T_STRING);
    rb_check_type(dest, RUBY_T_STRING);

    struct block_processor *p = get_block_processor(self);

    size_t srclen = RSTRING_LEN(src);
    if (srclen > p->blocksize) {
        rb_raise(rb_eRuntimeError, "src too big - #<%" PRIsVALUE ":0x%" PRIxVALUE ">", rb_class_of(src), src);
    }

    size_t destcapa = bz3_bound((uint32_t)srclen);
    rb_str_modify(dest);
    rb_str_set_len(dest, 0);
    rb_str_modify_expand(dest, (uint32_t)destcapa);

    memmove(RSTRING_PTR(dest), RSTRING_PTR(src), srclen);
    int32_t ret = aux_bz3_encode_block_nogvl(p->bzip3, RSTRING_PTR(dest), (int32_t)srclen);
    extbzip3_check_error(ret);

    rb_str_set_len(dest, ret);

    return dest;
}