bzip2-ffi 1.0.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
- SHA1:
3
- metadata.gz: 91dd417ec50336680acdedba3bc7eb9c80a268f6
4
- data.tar.gz: 637b7684138b2e615ce3720dd8d9a927029481bb
2
+ SHA256:
3
+ metadata.gz: 25b15e037a74f589a612d955890d194519a97abfa903c993589d0096794b6459
4
+ data.tar.gz: '088c393a99b19d1d625148c951461333d2ed9ef934df6e5efaee2ea0007b9620'
5
5
  SHA512:
6
- metadata.gz: a74b7c8e55a23de078c58b0d1c10b9f1addba8867a3b91bac0fbd7c4f22a663e5dccbbc1523814c5e6fdd779728c2d6acb92ad08bce3c05102a42eb97dd743b4
7
- data.tar.gz: 10a5f0950a4bb5e4005632679097bcfdfb838bfcebf120ea9f986b9d30c5d1042ebb01bb7e866cb1891a919cbc90746f2a30df5dbce58bc3aa0c570cd828c750
6
+ metadata.gz: 84ff7dd72ab2d08ebaf3eda64b104db414b882f90f4d05df06485bf0b5f9e6c116512d5c5183e8f921aacf660eaf58eb37d5d2fd959002b859fd97f9c8af7a8e
7
+ data.tar.gz: 59ee28b33e364ce56a453ad9abd2f6fad30e8aa623d6ddb89f50d8211b4ad77d32e3493bbac853e74b558e307af6f7db71d057aaddb72cbcc15338c332dec16b
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,4 +1,35 @@
1
- Version 1.0.0 - 28-Feb-2015
2
- ---------------------------
1
+ # Changes
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
+
13
+ ## Version 1.1.0 - 27-Feb-2021
14
+
15
+ * `Bzip2::FFI::Reader` will now read all consecutive bzip2 compressed structures
16
+ in the input by default instead of just the first (the same as the
17
+ bzip2/bunzip2 commands). A new `:first_only` option has been added to allow
18
+ the version 1.0.0 behaviour to be retained. #1.
19
+ * Added `#eof?` and `#eof` to `Bzip2::FFI::Reader`, indicating when
20
+ decompression has completed.
21
+ * Added `Bzip2::FFI::Reader#pos`, returning the number of decompressed bytes
22
+ that have been read.
23
+ * Added `Bzip2::FFI::Writer#pos`, returning the number of uncompressed bytes
24
+ that have been written.
25
+ * Support using Bzip2::FFI with frozen string literals enabled (and enable in
26
+ all files with `# frozen_string_literal: true`).
27
+ * Constants documented as private in version 1.0.0 are now set as private using
28
+ `Module#private_constant`.
29
+ * `require_relative` is now used when loading dependencies for a minor
30
+ performance gain.
31
+
32
+
33
+ ## Version 1.0.0 - 28-Feb-2015
3
34
 
4
35
  * First release.
data/Gemfile CHANGED
@@ -3,12 +3,53 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem 'rake', '~> 10.0'
6
+ gem 'rake', ['>= 12.2.1', '< 14']
7
7
  gem 'git', '~> 1.2', require: false
8
8
  end
9
9
 
10
10
  group :test do
11
11
  gem 'minitest', '~> 5.0'
12
12
  gem 'simplecov', '~> 0.9', require: false
13
- gem 'coveralls', '~> 0.7', require: false
13
+
14
+ # coveralls is no longer maintained, but supports Ruby < 2.3.
15
+ # coveralls_reborn is maintained, but requires Ruby >= 2.3.
16
+ gem 'coveralls', git: 'https://github.com/philr/coveralls-ruby.git', require: false if RUBY_VERSION < '2.3'
17
+ gem 'coveralls_reborn', '~> 0.13', require: false if RUBY_VERSION >= '2.3'
18
+
19
+
20
+ # json is a dependency of simplecov. Version 2.3.0 is declared as compatible
21
+ # with Ruby >= 1.9, but actually fails with a syntax error:
22
+ # https://travis-ci.org/tzinfo/tzinfo/jobs/625092293#L605
23
+ #
24
+ # 2.5.1 is declared as compatible with Ruby >= 2.0, but actually fails to
25
+ # compile with an undefined reference to `rb_funcallv` on Windows:
26
+ # https://github.com/tzinfo/tzinfo/runs/1664656059#step:3:757
27
+ #
28
+ # 2.3.0 also fails to build the native extension with Rubinius:
29
+ # https://travis-ci.org/tzinfo/tzinfo/jobs/625092305#L1310
30
+ #
31
+ # Limit to earlier compatible versions.
32
+ if RUBY_VERSION < '2.0' || RUBY_ENGINE == 'rbx'
33
+ gem 'json', '< 2.3.0'
34
+ elsif RUBY_VERSION < '2.1' && RUBY_PLATFORM =~ /mingw/
35
+ gem 'json', '< 2.5.0'
36
+ end
37
+
38
+ # ffi 1.9.15 is declared as compatible with Ruby >= 1.8.7, but doesn't compile
39
+ # on Ruby 1.9.3 on Windows.
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
+ #
49
+ # Limit to earlier compatible versions.
50
+ if RUBY_VERSION < '2.0' && RUBY_PLATFORM =~ /mingw/
51
+ gem 'ffi', '< 1.9.0'
52
+ elsif RUBY_VERSION < '2.4' && RUBY_PLATFORM =~ /mingw/
53
+ gem 'ffi', '< 1.15.0'
54
+ end
14
55
  end
