zstd 1.1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +64 -0
  7. data/Rakefile +19 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/exe/zstd +3 -0
  11. data/ext/zstd/extconf.rb +20 -0
  12. data/ext/zstd/libzstd/.gitignore +2 -0
  13. data/ext/zstd/libzstd/LICENSE +1262 -0
  14. data/ext/zstd/libzstd/Makefile +133 -0
  15. data/ext/zstd/libzstd/PATENTS +1272 -0
  16. data/ext/zstd/libzstd/README.md +77 -0
  17. data/ext/zstd/libzstd/common/bitstream.h +414 -0
  18. data/ext/zstd/libzstd/common/entropy_common.c +227 -0
  19. data/ext/zstd/libzstd/common/error_private.c +43 -0
  20. data/ext/zstd/libzstd/common/error_private.h +76 -0
  21. data/ext/zstd/libzstd/common/fse.h +668 -0
  22. data/ext/zstd/libzstd/common/fse_decompress.c +329 -0
  23. data/ext/zstd/libzstd/common/huf.h +238 -0
  24. data/ext/zstd/libzstd/common/mem.h +372 -0
  25. data/ext/zstd/libzstd/common/xxhash.c +867 -0
  26. data/ext/zstd/libzstd/common/xxhash.h +309 -0
  27. data/ext/zstd/libzstd/common/zstd_common.c +77 -0
  28. data/ext/zstd/libzstd/common/zstd_errors.h +60 -0
  29. data/ext/zstd/libzstd/common/zstd_internal.h +270 -0
  30. data/ext/zstd/libzstd/compress/fse_compress.c +850 -0
  31. data/ext/zstd/libzstd/compress/huf_compress.c +609 -0
  32. data/ext/zstd/libzstd/compress/zstd_compress.c +3291 -0
  33. data/ext/zstd/libzstd/compress/zstd_opt.h +919 -0
  34. data/ext/zstd/libzstd/decompress/huf_decompress.c +885 -0
  35. data/ext/zstd/libzstd/decompress/zstd_decompress.c +2154 -0
  36. data/ext/zstd/libzstd/deprecated/zbuff.h +210 -0
  37. data/ext/zstd/libzstd/deprecated/zbuff_compress.c +145 -0
  38. data/ext/zstd/libzstd/deprecated/zbuff_decompress.c +74 -0
  39. data/ext/zstd/libzstd/dictBuilder/divsufsort.c +1913 -0
  40. data/ext/zstd/libzstd/dictBuilder/divsufsort.h +67 -0
  41. data/ext/zstd/libzstd/dictBuilder/zdict.c +1012 -0
  42. data/ext/zstd/libzstd/dictBuilder/zdict.h +111 -0
  43. data/ext/zstd/libzstd/dll/example/Makefile +47 -0
  44. data/ext/zstd/libzstd/dll/example/README.md +69 -0
  45. data/ext/zstd/libzstd/dll/example/build_package.bat +17 -0
  46. data/ext/zstd/libzstd/dll/example/fullbench-dll.sln +25 -0
  47. data/ext/zstd/libzstd/dll/example/fullbench-dll.vcxproj +179 -0
  48. data/ext/zstd/libzstd/dll/libzstd.def +86 -0
  49. data/ext/zstd/libzstd/legacy/zstd_legacy.h +259 -0
  50. data/ext/zstd/libzstd/legacy/zstd_v01.c +2095 -0
  51. data/ext/zstd/libzstd/legacy/zstd_v01.h +80 -0
  52. data/ext/zstd/libzstd/legacy/zstd_v02.c +3518 -0
  53. data/ext/zstd/libzstd/legacy/zstd_v02.h +79 -0
  54. data/ext/zstd/libzstd/legacy/zstd_v03.c +3159 -0
  55. data/ext/zstd/libzstd/legacy/zstd_v03.h +79 -0
  56. data/ext/zstd/libzstd/legacy/zstd_v04.c +3795 -0
  57. data/ext/zstd/libzstd/legacy/zstd_v04.h +128 -0
  58. data/ext/zstd/libzstd/legacy/zstd_v05.c +4056 -0
  59. data/ext/zstd/libzstd/legacy/zstd_v05.h +149 -0
  60. data/ext/zstd/libzstd/legacy/zstd_v06.c +4167 -0
  61. data/ext/zstd/libzstd/legacy/zstd_v06.h +159 -0
  62. data/ext/zstd/libzstd/legacy/zstd_v07.c +4540 -0
  63. data/ext/zstd/libzstd/legacy/zstd_v07.h +173 -0
  64. data/ext/zstd/libzstd/libzstd.pc.in +14 -0
  65. data/ext/zstd/libzstd/zstd.h +673 -0
  66. data/ext/zstd/zstd.c +185 -0
  67. data/ext/zstd/zstd.h +7 -0
  68. data/lib/zstd/version.rb +3 -0
  69. data/lib/zstd.rb +6 -0
  70. data/zstd.gemspec +38 -0
  71. metadata +172 -0
