pr-zlib 1.0.6 → 1.1.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +13 -7
- data/Gemfile +6 -0
- data/MANIFEST.md +20 -0
- data/{README → README.md} +29 -12
- data/Rakefile +10 -60
- data/bin/minirbgzip +4 -2
- data/lib/pr/rbzlib/bytef.rb +16 -0
- data/lib/pr/rbzlib/bytef_arr.rb +29 -0
- data/lib/pr/rbzlib/bytef_str.rb +52 -0
- data/lib/pr/rbzlib/posf.rb +33 -0
- data/lib/pr/rbzlib.rb +1758 -1855
- data/lib/pr/zlib/deflate.rb +99 -0
- data/lib/pr/zlib/errors.rb +27 -0
- data/lib/pr/zlib/gzipfile.rb +315 -0
- data/lib/pr/zlib/gzipfile_errors.rb +19 -0
- data/lib/pr/zlib/gzipreader.rb +338 -0
- data/lib/pr/zlib/gzipwriter.rb +167 -0
- data/lib/pr/zlib/inflate.rb +114 -0
- data/lib/pr/zlib/zstream.rb +417 -0
- data/lib/pr/zlib.rb +25 -1466
- data/pr-zlib.gemspec +14 -15
- data/profile/bench_pr_zlib.rb +7 -5
- data/profile/bench_zlib.rb +7 -5
- data/profile/profile_pr_zlib_read.rb +3 -3
- data/profile/profile_pr_zlib_write.rb +3 -3
- data/spec/README.md +46 -0
- data/spec/rbzlib/bytef_arr_spec.rb +82 -0
- data/spec/rbzlib/bytef_spec.rb +72 -0
- data/spec/rbzlib/bytef_str_spec.rb +113 -0
- data/spec/rbzlib/posf_spec.rb +83 -0
- data/spec/rbzlib_spec.rb +170 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/zlib/deflate_spec.rb +44 -0
- data/spec/zlib/gzip_file_spec.rb +86 -0
- data/spec/zlib/gzip_reader_spec.rb +276 -0
- data/spec/zlib/gzip_writer_spec.rb +275 -0
- data/spec/zlib/inflate_spec.rb +44 -0
- data/spec/zlib/zstream_spec.rb +156 -0
- data/spec/zlib_spec.rb +195 -0
- data.tar.gz.sig +0 -0
- metadata +65 -53
- metadata.gz.sig +0 -0
- data/MANIFEST +0 -20
- data/test/test_rbzlib.rb +0 -133
- data/test/test_rbzlib_bytef.rb +0 -76
- data/test/test_rbzlib_posf.rb +0 -56
- data/test/test_zlib.rb +0 -162
- data/test/test_zlib_deflate.rb +0 -55
- data/test/test_zlib_gzip_file.rb +0 -93
- data/test/test_zlib_gzip_reader.rb +0 -183
- data/test/test_zlib_gzip_writer.rb +0 -186
- data/test/test_zlib_inflate.rb +0 -55
- data/test/test_zlib_zstream.rb +0 -146
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cde92bf4908555ba88f41b5c5e21634008c87aa817d1630eb33f153ad9bb9e19
|
4
|
+
data.tar.gz: 70418f20d59f855af6ac56a85959f09a68ce03e72ecbcb76a5b869accbf026a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 704e0d45e29f0199f7b1dc627a8670900de6b93303dcc324ca25c9607b5d7e9e41ee78e2aee12d2e7f6c56771d3a634b0e6d87185a5b055c3bce23ae77a9d7fc
|
7
|
+
data.tar.gz: 29a6adb5f8fd1ee0afa422a39f20d00d9d907db56e09641426d5f20b98c7a06096566e8a3ec1a369226fc06c27c6239cd94edce6b8fc16c786beb5adf59bd00e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/{CHANGES → CHANGES.md}
RENAMED
@@ -1,11 +1,17 @@
|
|
1
|
-
|
1
|
+
## 1.1.0 - 30-Aug-2025
|
2
|
+
* Fixed several critical bugs.
|
3
|
+
* Many Ruby and Rubocop warnings cleaned up.
|
4
|
+
* Tests now use rspec instead of test-unit.
|
5
|
+
* Lots of cleanup, reorganization and general refactoring.
|
6
|
+
|
7
|
+
## 1.0.6 - 19-Mar-2018
|
2
8
|
* Added the minirbgzip executable, a Ruby implementation of minigzip.
|
3
9
|
Formerly minigzip.rb, this had been part of the repo but had never been
|
4
10
|
released with the gem.
|
5
11
|
* Some minor updates and fixes to the minirbgzip executable.
|
6
12
|
* Metadata fix for changelog_uri.
|
7
13
|
|
8
|
-
|
14
|
+
## 1.0.5 - 18-Mar-2018
|
9
15
|
* Set the frozen_string_literal pragma, which gives us a small performance
|
10
16
|
boost for reads.
|
11
17
|
* Removed the custom Fixnum#ord method.
|
@@ -13,12 +19,12 @@
|
|
13
19
|
* Added metadata to the gemspec plus some other minor updates.
|
14
20
|
* Updated cert.
|
15
21
|
|
16
|
-
|
22
|
+
## 1.0.4 - 15-Nov-2016
|
17
23
|
* Fixed an endian bug. Thanks go to Benoit Daloze for the patch.
|
18
24
|
* The version constants are now frozen (and fixed the version number).
|
19
25
|
* Updated the cert.
|
20
26
|
|
21
|
-
|
27
|
+
## 1.0.3 - 3-Dec-2015
|
22
28
|
* Added a license. This library is now covered under the zlib license.
|
23
29
|
* Some performance tuning. Reads are 2-3 times faster, while writes are
|
24
30
|
about twenty percent faster.
|
@@ -28,10 +34,10 @@
|
|
28
34
|
* More stringent value and limit checking added. Thanks go to
|
29
35
|
Chris Seaton for the patches.
|
30
36
|
|
31
|
-
|
37
|
+
## 1.0.2 - 24-Jun-2015
|
32
38
|
* Fixed a marshalling issue.
|
33
39
|
|
34
|
-
|
40
|
+
## 1.0.1 - 16-Oct-2014
|
35
41
|
* Added benchmark and profiler scripts and rake tasks.
|
36
42
|
* Switched profiling scripts to use ruby-prof.
|
37
43
|
* The test-unit and ruby-prof libraries are now development dependencies.
|
@@ -39,5 +45,5 @@
|
|
39
45
|
* Some minor test suite updates, mostly for 1.9.3.
|
40
46
|
* Updated the gemspec, removed Rubyforge references.
|
41
47
|
|
42
|
-
|
48
|
+
## 1.0.0 - 12-Jun-2009
|
43
49
|
* Initial release
|
data/Gemfile
ADDED
data/MANIFEST.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
* CHANGES.md
|
2
|
+
* MANIFEST.md
|
3
|
+
* README.md
|
4
|
+
* pr-zlib.gemspec
|
5
|
+
* bin/minirbgzip
|
6
|
+
* certs/djberg96_pub.pem
|
7
|
+
* examples/example_rbzlib.rb
|
8
|
+
* lib/pr-zlib.rb
|
9
|
+
* lib/pr/rbzlib.rb
|
10
|
+
* lib/pr/zlib.rb
|
11
|
+
* test/test_rbzlib_bytef.rb
|
12
|
+
* test/test_rbzlib_posf.rb
|
13
|
+
* test/test_rbzlib.rb
|
14
|
+
* test/test_zlib_deflate.rb
|
15
|
+
* test/test_zlib_gzip_file.rb
|
16
|
+
* test/test_zlib_gzip_reader.rb
|
17
|
+
* test/test_zlib_gzip_writer.rb
|
18
|
+
* test/test_zlib_inflate.rb
|
19
|
+
* test/test_zlib_zstream.rb
|
20
|
+
* test/test_zlib.rb
|
data/{README → README.md}
RENAMED
@@ -1,19 +1,25 @@
|
|
1
|
-
|
1
|
+
## Description
|
2
2
|
The pr-zlib library is a pure Ruby version of the zlib compression library.
|
3
3
|
It consists of both a port of zlib.h and the Ruby zlib library that ships as
|
4
4
|
part of the standard library.
|
5
5
|
|
6
|
-
|
6
|
+
## Installation
|
7
|
+
`gem install pr-zlib`
|
7
8
|
|
9
|
+
## Adding the trusted cert
|
10
|
+
`gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/pr-zlib/main/certs/djberg96_pub.pem)`
|
11
|
+
|
12
|
+
## Synopsis
|
13
|
+
```ruby
|
8
14
|
# Imitating a bit of code used in rubygems
|
9
15
|
require 'pr/zlib'
|
10
16
|
require 'stringio'
|
11
17
|
|
12
18
|
data = StringIO.new(data)
|
13
19
|
Zlib::GzipReader.new(data).read
|
20
|
+
```
|
14
21
|
|
15
|
-
|
16
|
-
|
22
|
+
## Motivation
|
17
23
|
First, building the zlib C library on MS Windows with Visual C++ is very
|
18
24
|
difficult. However, certain libraries depend on zlib, most notably rubygems.
|
19
25
|
By providing a pure Ruby version we eliminate any compiler or platform
|
@@ -32,21 +38,32 @@ Last, the zlib interface that ships as part of the stdlib is a little on the
|
|
32
38
|
clunky side. By providing a pure Ruby version, authors can create their own
|
33
39
|
interface as they see fit.
|
34
40
|
|
35
|
-
|
41
|
+
Update August 2025: Most of the original motivation for this library is no
|
42
|
+
longer relevant today. Desktop users of MS Windows typically use the one-click
|
43
|
+
installer which bundles the shared objects it needs. In the land of Unix, where
|
44
|
+
most actual production code happens, folks use Docker images for Ruby which
|
45
|
+
either already bundles everything, or they just add it to their Dockerfile.
|
46
|
+
|
47
|
+
But, hey, I paid for this and it works. Who knows, maybe it'll be nice to have
|
48
|
+
around someday.
|
49
|
+
|
50
|
+
## Origins
|
51
|
+
This library was the result of a small code bounty that I (Daniel Berger) funded:
|
36
52
|
|
53
|
+
https://rubytalk.org/t/bounty-pure-ruby-zlib-gzipwriter/50730
|
54
|
+
|
55
|
+
## TODO
|
37
56
|
More tests, and better tests, are needed for both Rbzlib and Zlib.
|
38
57
|
|
39
|
-
|
58
|
+
## Caveats
|
40
59
|
You cannot use both this library and the zlib standard library at the same
|
41
60
|
time. If you try to use both there is a good chance you will get an allocation
|
42
61
|
error of some sort. If you already have zlib, you do not need this library.
|
43
62
|
|
44
|
-
|
45
|
-
|
63
|
+
## License
|
46
64
|
This library is covered under the same license as zlib itself. For the text
|
47
65
|
of the zlib license, please see http://zlib.net/zlib_license.html.
|
48
66
|
|
49
|
-
|
50
|
-
|
51
|
-
*
|
52
|
-
* Daniel Berger (Testing, packaging, deployment)
|
67
|
+
## Authors
|
68
|
+
* Park Heesob (Original C translation)
|
69
|
+
* Daniel Berger (Testing, packaging, deployment, maintenance)
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
|
-
require '
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
require 'rbconfig'
|
5
5
|
|
6
|
-
CLEAN.include("**/*.rbc", "**/*.gem", "**/*.txt", "**/*.gz")
|
6
|
+
CLEAN.include("**/*.rbc", "**/*.gem", "**/*.txt", "**/*.gz", "**/*.lock")
|
7
7
|
|
8
8
|
desc 'Install the pr-zlib library as zlib'
|
9
9
|
task :install_as_zlib do
|
@@ -20,7 +20,7 @@ namespace :gem do
|
|
20
20
|
require 'rubygems/package'
|
21
21
|
spec = eval(IO.read('pr-zlib.gemspec'))
|
22
22
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
23
|
-
Gem::Package.build(spec
|
23
|
+
Gem::Package.build(spec)
|
24
24
|
end
|
25
25
|
|
26
26
|
desc 'Install the pr-zlib gem'
|
@@ -54,63 +54,13 @@ namespace :profile do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
t.
|
57
|
+
# RSpec tests
|
58
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
59
|
+
t.pattern = 'spec/**/*_spec.rb'
|
60
|
+
t.rspec_opts = ['--format', 'documentation', '--color']
|
60
61
|
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
t.verbose = true
|
65
|
-
t.test_files = FileList['test/test_zlib.rb']
|
66
|
-
end
|
67
|
-
|
68
|
-
Rake::TestTask.new('test_gzip_file') do |t|
|
69
|
-
t.warning = true
|
70
|
-
t.verbose = true
|
71
|
-
t.test_files = FileList['test/test_zlib_gzip_file.rb']
|
72
|
-
end
|
73
|
-
|
74
|
-
Rake::TestTask.new('test_gzip_reader') do |t|
|
75
|
-
t.warning = true
|
76
|
-
t.verbose = true
|
77
|
-
t.test_files = FileList['test/test_zlib_gzip_reader.rb']
|
78
|
-
end
|
79
|
-
|
80
|
-
Rake::TestTask.new('test_gzip_writer') do |t|
|
81
|
-
t.warning = true
|
82
|
-
t.verbose = true
|
83
|
-
t.test_files = FileList['test/test_zlib_gzip_writer.rb']
|
84
|
-
end
|
85
|
-
|
86
|
-
Rake::TestTask.new('test_deflate') do |t|
|
87
|
-
t.warning = true
|
88
|
-
t.verbose = true
|
89
|
-
t.test_files = FileList['test/test_zlib_deflate.rb']
|
90
|
-
end
|
91
|
-
|
92
|
-
Rake::TestTask.new('test_inflate') do |t|
|
93
|
-
t.warning = true
|
94
|
-
t.verbose = true
|
95
|
-
t.test_files = FileList['test/test_zlib_inflate.rb']
|
96
|
-
end
|
97
|
-
|
98
|
-
Rake::TestTask.new('test_rbzlib') do |t|
|
99
|
-
t.warning = true
|
100
|
-
t.verbose = true
|
101
|
-
t.test_files = FileList['test/test_rbzlib.rb']
|
102
|
-
end
|
103
|
-
|
104
|
-
Rake::TestTask.new('test_rbzlib_bytef') do |t|
|
105
|
-
t.warning = true
|
106
|
-
t.verbose = true
|
107
|
-
t.test_files = FileList['test/test_rbzlib_bytef.rb']
|
108
|
-
end
|
109
|
-
|
110
|
-
Rake::TestTask.new('test_rbzlib_posf') do |t|
|
111
|
-
t.warning = true
|
112
|
-
t.verbose = true
|
113
|
-
t.test_files = FileList['test/test_rbzlib_posf.rb']
|
114
|
-
end
|
63
|
+
desc 'Run all RSpec tests'
|
64
|
+
task :test => :spec
|
115
65
|
|
116
|
-
task :default => :
|
66
|
+
task :default => :spec
|
data/bin/minirbgzip
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
1
3
|
# minigzip -- simulate gzip using the zlib compression library
|
2
4
|
# Copyright (C) 1995-2005 Jean-loup Gailly.
|
3
5
|
# For conditions of distribution and use, see copyright notice in rbzlib.rb
|
@@ -12,7 +14,7 @@
|
|
12
14
|
#
|
13
15
|
# minigzip to minirbgzip Ruby translation By Park Heesob.
|
14
16
|
|
15
|
-
|
17
|
+
require_relative '../lib/pr-zlib'
|
16
18
|
include Rbzlib
|
17
19
|
|
18
20
|
GZ_SUFFIX = ".gz"
|
@@ -147,7 +149,7 @@ end
|
|
147
149
|
-f : compress with Z_FILTERED
|
148
150
|
-h : compress with Z_HUFFMAN_ONLY
|
149
151
|
-r : compress with Z_RLE
|
150
|
-
-1 to -9 : compression level
|
152
|
+
-1 to -9 : compression level
|
151
153
|
HERE
|
152
154
|
puts help
|
153
155
|
exit!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'bytef_str'
|
4
|
+
require_relative 'bytef_arr'
|
5
|
+
|
6
|
+
module Rbzlib
|
7
|
+
class Bytef
|
8
|
+
def self.new(buffer, offset = 0)
|
9
|
+
if buffer.class == Array
|
10
|
+
Bytef_arr.new(buffer, offset)
|
11
|
+
else
|
12
|
+
Bytef_str.new(buffer, offset)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'bytef_str'
|
4
|
+
|
5
|
+
module Rbzlib
|
6
|
+
class Bytef_arr < Bytef_str
|
7
|
+
|
8
|
+
def initialize(buffer, offset = 0)
|
9
|
+
@buffer = buffer
|
10
|
+
@offset = offset
|
11
|
+
end
|
12
|
+
|
13
|
+
def [](idx)
|
14
|
+
@buffer[idx + @offset]
|
15
|
+
end
|
16
|
+
|
17
|
+
def []=(idx, val)
|
18
|
+
@buffer[idx + @offset] = val
|
19
|
+
end
|
20
|
+
|
21
|
+
def get
|
22
|
+
@buffer[@offset]
|
23
|
+
end
|
24
|
+
|
25
|
+
def set(val)
|
26
|
+
@buffer[@offset] = val
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rbzlib
|
4
|
+
class Bytef_str
|
5
|
+
attr_accessor :buffer, :offset
|
6
|
+
|
7
|
+
def initialize(buffer, offset = 0)
|
8
|
+
if buffer.class == String
|
9
|
+
@buffer = buffer
|
10
|
+
@offset = offset
|
11
|
+
@buffer.force_encoding('ASCII-8BIT')
|
12
|
+
else
|
13
|
+
@buffer = buffer.buffer
|
14
|
+
@offset = offset
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def length
|
19
|
+
@buffer.length
|
20
|
+
end
|
21
|
+
|
22
|
+
def +(inc)
|
23
|
+
@offset += inc
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def -(dec)
|
28
|
+
@offset -= dec
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](idx)
|
33
|
+
@buffer.getbyte(idx + @offset)
|
34
|
+
end
|
35
|
+
|
36
|
+
def []=(idx, val)
|
37
|
+
@buffer.setbyte(idx + @offset, val.ord)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get
|
41
|
+
@buffer.getbyte(@offset)
|
42
|
+
end
|
43
|
+
|
44
|
+
def set(val)
|
45
|
+
@buffer.setbyte(@offset, val.ord)
|
46
|
+
end
|
47
|
+
|
48
|
+
def current
|
49
|
+
@buffer[@offset..-1]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'bytef_str'
|
4
|
+
|
5
|
+
module Rbzlib
|
6
|
+
class Posf < Bytef_str
|
7
|
+
def +(inc)
|
8
|
+
@offset += inc * 2
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def -(dec)
|
13
|
+
@offset -= dec * 2
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](idx)
|
18
|
+
@buffer[(idx * 2) + @offset, 2].unpack('v').first
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(idx, val)
|
22
|
+
@buffer[(idx * 2) + @offset, 2] = [val].pack('v')
|
23
|
+
end
|
24
|
+
|
25
|
+
def get
|
26
|
+
@buffer[@offset, 2].unpack('v').first
|
27
|
+
end
|
28
|
+
|
29
|
+
def set(val)
|
30
|
+
@buffer[@offset, 2] = [val].pack('v')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|