bzip2-ffi 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03b164babce536cf85cdf6fa03a4baa85651c8a9463284eeb633a0db4ffcc6fa
4
- data.tar.gz: 42a231de039d293fe25cf5dc98c22d4650225a73fb363cee7fb3c16d69af0355
3
+ metadata.gz: 25b15e037a74f589a612d955890d194519a97abfa903c993589d0096794b6459
4
+ data.tar.gz: '088c393a99b19d1d625148c951461333d2ed9ef934df6e5efaee2ea0007b9620'
5
5
  SHA512:
6
- metadata.gz: 12a699a68f65e217b5c958697709bc65f3a64e2d627ab1ee16bf7519c43a0571321bb435a38f199639b6b1a9842a0e179022d91fd033ebf8ac907897c9e76c27
7
- data.tar.gz: 0dc68221d4c9ee943efd3bffaea0584cefd6d5b30f5ad4d998384177a3d6fe83e29691f344e4ee110786a0558355f2a90a74aed2624ff30257e72c66ad90727f
6
+ metadata.gz: 84ff7dd72ab2d08ebaf3eda64b104db414b882f90f4d05df06485bf0b5f9e6c116512d5c5183e8f921aacf660eaf58eb37d5d2fd959002b859fd97f9c8af7a8e
7
+ data.tar.gz: 59ee28b33e364ce56a453ad9abd2f6fad30e8aa623d6ddb89f50d8211b4ad77d32e3493bbac853e74b558e307af6f7db71d057aaddb72cbcc15338c332dec16b
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changes
2
2
 
3
+ ## Version 1.1.1 - 8-Jul-2023
4
+
5
+ * Added `Bzip2::FFI::Reader#tell`, returning the number of decompressed bytes
6
+ that have been read. `Bzip2::FFI::Reader#pos` is now an alias for
7
+ `Bzip2::FFI::Reader#tell`.
8
+ * Added `Bzip2::FFI::Writer#tell`, returning the number of uncompressed bytes
9
+ that have been written. `Bzip2::FFI::Writer#pos` is now an alias for
10
+ `Bzip2::FFI::Writer#tell`.
11
+
12
+
3
13
  ## Version 1.1.0 - 27-Feb-2021
4
14
 
5
15
  * `Bzip2::FFI::Reader` will now read all consecutive bzip2 compressed structures
data/Gemfile CHANGED
@@ -13,7 +13,7 @@ group :test do
13
13
 
14
14
  # coveralls is no longer maintained, but supports Ruby < 2.3.
15
15
  # coveralls_reborn is maintained, but requires Ruby >= 2.3.
16
- gem 'coveralls', '~> 0.8', require: false if RUBY_VERSION < '2.3'
16
+ gem 'coveralls', git: 'https://github.com/philr/coveralls-ruby.git', require: false if RUBY_VERSION < '2.3'
17
17
  gem 'coveralls_reborn', '~> 0.13', require: false if RUBY_VERSION >= '2.3'
18
18
 
19
19
 
@@ -38,8 +38,18 @@ group :test do
38
38
  # ffi 1.9.15 is declared as compatible with Ruby >= 1.8.7, but doesn't compile
39
39
  # on Ruby 1.9.3 on Windows.
40
40
  #
41
+ # The source version of ffi 1.15.5 is declared as compatible with Ruby >= 2.3.
42
+ # The binary version of 1.15.5 is declared as compatible with Ruby >= 2.4, so
43
+ # doesn't get used. The using the source version results in a segmentation
44
+ # fault during libffi initialization.
45
+ #
46
+ # Binaries of 15.5.0 to 15.5.4 are declared as compatible with Ruby >= 2.3,
47
+ # but don't get used with Bundler 2.3.23 and Ruby 2.3 on Windows.
48
+ #
41
49
  # Limit to earlier compatible versions.
42
50
  if RUBY_VERSION < '2.0' && RUBY_PLATFORM =~ /mingw/
43
51
  gem 'ffi', '< 1.9.0'
52
+ elsif RUBY_VERSION < '2.4' && RUBY_PLATFORM =~ /mingw/
53
+ gem 'ffi', '< 1.15.0'
44
54
  end
45
55
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2021 Philip Ross
1
+ Copyright (c) 2015-2023 Philip Ross
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -27,7 +27,7 @@ Bzip2::FFI is a pure-Ruby library that uses
27
27
  the libbz2 dynamic library at runtime.
28
28
 
