omnizip 0.3.24 → 0.3.26
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/CHANGELOG.md +20 -0
- data/lib/omnizip/algorithms/bzip2/bwt.rb +31 -19
- data/lib/omnizip/algorithms/bzip2/bz2.rb +625 -0
- data/lib/omnizip/algorithms/bzip2.rb +11 -39
- data/lib/omnizip/version.rb +1 -1
- metadata +2 -5
- data/lib/omnizip/algorithms/bzip2/decoder.rb +0 -187
- data/lib/omnizip/algorithms/bzip2/encoder.rb +0 -231
- data/lib/omnizip/algorithms/bzip2/huffman.rb +0 -206
- data/lib/omnizip/algorithms/bzip2/mtf.rb +0 -101
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (C) 2025 Ribose Inc.
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
6
|
-
# copy of this software and associated documentation files (the "Software"),
|
|
7
|
-
# to deal in the Software without restriction, including without limitation
|
|
8
|
-
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
-
# and/or sell copies of the Software, and to permit persons to whom the
|
|
10
|
-
# Software is furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
21
|
-
# DEALINGS IN THE SOFTWARE.
|
|
22
|
-
|
|
23
|
-
module Omnizip
|
|
24
|
-
module Algorithms
|
|
25
|
-
class BZip2 < Algorithm
|
|
26
|
-
# Move-to-Front (MTF) Transform
|
|
27
|
-
#
|
|
28
|
-
# MTF is a data transformation that exploits locality of reference.
|
|
29
|
-
# It maintains a list of symbols and moves accessed symbols to the
|
|
30
|
-
# front of the list. This tends to concentrate frequently accessed
|
|
31
|
-
# symbols at low indices, making the data more compressible.
|
|
32
|
-
#
|
|
33
|
-
# After BWT, the data often has runs of the same character. MTF
|
|
34
|
-
# converts these to runs of low numbers (often 0), which are then
|
|
35
|
-
# efficiently compressed by RLE.
|
|
36
|
-
#
|
|
37
|
-
# The algorithm:
|
|
38
|
-
# 1. Initialize symbol list [0, 1, 2, ..., 255]
|
|
39
|
-
# 2. For each byte in input:
|
|
40
|
-
# - Find its position in the symbol list
|
|
41
|
-
# - Output that position
|
|
42
|
-
# - Move the byte to the front of the list
|
|
43
|
-
class Mtf
|
|
44
|
-
# Encode data using Move-to-Front transform
|
|
45
|
-
#
|
|
46
|
-
# @param data [String] Input data to transform
|
|
47
|
-
# @return [String] MTF-encoded data (byte indices)
|
|
48
|
-
def encode(data)
|
|
49
|
-
return "".b if data.empty?
|
|
50
|
-
|
|
51
|
-
symbols = init_symbol_list
|
|
52
|
-
result = []
|
|
53
|
-
|
|
54
|
-
data.each_byte do |byte|
|
|
55
|
-
# Find position of byte in symbol list
|
|
56
|
-
index = symbols.index(byte)
|
|
57
|
-
result << index
|
|
58
|
-
|
|
59
|
-
# Move byte to front
|
|
60
|
-
symbols.delete_at(index)
|
|
61
|
-
symbols.unshift(byte)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
result.pack("C*")
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Decode MTF-encoded data
|
|
68
|
-
#
|
|
69
|
-
# @param data [String] MTF-encoded indices
|
|
70
|
-
# @return [String] Original data
|
|
71
|
-
def decode(data)
|
|
72
|
-
return "".b if data.empty?
|
|
73
|
-
|
|
74
|
-
symbols = init_symbol_list
|
|
75
|
-
result = []
|
|
76
|
-
|
|
77
|
-
data.each_byte do |index|
|
|
78
|
-
# Get byte at this index
|
|
79
|
-
byte = symbols[index]
|
|
80
|
-
result << byte
|
|
81
|
-
|
|
82
|
-
# Move byte to front
|
|
83
|
-
symbols.delete_at(index)
|
|
84
|
-
symbols.unshift(byte)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
result.pack("C*")
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
private
|
|
91
|
-
|
|
92
|
-
# Initialize symbol list with all possible byte values
|
|
93
|
-
#
|
|
94
|
-
# @return [Array<Integer>] Symbol list [0, 1, 2, ..., 255]
|
|
95
|
-
def init_symbol_list
|
|
96
|
-
(0..255).to_a
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|