extzstd 0.0.3.CONCEPT → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/HISTORY.ja.md +39 -0
- data/LICENSE +6 -6
- data/README.md +26 -45
- data/contrib/zstd/CHANGELOG +555 -0
- data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
- data/contrib/zstd/CONTRIBUTING.md +392 -0
- data/contrib/zstd/COPYING +339 -0
- data/contrib/zstd/LICENSE +13 -9
- data/contrib/zstd/Makefile +414 -0
- data/contrib/zstd/README.md +170 -45
- data/contrib/zstd/TESTING.md +44 -0
- data/contrib/zstd/appveyor.yml +289 -0
- data/contrib/zstd/lib/BUCK +234 -0
- data/contrib/zstd/lib/Makefile +354 -0
- data/contrib/zstd/lib/README.md +179 -0
- data/contrib/zstd/{common → lib/common}/bitstream.h +170 -130
- data/contrib/zstd/lib/common/compiler.h +175 -0
- data/contrib/zstd/lib/common/cpu.h +215 -0
- data/contrib/zstd/lib/common/debug.c +24 -0
- data/contrib/zstd/lib/common/debug.h +114 -0
- data/contrib/zstd/{common → lib/common}/entropy_common.c +79 -94
- data/contrib/zstd/lib/common/error_private.c +55 -0
- data/contrib/zstd/lib/common/error_private.h +80 -0
- data/contrib/zstd/{common → lib/common}/fse.h +153 -93
- data/contrib/zstd/{common → lib/common}/fse_decompress.c +37 -82
- data/contrib/zstd/lib/common/huf.h +340 -0
- data/contrib/zstd/{common → lib/common}/mem.h +154 -78
- data/contrib/zstd/lib/common/pool.c +344 -0
- data/contrib/zstd/lib/common/pool.h +84 -0
- data/contrib/zstd/lib/common/threading.c +121 -0
- data/contrib/zstd/lib/common/threading.h +155 -0
- data/contrib/zstd/{common → lib/common}/xxhash.c +85 -75
- data/contrib/zstd/{common → lib/common}/xxhash.h +85 -73
- data/contrib/zstd/lib/common/zstd_common.c +83 -0
- data/contrib/zstd/lib/common/zstd_errors.h +94 -0
- data/contrib/zstd/lib/common/zstd_internal.h +447 -0
- data/contrib/zstd/{compress → lib/compress}/fse_compress.c +194 -303
- data/contrib/zstd/lib/compress/hist.c +183 -0
- data/contrib/zstd/lib/compress/hist.h +75 -0
- data/contrib/zstd/lib/compress/huf_compress.c +798 -0
- data/contrib/zstd/lib/compress/zstd_compress.c +4278 -0
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +1125 -0
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
- data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +419 -0
- data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +845 -0
- data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
- data/contrib/zstd/lib/compress/zstd_cwksp.h +525 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
- data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
- data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
- data/contrib/zstd/lib/compress/zstd_lazy.c +1138 -0
- data/contrib/zstd/lib/compress/zstd_lazy.h +67 -0
- data/contrib/zstd/lib/compress/zstd_ldm.c +619 -0
- data/contrib/zstd/lib/compress/zstd_ldm.h +110 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +1200 -0
- data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
- data/contrib/zstd/lib/compress/zstdmt_compress.c +2143 -0
- data/contrib/zstd/lib/compress/zstdmt_compress.h +192 -0
- data/contrib/zstd/lib/decompress/huf_decompress.c +1248 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
- data/contrib/zstd/lib/decompress/zstd_decompress.c +1885 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1432 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +59 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +189 -0
- data/contrib/zstd/{common → lib/deprecated}/zbuff.h +86 -69
- data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
- data/contrib/zstd/lib/dictBuilder/cover.c +1236 -0
- data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +5 -5
- data/contrib/zstd/lib/dictBuilder/fastcover.c +757 -0
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +437 -347
- data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
- data/contrib/zstd/lib/legacy/zstd_legacy.h +415 -0
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +272 -292
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +162 -392
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +162 -391
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +27 -33
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +195 -604
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +300 -575
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +22 -31
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +165 -592
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +54 -67
- data/contrib/zstd/lib/legacy/zstd_v07.c +4541 -0
- data/contrib/zstd/lib/legacy/zstd_v07.h +187 -0
- data/contrib/zstd/lib/libzstd.pc.in +15 -0
- data/contrib/zstd/lib/zstd.h +2090 -0
- data/ext/depend +2 -0
- data/ext/extconf.rb +18 -5
- data/ext/extzstd.c +296 -214
- data/ext/extzstd.h +81 -36
- data/ext/extzstd_nogvls.h +0 -117
- data/ext/extzstd_stream.c +622 -0
- data/ext/libzstd_conf.h +8 -0
- data/ext/zstd_common.c +11 -0
- data/ext/zstd_compress.c +15 -0
- data/ext/zstd_decompress.c +6 -0
- data/ext/zstd_dictbuilder.c +10 -0
- data/ext/zstd_dictbuilder_fastcover.c +3 -0
- data/ext/zstd_legacy_v01.c +3 -1
- data/ext/zstd_legacy_v02.c +3 -1
- data/ext/zstd_legacy_v03.c +3 -1
- data/ext/zstd_legacy_v04.c +3 -1
- data/ext/zstd_legacy_v05.c +3 -1
- data/ext/zstd_legacy_v06.c +3 -1
- data/ext/zstd_legacy_v07.c +3 -0
- data/gemstub.rb +27 -21
- data/lib/extzstd.rb +82 -161
- data/lib/extzstd/version.rb +1 -1
- data/test/test_basic.rb +19 -6
- metadata +127 -59
- data/contrib/zstd/common/error_private.h +0 -125
- data/contrib/zstd/common/error_public.h +0 -77
- data/contrib/zstd/common/huf.h +0 -228
- data/contrib/zstd/common/zstd.h +0 -475
- data/contrib/zstd/common/zstd_common.c +0 -91
- data/contrib/zstd/common/zstd_internal.h +0 -238
- data/contrib/zstd/compress/huf_compress.c +0 -577
- data/contrib/zstd/compress/zbuff_compress.c +0 -327
- data/contrib/zstd/compress/zstd_compress.c +0 -3074
- data/contrib/zstd/compress/zstd_opt.h +0 -1046
- data/contrib/zstd/decompress/huf_decompress.c +0 -894
- data/contrib/zstd/decompress/zbuff_decompress.c +0 -294
- data/contrib/zstd/decompress/zstd_decompress.c +0 -1362
- data/contrib/zstd/dictBuilder/zdict.h +0 -113
- data/contrib/zstd/legacy/zstd_legacy.h +0 -140
- data/ext/extzstd_buffered.c +0 -265
- data/ext/zstd_amalgam.c +0 -18
data/ext/libzstd_conf.h
ADDED
data/ext/zstd_common.c
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#include "libzstd_conf.h"
|
2
|
+
|
3
|
+
#include "../contrib/zstd/lib/common/entropy_common.c"
|
4
|
+
#include "../contrib/zstd/lib/common/error_private.c"
|
5
|
+
#include "../contrib/zstd/lib/common/fse_decompress.c"
|
6
|
+
|
7
|
+
#undef CHECK_F
|
8
|
+
#include "../contrib/zstd/lib/common/pool.c"
|
9
|
+
#include "../contrib/zstd/lib/common/threading.c"
|
10
|
+
#include "../contrib/zstd/lib/common/xxhash.c"
|
11
|
+
#include "../contrib/zstd/lib/common/zstd_common.c"
|
data/ext/zstd_compress.c
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "libzstd_conf.h"
|
2
|
+
|
3
|
+
#include "../contrib/zstd/lib/compress/fse_compress.c"
|
4
|
+
#include "../contrib/zstd/lib/compress/huf_compress.c"
|
5
|
+
|
6
|
+
#undef CHECK_F
|
7
|
+
#include "../contrib/zstd/lib/compress/zstd_compress.c"
|
8
|
+
#include "../contrib/zstd/lib/compress/zstd_compress_literals.c"
|
9
|
+
#include "../contrib/zstd/lib/compress/zstd_compress_sequences.c"
|
10
|
+
#include "../contrib/zstd/lib/compress/zstd_double_fast.c"
|
11
|
+
#include "../contrib/zstd/lib/compress/zstd_fast.c"
|
12
|
+
#include "../contrib/zstd/lib/compress/zstd_lazy.c"
|
13
|
+
#include "../contrib/zstd/lib/compress/zstd_ldm.c"
|
14
|
+
#include "../contrib/zstd/lib/compress/zstd_opt.c"
|
15
|
+
#include "../contrib/zstd/lib/compress/hist.c"
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#include "libzstd_conf.h"
|
2
|
+
|
3
|
+
#include "../contrib/zstd/lib/decompress/zstd_decompress.c"
|
4
|
+
#include "../contrib/zstd/lib/decompress/zstd_decompress_block.c"
|
5
|
+
#include "../contrib/zstd/lib/decompress/huf_decompress.c"
|
6
|
+
#include "../contrib/zstd/lib/decompress/zstd_ddict.c"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#include "libzstd_conf.h"
|
2
|
+
|
3
|
+
#include "../contrib/zstd/lib/dictBuilder/zdict.c"
|
4
|
+
#include "../contrib/zstd/lib/dictBuilder/divsufsort.c"
|
5
|
+
|
6
|
+
#undef DISPLAY
|
7
|
+
#undef DISPLAYLEVEL
|
8
|
+
#undef DISPLAYUPDATE
|
9
|
+
#define prime4bytes cover_prime4bytes
|
10
|
+
#include "../contrib/zstd/lib/dictBuilder/cover.c"
|
data/ext/zstd_legacy_v01.c
CHANGED
data/ext/zstd_legacy_v02.c
CHANGED
data/ext/zstd_legacy_v03.c
CHANGED
data/ext/zstd_legacy_v04.c
CHANGED
data/ext/zstd_legacy_v05.c
CHANGED
data/ext/zstd_legacy_v06.c
CHANGED
data/gemstub.rb
CHANGED
@@ -1,35 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
1
|
+
verreg = /^\s*\*\s+version:\s*(\d+(?:\.\w+)+)\s*$/i
|
2
|
+
unless File.read("README.md", mode: "rt") =~ verreg
|
3
|
+
raise "``version'' is not defined or bad syntax in ``README.md''"
|
15
4
|
end
|
16
5
|
|
17
|
-
|
6
|
+
version = String($1)
|
18
7
|
|
19
8
|
GEMSTUB = Gem::Specification.new do |s|
|
20
9
|
s.name = "extzstd"
|
21
|
-
s.version =
|
10
|
+
s.version = version
|
22
11
|
s.summary = "ruby bindings for Zstandard (zstd)"
|
23
12
|
s.description = <<EOS
|
24
|
-
unoficial ruby bindings for Zstandard (zstd) <https://github.com/
|
13
|
+
unoficial ruby bindings for Zstandard (zstd) <https://github.com/facebook/zstd>.
|
25
14
|
EOS
|
26
|
-
s.homepage = "https://
|
27
|
-
s.license = "2-
|
15
|
+
s.homepage = "https://github.com/dearblue/ruby-extzstd/"
|
16
|
+
s.license = "BSD-2-Clause"
|
28
17
|
s.author = "dearblue"
|
29
|
-
s.email = "dearblue@users.
|
18
|
+
s.email = "dearblue@users.noreply.github.com"
|
30
19
|
|
31
20
|
s.required_ruby_version = ">= 2.0"
|
32
|
-
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "rake", ">= 12.0"
|
22
|
+
end
|
23
|
+
|
24
|
+
LIB << "lib/extzstd/version.rb"
|
25
|
+
|
26
|
+
file "lib/extzstd/version.rb" => %w(README.md) do
|
27
|
+
GEMSTUB.version = version
|
28
|
+
|
29
|
+
mkpath "lib/extzstd"
|
30
|
+
File.write "lib/extzstd/version.rb", <<-"EOS", mode: "wb"
|
31
|
+
module Zstd
|
32
|
+
VERSION = #{version.inspect}
|
33
|
+
end
|
34
|
+
EOS
|
33
35
|
end
|
34
36
|
|
35
37
|
EXTRA.concat(FileList["contrib/**/*"])
|
38
|
+
|
39
|
+
filter = %r(contrib/zstd/(?:build|contrib|doc|examples|lib/dll|programs|tests|zlibWrapper))
|
40
|
+
DOC.reject! { |path| path =~ filter }
|
41
|
+
EXTRA.reject! { |path| path =~ filter }
|
data/lib/extzstd.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ver = RUBY_VERSION.slice(/\d+\.\d+/)
|
4
4
|
soname = File.basename(__FILE__, ".rb") << ".so"
|
5
|
-
|
5
|
+
require File.join(ver, soname)
|
6
6
|
|
7
7
|
require_relative "extzstd/version"
|
8
8
|
|
@@ -12,44 +12,82 @@ require "stringio"
|
|
12
12
|
# This is ruby bindings for zstd <https://github.com/Cyan4973/zstd> the compression library.
|
13
13
|
#
|
14
14
|
module Zstd
|
15
|
+
module Internals
|
16
|
+
unless String.method_defined? :b
|
17
|
+
refine String do
|
18
|
+
def b
|
19
|
+
dup.force_encoding(Encoding::BINARY)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
using Internals
|
26
|
+
|
27
|
+
refine String do
|
28
|
+
def to_zstd(params = nil, dict: nil)
|
29
|
+
ContextLess.encode(self, "".b, nil, dict, params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def unzstd(size = nil, dict: nil)
|
33
|
+
Decoder.open(self, dict) { |d| return d.read(size) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
refine Object do
|
38
|
+
def to_zstd(params = nil, dict: nil, &block)
|
39
|
+
Encoder.open(self, params, dict, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def unzstd(dict: nil, &block)
|
43
|
+
Decoder.open(self, dict, &block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
using Zstd
|
48
|
+
|
15
49
|
#
|
16
50
|
# call-seq:
|
17
|
-
# encode(src_string, level = nil,
|
18
|
-
# encode(src_string,
|
19
|
-
# encode(outport, level = nil,
|
20
|
-
# encode(outport, level = nil,
|
21
|
-
# encode(outport,
|
22
|
-
# encode(outport,
|
51
|
+
# encode(src_string, level = nil, opts = {}) -> zstd string
|
52
|
+
# encode(src_string, encode_params, opts = {}) -> zstd string
|
53
|
+
# encode(outport, level = nil, opts = {}) -> zstd encoder
|
54
|
+
# encode(outport, level = nil, opts = {}) { |encoder| ... } -> yield returned value
|
55
|
+
# encode(outport, encode_params, opts = {}) -> zstd encoder
|
56
|
+
# encode(outport, encode_params, opts = {}) { |encoder| ... } -> yield returned value
|
23
57
|
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
58
|
+
# [src_string (string)]
|
59
|
+
# [outport (io liked object)]
|
60
|
+
# [level = nil (integer or nil)]
|
61
|
+
# [encode_params (instance of Zstd::Parameters)]
|
62
|
+
# [opts dict: nil (string or nil)]
|
63
|
+
def self.encode(src, *args, **opts, &block)
|
64
|
+
src.to_zstd(*args, **opts, &block)
|
31
65
|
end
|
32
66
|
|
33
67
|
#
|
34
68
|
# call-seq:
|
35
|
-
# decode(zstd_string, maxsize = nil, dict
|
36
|
-
# decode(zstd_stream,
|
37
|
-
# decode(zstd_stream,
|
69
|
+
# decode(zstd_string, maxsize = nil, dict: nil) -> string
|
70
|
+
# decode(zstd_stream, dict: nil) -> zstd decoder
|
71
|
+
# decode(zstd_stream, dict: nil) { |decoder| ... } -> yield returned value
|
38
72
|
#
|
39
|
-
def self.decode(src,
|
40
|
-
|
41
|
-
|
42
|
-
return Decoder.open(src, dict) { |d| return d.read(maxsize) }
|
43
|
-
end
|
73
|
+
def self.decode(src, *args, **opts, &block)
|
74
|
+
src.unzstd(*args, **opts, &block)
|
75
|
+
end
|
44
76
|
|
45
|
-
|
77
|
+
class << Zstd
|
78
|
+
alias compress encode
|
79
|
+
alias decompress decode
|
80
|
+
alias uncompress decode
|
46
81
|
end
|
47
82
|
|
48
|
-
|
83
|
+
Compressor = Encoder
|
84
|
+
StreamEncoder = Encoder
|
85
|
+
|
86
|
+
class Encoder
|
49
87
|
#
|
50
88
|
# call-seq:
|
51
89
|
# open(outport, level = nil, dict = nil) -> zstd encoder
|
52
|
-
# open(outport,
|
90
|
+
# open(outport, encode_params, dict = nil) { |encoder| ... } -> yield returned value
|
53
91
|
#
|
54
92
|
def self.open(outport, *args)
|
55
93
|
e = new(outport, *args)
|
@@ -59,68 +97,24 @@ module Zstd
|
|
59
97
|
begin
|
60
98
|
yield e
|
61
99
|
ensure
|
62
|
-
e.close
|
100
|
+
e.close unless e.eof?
|
63
101
|
end
|
64
102
|
end
|
65
103
|
|
66
|
-
|
67
|
-
|
68
|
-
# initialize(outport, level = nil, dict = nil)
|
69
|
-
# initialize(outport, encoder_params, dict = nil)
|
70
|
-
#
|
71
|
-
# +outport+ need has +.<<+ method.
|
72
|
-
#
|
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
|
+
def self.encode(src, params = nil, dest: nil, dict: nil)
|
105
|
+
ContextLess.encode(src, dest || "".b, nil, dict, params)
|
104
106
|
end
|
105
107
|
|
106
|
-
|
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
|
108
|
+
class << Encoder
|
109
|
+
alias compress encode
|
116
110
|
end
|
117
111
|
end
|
118
112
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
STATUS_INPORT_EOF = 1
|
113
|
+
Uncompressor = Decoder
|
114
|
+
Decompressor = Decoder
|
115
|
+
StreamDecoder = Decoder
|
123
116
|
|
117
|
+
class Decoder
|
124
118
|
#
|
125
119
|
# call-seq:
|
126
120
|
# open(inport, dict = nil) -> decoder
|
@@ -143,77 +137,20 @@ module Zstd
|
|
143
137
|
end
|
144
138
|
end
|
145
139
|
|
146
|
-
def
|
147
|
-
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
def close
|
152
|
-
decoder.reset
|
153
|
-
inport.close rescue nil if inport.respond_to?(:close)
|
154
|
-
readbuf.clear
|
155
|
-
#destbuf.clear
|
156
|
-
self.status = STATUS_CLOSED
|
157
|
-
nil
|
158
|
-
end
|
159
|
-
|
160
|
-
def eof
|
161
|
-
!status
|
162
|
-
end
|
163
|
-
|
164
|
-
alias eof? eof
|
165
|
-
|
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
|
171
|
-
|
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
|
178
|
-
end
|
140
|
+
def self.decode(src, dest: nil, dict: nil)
|
141
|
+
# NOTE: ContextLess.decode は伸長時のサイズが必要なため、常に利用できるわけではない
|
142
|
+
# ContextLess.decode(src, dest || "".b, nil, dict)
|
179
143
|
|
180
|
-
|
181
|
-
dest << d
|
182
|
-
|
183
|
-
size -= d.bytesize if size
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
if dest.empty?
|
188
|
-
nil
|
189
|
-
else
|
190
|
-
dest
|
191
|
-
end
|
144
|
+
new(StringIO.new(src), dict).read(nil, dest)
|
192
145
|
end
|
193
146
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
while true
|
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
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
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
|
212
|
-
end
|
147
|
+
class << Decoder
|
148
|
+
alias decompress decode
|
149
|
+
alias uncompress decode
|
213
150
|
end
|
214
151
|
end
|
215
152
|
|
216
|
-
class
|
153
|
+
class Parameters
|
217
154
|
def inspect
|
218
155
|
"#<#{self.class} windowlog=#{windowlog}, chainlog=#{chainlog}, " \
|
219
156
|
"hashlog=#{hashlog}, searchlog=#{searchlog}, " \
|
@@ -233,26 +170,10 @@ module Zstd
|
|
233
170
|
q.breakable " "
|
234
171
|
q.text "searchlength=#{searchlength},"
|
235
172
|
q.breakable " "
|
173
|
+
q.text "targetlength=#{targetlength},"
|
174
|
+
q.breakable " "
|
236
175
|
q.text "strategy=#{strategy}>"
|
237
176
|
end
|
238
177
|
end
|
239
178
|
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
|
258
179
|
end
|