extzstd 0.0.2.CONCEPT-x86-mingw32 → 0.0.3.CONCEPT-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +72 -22
- data/Rakefile +73 -19
- data/contrib/zstd/README.md +68 -0
- data/contrib/zstd/common/bitstream.h +414 -0
- data/contrib/zstd/common/entropy_common.c +231 -0
- data/contrib/zstd/common/error_private.h +125 -0
- data/contrib/zstd/common/error_public.h +77 -0
- data/contrib/zstd/common/fse.h +628 -0
- data/contrib/zstd/common/fse_decompress.c +331 -0
- data/contrib/zstd/common/huf.h +228 -0
- data/contrib/zstd/common/mem.h +377 -0
- data/contrib/zstd/common/xxhash.c +854 -0
- data/contrib/zstd/common/xxhash.h +273 -0
- data/contrib/zstd/common/zbuff.h +197 -0
- data/contrib/zstd/common/zstd.h +475 -0
- data/contrib/zstd/common/zstd_common.c +91 -0
- data/contrib/zstd/common/zstd_internal.h +238 -0
- data/contrib/zstd/compress/fse_compress.c +807 -0
- data/contrib/zstd/compress/huf_compress.c +577 -0
- data/contrib/zstd/compress/zbuff_compress.c +327 -0
- data/contrib/zstd/compress/zstd_compress.c +3074 -0
- data/contrib/zstd/compress/zstd_opt.h +1046 -0
- data/contrib/zstd/decompress/huf_decompress.c +894 -0
- data/contrib/zstd/decompress/zbuff_decompress.c +294 -0
- data/contrib/zstd/decompress/zstd_decompress.c +1362 -0
- data/contrib/zstd/dictBuilder/divsufsort.c +1913 -0
- data/contrib/zstd/dictBuilder/divsufsort.h +67 -0
- data/contrib/zstd/dictBuilder/zdict.c +1045 -0
- data/contrib/zstd/dictBuilder/zdict.h +113 -0
- data/contrib/zstd/legacy/zstd_legacy.h +140 -0
- data/contrib/zstd/legacy/zstd_v01.c +2178 -0
- data/contrib/zstd/{zstd.h → legacy/zstd_v01.h} +46 -39
- data/contrib/zstd/legacy/zstd_v02.c +3748 -0
- data/contrib/zstd/legacy/zstd_v02.h +99 -0
- data/contrib/zstd/legacy/zstd_v03.c +3389 -0
- data/contrib/zstd/legacy/zstd_v03.h +99 -0
- data/contrib/zstd/legacy/zstd_v04.c +4056 -0
- data/contrib/zstd/legacy/zstd_v04.h +148 -0
- data/contrib/zstd/legacy/zstd_v05.c +4325 -0
- data/contrib/zstd/legacy/zstd_v05.h +171 -0
- data/contrib/zstd/legacy/zstd_v06.c +4581 -0
- data/contrib/zstd/legacy/zstd_v06.h +185 -0
- data/ext/extconf.rb +10 -12
- data/ext/extzstd.c +497 -144
- data/ext/extzstd.h +127 -22
- data/ext/extzstd_buffered.c +265 -0
- data/ext/extzstd_nogvls.h +174 -0
- data/ext/zstd_amalgam.c +18 -0
- data/ext/zstd_legacy_v01.c +1 -0
- data/ext/zstd_legacy_v02.c +1 -0
- data/ext/zstd_legacy_v03.c +1 -0
- data/ext/zstd_legacy_v04.c +1 -0
- data/ext/zstd_legacy_v05.c +1 -0
- data/ext/zstd_legacy_v06.c +1 -0
- data/gemstub.rb +17 -1
- data/lib/2.0/extzstd.so +0 -0
- data/lib/2.1/extzstd.so +0 -0
- data/lib/2.2/extzstd.so +0 -0
- data/lib/2.3/extzstd.so +0 -0
- data/lib/extzstd.rb +197 -77
- data/lib/extzstd/version.rb +1 -1
- data/test/test_basic.rb +41 -0
- metadata +71 -20
- data/contrib/zstd/Makefile +0 -115
- data/contrib/zstd/fse.c +0 -2466
- data/contrib/zstd/fse.h +0 -320
- data/contrib/zstd/fse_static.h +0 -282
- data/contrib/zstd/libzstd.pc.in +0 -14
- data/contrib/zstd/zstd.c +0 -1768
- data/contrib/zstd/zstd_static.h +0 -89
- data/ext/extzstd-stream.c +0 -398
data/ext/zstd_amalgam.c
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#define ZSTD_LEGACY_SUPPORT 1
|
2
|
+
#define MEM_MODULE 1
|
3
|
+
|
4
|
+
#include "../contrib/zstd/compress/zbuff_compress.c"
|
5
|
+
#include "../contrib/zstd/compress/fse_compress.c"
|
6
|
+
#include "../contrib/zstd/compress/zstd_compress.c"
|
7
|
+
#include "../contrib/zstd/compress/huf_compress.c"
|
8
|
+
#include "../contrib/zstd/common/xxhash.c"
|
9
|
+
#include "../contrib/zstd/common/zstd_common.c"
|
10
|
+
#define FSE_abs FSE_abs__redef
|
11
|
+
#include "../contrib/zstd/common/entropy_common.c"
|
12
|
+
#include "../contrib/zstd/common/fse_decompress.c"
|
13
|
+
#include "../contrib/zstd/decompress/zstd_decompress.c"
|
14
|
+
#include "../contrib/zstd/decompress/huf_decompress.c"
|
15
|
+
#define ZBUFF_limitCopy ZBUFF_limitCopy__redef
|
16
|
+
#include "../contrib/zstd/decompress/zbuff_decompress.c"
|
17
|
+
#include "../contrib/zstd/dictBuilder/zdict.c"
|
18
|
+
#include "../contrib/zstd/dictBuilder/divsufsort.c"
|
@@ -0,0 +1 @@
|
|
1
|
+
#include "../contrib/zstd/legacy/zstd_v01.c"
|
@@ -0,0 +1 @@
|
|
1
|
+
#include "../contrib/zstd/legacy/zstd_v02.c"
|
@@ -0,0 +1 @@
|
|
1
|
+
#include "../contrib/zstd/legacy/zstd_v03.c"
|
@@ -0,0 +1 @@
|
|
1
|
+
#include "../contrib/zstd/legacy/zstd_v04.c"
|
@@ -0,0 +1 @@
|
|
1
|
+
#include "../contrib/zstd/legacy/zstd_v05.c"
|
@@ -0,0 +1 @@
|
|
1
|
+
#include "../contrib/zstd/legacy/zstd_v06.c"
|
data/gemstub.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
|
2
|
+
file "lib/extzstd/version.rb" => %w(README.md) do
|
3
|
+
reg = /^\s*\*\s+version:\s*(\d+(?:\.\w+)+)\s*$/i
|
4
|
+
unless File.read("README.md", mode: "rt") =~ reg
|
5
|
+
raise "``version'' is not defined or bad syntax in ``README.md''"
|
6
|
+
end
|
7
|
+
|
8
|
+
GEMSTUB.version = ver = String($1)
|
9
|
+
|
10
|
+
File.write "lib/extzstd/version.rb", <<-"EOS", mode: "wb"
|
11
|
+
module Zstd
|
12
|
+
VERSION = #{ver.inspect}
|
13
|
+
end
|
14
|
+
EOS
|
15
|
+
end
|
16
|
+
|
1
17
|
require_relative "lib/extzstd/version"
|
2
18
|
|
3
19
|
GEMSTUB = Gem::Specification.new do |s|
|
@@ -13,7 +29,7 @@ EOS
|
|
13
29
|
s.email = "dearblue@users.osdn.me"
|
14
30
|
|
15
31
|
s.required_ruby_version = ">= 2.0"
|
16
|
-
s.add_development_dependency "rake"
|
32
|
+
s.add_development_dependency "rake"
|
17
33
|
end
|
18
34
|
|
19
35
|
EXTRA.concat(FileList["contrib/**/*"])
|
data/lib/2.0/extzstd.so
CHANGED
Binary file
|
data/lib/2.1/extzstd.so
CHANGED
Binary file
|
data/lib/2.2/extzstd.so
CHANGED
Binary file
|
data/lib/2.3/extzstd.so
ADDED
Binary file
|
data/lib/extzstd.rb
CHANGED
@@ -1,55 +1,138 @@
|
|
1
|
-
|
1
|
+
#!ruby
|
2
2
|
|
3
|
-
ver =
|
3
|
+
ver = RUBY_VERSION.slice(/\d+\.\d+/)
|
4
4
|
soname = File.basename(__FILE__, ".rb") << ".so"
|
5
|
-
|
6
|
-
if File.file?(lib)
|
7
|
-
require_relative File.join(ver, soname)
|
8
|
-
else
|
9
|
-
require_relative soname
|
10
|
-
end
|
5
|
+
require_relative File.join(ver, soname)
|
11
6
|
|
12
7
|
require_relative "extzstd/version"
|
13
8
|
|
14
9
|
require "stringio"
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
#
|
12
|
+
# This is ruby bindings for zstd <https://github.com/Cyan4973/zstd> the compression library.
|
13
|
+
#
|
14
|
+
module Zstd
|
15
|
+
#
|
16
|
+
# call-seq:
|
17
|
+
# encode(src_string, level = nil, dict = nil) -> zstd string
|
18
|
+
# encode(src_string, encoder_params, dict = nil) -> zstd string
|
19
|
+
# encode(outport, level = nil, dict = nil) -> zstd encoder
|
20
|
+
# encode(outport, level = nil, dict = nil) { |encoder| ... } -> yield returned value
|
21
|
+
# encode(outport, encoder_params, dict = nil) -> zstd encoder
|
22
|
+
# encode(outport, encoder_params, dict = nil) { |encoder| ... } -> yield returned value
|
23
|
+
#
|
24
|
+
def self.encode(src, *args, &block)
|
25
|
+
if src.kind_of?(String)
|
26
|
+
dest = Aux::EMPTY_BUFFER.dup
|
27
|
+
return Encoder.open(dest, *args) { |e| e.write src; dest }
|
28
|
+
end
|
29
|
+
|
30
|
+
Encoder.open(src, *args, &block)
|
21
31
|
end
|
22
|
-
return *args
|
23
|
-
end
|
24
|
-
end
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
#
|
34
|
+
# call-seq:
|
35
|
+
# decode(zstd_string, maxsize = nil, dict = nil) -> string
|
36
|
+
# decode(zstd_stream, maxsize = nil, dict = nil) -> zstd decoder
|
37
|
+
# decode(zstd_stream, maxsize = nil, dict = nil) { |decoder| ... } -> yield returned value
|
38
|
+
#
|
39
|
+
def self.decode(src, maxsize = nil, dict = nil, &block)
|
40
|
+
if src.kind_of?(String)
|
41
|
+
maxsize &&= maxsize.to_i
|
42
|
+
return Decoder.open(src, dict) { |d| return d.read(maxsize) }
|
33
43
|
end
|
44
|
+
|
45
|
+
Decoder.open(src, dict, &block)
|
34
46
|
end
|
35
47
|
|
36
|
-
class
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
48
|
+
class Encoder < Struct.new(:encoder, :outport, :destbuf, :status)
|
49
|
+
#
|
50
|
+
# call-seq:
|
51
|
+
# open(outport, level = nil, dict = nil) -> zstd encoder
|
52
|
+
# open(outport, encoder_params, dict = nil) { |encoder| ... } -> yield returned value
|
53
|
+
#
|
54
|
+
def self.open(outport, *args)
|
55
|
+
e = new(outport, *args)
|
56
|
+
|
57
|
+
return e unless block_given?
|
58
|
+
|
59
|
+
begin
|
60
|
+
yield e
|
61
|
+
ensure
|
62
|
+
e.close rescue nil unless e.eof?
|
63
|
+
end
|
64
|
+
end
|
41
65
|
|
42
66
|
#
|
43
67
|
# call-seq:
|
44
|
-
#
|
45
|
-
#
|
68
|
+
# initialize(outport, level = nil, dict = nil)
|
69
|
+
# initialize(outport, encoder_params, dict = nil)
|
70
|
+
#
|
71
|
+
# +outport+ need has +.<<+ method.
|
46
72
|
#
|
47
|
-
|
73
|
+
def initialize(outport, params = nil, dict = nil)
|
74
|
+
encoder = BufferedEncoder.new(params, dict)
|
75
|
+
super encoder, outport, "".force_encoding(Encoding::BINARY), [true]
|
76
|
+
end
|
77
|
+
|
78
|
+
def eof
|
79
|
+
!status[0]
|
80
|
+
end
|
81
|
+
|
82
|
+
alias eof? eof
|
83
|
+
|
84
|
+
def close
|
85
|
+
return nil if eof?
|
86
|
+
encoder.end(destbuf, BufferedEncoder.recommended_outsize)
|
87
|
+
outport << destbuf
|
88
|
+
status[0] = false
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
|
92
|
+
def write(buf)
|
93
|
+
raise IOError, "closed stream" if eof?
|
94
|
+
|
95
|
+
off = 0
|
96
|
+
rest = buf.bytesize
|
97
|
+
outsize = BufferedEncoder.recommended_outsize
|
98
|
+
while off && off < rest
|
99
|
+
off = encoder.continue(buf, off, destbuf, outsize)
|
100
|
+
outport << destbuf
|
101
|
+
end
|
102
|
+
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
alias << write
|
107
|
+
|
108
|
+
def flush
|
109
|
+
raise IOError, "closed stream" if eof?
|
110
|
+
|
111
|
+
off = 0
|
112
|
+
encoder.flush(destbuf, BufferedEncoder.recommended_outsize)
|
113
|
+
outport << destbuf
|
114
|
+
|
115
|
+
self
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Decoder < Struct.new(:decoder, :inport, :readbuf, :destbuf, :status)
|
120
|
+
STATUS_CLOSED = nil
|
121
|
+
STATUS_READY = 0
|
122
|
+
STATUS_INPORT_EOF = 1
|
123
|
+
|
124
|
+
#
|
125
|
+
# call-seq:
|
126
|
+
# open(inport, dict = nil) -> decoder
|
127
|
+
# open(inport, dict = nil) { |decoder| ... } -> yield returned value
|
128
|
+
#
|
129
|
+
# [inport]
|
48
130
|
# String instance or +read+ method haved Object.
|
49
131
|
#
|
50
|
-
def self.open(
|
51
|
-
|
52
|
-
|
132
|
+
def self.open(inport, dict = nil)
|
133
|
+
inport = StringIO.new(inport) if inport.kind_of?(String)
|
134
|
+
|
135
|
+
dec = new(inport, dict)
|
53
136
|
|
54
137
|
return dec unless block_given?
|
55
138
|
|
@@ -60,21 +143,17 @@ module Zstd
|
|
60
143
|
end
|
61
144
|
end
|
62
145
|
|
63
|
-
def initialize(
|
64
|
-
raise Error, "require .read method - <%s:0x%08x>" % [
|
65
|
-
super(
|
66
|
-
|
67
|
-
# read header
|
68
|
-
Aux.io_read(import, decoder.next_srcsize, readbuf)
|
69
|
-
decoder.decode(readbuf, "", 0)
|
146
|
+
def initialize(inport, dict = nil)
|
147
|
+
raise Error, "require .read method - <%s:0x%08x>" % [inport.class, inport.object_id << 1] unless inport.respond_to?(:read)
|
148
|
+
super(BufferedDecoder.new(dict), inport, StringIO.new(Aux::EMPTY_BUFFER.dup), StringIO.new(Aux::EMPTY_BUFFER.dup), STATUS_READY)
|
70
149
|
end
|
71
150
|
|
72
151
|
def close
|
73
152
|
decoder.reset
|
74
|
-
|
153
|
+
inport.close rescue nil if inport.respond_to?(:close)
|
75
154
|
readbuf.clear
|
76
|
-
destbuf.clear
|
77
|
-
self.status =
|
155
|
+
#destbuf.clear
|
156
|
+
self.status = STATUS_CLOSED
|
78
157
|
nil
|
79
158
|
end
|
80
159
|
|
@@ -84,55 +163,96 @@ module Zstd
|
|
84
163
|
|
85
164
|
alias eof? eof
|
86
165
|
|
87
|
-
def read(size = nil, dest =
|
88
|
-
dest.
|
89
|
-
|
90
|
-
|
166
|
+
def read(size = nil, dest = Aux::EMPTY_BUFFER.dup)
|
167
|
+
dest ||= Aux::EMPTY_BUFFER.dup
|
168
|
+
Aux.change_binary(dest) do
|
169
|
+
#dest.clear
|
170
|
+
dest[0 .. -1] = Aux::EMPTY_BUFFER # keep allocated heap
|
91
171
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
172
|
+
return dest if size == 0
|
173
|
+
|
174
|
+
d = Aux::EMPTY_BUFFER.dup
|
175
|
+
until size && size <= 0
|
176
|
+
if destbuf.eof?
|
177
|
+
break unless fetch
|
97
178
|
end
|
98
|
-
end
|
99
179
|
|
100
|
-
|
101
|
-
|
180
|
+
destbuf.read(size, d)
|
181
|
+
dest << d
|
102
182
|
|
103
|
-
|
183
|
+
size -= d.bytesize if size
|
184
|
+
end
|
104
185
|
end
|
105
186
|
|
106
|
-
dest
|
107
|
-
|
108
|
-
|
187
|
+
if dest.empty?
|
188
|
+
nil
|
189
|
+
else
|
190
|
+
dest
|
191
|
+
end
|
109
192
|
end
|
110
193
|
|
111
194
|
private
|
112
195
|
def fetch
|
113
|
-
return nil if eof?
|
196
|
+
return nil if eof? || status == STATUS_INPORT_EOF
|
114
197
|
|
115
198
|
while true
|
116
|
-
if
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
199
|
+
if readbuf.eof?
|
200
|
+
readbuf.string[0 .. -1] = Aux::EMPTY_BUFFER
|
201
|
+
readbuf.rewind
|
202
|
+
unless inport.read(BufferedDecoder.recommended_insize, readbuf.string)
|
203
|
+
self.status = STATUS_INPORT_EOF
|
204
|
+
return nil
|
122
205
|
end
|
123
|
-
self.status = STATUS_BLOCK_APPROACH
|
124
206
|
end
|
125
207
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
return nil
|
131
|
-
end
|
132
|
-
Aux.io_read(import, s, readbuf)
|
133
|
-
decoder.decode(readbuf, "", 0)
|
134
|
-
self.status = STATUS_INBLOCK
|
208
|
+
off = decoder.continue(readbuf.string, readbuf.pos, destbuf.string, BufferedDecoder.recommended_outsize)
|
209
|
+
readbuf.pos = off if off
|
210
|
+
destbuf.rewind
|
211
|
+
return self if destbuf.size > 0
|
135
212
|
end
|
136
213
|
end
|
137
214
|
end
|
215
|
+
|
216
|
+
class EncodeParameters
|
217
|
+
def inspect
|
218
|
+
"#<#{self.class} windowlog=#{windowlog}, chainlog=#{chainlog}, " \
|
219
|
+
"hashlog=#{hashlog}, searchlog=#{searchlog}, " \
|
220
|
+
"searchlength=#{searchlength}, strategy=#{strategy}>"
|
221
|
+
end
|
222
|
+
|
223
|
+
def pretty_print(q)
|
224
|
+
q.group(2, "#<#{self.class}") do
|
225
|
+
q.breakable " "
|
226
|
+
q.text "windowlog=#{windowlog},"
|
227
|
+
q.breakable " "
|
228
|
+
q.text "chainlog=#{chainlog},"
|
229
|
+
q.breakable " "
|
230
|
+
q.text "hashlog=#{hashlog},"
|
231
|
+
q.breakable " "
|
232
|
+
q.text "searchlog=#{searchlog},"
|
233
|
+
q.breakable " "
|
234
|
+
q.text "searchlength=#{searchlength},"
|
235
|
+
q.breakable " "
|
236
|
+
q.text "strategy=#{strategy}>"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
module Aux
|
242
|
+
EMPTY_BUFFER = "".force_encoding(Encoding::BINARY).freeze
|
243
|
+
|
244
|
+
def self.io_read(io, size, buf)
|
245
|
+
raise Error, "encounted EOF (read error)" unless io.read(size, buf)
|
246
|
+
raise Error, "read size too small (read error)" unless buf.bytesize == size
|
247
|
+
buf
|
248
|
+
end
|
249
|
+
|
250
|
+
def self.change_binary(str)
|
251
|
+
e = str.encoding
|
252
|
+
str.force_encoding(Encoding::BINARY)
|
253
|
+
yield
|
254
|
+
ensure
|
255
|
+
str.force_encoding e rescue nil if e
|
256
|
+
end
|
257
|
+
end
|
138
258
|
end
|
data/lib/extzstd/version.rb
CHANGED
data/test/test_basic.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!ruby
|
2
|
+
|
3
|
+
require "test-unit"
|
4
|
+
require "extzstd"
|
5
|
+
require "digest"
|
6
|
+
|
7
|
+
class TestZstd < Test::Unit::TestCase
|
8
|
+
def test_encode_decode
|
9
|
+
src = "ABCDEFGabcdefg" * 50
|
10
|
+
assert_equal(src, Zstd.decode(Zstd.encode(src), src.bytesize))
|
11
|
+
#assert_raise(Zstd::Error) { Zstd.decode("", 1111) }
|
12
|
+
d1 = Zstd.encode(src)
|
13
|
+
assert_same(src.tainted?, Zstd.encode(src).tainted?)
|
14
|
+
src1 = src.dup
|
15
|
+
src1.taint
|
16
|
+
assert_same(src1.tainted?, Zstd.encode(src1).tainted?)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_huge
|
20
|
+
src = "ABCDEFGabcdefg" * 10000000
|
21
|
+
assert_equal(Digest::MD5.hexdigest(src), Digest::MD5.hexdigest(Zstd.decode(Zstd.encode(src))))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_huge_stream
|
25
|
+
src = "abcdefghijklmnopqrstuvwxyz" * 1000
|
26
|
+
md5a = Digest::MD5.new
|
27
|
+
d = StringIO.new("")
|
28
|
+
Zstd.encode(d) { |z| 1000.times { z << src; md5a.update src } }
|
29
|
+
d.pos = 0
|
30
|
+
md5b = Digest::MD5.new
|
31
|
+
Zstd.decode(d) { |z| buf = ""; while z.read(654321, buf); md5b.update buf; end }
|
32
|
+
assert_equal(md5a.hexdigest, md5b.hexdigest)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_dictionary
|
36
|
+
dictsrc = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz" * 10
|
37
|
+
dict = Zstd.dict_train_from_buffer(dictsrc, 10000)
|
38
|
+
src = "ABCDEFGabcdefg" * 50
|
39
|
+
assert_equal(src, Zstd.decode(Zstd.encode(src, nil, dict), src.bytesize, dict))
|
40
|
+
end
|
41
|
+
end
|