pr-zlib 1.0.5 → 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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/{CHANGES → CHANGES.md} +19 -6
  4. data/Gemfile +6 -0
  5. data/MANIFEST.md +20 -0
  6. data/{README → README.md} +29 -12
  7. data/Rakefile +11 -61
  8. data/bin/{minizip.rb → minirbgzip} +77 -65
  9. data/lib/pr/rbzlib/bytef.rb +16 -0
  10. data/lib/pr/rbzlib/bytef_arr.rb +29 -0
  11. data/lib/pr/rbzlib/bytef_str.rb +52 -0
  12. data/lib/pr/rbzlib/posf.rb +33 -0
  13. data/lib/pr/rbzlib.rb +1758 -1855
  14. data/lib/pr/zlib/deflate.rb +99 -0
  15. data/lib/pr/zlib/errors.rb +27 -0
  16. data/lib/pr/zlib/gzipfile.rb +315 -0
  17. data/lib/pr/zlib/gzipfile_errors.rb +19 -0
  18. data/lib/pr/zlib/gzipreader.rb +338 -0
  19. data/lib/pr/zlib/gzipwriter.rb +167 -0
  20. data/lib/pr/zlib/inflate.rb +114 -0
  21. data/lib/pr/zlib/zstream.rb +417 -0
  22. data/lib/pr/zlib.rb +25 -1466
  23. data/pr-zlib.gemspec +15 -15
  24. data/profile/bench_pr_zlib.rb +7 -5
  25. data/profile/bench_zlib.rb +7 -5
  26. data/profile/profile_pr_zlib_read.rb +3 -3
  27. data/profile/profile_pr_zlib_write.rb +3 -3
  28. data/spec/README.md +46 -0
  29. data/spec/rbzlib/bytef_arr_spec.rb +82 -0
  30. data/spec/rbzlib/bytef_spec.rb +72 -0
  31. data/spec/rbzlib/bytef_str_spec.rb +113 -0
  32. data/spec/rbzlib/posf_spec.rb +83 -0
  33. data/spec/rbzlib_spec.rb +170 -0
  34. data/spec/spec_helper.rb +27 -0
  35. data/spec/zlib/deflate_spec.rb +44 -0
  36. data/spec/zlib/gzip_file_spec.rb +86 -0
  37. data/spec/zlib/gzip_reader_spec.rb +276 -0
  38. data/spec/zlib/gzip_writer_spec.rb +275 -0
  39. data/spec/zlib/inflate_spec.rb +44 -0
  40. data/spec/zlib/zstream_spec.rb +156 -0
  41. data/spec/zlib_spec.rb +195 -0
  42. data.tar.gz.sig +0 -0
  43. metadata +68 -55
  44. metadata.gz.sig +0 -0
  45. data/MANIFEST +0 -20
  46. data/test/test_rbzlib.rb +0 -133
  47. data/test/test_rbzlib_bytef.rb +0 -76
  48. data/test/test_rbzlib_posf.rb +0 -56
  49. data/test/test_zlib.rb +0 -162
  50. data/test/test_zlib_deflate.rb +0 -55
  51. data/test/test_zlib_gzip_file.rb +0 -93
  52. data/test/test_zlib_gzip_reader.rb +0 -183
  53. data/test/test_zlib_gzip_writer.rb +0 -186
  54. data/test/test_zlib_inflate.rb +0 -55
  55. data/test/test_zlib_zstream.rb +0 -146
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e267929bdd826d6886a7c925291f1a8e2f344e9d2d6a4458c11f7fff0a68f896
4
- data.tar.gz: 04d530d76deb665ba5b825545ac41b032ae0b2a792d24b72ab09e5bc3281c642
3
+ metadata.gz: cde92bf4908555ba88f41b5c5e21634008c87aa817d1630eb33f153ad9bb9e19
4
+ data.tar.gz: 70418f20d59f855af6ac56a85959f09a68ce03e72ecbcb76a5b869accbf026a1
5
5
  SHA512:
