yaz0 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/yaz0/yaz0.c DELETED
@@ -1,48 +0,0 @@
1
- #include "yaz0.h"
2
- #include <stdio.h>
3
-
4
- static VALUE compress(VALUE self, VALUE str)
5
- {
6
- Yaz0Buffer buffer;
7
- VALUE ret;
8
-
9
- if (TYPE(str) != T_STRING)
10
- {
11
- rb_raise(rb_eTypeError, "Expected a string");
12
- return Qnil;
13
- }
14
-
15
- yaz0BufferAlloc(&buffer, 16);
16
- yaz0Compress(&buffer, StringValuePtr(str), RSTRING_LEN(str));
17
- ret = rb_str_new(buffer.data, buffer.size);
18
- yaz0BufferFree(&buffer);
19
-
20
- return ret;
21
- }
22
-
23
- static VALUE decompress(VALUE self, VALUE str)
24
- {
25
- Yaz0Buffer buffer;
26
- VALUE ret;
27
-
28
- if (TYPE(str) != T_STRING)
29
- {
30
- rb_raise(rb_eTypeError, "Expected a string");
31
- return Qnil;
32
- }
33
-
34
- yaz0BufferAlloc(&buffer, 16);
35
- yaz0Decompress(&buffer, StringValuePtr(str), RSTRING_LEN(str));
36
- ret = rb_str_new(buffer.data, buffer.size);
37
- yaz0BufferFree(&buffer);
38
-
39
- return ret;
40
- }
41
-
42
- void Init_yaz0(void)
43
- {
44
- VALUE mod;
45
- mod = rb_define_module("Yaz0");
46
- rb_define_module_function(mod, "compress", &compress, 1);
47
- rb_define_module_function(mod, "decompress", &decompress, 1);
48
- }
data/ext/yaz0/yaz0.h DELETED
@@ -1,38 +0,0 @@
1
- #ifndef YAZ0_H
2
- #define YAZ0_H 1
3
-
4
- #include <stddef.h>
5
- #include "ruby.h"
6
-
7
- /*
8
- * Swap
9
- */
10
- inline static uint16_t swap16(uint16_t v)
11
- {
12
- return (v << 8) | (v >> 8);
13
- }
14
-
15
- inline static uint32_t swap32(uint32_t v)
16
- {
17
- return (v << 24) | ((v << 8) & 0x00ff0000) | ((v >> 8) & 0x0000ff00) | (v >> 24);
18
- }
19
-
20
- /*
21
- * Buffer
22
- */
23
-
24
- typedef struct
25
- {
26
- size_t size;
27
- size_t capacity;
28
- char *data;
29
- } Yaz0Buffer;
30
-
31
- void yaz0BufferAlloc(Yaz0Buffer *buf, size_t cap);
32
- void yaz0BufferFree(Yaz0Buffer *buf);
33
- void yaz0BufferWrite(Yaz0Buffer *buf, const void *data, size_t len);
34
-
35
- int yaz0Compress(Yaz0Buffer *dst, const char *data, size_t len);
36
- int yaz0Decompress(Yaz0Buffer *dst, const char *data, size_t len);
37
-
38
- #endif /* YAZ0_H */