data/ext/zstd/zstd.c ADDED
@@ -0,0 +1,185 @@
1
+ #include "zstd.h"
2
+
3
+ struct dic_struct {
4
+ ZSTD_CDict* cdic;
5
+ ZSTD_CCtx* cctx;
6
+ ZSTD_DDict* ddic;
7
+ ZSTD_DCtx* dctx;
8
+ };
9
+
10
+ static off_t fsize_or_raise(const char *filename) {
11
+ struct stat st;
12
+ if (stat(filename, &st) == 0) return st.st_size;
13
+ rb_raise(rb_eRuntimeError, "file not found: %s", filename);
14
+ }
15
+
16
+ static FILE* fopen_or_raise(const char *filename, const char *instruction) {
17
+ FILE* const inFile = fopen(filename, instruction);
18
+ if (inFile) return inFile;
19
+ rb_raise(rb_eRuntimeError, "cannot open file: %s", filename);
20
+ }
21
+
22
+ static void* malloc_or_raise(size_t size) {
23
+ void* const buff = malloc(size);
24
+ if (buff) return buff;
25
+ rb_raise(rb_eRuntimeError, "malloc failed");
26
+ }
27
+
28
+ static void* load_file_or_raise(const char* filename, size_t* size) {
29
+ off_t const buffSize = fsize_or_raise(filename);
30
+ FILE* const inFile = fopen_or_raise(filename, "rb");
31
+ void* const buffer = malloc_or_raise(buffSize);
32
+ size_t const readSize = fread(buffer, 1, buffSize, inFile);
33
+ if (readSize != (size_t)buffSize) {
34
+ rb_raise(rb_eRuntimeError, "failed to read file: %s", filename);
35
+ }
36
+ fclose(inFile);
37
+ *size = buffSize;
38
+ return buffer;
39
+ }
40
+
41
+ static ZSTD_CDict* createCDict_or_raise(const char* dictFileName, int cLevel) {
42
+ size_t dictSize;
43
+ void* const dictBuffer = load_file_or_raise(dictFileName, &dictSize);
44
+ ZSTD_CDict* const cdict = ZSTD_createCDict(dictBuffer, dictSize, cLevel);
45
+ if (!cdict) {
46
+ rb_raise(rb_eRuntimeError, "failed to create dictionary: %s", dictFileName);
47
+ }
48
+ free(dictBuffer);
49
+ return cdict;
50
+ }
51
+
52
+ static ZSTD_DDict* createDDict_or_raise(const char* dictFileName) {
53
+ size_t dictSize;
54
+ void* const dictBuffer = load_file_or_raise(dictFileName, &dictSize);
55
+ ZSTD_DDict* const ddict = ZSTD_createDDict(dictBuffer, dictSize);
56
+ if (!ddict) {
57
+ rb_raise(rb_eRuntimeError, "failed to create dictionary: %s", dictFileName);
58
+ }
59
+ free(dictBuffer);
60
+ return ddict;
61
+ }
62
+
63
+ static VALUE compress(int argc, VALUE *argv, VALUE self) {
64
+ VALUE src_buf, dst_buf, comp_level_arg;
65
+ const char* src_ptr;
66
+ char* dst_ptr;
67
+ size_t src_size, dst_size, res;
68
+ int comp_level;
69
+
70
+ rb_scan_args(argc, argv, "11", &src_buf, &comp_level_arg);
71
+
72
+ Check_Type(src_buf, RUBY_T_STRING);
73
+ src_ptr = RSTRING_PTR(src_buf);
74
+ src_size = RSTRING_LEN(src_buf);
75
+
76
+ dst_size = ZSTD_compressBound(src_size);
77
+ dst_buf = rb_str_new(NULL, dst_size);
78
+ dst_ptr = RSTRING_PTR(dst_buf);
79
+
80
+ comp_level = 3;
81
+ if (!NIL_P(comp_level_arg)) {
82
+ Check_Type(comp_level_arg, RUBY_T_FIXNUM);
83
+ comp_level = FIX2INT(comp_level_arg);
84
+ }
85
+
86
+ struct dic_struct *ds;
87
+ Data_Get_Struct(self, struct dic_struct, ds);
88
+
89
+ if (ds->cdic == NULL) {
90
+ res = ZSTD_compress((void*)dst_ptr, dst_size, (const void*)src_ptr, src_size, comp_level);
91
+ } else {
92
+ res = ZSTD_compress_usingCDict(ds->cctx, (void*)dst_ptr, dst_size, (const void*)src_ptr, src_size, ds->cdic);
93
+ }
94
+
95
+ if (ZSTD_isError(res)) {
96
+ rb_raise(rb_eRuntimeError, "error compressing: %s", ZSTD_getErrorName(res));
97
+ } else {
98
+ rb_str_resize(dst_buf, res);
99
+ }
100
+
101
+ return dst_buf;
102
+ }
103
+
104
+ static VALUE decompress(int argc, VALUE *argv, VALUE self) {
105
+ VALUE src_buf, dst_buf;
106
+ const char* src_ptr;
107
+ char* dst_ptr;
108
+ size_t src_size, dst_size, res;
109
+
110
+ rb_scan_args(argc, argv, "10", &src_buf);
111
+
112
+ Check_Type(src_buf, RUBY_T_STRING);
113
+ src_ptr = RSTRING_PTR(src_buf);
114
+ src_size = RSTRING_LEN(src_buf);
115
+
116
+ dst_size = ZSTD_getDecompressedSize(src_ptr, src_size);
117
+ dst_buf = rb_str_new(NULL, dst_size);
118
+ dst_ptr = RSTRING_PTR(dst_buf);
119
+
120
+ struct dic_struct *ds;
121
+ Data_Get_Struct(self, struct dic_struct, ds);
122
+
123
+ if (ds->ddic == NULL) {
124
+ res = ZSTD_decompress((void*)dst_ptr, dst_size, (const void*)src_ptr, src_size);
125
+ } else {
126
+ res = ZSTD_decompress_usingDDict(ds->dctx, (void*)dst_ptr, dst_size, (const void*)src_ptr, src_size, ds->ddic);
127
+ }
128
+
129
+ if (ZSTD_isError(res)) {
130
+ rb_raise(rb_eRuntimeError, "error decompressing: %s", ZSTD_getErrorName(res));
131
+ } else {
132
+ rb_str_resize(dst_buf, res);
133
+ }
134
+
135
+ return dst_buf;
136
+ }
137
+
138
+ static void deallocate(void *ds) {
139
+ if ((((struct dic_struct *)ds)->cctx) != NULL) {
140
+ ZSTD_freeCCtx(((struct dic_struct *)ds)->cctx);
141
+ ZSTD_freeCDict(((struct dic_struct *)ds)->cdic);
142
+ ZSTD_freeDCtx(((struct dic_struct *)ds)->dctx);
143
+ ZSTD_freeDDict(((struct dic_struct *)ds)->ddic);
144
+ }
145
+ //xfree(ds); // TODO: verify
146
+ }
147
+
148
+ static VALUE allocate(VALUE claes) {
149
+ struct dic_struct *ds;
150
+ ds = ALLOC(struct dic_struct);
151
+ return Data_Wrap_Struct(claes, NULL, deallocate, ds);
152
+ }
153
+
154
+ static VALUE initialize(int argc, VALUE *argv, VALUE self) {
155
+ VALUE dic_arg;
156
+ struct dic_struct *ds;
157
+ Data_Get_Struct(self, struct dic_struct, ds);
158
+ ds->cdic = NULL;
159
+ ds->cctx = NULL;
160
+ ds->ddic = NULL;
161
+ ds->dctx = NULL;
162
+
163
+ rb_scan_args(argc, argv, "01", &dic_arg);
164
+
165
+ if (!NIL_P(dic_arg)) {
166
+ Check_Type(dic_arg, RUBY_T_STRING);
167
+ const char* dic_ptr = RSTRING_PTR(dic_arg);
168
+ ds->cdic = createCDict_or_raise(dic_ptr, 19);
169
+ ds->cctx = ZSTD_createCCtx();
170
+ ds->ddic = createDDict_or_raise(dic_ptr);
171
+ ds->dctx = ZSTD_createDCtx();
172
+ }
173
+
174
+ return self;
175
+ }
176
+
177
+ void Init_zstd(void) {
178
+ VALUE rb_cZstd = rb_define_class("Zstd", rb_cObject);
179
+
180
+ rb_define_alloc_func(rb_cZstd, allocate);
181
+ rb_define_method(rb_cZstd, "initialize", initialize, -1);
182
+
183
+ rb_define_method(rb_cZstd, "compress", compress, -1);
184
+ rb_define_method(rb_cZstd, "decompress", decompress, -1);
185
+ }
data/ext/zstd/zstd.h ADDED
@@ -0,0 +1,7 @@
1
+ #ifndef ZSTD_H
2
+ #define ZSTD_H 1
3
+
4
+ #include "ruby.h"
5
+ #include <libzstd/zstd.h>
6
+
7
+ #endif /* ZSTD_H */
@@ -0,0 +1,3 @@
1
+ class Zstd
2
+ VERSION = "1.1.2.0"
3
+ end
data/lib/zstd.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "zstd/version"
2
+ require "zstd/zstd"
3
+
4
+ class Zstd
5
+ # Your code goes here...
6
+ end
data/zstd.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zstd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'zstd'
8
+ spec.version = Zstd::VERSION
9
+ spec.authors = ['Lars Ingjer']
10
+ spec.email = ['lars@datek.no']
11
+
12
+ spec.summary = %q{Ruby wrapper for Facebook Zstandard}
13
+ spec.description = %q{Ruby wrapper for Facebook Zstandard library}
14
+ spec.homepage = 'https://github.com/DatekWireless/zstd'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+ spec.extensions = ["ext/zstd/extconf.rb"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.12"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rake-compiler"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
38
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zstd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Lars Ingjer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: Ruby wrapper for Facebook Zstandard library
70
+ email:
71
+ - lars@datek.no
72
+ executables:
73
+ - zstd
74
+ extensions:
75
+ - ext/zstd/extconf.rb
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exe/zstd
87
+ - ext/zstd/extconf.rb
88
+ - ext/zstd/libzstd/.gitignore
89
+ - ext/zstd/libzstd/LICENSE
90
+ - ext/zstd/libzstd/Makefile
91
+ - ext/zstd/libzstd/PATENTS
92
+ - ext/zstd/libzstd/README.md
93
+ - ext/zstd/libzstd/common/bitstream.h
94
+ - ext/zstd/libzstd/common/entropy_common.c
95
+ - ext/zstd/libzstd/common/error_private.c
96
+ - ext/zstd/libzstd/common/error_private.h
97
+ - ext/zstd/libzstd/common/fse.h
98
+ - ext/zstd/libzstd/common/fse_decompress.c
99
+ - ext/zstd/libzstd/common/huf.h
100
+ - ext/zstd/libzstd/common/mem.h
101
+ - ext/zstd/libzstd/common/xxhash.c
102
+ - ext/zstd/libzstd/common/xxhash.h
103
+ - ext/zstd/libzstd/common/zstd_common.c
104
+ - ext/zstd/libzstd/common/zstd_errors.h
105
+ - ext/zstd/libzstd/common/zstd_internal.h
106
+ - ext/zstd/libzstd/compress/fse_compress.c
107
+ - ext/zstd/libzstd/compress/huf_compress.c
108
+ - ext/zstd/libzstd/compress/zstd_compress.c
109
+ - ext/zstd/libzstd/compress/zstd_opt.h
110
+ - ext/zstd/libzstd/decompress/huf_decompress.c
111
+ - ext/zstd/libzstd/decompress/zstd_decompress.c
112
+ - ext/zstd/libzstd/deprecated/zbuff.h
113
+ - ext/zstd/libzstd/deprecated/zbuff_compress.c
114
+ - ext/zstd/libzstd/deprecated/zbuff_decompress.c
115
+ - ext/zstd/libzstd/dictBuilder/divsufsort.c
116
+ - ext/zstd/libzstd/dictBuilder/divsufsort.h
117
+ - ext/zstd/libzstd/dictBuilder/zdict.c
118
+ - ext/zstd/libzstd/dictBuilder/zdict.h
119
+ - ext/zstd/libzstd/dll/example/Makefile
120
+ - ext/zstd/libzstd/dll/example/README.md
121
+ - ext/zstd/libzstd/dll/example/build_package.bat
122
+ - ext/zstd/libzstd/dll/example/fullbench-dll.sln
123
+ - ext/zstd/libzstd/dll/example/fullbench-dll.vcxproj
124
+ - ext/zstd/libzstd/dll/libzstd.def
125
+ - ext/zstd/libzstd/legacy/zstd_legacy.h
126
+ - ext/zstd/libzstd/legacy/zstd_v01.c
127
+ - ext/zstd/libzstd/legacy/zstd_v01.h
128
+ - ext/zstd/libzstd/legacy/zstd_v02.c
129
+ - ext/zstd/libzstd/legacy/zstd_v02.h
130
+ - ext/zstd/libzstd/legacy/zstd_v03.c
131
+ - ext/zstd/libzstd/legacy/zstd_v03.h
132
+ - ext/zstd/libzstd/legacy/zstd_v04.c
133
+ - ext/zstd/libzstd/legacy/zstd_v04.h
134
+ - ext/zstd/libzstd/legacy/zstd_v05.c
135
+ - ext/zstd/libzstd/legacy/zstd_v05.h
136
+ - ext/zstd/libzstd/legacy/zstd_v06.c
137
+ - ext/zstd/libzstd/legacy/zstd_v06.h
138
+ - ext/zstd/libzstd/legacy/zstd_v07.c
139
+ - ext/zstd/libzstd/legacy/zstd_v07.h
140
+ - ext/zstd/libzstd/libzstd.pc.in
141
+ - ext/zstd/libzstd/zstd.h
142
+ - ext/zstd/zstd.c
143
+ - ext/zstd/zstd.h
144
+ - lib/zstd.rb
145
+ - lib/zstd/version.rb
146
+ - zstd.gemspec
147
+ homepage: https://github.com/DatekWireless/zstd
148
+ licenses:
149
+ - MIT
150
+ metadata:
151
+ allowed_push_host: https://rubygems.org
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.4.8
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Ruby wrapper for Facebook Zstandard
172
+ test_files: []