extlzham 0.0.1.PROTOTYPE

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +27 -0
  3. data/README.md +21 -0
  4. data/Rakefile +143 -0
  5. data/contrib/lzham/LICENSE +22 -0
  6. data/contrib/lzham/README.md +209 -0
  7. data/contrib/lzham/include/lzham.h +781 -0
  8. data/contrib/lzham/lzhamcomp/lzham_comp.h +38 -0
  9. data/contrib/lzham/lzhamcomp/lzham_lzbase.cpp +244 -0
  10. data/contrib/lzham/lzhamcomp/lzham_lzbase.h +45 -0
  11. data/contrib/lzham/lzhamcomp/lzham_lzcomp.cpp +608 -0
  12. data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.cpp +1966 -0
  13. data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.h +472 -0
  14. data/contrib/lzham/lzhamcomp/lzham_lzcomp_state.cpp +1413 -0
  15. data/contrib/lzham/lzhamcomp/lzham_match_accel.cpp +562 -0
  16. data/contrib/lzham/lzhamcomp/lzham_match_accel.h +146 -0
  17. data/contrib/lzham/lzhamcomp/lzham_null_threading.h +97 -0
  18. data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.cpp +229 -0
  19. data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.h +520 -0
  20. data/contrib/lzham/lzhamcomp/lzham_threading.h +12 -0
  21. data/contrib/lzham/lzhamcomp/lzham_win32_threading.cpp +220 -0
  22. data/contrib/lzham/lzhamcomp/lzham_win32_threading.h +368 -0
  23. data/contrib/lzham/lzhamdecomp/lzham_assert.cpp +66 -0
  24. data/contrib/lzham/lzhamdecomp/lzham_assert.h +40 -0
  25. data/contrib/lzham/lzhamdecomp/lzham_checksum.cpp +73 -0
  26. data/contrib/lzham/lzhamdecomp/lzham_checksum.h +13 -0
  27. data/contrib/lzham/lzhamdecomp/lzham_config.h +23 -0
  28. data/contrib/lzham/lzhamdecomp/lzham_core.h +264 -0
  29. data/contrib/lzham/lzhamdecomp/lzham_decomp.h +37 -0
  30. data/contrib/lzham/lzhamdecomp/lzham_helpers.h +54 -0
  31. data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.cpp +262 -0
  32. data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.h +14 -0
  33. data/contrib/lzham/lzhamdecomp/lzham_lzdecomp.cpp +1527 -0
  34. data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.cpp +131 -0
  35. data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.h +89 -0
  36. data/contrib/lzham/lzhamdecomp/lzham_math.h +142 -0
  37. data/contrib/lzham/lzhamdecomp/lzham_mem.cpp +284 -0
  38. data/contrib/lzham/lzhamdecomp/lzham_mem.h +112 -0
  39. data/contrib/lzham/lzhamdecomp/lzham_platform.cpp +157 -0
  40. data/contrib/lzham/lzhamdecomp/lzham_platform.h +284 -0
  41. data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.cpp +351 -0
  42. data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.h +146 -0
  43. data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.cpp +1484 -0
  44. data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.h +556 -0
  45. data/contrib/lzham/lzhamdecomp/lzham_timer.cpp +147 -0
  46. data/contrib/lzham/lzhamdecomp/lzham_timer.h +99 -0
  47. data/contrib/lzham/lzhamdecomp/lzham_traits.h +141 -0
  48. data/contrib/lzham/lzhamdecomp/lzham_types.h +97 -0
  49. data/contrib/lzham/lzhamdecomp/lzham_utils.h +58 -0
  50. data/contrib/lzham/lzhamdecomp/lzham_vector.cpp +75 -0
  51. data/contrib/lzham/lzhamdecomp/lzham_vector.h +588 -0
  52. data/contrib/lzham/lzhamlib/lzham_lib.cpp +179 -0
  53. data/examples/basic.rb +48 -0
  54. data/ext/extconf.rb +26 -0
  55. data/ext/extlzham.c +741 -0
  56. data/gemstub.rb +22 -0
  57. data/lib/extlzham/version.rb +5 -0
  58. data/lib/extlzham.rb +153 -0
  59. metadata +135 -0
