Skip to content

Commit

Permalink
Add RubyZip 2.4 and 3.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed Dec 9, 2024
1 parent 7590d81 commit c00d4cc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
allow_failures: 'allow failures'
- ruby: jruby-head
allow_failures: 'allow failures'
- ruby: 3.3
gemfile: 'gemfiles/rubyzip_3.gemfile'
allow_failures: 'allow failures'

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ examples/sprk2012
.~lock*
*.qcachegrind
*.iml
.idea
.idea
gemfiles/*.lock
14 changes: 14 additions & 0 deletions gemfiles/rubyzip_3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

source 'https://rubygems.org'
gemspec path: "../"

gem 'rubyzip', git: 'https://github.com/rubyzip/rubyzip.git'

group :test do
gem 'rake'
gem 'simplecov'
gem 'minitest'
gem 'timecop'
gem 'webmock'
end
1 change: 1 addition & 0 deletions lib/axlsx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'marcel'
require 'nokogiri'
require 'zip'
require 'zip/version'

# Ruby core dependencies
require 'cgi'
Expand Down
7 changes: 6 additions & 1 deletion lib/axlsx/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,12 @@ def write_parts(zip)
# @return [Zip::Entry]
def zip_entry_for_part(part)
timestamp = Zip::DOSTime.at(@core.created.to_i)
Zip::Entry.new("", part[:entry], "", "", 0, 0, Zip::Entry::DEFLATED, 0, timestamp)

if Zip::VERSION >= '2.4'
Zip::Entry.new("", part[:entry], time: timestamp)
else
Zip::Entry.new("", part[:entry], "", "", 0, 0, Zip::Entry::DEFLATED, 0, timestamp)
end
end

# The parts of a package
Expand Down
38 changes: 28 additions & 10 deletions lib/axlsx/util/buffered_zip_output_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,38 @@ def initialize(zos)
#
# The directory and its contents are removed at the end of the block.
def self.open(file_name, encrypter = nil)
Zip::OutputStream.open(file_name, encrypter) do |zos|
bzos = new(zos)
yield(bzos)
ensure
bzos.flush if bzos
if Zip::VERSION >= '2.4'
Zip::OutputStream.open(file_name, encrypter: encrypter) do |zos|
bzos = new(zos)
yield(bzos)
ensure
bzos.flush if bzos
end
else
Zip::OutputStream.open(file_name, encrypter) do |zos|
bzos = new(zos)
yield(bzos)
ensure
bzos.flush if bzos
end
end
end

def self.write_buffer(io = ::StringIO.new, encrypter = nil)
Zip::OutputStream.write_buffer(io, encrypter) do |zos|
bzos = new(zos)
yield(bzos)
ensure
bzos.flush if bzos
if Zip::VERSION >= '2.4'
Zip::OutputStream.write_buffer(io, encrypter: encrypter) do |zos|
bzos = new(zos)
yield(bzos)
ensure
bzos.flush if bzos
end
else
Zip::OutputStream.write_buffer(io, encrypter) do |zos|
bzos = new(zos)
yield(bzos)
ensure
bzos.flush if bzos
end
end
end

Expand Down

0 comments on commit c00d4cc

Please sign in to comment.