29
29
  libbz2 is available as a package on most UNIX-based systems (for example,
30
- `libbz2-1.0` on Debian and Ubuntu, or `bzip2-libs` on Fedora, Red Hat, and
30
+ `libbz2-1.0` on Debian and Ubuntu, or `bzip2-libs` on Fedora, Red Hat and
31
31
  CentOS).
32
32
 
33
33
 
@@ -42,7 +42,7 @@ Download the DLL only package that matches your Ruby installation (x86 or x64)
42
42
  and extract to your `ruby\bin` directory.
43
43
 
44
44
  Builds from the bzip2-windows project depend on the Visual Studio C Runtime
45
- Library. Links to the installer can be found on the bzip2-windows release page.
45
+ Library. Links to the installer can be found on the bzip2-windows releases page.
46
46
 
47
47
 
48
48
  ## Usage
@@ -58,7 +58,7 @@ require 'bzip2/ffi'
58
58
 
59
59
  Data can be compressed using the `Bzip2::FFI::Writer` class. For example, the
60
60
  following compresses lines read from `ARGF` (either standard input, or file
61
- names given as command-line arguments:
61
+ names given as command-line arguments):
62
62
 
63
63
  ```ruby
64
64
  Bzip2::FFI::Writer.open(io_or_path) do |writer|
@@ -116,7 +116,8 @@ ensure
116
116
  end
117
117
  ```
118
118
 
119
- All the available bzipped data can be read and decompressed in a single step:
119
+ All the available bzipped data can also be read and decompressed in a single
120
+ step:
120
121
 
121
122
  ```ruby
122
123
  uncompressed = Bzip2::FFI::Reader.read(io_or_path)
@@ -135,6 +136,26 @@ ASCII-8BIT (BINARY) encoding representing the raw decompressed bytes.
135
136
  to the `#write` method (using the encoding of the `String`).
136
137
 
137
138
 