6
- metadata.gz: 5bfa36efad4f579428aa55297044cf0a1174fbded31d7b0e4c2d79815306bb9406f9b48ed4afb7c71c2e12d8114650efca13a444c391dcc5f11a72bc56da3073
7
- data.tar.gz: ae47b4147c1607ec1ab0962a5c49200874c3b62010186a1648b2c27f8b85f341a5ef83074774acdaa9b809c73d21938098850279cc037b3742fce98321675381
6
+ metadata.gz: 704e0d45e29f0199f7b1dc627a8670900de6b93303dcc324ca25c9607b5d7e9e41ee78e2aee12d2e7f6c56771d3a634b0e6d87185a5b055c3bce23ae77a9d7fc
7
+ data.tar.gz: 29a6adb5f8fd1ee0afa422a39f20d00d9d907db56e09641426d5f20b98c7a06096566e8a3ec1a369226fc06c27c6239cd94edce6b8fc16c786beb5adf59bd00e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,4 +1,17 @@
1
- = 1.0.5 - 18-Mar-2018
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
8
+ * Added the minirbgzip executable, a Ruby implementation of minigzip.
9
+ Formerly minigzip.rb, this had been part of the repo but had never been
10
+ released with the gem.
11
+ * Some minor updates and fixes to the minirbgzip executable.
12
+ * Metadata fix for changelog_uri.
13
+
14
+ ## 1.0.5 - 18-Mar-2018
2
15
  * Set the frozen_string_literal pragma, which gives us a small performance
3
16
  boost for reads.
4
17
  * Removed the custom Fixnum#ord method.
@@ -6,12 +19,12 @@
6
19
  * Added metadata to the gemspec plus some other minor updates.
7
20
  * Updated cert.
8
21
 
9
- = 1.0.4 - 15-Nov-2016
22
+ ## 1.0.4 - 15-Nov-2016
10
23
  * Fixed an endian bug. Thanks go to Benoit Daloze for the patch.
11
24
  * The version constants are now frozen (and fixed the version number).
12
25
  * Updated the cert.
13
26
 
14
- = 1.0.3 - 3-Dec-2015
27
+ ## 1.0.3 - 3-Dec-2015
15
28
  * Added a license. This library is now covered under the zlib license.
16
29
  * Some performance tuning. Reads are 2-3 times faster, while writes are
17
30
  about twenty percent faster.
@@ -21,10 +34,10 @@
21
34
  * More stringent value and limit checking added. Thanks go to
22
35
  Chris Seaton for the patches.
23
36
 
24
- = 1.0.2 - 24-Jun-2015
37
+ ## 1.0.2 - 24-Jun-2015
25
38
  * Fixed a marshalling issue.
26
39
 
27
- = 1.0.1 - 16-Oct-2014
40
+ ## 1.0.1 - 16-Oct-2014
28
41
  * Added benchmark and profiler scripts and rake tasks.
29
42
  * Switched profiling scripts to use ruby-prof.
30
43
  * The test-unit and ruby-prof libraries are now development dependencies.
@@ -32,5 +45,5 @@
32
45
  * Some minor test suite updates, mostly for 1.9.3.
33
46
  * Updated the gemspec, removed Rubyforge references.
34
47
 
35
- = 1.0.0 - 12-Jun-2009
48
+ ## 1.0.0 - 12-Jun-2009
36
49
  * Initial release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "ruby-prof", :platforms => [:mri, :truffleruby]
4
+ gem "jruby-prof", :platforms => :jruby
5
+
6
+ gemspec
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
@@ -1,19 +1,25 @@
1
- = Description
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
- = Synopsis
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
- = Motivation
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
- = TODO
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
- = Caveats
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
- = License
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
- = Authors
50
-
51
- * Park Heesob (C translation)
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 'rake/testtask'
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
@@ -16,11 +16,11 @@ end
16
16
 
