Class: ZstdNative::CCtx

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

Instance Method Summary collapse

Instance Method Details

#compress(data, level_val) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'ext/zstd_native/zstd_native.c', line 148

static VALUE cctx_compress(VALUE self, VALUE data, VALUE level_val) {
    Check_Type(data, T_STRING);
    int level = NUM2INT(level_val);

    ZSTD_CCtx *ctx;
    TypedData_Get_Struct(self, ZSTD_CCtx, &cctx_type, ctx);

    const char *src = RSTRING_PTR(data);
    size_t src_size = RSTRING_LEN(data);

    size_t dst_capacity = ZSTD_compressBound(src_size);
    VALUE result = rb_str_buf_new(dst_capacity);
    char *dst = RSTRING_PTR(result);

    size_t compressed_size = ZSTD_compressCCtx(ctx, dst, dst_capacity, src, src_size, level);
    check_zstd_error(compressed_size, "CCtx compression failed");

    rb_str_set_len(result, compressed_size);
    return result;
}

#load_dictionary(dict) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'ext/zstd_native/zstd_native.c', line 178

static VALUE cctx_load_dictionary(VALUE self, VALUE dict) {
    Check_Type(dict, T_STRING);

    ZSTD_CCtx *ctx;
    TypedData_Get_Struct(self, ZSTD_CCtx, &cctx_type, ctx);

    const char *dict_data = RSTRING_PTR(dict);
    size_t dict_size = RSTRING_LEN(dict);

    size_t result = ZSTD_CCtx_loadDictionary(ctx, dict_data, dict_size);
    check_zstd_error(result, "Failed to load dictionary");
    return Qnil;
}

#ref_cdict(cdict_val) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
# File 'ext/zstd_native/zstd_native.c', line 192

static VALUE cctx_ref_cdict(VALUE self, VALUE cdict_val) {
    ZSTD_CCtx *ctx;
    TypedData_Get_Struct(self, ZSTD_CCtx, &cctx_type, ctx);

    ZSTD_CDict *cdict;
    TypedData_Get_Struct(cdict_val, ZSTD_CDict, &cdict_type, cdict);

    size_t result = ZSTD_CCtx_refCDict(ctx, cdict);
    check_zstd_error(result, "Failed to reference CDict");
    return Qnil;
}

#ref_prefix(prefix) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'ext/zstd_native/zstd_native.c', line 204

static VALUE cctx_ref_prefix(VALUE self, VALUE prefix) {
    Check_Type(prefix, T_STRING);

    ZSTD_CCtx *ctx;
    TypedData_Get_Struct(self, ZSTD_CCtx, &cctx_type, ctx);

    const char *prefix_data = RSTRING_PTR(prefix);
    size_t prefix_size = RSTRING_LEN(prefix);

    size_t result = ZSTD_CCtx_refPrefix(ctx, prefix_data, prefix_size);
    check_zstd_error(result, "Failed to reference prefix");
    return Qnil;
}

#resetObject



169
170
171
172
173
174
175
176
# File 'ext/zstd_native/zstd_native.c', line 169

static VALUE cctx_reset(VALUE self) {
    ZSTD_CCtx *ctx;
    TypedData_Get_Struct(self, ZSTD_CCtx, &cctx_type, ctx);

    size_t result = ZSTD_CCtx_reset(ctx, ZSTD_reset_session_only);
    check_zstd_error(result, "CCtx reset failed");
    return Qnil;
}

#sizeofObject



218
219
220
221
222
# File 'ext/zstd_native/zstd_native.c', line 218

static VALUE cctx_sizeof(VALUE self) {
    ZSTD_CCtx *ctx;
    TypedData_Get_Struct(self, ZSTD_CCtx, &cctx_type, ctx);
    return SIZET2NUM(ZSTD_sizeof_CCtx(ctx));
}