@@ -0,0 +1,179 @@
1
+ // File: lzham_lib.cpp - Static library entrypoints.
2
+ // See Copyright Notice and license at the end of include/lzham.h
3
+ #include "lzham_core.h"
4
+ #include "lzham_decomp.h"
5
+ #include "lzham_comp.h"
6
+
7
+ extern "C" lzham_uint32 LZHAM_CDECL lzham_get_version(void)
8
+ {
9
+ return LZHAM_DLL_VERSION;
10
+ }
11
+
12
+ extern "C" void LZHAM_CDECL lzham_set_memory_callbacks(lzham_realloc_func pRealloc, lzham_msize_func pMSize, void* pUser_data)
13
+ {
14
+ lzham::lzham_lib_set_memory_callbacks(pRealloc, pMSize, pUser_data);
15
+ }
16
+
17
+ extern "C" lzham_decompress_state_ptr LZHAM_CDECL lzham_decompress_init(const lzham_decompress_params *pParams)
18
+ {
19
+ return lzham::lzham_lib_decompress_init(pParams);
20
+ }
21
+
22
+ extern "C" lzham_decompress_state_ptr LZHAM_CDECL lzham_decompress_reinit(lzham_decompress_state_ptr p, const lzham_decompress_params *pParams)
23
+ {
24
+ return lzham::lzham_lib_decompress_reinit(p, pParams);
25
+ }
26
+
27
+ extern "C" lzham_uint32 LZHAM_CDECL lzham_decompress_deinit(lzham_decompress_state_ptr p)
28
+ {
29
+ return lzham::lzham_lib_decompress_deinit(p);
30
+ }
31
+
32
+ extern "C" lzham_decompress_status_t LZHAM_CDECL lzham_decompress(
33
+ lzham_decompress_state_ptr p,
34
+ const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
35
+ lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
36
+ lzham_bool no_more_input_bytes_flag)
37
+ {
38
+ return lzham::lzham_lib_decompress(p, pIn_buf, pIn_buf_size, pOut_buf, pOut_buf_size, no_more_input_bytes_flag);
39
+ }
40
+
41
+ extern "C" lzham_decompress_status_t LZHAM_CDECL lzham_decompress_memory(const lzham_decompress_params *pParams, lzham_uint8* pDst_buf, size_t *pDst_len, const lzham_uint8* pSrc_buf, size_t src_len, lzham_uint32 *pAdler32)
42
+ {
43
+ return lzham::lzham_lib_decompress_memory(pParams, pDst_buf, pDst_len, pSrc_buf, src_len, pAdler32);
44
+ }
45
+
46
+ extern "C" lzham_compress_state_ptr LZHAM_CDECL lzham_compress_init(const lzham_compress_params *pParams)
47
+ {
48
+ return lzham::lzham_lib_compress_init(pParams);
49
+ }
50
+
51
+ extern "C" lzham_compress_state_ptr LZHAM_CDECL lzham_compress_reinit(lzham_compress_state_ptr p)
52
+ {
53
+ return lzham::lzham_lib_compress_reinit(p);
54
+ }
55
+
56
+ extern "C" lzham_uint32 LZHAM_CDECL lzham_compress_deinit(lzham_compress_state_ptr p)
57
+ {
58
+ return lzham::lzham_lib_compress_deinit(p);
59
+ }
60
+
61
+ extern "C" lzham_compress_status_t LZHAM_CDECL lzham_compress(
62
+ lzham_compress_state_ptr p,
63
+ const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
64
+ lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
65
+ lzham_bool no_more_input_bytes_flag)
66
+ {
67
+ return lzham::lzham_lib_compress(p, pIn_buf, pIn_buf_size, pOut_buf, pOut_buf_size, no_more_input_bytes_flag);
68
+ }
69
+
70
+ extern "C" lzham_compress_status_t LZHAM_CDECL lzham_compress2(
71
+ lzham_compress_state_ptr p,
72
+ const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
73
+ lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
74
+ lzham_flush_t flush_type)
75
+ {
76
+ return lzham::lzham_lib_compress2(p, pIn_buf, pIn_buf_size, pOut_buf, pOut_buf_size, flush_type);
77
+ }
78
+
79
+ extern "C" lzham_compress_status_t LZHAM_CDECL lzham_compress_memory(const lzham_compress_params *pParams, lzham_uint8* pDst_buf, size_t *pDst_len, const lzham_uint8* pSrc_buf, size_t src_len, lzham_uint32 *pAdler32)
80
+ {
81
+ return lzham::lzham_lib_compress_memory(pParams, pDst_buf, pDst_len, pSrc_buf, src_len, pAdler32);
82
+ }
83
+
84
+ // ----------------- zlib-style API's
85
+
86
+ extern "C" const char * LZHAM_CDECL lzham_z_version(void)
87
+ {
88
+ return LZHAM_Z_VERSION;
89
+ }
90
+
91
+ extern "C" lzham_z_ulong LZHAM_CDECL lzham_z_adler32(lzham_z_ulong adler, const unsigned char *ptr, size_t buf_len)
92
+ {
93
+ return lzham::lzham_lib_z_adler32(adler, ptr, buf_len);
94
+ }
95
+
96
+ extern "C" lzham_z_ulong LZHAM_CDECL lzham_z_crc32(lzham_z_ulong crc, const lzham_uint8 *ptr, size_t buf_len)
97
+ {
98
+ return lzham::lzham_lib_z_crc32(crc, ptr, buf_len);
99
+ }
100
+
101
+ extern "C" int LZHAM_CDECL lzham_z_deflateInit(lzham_z_streamp pStream, int level)
102
+ {
103
+ return lzham::lzham_lib_z_deflateInit(pStream, level);
104
+ }
105
+
106
+ extern "C" int LZHAM_CDECL lzham_z_deflateInit2(lzham_z_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
107
+ {
108
+ return lzham::lzham_lib_z_deflateInit2(pStream, level, method, window_bits, mem_level, strategy);
109
+ }
110
+
111
+ extern "C" int LZHAM_CDECL lzham_z_deflateReset(lzham_z_streamp pStream)
112
+ {
113
+ return lzham::lzham_lib_z_deflateReset(pStream);
114
+ }
115
+
116
+ extern "C" int LZHAM_CDECL lzham_z_deflate(lzham_z_streamp pStream, int flush)
117
+ {
118
+ return lzham::lzham_lib_z_deflate(pStream, flush);
119
+ }
120
+
121
+ extern "C" int LZHAM_CDECL lzham_z_deflateEnd(lzham_z_streamp pStream)
122
+ {
123
+ return lzham::lzham_lib_z_deflateEnd(pStream);
124
+ }
125
+
126
+ extern "C" lzham_z_ulong LZHAM_CDECL lzham_z_deflateBound(lzham_z_streamp pStream, lzham_z_ulong source_len)
127
+ {
128
+ return lzham::lzham_lib_z_deflateBound(pStream, source_len);
129
+ }
130
+
131
+ extern "C" int LZHAM_CDECL lzham_z_compress(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len)
132
+ {
133
+ return lzham::lzham_lib_z_compress(pDest, pDest_len, pSource, source_len);
134
+ }
135
+
136
+ extern "C" int LZHAM_CDECL lzham_z_compress2(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len, int level)
137
+ {
138
+ return lzham::lzham_lib_z_compress2(pDest, pDest_len, pSource, source_len, level);
139
+ }
140
+
141
+ extern "C" lzham_z_ulong LZHAM_CDECL lzham_z_compressBound(lzham_z_ulong source_len)
142
+ {
143
+ return lzham::lzham_lib_z_compressBound(source_len);
144
+ }
145
+
146
+ extern "C" int LZHAM_CDECL lzham_z_inflateInit(lzham_z_streamp pStream)
147
+ {
148
+ return lzham::lzham_lib_z_inflateInit(pStream);
149
+ }
150
+
151
+ extern "C" int LZHAM_CDECL lzham_z_inflateInit2(lzham_z_streamp pStream, int window_bits)
152
+ {
153
+ return lzham::lzham_lib_z_inflateInit2(pStream, window_bits);
154
+ }
155
+
156
+ extern "C" int LZHAM_CDECL lzham_z_inflateReset(lzham_z_streamp pStream)
157
+ {
158
+ return lzham::lzham_lib_z_inflateReset(pStream);
159
+ }
160
+
161
+ extern "C" int LZHAM_CDECL lzham_z_inflate(lzham_z_streamp pStream, int flush)
162
+ {
163
+ return lzham::lzham_lib_z_inflate(pStream, flush);
164
+ }
165
+
166
+ extern "C" int LZHAM_CDECL lzham_z_inflateEnd(lzham_z_streamp pStream)
167
+ {
168
+ return lzham::lzham_lib_z_inflateEnd(pStream);
169
+ }
170
+
171
+ extern "C" int LZHAM_CDECL lzham_z_uncompress(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len)
172
+ {
173
+ return lzham::lzham_lib_z_uncompress(pDest, pDest_len, pSource, source_len);
174
+ }
175
+
176
+ extern "C" const char * LZHAM_CDECL lzham_z_error(int err)
177
+ {
178
+ return lzham::lzham_lib_z_error(err);
179
+ }
data/examples/basic.rb ADDED
@@ -0,0 +1,48 @@
1
+ #!ruby
2
+
3
+ require "extlzham"
4
+
5
+ # directly string encode / decode
6
+ p data = LZHAM.encode("abcdefghijklmnopqrstuvwxyz" * 10)
7
+ p LZHAM.decode(data)
8
+
9
+
10
+ # directly string encode / decode with dictionaly size
11
+ # (IMPORTANT! MUST BE SAME SIZE both encoding and decoding)
12
+ dictsize = 20 # log(2)'d dictionaly size. This case is 1 MiB (2 ** 20).
13
+ p data = LZHAM.encode("abcdefghijklmnopqrstuvwxyz" * 10, dictsize: dictsize)
14
+ p LZHAM.decode(data, dictsize: dictsize)
15
+
16
+
17
+ # streaming processing
18
+
19
+ # setup streaming data
20
+ ss = StringIO.new("abcdefghijklmnopqrstuvwxyz" * 10) # source stream
21
+ es = StringIO.new # encoded stream
22
+ ds = StringIO.new # destination stream
23
+
24
+ # streaming encode with block
25
+ ss.rewind
26
+ es.rewind
27
+ LZHAM.encode(es) { |lzham| lzham << ss.read }
28
+
29
+ # streaming encode without block
30
+ ss.rewind
31
+ es.rewind
32
+ lzham = LZHAM.encode(es)
33
+ lzham << ss.read
34
+ lzham.finish # or lzham.close
35
+
36
+ # streaming decode with block
37
+ ss.rewind
38
+ es.rewind
39
+ ds.rewind
40
+ LZHAM.decode(ds) { |lzham| lzham << es.read }
41
+
42
+ # streaming decode without block
43
+ ss.rewind
44
+ es.rewind
45
+ ds.rewind
46
+ lzham = LZHAM.decode(ds)
47
+ lzham << es.read
48
+ lzham.finish # or lzham.close
data/ext/extconf.rb ADDED
@@ -0,0 +1,26 @@
1
+ #!ruby
2
+ #vim: set fileencoding:utf-8
3
+
4
+ require "mkmf"
5
+
6
+ dir = File.dirname(__FILE__).gsub(/[\[\{\?\*]/, "[\\0]")
7
+ filepattern = "{.,../contrib/lzham/{lzhamcomp,lzhamdecomp,lzhamlib}}/*.c{,pp}"
8
+ target = File.join(dir, filepattern)
9
+ files = Dir.glob(target).map { |n| File.basename n }
10
+ rejects = (RbConfig::CONFIG["arch"] =~ /mswin|mingw/) ? /_pthreads_/ : /_win32_/
11
+ files.reject! { |n| n =~ rejects }
12
+ $srcs = files
13
+
14
+ $VPATH.push "$(srcdir)/../contrib/lzham/lzhamcomp",
15
+ "$(srcdir)/../contrib/lzham/lzhamdecomp",
16
+ "$(srcdir)/../contrib/lzham/lzhamlib"
17
+
18
+ find_header "lzham.h", "$(srcdir)/../contrib/lzham/include"
19
+ find_header "lzham_comp.h", "$(srcdir)/../contrib/lzham/lzhamcomp"
20
+ find_header "lzham_decomp.h", "$(srcdir)/../contrib/lzham/lzhamdecomp"
21
+
22
+ if RbConfig::CONFIG["arch"] =~ /mingw/
23
+ $CPPFLAGS << " -D__forceinline=__attribute__\\(\\(always_inline\\)\\)"
24
+ end
25
+
26
+ create_makefile("extlzham")