lzoruby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE.txt +339 -0
- data/README.txt +57 -0
- data/ext/compr1b.h +81 -0
- data/ext/compr1c.h +81 -0
- data/ext/config1.h +61 -0
- data/ext/config1a.h +196 -0
- data/ext/config1b.h +140 -0
- data/ext/config1c.h +145 -0
- data/ext/config1f.h +97 -0
- data/ext/config1x.h +118 -0
- data/ext/config1y.h +66 -0
- data/ext/config1z.h +65 -0
- data/ext/config2a.h +155 -0
- data/ext/extconf.rb +2 -0
- data/ext/lzo/lzo1.h +96 -0
- data/ext/lzo/lzo1a.h +96 -0
- data/ext/lzo/lzo1b.h +160 -0
- data/ext/lzo/lzo1c.h +160 -0
- data/ext/lzo/lzo1f.h +108 -0
- data/ext/lzo/lzo1x.h +177 -0
- data/ext/lzo/lzo1y.h +145 -0
- data/ext/lzo/lzo1z.h +150 -0
- data/ext/lzo/lzo2a.h +92 -0
- data/ext/lzo/lzo_asm.h +139 -0
- data/ext/lzo/lzoconf.h +417 -0
- data/ext/lzo/lzodefs.h +1807 -0
- data/ext/lzo/lzoutil.h +73 -0
- data/ext/lzo1.c +635 -0
- data/ext/lzo1_99.c +130 -0
- data/ext/lzo1_cm.ch +52 -0
- data/ext/lzo1_d.ch +155 -0
- data/ext/lzo1a.c +657 -0
- data/ext/lzo1a_99.c +130 -0
- data/ext/lzo1a_cm.ch +242 -0
- data/ext/lzo1a_cr.ch +128 -0
- data/ext/lzo1a_de.h +158 -0
- data/ext/lzo1b_1.c +46 -0
- data/ext/lzo1b_2.c +46 -0
- data/ext/lzo1b_3.c +46 -0
- data/ext/lzo1b_4.c +46 -0
- data/ext/lzo1b_5.c +46 -0
- data/ext/lzo1b_6.c +46 -0
- data/ext/lzo1b_7.c +46 -0
- data/ext/lzo1b_8.c +46 -0
- data/ext/lzo1b_9.c +46 -0
- data/ext/lzo1b_99.c +49 -0
- data/ext/lzo1b_9x.c +365 -0
- data/ext/lzo1b_c.ch +270 -0
- data/ext/lzo1b_cc.c +167 -0
- data/ext/lzo1b_cc.h +93 -0
- data/ext/lzo1b_cm.ch +294 -0
- data/ext/lzo1b_cr.ch +126 -0
- data/ext/lzo1b_d.ch +282 -0
- data/ext/lzo1b_d1.c +46 -0
- data/ext/lzo1b_d2.c +46 -0
- data/ext/lzo1b_de.h +344 -0
- data/ext/lzo1b_r.ch +117 -0
- data/ext/lzo1b_rr.c +43 -0
- data/ext/lzo1b_sm.ch +210 -0
- data/ext/lzo1b_tm.ch +99 -0
- data/ext/lzo1b_xx.c +98 -0
- data/ext/lzo1c_1.c +46 -0
- data/ext/lzo1c_2.c +46 -0
- data/ext/lzo1c_3.c +46 -0
- data/ext/lzo1c_4.c +46 -0
- data/ext/lzo1c_5.c +46 -0
- data/ext/lzo1c_6.c +46 -0
- data/ext/lzo1c_7.c +46 -0
- data/ext/lzo1c_8.c +46 -0
- data/ext/lzo1c_9.c +46 -0
- data/ext/lzo1c_99.c +49 -0
- data/ext/lzo1c_9x.c +379 -0
- data/ext/lzo1c_cc.c +167 -0
- data/ext/lzo1c_cc.h +93 -0
- data/ext/lzo1c_d1.c +46 -0
- data/ext/lzo1c_d2.c +46 -0
- data/ext/lzo1c_rr.c +43 -0
- data/ext/lzo1c_xx.c +98 -0
- data/ext/lzo1f_1.c +312 -0
- data/ext/lzo1f_9x.c +345 -0
- data/ext/lzo1f_d.ch +223 -0
- data/ext/lzo1f_d1.c +46 -0
- data/ext/lzo1f_d2.c +46 -0
- data/ext/lzo1x_1.c +50 -0
- data/ext/lzo1x_1k.c +50 -0
- data/ext/lzo1x_1l.c +50 -0
- data/ext/lzo1x_1o.c +50 -0
- data/ext/lzo1x_9x.c +881 -0
- data/ext/lzo1x_c.ch +351 -0
- data/ext/lzo1x_d.ch +466 -0
- data/ext/lzo1x_d1.c +46 -0
- data/ext/lzo1x_d2.c +46 -0
- data/ext/lzo1x_d3.c +108 -0
- data/ext/lzo1x_o.c +45 -0
- data/ext/lzo1x_oo.ch +366 -0
- data/ext/lzo1y_1.c +50 -0
- data/ext/lzo1y_9x.c +42 -0
- data/ext/lzo1y_d1.c +46 -0
- data/ext/lzo1y_d2.c +46 -0
- data/ext/lzo1y_d3.c +45 -0
- data/ext/lzo1y_o.c +45 -0
- data/ext/lzo1z_9x.c +42 -0
- data/ext/lzo1z_d1.c +46 -0
- data/ext/lzo1z_d2.c +46 -0
- data/ext/lzo1z_d3.c +45 -0
- data/ext/lzo2a_9x.c +357 -0
- data/ext/lzo2a_d.ch +188 -0
- data/ext/lzo2a_d1.c +46 -0
- data/ext/lzo2a_d2.c +46 -0
- data/ext/lzo_conf.h +323 -0
- data/ext/lzo_crc.c +167 -0
- data/ext/lzo_dict.h +316 -0
- data/ext/lzo_dll.ch +64 -0
- data/ext/lzo_init.c +176 -0
- data/ext/lzo_mchw.ch +242 -0
- data/ext/lzo_ptr.c +92 -0
- data/ext/lzo_ptr.h +154 -0
- data/ext/lzo_str.c +71 -0
- data/ext/lzo_swd.ch +707 -0
- data/ext/lzo_util.c +165 -0
- data/ext/lzoruby.c +149 -0
- data/ext/miniacc.h +6553 -0
- data/ext/stats1a.h +137 -0
- data/ext/stats1b.h +142 -0
- data/ext/stats1c.h +61 -0
- metadata +180 -0
data/ext/lzo_util.c
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/* lzo_util.c -- utilities for the LZO library
|
|
2
|
+
|
|
3
|
+
This file is part of the LZO real-time data compression library.
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
|
6
|
+
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
|
7
|
+
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
|
8
|
+
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
|
9
|
+
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
|
10
|
+
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
|
11
|
+
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
|
12
|
+
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
|
13
|
+
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
|
14
|
+
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
|
15
|
+
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
|
16
|
+
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
|
17
|
+
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
|
18
|
+
All Rights Reserved.
|
|
19
|
+
|
|
20
|
+
The LZO library is free software; you can redistribute it and/or
|
|
21
|
+
modify it under the terms of the GNU General Public License as
|
|
22
|
+
published by the Free Software Foundation; either version 2 of
|
|
23
|
+
the License, or (at your option) any later version.
|
|
24
|
+
|
|
25
|
+
The LZO library is distributed in the hope that it will be useful,
|
|
26
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
27
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
28
|
+
GNU General Public License for more details.
|
|
29
|
+
|
|
30
|
+
You should have received a copy of the GNU General Public License
|
|
31
|
+
along with the LZO library; see the file COPYING.
|
|
32
|
+
If not, write to the Free Software Foundation, Inc.,
|
|
33
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
34
|
+
|
|
35
|
+
Markus F.X.J. Oberhumer
|
|
36
|
+
<markus@oberhumer.com>
|
|
37
|
+
http://www.oberhumer.com/opensource/lzo/
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
#include "lzo_conf.h"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/***********************************************************************
|
|
45
|
+
//
|
|
46
|
+
************************************************************************/
|
|
47
|
+
|
|
48
|
+
/* If you use the LZO library in a product, I would appreciate that you
|
|
49
|
+
* keep this copyright string in the executable of your product.
|
|
50
|
+
.*/
|
|
51
|
+
|
|
52
|
+
const char __lzo_copyright[] =
|
|
53
|
+
#if !defined(__LZO_IN_MINLZO)
|
|
54
|
+
/* save space as some people want a really small decompressor */
|
|
55
|
+
LZO_VERSION_STRING;
|
|
56
|
+
#else
|
|
57
|
+
"\r\n\n"
|
|
58
|
+
"LZO data compression library.\n"
|
|
59
|
+
"$Copyright: LZO (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Markus Franz Xaver Johannes Oberhumer\n"
|
|
60
|
+
"<markus@oberhumer.com>\n"
|
|
61
|
+
"http://www.oberhumer.com $\n\n"
|
|
62
|
+
"$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n"
|
|
63
|
+
"$Built: " __DATE__ " " __TIME__ " $\n"
|
|
64
|
+
"$Info: " LZO_INFO_STRING " $\n";
|
|
65
|
+
#endif
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
LZO_PUBLIC(const lzo_bytep)
|
|
69
|
+
lzo_copyright(void)
|
|
70
|
+
{
|
|
71
|
+
#if (LZO_OS_DOS16 && LZO_CC_TURBOC)
|
|
72
|
+
return (lzo_voidp) __lzo_copyright;
|
|
73
|
+
#else
|
|
74
|
+
return (const lzo_bytep) __lzo_copyright;
|
|
75
|
+
#endif
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
LZO_PUBLIC(unsigned)
|
|
79
|
+
lzo_version(void)
|
|
80
|
+
{
|
|
81
|
+
return LZO_VERSION;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
LZO_PUBLIC(const char *)
|
|
85
|
+
lzo_version_string(void)
|
|
86
|
+
{
|
|
87
|
+
return LZO_VERSION_STRING;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
LZO_PUBLIC(const char *)
|
|
91
|
+
lzo_version_date(void)
|
|
92
|
+
{
|
|
93
|
+
return LZO_VERSION_DATE;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
LZO_PUBLIC(const lzo_charp)
|
|
97
|
+
_lzo_version_string(void)
|
|
98
|
+
{
|
|
99
|
+
return LZO_VERSION_STRING;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
LZO_PUBLIC(const lzo_charp)
|
|
103
|
+
_lzo_version_date(void)
|
|
104
|
+
{
|
|
105
|
+
return LZO_VERSION_DATE;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/***********************************************************************
|
|
110
|
+
// adler32 checksum
|
|
111
|
+
// adapted from free code by Mark Adler <madler@alumni.caltech.edu>
|
|
112
|
+
// see http://www.zlib.org/
|
|
113
|
+
************************************************************************/
|
|
114
|
+
|
|
115
|
+
#define LZO_BASE 65521u /* largest prime smaller than 65536 */
|
|
116
|
+
#define LZO_NMAX 5552
|
|
117
|
+
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
|
118
|
+
|
|
119
|
+
#define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1
|
|
120
|
+
#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1);
|
|
121
|
+
#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2);
|
|
122
|
+
#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4);
|
|
123
|
+
#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8);
|
|
124
|
+
|
|
125
|
+
LZO_PUBLIC(lzo_uint32)
|
|
126
|
+
lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len)
|
|
127
|
+
{
|
|
128
|
+
lzo_uint32 s1 = adler & 0xffff;
|
|
129
|
+
lzo_uint32 s2 = (adler >> 16) & 0xffff;
|
|
130
|
+
unsigned k;
|
|
131
|
+
|
|
132
|
+
if (buf == NULL)
|
|
133
|
+
return 1;
|
|
134
|
+
|
|
135
|
+
while (len > 0)
|
|
136
|
+
{
|
|
137
|
+
k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX;
|
|
138
|
+
len -= k;
|
|
139
|
+
if (k >= 16) do
|
|
140
|
+
{
|
|
141
|
+
LZO_DO16(buf,0);
|
|
142
|
+
buf += 16;
|
|
143
|
+
k -= 16;
|
|
144
|
+
} while (k >= 16);
|
|
145
|
+
if (k != 0) do
|
|
146
|
+
{
|
|
147
|
+
s1 += *buf++;
|
|
148
|
+
s2 += s1;
|
|
149
|
+
} while (--k > 0);
|
|
150
|
+
s1 %= LZO_BASE;
|
|
151
|
+
s2 %= LZO_BASE;
|
|
152
|
+
}
|
|
153
|
+
return (s2 << 16) | s1;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#undef LZO_DO1
|
|
157
|
+
#undef LZO_DO2
|
|
158
|
+
#undef LZO_DO4
|
|
159
|
+
#undef LZO_DO8
|
|
160
|
+
#undef LZO_DO16
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
vi:ts=4:et
|
|
165
|
+
*/
|
data/ext/lzoruby.c
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Ruby bindings for LZO.
|
|
3
|
+
LZO is a portable lossless data compression library written in ANSI C.
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2008 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifdef _WIN32
|
|
9
|
+
__declspec(dllexport) void Init_lzoruby(void);
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "lzo/lzoconf.h"
|
|
13
|
+
#include "lzo/lzo1x.h"
|
|
14
|
+
#include "ruby.h"
|
|
15
|
+
|
|
16
|
+
#ifndef RSTRING_PTR
|
|
17
|
+
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#ifndef RSTRING_LEN
|
|
21
|
+
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#define VERSION "0.1.0"
|
|
25
|
+
|
|
26
|
+
static VALUE LZO;
|
|
27
|
+
static VALUE LZO_Error;
|
|
28
|
+
|
|
29
|
+
/* */
|
|
30
|
+
static VALUE lzoruby_compress(int argc, const VALUE *argv, VALUE self) {
|
|
31
|
+
const lzo_bytep in;
|
|
32
|
+
lzo_bytep out;
|
|
33
|
+
lzo_voidp wrkmem = NULL;
|
|
34
|
+
lzo_uint in_len;
|
|
35
|
+
lzo_uint out_len;
|
|
36
|
+
lzo_uint new_len;
|
|
37
|
+
VALUE v_in, v_out, v_level;
|
|
38
|
+
int level, err;
|
|
39
|
+
|
|
40
|
+
rb_scan_args(argc, argv, "11", &v_in, &v_level);
|
|
41
|
+
Check_Type(v_in, T_STRING);
|
|
42
|
+
level = NIL_P(v_level) ? 1 : NUM2INT(v_level);
|
|
43
|
+
|
|
44
|
+
in = RSTRING_PTR(v_in);
|
|
45
|
+
in_len = RSTRING_LEN(v_in);
|
|
46
|
+
out_len = in_len + in_len / 64 + 16 + 3;
|
|
47
|
+
out = xmalloc(5 + out_len);
|
|
48
|
+
new_len = out_len;
|
|
49
|
+
wrkmem = xmalloc((level == 1) ? LZO1X_1_MEM_COMPRESS : LZO1X_999_MEM_COMPRESS);
|
|
50
|
+
|
|
51
|
+
if (level == 1) {
|
|
52
|
+
out[0] = 0xf0;
|
|
53
|
+
err = lzo1x_1_compress(in, in_len, out + 5, &new_len, wrkmem);
|
|
54
|
+
} else {
|
|
55
|
+
out[0] = 0xf1;
|
|
56
|
+
err = lzo1x_999_compress(in, in_len, out + 5, &new_len, wrkmem);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
xfree(wrkmem);
|
|
60
|
+
|
|
61
|
+
if (err != LZO_E_OK || new_len > out_len) {
|
|
62
|
+
xfree(out);
|
|
63
|
+
rb_raise(LZO_Error, "Error %d while compressing data", err);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
out[1] = (unsigned char) ((in_len >> 24) & 0xff);
|
|
67
|
+
out[2] = (unsigned char) ((in_len >> 16) & 0xff);
|
|
68
|
+
out[3] = (unsigned char) ((in_len >> 8) & 0xff);
|
|
69
|
+
out[4] = (unsigned char) ((in_len >> 0) & 0xff);
|
|
70
|
+
v_out = rb_str_new(out, 5 + new_len);
|
|
71
|
+
xfree(out);
|
|
72
|
+
|
|
73
|
+
return v_out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* */
|
|
77
|
+
static VALUE lzoruby_decompress(VALUE self, VALUE v_in) {
|
|
78
|
+
lzo_bytep in;
|
|
79
|
+
lzo_bytep out;
|
|
80
|
+
lzo_uint in_len;
|
|
81
|
+
lzo_uint out_len;
|
|
82
|
+
lzo_uint new_len;
|
|
83
|
+
VALUE v_out;
|
|
84
|
+
int err;
|
|
85
|
+
|
|
86
|
+
Check_Type(v_in, T_STRING);
|
|
87
|
+
|
|
88
|
+
in = RSTRING_PTR(v_in);
|
|
89
|
+
in_len = RSTRING_LEN(v_in);
|
|
90
|
+
|
|
91
|
+
if (((int) in_len) < 5 + 3 || in[0] < 0xf0 || in[0] > 0xf1) {
|
|
92
|
+
rb_raise(LZO_Error, "Header error - invalid compressed data");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
in_len -= 5;
|
|
96
|
+
out_len = (in[1] << 24) | (in[2] << 16) | (in[3] << 8) | in[4];
|
|
97
|
+
|
|
98
|
+
if (((int) out_len) < 0 || in_len > out_len + out_len / 64 + 16 + 3) {
|
|
99
|
+
rb_raise(LZO_Error, "Header error - invalid compressed data");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
out = xmalloc(out_len);
|
|
103
|
+
new_len = out_len;
|
|
104
|
+
|
|
105
|
+
err = lzo1x_decompress_safe(in + 5, in_len, out, &new_len, NULL);
|
|
106
|
+
|
|
107
|
+
if (err != LZO_E_OK || new_len != out_len) {
|
|
108
|
+
xfree(out);
|
|
109
|
+
rb_raise(LZO_Error, "Compressed data violation %d", err);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
v_out = rb_str_new(out, new_len);
|
|
113
|
+
xfree(out);
|
|
114
|
+
|
|
115
|
+
return v_out;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* */
|
|
119
|
+
static VALUE lzoruby_adler32(VALUE self, VALUE v_adler, VALUE v_buf) {
|
|
120
|
+
lzo_uint32 adler;
|
|
121
|
+
lzo_bytep buf;
|
|
122
|
+
lzo_uint len;
|
|
123
|
+
|
|
124
|
+
Check_Type(v_adler, T_FIXNUM);
|
|
125
|
+
Check_Type(v_buf, T_STRING);
|
|
126
|
+
adler = FIX2LONG(v_adler);
|
|
127
|
+
buf = RSTRING_PTR(v_buf);
|
|
128
|
+
len = RSTRING_LEN(v_buf);
|
|
129
|
+
|
|
130
|
+
adler = lzo_adler32(adler, buf, len);
|
|
131
|
+
|
|
132
|
+
return LONG2FIX(adler);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
void Init_lzoruby() {
|
|
136
|
+
if (lzo_init() != LZO_E_OK) {
|
|
137
|
+
rb_warn("internal error - lzo_init() failed !!!");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
LZO = rb_define_module("LZO");
|
|
142
|
+
LZO_Error = rb_define_class_under(LZO, "Error", rb_eStandardError);
|
|
143
|
+
|
|
144
|
+
rb_define_const(LZO, "VERSION", rb_str_new2(VERSION));
|
|
145
|
+
rb_define_const(LZO, "LZO_VERSION", rb_str_new2(lzo_version_string()));
|
|
146
|
+
rb_define_module_function(LZO, "compress", lzoruby_compress, -1);
|
|
147
|
+
rb_define_module_function(LZO, "decompress", lzoruby_decompress, 1);
|
|
148
|
+
rb_define_module_function(LZO, "adler32", lzoruby_adler32, 2);
|
|
149
|
+
}
|