17
17
  namespace :gem do
18
18
  desc 'Create the pr-zlib gem'
19
- task :create do
19
+ task :create => :clean 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, true)
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
- Rake::TestTask.new do |t|
58
- t.warning = true
59
- t.verbose = true
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
- Rake::TestTask.new('test_zlib') do |t|
63
- t.warning = true
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 => :test
66
+ task :default => :spec
@@ -1,9 +1,9 @@
1
- # minigzip.rb -- simulate gzip using the zlib compression library
1
+ #!/usr/bin/env ruby
2
+
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
4
6
  #
5
- #
6
- #
7
7
  # minigzip is a minimal implementation of the gzip utility. This is
8
8
  # only an example of using zlib and isn't meant to replace the
9
9
  # full-featured gzip. No attempt is made to deal with file systems
@@ -11,10 +11,10 @@
11
11
  # very limited. So use minigzip only for testing; use gzip for the
12
12
  # real thing. On MSDOS, use only on file names without extension
13
13
  # or in pipe mode.
14
- #
15
- # Ruby tralnslation By Park Heesob.
14
+ #
15
+ # minigzip to minirbgzip Ruby translation By Park Heesob.
16
16
 
17
- require 'rbzlib'
17
+ require_relative '../lib/pr-zlib'
18
18
  include Rbzlib
19
19
 
20
20
  GZ_SUFFIX = ".gz"
@@ -23,69 +23,70 @@ SUFFIX_LEN = GZ_SUFFIX.length
23
23
  BUFLEN = 16384
24
24
  MAX_NAME_LEN = 1024
25
25
 
26
-
27
26
  def error(msg)
28
- puts("#{__FILE__}: #{msg}")
29
- exit(1)
27
+ puts("#{__FILE__}: #{msg}")
28
+ exit(1)
30
29
  end
31
30
 
32
31
  def gz_compress(_in, out)
33
- while(true)
34
- begin
35
- buf = _in.read(BUFLEN)
36
- rescue
37
- raise RuntimeError,"read"
38
- end
39
- break if buf.nil?
40
- err = 0
41
- len = buf.length
42
- if (gzwrite(out, buf, len) != len)
43
- error(gzerror(out, err))
44
- end
32
+ while true
33
+ begin
34
+ buf = _in.read(BUFLEN)
35
+ rescue
36
+ raise RuntimeError,"read"
45
37
  end
46
- _in.close
47
- error("failed gzclose") if (gzclose(out) != Z_OK)
48
- end
49
38
 
39
+ break if buf.nil?
40
+
41
+ err = 0
42
+ len = buf.length
43
+
44
+ if (gzwrite(out, buf, len) != len)
45
+ error(gzerror(out, err))
46
+ end
47
+ end
48
+ _in.close
49
+ error("failed gzclose") if (gzclose(out) != Z_OK)
50
+ end
50
51
 
51
52
  def gz_uncompress(_in, out)
52
- buf = 0.chr * BUFLEN
53
- while true
54
- len = gzread(_in, buf, buf.length)
55
- err = 0
56
- error(gzerror(_in, err)) if (len < 0)
57
- break if len.zero?
53
+ buf = 0.chr * BUFLEN
54
+ while true
55
+ len = gzread(_in, buf, buf.length)
56
+ err = 0
57
+ error(gzerror(_in, err)) if (len < 0)
58
+ break if len.zero?
58
59
  if(out.write(buf[0,len]) != len)
59
- error("failed write")
60
- end
60
+ error("failed write")
61
61
  end
62
- begin
63
- out.close
64
- rescue
65
- error("failed fclose")
66
- end
67
-
68
- error("failed gzclose") if (gzclose(_in) != Z_OK)
62
+ end
63
+ begin
64
+ out.close
65
+ rescue
66
+ error("failed fclose")
67
+ end
68
+
69
+ error("failed gzclose") if (gzclose(_in) != Z_OK)
69
70
  end
