diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b8533ad..0de9158 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,7 +12,7 @@ jobs: - name: Install and set up ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.4 + ruby-version: '3.0' bundler-cache: true - name: Rubocop diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 45a98af..2b6b635 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,12 +8,12 @@ jobs: fail-fast: false matrix: os: [ubuntu] - ruby: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head, jruby, jruby-head, truffleruby, truffleruby-head] + ruby: ['3.0', '3.1', '3.2', '3.3', '3.4', head, jruby, jruby-head, truffleruby, truffleruby-head] include: - os: macos - ruby: '2.6' + ruby: '3.0' - os: windows - ruby: '2.4.10' + ruby: '3.0' runs-on: ${{ matrix.os }}-latest continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.os == 'windows' }} steps: diff --git a/.rubocop.yml b/.rubocop.yml index 2db80d2..b3efced 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,16 @@ +require: + - rubocop-performance + - rubocop-rake + +# Set this to the minimum supported ruby in the gemspec. Otherwise +# we get errors if our ruby version doesn't match. AllCops: - TargetRubyVersion: 2.4 + SuggestExtensions: false + TargetRubyVersion: 3.0 + NewCops: enable + +Gemspec/DevelopmentDependencies: + EnforcedStyle: gemspec Layout/LineLength: Max: 120 diff --git a/.simplecov b/.simplecov index 611a952..91415df 100644 --- a/.simplecov +++ b/.simplecov @@ -17,6 +17,6 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new( ) SimpleCov.start do - # enable_coverage :branch <-- Re-enable this when we move to ruby ~> 2.5. + enable_coverage :branch add_filter ['/test/', '/samples/'] end diff --git a/Changelog.md b/Changelog.md index 9447446..c81da15 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,6 @@ -# X.X.X (Next) +# 2.0.0 (Next) + +# 1.0.0 (2025-02-07) * Fix automatic require * Fix the Libbz2::finalizer method. diff --git a/Rakefile b/Rakefile index 4caa98e..8bd2b55 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,9 @@ require 'bundler/gem_tasks' require 'rake/testtask' +require 'rubocop/rake_task' + +task default: :test Rake::TestTask.new(:test) do |t| t.libs << 'test' @@ -9,4 +12,4 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList['test/**/*_test.rb'] end -task default: :test +RuboCop::RakeTask.new diff --git a/lib/zip/bzip2.rb b/lib/zip/bzip2.rb index ed697bd..69afc08 100644 --- a/lib/zip/bzip2.rb +++ b/lib/zip/bzip2.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true require 'zip' -require 'zip/bzip2/version' -require 'zip/bzip2/decompressor' +require_relative 'bzip2/version' +require_relative 'bzip2/decompressor' module Zip # The Zip::Bzip2 module extends Rubyzip with support for the bzip2 compression method. diff --git a/lib/zip/bzip2/decompress.rb b/lib/zip/bzip2/decompress.rb index 278091c..9833a56 100644 --- a/lib/zip/bzip2/decompress.rb +++ b/lib/zip/bzip2/decompress.rb @@ -1,24 +1,24 @@ # frozen_string_literal: true -require 'zip/bzip2/libbz2' +require_relative 'libbz2' module Zip module Bzip2 - class Decompress #:nodoc: + class Decompress # :nodoc: OUTPUT_BUFFER_SIZE = 4096 def initialize(options = {}) small = options[:small] @libbz2 = Libbz2.new.tap do |libbz2| - libbz2.decompress_init!(small) + libbz2.decompress_init!(small: small) end @finished = false end def decompress(data) - result = ''.dup + result = +'' with_input_buffer(data) do |input_buffer| @libbz2.input_buffer = input_buffer diff --git a/lib/zip/bzip2/decompressor.rb b/lib/zip/bzip2/decompressor.rb index 0e19e68..a64ba30 100644 --- a/lib/zip/bzip2/decompressor.rb +++ b/lib/zip/bzip2/decompressor.rb @@ -1,19 +1,18 @@ # frozen_string_literal: true -require 'zip' -require 'zip/bzip2/decompress' +require_relative 'decompress' -module Zip #:nodoc: +module Zip # :nodoc: module Bzip2 - class Decompressor < ::Zip::Decompressor #:nodoc: + class Decompressor < ::Zip::Decompressor # :nodoc: def initialize(*args) super - @buffer = ''.dup + @buffer = +'' @bzip2_ffi_decompressor = ::Zip::Bzip2::Decompress.new end - def read(length = nil, outbuf = ''.dup) + def read(length = nil, outbuf = +'') return return_value_on_eof(length) if eof fill_buffer(length) @@ -30,7 +29,7 @@ def eof private def return_value_on_eof(length) - return '' if length.nil? || length.zero? + '' if length.nil? || length.zero? end def fill_buffer(min_length) diff --git a/lib/zip/bzip2/errors.rb b/lib/zip/bzip2/errors.rb index 6e11c52..8c15c77 100644 --- a/lib/zip/bzip2/errors.rb +++ b/lib/zip/bzip2/errors.rb @@ -11,7 +11,7 @@ class MemError < Error # Initializes a new instance of MemError. # # @private - def initialize #:nodoc: + def initialize # :nodoc: super('Could not allocate enough memory to perform this request') end end @@ -23,10 +23,10 @@ class DataError < Error # # @param message [String] Exception message (overrides the default). # @private - def initialize(message = nil) #:nodoc: + def initialize(message = nil) # :nodoc: super( message || - 'Data integrity error detected (mismatch between stored and computed CRCs, '\ + 'Data integrity error detected (mismatch between stored and computed CRCs, ' \ 'or other anomaly in the compressed data)', ) end @@ -38,7 +38,7 @@ class MagicDataError < DataError # Initializes a new instance of MagicDataError. # # @private - def initialize #:nodoc: + def initialize # :nodoc: super('Compressed data does not start with the correct magic bytes (\'BZh\')') end end @@ -48,7 +48,7 @@ class ConfigError < DataError # Initializes a new instance of ConfigError. # # @private - def initialize #:nodoc: + def initialize # :nodoc: super('libbz2 has been improperly compiled on your platform') end end @@ -59,7 +59,7 @@ class UnexpectedError < Error # # @param error_code [Integer] The error_code reported by libbz2. # @private - def initialize(error_code) #:nodoc: + def initialize(error_code) # :nodoc: super("An unexpected error was detected (error code: #{error_code})") end end diff --git a/lib/zip/bzip2/ffi/libbz2.rb b/lib/zip/bzip2/ffi/libbz2.rb index 0352201..04d69ba 100644 --- a/lib/zip/bzip2/ffi/libbz2.rb +++ b/lib/zip/bzip2/ffi/libbz2.rb @@ -34,7 +34,7 @@ module FFI # See bzlib.h and http://bzip.org/docs.html. # # @private - module Libbz2 #:nodoc: + module Libbz2 # :nodoc: extend ::FFI::Library ffi_lib ['bz2', 'libbz2.so.1', 'libbz2.dll'] @@ -62,7 +62,7 @@ module Libbz2 #:nodoc: callback :bzfree, %i[pointer pointer], :void # typedef struct { ... } bz_stream; - class BzStream < ::FFI::Struct #:nodoc: + class BzStream < ::FFI::Struct # :nodoc: layout :next_in, :pointer, :avail_in, :uint, :total_in_lo32, :uint, diff --git a/lib/zip/bzip2/libbz2.rb b/lib/zip/bzip2/libbz2.rb index 42ad397..9762368 100644 --- a/lib/zip/bzip2/libbz2.rb +++ b/lib/zip/bzip2/libbz2.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true -require 'ffi' -require 'zip/bzip2/errors' -require 'zip/bzip2/ffi/libbz2' +require_relative 'errors' +require_relative 'ffi/libbz2' module Zip module Bzip2 - class Libbz2 #:nodoc: + class Libbz2 # :nodoc: def self.finalizer(stream) lambda do |_id| FFI::Libbz2::BZ2_bzDecompressEnd(stream) @@ -28,7 +27,7 @@ def initialize @stream = FFI::Libbz2::BzStream.new end - def decompress_init!(small = false) + def decompress_init!(small: false) result = FFI::Libbz2::BZ2_bzDecompressInit(@stream, 0, small ? 1 : 0) check_error(result) diff --git a/lib/zip/bzip2/version.rb b/lib/zip/bzip2/version.rb index eefc9fe..ec1f7b1 100644 --- a/lib/zip/bzip2/version.rb +++ b/lib/zip/bzip2/version.rb @@ -2,6 +2,6 @@ module Zip module Bzip2 - VERSION = '1.0.0' + VERSION = '2.0.0' end end diff --git a/rubyzip-bzip2.gemspec b/rubyzip-bzip2.gemspec index 87eaa69..9f0eea3 100644 --- a/rubyzip-bzip2.gemspec +++ b/rubyzip-bzip2.gemspec @@ -1,25 +1,23 @@ # frozen_string_literal: true -lib = File.expand_path('lib', __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'zip/bzip2/version' +require_relative 'lib/zip/bzip2/version' Gem::Specification.new do |spec| spec.name = 'rubyzip-bzip2' - spec.version = ::Zip::Bzip2::VERSION + spec.version = Zip::Bzip2::VERSION spec.authors = [ 'Jan-Joost Spanjers', 'Robert Haines' ] spec.summary = 'Extension of rubyzip to read bzip2 compressed files' spec.description = - 'The rubyzip-bzip2 gem provides an extension of the rubyzip gem '\ + 'The rubyzip-bzip2 gem provides an extension of the rubyzip gem ' \ 'for reading zip files compressed with bzip2 compression' spec.homepage = 'http://github.com/rubyzip/rubyzip-bzip2' spec.license = 'BSD 2-Clause' spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 2.4' + spec.required_ruby_version = '>= 3.0' spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) @@ -35,11 +33,13 @@ Gem::Specification.new do |spec| } spec.add_dependency 'ffi', '~> 1.0' - spec.add_dependency 'rubyzip', '~> 2.4', '< 3.0' + spec.add_dependency 'rubyzip', '~> 3.0.0.rc2' spec.add_development_dependency 'minitest', '~> 5.15' spec.add_development_dependency 'rake', '~> 13.2' - spec.add_development_dependency 'rubocop', '~> 0.79.0' + spec.add_development_dependency 'rubocop', '~> 1.61.0' + spec.add_development_dependency 'rubocop-performance', '~> 1.20.0' + spec.add_development_dependency 'rubocop-rake', '~> 0.6.0' spec.add_development_dependency 'simplecov', '~> 0.18.0' spec.add_development_dependency 'simplecov-lcov', '~> 0.8' end diff --git a/test/integration/zip_file_bzip2_support_test.rb b/test/integration/zip_file_bzip2_support_test.rb index 568eb45..3ae2f24 100644 --- a/test/integration/zip_file_bzip2_support_test.rb +++ b/test/integration/zip_file_bzip2_support_test.rb @@ -17,10 +17,10 @@ def test_file_read private def file1_text - @file1_text ||= File.open(FILE1, 'r').read + @file1_text ||= File.read(FILE1) end def file2_text - @file2_text ||= File.open(FILE2, 'r').read + @file2_text ||= File.read(FILE2) end end diff --git a/test/integration/zip_input_stream_bzip2_support_test.rb b/test/integration/zip_input_stream_bzip2_support_test.rb index a2d4aa9..71941bd 100644 --- a/test/integration/zip_input_stream_bzip2_support_test.rb +++ b/test/integration/zip_input_stream_bzip2_support_test.rb @@ -20,7 +20,9 @@ def test_input_stream_read end def test_input_stream_encrypted_read - Zip::InputStream.open(BZIP2_ZIP_FILE_ENCRYPTED, 0, Zip::TraditionalDecrypter.new(PASSWORD)) do |zis| + decrypter = Zip::TraditionalDecrypter.new(PASSWORD) + + Zip::InputStream.open(BZIP2_ZIP_FILE_ENCRYPTED, decrypter: decrypter) do |zis| zis.get_next_entry assert_equal file1_text, zis.read @@ -32,10 +34,10 @@ def test_input_stream_encrypted_read private def file1_text - @file1_text ||= File.open(FILE1, 'r').read + @file1_text ||= File.read(FILE1) end def file2_text - @file2_text ||= File.open(FILE2, 'r').read + @file2_text ||= File.read(FILE2) end end diff --git a/test/models/zip/bzip2/decompress_test.rb b/test/models/zip/bzip2/decompress_test.rb index e3ca4a7..c6b425c 100644 --- a/test/models/zip/bzip2/decompress_test.rb +++ b/test/models/zip/bzip2/decompress_test.rb @@ -43,10 +43,10 @@ def test_decompress_with_corrupted_input private def file_text - @file_text ||= File.open(FILE, &:read) + @file_text ||= File.read(FILE) end def compressed_data - @compressed_data ||= File.open(BZIP2_FILE, 'rb', &:read) + @compressed_data ||= File.binread(BZIP2_FILE) end end diff --git a/test/models/zip/bzip2/decompressor_test.rb b/test/models/zip/bzip2/decompressor_test.rb index c015427..92f6a05 100644 --- a/test/models/zip/bzip2/decompressor_test.rb +++ b/test/models/zip/bzip2/decompressor_test.rb @@ -39,6 +39,6 @@ def test_data_error private def test_text - @test_text ||= File.open(FILE1, &:read) + @test_text ||= File.read(FILE1) end end diff --git a/test/models/zip/bzip2/libbz2_test.rb b/test/models/zip/bzip2/libbz2_test.rb index 30aecff..85dfed6 100644 --- a/test/models/zip/bzip2/libbz2_test.rb +++ b/test/models/zip/bzip2/libbz2_test.rb @@ -74,10 +74,10 @@ def decompress(data) end def file_text - @file_text ||= File.open(FILE, &:read) + @file_text ||= File.read(FILE) end def compressed_data - @compressed_data ||= File.open(BZIP2_FILE, 'rb', &:read) + @compressed_data ||= File.binread(BZIP2_FILE) end end