extlzma2 2.0.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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rspec_status +17 -0
- data/.rubocop.yml +42 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +37 -0
- data/LICENSE +26 -0
- data/README.md +9 -0
- data/Rakefile +15 -0
- data/ext/extlzma2/consts.c +66 -0
- data/ext/extlzma2/error.c +87 -0
- data/ext/extlzma2/extconf.rb +27 -0
- data/ext/extlzma2/extlzma2.c +89 -0
- data/ext/extlzma2/extlzma2.h +171 -0
- data/ext/extlzma2/filter.c +530 -0
- data/ext/extlzma2/index.c +66 -0
- data/ext/extlzma2/stream.c +440 -0
- data/ext/extlzma2/utils.c +93 -0
- data/extlzma2.gemspec +27 -0
- data/lib/extlzma2/aux.rb +42 -0
- data/lib/extlzma2/decoder.rb +73 -0
- data/lib/extlzma2/encoder.rb +82 -0
- data/lib/extlzma2/filter.rb +17 -0
- data/lib/extlzma2/stream.rb +49 -0
- data/lib/extlzma2/utils.rb +104 -0
- data/lib/extlzma2/version.rb +5 -0
- data/lib/extlzma2.rb +148 -0
- metadata +71 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
module LZMA
|
6
|
+
Encoder = Struct.new(:context, :outport, :writebuf, :workbuf, :status) do |klass|
|
7
|
+
klass::BLOCKSIZE = 256 * 1024 # 256 KiB
|
8
|
+
|
9
|
+
def initialize(context, outport)
|
10
|
+
super(context, outport, StringIO.new(String.new), String.new, [1])
|
11
|
+
self.class.method(:finalizer_regist).call(self, context, outport, writebuf, workbuf, status)
|
12
|
+
end
|
13
|
+
|
14
|
+
def write(buf)
|
15
|
+
writebuf.rewind
|
16
|
+
writebuf.string.clear
|
17
|
+
writebuf << buf
|
18
|
+
until writebuf.string.empty?
|
19
|
+
s = context.code(writebuf.string, workbuf, self.class::BLOCKSIZE, 0)
|
20
|
+
Utils.raise_err s unless s == 0
|
21
|
+
outport << workbuf
|
22
|
+
workbuf.clear
|
23
|
+
end
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method :<<, :write
|
29
|
+
|
30
|
+
def close
|
31
|
+
raise "already closed stream - #{inspect}" if eof?
|
32
|
+
|
33
|
+
self.class.method(:finalizer_close).call(context, outport, workbuf)
|
34
|
+
|
35
|
+
status[0] = nil
|
36
|
+
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def eof
|
41
|
+
!status[0]
|
42
|
+
end
|
43
|
+
|
44
|
+
alias_method :eof?, :eof
|
45
|
+
|
46
|
+
class << self
|
47
|
+
private
|
48
|
+
|
49
|
+
def finalizer_regist(obj, context, outport, writebuf, workbuf, status)
|
50
|
+
ObjectSpace.define_finalizer(obj, finalizer_make(context, outport, writebuf, workbuf, status))
|
51
|
+
end
|
52
|
+
|
53
|
+
def finalizer_make(context, outport, writebuf, workbuf, status)
|
54
|
+
proc do
|
55
|
+
if status[0]
|
56
|
+
until writebuf.string.empty?
|
57
|
+
s = context.code(writebuf.string, workbuf, self::BLOCKSIZE, 0)
|
58
|
+
Utils.raise_err s unless s == LZMA::OK
|
59
|
+
outport << workbuf
|
60
|
+
workbuf.clear
|
61
|
+
end
|
62
|
+
|
63
|
+
finalizer_close(context, outport, workbuf)
|
64
|
+
|
65
|
+
status[0] = nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def finalizer_close(context, outport, workbuf)
|
71
|
+
loop do
|
72
|
+
workbuf.clear
|
73
|
+
s = context.code(nil, workbuf, self::BLOCKSIZE, LZMA::FINISH)
|
74
|
+
outport << workbuf
|
75
|
+
break if s == LZMA::STREAM_END
|
76
|
+
|
77
|
+
Utils.raise_err s unless s == LZMA::OK
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LZMA
|
4
|
+
class Stream
|
5
|
+
def self.encoder(*args, **opts)
|
6
|
+
if args.empty?
|
7
|
+
Encoder.new(Filter::LZMA2.new(LZMA::PRESET_DEFAULT), **opts)
|
8
|
+
elsif args.size == 1 && args[0].is_a?(Numeric)
|
9
|
+
Encoder.new(Filter::LZMA2.new(args[0]), **opts)
|
10
|
+
else
|
11
|
+
Encoder.new(*args, **opts)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.decoder(*args)
|
16
|
+
if args.empty?
|
17
|
+
Decoder.new(Filter::LZMA2.new(LZMA::PRESET_DEFAULT))
|
18
|
+
elsif args.size == 1 && args[0].is_a?(Numeric)
|
19
|
+
Decoder.new(Filter::LZMA2.new(args[0]))
|
20
|
+
else
|
21
|
+
Decoder.new(*args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.auto_decoder(*args)
|
26
|
+
AutoDecoder.new(*args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.raw_encoder(*args)
|
30
|
+
if args.empty?
|
31
|
+
RawEncoder.new(Filter::LZMA2.new(LZMA::PRESET_DEFAULT))
|
32
|
+
elsif args.size == 1 && args[0].is_a?(Numeric)
|
33
|
+
RawEncoder.new(Filter::LZMA2.new(args[0]))
|
34
|
+
else
|
35
|
+
RawEncoder.new(*args)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.raw_decoder(*args)
|
40
|
+
if args.empty?
|
41
|
+
RawDecoder.new(Filter::LZMA2.new(LZMA::PRESET_DEFAULT))
|
42
|
+
elsif args.size == 1 && args[0].is_a?(Numeric)
|
43
|
+
RawDecoder.new(Filter::LZMA2.new(args[0]))
|
44
|
+
else
|
45
|
+
RawDecoder.new(*args)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LZMA
|
4
|
+
module Utils
|
5
|
+
def self.crc32_digest(seq, init = 0)
|
6
|
+
[Utils.crc32(seq, init)].pack('N')
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.crc32_hexdigest(seq, init = 0)
|
10
|
+
format('%08X', Utils.crc32(seq, init))
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.crc64_digest(seq, init = 0)
|
14
|
+
[Utils.crc64(seq, init)].pack('Q>')
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.crc64_hexdigest(seq, init = 0)
|
18
|
+
format('%016X', Utils.crc64(seq, init))
|
19
|
+
end
|
20
|
+
|
21
|
+
CRC32 = Struct.new(:state, :init) do
|
22
|
+
def initialize(state = 0)
|
23
|
+
state = state.to_i
|
24
|
+
super(state, state)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(data)
|
28
|
+
self.state = Utils.crc32(data, state)
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :<<, :update
|
33
|
+
|
34
|
+
def finish
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def reset
|
39
|
+
self.state = init
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def digest
|
44
|
+
[state].pack('N')
|
45
|
+
end
|
46
|
+
|
47
|
+
def hexdigest
|
48
|
+
format('%08x', state)
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method :to_s, :hexdigest
|
52
|
+
|
53
|
+
def to_str
|
54
|
+
"CRC32 <#{hexdigest}>"
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :inspect, :to_str
|
58
|
+
end
|
59
|
+
|
60
|
+
CRC64 = Struct.new(:state, :init) do
|
61
|
+
def initialize(state = 0)
|
62
|
+
state = state.to_i
|
63
|
+
super(state, state)
|
64
|
+
end
|
65
|
+
|
66
|
+
def update(data)
|
67
|
+
self.state = Utils.crc64(data, state)
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
alias_method :<<, :update
|
72
|
+
|
73
|
+
def finish
|
74
|
+
self
|
75
|
+
end
|
76
|
+
|
77
|
+
def reset
|
78
|
+
self.state = init
|
79
|
+
self
|
80
|
+
end
|
81
|
+
|
82
|
+
def digest
|
83
|
+
[state].pack('Q>')
|
84
|
+
end
|
85
|
+
|
86
|
+
def hexdigest
|
87
|
+
'%016x' % state
|
88
|
+
end
|
89
|
+
|
90
|
+
alias_method :to_s, :hexdigest
|
91
|
+
|
92
|
+
def to_str
|
93
|
+
"CRC64 <#{hexdigest}>"
|
94
|
+
end
|
95
|
+
|
96
|
+
alias_method :inspect, :to_str
|
97
|
+
end
|
98
|
+
|
99
|
+
def raise_err(lzma_ret, mesg = nil)
|
100
|
+
et = Utils.lookup_error(lzma_ret)
|
101
|
+
raise et, mesg, caller
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/extlzma2.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'extlzma2/aux'
|
4
|
+
require_relative 'extlzma2/decoder'
|
5
|
+
require_relative 'extlzma2/encoder'
|
6
|
+
require_relative 'extlzma2/filter'
|
7
|
+
require_relative 'extlzma2/stream'
|
8
|
+
require_relative 'extlzma2/utils'
|
9
|
+
require_relative 'extlzma2/extlzma2'
|
10
|
+
require_relative 'extlzma2/version'
|
11
|
+
|
12
|
+
module LZMA
|
13
|
+
#
|
14
|
+
# call-seq:
|
15
|
+
# encode(string_data, preset = LZMA::PRESET_DEFAULT, opts = {}) -> encoded_xz_data
|
16
|
+
# encode(string_data, filter...) -> encoded_xz_data
|
17
|
+
# encode(output_stream = nil, preset = LZMA::PRESET_DEFAULT, opts = {}) -> stream_encoder
|
18
|
+
# encode(output_stream, filter...) -> stream_encoder
|
19
|
+
# encode(output_stream = nil, preset = LZMA::PRESET_DEFAULT, opts = {}) { |encoder| ... } -> yield return value
|
20
|
+
# encode(output_stream, filter...) { |encoder| ... } -> yield return value
|
21
|
+
#
|
22
|
+
# データを圧縮、または圧縮器を生成します。
|
23
|
+
#
|
24
|
+
# 圧縮されたデータ列は xz ファイルフォーマットとなるため、コマンドラインの xz などで伸張させることが可能です。
|
25
|
+
#
|
26
|
+
# [RETURN encoded_xz_data]
|
27
|
+
# xz データストリームとしての String インスタンスです。
|
28
|
+
# [RETURN stream_encoder]
|
29
|
+
# xz データストリームを生成する圧縮器を返します。
|
30
|
+
# [RETURN output_stream]
|
31
|
+
# 引数として渡した <tt>output_stream</tt> そのものを返します。
|
32
|
+
# [string_data]
|
33
|
+
# 圧縮元となるデータを String インスタンスで渡します。
|
34
|
+
# liblzma はエンコーディング情報を無視し、そのままのバイト列をバイナリデータと見立て処理を行います。
|
35
|
+
# [preset = LZMA::PRESET_DEFAULT]
|
36
|
+
# 圧縮プリセット値を指定します (圧縮レベルのようなものです)。詳細は LZMA::Filter::LZMA2.new を見てください。
|
37
|
+
# [opts]
|
38
|
+
# LZMA::Filter::LZMA2.new に渡される可変引数です。詳細は LZMA::Filter::LZMA2.new を見てください。
|
39
|
+
# [filter]
|
40
|
+
# LZMA::Filter で定義されているクラスのインスタンスを指定します。最大4つまで指定することが出来ます。
|
41
|
+
# [output_stream]
|
42
|
+
# 圧縮データの受け皿となるオブジェクトを指定します。
|
43
|
+
#
|
44
|
+
# <tt>.<<</tt> メソッドが呼ばれます。
|
45
|
+
# [YIELD RETURN]
|
46
|
+
# 無視されます。
|
47
|
+
# [YIELD encoder]
|
48
|
+
# 圧縮器が渡されます。
|
49
|
+
#
|
50
|
+
# [EXCEPTIONS]
|
51
|
+
# (NO DOCUMENT)
|
52
|
+
#
|
53
|
+
def self.encode(src = nil, *args, &block)
|
54
|
+
Aux.encode(src, Stream.encoder(*args), &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# call-seq:
|
59
|
+
# decode(string_data) -> decoded data
|
60
|
+
# decode(string_data, filter...) -> decoded data
|
61
|
+
# decode(input_stream) -> decoder
|
62
|
+
# decode(input_stream, filter...) -> decoder
|
63
|
+
# decode(input_stream) { |decoder| ... }-> yield return value
|
64
|
+
# decode(input_stream, filter...) { |decoder| ... }-> yield return value
|
65
|
+
#
|
66
|
+
# 圧縮されたデータを伸張します。
|
67
|
+
#
|
68
|
+
# [RETURN decoded data]
|
69
|
+
# xz データストリームとしての String インスタンスです。
|
70
|
+
# [RETURN decoder]
|
71
|
+
# [RETURN yield return value]
|
72
|
+
# [string_data]
|
73
|
+
# 圧縮されたデータを与えます。圧縮されたデータの形式は xz と lzma です。これらはあらかじめ区別する必要なく与えることが出来ます。
|
74
|
+
# [options]
|
75
|
+
# LZMA::Filter::LZMA2.new に渡される可変引数です。詳細は LZMA::Filter::LZMA2.new を見てください。
|
76
|
+
# [EXCEPTIONS]
|
77
|
+
# (NO DOCUMENT)
|
78
|
+
#
|
79
|
+
def self.decode(src, *args, &block)
|
80
|
+
Aux.decode(src, Stream.auto_decoder(*args), &block)
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# call-seq:
|
85
|
+
# LZMA.raw_encode(src) -> encoded data
|
86
|
+
# LZMA.raw_encode(src, filter...) -> encoded data
|
87
|
+
# LZMA.raw_encode(outport = nil) -> encoder
|
88
|
+
# LZMA.raw_encode(outport, filter...) -> encoder
|
89
|
+
# LZMA.raw_encode(outport = nil) { |encoder| ... } -> yield return value
|
90
|
+
# LZMA.raw_encode(outport, filter...) { |encoder| ... } -> yield return value
|
91
|
+
#
|
92
|
+
# データを圧縮します。圧縮されたデータ列は生の lzma1/lzma2 のデータ列であるため、伸張する際に適切なフィルタを与える必要があります。
|
93
|
+
#
|
94
|
+
# xz ファイルフォーマットヘッダや整合値を持たないため、これらが不要な場合は有用かもしれません。
|
95
|
+
#
|
96
|
+
# [RETURN encoded data]
|
97
|
+
# 生の lzma1/lzma2 のデータ列となる String インスタンスです。
|
98
|
+
# [src]
|
99
|
+
# 圧縮元となるデータを String インスタンスで渡します。
|
100
|
+
# [filter]
|
101
|
+
# LZMA::Filter のインスタンスを与えます。最大4つまで指定可能です。
|
102
|
+
#
|
103
|
+
# 省略時は lzma2 フィルタが指定されたとみなします。
|
104
|
+
# [EXCEPTIONS]
|
105
|
+
# (NO DOCUMENT)
|
106
|
+
#
|
107
|
+
def self.raw_encode(src, *args, &block)
|
108
|
+
Aux.encode(src, Stream.raw_encoder(*args), &block)
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# call-seq:
|
113
|
+
# LZMA.raw_decode(encoded_data) -> decoded data
|
114
|
+
# LZMA.raw_decode(encoded_data, filter...) -> decoded data
|
115
|
+
# LZMA.raw_decode(inport) -> raw decoder
|
116
|
+
# LZMA.raw_decode(inport, filter...) -> raw decoder
|
117
|
+
# LZMA.raw_decode(inport) { |decoder| ... } -> yield return value
|
118
|
+
# LZMA.raw_decode(inport, filter...) { |decoder| ... } -> yield return value
|
119
|
+
#
|
120
|
+
# 圧縮されたデータを伸張します。圧縮した際に用いたフィルタをそのままの順番・数で与える必要があります。
|
121
|
+
#
|
122
|
+
# [RETURN decoded data]
|
123
|
+
# 伸張されたデータ列となる String インスタンスです。
|
124
|
+
# [src]
|
125
|
+
# 圧縮された生の lzma1/lzma2 の String インスタンスを渡します。
|
126
|
+
# [options]
|
127
|
+
# LZMA::Filter のインスタンスを与えます。最大4つまで指定可能です。
|
128
|
+
#
|
129
|
+
# 省略時は lzma2 フィルタが指定されたとみなします。
|
130
|
+
# [EXCEPTIONS]
|
131
|
+
# (NO DOCUMENT)
|
132
|
+
#
|
133
|
+
def self.raw_decode(src, *args, &block)
|
134
|
+
Aux.decode(src, Stream.raw_decoder(*args), &block)
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.lzma1(*args)
|
138
|
+
LZMA::Filter::LZMA1.new(*args)
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.lzma2(*args)
|
142
|
+
LZMA::Filter::LZMA2.new(*args)
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.delta(*args)
|
146
|
+
LZMA::Filter::Delta.new(*args)
|
147
|
+
end
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extlzma2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ishotihadus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby binding of liblzma that is compatible with Ruby 3.2
|
14
|
+
email:
|
15
|
+
- hanachan.pao@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- ext/extlzma2/extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rspec"
|
22
|
+
- ".rspec_status"
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- ext/extlzma2/consts.c
|
30
|
+
- ext/extlzma2/error.c
|
31
|
+
- ext/extlzma2/extconf.rb
|
32
|
+
- ext/extlzma2/extlzma2.c
|
33
|
+
- ext/extlzma2/extlzma2.h
|
34
|
+
- ext/extlzma2/filter.c
|
35
|
+
- ext/extlzma2/index.c
|
36
|
+
- ext/extlzma2/stream.c
|
37
|
+
- ext/extlzma2/utils.c
|
38
|
+
- extlzma2.gemspec
|
39
|
+
- lib/extlzma2.rb
|
40
|
+
- lib/extlzma2/aux.rb
|
41
|
+
- lib/extlzma2/decoder.rb
|
42
|
+
- lib/extlzma2/encoder.rb
|
43
|
+
- lib/extlzma2/filter.rb
|
44
|
+
- lib/extlzma2/stream.rb
|
45
|
+
- lib/extlzma2/utils.rb
|
46
|
+
- lib/extlzma2/version.rb
|
47
|
+
homepage: https://github.com/Ishotihadus/extlzma2
|
48
|
+
licenses: []
|
49
|
+
metadata:
|
50
|
+
homepage_uri: https://github.com/Ishotihadus/extlzma2
|
51
|
+
source_code_uri: https://github.com/Ishotihadus/extlzma2
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.6.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.4.0.dev
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: A Ruby binding of liblzma
|
71
|
+
test_files: []
|