139
+ ### Streaming and Memory Usage
140
+
141
+ Bzip2::FFI compresses and decompresses data as a stream, allowing large files to
142
+ be handled without requiring the complete contents to be held in memory.
143
+
144
+ When decompressing, 4 KB of compressed data is read at a time. An additional 4
145
+ KB is required to pass the data to libbz2. Decompressed data is output in blocks
146
+ dictated by the length passed to `Bzip2::FFI::Reader#read` (defaulting to 4 KB
147
+ and requiring twice the length in memory to read from libbz2).
148
+
149
+ When compressing, up to 4 KB of compressed data is written at a time, requiring
150
+ up to 8 KB of memory. An additional copy is also taken of the `String` passed to
151
+ `Bzip2::FFI::Writer#write`.
152
+
153
+ Internally, libbz2 allocates additional memory according to the bzip2 block
154
+ size. Please refer to the
155
+ [Memory Management](https://sourceware.org/bzip2/manual/manual.html#memory-management)
156
+ section of the Bzip2 documentation for details.
157
+
158
+
138
159
  ## Documentation
139
160
 
140
161
  Documentation for Bzip2::FFI is available on
data/bzip2-ffi.gemspec CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.join('..', 'lib', 'bzip2', 'ffi', 'version'), __FI
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bzip2-ffi'
5
5
  s.version = Bzip2::FFI::VERSION
6
- s.summary = 'Reads and writes bzip2 compressed data using FFI bindings for libbz2.'
6
+ s.summary = 'Reads and writes bzip2 compressed data as a stream using FFI bindings for libbz2.'
7
7
  s.description = <<-EOF
8
8
  Bzip2::FFI is a Ruby wrapper for libbz2 using FFI bindings.
9
9
 
@@ -51,6 +51,11 @@ module Bzip2
51
51
  # the stream to the byte immediately following the end of the compressed
52
52
  # bzip2 data. If `#seek` raises an `IOError`, it will be caught and the
53
53
  # stream position will be left unchanged.
54
+ #
55
+ # {Reader} does not support seeking (it's not supported by the underlying
56
+ # libbz2 library). There are no `#seek` or `#pos=` methods. The only way to
57
+ # advance the position is to call {#read}. Discard the result if it's not
58
+ # needed.
54
59
  class Reader < IO
55
60
  # The number of bytes read from the compressed data stream at a time.
56
61
  #
@@ -352,10 +357,11 @@ module Bzip2
352
357
  #
353
358
  # @return [Integer] The number of decompressed bytes that have been read.
354
359
  # @raise [IOError] If the {Reader} has been closed.
355
- def pos
360
+ def tell
356
361
  check_closed
357
362
  @out_pos
358
363
  end
364
+ alias pos tell
359
365
 
360
366
  private
361
367
 
@@ -4,6 +4,6 @@
4
4
  module Bzip2
5
5
  module FFI
6
6
  # The Bzip2::FFI version number.
7
- VERSION = '1.1.0'
7
+ VERSION = '1.1.1'
8
8
  end
9
9
  end
@@ -40,6 +40,9 @@ module Bzip2
40
40
  # No character conversion is performed when writing and compressing. The
41
41
  # {write} and {#write} methods compress the raw bytes from the given
42
42
  # `String` (using the encoding of the `String`).
43
+ #
44
+ # {Writer} does not support seeking (it's not supported by the underlying
45
+ # libbz2 library). There are no `#seek` or `#pos=` methods.
43
46
  class Writer < IO
44
47
  # Size of the buffer passed to libbz2 for it to write compressed data to.
45
48
  #
@@ -344,10 +347,11 @@ module Bzip2
344
347
  # @return [Integer] The number of uncompressed bytes that have been
345
348
  # written.
346
349
  # @raise [IOError] If the {Writer} has been closed.
347
- def pos
350
+ def tell
348
351
  s = stream
349
352
  (s[:total_in_hi32] << 32) | s[:total_in_lo32]
350
353
  end
354
+ alias pos tell
351
355
 
352
356
  private
353
357
 
data/test/reader_test.rb CHANGED
@@ -79,6 +79,7 @@ class ReaderTest < Minitest::Test
79
79
  decompressed = reader.read(read_size)
80
80
  end
81
81
 
82
+ assert_equal(input.tell, reader.tell)
82
83
  assert_equal(input.pos, reader.pos)
83
84
 
84
85
  if buffer
@@ -104,6 +105,7 @@ class ReaderTest < Minitest::Test
104
105
  decompressed = reader.read
105
106
  end
106
107
 
108
+ assert_equal(buffer.bytesize, reader.tell)
107
109
  assert_equal(buffer.bytesize, reader.pos)
108
110
 
109
111
  refute_nil(decompressed)
@@ -569,23 +571,25 @@ class ReaderTest < Minitest::Test
569
571
  end
570
572
  end
571
573
 
572
- def test_pos_returns_decompressed_position
573
- Bzip2::FFI::Reader.open(fixture_path('compressed.bz2')) do |reader|
574
- assert_equal(0, reader.pos)
575
- reader.read(17)
576
- assert_equal(17, reader.pos)
577
- reader.read(8837)
578
- assert_equal(8854, reader.pos)
579
- reader.read
580
- assert_equal(65670, reader.pos)
574
+ [:tell, :pos].each do |method|
575
+ define_method("test_#{method}_returns_decompressed_position") do
576
+ Bzip2::FFI::Reader.open(fixture_path('compressed.bz2')) do |reader|
577
+ assert_equal(0, reader.public_send(method))
578
+ reader.read(17)
579
+ assert_equal(17, reader.public_send(method))
580
+ reader.read(8837)
581
+ assert_equal(8854, reader.public_send(method))
582
+ reader.read
583
+ assert_equal(65670, reader.public_send(method))
584
+ end
581
585
  end
582
- end
583
586
 
584
- def test_pos_raises_io_error_when_closed
585
- File.open(fixture_path('compressed.bz2'), 'rb') do |file|
586
- reader = Bzip2::FFI::Reader.new(file)
587
- reader.close
588
- assert_raises(IOError) { reader.pos }
587
+ define_method("test_#{method}_raises_io_error_when_closed") do
588
+ File.open(fixture_path('compressed.bz2'), 'rb') do |file|
589
+ reader = Bzip2::FFI::Reader.new(file)
590
+ reader.close
591
+ assert_raises(IOError) { reader.public_send(method) }
592
+ end
589
593
  end
590
594
  end
591
595
 
data/test/writer_test.rb CHANGED
@@ -48,11 +48,13 @@ class WriterTest < Minitest::Test
48
48
  buffer = io.read(read_size)
49
49
  break unless buffer
50
50
  assert_equal(buffer.bytesize, writer.write(buffer))
51
+ assert_equal(io.tell, writer.tell)
51
52
  assert_equal(io.pos, writer.pos)
52
53
  end
53
54
  else
54
55
  buffer = io.read
55
56
  assert_equal(buffer.bytesize, writer.write(buffer))
57
+ assert_equal(io.tell, writer.tell)
56
58
  assert_equal(io.pos, writer.pos)
57
59
  end
58
60
  end
@@ -226,38 +228,40 @@ class WriterTest < Minitest::Test
226
228
  assert_nil(writer.close)
227
229
  end
228
230
 
229
- def test_pos_returns_uncompressed_position
230
- Bzip2::FFI::Writer.open(DummyIO.new) do |writer|
231
- assert_equal(0, writer.pos)
232
- writer.write('Test')
233
- assert_equal(4, writer.pos)
234
- writer.write('Complete')
235
- assert_equal(12, writer.pos)
231
+ [:tell, :pos].each do |method|
232
+ define_method("test_#{method}_returns_uncompressed_position") do
233
+ Bzip2::FFI::Writer.open(DummyIO.new) do |writer|
234
+ assert_equal(0, writer.public_send(method))
235
+ writer.write('Test')
236
+ assert_equal(4, writer.public_send(method))
237
+ writer.write('Complete')
238
+ assert_equal(12, writer.public_send(method))
239
+ end
236
240
  end
237
- end
238
241
 
239
- def test_pos_returns_uncompressed_64bit_position
240
- skip_slow_test_unless_enabled
242
+ define_method("test_#{method}_returns_uncompressed_64bit_position") do
243
+ skip_slow_test_unless_enabled
241
244
 
242
- # The position is read from separate 32-bit low and high words.
243
- Bzip2::FFI::Writer.open(DummyIO.new) do |writer|
244
- buffer_bits = 12
245
- buffer = "\0".encode(Encoding::ASCII_8BIT) * 2**buffer_bits
245
+ # The position is read from separate 32-bit low and high words.
246
+ Bzip2::FFI::Writer.open(DummyIO.new) do |writer|
247
+ buffer_bits = 12
248
+ buffer = "\0".encode(Encoding::ASCII_8BIT) * 2**buffer_bits
246
249
 
247
- (2**(32 - buffer_bits)).times do |i|
250
+ (2**(32 - buffer_bits)).times do |i|
251
+ writer.write(buffer)
252
+ end
253
+
254
+ assert_equal(2**32, writer.public_send(method))
248
255
  writer.write(buffer)
256
+ assert_equal(2**32 + buffer.bytesize, writer.public_send(method))
249
257
  end
250
-
251
- assert_equal(2**32, writer.pos)
252
- writer.write(buffer)
253
- assert_equal(2**32 + buffer.bytesize, writer.pos)
254
258
  end
255
- end
256
259
 
257
- def test_pos_raises_io_error_when_closed
258
- writer = Bzip2::FFI::Writer.new(DummyIO.new)
259
- writer.close
260
- assert_raises(IOError) { writer.pos }
260
+ define_method("test_#{method}_raises_io_error_when_closed") do
261
+ writer = Bzip2::FFI::Writer.new(DummyIO.new)
262
+ writer.close
263
+ assert_raises(IOError) { writer.public_send(method) }
264
+ end
261
265
  end
262
266
 
263
267
  def test_finalizer
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bzip2-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Ross
@@ -29,7 +29,7 @@ cert_chain:
29
29
  J3Zn/kSTjTekiaspyGbczC3PUaeJNxr+yCvR4sk71Xmk/GaKKGOHedJ1uj/LAXrA
30
30
  MR0mpl7b8zCg0PFC1J73uw==
31
31
  -----END CERTIFICATE-----
32
- date: 2021-02-27 00:00:00.000000000 Z
32
+ date: 2023-07-08 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: ffi
@@ -91,9 +91,9 @@ licenses:
91
91
  metadata:
92
92
  bug_tracker_uri: https://github.com/philr/bzip2-ffi/issues
93
93
  changelog_uri: https://github.com/philr/bzip2-ffi/blob/master/CHANGES.md
94
- documentation_uri: https://rubydoc.info/gems/bzip2-ffi/1.1.0
94
+ documentation_uri: https://rubydoc.info/gems/bzip2-ffi/1.1.1
95
95
  homepage_uri: https://github.com/philr/bzip2-ffi
96
- source_code_uri: https://github.com/philr/bzip2-ffi/tree/v1.1.0
96
+ source_code_uri: https://github.com/philr/bzip2-ffi/tree/v1.1.1
97
97
  post_install_message:
98
98
  rdoc_options:
99
99
  - "--title"
@@ -116,8 +116,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements:
118
118
  - libbz2.(so|dll|dylib) available on the library search path
119
- rubygems_version: 3.2.3
119
+ rubygems_version: 3.4.9
120
120
  signing_key:
121
121
  specification_version: 4
122
- summary: Reads and writes bzip2 compressed data using FFI bindings for libbz2.
122
+ summary: Reads and writes bzip2 compressed data as a stream using FFI bindings for
123
+ libbz2.
123
124
  test_files: []
metadata.gz.sig CHANGED
Binary file