Module: Snappy
- Defined in:
- lib/snappy/reader.rb,
lib/snappy/writer.rb,
lib/snappy/version.rb,
ext/api.c
Defined Under Namespace
Classes: Error, Reader, Writer
Constant Summary collapse
- VERSION =
"0.0.10"
Class Method Summary collapse
Class Method Details
.deflate(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'ext/api.c', line 20
static VALUE
snappy_deflate(int argc, VALUE *argv, VALUE self)
{
VALUE src, dst;
size_t output_length;
snappy_status result;
rb_scan_args(argc, argv, "11", &src, &dst);
StringValue(src);
output_length = snappy_max_compressed_length(RSTRING_LEN(src));
if (NIL_P(dst)) {
dst = rb_str_new(NULL, output_length);
} else {
StringValue(dst);
rb_str_resize(dst, output_length);
}
result = snappy_compress(RSTRING_PTR(src), RSTRING_LEN(src), RSTRING_PTR(dst), &output_length);
if (result == SNAPPY_OK) {
rb_str_resize(dst, output_length);
return dst;
} else {
return snappy_raise(result);
}
}
|
.inflate(*args) ⇒ Object
48 49 50 51 52 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 |
# File 'ext/api.c', line 48
static VALUE
snappy_inflate(int argc, VALUE *argv, VALUE self)
{
VALUE src, dst;
size_t output_length;
snappy_status result;
rb_scan_args(argc, argv, "11", &src, &dst);
StringValue(src);
result = snappy_uncompressed_length(RSTRING_PTR(src), RSTRING_LEN(src), &output_length);
if (result != SNAPPY_OK) {
return snappy_raise(result);
}
if (NIL_P(dst)) {
dst = rb_str_new(NULL, output_length);
} else {
StringValue(dst);
rb_str_resize(dst, output_length);
}
result = snappy_uncompress(RSTRING_PTR(src), RSTRING_LEN(src), RSTRING_PTR(dst), &output_length);
if (result != SNAPPY_OK) {
return snappy_raise(result);
}
StringValue(dst);
rb_str_resize(dst, output_length);
return dst;
}
|