compress-bsc 1.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
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +8 -0
- data/LICENSE +192 -0
- data/README.md +279 -0
- data/Rakefile +96 -0
- data/bin/rbsc +306 -0
- data/certs/djberg96_pub.pem +26 -0
- data/compress-bsc.gemspec +45 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_asc.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_both.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_desc.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
- data/coverage/assets/0.13.2/application.css +1 -0
- data/coverage/assets/0.13.2/application.js +7 -0
- data/coverage/assets/0.13.2/colorbox/border.png +0 -0
- data/coverage/assets/0.13.2/colorbox/controls.png +0 -0
- data/coverage/assets/0.13.2/colorbox/loading.gif +0 -0
- data/coverage/assets/0.13.2/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.13.2/favicon_green.png +0 -0
- data/coverage/assets/0.13.2/favicon_red.png +0 -0
- data/coverage/assets/0.13.2/favicon_yellow.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/assets/0.13.2/loading.gif +0 -0
- data/coverage/assets/0.13.2/magnify.png +0 -0
- data/coverage/index.html +4779 -0
- data/examples/usage_example.rb +215 -0
- data/lib/compress/bsc/compressor.rb +81 -0
- data/lib/compress/bsc/decompressor.rb +159 -0
- data/lib/compress/bsc/error.rb +18 -0
- data/lib/compress/bsc/library.rb +100 -0
- data/lib/compress/bsc/version.rb +5 -0
- data/lib/compress/bsc.rb +26 -0
- data/lib/compress-bsc.rb +5 -0
- data/spec/compressor_spec.rb +124 -0
- data/spec/decompressor_spec.rb +135 -0
- data/spec/error_spec.rb +63 -0
- data/spec/examples.txt +60 -0
- data/spec/ffi_bsc_spec.rb +101 -0
- data/spec/library_spec.rb +97 -0
- data/spec/spec_helper.rb +53 -0
- data.tar.gz.sig +0 -0
- metadata +232 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a6bb538b17954a08da49b2b72664330e47c044d921cb5f5fbf8fcbf35b15f901
|
4
|
+
data.tar.gz: 723c26400539bc91dc0e290706f672908ea6af8e654641a8c5f1d1f73585a6ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f888361c887e1da90ee5a0dd70a44e35cdb7532ee0580d1d5e0ad46490618cdb77b2a139eb9f07feb6407ebba1c2be6026ceacdb344a3850abeec43215cacae5
|
7
|
+
data.tar.gz: 581f874b1e6eb9923a113e86a788c33af70ecb84a0747754772db355c1a90c1cd6312444af0fb49a9cd24f05714ecf4e705e85a1bbe31cb4154af732289796db
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity granting the License.
|
13
|
+
|
14
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
15
|
+
other entities that control, are controlled by, or are under common
|
16
|
+
control with that entity. For the purposes of this definition,
|
17
|
+
"control" means (i) the power, direct or indirect, to cause the
|
18
|
+
direction or management of such entity, whether by contract or
|
19
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
21
|
+
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
23
|
+
exercising permissions granted by this License.
|
24
|
+
|
25
|
+
"Source" shall mean the preferred form for making modifications,
|
26
|
+
including but not limited to software source code, documentation
|
27
|
+
source, and configuration files.
|
28
|
+
|
29
|
+
"Object" shall mean any form resulting from mechanical
|
30
|
+
transformation or translation of a Source form, including but
|
31
|
+
not limited to compiled object code, generated documentation,
|
32
|
+
and conversions to other media types.
|
33
|
+
|
34
|
+
"Work" shall mean the work of authorship, whether in Source or
|
35
|
+
Object form, made available under the License, as indicated by a
|
36
|
+
copyright notice that is included in or attached to the work
|
37
|
+
(which shall not include communications that are posted to public
|
38
|
+
discussions, are filed in support of a separate claim or are posted
|
39
|
+
to the License.
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based upon (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and derivative works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control
|
58
|
+
systems, and issue tracking systems that are managed by, or on behalf
|
59
|
+
of, the Licensor for the purpose of discussing and improving the Work,
|
60
|
+
but excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to use, reproduce, modify, distribute, sublicense,
|
71
|
+
and/or sell copies of the Work, and to permit persons to whom the
|
72
|
+
Work is furnished to do so, subject to the following conditions:
|
73
|
+
|
74
|
+
The above copyright notice and this permission notice shall be
|
75
|
+
included in all copies or substantial portions of the Work.
|
76
|
+
|
77
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
78
|
+
this License, each Contributor hereby grants to You a perpetual,
|
79
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
80
|
+
(except as stated in this section) patent license to make, have made,
|
81
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
82
|
+
where such license applies only to those patent claims licensable
|
83
|
+
by such Contributor that are necessarily infringed by their
|
84
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
85
|
+
with the Work to which such Contribution(s) was submitted. If You
|
86
|
+
institute patent litigation against any entity (including a
|
87
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
88
|
+
or a Contribution incorporated within the Work constitutes direct
|
89
|
+
or contributory patent infringement, then any patent licenses
|
90
|
+
granted to You under this License for that Work shall terminate
|
91
|
+
as of the date such litigation is filed.
|
92
|
+
|
93
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
94
|
+
Work or Derivative Works thereof in any medium, with or without
|
95
|
+
modifications, and in Source or Object form, provided that You
|
96
|
+
meet the following conditions:
|
97
|
+
|
98
|
+
(a) You must give any other recipients of the Work or
|
99
|
+
Derivative Works a copy of this License; and
|
100
|
+
|
101
|
+
(b) You must cause any modified files to carry prominent notices
|
102
|
+
stating that You changed the files; and
|
103
|
+
|
104
|
+
(c) You must retain, in the Source form of any Derivative Works
|
105
|
+
that You distribute, all copyright, trademark, patent,
|
106
|
+
and attribution notices from the Source form of the Work,
|
107
|
+
excluding those notices that do not pertain to any part of
|
108
|
+
the Derivative Works; and
|
109
|
+
|
110
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
111
|
+
distribution, then any Derivative Works that You distribute must
|
112
|
+
include a readable copy of the attribution notices contained
|
113
|
+
within such NOTICE file, excluding those notices that do not
|
114
|
+
pertain to any part of the Derivative Works, in at least one
|
115
|
+
of the following places: within a NOTICE text file distributed
|
116
|
+
as part of the Derivative Works; within the Source form or
|
117
|
+
documentation, if provided along with the Derivative Works; or,
|
118
|
+
within a display generated by the Derivative Works, if and
|
119
|
+
wherever such third-party notices normally appear. The contents
|
120
|
+
of the NOTICE file are for informational purposes only and
|
121
|
+
do not modify the License. You may add Your own attribution
|
122
|
+
notices within Derivative Works that You distribute, alongside
|
123
|
+
or as an addendum to the NOTICE text from the Work, provided
|
124
|
+
that such additional attribution notices cannot be construed
|
125
|
+
as modifying the License.
|
126
|
+
|
127
|
+
You may add Your own copyright notice to Your modifications and
|
128
|
+
may provide additional or different license terms and conditions
|
129
|
+
for use, reproduction, or distribution of Your modifications, or
|
130
|
+
for any such Derivative Works as a whole, provided Your use,
|
131
|
+
reproduction, and distribution of the Work otherwise complies with
|
132
|
+
the conditions stated in this License.
|
133
|
+
|
134
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
135
|
+
any Contribution intentionally submitted for inclusion in the Work
|
136
|
+
by You to the Licensor shall be under the terms and conditions of
|
137
|
+
this License, without any additional terms or conditions.
|
138
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
139
|
+
the terms of any separate license agreement you may have executed
|
140
|
+
with Licensor regarding such Contributions.
|
141
|
+
|
142
|
+
6. Trademarks. This License does not grant permission to use the trade
|
143
|
+
names, trademarks, service marks, or product names of the Licensor,
|
144
|
+
except as required for reasonable and customary use in describing the
|
145
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
146
|
+
|
147
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
148
|
+
agreed to in writing, Licensor provides the Work (and each
|
149
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
150
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
151
|
+
implied, including, without limitation, any warranties or conditions
|
152
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
153
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
154
|
+
appropriateness of using or redistributing the Work and assume any
|
155
|
+
risks associated with Your exercise of permissions under this License.
|
156
|
+
|
157
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
158
|
+
whether in tort (including negligence), contract, or otherwise,
|
159
|
+
unless required by applicable law (such as deliberate and grossly
|
160
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
161
|
+
liable to You for damages, including any direct, indirect, special,
|
162
|
+
incidental, or consequential damages of any character arising as a
|
163
|
+
result of this License or out of the use or inability to use the
|
164
|
+
Work (including but not limited to damages for loss of goodwill,
|
165
|
+
work stoppage, computer failure or malfunction, or any and all
|
166
|
+
other commercial damages or losses), even if such Contributor
|
167
|
+
has been advised of the possibility of such damages.
|
168
|
+
|
169
|
+
9. Accepting Warranty or Support. You may choose to offer, and to
|
170
|
+
charge a fee for, warranty, support, indemnity or other liability
|
171
|
+
obligations and/or rights consistent with this License. However, in
|
172
|
+
accepting such obligations, You may act only on Your own behalf and on
|
173
|
+
Your sole responsibility, not on behalf of any other Contributor, and
|
174
|
+
only if You agree to indemnify, defend, and hold each Contributor
|
175
|
+
harmless for any liability incurred by, or claims asserted against,
|
176
|
+
such Contributor by reason of your accepting any such warranty or support.
|
177
|
+
|
178
|
+
END OF TERMS AND CONDITIONS
|
179
|
+
|
180
|
+
Copyright 2025 compress-bsc Contributors
|
181
|
+
|
182
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
183
|
+
you may not use this file except in compliance with the License.
|
184
|
+
You may obtain a copy of the License at
|
185
|
+
|
186
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
187
|
+
|
188
|
+
Unless required by applicable law or agreed to in writing, software
|
189
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
190
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
191
|
+
See the License for the specific language governing permissions and
|
192
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,279 @@
|
|
1
|
+
# compress-bsc
|
2
|
+
|
3
|
+
A Ruby interface to the [libbsc](https://github.com/IlyaGrebnov/libbsc) high-performance block-sorting compression library using FFI.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Fast block-sorting compression and decompression
|
8
|
+
- Multiple compression algorithms (BWT, ST3-ST8)
|
9
|
+
- LZP (Lempel-Ziv-Prediction) preprocessing for improved compression
|
10
|
+
- Multi-threading support
|
11
|
+
- Memory-efficient streaming for large files
|
12
|
+
- Command-line interface
|
13
|
+
- Comprehensive error handling
|
14
|
+
- Object-oriented and functional APIs
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
First, install the libbsc library. On macOS with Homebrew:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
brew install libbsc
|
22
|
+
```
|
23
|
+
|
24
|
+
On Ubuntu/Debian:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
sudo apt-get install libbsc-dev
|
28
|
+
|
29
|
+
# or, if not available
|
30
|
+
|
31
|
+
apt-get install -y build-essential cmake
|
32
|
+
git clone https://github.com/IlyaGrebnov/libbsc
|
33
|
+
cd libbsc
|
34
|
+
cmake -DBSC_BUILD_SHARED_LIB=ON .
|
35
|
+
make
|
36
|
+
make install
|
37
|
+
```
|
38
|
+
|
39
|
+
Then add this line to your application's Gemfile:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
gem 'compress-bsc'
|
43
|
+
```
|
44
|
+
|
45
|
+
And then execute:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
bundle install
|
49
|
+
```
|
50
|
+
|
51
|
+
Or install it yourself as:
|
52
|
+
|
53
|
+
```bash
|
54
|
+
gem install compress-bsc
|
55
|
+
```
|
56
|
+
|
57
|
+
## Usage
|
58
|
+
|
59
|
+
### Simple API
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# You can require the library in either of these ways:
|
63
|
+
require 'compress/bsc'
|
64
|
+
# or
|
65
|
+
require 'compress-bsc'
|
66
|
+
|
67
|
+
# Initialize the library with default features (fast mode + multithreading)
|
68
|
+
bsc = Compress::BSC.new
|
69
|
+
|
70
|
+
# Initialize with custom features
|
71
|
+
bsc_fast = Compress::BSC.new(features: Compress::BSC::Library::LIBBSC_FEATURE_FASTMODE)
|
72
|
+
|
73
|
+
# Initialize with multiple features
|
74
|
+
bsc_custom = Compress::BSC.new(
|
75
|
+
features: Compress::BSC::Library::LIBBSC_FEATURE_FASTMODE |
|
76
|
+
Compress::BSC::Library::LIBBSC_FEATURE_MULTITHREADING |
|
77
|
+
Compress::BSC::Library::LIBBSC_FEATURE_LARGEPAGES
|
78
|
+
)
|
79
|
+
|
80
|
+
# Compress data
|
81
|
+
original = "Hello, World!" * 1000
|
82
|
+
compressed = bsc.compress(original)
|
83
|
+
puts "Compressed #{original.length} bytes to #{compressed.length} bytes"
|
84
|
+
|
85
|
+
# Decompress data
|
86
|
+
decompressed = bsc.decompress(compressed)
|
87
|
+
puts decompressed == original # => true
|
88
|
+
```
|
89
|
+
|
90
|
+
### Available Features
|
91
|
+
|
92
|
+
The BSC library can be initialized with different feature combinations:
|
93
|
+
|
94
|
+
- `LIBBSC_FEATURE_NONE` - No special features
|
95
|
+
- `LIBBSC_FEATURE_FASTMODE` - Enable fast mode for faster compression/decompression
|
96
|
+
- `LIBBSC_FEATURE_MULTITHREADING` - Enable multi-threading support
|
97
|
+
- `LIBBSC_FEATURE_LARGEPAGES` - Enable large pages for better memory performance
|
98
|
+
- `LIBBSC_FEATURE_CUDA` - Enable CUDA GPU acceleration (if available)
|
99
|
+
|
100
|
+
The default is `LIBBSC_FEATURE_FASTMODE | LIBBSC_FEATURE_MULTITHREADING`.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
# Examples of different feature combinations:
|
104
|
+
bsc_minimal = Compress::BSC.new(features: Compress::BSC::Library::LIBBSC_FEATURE_NONE)
|
105
|
+
bsc_gpu = Compress::BSC.new(features: Compress::BSC::Library::LIBBSC_FEATURE_CUDA)
|
106
|
+
bsc_all = Compress::BSC.new(
|
107
|
+
features: Compress::BSC::Library::LIBBSC_FEATURE_FASTMODE |
|
108
|
+
Compress::BSC::Library::LIBBSC_FEATURE_MULTITHREADING |
|
109
|
+
Compress::BSC::Library::LIBBSC_FEATURE_LARGEPAGES |
|
110
|
+
Compress::BSC::Library::LIBBSC_FEATURE_CUDA
|
111
|
+
)
|
112
|
+
```
|
113
|
+
|
114
|
+
### Object-Oriented API
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
require 'compress/bsc'
|
118
|
+
|
119
|
+
bsc = Compress::BSC.new
|
120
|
+
|
121
|
+
# Create a compressor with custom options
|
122
|
+
compressor = Compress::BSC::Compressor.new(
|
123
|
+
lzp_hash_size: 16, # Enable LZP with 64KB hash table
|
124
|
+
lzp_min_len: 128, # Minimum LZP match length
|
125
|
+
block_sorter: Compress::BSC::Library::LIBBSC_BLOCKSORTER_ST4,
|
126
|
+
features: Compress::BSC::Library::LIBBSC_FEATURE_MULTITHREADING
|
127
|
+
)
|
128
|
+
|
129
|
+
# Compress data
|
130
|
+
data = File.binread("large_file.txt")
|
131
|
+
compressed = compressor.compress(data)
|
132
|
+
|
133
|
+
# Or compress directly to file
|
134
|
+
compressor.compress_file("input.txt", "output.bsc")
|
135
|
+
```
|
136
|
+
|
137
|
+
### Decompression
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
# Create a decompressor
|
141
|
+
decompressor = Compress::BSC::Decompressor.new
|
142
|
+
|
143
|
+
# Decompress data
|
144
|
+
decompressed = decompressor.decompress(compressed)
|
145
|
+
|
146
|
+
# Or decompress from file
|
147
|
+
decompressor.decompress_file("output.bsc", "restored.txt")
|
148
|
+
|
149
|
+
# Get information about compressed data
|
150
|
+
info = Compress::BSC::Decompressor.block_info(compressed)
|
151
|
+
puts "Original size: #{info[:data_size]} bytes"
|
152
|
+
puts "Block size: #{info[:block_size]} bytes"
|
153
|
+
```
|
154
|
+
|
155
|
+
### Command-Line Interface
|
156
|
+
|
157
|
+
The gem includes a command-line tool for compression and decompression:
|
158
|
+
|
159
|
+
```bash
|
160
|
+
# Compress a file
|
161
|
+
rbsc -c -f input.txt -o output.bsc
|
162
|
+
|
163
|
+
# Decompress a file
|
164
|
+
rbsc -d -f output.bsc -o restored.txt
|
165
|
+
|
166
|
+
# Show information about a compressed file
|
167
|
+
rbsc -i -f output.bsc
|
168
|
+
|
169
|
+
# Advanced compression with LZP preprocessing
|
170
|
+
rbsc -c -f large.txt -o large.bsc --lzp-hash 16 --lzp-min 64 --threads
|
171
|
+
|
172
|
+
# Show help
|
173
|
+
rbsc --help
|
174
|
+
```
|
175
|
+
|
176
|
+
### Advanced Options
|
177
|
+
|
178
|
+
#### Block Sorters
|
179
|
+
|
180
|
+
- `LIBBSC_BLOCKSORTER_BWT` (0) - Burrows-Wheeler Transform (default)
|
181
|
+
- `LIBBSC_BLOCKSORTER_ST3` (3) - Suffix Tree depth 3
|
182
|
+
- `LIBBSC_BLOCKSORTER_ST4` (4) - Suffix Tree depth 4
|
183
|
+
- `LIBBSC_BLOCKSORTER_ST5` (5) - Suffix Tree depth 5
|
184
|
+
- `LIBBSC_BLOCKSORTER_ST6` (6) - Suffix Tree depth 6
|
185
|
+
- `LIBBSC_BLOCKSORTER_ST7` (7) - Suffix Tree depth 7
|
186
|
+
- `LIBBSC_BLOCKSORTER_ST8` (8) - Suffix Tree depth 8
|
187
|
+
|
188
|
+
#### Coders
|
189
|
+
|
190
|
+
- `LIBBSC_CODER_QLFC_STATIC` (1) - Static QLFC
|
191
|
+
- `LIBBSC_CODER_QLFC_ADAPTIVE` (2) - Adaptive QLFC (default)
|
192
|
+
- `LIBBSC_CODER_QLFC_FAST` (3) - Fast QLFC
|
193
|
+
|
194
|
+
#### Features
|
195
|
+
|
196
|
+
- `LIBBSC_FEATURE_FASTMODE` - Enable fast compression mode
|
197
|
+
- `LIBBSC_FEATURE_MULTITHREADING` - Enable multi-threading
|
198
|
+
- `LIBBSC_FEATURE_LARGEPAGES` - Use large memory pages
|
199
|
+
- `LIBBSC_FEATURE_CUDA` - Enable CUDA acceleration (if available)
|
200
|
+
|
201
|
+
#### LZP Options
|
202
|
+
|
203
|
+
- `lzp_hash_size`: Hash table size (10-28, 0 to disable)
|
204
|
+
- `lzp_min_len`: Minimum match length (4-255, 0 to disable)
|
205
|
+
|
206
|
+
### Error Handling
|
207
|
+
|
208
|
+
The library provides detailed error information:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
begin
|
212
|
+
bsc = Compress::BSC.new
|
213
|
+
compressed = bsc.compress("some data")
|
214
|
+
rescue Compress::BSC::Error => e
|
215
|
+
puts "Error: #{e.error_name} (code: #{e.code})"
|
216
|
+
puts e.message
|
217
|
+
end
|
218
|
+
```
|
219
|
+
|
220
|
+
## Performance
|
221
|
+
|
222
|
+
BSC typically provides better compression ratios than traditional algorithms:
|
223
|
+
|
224
|
+
- Better than gzip/zlib for most data types
|
225
|
+
- Competitive with LZMA/7zip but faster decompression
|
226
|
+
- Excellent for text, logs, and structured data
|
227
|
+
- LZP preprocessing significantly improves compression for repetitive data
|
228
|
+
|
229
|
+
Example compression ratios on text data:
|
230
|
+
- Plain text: 3-5x compression
|
231
|
+
- Log files: 5-10x compression
|
232
|
+
- Source code: 4-7x compression
|
233
|
+
- JSON/XML: 6-12x compression
|
234
|
+
|
235
|
+
## Requirements
|
236
|
+
|
237
|
+
- Ruby 2.7 or later
|
238
|
+
- libbsc library installed on your system
|
239
|
+
- FFI gem
|
240
|
+
|
241
|
+
## Development
|
242
|
+
|
243
|
+
After checking out the repo, run:
|
244
|
+
|
245
|
+
```bash
|
246
|
+
bundle install
|
247
|
+
```
|
248
|
+
|
249
|
+
To run the test suite:
|
250
|
+
|
251
|
+
```bash
|
252
|
+
bundle exec rspec
|
253
|
+
```
|
254
|
+
|
255
|
+
To run a specific test:
|
256
|
+
|
257
|
+
```bash
|
258
|
+
bundle exec rspec spec/compressor_spec.rb
|
259
|
+
```
|
260
|
+
|
261
|
+
## Contributing
|
262
|
+
|
263
|
+
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.
|
264
|
+
|
265
|
+
## License
|
266
|
+
|
267
|
+
This gem is available as open source under the terms of the [Apache License 2.0](https://opensource.org/licenses/Apache-2.0), matching the license of the underlying libbsc library.
|
268
|
+
|
269
|
+
## Credits
|
270
|
+
|
271
|
+
- [libbsc](https://github.com/IlyaGrebnov/libbsc) by Ilya Grebnov - The underlying compression library
|
272
|
+
- This Ruby wrapper provides an idiomatic interface to the excellent libbsc library
|
273
|
+
|
274
|
+
## Copyright
|
275
|
+
(C) 2025, Daniel J. Berger
|
276
|
+
All Rights Reserved
|
277
|
+
|
278
|
+
## Author
|
279
|
+
Daniel J. Berger
|
data/Rakefile
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "ruby.core", "**/*.lock")
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
desc "Create the compress-bsc gem"
|
9
|
+
task :create => [:clean] do
|
10
|
+
require 'rubygems/package'
|
11
|
+
spec = Gem::Specification.load('compress-bsc.gemspec')
|
12
|
+
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
13
|
+
Gem::Package.build(spec)
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Install the compress-bsc gem"
|
17
|
+
task :install => [:create] do
|
18
|
+
file = Dir["*.gem"].first
|
19
|
+
sh "gem install -l #{file}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Default RSpec task
|
24
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
25
|
+
task.rspec_opts = ['--color', '--format', 'documentation']
|
26
|
+
end
|
27
|
+
|
28
|
+
# RSpec task with coverage
|
29
|
+
RSpec::Core::RakeTask.new(:spec_with_coverage) do |task|
|
30
|
+
task.rspec_opts = ['--color', '--format', 'documentation']
|
31
|
+
ENV['COVERAGE'] = 'true'
|
32
|
+
end
|
33
|
+
|
34
|
+
# RSpec task with verbose output
|
35
|
+
RSpec::Core::RakeTask.new(:spec_verbose) do |task|
|
36
|
+
task.rspec_opts = ['--color', '--format', 'documentation', '--backtrace']
|
37
|
+
end
|
38
|
+
|
39
|
+
# RSpec task for CI environments
|
40
|
+
RSpec::Core::RakeTask.new(:spec_ci) do |task|
|
41
|
+
task.rspec_opts = ['--color', '--format', 'progress', '--format', 'RspecJunitFormatter', '--out', 'tmp/rspec.xml']
|
42
|
+
end
|
43
|
+
|
44
|
+
task default: :spec
|
45
|
+
|
46
|
+
# Documentation tasks
|
47
|
+
YARD::Rake::YardocTask.new do |task|
|
48
|
+
task.files = ['lib/**/*.rb']
|
49
|
+
task.options = ['--markup', 'markdown', '--readme', 'README.md']
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Generate documentation and open it"
|
53
|
+
task :doc => :yard do
|
54
|
+
system "open doc/index.html" if RUBY_PLATFORM =~ /darwin/
|
55
|
+
end
|
56
|
+
|
57
|
+
# Code quality tasks
|
58
|
+
begin
|
59
|
+
require 'rubocop/rake_task'
|
60
|
+
RuboCop::RakeTask.new
|
61
|
+
rescue LoadError
|
62
|
+
# RuboCop not available
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "Install libbsc on macOS using Homebrew"
|
66
|
+
task :install_libbsc_mac do
|
67
|
+
puts "Installing libbsc on macOS..."
|
68
|
+
sh "brew install libbsc" rescue puts "Failed to install via Homebrew. Please install libbsc manually."
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Install libbsc on Ubuntu/Debian"
|
72
|
+
task :install_libbsc_ubuntu do
|
73
|
+
puts "Installing libbsc on Ubuntu/Debian..."
|
74
|
+
sh "sudo apt-get update && sudo apt-get install -y libbsc-dev" rescue puts "Failed to install via apt. Please install libbsc manually."
|
75
|
+
end
|
76
|
+
|
77
|
+
desc "Build libbsc from source"
|
78
|
+
task :build_libbsc do
|
79
|
+
puts "Building libbsc from source..."
|
80
|
+
puts "Please follow the instructions at: https://github.com/IlyaGrebnov/libbsc"
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "Check if libbsc is available"
|
84
|
+
task :check_libbsc do
|
85
|
+
begin
|
86
|
+
require_relative 'lib/compress/bsc'
|
87
|
+
Compress::BSC::Library # Try to load the library
|
88
|
+
puts "✓ libbsc library found and loaded successfully"
|
89
|
+
rescue LoadError => e
|
90
|
+
puts "✗ libbsc library not found: #{e.message}"
|
91
|
+
puts "\nTo install libbsc:"
|
92
|
+
puts " macOS: rake install_libbsc_mac"
|
93
|
+
puts " Ubuntu/Debian: rake install_libbsc_ubuntu"
|
94
|
+
puts " From source: rake build_libbsc"
|
95
|
+
end
|
96
|
+
end
|