rbzip2 0.2.0 → 0.3.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/LICENSE +1 -1
- data/README.md +73 -37
- data/Rakefile +2 -0
- data/lib/core_ext/io.rb +12 -0
- data/lib/rbzip2.rb +13 -9
- data/lib/rbzip2/adapter.rb +17 -0
- data/lib/rbzip2/ffi.rb +33 -0
- data/lib/rbzip2/ffi/compressor.rb +85 -0
- data/lib/rbzip2/ffi/constants.rb +30 -0
- data/lib/rbzip2/ffi/decompressor.rb +163 -0
- data/lib/rbzip2/ffi/errors.rb +14 -0
- data/lib/rbzip2/io.rb +19 -5
- data/lib/rbzip2/java.rb +23 -0
- data/lib/rbzip2/java/compressor.rb +38 -0
- data/lib/rbzip2/java/decompressor.rb +65 -0
- data/lib/rbzip2/ruby.rb +18 -0
- data/lib/rbzip2/{compressor.rb → ruby/compressor.rb} +141 -191
- data/lib/rbzip2/{constants.rb → ruby/constants.rb} +2 -2
- data/lib/rbzip2/ruby/crc.rb +70 -0
- data/lib/rbzip2/{decompressor.rb → ruby/decompressor.rb} +107 -127
- data/lib/rbzip2/{input_data.rb → ruby/input_data.rb} +8 -18
- data/lib/rbzip2/{output_data.rb → ruby/output_data.rb} +6 -9
- data/lib/rbzip2/version.rb +2 -2
- data/spec/common/compressor_spec.rb +68 -0
- data/spec/common/decompressor_spec.rb +63 -0
- data/spec/ffi/compressor_spec.rb +12 -0
- data/spec/ffi/decompressor_spec.rb +12 -0
- data/spec/java/compressor_spec.rb +12 -0
- data/spec/java/decompressor_spec.rb +12 -0
- data/spec/ruby/compressor_spec.rb +12 -0
- data/spec/ruby/decompressor_spec.rb +12 -0
- metadata +56 -149
- data/.gemtest +0 -0
- data/.gitignore +0 -3
- data/.travis.yml +0 -9
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -28
- data/lib/rbzip2/crc.rb +0 -105
- data/rbzip2.gemspec +0 -27
- data/spec/compressor_spec.rb +0 -42
- data/spec/decompressor_spec.rb +0 -41
- data/spec/fixtures/big_test.bz2 +0 -0
- data/spec/fixtures/big_test.txt +0 -2018
- data/spec/fixtures/test.bz2 +0 -0
- data/spec/fixtures/test.txt +0 -11
- data/spec/helper.rb +0 -12
@@ -1,9 +1,9 @@
|
|
1
1
|
# This code is free software; you can redistribute it and/or modify it under
|
2
2
|
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2011, Sebastian Staudt
|
4
|
+
# Copyright (c) 2011-2013, Sebastian Staudt
|
5
5
|
|
6
|
-
module RBzip2::Constants
|
6
|
+
module RBzip2::Ruby::Constants
|
7
7
|
|
8
8
|
BASEBLOCKSIZE = 100000
|
9
9
|
MAX_ALPHA_SIZE = 258
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2011-2017, Sebastian Staudt
|
5
|
+
|
6
|
+
class RBzip2::Ruby::CRC
|
7
|
+
|
8
|
+
CRC32_TABLE = [
|
9
|
+
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
|
10
|
+
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
11
|
+
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
|
12
|
+
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
13
|
+
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
|
14
|
+
0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
|
15
|
+
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
|
16
|
+
0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
17
|
+
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
|
18
|
+
0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
|
19
|
+
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
|
20
|
+
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
21
|
+
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
|
22
|
+
0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
|
23
|
+
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
|
24
|
+
0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
25
|
+
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
|
26
|
+
0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
|
27
|
+
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
|
28
|
+
0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
29
|
+
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
|
30
|
+
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
|
31
|
+
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
|
32
|
+
0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
33
|
+
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
|
34
|
+
0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
|
35
|
+
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
|
36
|
+
0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
37
|
+
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
|
38
|
+
0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
|
39
|
+
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
|
40
|
+
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
41
|
+
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
|
42
|
+
0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
|
43
|
+
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
|
44
|
+
0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
45
|
+
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
|
46
|
+
0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
|
47
|
+
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
|
48
|
+
0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
49
|
+
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
|
50
|
+
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
|
51
|
+
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
|
52
|
+
]
|
53
|
+
|
54
|
+
def initialize
|
55
|
+
initialize_crc
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize_crc
|
59
|
+
@global_crc = 0xffffffff
|
60
|
+
end
|
61
|
+
|
62
|
+
def final_crc
|
63
|
+
@global_crc ^ 0xffffffff
|
64
|
+
end
|
65
|
+
|
66
|
+
def update_crc(in_ch)
|
67
|
+
@global_crc = ((@global_crc << 8) & 0xffffffff) ^ CRC32_TABLE[(@global_crc >> 24) ^ in_ch]
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
# This code is free software; you can redistribute it and/or modify it under
|
2
2
|
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2011, Sebastian Staudt
|
4
|
+
# Copyright (c) 2011-2017, Sebastian Staudt
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'core_ext/io'
|
7
7
|
|
8
|
-
class RBzip2::Decompressor
|
8
|
+
class RBzip2::Ruby::Decompressor
|
9
9
|
|
10
|
-
include RBzip2::Constants
|
10
|
+
include RBzip2::Ruby::Constants
|
11
11
|
|
12
12
|
def initialize(io)
|
13
13
|
@buff = 0
|
14
14
|
@bytes_read = 0
|
15
15
|
@computed_combined_crc = 0
|
16
|
-
@crc = RBzip2::CRC.new
|
16
|
+
@crc = RBzip2::Ruby::CRC.new
|
17
17
|
@current_char = -1
|
18
18
|
@io = io
|
19
19
|
@live = 0
|
@@ -26,57 +26,62 @@ class RBzip2::Decompressor
|
|
26
26
|
@bytes_read += read if read != -1
|
27
27
|
end
|
28
28
|
|
29
|
+
def getc
|
30
|
+
read 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def gets
|
34
|
+
line = ''
|
35
|
+
loop do
|
36
|
+
char = getc
|
37
|
+
line += char
|
38
|
+
break if char == "\n"
|
39
|
+
end
|
40
|
+
line
|
41
|
+
end
|
42
|
+
|
29
43
|
def read(length = nil)
|
30
44
|
raise 'stream closed' if @io.nil?
|
31
45
|
|
32
46
|
if length == 1
|
33
47
|
r = read0
|
34
48
|
count (r < 0 ? -1 : 1)
|
35
|
-
r
|
49
|
+
r.chr
|
36
50
|
else
|
37
|
-
r =
|
51
|
+
r = ''
|
38
52
|
if length == nil
|
39
|
-
|
53
|
+
while true do
|
40
54
|
b = read0
|
41
55
|
break if b < 0
|
42
|
-
r
|
56
|
+
r << b.chr
|
43
57
|
end
|
44
58
|
elsif length > 0
|
45
59
|
length.times do
|
46
60
|
b = read0
|
47
61
|
break if b < 0
|
48
|
-
r
|
62
|
+
r << b.chr
|
49
63
|
end
|
50
64
|
count r.size
|
51
65
|
end
|
52
|
-
r
|
66
|
+
r
|
53
67
|
end
|
54
68
|
end
|
55
69
|
|
56
70
|
def read0
|
57
71
|
ret_char = @current_char
|
58
72
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
when NO_RAND_PART_C_STATE
|
73
|
-
setup_no_rand_part_c
|
74
|
-
|
75
|
-
when START_BLOCK_STATE
|
76
|
-
when RAND_PART_A_STATE
|
77
|
-
when NO_RAND_PART_A_STATE
|
78
|
-
else
|
79
|
-
raise 'illegal state'
|
73
|
+
if @current_state == RAND_PART_B_STATE
|
74
|
+
setup_rand_part_b
|
75
|
+
elsif @current_state == NO_RAND_PART_B_STATE
|
76
|
+
setup_no_rand_part_b
|
77
|
+
elsif @current_state == RAND_PART_C_STATE
|
78
|
+
setup_rand_part_c
|
79
|
+
elsif @current_state == NO_RAND_PART_C_STATE
|
80
|
+
setup_no_rand_part_c
|
81
|
+
elsif @current_state == EOF
|
82
|
+
return -1
|
83
|
+
else
|
84
|
+
raise 'illegal state'
|
80
85
|
end
|
81
86
|
|
82
87
|
ret_char
|
@@ -84,9 +89,9 @@ class RBzip2::Decompressor
|
|
84
89
|
|
85
90
|
def make_maps
|
86
91
|
in_use = @data.in_use
|
87
|
-
seq_to_unseq = @data.seq_to_unseq
|
92
|
+
seq_to_unseq = @data.seq_to_unseq
|
88
93
|
|
89
|
-
n_in_use_shadow = 0
|
94
|
+
n_in_use_shadow = 0
|
90
95
|
|
91
96
|
256.times do |i|
|
92
97
|
if in_use[i]
|
@@ -95,7 +100,7 @@ class RBzip2::Decompressor
|
|
95
100
|
end
|
96
101
|
end
|
97
102
|
|
98
|
-
@n_in_use = n_in_use_shadow
|
103
|
+
@n_in_use = n_in_use_shadow
|
99
104
|
end
|
100
105
|
|
101
106
|
def init
|
@@ -126,7 +131,7 @@ class RBzip2::Decompressor
|
|
126
131
|
@stored_block_crc = int
|
127
132
|
@block_randomised = bit
|
128
133
|
|
129
|
-
@data = RBzip2::InputData.new @block_size if @data.nil?
|
134
|
+
@data = RBzip2::Ruby::InputData.new @block_size if @data.nil?
|
130
135
|
|
131
136
|
get_and_move_to_front_decode
|
132
137
|
|
@@ -138,14 +143,9 @@ class RBzip2::Decompressor
|
|
138
143
|
def end_block
|
139
144
|
@computed_block_crc = @crc.final_crc
|
140
145
|
|
141
|
-
if @stored_block_crc != @computed_block_crc
|
142
|
-
@computed_combined_crc = (@stored_combined_crc << 1) | (@stored_combined_crc >> 31)
|
143
|
-
@computed_combined_crc ^= @stored_block_crc
|
144
|
-
|
145
|
-
raise 'BZip2 CRC error'
|
146
|
-
end
|
146
|
+
raise 'BZip2 CRC error' if @stored_block_crc != @computed_block_crc
|
147
147
|
|
148
|
-
@computed_combined_crc = (@computed_combined_crc << 1) | (@computed_combined_crc >> 31)
|
148
|
+
@computed_combined_crc = ((@computed_combined_crc << 1) & 0xffffffff) | (@computed_combined_crc >> 31)
|
149
149
|
@computed_combined_crc ^= @computed_block_crc
|
150
150
|
end
|
151
151
|
|
@@ -170,7 +170,7 @@ class RBzip2::Decompressor
|
|
170
170
|
|
171
171
|
if live_shadow < n
|
172
172
|
begin
|
173
|
-
thech = @io.
|
173
|
+
thech = @io.readbyte
|
174
174
|
|
175
175
|
raise 'unexpected end of stream' if thech < 0
|
176
176
|
|
@@ -195,7 +195,7 @@ class RBzip2::Decompressor
|
|
195
195
|
end
|
196
196
|
|
197
197
|
def int
|
198
|
-
|
198
|
+
r 32
|
199
199
|
end
|
200
200
|
|
201
201
|
def create_decode_tables(limit, base, perm, length, min_len, max_len, alpha_size)
|
@@ -209,10 +209,8 @@ class RBzip2::Decompressor
|
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
|
-
MAX_CODE_LEN
|
213
|
-
|
214
|
-
limit[i] = 0
|
215
|
-
end
|
212
|
+
base[1..MAX_CODE_LEN] = 0
|
213
|
+
limit[1..MAX_CODE_LEN] = 0
|
216
214
|
|
217
215
|
alpha_size.times do |i|
|
218
216
|
base[length[i] + 1] += 1
|
@@ -229,8 +227,7 @@ class RBzip2::Decompressor
|
|
229
227
|
b = base[i]
|
230
228
|
nb = base[i + 1]
|
231
229
|
vec += nb - b
|
232
|
-
|
233
|
-
limit[i] = vec -1
|
230
|
+
limit[i] = vec - 1
|
234
231
|
vec = vec << 1
|
235
232
|
end
|
236
233
|
|
@@ -251,9 +248,7 @@ class RBzip2::Decompressor
|
|
251
248
|
in_use16 |= 1 << i if bit
|
252
249
|
end
|
253
250
|
|
254
|
-
|
255
|
-
in_use[i] = false
|
256
|
-
end
|
251
|
+
in_use.fill false
|
257
252
|
|
258
253
|
16.times do |i|
|
259
254
|
if (in_use16 & (1 << i)) != 0
|
@@ -275,19 +270,18 @@ class RBzip2::Decompressor
|
|
275
270
|
while bit
|
276
271
|
j += 1
|
277
272
|
end
|
278
|
-
selector_mtf[i] = j
|
273
|
+
selector_mtf[i] = j & 0xff
|
279
274
|
end
|
280
275
|
|
281
|
-
|
282
|
-
pos[v] = v
|
283
|
-
end
|
276
|
+
pos.fill(0..groups) { |v| v & 0xff }
|
284
277
|
|
285
278
|
selectors.times do |i|
|
286
|
-
v = selector_mtf[i]
|
279
|
+
v = selector_mtf[i]
|
287
280
|
tmp = pos[v]
|
288
281
|
|
289
282
|
while v > 0 do
|
290
|
-
|
283
|
+
v -= 1
|
284
|
+
pos[v + 1] = pos[v]
|
291
285
|
end
|
292
286
|
|
293
287
|
pos[0] = tmp
|
@@ -349,30 +343,26 @@ class RBzip2::Decompressor
|
|
349
343
|
perm = @data.perm
|
350
344
|
limit_last = @block_size * BASEBLOCKSIZE
|
351
345
|
|
352
|
-
|
353
|
-
|
354
|
-
unzftab[i] = 0
|
355
|
-
end
|
346
|
+
yy.fill(0..256) { |i| i }
|
347
|
+
unzftab.fill 0
|
356
348
|
|
357
349
|
group_no = 0
|
358
350
|
group_pos = G_SIZE - 1
|
359
351
|
eob = @n_in_use + 1
|
360
352
|
next_sym = get_and_move_to_front_decode0 0
|
361
|
-
|
362
|
-
|
363
|
-
last_shadow = -1
|
364
|
-
zt = selector[group_no] & 0xff
|
353
|
+
@last = -1
|
354
|
+
zt = selector[group_no]
|
365
355
|
base_zt = base[zt]
|
366
356
|
limit_zt = limit[zt]
|
367
357
|
perm_zt = perm[zt]
|
368
358
|
min_lens_zt = min_lens[zt]
|
369
359
|
|
370
360
|
while next_sym != eob
|
371
|
-
if
|
361
|
+
if next_sym == RUNA || next_sym == RUNB
|
372
362
|
s = -1
|
373
363
|
|
374
364
|
n = 1
|
375
|
-
|
365
|
+
while true do
|
376
366
|
if next_sym == RUNA
|
377
367
|
s += n
|
378
368
|
elsif next_sym == RUNB
|
@@ -384,7 +374,7 @@ class RBzip2::Decompressor
|
|
384
374
|
if group_pos == 0
|
385
375
|
group_pos = G_SIZE - 1
|
386
376
|
group_no += 1
|
387
|
-
zt = selector[group_no]
|
377
|
+
zt = selector[group_no]
|
388
378
|
base_zt = base[zt]
|
389
379
|
limit_zt = limit[zt]
|
390
380
|
perm_zt = perm[zt]
|
@@ -395,32 +385,32 @@ class RBzip2::Decompressor
|
|
395
385
|
|
396
386
|
zn = min_lens_zt
|
397
387
|
|
398
|
-
while
|
399
|
-
thech = @io.
|
388
|
+
while @live < zn
|
389
|
+
thech = @io.readbyte
|
400
390
|
|
401
391
|
raise 'unexpected end of stream' if thech < 0
|
402
392
|
|
403
|
-
|
404
|
-
|
393
|
+
@buff = ((@buff << 8) & 0xffffffff) | thech
|
394
|
+
@live += 8
|
405
395
|
end
|
406
396
|
|
407
|
-
zvec = (
|
408
|
-
|
397
|
+
zvec = ((@buff >> (@live - zn)) & 0xffffffff) & ((1 << zn) - 1)
|
398
|
+
@live -= zn
|
409
399
|
|
410
400
|
while zvec > limit_zt[zn]
|
411
401
|
zn += 1
|
412
402
|
|
413
|
-
while
|
414
|
-
thech = @io.
|
403
|
+
while @live < 1
|
404
|
+
thech = @io.readbyte
|
415
405
|
|
416
406
|
raise 'unexpected end of stream' if thech < 0
|
417
407
|
|
418
|
-
|
419
|
-
|
408
|
+
@buff = ((@buff << 8) & 0xffffffff) | thech
|
409
|
+
@live += 8
|
420
410
|
end
|
421
411
|
|
422
|
-
|
423
|
-
zvec = (zvec << 1) | ((
|
412
|
+
@live -= 1
|
413
|
+
zvec = (zvec << 1) | ((@buff >> @live) & 1)
|
424
414
|
end
|
425
415
|
|
426
416
|
next_sym = perm_zt[zvec - base_zt[zn]]
|
@@ -432,19 +422,19 @@ class RBzip2::Decompressor
|
|
432
422
|
unzftab[ch & 0xff] += s + 1
|
433
423
|
|
434
424
|
while s >= 0
|
435
|
-
|
436
|
-
ll8[
|
425
|
+
@last += 1
|
426
|
+
ll8[@last] = ch
|
437
427
|
s -= 1
|
438
428
|
end
|
439
429
|
|
440
|
-
raise 'block overrun' if
|
430
|
+
raise 'block overrun' if @last >= limit_last
|
441
431
|
else
|
442
|
-
|
443
|
-
raise 'block overrun' if
|
432
|
+
@last += 1
|
433
|
+
raise 'block overrun' if @last >= limit_last
|
444
434
|
|
445
435
|
tmp = yy[next_sym - 1]
|
446
|
-
unzftab[seq_to_unseq[tmp]
|
447
|
-
ll8[
|
436
|
+
unzftab[seq_to_unseq[tmp]] += 1
|
437
|
+
ll8[@last] = seq_to_unseq[tmp]
|
448
438
|
|
449
439
|
yy[1, next_sym - 1] = yy[0, next_sym - 1]
|
450
440
|
yy[0] = tmp
|
@@ -452,7 +442,7 @@ class RBzip2::Decompressor
|
|
452
442
|
if group_pos == 0
|
453
443
|
group_pos = G_SIZE - 1
|
454
444
|
group_no += 1
|
455
|
-
zt = selector[group_no]
|
445
|
+
zt = selector[group_no]
|
456
446
|
base_zt = base[zt]
|
457
447
|
limit_zt = limit[zt]
|
458
448
|
perm_zt = perm[zt]
|
@@ -463,67 +453,58 @@ class RBzip2::Decompressor
|
|
463
453
|
|
464
454
|
zn = min_lens_zt
|
465
455
|
|
466
|
-
while
|
467
|
-
thech = @io.
|
456
|
+
while @live < zn
|
457
|
+
thech = @io.readbyte
|
468
458
|
|
469
459
|
raise 'unexpected end of stream' if thech < 0
|
470
460
|
|
471
|
-
|
472
|
-
|
461
|
+
@buff = ((@buff << 8) & 0xffffffff) | thech
|
462
|
+
@live += 8
|
473
463
|
end
|
474
|
-
zvec = (
|
475
|
-
|
464
|
+
zvec = (@buff >> (@live - zn)) & ((1 << zn) - 1)
|
465
|
+
@live -= zn
|
476
466
|
|
477
467
|
while zvec > limit_zt[zn]
|
478
468
|
zn += 1
|
479
|
-
while
|
480
|
-
thech = @io.
|
469
|
+
while @live < 1
|
470
|
+
thech = @io.readbyte
|
481
471
|
|
482
472
|
raise 'unexpected end of stream' if thech < 0
|
483
473
|
|
484
|
-
|
485
|
-
|
474
|
+
@buff = ((@buff << 8) & 0xffffffff) | thech
|
475
|
+
@live += 8
|
486
476
|
end
|
487
|
-
|
488
|
-
zvec = (zvec << 1) | ((
|
477
|
+
@live -= 1
|
478
|
+
zvec = (zvec << 1) | ((@buff >> @live) & 1)
|
489
479
|
end
|
490
480
|
|
491
481
|
next_sym = perm_zt[zvec - base_zt[zn]]
|
492
482
|
end
|
493
483
|
end
|
494
|
-
|
495
|
-
@last = last_shadow
|
496
|
-
@live = live_shadow
|
497
|
-
@buff = buff_shadow
|
498
484
|
end
|
499
485
|
|
500
486
|
def get_and_move_to_front_decode0(group_no)
|
501
|
-
zt = @data.selector[group_no]
|
487
|
+
zt = @data.selector[group_no]
|
502
488
|
limit_zt = @data.limit[zt]
|
503
489
|
zn = @data.min_lens[zt]
|
504
490
|
zvec = r zn
|
505
|
-
live_shadow = @live
|
506
|
-
buff_shadow = @buff
|
507
491
|
|
508
492
|
while zvec > limit_zt[zn]
|
509
493
|
zn += 1
|
510
494
|
|
511
|
-
while
|
512
|
-
thech = @io.
|
495
|
+
while @live < 1
|
496
|
+
thech = @io.readbyte
|
513
497
|
|
514
498
|
raise 'unexpected end of stream' if thech < 0
|
515
499
|
|
516
|
-
|
517
|
-
|
500
|
+
@buff = ((@buff << 8) & 0xffffffff) | thech
|
501
|
+
@live += 8
|
518
502
|
end
|
519
503
|
|
520
|
-
|
521
|
-
zvec = (zvec << 1) | ((
|
504
|
+
@live -=1
|
505
|
+
zvec = (zvec << 1) | ((@buff >> @live) & 1)
|
522
506
|
end
|
523
507
|
|
524
|
-
@live = live_shadow
|
525
|
-
@buff = buff_shadow
|
526
|
-
|
527
508
|
@data.perm[zt][zvec - @data.base[zt][zn]]
|
528
509
|
end
|
529
510
|
|
@@ -536,15 +517,14 @@ class RBzip2::Decompressor
|
|
536
517
|
cftab[0] = 0
|
537
518
|
cftab[1, 256] = @data.unzftab[0, 256]
|
538
519
|
|
539
|
-
c =
|
520
|
+
c = 0
|
540
521
|
1.upto(256) do |i|
|
541
522
|
c += cftab[i]
|
542
523
|
cftab[i] = c
|
543
524
|
end
|
544
525
|
|
545
|
-
|
546
|
-
|
547
|
-
cftab_i = ll8[i] & 0xff
|
526
|
+
(@last + 1).times do |i|
|
527
|
+
cftab_i = ll8[i]
|
548
528
|
tt[cftab[cftab_i]] = i
|
549
529
|
cftab[cftab_i] += 1
|
550
530
|
end
|
@@ -569,7 +549,7 @@ class RBzip2::Decompressor
|
|
569
549
|
def setup_rand_part_a
|
570
550
|
if @su_i2 <= @last
|
571
551
|
@su_ch_prev = @su_ch2
|
572
|
-
su_ch2_shadow = @data.ll8[@su_t_pos]
|
552
|
+
su_ch2_shadow = @data.ll8[@su_t_pos]
|
573
553
|
@su_t_pos = @data.tt[@su_t_pos]
|
574
554
|
|
575
555
|
if @su_r_n_to_go == 0
|
@@ -595,7 +575,7 @@ class RBzip2::Decompressor
|
|
595
575
|
def setup_no_rand_part_a
|
596
576
|
if @su_i2 <= @last
|
597
577
|
@su_ch_prev = @su_ch2
|
598
|
-
su_ch2_shadow = @data.ll8[@su_t_pos]
|
578
|
+
su_ch2_shadow = @data.ll8[@su_t_pos]
|
599
579
|
@su_ch2 = su_ch2_shadow
|
600
580
|
@su_t_pos = @data.tt[@su_t_pos]
|
601
581
|
@su_i2 += 1
|
@@ -618,7 +598,7 @@ class RBzip2::Decompressor
|
|
618
598
|
else
|
619
599
|
@su_count += 1
|
620
600
|
if @su_count >= 4
|
621
|
-
@su_z = @data.ll8[@su_t_pos]
|
601
|
+
@su_z = @data.ll8[@su_t_pos]
|
622
602
|
@su_t_pos = @data.tt[@su_t_pos]
|
623
603
|
|
624
604
|
if @su_r_n_to_go == 0
|
@@ -660,7 +640,7 @@ class RBzip2::Decompressor
|
|
660
640
|
else
|
661
641
|
@su_count += 1
|
662
642
|
if @su_count >= 4
|
663
|
-
@su_z = @data.ll8[@su_t_pos]
|
643
|
+
@su_z = @data.ll8[@su_t_pos]
|
664
644
|
@su_t_pos = @data.tt[@su_t_pos]
|
665
645
|
@su_j2 = 0
|
666
646
|
setup_no_rand_part_c
|