Module: Snappy

Defined in:
lib/snappy/shim.rb,
lib/snappy/hadoop.rb,
lib/snappy/reader.rb,
lib/snappy/writer.rb,
lib/snappy/version.rb,
lib/snappy/hadoop/reader.rb,
lib/snappy/hadoop/writer.rb,
ext/api.c

Defined Under Namespace

Modules: Hadoop Classes: Error, Reader, Writer

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.deflate(*args) ⇒ Object



19
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
# File 'ext/api.c', line 19

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) {
        return snappy_raise(result);
    }

    rb_str_resize(dst, output_length);
    return dst;
}

.inflate(*args) ⇒ Object



47
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
# File 'ext/api.c', line 47

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);
    }

    rb_str_resize(dst, output_length);
    return dst;
}

.valid?(str) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'ext/api.c', line 78

static VALUE
snappy_valid_p(VALUE self, VALUE str)
{
    snappy_status result;

    StringValue(str);
    result = snappy_validate_compressed_buffer(RSTRING_PTR(str), RSTRING_LEN(str));
    if (result == SNAPPY_OK) {
        return Qtrue;
    } else {
        return Qfalse;
    }
}

Instance Method Details

#b(str) ⇒ Object



11
12
13
# File 'lib/snappy/shim.rb', line 11

def b(str)
  str
end

#set_encoding(io) ⇒ Object



7
8
9
# File 'lib/snappy/shim.rb', line 7

def set_encoding(io)
  io
end