byteboozer2 0.0.4 → 0.0.5
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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -3
- data/Gemfile +7 -0
- data/Gemfile.lock +97 -38
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/byteboozer2.gemspec +3 -8
- data/lib/byteboozer2/cruncher.rb +64 -64
- data/lib/byteboozer2/file.rb +5 -5
- data/lib/byteboozer2/version.rb +1 -1
- data/lib/byteboozer2.rb +2 -2
- metadata +8 -94
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d6c9bd178305d32593aeec91fdbddbb8c881942c623038c61401109547a30b3
|
|
4
|
+
data.tar.gz: de3960c536021945f78d6c41284a4d54de9588a9b581cad94a7e9fd9a251691b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e73d8780759fbd02d495c97ebfc37af1a1fc6591486dfba5ad7b3fde4cbb6f702b1fb20b71492dbc119b3f6e714a7d189fbaa4ecfc7582c3da98645956fbf856
|
|
7
|
+
data.tar.gz: 32783eaf2a01fb321f40f0f9a41a46b7c298f52325dbd13402068d8fa18ae0aa21682c85b22ed1347d476db40a723c95a726b71413e74324ab3003bd942be4c6
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
AllCops:
|
|
2
|
-
|
|
2
|
+
NewCops: enable
|
|
3
|
+
SuggestExtensions: false
|
|
4
|
+
TargetRubyVersion: 4.0.6
|
|
3
5
|
Layout/EmptyLinesAroundAttributeAccessor:
|
|
4
6
|
Enabled: true
|
|
7
|
+
Layout/LineLength:
|
|
8
|
+
Max: 120
|
|
5
9
|
Layout/SpaceAroundMethodCallOperator:
|
|
6
10
|
Enabled: true
|
|
7
11
|
Lint/DeprecatedOpenSSLConstant:
|
|
@@ -20,8 +24,6 @@ Metrics/ClassLength:
|
|
|
20
24
|
Max: 472
|
|
21
25
|
Metrics/CyclomaticComplexity:
|
|
22
26
|
Max: 48
|
|
23
|
-
Metrics/LineLength:
|
|
24
|
-
Max: 120
|
|
25
27
|
Metrics/MethodLength:
|
|
26
28
|
Max: 116
|
|
27
29
|
Metrics/PerceivedComplexity:
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,62 +1,121 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
byteboozer2 (0.0.
|
|
5
|
-
activemodel (~>
|
|
4
|
+
byteboozer2 (0.0.5)
|
|
5
|
+
activemodel (~> 8.1.3.1)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activemodel (
|
|
11
|
-
activesupport (=
|
|
12
|
-
activesupport (
|
|
13
|
-
|
|
10
|
+
activemodel (8.1.3.1)
|
|
11
|
+
activesupport (= 8.1.3.1)
|
|
12
|
+
activesupport (8.1.3.1)
|
|
13
|
+
base64
|
|
14
|
+
bigdecimal
|
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
16
|
+
connection_pool (>= 2.2.5)
|
|
17
|
+
drb
|
|
14
18
|
i18n (>= 1.6, < 2)
|
|
19
|
+
json
|
|
20
|
+
logger (>= 1.4.2)
|
|
15
21
|
minitest (>= 5.1)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
securerandom (>= 0.3)
|
|
23
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
24
|
+
uri (>= 0.13.1)
|
|
25
|
+
ast (2.4.3)
|
|
19
26
|
awesome_print (1.9.2)
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
base64 (0.3.0)
|
|
28
|
+
bigdecimal (4.1.2)
|
|
29
|
+
concurrent-ruby (1.3.8)
|
|
30
|
+
connection_pool (3.0.2)
|
|
31
|
+
drb (2.2.3)
|
|
32
|
+
i18n (1.15.2)
|
|
22
33
|
concurrent-ruby (~> 1.0)
|
|
23
|
-
json (2.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
json (2.21.2)
|
|
35
|
+
language_server-protocol (3.17.0.6)
|
|
36
|
+
lint_roller (1.1.0)
|
|
37
|
+
logger (1.7.0)
|
|
38
|
+
minitest (6.0.6)
|
|
39
|
+
drb (~> 2.0)
|
|
40
|
+
prism (~> 1.5)
|
|
41
|
+
parallel (2.1.0)
|
|
42
|
+
parser (3.3.12.0)
|
|
27
43
|
ast (~> 2.4.1)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
racc
|
|
45
|
+
prism (1.9.0)
|
|
46
|
+
racc (1.8.1)
|
|
47
|
+
rainbow (3.1.1)
|
|
48
|
+
rake (13.4.2)
|
|
49
|
+
regexp_parser (2.12.0)
|
|
50
|
+
rubocop (1.89.0)
|
|
51
|
+
json (~> 2.3)
|
|
52
|
+
language_server-protocol (~> 3.17.0.2)
|
|
53
|
+
lint_roller (~> 1.1.0)
|
|
54
|
+
parallel (>= 1.10)
|
|
55
|
+
parser (>= 3.3.0.2)
|
|
35
56
|
rainbow (>= 2.2.2, < 4.0)
|
|
36
|
-
regexp_parser (>=
|
|
37
|
-
|
|
38
|
-
rubocop-ast (>= 1.2.0, < 2.0)
|
|
57
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
58
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
39
59
|
ruby-progressbar (~> 1.7)
|
|
40
|
-
unicode-display_width (>=
|
|
41
|
-
rubocop-ast (1.
|
|
42
|
-
parser (>=
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
61
|
+
rubocop-ast (1.50.0)
|
|
62
|
+
parser (>= 3.3.7.2)
|
|
63
|
+
prism (~> 1.7)
|
|
64
|
+
ruby-progressbar (1.13.0)
|
|
65
|
+
securerandom (0.4.1)
|
|
66
|
+
tzinfo (2.0.6)
|
|
45
67
|
concurrent-ruby (~> 1.0)
|
|
46
|
-
unicode-display_width (2.0
|
|
47
|
-
|
|
68
|
+
unicode-display_width (3.2.0)
|
|
69
|
+
unicode-emoji (~> 4.1)
|
|
70
|
+
unicode-emoji (4.2.0)
|
|
71
|
+
uri (1.1.1)
|
|
48
72
|
|
|
49
73
|
PLATFORMS
|
|
50
74
|
ruby
|
|
75
|
+
x86_64-linux
|
|
51
76
|
|
|
52
77
|
DEPENDENCIES
|
|
53
78
|
awesome_print (~> 1.9.2)
|
|
54
|
-
bundler (~>
|
|
79
|
+
bundler (~> 4.0.18)
|
|
55
80
|
byteboozer2!
|
|
56
|
-
json (~> 2.
|
|
57
|
-
minitest (~>
|
|
58
|
-
rake (~> 13.
|
|
59
|
-
rubocop (~> 1.
|
|
81
|
+
json (~> 2.21.2)
|
|
82
|
+
minitest (~> 6.0.6)
|
|
83
|
+
rake (~> 13.4.2)
|
|
84
|
+
rubocop (~> 1.89.0)
|
|
85
|
+
|
|
86
|
+
CHECKSUMS
|
|
87
|
+
activemodel (8.1.3.1) sha256=99cc02ce2faec371d14440949d85787ebd23a907c9baef0a9d4bcd4d21888f88
|
|
88
|
+
activesupport (8.1.3.1) sha256=85458765f25ea48b9019c46b6bb3fa5683197bf4280d9f06710a6e8d7a831376
|
|
89
|
+
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
|
|
90
|
+
awesome_print (1.9.2) sha256=e99b32b704acff16d768b3468680793ced40bfdc4537eb07e06a4be11133786e
|
|
91
|
+
base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
|
|
92
|
+
bigdecimal (4.1.2) sha256=53d217666027eab4280346fba98e7d5b66baaae1b9c3c1c0ffe89d48188a3fbd
|
|
93
|
+
bundler (4.0.18) sha256=02d9a17429de1847b4e0c9f27a9ee4b20c0a74c0a641b4e77195d6019e3618ac
|
|
94
|
+
byteboozer2 (0.0.5)
|
|
95
|
+
concurrent-ruby (1.3.8) sha256=b2f1be836e968ccc78ccfce277ea79c72a88633f22306782c16ff23fb415d1e1
|
|
96
|
+
connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a
|
|
97
|
+
drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
|
|
98
|
+
i18n (1.15.2) sha256=00f9eb62412fe593b2a65a97daa75300d37abb8f7202ec748e94b6d46a9dd1b5
|
|
99
|
+
json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
|
|
100
|
+
language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0
|
|
101
|
+
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
|
|
102
|
+
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
103
|
+
minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
|
|
104
|
+
parallel (2.1.0) sha256=b35258865c2e31134c5ecb708beaaf6772adf9d5efae28e93e99260877b09356
|
|
105
|
+
parser (3.3.12.0) sha256=21a6d7f755d5a24dfbdc6e6b772e4e879a52e7631a88bc5a3a134606052c9828
|
|
106
|
+
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
|
|
107
|
+
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
|
|
108
|
+
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
|
|
109
|
+
rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
|
|
110
|
+
regexp_parser (2.12.0) sha256=35a916a1d63190ab5c9009457136ae5f3c0c7512d60291d0d1378ba18ce08ebb
|
|
111
|
+
rubocop (1.89.0) sha256=4dee8e3ee9c45e474834efd9e8d6fd031e8331c8dacdff0de4ad65ae0a6faae7
|
|
112
|
+
rubocop-ast (1.50.0) sha256=b9ca88300da0803ee222ad20cdb30494c0a784eed06fdc35d254b06d662788db
|
|
113
|
+
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
|
|
114
|
+
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
|
|
115
|
+
tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b
|
|
116
|
+
unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
|
|
117
|
+
unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
|
|
118
|
+
uri (1.1.1) sha256=379fa58d27ffb1387eaada68c749d1426738bd0f654d812fcc07e7568f5c57c6
|
|
60
119
|
|
|
61
120
|
BUNDLED WITH
|
|
62
|
-
|
|
121
|
+
4.0.18
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## Version
|
|
8
8
|
|
|
9
|
-
Version 0.0.
|
|
9
|
+
Version 0.0.5 (2026-08-15)
|
|
10
10
|
|
|
11
11
|
## Description
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@ Compressed data is by default written into a file named with `.b2` suffix. Targe
|
|
|
19
19
|
Add this line to your application's Gemfile:
|
|
20
20
|
|
|
21
21
|
```ruby
|
|
22
|
-
gem 'byteboozer2', '~> 0.0.
|
|
22
|
+
gem 'byteboozer2', '~> 0.0.5'
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
And then execute:
|
data/byteboozer2.gemspec
CHANGED
|
@@ -20,14 +20,9 @@ Gem::Specification.new do |spec|
|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
21
|
spec.require_paths = ['lib']
|
|
22
22
|
|
|
23
|
-
spec.required_ruby_version = '>=
|
|
23
|
+
spec.required_ruby_version = '>= 4.0.6'
|
|
24
24
|
|
|
25
|
-
spec.
|
|
26
|
-
spec.add_development_dependency 'bundler', '~> 2.2.16'
|
|
27
|
-
spec.add_development_dependency 'json', '~> 2.5.1'
|
|
28
|
-
spec.add_development_dependency 'minitest', '~> 5.14.4'
|
|
29
|
-
spec.add_development_dependency 'rake', '~> 13.0.3'
|
|
30
|
-
spec.add_development_dependency 'rubocop', '~> 1.13.0'
|
|
25
|
+
spec.add_dependency 'activemodel', '~> 8.1.3.1'
|
|
31
26
|
|
|
32
|
-
spec.
|
|
27
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
33
28
|
end
|
data/lib/byteboozer2/cruncher.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'active_model'
|
|
4
|
-
require '
|
|
4
|
+
require 'cgi/escape'
|
|
5
5
|
|
|
6
6
|
module ByteBoozer2
|
|
7
7
|
# This class implements ByteBoozer's 2.0 crunching algorithm.
|
|
@@ -15,8 +15,12 @@ module ByteBoozer2
|
|
|
15
15
|
greater_than_or_equal_to: 0x0000,
|
|
16
16
|
less_than_or_equal_to: 0xffff
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
RleInfo = Struct.new(:value, :value_after, :length, keyword_init: true) # rubocop:disable Lint/StructNewOverride
|
|
19
|
+
Matches = Struct.new(:length, :offset, keyword_init: true) # rubocop:disable Lint/StructNewOverride
|
|
20
|
+
NewNode = Struct.new(:cost, :next, :lit_len, :offset, keyword_init: true)
|
|
21
|
+
|
|
22
|
+
def self.crunch(*)
|
|
23
|
+
new(*).crunch
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
def initialize(data, options = {})
|
|
@@ -28,14 +32,14 @@ module ByteBoozer2
|
|
|
28
32
|
raise ArgumentError unless valid?
|
|
29
33
|
end
|
|
30
34
|
|
|
31
|
-
def
|
|
35
|
+
def crunched?
|
|
32
36
|
@ibuf_size = @data.length - 2
|
|
33
37
|
|
|
34
38
|
# Load ibuf and clear context
|
|
35
39
|
@ibuf = @data[2..]
|
|
36
40
|
@context = Array.new(@ibuf_size) { new_node }
|
|
37
41
|
@link = Array.new(@ibuf_size) { 0 }
|
|
38
|
-
@rle_info = Array.new(@ibuf_size) {
|
|
42
|
+
@rle_info = Array.new(@ibuf_size) { RleInfo.new(value: 0, value_after: 0, length: 0) }
|
|
39
43
|
|
|
40
44
|
setup_help_structures
|
|
41
45
|
find_matches
|
|
@@ -93,11 +97,9 @@ module ByteBoozer2
|
|
|
93
97
|
end
|
|
94
98
|
|
|
95
99
|
def crunch
|
|
96
|
-
@result if
|
|
100
|
+
@result if crunched?
|
|
97
101
|
end
|
|
98
102
|
|
|
99
|
-
private
|
|
100
|
-
|
|
101
103
|
DECRUNCHER = [
|
|
102
104
|
0x0b, 0x08, 0x00, 0x00, 0x9e, 0x32, 0x30, 0x36, 0x31, 0x00, 0x00, 0x00, 0x78, 0xa9, 0x34, 0x85,
|
|
103
105
|
0x01, 0xa2, 0xb7, 0xbd, 0x1e, 0x08, 0x95, 0x0f, 0xca, 0xd0, 0xf8, 0x4c, 0x10, 0x00, 0xbd, 0xd6,
|
|
@@ -139,22 +141,24 @@ module ByteBoozer2
|
|
|
139
141
|
MAX_OFFSET = LEN_LONG_3
|
|
140
142
|
MAX_OFFSET_SHORT = LEN_SHORT_3
|
|
141
143
|
|
|
144
|
+
private
|
|
145
|
+
|
|
142
146
|
def cost_of_length(len)
|
|
143
147
|
if len == 1
|
|
144
148
|
1
|
|
145
|
-
elsif len
|
|
149
|
+
elsif len.between?(2, 3)
|
|
146
150
|
3
|
|
147
|
-
elsif len
|
|
151
|
+
elsif len.between?(4, 7)
|
|
148
152
|
5
|
|
149
|
-
elsif len
|
|
153
|
+
elsif len.between?(8, 15)
|
|
150
154
|
7
|
|
151
|
-
elsif len
|
|
155
|
+
elsif len.between?(16, 31)
|
|
152
156
|
9
|
|
153
|
-
elsif len
|
|
157
|
+
elsif len.between?(32, 63)
|
|
154
158
|
11
|
|
155
|
-
elsif len
|
|
159
|
+
elsif len.between?(64, 127)
|
|
156
160
|
13
|
|
157
|
-
elsif len
|
|
161
|
+
elsif len.between?(128, 255)
|
|
158
162
|
14
|
|
159
163
|
else
|
|
160
164
|
ByteBoozer2.logger.warn "cost_of_length got wrong value: #{len}"
|
|
@@ -172,14 +176,8 @@ module ByteBoozer2
|
|
|
172
176
|
# literal run, which in the end results in a worse result
|
|
173
177
|
# Most obvious on files hard to crunch
|
|
174
178
|
case lit_len
|
|
175
|
-
when 1 then new_cost += 1
|
|
176
|
-
when
|
|
177
|
-
when 2 then new_cost += 2
|
|
178
|
-
when 4 then new_cost += 2
|
|
179
|
-
when 8 then new_cost += 2
|
|
180
|
-
when 16 then new_cost += 2
|
|
181
|
-
when 32 then new_cost += 2
|
|
182
|
-
when 64 then new_cost += 2
|
|
179
|
+
when 1, 128 then new_cost += 1
|
|
180
|
+
when 2, 4, 8, 16, 32, 64 then new_cost += 2
|
|
183
181
|
end
|
|
184
182
|
|
|
185
183
|
new_cost
|
|
@@ -195,50 +193,50 @@ module ByteBoozer2
|
|
|
195
193
|
|
|
196
194
|
def cost_of_offset(offset, len)
|
|
197
195
|
if len == 1
|
|
198
|
-
return NUM_BITS_SHORT_0 if cond_short_0(offset)
|
|
199
|
-
return NUM_BITS_SHORT_1 if cond_short_1(offset)
|
|
200
|
-
return NUM_BITS_SHORT_2 if cond_short_2(offset)
|
|
201
|
-
return NUM_BITS_SHORT_3 if cond_short_3(offset)
|
|
196
|
+
return NUM_BITS_SHORT_0 if cond_short_0?(offset)
|
|
197
|
+
return NUM_BITS_SHORT_1 if cond_short_1?(offset)
|
|
198
|
+
return NUM_BITS_SHORT_2 if cond_short_2?(offset)
|
|
199
|
+
return NUM_BITS_SHORT_3 if cond_short_3?(offset)
|
|
202
200
|
else
|
|
203
|
-
return NUM_BITS_LONG_0 if cond_long_0(offset)
|
|
204
|
-
return NUM_BITS_LONG_1 if cond_long_1(offset)
|
|
205
|
-
return NUM_BITS_LONG_2 if cond_long_2(offset)
|
|
206
|
-
return NUM_BITS_LONG_3 if cond_long_3(offset)
|
|
201
|
+
return NUM_BITS_LONG_0 if cond_long_0?(offset)
|
|
202
|
+
return NUM_BITS_LONG_1 if cond_long_1?(offset)
|
|
203
|
+
return NUM_BITS_LONG_2 if cond_long_2?(offset)
|
|
204
|
+
return NUM_BITS_LONG_3 if cond_long_3?(offset)
|
|
207
205
|
end
|
|
208
206
|
|
|
209
207
|
ByteBoozer2.logger.warn "cost_of_offset got wrong offset: #{offset}"
|
|
210
208
|
10_000
|
|
211
209
|
end
|
|
212
210
|
|
|
213
|
-
def cond_short_0(o)
|
|
211
|
+
def cond_short_0?(o)
|
|
214
212
|
o >= 0 && o < LEN_SHORT_0
|
|
215
213
|
end
|
|
216
214
|
|
|
217
|
-
def cond_short_1(o)
|
|
215
|
+
def cond_short_1?(o)
|
|
218
216
|
o >= LEN_SHORT_0 && o < LEN_SHORT_1
|
|
219
217
|
end
|
|
220
218
|
|
|
221
|
-
def cond_short_2(o)
|
|
219
|
+
def cond_short_2?(o)
|
|
222
220
|
o >= LEN_SHORT_1 && o < LEN_SHORT_2
|
|
223
221
|
end
|
|
224
222
|
|
|
225
|
-
def cond_short_3(o)
|
|
223
|
+
def cond_short_3?(o)
|
|
226
224
|
o >= LEN_SHORT_2 && o < LEN_SHORT_3
|
|
227
225
|
end
|
|
228
226
|
|
|
229
|
-
def cond_long_0(o)
|
|
227
|
+
def cond_long_0?(o)
|
|
230
228
|
o >= 0 && o < LEN_LONG_0
|
|
231
229
|
end
|
|
232
230
|
|
|
233
|
-
def cond_long_1(o)
|
|
231
|
+
def cond_long_1?(o)
|
|
234
232
|
o >= LEN_LONG_0 && o < LEN_LONG_1
|
|
235
233
|
end
|
|
236
234
|
|
|
237
|
-
def cond_long_2(o)
|
|
235
|
+
def cond_long_2?(o)
|
|
238
236
|
o >= LEN_LONG_1 && o < LEN_LONG_2
|
|
239
237
|
end
|
|
240
238
|
|
|
241
|
-
def cond_long_3(o)
|
|
239
|
+
def cond_long_3?(o)
|
|
242
240
|
o >= LEN_LONG_2 && o < LEN_LONG_3
|
|
243
241
|
end
|
|
244
242
|
|
|
@@ -247,7 +245,7 @@ module ByteBoozer2
|
|
|
247
245
|
end
|
|
248
246
|
|
|
249
247
|
def find_matches
|
|
250
|
-
matches = Array.new(256) {
|
|
248
|
+
matches = Array.new(256) { Matches.new(length: 0, offset: 0) }
|
|
251
249
|
|
|
252
250
|
last_node = new_node
|
|
253
251
|
|
|
@@ -268,7 +266,8 @@ module ByteBoozer2
|
|
|
268
266
|
|
|
269
267
|
longest_match = 0
|
|
270
268
|
|
|
271
|
-
|
|
269
|
+
# No RLE-match here...
|
|
270
|
+
if @rle_info[get].length.zero? # rubocop:disable Style/ZeroLengthPredicate
|
|
272
271
|
# Scan until start of file, or max offset
|
|
273
272
|
while get - scn <= MAX_OFFSET && scn.positive? && longest_match < 255
|
|
274
273
|
# OK, we have a match of length 2 or longer, but max 255 or file start
|
|
@@ -283,7 +282,7 @@ module ByteBoozer2
|
|
|
283
282
|
longest_match = len
|
|
284
283
|
|
|
285
284
|
# Store the match only if first (= best) of this length
|
|
286
|
-
while len >= 2 && matches[len].length.zero?
|
|
285
|
+
while len >= 2 && matches[len].length.zero? # rubocop:disable Style/ZeroLengthPredicate
|
|
287
286
|
# If len == 2, check against short offset!
|
|
288
287
|
if len > 2 || (len == 2 && offset <= MAX_OFFSET_SHORT)
|
|
289
288
|
matches[len].length = len
|
|
@@ -351,7 +350,7 @@ module ByteBoozer2
|
|
|
351
350
|
longest_match = len
|
|
352
351
|
|
|
353
352
|
# Store the match only if first (= best) of this length
|
|
354
|
-
while len >= 2 && matches[len].length.zero?
|
|
353
|
+
while len >= 2 && matches[len].length.zero? # rubocop:disable Style/ZeroLengthPredicate
|
|
355
354
|
# If len == 2, check against short offset!
|
|
356
355
|
if len > 2 || (len == 2 && offset <= MAX_OFFSET_SHORT)
|
|
357
356
|
matches[len].length = len
|
|
@@ -424,7 +423,7 @@ module ByteBoozer2
|
|
|
424
423
|
end
|
|
425
424
|
|
|
426
425
|
def new_node
|
|
427
|
-
|
|
426
|
+
NewNode.new(cost: 0, next: 0, lit_len: 0, offset: 0)
|
|
428
427
|
end
|
|
429
428
|
|
|
430
429
|
def setup_help_structures
|
|
@@ -464,7 +463,8 @@ module ByteBoozer2
|
|
|
464
463
|
@last[cur] = get
|
|
465
464
|
end
|
|
466
465
|
|
|
467
|
-
|
|
466
|
+
# If RLE-match...
|
|
467
|
+
get -= @rle_info[get].length.zero? ? 1 : @rle_info[get].length - 1 # rubocop:disable Style/ZeroLengthPredicate
|
|
468
468
|
end
|
|
469
469
|
end
|
|
470
470
|
|
|
@@ -488,7 +488,7 @@ module ByteBoozer2
|
|
|
488
488
|
end
|
|
489
489
|
|
|
490
490
|
def wbytes(get, len)
|
|
491
|
-
(0..len - 1).each do
|
|
491
|
+
(0..(len - 1)).each do
|
|
492
492
|
wbyte(@ibuf[get])
|
|
493
493
|
get += 1
|
|
494
494
|
end
|
|
@@ -506,12 +506,12 @@ module ByteBoozer2
|
|
|
506
506
|
# return if len.zero? # Should never happen
|
|
507
507
|
|
|
508
508
|
bit = 0x80
|
|
509
|
-
bit >>= 1 while (
|
|
509
|
+
bit >>= 1 while len.nobits?(bit)
|
|
510
510
|
|
|
511
511
|
while bit > 1
|
|
512
512
|
wbit(1)
|
|
513
513
|
bit >>= 1
|
|
514
|
-
wbit((
|
|
514
|
+
wbit(len.nobits?(bit) ? 0 : 1)
|
|
515
515
|
end
|
|
516
516
|
|
|
517
517
|
wbit(0) if len < 0x80
|
|
@@ -522,44 +522,44 @@ module ByteBoozer2
|
|
|
522
522
|
n = 0
|
|
523
523
|
|
|
524
524
|
if len == 1
|
|
525
|
-
if cond_short_0(offset)
|
|
525
|
+
if cond_short_0?(offset)
|
|
526
526
|
i = 0
|
|
527
527
|
n = NUM_BITS_SHORT_0
|
|
528
528
|
end
|
|
529
|
-
if cond_short_1(offset)
|
|
529
|
+
if cond_short_1?(offset)
|
|
530
530
|
i = 1
|
|
531
531
|
n = NUM_BITS_SHORT_1
|
|
532
532
|
end
|
|
533
|
-
if cond_short_2(offset)
|
|
533
|
+
if cond_short_2?(offset)
|
|
534
534
|
i = 2
|
|
535
535
|
n = NUM_BITS_SHORT_2
|
|
536
536
|
end
|
|
537
|
-
if cond_short_3(offset)
|
|
537
|
+
if cond_short_3?(offset)
|
|
538
538
|
i = 3
|
|
539
539
|
n = NUM_BITS_SHORT_3
|
|
540
540
|
end
|
|
541
541
|
else
|
|
542
|
-
if cond_long_0(offset)
|
|
542
|
+
if cond_long_0?(offset)
|
|
543
543
|
i = 0
|
|
544
544
|
n = NUM_BITS_LONG_0
|
|
545
545
|
end
|
|
546
|
-
if cond_long_1(offset)
|
|
546
|
+
if cond_long_1?(offset)
|
|
547
547
|
i = 1
|
|
548
548
|
n = NUM_BITS_LONG_1
|
|
549
549
|
end
|
|
550
|
-
if cond_long_2(offset)
|
|
550
|
+
if cond_long_2?(offset)
|
|
551
551
|
i = 2
|
|
552
552
|
n = NUM_BITS_LONG_2
|
|
553
553
|
end
|
|
554
|
-
if cond_long_3(offset)
|
|
554
|
+
if cond_long_3?(offset)
|
|
555
555
|
i = 3
|
|
556
556
|
n = NUM_BITS_LONG_3
|
|
557
557
|
end
|
|
558
558
|
end
|
|
559
559
|
|
|
560
560
|
# First write number of bits
|
|
561
|
-
wbit((
|
|
562
|
-
wbit((
|
|
561
|
+
wbit(i.nobits?(2) ? 0 : 1)
|
|
562
|
+
wbit(i.nobits?(1) ? 0 : 1)
|
|
563
563
|
|
|
564
564
|
b = 1 << n
|
|
565
565
|
if n >= 8 # Offset is 2 bytes
|
|
@@ -567,11 +567,11 @@ module ByteBoozer2
|
|
|
567
567
|
# Then write the bits less than 8
|
|
568
568
|
while b > 0x100
|
|
569
569
|
b >>= 1
|
|
570
|
-
wbit((
|
|
570
|
+
wbit(b.nobits?(offset) ? 0 : 1)
|
|
571
571
|
end
|
|
572
572
|
|
|
573
573
|
# Finally write a whole byte, if necessary
|
|
574
|
-
wbyte(offset & 255 ^ 255) # Inverted (!)
|
|
574
|
+
wbyte((offset & 255) ^ 255) # Inverted (!)
|
|
575
575
|
# offset >>= 8
|
|
576
576
|
|
|
577
577
|
else # Offset is 1 byte
|
|
@@ -579,7 +579,7 @@ module ByteBoozer2
|
|
|
579
579
|
# Then write the bits less than 8
|
|
580
580
|
while b > 1
|
|
581
581
|
b >>= 1
|
|
582
|
-
wbit((
|
|
582
|
+
wbit(b.nobits?(offset) ? 1 : 0) # Inverted (!)
|
|
583
583
|
end
|
|
584
584
|
end
|
|
585
585
|
end
|
|
@@ -607,7 +607,7 @@ module ByteBoozer2
|
|
|
607
607
|
# Put match
|
|
608
608
|
len = link - i
|
|
609
609
|
|
|
610
|
-
ByteBoozer2.logger.debug format('$%<i>04x: Mat(%<len>i, %<offset>i)', i
|
|
610
|
+
ByteBoozer2.logger.debug format('$%<i>04x: Mat(%<len>i, %<offset>i)', i:, len:, offset:)
|
|
611
611
|
|
|
612
612
|
wbit(1) if need_copy_bit
|
|
613
613
|
wlength(len - 1)
|
|
@@ -621,9 +621,9 @@ module ByteBoozer2
|
|
|
621
621
|
need_copy_bit = false
|
|
622
622
|
|
|
623
623
|
while lit_len.positive?
|
|
624
|
-
len = lit_len
|
|
624
|
+
len = [lit_len, 255].min
|
|
625
625
|
|
|
626
|
-
ByteBoozer2.logger.debug format('$%<i>04x: Lit(%<len>i)', i
|
|
626
|
+
ByteBoozer2.logger.debug format('$%<i>04x: Lit(%<len>i)', i:, len:)
|
|
627
627
|
|
|
628
628
|
wbit(0)
|
|
629
629
|
wlength(len)
|
data/lib/byteboozer2/file.rb
CHANGED
|
@@ -5,12 +5,12 @@ module ByteBoozer2
|
|
|
5
5
|
class File
|
|
6
6
|
attr_accessor :data, :name
|
|
7
7
|
|
|
8
|
-
def self.load(*
|
|
9
|
-
new(*
|
|
8
|
+
def self.load(*)
|
|
9
|
+
new(*).tap(&:read)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def self.save(*
|
|
13
|
-
new(*
|
|
12
|
+
def self.save(*)
|
|
13
|
+
new(*).tap(&:write)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def initialize(name, data = nil)
|
|
@@ -19,7 +19,7 @@ module ByteBoozer2
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def read
|
|
22
|
-
@data =
|
|
22
|
+
@data = ::File.binread(@name).unpack('C*')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def write
|
data/lib/byteboozer2/version.rb
CHANGED
data/lib/byteboozer2.rb
CHANGED
|
@@ -12,7 +12,7 @@ module ByteBoozer2
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def ecrunch(file_name, address)
|
|
15
|
-
compress(file_name, address
|
|
15
|
+
compress(file_name, address:, executable: true)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def self.logger
|
|
@@ -27,7 +27,7 @@ module ByteBoozer2
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def rcrunch(file_name, address)
|
|
30
|
-
compress(file_name, address
|
|
30
|
+
compress(file_name, address:, relocated: true)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
private
|
metadata
CHANGED
|
@@ -1,113 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: byteboozer2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pawel Krol
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: awesome_print
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.9.2
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.9.2
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: bundler
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 2.2.16
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: 2.2.16
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: json
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: 2.5.1
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: 2.5.1
|
|
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.14.4
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: 5.14.4
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: rake
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: 13.0.3
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: 13.0.3
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: rubocop
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - "~>"
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: 1.13.0
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - "~>"
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: 1.13.0
|
|
97
12
|
- !ruby/object:Gem::Dependency
|
|
98
13
|
name: activemodel
|
|
99
14
|
requirement: !ruby/object:Gem::Requirement
|
|
100
15
|
requirements:
|
|
101
16
|
- - "~>"
|
|
102
17
|
- !ruby/object:Gem::Version
|
|
103
|
-
version:
|
|
18
|
+
version: 8.1.3.1
|
|
104
19
|
type: :runtime
|
|
105
20
|
prerelease: false
|
|
106
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
22
|
requirements:
|
|
108
23
|
- - "~>"
|
|
109
24
|
- !ruby/object:Gem::Version
|
|
110
|
-
version:
|
|
25
|
+
version: 8.1.3.1
|
|
111
26
|
description: This is a native Ruby port of David Malmborg's ByteBoozer 2.0.
|
|
112
27
|
email:
|
|
113
28
|
- djgruby@gmail.com
|
|
@@ -133,8 +48,8 @@ files:
|
|
|
133
48
|
homepage: https://github.com/pawelkrol/byteboozer2_ruby
|
|
134
49
|
licenses:
|
|
135
50
|
- MIT
|
|
136
|
-
metadata:
|
|
137
|
-
|
|
51
|
+
metadata:
|
|
52
|
+
rubygems_mfa_required: 'true'
|
|
138
53
|
rdoc_options: []
|
|
139
54
|
require_paths:
|
|
140
55
|
- lib
|
|
@@ -142,15 +57,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
142
57
|
requirements:
|
|
143
58
|
- - ">="
|
|
144
59
|
- !ruby/object:Gem::Version
|
|
145
|
-
version:
|
|
60
|
+
version: 4.0.6
|
|
146
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
62
|
requirements:
|
|
148
63
|
- - ">="
|
|
149
64
|
- !ruby/object:Gem::Version
|
|
150
65
|
version: '0'
|
|
151
66
|
requirements: []
|
|
152
|
-
rubygems_version:
|
|
153
|
-
signing_key:
|
|
67
|
+
rubygems_version: 4.0.18
|
|
154
68
|
specification_version: 4
|
|
155
69
|
summary: A data cruncher for Commodore files written in pure Ruby
|
|
156
70
|
test_files: []
|