70
71
 
71
-
72
72
  def file_compress(file, mode)
73
- outfile = file + GZ_SUFFIX
73
+ outfile = file + GZ_SUFFIX
74
74
 
75
- _in = File.open(file, "rb")
76
- if _in.nil?
77
- raise RuntimeError,file
78
- end
79
- out = gzopen(outfile, mode)
80
- if out.nil?
81
- puts("#{__FILE__}: can't gzopen #{outfile}")
82
- exit(1)
83
- end
84
- gz_compress(_in, out)
75
+ _in = File.open(file, "rb")
76
+ if _in.nil?
77
+ raise RuntimeError,file
78
+ end
79
+ out = gzopen(outfile, mode)
85
80
 
86
- File.unlink(file)
87
- end
81
+ if out.nil?
82
+ puts("#{__FILE__}: can't gzopen #{outfile}")
83
+ exit(1)
84
+ end
88
85
 
86
+ gz_compress(_in, out)
87
+
88
+ File.unlink(file)
89
+ end
89
90
 
90
91
  def file_uncompress(file)
91
92
  len = file.length
@@ -94,17 +95,17 @@ def file_uncompress(file)
94
95
  if (file[-SUFFIX_LEN..-1] == GZ_SUFFIX)
95
96
  infile = file.dup
96
97
  outfile = buf[0..(-SUFFIX_LEN-1)]
97
- else
98
+ else
98
99
  outfile = file.dup
99
100
  infile = buf + GZ_SUFFIX
100
101
  end
101
102
  _in = gzopen(infile, "rb")
102
- if _in.nil?
103
+ if _in.nil?
103
104
  puts("#{__FILE__}: can't gzopen #{infile}")
104
105
  exit(1)
105
106
  end
106
107
  out = File.open(outfile, "wb")
107
- if out.nil?
108
+ if out.nil?
108
109
  raise RuntimeError,file
109
110
  exit(1)
110
111
  end
@@ -141,6 +142,17 @@ end
141
142
  outmode[3] = 'R'
142
143
  when "-1".."-9"
143
144
  outmode[2] = argv[1]
145
+ when "--help"
146
+ help = <<-HERE
147
+ Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...]
148
+ -d : decompress
149
+ -f : compress with Z_FILTERED
150
+ -h : compress with Z_HUFFMAN_ONLY
151
+ -r : compress with Z_RLE
152
+ -1 to -9 : compression level
153
+ HERE
154
+ puts help
155
+ exit!
144
156
  else
145
157
  ARGV.unshift(argv)
146
158
  break
@@ -149,23 +161,23 @@ end
149
161
  if (outmode[3].chr == ' ')
150
162
  outmode = outmode[0,3]
151
163
  end
152
- if (ARGV.empty?)
164
+ if (ARGV.empty?)
153
165
  $stdin.binmode
154
166
  $stdout.binmode
155
- if (uncompr)
167
+ if (uncompr)
156
168
  file = gzdopen($stdin.fileno, "rb")
157
- error("can't gzdopen stdin") if file.nil?
169
+ error("can't gzdopen stdin") if file.nil?
158
170
  gz_uncompress(file, $stdout)
159
- else
171
+ else
160
172
  file = gzdopen($stdout.fileno, outmode)
161
- error("can't gzdopen stdout") if file.nil?
173
+ error("can't gzdopen stdout") if file.nil?
162
174
  gz_compress($stdin, file)
163
175
  end
164
- else
165
- while !ARGV.empty?
166
- if (uncompr)
176
+ else
177
+ while !ARGV.empty?
178
+ if (uncompr)
167
179
  file_uncompress(ARGV.shift)
168
- else
180
+ else
169
181
  file_compress(ARGV.shift, outmode)
170
182
  end
171
183
  end
@@ -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