data/LICENSE CHANGED
@@ -1,19 +1,19 @@
1
- Copyright (c) 2015 Philip Ross
1
+ Copyright (c) 2015-2023 Philip Ross
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
- of the Software, and to permit persons to whom the Software is furnished to do
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
8
  so, subject to the following conditions:
9
9
 
10
- The above copyright notice and this permission notice shall be included in all
10
+ The above copyright notice and this permission notice shall be included in all
11
11
  copies or substantial portions of the Software.
12
12
 
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Bzip2::FFI #
1
+ # Bzip2::FFI
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/bzip2-ffi.svg)](http://badge.fury.io/rb/bzip2-ffi) [![Build Status](https://travis-ci.org/philr/bzip2-ffi.svg?branch=master)](https://travis-ci.org/philr/bzip2-ffi) [![Coverage Status](https://coveralls.io/repos/philr/bzip2-ffi/badge.svg?branch=master)](https://coveralls.io/r/philr/bzip2-ffi?branch=master)
3
+ [![RubyGems](https://img.shields.io/gem/v/bzip2-ffi?logo=rubygems&label=Gem)](https://rubygems.org/gems/bzip2-ffi) [![Tests](https://github.com/philr/bzip2-ffi/workflows/Tests/badge.svg?branch=master&event=push)](https://github.com/philr/bzip2-ffi/actions?query=workflow%3ATests+branch%3Amaster+event%3Apush) [![Coverage Status](https://img.shields.io/coveralls/github/philr/bzip2-ffi/master?label=Coverage&logo=Coveralls)](https://coveralls.io/github/philr/bzip2-ffi?branch=master)
4
4
 
5
5
  Bzip2::FFI is a Ruby wrapper for libbz2 using FFI bindings.
6
6
 
@@ -8,35 +8,30 @@ The Bzip2::FFI Reader and Writer classes support reading and writing bzip2
8
8
  compressed data as an `IO`-like stream.
9
9
 
10
10
 
11
- ## Installation ##
11
+ ## Installation
12
12
 
13
- To install the Bzip2::FFI gem, run the following command:
13
+ The Bzip2::FFI gem can be installed by running `gem install bzip2-ffi` or by
14
+ adding `gem 'bzip2-ffi'` to your `Gemfile` and running `bundle install`.
14
15
 
15
- gem install bzip2-ffi
16
16
 
17
- To add Bzip2::FFI as a Bundler dependency, add the following line to your
18
- `Gemfile`:
17
+ ## Compatibility
19
18
 
20
- gem 'bzip2-ffi'
19
+ Bzip2::FFI requires a minimum of Ruby MRI 1.9.3 or JRuby 1.7 (in 1.9 mode or
20
+ later).
21
21
 
22
22
 
23
- ## Compatibility ##
24
-
25
- Bzip2::FFI is tested on Ruby MRI 1.9.3+, JRuby 1.7+ and Rubinius 2+.
26
-
27
-
28
- ## Runtime Dependencies ##
23
+ ## Runtime Dependencies
29
24
 
30
25
  Bzip2::FFI is a pure-Ruby library that uses
31
26
  [Ruby-FFI](https://rubygems.org/gems/ffi) (Foreign Function Interface) to load
32
27
  the libbz2 dynamic library at runtime.
33
28
 
34
29
  libbz2 is available as a package on most UNIX-based systems (for example,
35
- `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
36
31
  CentOS).
37
32
 
38
33
 
39
- ### Windows ###
34
+ ### Windows
40
35
 
41
36
  On Windows, you will need to have `libbz2.dll` or `bz2.dll` available on the
42
37
  `PATH` or in the Ruby `bin` directory.
@@ -46,99 +41,134 @@ Suitable builds of `libbz2.dll` are available from the
46
41
  Download the DLL only package that matches your Ruby installation (x86 or x64)
47
42
  and extract to your `ruby\bin` directory.
48
43
 
49
- Builds from the bzip2-windows project depend on the Visual Studio 2013 C Runtime
50
- Library (msvcr120.dll). This can be installed using the
51
- [Visual C++ Redistributable Packages for Visual Studio 2013 installer](http://www.microsoft.com/en-gb/download/details.aspx?id=40784).
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 releases page.
52
46
 
53
47
 
54
- ## Usage ##
48
+ ## Usage
55
49
 
56
50
  To use Bzip2::FFI, it must first be loaded with:
57
51
 
58
- require 'bzip2/ffi'
52
+ ```ruby
53
+ require 'bzip2/ffi'
54
+ ```
59
55
 
60
56
 
61
- ### Compressing ###
57
+ ### Compressing
62
58
 
63
59
  Data can be compressed using the `Bzip2::FFI::Writer` class. For example, the
64
- following compresses lines read from standard input (`ARGF`):
60
+ following compresses lines read from `ARGF` (either standard input, or file
61
+ names given as command-line arguments):
65
62
 
66
- Bzip2::FFI::Writer.open(io_or_path) do |writer|
67
- ARGF.each_line do |line|
68
- writer.write(line)
69
- end
70
- end
63
+ ```ruby
64
+ Bzip2::FFI::Writer.open(io_or_path) do |writer|
65
+ ARGF.each_line do |line|
66
+ writer.write(line)
67
+ end
68
+ end
69
+ ```
71
70
 
72
71
  Alternatively, without passing a block to `open`:
73
72
 
74
- writer = Bzip2::FFI::Writer.open(io_or_path)
75
- begin
76
- ARGF.each_line do |line|
77
- writer.write(line)
78
- end
79
- ensure
80
- writer.close
81
- end
73
+ ```ruby
74
+ writer = Bzip2::FFI::Writer.open(io_or_path)
75
+ begin
76
+ ARGF.each_line do |line|
77
+ writer.write(line)
78
+ end
79
+ ensure
80
+ writer.close
81
+ end
82
+ ```
82
83
 
83
84
  An entire bzip2 structure can also be written in a single step:
84
85
 
85
- Bzip2::FFI::Writer.write(io_or_path, 'Hello, World!')
86
+ ```ruby
87
+ Bzip2::FFI::Writer.write(io_or_path, 'Hello, World!')
88
+ ```
86
89
 
87
90
  In each of the examples above, `io_or_path` can either be a path to a file to
88
- write to or an `IO`-like object that has a `write` method.
91
+ write to or an `IO`-like object that has a `#write` method.
89
92
 
90
93
 
91
- ### Decompressing ###
94
+ ### Decompressing
92
95
 
93
96
  Data can be decompressed using the `Bzip2::FFI::Reader` class. For example:
94
97
 
95
- Bzip2::FFI::Reader.open(io_or_path) do |reader|
96
- while buffer = reader.read(1024) do
97
- # process uncompressed bytes in buffer
98
- end
99
- end
98
+ ```ruby
99
+ Bzip2::FFI::Reader.open(io_or_path) do |reader|
100
+ while buffer = reader.read(1024) do
101
+ # process uncompressed bytes in buffer
102
+ end
103
+ end
104
+ ```
100
105
 
101
106
  Alternatively, without passing a block to `open`:
102
107
 
103
- reader = Bzip2::FFI::Reader.open(io_or_path)
104
- begin
105
- while buffer = reader.read(1024) do
106
- # process uncompressed bytes in buffer
107
- end
108
- ensure
109
- reader.close
110
- end
108
+ ```ruby
109
+ reader = Bzip2::FFI::Reader.open(io_or_path)
110
+ begin
111
+ while buffer = reader.read(1024) do
112
+ # process uncompressed bytes in buffer
113
+ end
114
+ ensure
115
+ reader.close
116
+ end
117
+ ```
111
118
 
112
- An entire bzip2 structure 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:
113
121
 
114
- uncompressed = Bzip2::FFI::Reader.read(io_or_path)
122
+ ```ruby
123
+ uncompressed = Bzip2::FFI::Reader.read(io_or_path)
124
+ ```
115
125
 
116
126
  In each of the examples above, `io_or_path` can either be a path to a file to
117
- read from or an `IO`-like object that has a `read` method.
127
+ read from or an `IO`-like object that has a `#read` method.
118
128
 
119
129
 
120
- ### Character Encoding ###
130
+ ### Character Encoding
121
131
 
122
132
  Bzip2::FFI does not perform any encoding conversion when reading or writing.
123
133
  Data read using `Bzip2::FFI::Reader` is returned as `String` instances with
124
134
  ASCII-8BIT (BINARY) encoding representing the raw decompressed bytes.
125
- `Bzip2::FFI::Writer` compresses the raw bytes from the `Strings` passed to the
126
- `write` method (using the encoding of the `String`).
135
+ `Bzip2::FFI::Writer` compresses the raw bytes from the `String` instances passed
136
+ to the `#write` method (using the encoding of the `String`).
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.
127
157
 
128
158
 
129
- ## Documentation ##
159
+ ## Documentation
130
160
 
131
161
  Documentation for Bzip2::FFI is available on
132
- [RubyDoc.info](http://www.rubydoc.info/gems/bzip2-ffi).
162
+ [RubyDoc.info](https://www.rubydoc.info/gems/bzip2-ffi).
133
163
 
134
164
 
135
- ## License ##
165
+ ## License
136
166
 
137
167
  Bzip2::FFI is distributed under the terms of the MIT license. A copy of this
138
168
  license can be found in the included LICENSE file.
139
169
 
140
170
 
141
- ## GitHub Project ##
171
+ ## GitHub Project
142
172
 
143
173
  Source code, release information and the issue tracker can be found on the
144
174
  [Bzip2::FFI GitHub project page](https://github.com/philr/bzip2-ffi).
data/Rakefile CHANGED
@@ -60,3 +60,27 @@ Rake::TestTask.new do |t|
60
60
  t.pattern = File.join(BASE_DIR, 'test', '**', '*_test.rb')
61
61
  t.warning = true
62
62
  end
63
+
64
+ # Coveralls expects an sh compatible shell when running git commands with Kernel#`
65
+ # On Windows, the results end up wrapped in single quotes.
66
+ # Patch Coveralls::Configuration to remove the quotes.
67
+ if RUBY_PLATFORM =~ /mingw/
68
+ module CoverallsFixConfigurationOnWindows
69
+ def self.included(base)
70
+ base.instance_eval do
71
+ class << self
72
+ alias_method :git_without_windows_fix, :git
73
+
74
+ def git
75
+ git_without_windows_fix.tap do |hash|
76
+ hash[:head] = hash[:head].map {|k, v| [k, v =~ /\A'(.*)'\z/ ? $1 : v] }.to_h
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ require 'coveralls'
85
+ Coveralls::Configuration.send(:include, CoverallsFixConfigurationOnWindows)
86
+ end
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
 
@@ -14,6 +14,15 @@ Gem::Specification.new do |s|
14
14
  s.email = 'phil.ross@gmail.com'
15
15
  s.homepage = 'https://github.com/philr/bzip2-ffi'
16
16
  s.license = 'MIT'
17
+ if s.respond_to? :metadata=
18
+ s.metadata = {
19
+ 'bug_tracker_uri' => 'https://github.com/philr/bzip2-ffi/issues',
20
+ 'changelog_uri' => 'https://github.com/philr/bzip2-ffi/blob/master/CHANGES.md',
21
+ 'documentation_uri' => "https://rubydoc.info/gems/#{s.name}/#{s.version}",
22
+ 'homepage_uri' => s.homepage,
23
+ 'source_code_uri' => "https://github.com/philr/bzip2-ffi/tree/v#{s.version}"
24
+ }
25
+ end
17
26
  s.files = %w(CHANGES.md Gemfile LICENSE README.md Rakefile bzip2-ffi.gemspec .yardopts) +
18
27
  Dir['lib/**/*.rb'] +
19
28
  Dir['test/**/*.rb'] +
@@ -1,7 +1,10 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Bzip2
2
5
  module FFI
3
- # The Bzip2::FFI::Error namespace contains exception classes that are raised
4
- # if an error occurs whilst compressing or decompressing data.
6
+ # The {Error} module contains exception classes that are raised if an error
7
+ # occurs whilst compressing or decompressing data.
5
8
  module Error
6
9
  # Base class for Bzip2::FFI exceptions.
7
10
  class Bzip2Error < IOError